Fix adb related warnings
Summary: Fix lint warnings Reviewed By: passy Differential Revision: D30929702 fbshipit-source-id: 8763783a7faf978f81087258fb6ef345d9abdbe4
This commit is contained in:
committed by
Facebook GitHub Bot
parent
b0310f4528
commit
384fd5ab1d
@@ -130,7 +130,9 @@ export default class AndroidDevice extends BaseDevice {
|
|||||||
return Buffer.from([]);
|
return Buffer.from([]);
|
||||||
}
|
}
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.adb.screencap(this.serial).then((stream) => {
|
this.adb
|
||||||
|
.screencap(this.serial)
|
||||||
|
.then((stream) => {
|
||||||
const chunks: Array<Buffer> = [];
|
const chunks: Array<Buffer> = [];
|
||||||
stream
|
stream
|
||||||
.on('data', (chunk: Buffer) => chunks.push(chunk))
|
.on('data', (chunk: Buffer) => chunks.push(chunk))
|
||||||
@@ -138,6 +140,9 @@ export default class AndroidDevice extends BaseDevice {
|
|||||||
resolve(Buffer.concat(chunks));
|
resolve(Buffer.concat(chunks));
|
||||||
})
|
})
|
||||||
.once('error', reject);
|
.once('error', reject);
|
||||||
|
})
|
||||||
|
.catch((e) => {
|
||||||
|
reject(e);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -224,14 +229,16 @@ export default class AndroidDevice extends BaseDevice {
|
|||||||
})
|
})
|
||||||
.then(
|
.then(
|
||||||
(_) =>
|
(_) =>
|
||||||
new Promise((resolve, reject) => {
|
new Promise(async (resolve, reject) => {
|
||||||
this.adb.pull(this.serial, recordingLocation).then((stream) => {
|
const stream: PullTransfer = await this.adb.pull(
|
||||||
|
this.serial,
|
||||||
|
recordingLocation,
|
||||||
|
);
|
||||||
stream.on('end', resolve as () => void);
|
stream.on('end', resolve as () => void);
|
||||||
stream.on('error', reject);
|
stream.on('error', reject);
|
||||||
stream.pipe(createWriteStream(destination, {autoClose: true}), {
|
stream.pipe(createWriteStream(destination, {autoClose: true}), {
|
||||||
end: true,
|
end: true,
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.then((_) => destination);
|
.then((_) => destination);
|
||||||
|
|||||||
@@ -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,
|
/* 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
|
however, it sometimes fails with ENOENT errors. So instead, we start it
|
||||||
manually before requesting a client. */
|
manually before requesting a client. */
|
||||||
function createClient(config: Config): Promise<Client> {
|
async function createClient(config: Config): Promise<Client> {
|
||||||
const androidHome = config.androidHome;
|
const androidHome = config.androidHome;
|
||||||
const adbPath = path.resolve(androidHome, 'platform-tools/adb');
|
const adbPath = path.resolve(androidHome, 'platform-tools/adb');
|
||||||
|
try {
|
||||||
return reportPlatformFailures<Client>(
|
return reportPlatformFailures<Client>(
|
||||||
execFile(adbPath, ['start-server']).then(() =>
|
execFile(adbPath, ['start-server']).then(() =>
|
||||||
adbkit.createClient(adbConfig()),
|
adbkit.createClient(adbConfig()),
|
||||||
),
|
),
|
||||||
'createADBClient.shell',
|
'createADBClient.shell',
|
||||||
).catch((err) => {
|
);
|
||||||
|
} catch (err) {
|
||||||
console.log(
|
console.log(
|
||||||
'Failed to create adb client using shell adb command. Trying with adbkit.\n' +
|
'Failed to create adb client using shell adb command. Trying with adbkit.\n' +
|
||||||
err.toString(),
|
err.toString(),
|
||||||
@@ -48,23 +50,19 @@ function createClient(config: Config): Promise<Client> {
|
|||||||
/* In the event that starting adb with the above method fails, fallback
|
/* In the event that starting adb with the above method fails, fallback
|
||||||
to using adbkit, though its known to be unreliable. */
|
to using adbkit, though its known to be unreliable. */
|
||||||
const unsafeClient: Client = adbkit.createClient(adbConfig());
|
const unsafeClient: Client = adbkit.createClient(adbConfig());
|
||||||
return reportPlatformFailures<Client>(
|
return await reportPlatformFailures<Client>(
|
||||||
promiseRetry<Client>(
|
promiseRetry<Client>(
|
||||||
(retry, attempt): Promise<Client> => {
|
async (retry, attempt): Promise<Client> => {
|
||||||
return unsafeClient
|
try {
|
||||||
.listDevices()
|
await unsafeClient.listDevices();
|
||||||
.then(() => {
|
|
||||||
return unsafeClient;
|
return unsafeClient;
|
||||||
})
|
} catch (e) {
|
||||||
.catch((e: Error) => {
|
console.warn(`Failed to start adb client. Retrying. ${e.message}`);
|
||||||
console.warn(
|
|
||||||
`Failed to start adb client. Retrying. ${e.message}`,
|
|
||||||
);
|
|
||||||
if (attempt <= MAX_RETRIES) {
|
if (attempt <= MAX_RETRIES) {
|
||||||
retry(e);
|
retry(e);
|
||||||
}
|
}
|
||||||
throw e;
|
throw e;
|
||||||
});
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
minTimeout: 200,
|
minTimeout: 200,
|
||||||
@@ -73,5 +71,5 @@ function createClient(config: Config): Promise<Client> {
|
|||||||
),
|
),
|
||||||
'createADBClient.adbkit',
|
'createADBClient.adbkit',
|
||||||
);
|
);
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,31 +16,26 @@ import {
|
|||||||
} from './androidContainerUtilityInternal';
|
} from './androidContainerUtilityInternal';
|
||||||
import {Client} from 'adbkit';
|
import {Client} from 'adbkit';
|
||||||
|
|
||||||
export function push(
|
export async function push(
|
||||||
client: Client,
|
client: Client,
|
||||||
deviceId: string,
|
deviceId: string,
|
||||||
app: string,
|
app: string,
|
||||||
filepath: string,
|
filepath: string,
|
||||||
contents: string,
|
contents: string,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
return validateAppName(app).then((validApp) =>
|
const validApp = await validateAppName(app);
|
||||||
validateFilePath(filepath).then((validFilepath) =>
|
const validFilepath = await validateFilePath(filepath);
|
||||||
validateFileContent(contents).then((validContent) =>
|
const validContent = await validateFileContent(contents);
|
||||||
_push(client, deviceId, validApp, validFilepath, validContent),
|
return await _push(client, deviceId, validApp, validFilepath, validContent);
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function pull(
|
export async function pull(
|
||||||
client: Client,
|
client: Client,
|
||||||
deviceId: string,
|
deviceId: string,
|
||||||
app: string,
|
app: string,
|
||||||
path: string,
|
path: string,
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
return validateAppName(app).then((validApp) =>
|
const validApp = await validateAppName(app);
|
||||||
validateFilePath(path).then((validPath) =>
|
const validPath = await validateFilePath(path);
|
||||||
_pull(client, deviceId, validApp, validPath),
|
return await _pull(client, deviceId, validApp, validPath);
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,12 +78,8 @@ export function _push(
|
|||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
if (error instanceof RunAsError) {
|
if (error instanceof RunAsError) {
|
||||||
// Fall back to running the command directly. This will work if adb is running as root.
|
// Fall back to running the command directly. This will work if adb is running as root.
|
||||||
return executeCommandWithSu(client, deviceId, app, command)
|
executeCommandWithSu(client, deviceId, app, command, error);
|
||||||
.then((_) => undefined)
|
return undefined;
|
||||||
.catch((e) => {
|
|
||||||
console.debug(e);
|
|
||||||
throw error;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
throw error;
|
throw error;
|
||||||
});
|
});
|
||||||
@@ -99,11 +95,7 @@ export function _pull(
|
|||||||
return executeCommandAsApp(client, deviceId, app, command).catch((error) => {
|
return executeCommandAsApp(client, deviceId, app, command).catch((error) => {
|
||||||
if (error instanceof RunAsError) {
|
if (error instanceof RunAsError) {
|
||||||
// Fall back to running the command directly. This will work if adb is running as root.
|
// Fall back to running the command directly. This will work if adb is running as root.
|
||||||
return executeCommandWithSu(client, deviceId, app, command).catch((e) => {
|
return executeCommandWithSu(client, deviceId, app, command, error);
|
||||||
// Throw the original error.
|
|
||||||
console.debug(e);
|
|
||||||
throw error;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
throw error;
|
throw error;
|
||||||
});
|
});
|
||||||
@@ -125,13 +117,19 @@ function executeCommandAsApp(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function executeCommandWithSu(
|
async function executeCommandWithSu(
|
||||||
client: Client,
|
client: Client,
|
||||||
deviceId: string,
|
deviceId: string,
|
||||||
app: string,
|
app: string,
|
||||||
command: string,
|
command: string,
|
||||||
|
originalErrorToThrow: RunAsError,
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
|
try {
|
||||||
return _executeCommandWithRunner(client, deviceId, app, command, 'su');
|
return _executeCommandWithRunner(client, deviceId, app, command, 'su');
|
||||||
|
} catch (e) {
|
||||||
|
console.debug(e);
|
||||||
|
throw originalErrorToThrow;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function _executeCommandWithRunner(
|
function _executeCommandWithRunner(
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ import {FlipperServer} from '../../../FlipperServer';
|
|||||||
const mockStore = configureStore<State, {}>([])(
|
const mockStore = configureStore<State, {}>([])(
|
||||||
createRootReducer()(undefined, {type: 'INIT'}),
|
createRootReducer()(undefined, {type: 'INIT'}),
|
||||||
);
|
);
|
||||||
const logger = getInstance();
|
|
||||||
|
|
||||||
const standardCoresimulatorLog =
|
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';
|
'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';
|
||||||
|
|||||||
Reference in New Issue
Block a user