Skip to content

Commit

Permalink
fix(android): handle devices connected over tcp/ip
Browse files Browse the repository at this point in the history
fixes #30
  • Loading branch information
imhoffd committed May 31, 2019
1 parent 70fc283 commit 4869f4a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
30 changes: 30 additions & 0 deletions src/android/utils/__tests__/adb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ emulator-5554 device product:sdk_gphone_x86 model:Android_SDK_built_for
serial: 'emulator-5554',
state: 'device',
type: 'emulator',
connection: null,
manufacturer: '',
model: 'Android_SDK_built_for_x86',
product: '',
Expand All @@ -47,6 +48,7 @@ LGUS996e5ef677 device usb:341835776X product:elsa_nao_us model:LG_US996
serial: 'LGUS996e5ef677',
state: 'device',
type: 'hardware',
connection: 'usb',
manufacturer: '',
model: 'LG_US996',
product: '',
Expand All @@ -73,6 +75,7 @@ List of devices attached
serial: '0a388e93',
state: 'device',
type: 'hardware',
connection: 'usb',
manufacturer: '',
model: 'Nexus_7',
product: '',
Expand All @@ -87,6 +90,32 @@ List of devices attached
]);
});

it('should parse hardware device over tcpip ()', async () => {
const output = `
List of devices attached
192.168.0.3:5555 device product:mido model:Redmi_Note_4 device:mido transport_id:1\n\n`;
const devices = adbUtils.parseAdbDevices(output);

expect(devices).toEqual([
{
serial: '192.168.0.3:5555',
state: 'device',
type: 'hardware',
connection: 'tcpip',
manufacturer: '',
model: 'Redmi_Note_4',
product: '',
sdkVersion: '',
properties: {
device: 'mido',
product: 'mido',
model: 'Redmi_Note_4',
transport_id: '1',
},
},
]);
});

describe('windows', () => {

let adbUtils: typeof import('../adb');
Expand All @@ -107,6 +136,7 @@ List of devices attached
serial: 'MWS0216B24001482',
state: 'offline',
type: 'emulator',
connection: null,
manufacturer: '',
model: '',
product: '',
Expand Down
11 changes: 10 additions & 1 deletion src/android/utils/adb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export interface Device extends MappedDeviceProps {
serial: string;
state: string; // 'offline' | 'device' | 'no device'
type: 'emulator' | 'hardware';
connection: 'usb' | 'tcpip' | null;
properties: DeviceProperties;
}

Expand Down Expand Up @@ -254,8 +255,11 @@ export async function startActivity(sdk: SDK, device: Device, packageName: strin
export function parseAdbDevices(output: string): Device[] {
const debug = Debug(`${modulePrefix}:${parseAdbDevices.name}`);
const re = /^([\S]+)\s+([a-z\s]+)\s+(.*)$/;
const ipRe = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d+$/;
const lines = output.split(os.EOL);

debug('Parsing adb devices from output lines: %O', lines);

const devices: Device[] = [];

for (const line of lines) {
Expand All @@ -276,10 +280,15 @@ export function parseAdbDevices(output: string): Device[] {
return acc;
}, {} as { [key: string]: string; });

const isIP = !!serial.match(ipRe);
const type = 'usb' in properties || isIP ? 'hardware' : 'emulator';
const connection = 'usb' in properties ? 'usb' : isIP ? 'tcpip' : null;

devices.push({
serial,
state,
type: 'usb' in properties ? 'hardware' : 'emulator',
type,
connection,
properties,
// We might not know these yet
manufacturer: '',
Expand Down

0 comments on commit 4869f4a

Please sign in to comment.