Explicitly start adb server

Summary: We were relying on adbkit to do this, implicitly by calling listDevices(). However, this doesn't appear to be reliable, with retries, it usually succeeds, but sometimes still doesn't. I'm aiming to avoid all this entirely by just starting it directly using adb itself, which I expect to be much more reliable.

Reviewed By: danielbuechele

Differential Revision: D13487864

fbshipit-source-id: b1eae542aaa6ecb2b74b575a3582934093ccd588
This commit is contained in:
John Knox
2018-12-17 07:39:32 -08:00
committed by Facebook Github Bot
parent a1541b1c81
commit cc5fba6975
3 changed files with 14 additions and 43 deletions

View File

@@ -71,7 +71,6 @@
"lodash.debounce": "^4.0.8",
"mkdirp": "^0.5.1",
"openssl-wrapper": "^0.3.4",
"promise-retry": "^1.1.1",
"prop-types": "^15.6.0",
"react": "16",
"react-color": "^2.11.7",

View File

@@ -7,7 +7,7 @@
import AndroidDevice from '../devices/AndroidDevice';
import child_process from 'child_process';
import promiseRetry from 'promise-retry';
import {promisify} from 'util';
import type {Store} from '../reducers/index.js';
import type BaseDevice from '../devices/BaseDevice';
import type Logger from '../fb-stubs/Logger.js';
@@ -55,31 +55,21 @@ function getRunningEmulatorName(id: string): Promise<?string> {
}
export default (store: Store, logger: Logger) => {
// 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.
// 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.
function 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,
},
);
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 clientPromise = createClient();
const watchAndroidDevices = () => {
// get emulators
@@ -98,7 +88,7 @@ export default (store: Store, logger: Logger) => {
},
);
clientPromise
createClient()
.then(client => {
client
.trackDevices()

View File

@@ -2280,11 +2280,6 @@ env-paths@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/env-paths/-/env-paths-1.0.0.tgz#4168133b42bb05c38a35b1ae4397c8298ab369e0"
err-code@^1.0.0:
version "1.1.2"
resolved "https://registry.yarnpkg.com/err-code/-/err-code-1.1.2.tgz#06e0116d3028f6aef4806849eb0ea6a748ae6960"
integrity sha1-BuARbTAo9q70gGhJ6w6mp0iuaWA=
error-ex@^1.2.0:
version "1.3.1"
resolved "https://registry.yarnpkg.com/error-ex/-/error-ex-1.3.1.tgz#f855a86ce61adc4e8621c3cda21e7a7612c3a8dc"
@@ -5149,14 +5144,6 @@ progress@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/progress/-/progress-2.0.0.tgz#8a1be366bf8fc23db2bd23f10c6fe920b4389d1f"
promise-retry@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/promise-retry/-/promise-retry-1.1.1.tgz#6739e968e3051da20ce6497fb2b50f6911df3d6d"
integrity sha1-ZznpaOMFHaIM5kl/srUPaRHfPW0=
dependencies:
err-code "^1.0.0"
retry "^0.10.0"
promise@^7.1.1:
version "7.3.1"
resolved "https://registry.yarnpkg.com/promise/-/promise-7.3.1.tgz#064b72602b18f90f29192b8b1bc418ffd1ebd3bf"
@@ -5653,11 +5640,6 @@ ret@~0.1.10:
resolved "https://registry.yarnpkg.com/ret/-/ret-0.1.15.tgz#b8a4825d5bdb1fc3f6f53c2bc33f81388681c7bc"
integrity sha512-TTlYpa+OL+vMMNG24xSlQGEJ3B/RzEfUlLct7b5G/ytav+wPrplCpVMFuwzXbkecJrb6IYo1iFb0S9v37754mg==
retry@^0.10.0:
version "0.10.1"
resolved "https://registry.yarnpkg.com/retry/-/retry-0.10.1.tgz#e76388d217992c252750241d3d3956fed98d8ff4"
integrity sha1-52OI0heZLCUnUCQdPTlW/tmNj/Q=
rimraf@^2.2.8, rimraf@^2.5.2, rimraf@^2.5.4, rimraf@^2.6.1:
version "2.6.2"
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.6.2.tgz#2ed8150d24a16ea8651e6d6ef0f47c4158ce7a36"