Skip to content

Commit d6cb68f

Browse files
committed
GitHub migration
1 parent bc76abc commit d6cb68f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+4052
-3
lines changed

.babelrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["react", "es2015"],
3+
}

.editorconfig

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
root = true
2+
3+
[*]
4+
indent_style = tab
5+
end_of_line = lf
6+
charset = utf-8
7+
trim_trailing_whitespace = true
8+
insert_final_newline = true
9+
10+
[{package.json,*.yml}]
11+
indent_style = space
12+
indent_size = 2
13+
14+
[*.md]
15+
trim_trailing_whitespace = false

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
node_modules
2+
/dist
3+
*.swp
4+
app.js
5+
/out
6+
.DS_Store

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright {yyyy} {name of copyright owner}
189+
Copyright 2017 neXenio GmbH
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

README.md

100644100755
+51-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,51 @@
1-
# adb-util
2-
ADB Util
1+
# ADB Utility
2+
3+
An [Electron] application for Android developers, providing a GUI for common [ADB] operations.
4+
5+
![screenshot]
6+
7+
The tool offers some convenience utilities to speed up the development, including:
8+
9+
- [x] Listing connected devices (`adb devices`)
10+
- [ ] Discovering network devices with the ADB deamon (`nmap -p 5555`)
11+
- [ ] Connecting and disconnecting devices (`adb connect`, ...)
12+
- [ ] Toggling connections between USB and TCP (`adb usb`, ...)
13+
- [x] Executing shell commands (`adb shell`)
14+
- [x] Fetching features (`pm list features`)
15+
- [x] Fetching properties (`getprop`)
16+
- [x] Fetching settings (`settings get`)
17+
- [x] Fetching network configuration (`ip addr show wlan0`)
18+
- [ ] Starting and stopping applications (`am start`, ...)
19+
- [ ] Clearing application data (`pm clear`)
20+
- [ ] Grabbing screenshots (`screencap`)
21+
- [ ] Installing and uninstalling applications (`adb install`, ...)
22+
- [ ] Pushing and pulling files and folders
23+
- [ ] Viewing Logcat output (`adb logcat`)
24+
25+
## Requirements
26+
27+
Make sure that `adb` is available in your `PATH`. You can check if that's the case by opening a terminal and executing `adb version`.
28+
29+
## Development
30+
31+
#### Deploying
32+
```sh
33+
$ npm install # install dependencies
34+
$ npm start # support for reloading views, restarting electron
35+
```
36+
37+
#### Building Releases
38+
39+
```sh
40+
$ npm run build # all
41+
$ npm run build-osx # osx(64)
42+
$ npm run build-win # win(32, 64)
43+
```
44+
45+
## License
46+
47+
[Apache License V2](LICENSE.md)
48+
49+
[electron]: https://electron.atom.io/
50+
[adb]: https://developer.android.com/studio/command-line/adb.html
51+
[screenshot]: assets/screenshot.png

adb/adbkit-wrapper.js

