@@ -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
153155type 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