Start by importing Client
.
import { Client } from 'adb-ts';
const adb = new Client();
const statuses = await adb.map((device) => {
return device.batteryStatus();
});
In order to start adb server automatically adb
must be globally accessible or path to adb
binary must be specified.
import { Client } from 'adb-ts';
const adb = new Client({ bin: '/path/to/adb' });
// ...
For operations on all connected device map
method can be used.
In the callback an instance of Device
comes as input parameter.
const packages = await Promise.all(
adb.map(async (device) => {
await device.uninstall('con.example.app');
await device.install('/path/to/app.apk', { test: true });
return device.listPackages();
})
);
console.log(packages);
Part of this module is also a Logcat
client...
const logcat = await adb.openLogcat('serial', {
filter: (entry) => entry.message.includes('test')
});
logcat.on('entry', (entry) => {
console.log(entry);
});
// logcat.end();
and Monkey
client.
const monkey = await adb.openMonkey('serial');
monkey.getBuildBoard((err, value) => {
console.log('getBuildBoard', err, value);
});
// monkey.end();
In addition to map
method, there is tracking function via Tracker
.
const tracker = await adb.trackDevices();
tracker.on('add', (device) => {
console.log('add', device);
});
tracker.on('remove', (device) => {
console.log('remove', device);
});
tracker.on('change', (device) => {
console.log('change', device);
});
// tracker.end();
Every Client
method has an overload with callback parameter.
const devices = await adb.listDevices();
console.log(devices);
adb.listDevices((devices) => {
console.log(devices);
});
time
option in touch
method is converted to UTC time.change
event emits the same instance of the device instead of creating a new device object every time.install
and uninstall
commands will fail if any other response than Success
is received. Until V5 the promise could have resolved even when the operation was not successful.exec
methods accept string[]
as an argument. Fix for https://github.com/Maaaartin/adb-ts/issues/13.
PropertyMap
values do not contain Date
type. This is because parsing date is tricky https://github.com/Maaaartin/adb-ts/issues/15.
listFeatures
types are determined from getprop -T
command. Types returned from this method are number | boolean | string
.