Populate the initial list of connected devices on startup
Summary: When we start using Flipper from the CLI for automation, we want to have the list of currently connected devices as soon as flipper server is alive. Otherwise, we would have to poll flipper server waiting for some magical moment in the future when devices connect. This way, we can be certain that if flipper server started, but we do not see a device, it is not connected at all. Reviewed By: mweststrate Differential Revision: D40184106 fbshipit-source-id: ce4c2b897a2df0081e3a0b6a8c26640599e0f9e8
This commit is contained in:
committed by
Facebook GitHub Bot
parent
fbbd90e9f5
commit
b5a750935d
@@ -198,7 +198,7 @@ export class FlipperServerImpl implements FlipperServer {
|
||||
return;
|
||||
}
|
||||
this.android = new AndroidDeviceManager(this, adbClient);
|
||||
return this.android.watchAndroidDevices();
|
||||
return this.android.watchAndroidDevices(true);
|
||||
})
|
||||
.catch((e) => {
|
||||
console.error(
|
||||
@@ -588,6 +588,10 @@ export class FlipperServerImpl implements FlipperServer {
|
||||
return device;
|
||||
}
|
||||
|
||||
hasDevice(serial: string): boolean {
|
||||
return !!this.devices.get(serial);
|
||||
}
|
||||
|
||||
getDeviceSerials(): string[] {
|
||||
return Array.from(this.devices.keys());
|
||||
}
|
||||
|
||||
@@ -191,7 +191,24 @@ export class AndroidDeviceManager {
|
||||
});
|
||||
}
|
||||
|
||||
async watchAndroidDevices() {
|
||||
async watchAndroidDevices(initialRun = false) {
|
||||
if (initialRun) {
|
||||
try {
|
||||
const devices = await this.adbClient.listDevices();
|
||||
for (const device of devices) {
|
||||
if (device.type !== 'offline') {
|
||||
this.registerDevice(this.adbClient, device);
|
||||
} else {
|
||||
this.handleOfflineDevice(device);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn(
|
||||
`Failed to populate the initial list of android devices: ${e.message}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
this.adbClient
|
||||
.trackDevices()
|
||||
@@ -214,12 +231,17 @@ export class AndroidDeviceManager {
|
||||
});
|
||||
|
||||
tracker.on('add', async (device) => {
|
||||
// Check if we have already registered this device during the `initialRun`
|
||||
if (this.flipperServer.hasDevice(device.id)) {
|
||||
console.debug(
|
||||
`[conn] Trying to add an existing Android device ${device.id}. Skipping.`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (device.type !== 'offline') {
|
||||
this.registerDevice(this.adbClient, device);
|
||||
} else {
|
||||
console.warn(
|
||||
`[conn] Found device ${device.id}, but it has status offline. If this concerns an emulator and the problem persists, try these potential solutions: https://stackoverflow.com/a/21330228/1983583, https://stackoverflow.com/a/56053223/1983583`,
|
||||
);
|
||||
this.handleOfflineDevice(device);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -247,6 +269,12 @@ export class AndroidDeviceManager {
|
||||
}
|
||||
}
|
||||
|
||||
private handleOfflineDevice(device: Device): void {
|
||||
console.warn(
|
||||
`[conn] Found device ${device.id}, but it has status offline. If this concerns an emulator and the problem persists, try these potential solutions: https://stackoverflow.com/a/21330228/1983583, https://stackoverflow.com/a/56053223/1983583`,
|
||||
);
|
||||
}
|
||||
|
||||
private async registerDevice(adbClient: ADBClient, deviceData: Device) {
|
||||
const androidDevice = await this.createDevice(adbClient, deviceData);
|
||||
if (!androidDevice) {
|
||||
|
||||
@@ -149,7 +149,7 @@ export class IOSDeviceManager {
|
||||
isDetected,
|
||||
this.idbConfig.enablePhysicalIOS,
|
||||
);
|
||||
this.queryDevicesForever(bridge);
|
||||
await this.queryDevicesForever(bridge);
|
||||
} catch (err) {
|
||||
// This case is expected if both Xcode and idb are missing.
|
||||
if (err.message === ERR_NO_IDB_OR_XCODE_AVAILABLE) {
|
||||
|
||||
Reference in New Issue
Block a user