-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathADB.cs
More file actions
195 lines (184 loc) · 8.14 KB
/
ADB.cs
File metadata and controls
195 lines (184 loc) · 8.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
using AdvancedSharpAdbClient.Exceptions;
using AdvancedSharpAdbClient;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.IO.Compression;
using System.Windows.Forms;
using static OculusTouchUI.OculusWrapper;
using System.Net.Sockets;
using System.Text.RegularExpressions;
/*using VRCOSC.OpenVR;
using VRCOSC.OpenVR.Metadata;
using Valve.VR;
using VRCOSC.OpenVR.Device;*/
namespace OculusTouchUI
{
/*internal class OVRDispatcher
{
private static OVRClient ovrClient;
public static void Initialize()
{
if (ovrClient != null)
return;
ovrClient = new OVRClient(new OVRMetadata
{
ApplicationType = EVRApplicationType.VRApplication_Background,
ApplicationManifest = string.Empty,
ActionManifest = string.Empty
});
OVRHelper.OnError += m => Console.WriteLine($"OpenVR Exception: {m}");
ovrClient.Init();
//ovrclient.OnShutdown += () => Console.WriteLine($"OpenVR Shutdown");
}
public static IEnumerable<Tracker> GetTrackers()
{
ovrClient.Update();
return ovrClient.Trackers.Where(x => x.IsConnected);
}
}*/
internal static class ADB
{
static public AdbClient client;
static public DeviceData device;
public static string deviceSerial;
public static string deviceModel;
public static string deviceName;
public static DeviceState deviceState;
public static bool isConnected;
public static bool wirelessConnection;
public static string headsetBattery = "N/A";
public static string rTouchBattery = "N/A";
public static string lTouchBattery = "N/A";
public static bool batteryFetched = false;
public static void StartADB()
{
if (!AdbServer.Instance.GetStatus().IsRunning)
{
AdbServer server = new AdbServer();
try
{
bool exists = Directory.Exists("platform-tools"); // ADB Auto donwloader
if (!exists)
{
MessageBox.Show("ADB directory does not exist, creating...\nDowloading ADB");
var client = new WebClient();
string uri = "https://dl.google.com/android/repository/platform-tools-latest-windows.zip";
string filename = "platform-tools-latest-windows.zip";
string extractPath = AppDomain.CurrentDomain.BaseDirectory;
client.DownloadFile(uri, filename);
ZipFile.ExtractToDirectory(filename, extractPath);
File.Delete(filename);
MessageBox.Show("Download completed");
}
StartServerResult result = server.StartServer(@"platform-tools\adb.exe", false);
if (result != StartServerResult.Started)
{
MessageBox.Show($"Can't start adb server, please restart app and try again {result}");
}
}
catch (WebException wExc)
{
MessageBox.Show($"Unable to download ADB from Google servers, try again or download files manually https://developer.android.com/studio/releases/platform-tools, press any key to exit\n{wExc.Message}");
}
}
else
{
MessageBox.Show("ADB server is already running, no checks are required");
}
client = new AdbClient();
while (!isConnected)
{
client.Connect("127.0.0.1:62001");
var devices = client.GetDevices();
if (devices.Count() == 0)
{
var fileName = $"deviceIp.txt";
if (File.Exists(fileName))
{
//192.168.2.102
var diviceIp = File.ReadAllText(fileName);
if (diviceIp.Split('.').Count() == 4)
{
client.Connect($"{diviceIp}:5555");
devices = client.GetDevices();
}
}
else
MessageBox.Show("Please create deviceIp.txt id current program directory with headset local-IP");
}
device = devices.First();
if (device.Model == "Quest_2")
{
try
{
deviceSerial = device.Serial;
deviceModel = device.Model;
deviceName = device.Name;
deviceState = device.State;
if (device.Serial.Contains('.') && device.Serial.Split('.').Count() == 4)
wirelessConnection = true;
isConnected = true;
MessageBox.Show($"Successfully connected via {(wirelessConnection ? "Wi-Fi" : "Usb")} to {deviceModel} ({deviceName}) [{deviceSerial}] state: {deviceState}");
}
catch (AdbException adbExc)
{
MessageBox.Show($"Error connecting to headset {adbExc.Message}\nTrying again in 3 seconds...");
Thread.Sleep(3000);
}
}
}
Thread batteryUpdater = new Thread(() =>
{
int Hbatlevelint = 0;
int Rbatlevelint = 0;
int Lbatlevelint = 0;
while (true)
{
try
{
ConsoleOutputReceiver Hbat_receiver = new ConsoleOutputReceiver();
ADB.client.ExecuteRemoteCommand("dumpsys CompanionService | grep Battery", ADB.device, Hbat_receiver);
ConsoleOutputReceiver Lbat_receiver = new ConsoleOutputReceiver();
ADB.client.ExecuteRemoteCommand("dumpsys OVRRemoteService | grep Left", ADB.device, Lbat_receiver);
ConsoleOutputReceiver Rbat_receiver = new ConsoleOutputReceiver();
ADB.client.ExecuteRemoteCommand("dumpsys OVRRemoteService | grep Right", ADB.device, Rbat_receiver);
var Hbat_match = Regex.Match(Hbat_receiver.ToString(), @"\d+", RegexOptions.RightToLeft);
var Lbat_match = Regex.Match(Lbat_receiver.ToString(), @"\d+", RegexOptions.RightToLeft);
var Rbat_match = Regex.Match(Rbat_receiver.ToString(), @"\d+", RegexOptions.RightToLeft);
try
{
Hbatlevelint = int.Parse(Hbat_match.Value);
Lbatlevelint = int.Parse(Lbat_match.Value);
Rbatlevelint = int.Parse(Rbat_match.Value);
headsetBattery = Hbatlevelint.ToString() + "%";
lTouchBattery = Lbatlevelint.ToString() + "%";
rTouchBattery = Rbatlevelint.ToString() + "%";
}
catch
{
headsetBattery = Hbat_match.Value;
lTouchBattery = Lbat_match.Value;
rTouchBattery = Rbat_match.Value;
}
batteryFetched = true;
Thread.Sleep(3000);
}
catch (AdbException)
{
headsetBattery = lTouchBattery = rTouchBattery = "N/A";
batteryFetched = false;
Thread.Sleep(3000);
}
}
});
batteryUpdater.IsBackground = true;
batteryUpdater.Start();
}
}
}