Skip to content

Commit 7324f55

Browse files
committed
Fix Chrome flags writing so it works on more types of rooted devices
Previously it assumed that 'adb push' would work for root-only paths, which wasn't true for devices that expose an explicit 'su' binary we can use, where we don't use 'adb root'. We now push a script that does the writing and then run it with root directly, which should work for all root setups.
1 parent 9fc1b62 commit 7324f55

File tree

1 file changed

+30
-13
lines changed

1 file changed

+30
-13
lines changed

src/interceptors/android/adb-commands.ts

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -279,20 +279,37 @@ export async function setChromeFlags(
279279
`/data/local/tmp/${variant}-command-line`,
280280
]);
281281

282-
await Promise.all(chromeFlagsLocations.map((flagsFilePath) =>
283-
pushFile(
284-
adbClient,
285-
deviceId,
286-
stringAsStream(flagsFileContent),
287-
flagsFilePath,
288-
// Due to an Android bug, user mode is always duplicated to group & others. We set as read-only
289-
// to avoid making this writable by others.
290-
// More details: https://github.com/openstf/adbkit/issues/126
291-
0o444 // Read-only for everybody
292-
)
293-
));
282+
const chromeFlagsScriptPath = `${ANDROID_TEMP}/htk-set-chrome-flags.sh`;
283+
284+
await pushFile(
285+
adbClient,
286+
deviceId,
287+
stringAsStream(`
288+
set -e # Fail on error
289+
290+
${
291+
chromeFlagsLocations.map((flagsFilePath) => `
292+
echo "${flagsFileContent}" > "${flagsFilePath}"
293+
chmod 744 "${flagsFilePath}"`
294+
).join('\n')
295+
}
296+
297+
rm ${chromeFlagsScriptPath}
298+
299+
echo "Chrome flags script completed"
300+
`),
301+
chromeFlagsScriptPath,
302+
// Due to an Android bug, user mode is always duplicated to group & others. We set as read-only
303+
// to avoid making this writable by others before we run it as root in a moment.
304+
// More details: https://github.com/openstf/adbkit/issues/126
305+
0o444
306+
);
307+
308+
// Actually run the script that we just pushed above, as root
309+
const scriptOutput = await run(adbClient, deviceId, rootCmd.concat('sh', chromeFlagsScriptPath));
310+
console.log(scriptOutput);
294311

295-
// Restart chrome, now that the flags have been changed:
312+
// Try to restart chrome, now that the flags have probably been changed:
296313
await run(adbClient, deviceId, rootCmd.concat('am', 'force-stop', 'com.android.chrome')).catch(() => {});
297314
}
298315

0 commit comments

Comments
 (0)