Fix missing android devices bug
Summary: Finally tracked down this bug that's been annoying me. If you start flipper while the adb daemon is not running, then flipper will start the daemon, but it won't wait for it to have finished starting before telling the client to watch for devices. This is a race condition, and in practice never seems to work. To avoid this, I'm calling `adb devices` on the client and waiting for it to complete before doing anything else. This forces it to wait for the daemon to start up if it hasn't already, and if it has then it instantly returns. Reviewed By: passy Differential Revision: D13101963 fbshipit-source-id: b85bed24751ce5c8efdfc6e841400e4db2580ab0
This commit is contained in:
committed by
Facebook Github Bot
parent
ddbb3c7f89
commit
a6765deec6
@@ -54,7 +54,15 @@ function getRunningEmulatorName(id: string): Promise<?string> {
|
||||
}
|
||||
|
||||
export default (store: Store, logger: Logger) => {
|
||||
const client = adb.createClient();
|
||||
// Using this client before adb server is started up will cause failures.
|
||||
// safeClient gets around this by waiting for listDevices first, which ensures
|
||||
// the server is up and running.
|
||||
const unsafeClient = adb.createClient();
|
||||
|
||||
const safeClient = () =>
|
||||
new Promise((resolve, reject) => {
|
||||
resolve(unsafeClient.listDevices().then(() => unsafeClient));
|
||||
});
|
||||
|
||||
const watchAndroidDevices = () => {
|
||||
// get emulators
|
||||
@@ -73,6 +81,7 @@ export default (store: Store, logger: Logger) => {
|
||||
},
|
||||
);
|
||||
|
||||
safeClient().then(client => {
|
||||
client
|
||||
.trackDevices()
|
||||
.then(tracker => {
|
||||
@@ -80,7 +89,9 @@ export default (store: Store, logger: Logger) => {
|
||||
if (err.message === 'Connection closed') {
|
||||
// adb server has shutdown, remove all android devices
|
||||
const {connections} = store.getState();
|
||||
const deviceIDsToRemove: Array<string> = connections.devices
|
||||
const deviceIDsToRemove: Array<
|
||||
string,
|
||||
> = connections.devices
|
||||
.filter((device: BaseDevice) => device instanceof AndroidDevice)
|
||||
.map((device: BaseDevice) => device.serial);
|
||||
|
||||
@@ -134,6 +145,7 @@ export default (store: Store, logger: Logger) => {
|
||||
throw err;
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
watchAndroidDevices();
|
||||
|
||||
Reference in New Issue
Block a user