Fix adb related warnings

Summary: Fix lint warnings

Reviewed By: passy

Differential Revision: D30929702

fbshipit-source-id: 8763783a7faf978f81087258fb6ef345d9abdbe4
This commit is contained in:
Wenhuan Li
2021-09-14 07:36:25 -07:00
committed by Facebook GitHub Bot
parent b0310f4528
commit 384fd5ab1d
5 changed files with 65 additions and 68 deletions

View File

@@ -130,7 +130,9 @@ export default class AndroidDevice extends BaseDevice {
return Buffer.from([]);
}
return new Promise((resolve, reject) => {
this.adb.screencap(this.serial).then((stream) => {
this.adb
.screencap(this.serial)
.then((stream) => {
const chunks: Array<Buffer> = [];
stream
.on('data', (chunk: Buffer) => chunks.push(chunk))
@@ -138,6 +140,9 @@ export default class AndroidDevice extends BaseDevice {
resolve(Buffer.concat(chunks));
})
.once('error', reject);
})
.catch((e) => {
reject(e);
});
});
}
@@ -224,14 +229,16 @@ export default class AndroidDevice extends BaseDevice {
})
.then(
(_) =>
new Promise((resolve, reject) => {
this.adb.pull(this.serial, recordingLocation).then((stream) => {
new Promise(async (resolve, reject) => {
const stream: PullTransfer = await this.adb.pull(
this.serial,
recordingLocation,
);
stream.on('end', resolve as () => void);
stream.on('error', reject);
stream.pipe(createWriteStream(destination, {autoClose: true}), {
end: true,
});
});
}),
)
.then((_) => destination);

View File

@@ -31,15 +31,17 @@ export function getAdbClient(config: Config): Promise<Client> {
/* 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(config: Config): Promise<Client> {
async function createClient(config: Config): Promise<Client> {
const androidHome = config.androidHome;
const adbPath = path.resolve(androidHome, 'platform-tools/adb');
try {
return reportPlatformFailures<Client>(
execFile(adbPath, ['start-server']).then(() =>
adbkit.createClient(adbConfig()),
),
'createADBClient.shell',
).catch((err) => {
);
} catch (err) {
console.log(
'Failed to create adb client using shell adb command. Trying with adbkit.\n' +
err.toString(),
@@ -48,23 +50,19 @@ function createClient(config: Config): Promise<Client> {
/* In the event that starting adb with the above method fails, fallback
to using adbkit, though its known to be unreliable. */
const unsafeClient: Client = adbkit.createClient(adbConfig());
return reportPlatformFailures<Client>(
return await reportPlatformFailures<Client>(
promiseRetry<Client>(
(retry, attempt): Promise<Client> => {
return unsafeClient
.listDevices()
.then(() => {
async (retry, attempt): Promise<Client> => {
try {
await unsafeClient.listDevices();
return unsafeClient;
})
.catch((e: Error) => {
console.warn(
`Failed to start adb client. Retrying. ${e.message}`,
);
} catch (e) {
console.warn(`Failed to start adb client. Retrying. ${e.message}`);
if (attempt <= MAX_RETRIES) {
retry(e);
}
throw e;
});
}
},
{
minTimeout: 200,
@@ -73,5 +71,5 @@ function createClient(config: Config): Promise<Client> {
),
'createADBClient.adbkit',
);
});
}
}

View File

@@ -16,31 +16,26 @@ import {
} from './androidContainerUtilityInternal';
import {Client} from 'adbkit';
export function push(
export async function push(
client: Client,
deviceId: string,
app: string,
filepath: string,
contents: string,
): Promise<void> {
return validateAppName(app).then((validApp) =>
validateFilePath(filepath).then((validFilepath) =>
validateFileContent(contents).then((validContent) =>
_push(client, deviceId, validApp, validFilepath, validContent),
),
),
);
const validApp = await validateAppName(app);
const validFilepath = await validateFilePath(filepath);
const validContent = await validateFileContent(contents);
return await _push(client, deviceId, validApp, validFilepath, validContent);
}
export function pull(
export async function pull(
client: Client,
deviceId: string,
app: string,
path: string,
): Promise<string> {
return validateAppName(app).then((validApp) =>
validateFilePath(path).then((validPath) =>
_pull(client, deviceId, validApp, validPath),
),
);
const validApp = await validateAppName(app);
const validPath = await validateFilePath(path);
return await _pull(client, deviceId, validApp, validPath);
}

View File

@@ -78,12 +78,8 @@ export function _push(
.catch((error) => {
if (error instanceof RunAsError) {
// Fall back to running the command directly. This will work if adb is running as root.
return executeCommandWithSu(client, deviceId, app, command)
.then((_) => undefined)
.catch((e) => {
console.debug(e);
throw error;
});
executeCommandWithSu(client, deviceId, app, command, error);
return undefined;
}
throw error;
});
@@ -99,11 +95,7 @@ export function _pull(
return executeCommandAsApp(client, deviceId, app, command).catch((error) => {
if (error instanceof RunAsError) {
// Fall back to running the command directly. This will work if adb is running as root.
return executeCommandWithSu(client, deviceId, app, command).catch((e) => {
// Throw the original error.
console.debug(e);
throw error;
});
return executeCommandWithSu(client, deviceId, app, command, error);
}
throw error;
});
@@ -125,13 +117,19 @@ function executeCommandAsApp(
);
}
function executeCommandWithSu(
async function executeCommandWithSu(
client: Client,
deviceId: string,
app: string,
command: string,
originalErrorToThrow: RunAsError,
): Promise<string> {
try {
return _executeCommandWithRunner(client, deviceId, app, command, 'su');
} catch (e) {
console.debug(e);
throw originalErrorToThrow;
}
}
function _executeCommandWithRunner(

View File

@@ -17,7 +17,6 @@ import {FlipperServer} from '../../../FlipperServer';
const mockStore = configureStore<State, {}>([])(
createRootReducer()(undefined, {type: 'INIT'}),
);
const logger = getInstance();
const standardCoresimulatorLog =
'username 1264 0.0 0.1 5989740 41648 ?? Ss 2:23PM 0:12.92 /Applications/Xcode_12.4.0_fb.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/libexec/mobileassetd';