Back out "[flipper] Explicitly start adb server"

Summary:
Original commit changeset: b1eae542aaa6

 This D13487864 has broken `adb start-server` command for the production builds, thus this diff backs out the changes done by that diff.

Reviewed By: danielbuechele

Differential Revision: D13532003

fbshipit-source-id: 1d169dcdab11a52f075187803219915f444952d6
This commit is contained in:
Pritesh Nandgaonkar
2018-12-21 07:01:56 -08:00
committed by Facebook Github Bot
parent 9d4bb45dbc
commit 470c770e97
3 changed files with 43 additions and 14 deletions

View File

@@ -7,7 +7,7 @@
import AndroidDevice from '../devices/AndroidDevice';
import child_process from 'child_process';
import {promisify} from 'util';
import promiseRetry from 'promise-retry';
import type {Store} from '../reducers/index.js';
import type BaseDevice from '../devices/BaseDevice';
import type Logger from '../fb-stubs/Logger.js';
@@ -55,21 +55,31 @@ function getRunningEmulatorName(id: string): Promise<?string> {
}
export default (store: Store, logger: Logger) => {
// Adbkit will attempt to start the adb server if it's not already running,
// however, it sometimes fails with ENOENT errors. So instead, we start it
// manually before requesting a client.
// Using this client before adb server is started up will cause failures.
// this gets around this by waiting for listDevices first, which ensures
// the server is up and running before allowing any other operations.
function createClient() {
return promisify(child_process.exec)('adb start-server')
.then(result => {
if (result.error) {
throw new Error(
`Failed to start adb server: ${result.stderr.toString()}`,
);
}
})
.then(adb.createClient);
const unsafeClient = adb.createClient();
return promiseRetry(
(retry, number) => {
return unsafeClient
.listDevices()
.then(() => {
return unsafeClient;
})
.catch(e => {
console.warn(`Failed to start adb client. Retrying. ${e.message}`);
retry(e);
});
},
{
minTimeout: 200,
retries: 5,
},
);
}
const clientPromise = createClient();
const watchAndroidDevices = () => {
// get emulators
@@ -88,7 +98,7 @@ export default (store: Store, logger: Logger) => {
},
);
createClient()
clientPromise
.then(client => {
client
.trackDevices()