Skip to content

Commit 93b9154

Browse files
committed
Cover more cases in Android root command testing
1 parent 9b62da6 commit 93b9154

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/interceptors/android/adb-commands.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,9 @@ const runAsRootCommands = [
147147
// 'su' as available on official emulators:
148148
(...cmd: string[]) => ['su', 'root', ...cmd],
149149
// Su on many physical rooted devices requires quotes:
150-
(...cmd: string[]) => ['su', '-c', `'${cmd.join(' ')}'`]
150+
(...cmd: string[]) => ['su', '-c', `'${cmd.join(' ').replace("'", "\\'")}'`],
151+
// But sometimes it doesn't like them, so try that too:
152+
(...cmd: string[]) => ['su', '-c', ...cmd]
151153
];
152154

153155
type RootCmd = (...cmd: string[]) => string[];
@@ -156,7 +158,7 @@ export async function getRootCommand(adbClient: Adb.DeviceClient): Promise<RootC
156158
// Run whoami with each of the possible root commands
157159
const rootCheckResults = await Promise.all(
158160
runAsRootCommands.map((runAsRoot) =>
159-
run(adbClient, runAsRoot('whoami'), { timeout: 1000 }).catch(console.log)
161+
run(adbClient, runAsRoot('sh', '-c', 'whoami'), { timeout: 1000 }).catch(console.log)
160162
.then((whoami) => ({ cmd: runAsRoot, whoami }))
161163
)
162164
)

0 commit comments

Comments
 (0)