+158
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
'use strict';
2+
3+
const log = require('electron-log');
4+
const Promise = require('bluebird');
5+
const adb = require('adbkit');
6+
const client = adb.createClient();
7+
const toTitleCase = require('titlecase')
8+
9+
const ipcMain = require('electron').ipcMain;
10+
11+
ipcMain.on('adbkit-observe-devices', function(event, arg) {
12+
observeDevices(event, arg);
13+
});
14+
15+
function observeDevices(event, arg) {
16+
log.debug(`Starting to observe device state changes`);
17+
client.trackDevices()
18+
.then(function(tracker) {
19+
tracker.on('add', function(device) {
20+
event.sender.send('adbkit-device-added', device);
21+
});
22+
tracker.on('remove', function(device) {
23+
event.sender.send('adbkit-device-removed', device);
24+
});
25+
tracker.on('end', function() {
26+
log.debug(`Device state observation stopped`);
27+
});
28+
})
29+
.catch(function(err) {
30+
log.warn('Unable to observe devices:', err.stack)
31+
});
32+
}
33+
34+
ipcMain.on('adbkit-update-devices', function(event, arg) {
35+
updateDevices(event, arg);
36+
});
37+
38+
function updateDevices(event, arg) {
39+
log.debug(`Updating device list`);
40+
client.listDevicesWithPaths()
41+
.then(function(devices) {
42+
event.sender.send('adbkit-devices-updated', devices);
43+
})
44+
.catch(function(err) {
45+
log.warn('Unable to get devices:', err.stack)
46+
event.sender.send('adbkit-devices-updated', []);
47+
});
48+
}
49+
50+
ipcMain.on('adbkit-update-device', function(event, device) {
51+
updateDeviceFeatures(event, device);
52+
updateDeviceIpAddress(event, device);
53+
updateDeviceId(event, device);
54+
updateDeviceName(event, device);
55+
updateDeviceManufacturer(event, device);
56+
updateDeviceModel(event, device);
57+
});
58+
59+
function updateDeviceFeatures(event, device) {
60+
log.debug(`Updating features of device: ${device.id}`);
61+
client.getFeatures(device.id)
62+
.then(function(features) {
63+
device.features = features;
64+
event.sender.send('adbkit-device-features-updated', device);
65+
})
66+
.catch(function(err) {
67+
log.warn('Unable to get device features:', err.stack)
68+
});
69+
}
70+
71+
function updateDeviceIpAddress(event, device) {
72+
log.debug(`Updating IP address of device: ${device.id}`);
73+
runShellCommand(device, 'ip addr show wlan0 | grep \'inet \' | cut -d\' \' -f6|cut -d/ -f1')
74+
.then((output) => {
75+
device.ipAddress = output;
76+
event.sender.send('adbkit-device-updated', device);
77+
})
78+
.catch((err) => {
79+
log.warn('Unable to get device IP address:', err.stack)
80+
});
81+
}
82+
83+
function updateDeviceId(event, device) {
84+
log.debug(`Updating Android ID of device: ${device.id}`);
85+
runShellCommand(device, createGetSettingCommand('secure', 'android_id'))
86+
.then((output) => {
87+
device.androidId = output;
88+
event.sender.send('adbkit-device-updated', device);
89+
})
90+
.catch((err) => {
91+
log.warn('Unable to get device ID:', err.stack)
92+
});
93+
}
94+
95+
function updateDeviceName(event, device) {
96+
log.debug(`Updating name of device: ${device.id}`);
97+
runShellCommand(device, createGetSettingCommand('secure', 'bluetooth_name'))
98+
.then((output) => {
99+
device.bluetoothName = output;
100+
event.sender.send('adbkit-device-updated', device);
101+
})
102+
.catch((err) => {
103+
log.warn('Unable to get device name:', err.stack)
104+
});
105+
}
106+
107+
function updateDeviceManufacturer(event, device) {
108+
log.debug(`Updating manufacturer of device: ${device.id}`);
109+
runShellCommand(device, createGetPropCommand('ro.product.manufacturer'))
110+
.then((output) => {
111+
device.manufacturer = toTitleCase(output.toLowerCase());
112+
event.sender.send('adbkit-device-updated', device);
113+
})
114+
.catch((err) => {
115+
log.warn('Unable to get device name:', err.stack)
116+
});
117+
}
118+
119+
function updateDeviceModel(event, device) {
120+
log.debug(`Updating model of device: ${device.id}`);
121+
runShellCommand(device, createGetPropCommand('ro.product.model'))
122+
.then((output) => {
123+
device.model = toTitleCase(output.toLowerCase());
124+
event.sender.send('adbkit-device-updated', device);
125+
})
126+
.catch((err) => {
127+
log.warn('Unable to get device model:', err.stack)
128+
});
129+
}
130+
131+
function runShellCommand(device, command) {
132+
log.debug(`Executing shell command on ${device.id}: ${command}`);
133+
return new Promise((resolve, reject) => {
134+
client.shell(device.id, command)
135+
.then(function(outputStream) {
136+
adb.util.readAll(outputStream)
137+
.then(function(outputBuffer) {
138+
let output = outputBuffer.toString('utf-8');
139+
// remove linebreaks from start and end
140+
output = output.replace(/^\s+|\s+$/g, '');
141+
resolve(output);
142+
});
143+
})
144+
.catch(reject);
145+
});
146+
}
147+
148+
function createGetPropCommand(propertyId) {
149+
return `getprop | grep "${propertyId}" | cut -d ":" -f2 | cut -d "[" -f2 | cut -d "]" -f1`;
150+
}
151+
152+
function createGetSettingCommand(namespace, settingId) {
153+
return `settings get ${namespace} "${settingId}"`;
154+
}
155+
156+
module.exports = {
157+
updateDevices: updateDevices
158+
};

