Refactor command execution fallback for both push and pull
Summary: D20920582 was unfortunately not enough to fix ability for Flipper to connect to packages that are running as services without an `<application>` tag in the manifest. The issue there is that the push of `sonarCA.crt` succeeded due to erroneous changes to the target package. This change ensures both pull and push are covered. Reviewed By: jknoxville Differential Revision: D21024673 fbshipit-source-id: cad86ba9ae3b02a99187d3f6bd3b500d2a4b971a
This commit is contained in:
committed by
Facebook GitHub Bot
parent
8c9de002bf
commit
f4b0898de5
@@ -72,12 +72,24 @@ export function _push(
|
|||||||
contents: FileContent,
|
contents: FileContent,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
console.debug(`Deploying ${filename} to ${deviceId}:${app}`, logTag);
|
console.debug(`Deploying ${filename} to ${deviceId}:${app}`, logTag);
|
||||||
return executeCommandAsApp(
|
const command = `echo "${contents}" > '${filename}' && chmod 644 '${filename}'`;
|
||||||
client,
|
return executeCommandAsApp(client, deviceId, app, command)
|
||||||
deviceId,
|
.then((_) => undefined)
|
||||||
app,
|
.catch((error) => {
|
||||||
`echo "${contents}" > '${filename}' && chmod 644 '${filename}'`,
|
if (
|
||||||
).then((_) => undefined);
|
error instanceof RunAsError &&
|
||||||
|
error.code == RunAsErrorCode.NotAnApp
|
||||||
|
) {
|
||||||
|
// 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;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
throw error;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function _pull(
|
export function _pull(
|
||||||
@@ -86,24 +98,18 @@ export function _pull(
|
|||||||
app: AppName,
|
app: AppName,
|
||||||
path: FilePath,
|
path: FilePath,
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
return executeCommandAsApp(client, deviceId, app, `cat '${path}'`).catch(
|
const command = `cat '${path}'`;
|
||||||
(error) => {
|
return executeCommandAsApp(client, deviceId, app, command).catch((error) => {
|
||||||
if (
|
if (error instanceof RunAsError && error.code == RunAsErrorCode.NotAnApp) {
|
||||||
error instanceof RunAsError &&
|
// Fall back to running the command directly. This will work if adb is running as root.
|
||||||
error.code == RunAsErrorCode.NotAnApp
|
return executeCommandWithSu(client, deviceId, app, command).catch((e) => {
|
||||||
) {
|
// Throw the original error.
|
||||||
// Fall back to running the command directly. This will work if adb is running as root.
|
console.debug(e);
|
||||||
return client
|
throw error;
|
||||||
.shell(deviceId, `echo "cat ${path}" | su`)
|
});
|
||||||
.then(adbkit.util.readAll)
|
}
|
||||||
.then((buffer) => buffer.toString())
|
throw error;
|
||||||
.catch(() => {
|
});
|
||||||
throw error;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
throw error;
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Keep this method private since it relies on pre-validated arguments
|
// Keep this method private since it relies on pre-validated arguments
|
||||||
@@ -112,9 +118,34 @@ function executeCommandAsApp(
|
|||||||
deviceId: string,
|
deviceId: string,
|
||||||
app: string,
|
app: string,
|
||||||
command: string,
|
command: string,
|
||||||
|
): Promise<string> {
|
||||||
|
return _executeCommandWithRunner(
|
||||||
|
client,
|
||||||
|
deviceId,
|
||||||
|
app,
|
||||||
|
command,
|
||||||
|
`run-as '${app}'`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function executeCommandWithSu(
|
||||||
|
client: Client,
|
||||||
|
deviceId: string,
|
||||||
|
app: string,
|
||||||
|
command: string,
|
||||||
|
): Promise<string> {
|
||||||
|
return _executeCommandWithRunner(client, deviceId, app, command, 'su');
|
||||||
|
}
|
||||||
|
|
||||||
|
function _executeCommandWithRunner(
|
||||||
|
client: Client,
|
||||||
|
deviceId: string,
|
||||||
|
app: string,
|
||||||
|
command: string,
|
||||||
|
runner: string,
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
return client
|
return client
|
||||||
.shell(deviceId, `echo '${command}' | run-as '${app}'`)
|
.shell(deviceId, `echo '${command}' | ${runner}`)
|
||||||
.then(adbkit.util.readAll)
|
.then(adbkit.util.readAll)
|
||||||
.then((buffer) => buffer.toString())
|
.then((buffer) => buffer.toString())
|
||||||
.then((output) => {
|
.then((output) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user