@@ -147,7 +147,9 @@ const runAsRootCommands = [
147
147
// 'su' as available on official emulators:
148
148
( ...cmd : string [ ] ) => [ 'su' , 'root' , ...cmd ] ,
149
149
// 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 ]
151
153
] ;
152
154
153
155
type RootCmd = ( ...cmd : string [ ] ) => string [ ] ;
@@ -156,7 +158,7 @@ export async function getRootCommand(adbClient: Adb.DeviceClient): Promise<RootC
156
158
// Run whoami with each of the possible root commands
157
159
const rootCheckResults = await Promise . all (
158
160
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 )
160
162
. then ( ( whoami ) => ( { cmd : runAsRoot , whoami } ) )
161
163
)
162
164
)
0 commit comments