Skip to content

Commit 4869f4a

Browse files
committed
fix(android): handle devices connected over tcp/ip
fixes #30
1 parent 70fc283 commit 4869f4a

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

src/android/utils/__tests__/adb.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ emulator-5554 device product:sdk_gphone_x86 model:Android_SDK_built_for
2222
serial: 'emulator-5554',
2323
state: 'device',
2424
type: 'emulator',
25+
connection: null,
2526
manufacturer: '',
2627
model: 'Android_SDK_built_for_x86',
2728
product: '',
@@ -47,6 +48,7 @@ LGUS996e5ef677 device usb:341835776X product:elsa_nao_us model:LG_US996
4748
serial: 'LGUS996e5ef677',
4849
state: 'device',
4950
type: 'hardware',
51+
connection: 'usb',
5052
manufacturer: '',
5153
model: 'LG_US996',
5254
product: '',
@@ -73,6 +75,7 @@ List of devices attached
7375
serial: '0a388e93',
7476
state: 'device',
7577
type: 'hardware',
78+
connection: 'usb',
7679
manufacturer: '',
7780
model: 'Nexus_7',
7881
product: '',
@@ -87,6 +90,32 @@ List of devices attached
8790
]);
8891
});
8992

93+
it('should parse hardware device over tcpip ()', async () => {
94+
const output = `
95+
List of devices attached
96+
192.168.0.3:5555 device product:mido model:Redmi_Note_4 device:mido transport_id:1\n\n`;
97+
const devices = adbUtils.parseAdbDevices(output);
98+
99+
expect(devices).toEqual([
100+
{
101+
serial: '192.168.0.3:5555',
102+
state: 'device',
103+
type: 'hardware',
104+
connection: 'tcpip',
105+
manufacturer: '',
106+
model: 'Redmi_Note_4',
107+
product: '',
108+
sdkVersion: '',
109+
properties: {
110+
device: 'mido',
111+
product: 'mido',
112+
model: 'Redmi_Note_4',
113+
transport_id: '1',
114+
},
115+
},
116+
]);
117+
});
118+
90119
describe('windows', () => {
91120

92121
let adbUtils: typeof import('../adb');
@@ -107,6 +136,7 @@ List of devices attached
107136
serial: 'MWS0216B24001482',
108137
state: 'offline',
109138
type: 'emulator',
139+
connection: null,
110140
manufacturer: '',
111141
model: '',
112142
product: '',

src/android/utils/adb.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export interface Device extends MappedDeviceProps {
3232
serial: string;
3333
state: string; // 'offline' | 'device' | 'no device'
3434
type: 'emulator' | 'hardware';
35+
connection: 'usb' | 'tcpip' | null;
3536
properties: DeviceProperties;
3637
}
3738

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

261+
debug('Parsing adb devices from output lines: %O', lines);
262+
259263
const devices: Device[] = [];
260264

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

283+
const isIP = !!serial.match(ipRe);
284+
const type = 'usb' in properties || isIP ? 'hardware' : 'emulator';
285+
const connection = 'usb' in properties ? 'usb' : isIP ? 'tcpip' : null;
286+
279287
devices.push({
280288
serial,
281289
state,
282-
type: 'usb' in properties ? 'hardware' : 'emulator',
290+
type,
291+
connection,
283292
properties,
284293
// We might not know these yet
285294
manufacturer: '',

0 commit comments

Comments
 (0)