-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathadbhelper.js
110 lines (71 loc) · 3.22 KB
/
adbhelper.js
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
const GLib = imports.gi.GLib;
function findDevices() {
let [res, out, error] = GLib.spawn_sync(null, ["bash", "-c", "adb devices -l | awk 'NR>1 {print $1}'"], null, GLib.SpawnFlags.SEARCH_PATH, null, null);
if(!isEmpty(error.toString())) {
return {error: error.toString()};
}
if(!isEmpty(out.toString())) {
let devices = [];
let array = out.toString().split('\n');
for(var i = 0;i < array.length; i++) {
let deviceId = array[i];
if(!isEmpty(deviceId)) {
devices.push(getDeviceDetail(deviceId));
}
}
return {
devices : devices
}
} else {
return {error: "No devices found"}
}
}
function getDeviceDetail(deviceId) {
let [res, out, error] = GLib.spawn_sync(null, ["bash", "-c", "adb -s "+ deviceId +" shell getprop ro.product.model"], null, GLib.SpawnFlags.SEARCH_PATH, null, null);
let device;
if(!isEmpty(error.toString())) {
return;
}
if(!isEmpty(out.toString())) {
device = {deviceId: deviceId, name : out.toString()}
return device;
}
}
//start adb daemon on init
function startDaemon() {
GLib.spawn_async(null, ["bash", "-c", "adb devices"], null, GLib.SpawnFlags.SEARCH_PATH, null, null);
}
function takeScreenshot(deviceId) {
//current time
let time = '$(date +%Y-%m-%d-%H:%M)'
GLib.spawn_async(null, ["bash", "-c", "adb -s "+ deviceId +" shell screencap -p | sed 's/\r$//' > ~/Desktop/screen"+ time +".png"], null, GLib.SpawnFlags.SEARCH_PATH, null, null);
}
function recordScreen(deviceId) {
let time = '$(date +%Y-%m-%d-%H:%M)'
GLib.spawn_async(null, ["bash", "-c", "adb -s "+ deviceId +" shell screenrecord /sdcard/screenrecord.mp4"], null, GLib.SpawnFlags.SEARCH_PATH, null, null);
}
function stopScreenRecording(deviceId, pid) {
let time = '$(date +%Y-%m-%d-%H:%M)'
GLib.spawn_sync(null, ["bash", "-c", "adb -s "+ deviceId +" shell pkill -INT screenrecord"], null, GLib.SpawnFlags.SEARCH_PATH, null, null);
GLib.spawn_sync(null, ["bash", "-c", "adb -s "+ deviceId +" pull /sdcard/screenrecord.mp4 ~/Desktop/record"+ time +".mp4"], null, GLib.SpawnFlags.SEARCH_PATH, null, null);
}
function establishTCPConnection(deviceId) {
let deviceIp = getDeviceIp(deviceId);
GLib.spawn_sync(null, ["bash", "-c", "adb -s "+ deviceId + " tcpip 5555"], null, GLib.SpawnFlags.SEARCH_PATH, null, null);
let [res, out, error] = GLib.spawn_sync(null, ["bash", "-c", "adb -s "+ deviceId + " connect " + deviceIp+":5555"], null, GLib.SpawnFlags.SEARCH_PATH, null, null);
return out.toString().trim();
}
function useUsb() {
let [res, out, error] = GLib.spawn_async(null, ["bash", "-c", "adb usb"], null, GLib.SpawnFlags.SEARCH_PATH, null, null);
}
function captureBugReport(deviceId) {
let time = '$(date +%Y-%m-%d-%H:%M)'
let [res, out, error] = GLib.spawn_async(null, ["bash", "-c", "adb -s "+ deviceId +" bugreport > ~/Desktop/bugreport"+ time +".txt"], null, GLib.SpawnFlags.SEARCH_PATH, null, null);
}
function getDeviceIp(deviceId) {
let [res, out, error] = GLib.spawn_sync(null, ["bash", "-c", "adb -s "+ deviceId +" shell ip route | awk '{print $9}'"], null, GLib.SpawnFlags.SEARCH_PATH, null, null);
return out.toString().trim();
}
function isEmpty(str) {
return (!str || str.length === 0 || !str.trim());
}