Skip to content

Commit

Permalink
fix(cli): filter ADB trace logs from the device list
Browse files Browse the repository at this point in the history
  • Loading branch information
byCedric committed Mar 6, 2024
1 parent 94fb26c commit a21d2d3
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
Expand Up @@ -209,7 +209,40 @@ describe(getAttachedDevicesAsync, () => {
isAuthorized: true,
isBooted: true,
name: 'Pixel_4_XL_API_30',
pid: 'emulator-5554',
type: 'emulator',
},
]);
});

it(`gets devices when ADB_TRACE is set`, async () => {
jest
.mocked(getServer().runAsync)
.mockResolvedValueOnce(
[
'List of devices attached',
'adb D 03-06 15:25:53 63677 4018815 adb_client.cpp:393] adb_query: host:devices-l',
'adb D 03-06 15:25:53 63677 4018815 adb_client.cpp:351] adb_connect: service: host:devices-l',
'adb D 03-06 15:25:53 63677 4018815 adb_client.cpp:160] _adb_connect: host:devices-l',
'adb D 03-06 15:25:53 63677 4018815 adb_client.cpp:194] _adb_connect: return fd 3',
'adb D 03-06 15:25:53 63677 4018815 adb_client.cpp:369] adb_connect: return fd 3',
// Emulator
'emulator-5554 offline transport_id:1',
'',
].join('\n')
)
.mockResolvedValueOnce(
// Return the emulator name
['Pixel_4_XL_API_30', 'OK'].join('\n')
);

const devices = await getAttachedDevicesAsync();

expect(devices).toEqual([
{
isAuthorized: true,
isBooted: true,
name: 'Pixel_4_XL_API_30',
pid: 'emulator-5554',
type: 'emulator',
},
Expand Down
11 changes: 10 additions & 1 deletion packages/@expo/cli/src/start/platforms/android/adb.ts
Expand Up @@ -229,7 +229,16 @@ export function adbArgs(pid: Device['pid'], ...options: string[]): string[] {
export async function getAttachedDevicesAsync(): Promise<Device[]> {
const output = await getServer().runAsync(['devices', '-l']);

const splitItems = output.trim().replace(/\n$/, '').split(os.EOL);
const splitItems = output
.trim()
.replace(/\n$/, '')
.split(os.EOL)
// Filter ADB trace logs from the output, e.g.
// adb D 03-06 15:25:53 63677 4018815 adb_client.cpp:393] adb_query: host:devices-l
// 03-04 12:29:44.557 16415 16415 D adb : commandline.cpp:1646 Using server socket: tcp:172.27.192.1:5037
// 03-04 12:29:44.557 16415 16415 D adb : adb_client.cpp:160 _adb_connect: host:version
.filter((line) => !line.match(/\.cpp:[0-9]+/));

// First line is `"List of devices attached"`, remove it
// @ts-ignore: todo
const attachedDevices: {
Expand Down

0 comments on commit a21d2d3

Please sign in to comment.