adb/device-manager.js

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
'use strict';
2+
3+
const electron = require('electron');
4+
const ipcRenderer = electron.ipcRenderer;
5+
const log = require('electron-log');
6+
const actions = require('../app/actions');
7+
const {Device} = require('./device');
8+
9+
let instance = null;
10+
11+
export class DeviceManager {
12+
13+
constructor(dispatch) {
14+
if (!instance){
15+
this.deviceMap = new Map();
16+
this.adbKitListenersRegistered = false;
17+
instance = this;
18+
}
19+
instance.dispatch = dispatch;
20+
21+
if (!instance.adbKitListenersRegistered) {
22+
instance.registerAdbKitListeners();
23+
}
24+
return instance;
25+
}
26+
27+
registerAdbKitListeners() {
28+
log.debug("Registering ADB Kit IPC listeners");
29+
30+
ipcRenderer.on('adbkit-device-added', (event, device) => {
31+
this.onDeviceAdded(device);
32+
});
33+
34+
ipcRenderer.on('adbkit-device-removed', (event, device) => {
35+
this.onDeviceRemoved(device);
36+
});
37+
38+
ipcRenderer.on('adbkit-device-updated', (event, device) => {
39+
this.onDeviceUpdated(device);
40+
});
41+
42+
ipcRenderer.on('adbkit-devices-updated', (event, devices) => {
43+
devices.forEach((device) => this.onDeviceUpdated(device));
44+
});
45+
46+
ipcRenderer.on('adbkit-device-features-updated', (event, device) => {
47+
this.onDeviceFeaturesUpdated(device);
48+
});
49+
50+
// tell the adbkit that we care about device updates
51+
ipcRenderer.send('adbkit-observe-devices');
52+
ipcRenderer.send('adbkit-update-devices');
53+
54+
this.adbKitListenersRegistered = true;
55+
}
56+
57+
getDevice(adbKitDevice) {
58+
let device = this.deviceMap.get(adbKitDevice.id);
59+
if (!device) {
60+
device = Device.fromAdbKitDevice(adbKitDevice);
61+
this.deviceMap.set(adbKitDevice.id, device);
62+
}
63+
return device;
64+
}
65+
66+
onDeviceAdded(adbKitDevice) {
67+
let device = this.getDevice(adbKitDevice);
68+
Object.assign(device, adbKitDevice);
69+
device.onConnect();
70+
log.debug('Device added: ' + device.id);
71+
this.dispatch(actions.deviceAdded(device));
72+
//ipcRenderer.send('adbkit-update-device-features', device);
73+
ipcRenderer.send('adbkit-update-device', device);
74+
}
75+
76+
onDeviceRemoved(adbKitDevice) {
77+
let device = this.getDevice(adbKitDevice);
78+
Object.assign(device, adbKitDevice);
79+
device.onDisconnect();
80+
log.debug('Device removed: ' + device.id);
81+
this.dispatch(actions.deviceRemoved(device));
82+
}
83+
84+
onDeviceUpdated(adbKitDevice) {
85+
let device = this.getDevice(adbKitDevice);
86+
Object.assign(device, adbKitDevice);
87+
device.onPropertiesUpdated();
88+
log.debug('Device updated: ' + device.id);
89+
this.dispatch(actions.deviceUpdated(device));
90+
}
91+
92+
onDeviceFeaturesUpdated(adbKitDevice) {
93+
let device = this.getDevice(adbKitDevice);
94+
Object.assign(device, adbKitDevice);
95+
device.onFeaturesUpdated(device.features);
96+
device.onPropertiesUpdated();
97+
log.debug('Device features updated: ' + device.id);
98+
this.dispatch(actions.deviceUpdated(device));
99+
}
100+
101+
}

0 commit comments

Comments
 (0)