File tree Expand file tree Collapse file tree 4 files changed +39
-0
lines changed
common/drivers/android/exec Expand file tree Collapse file tree 4 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -160,6 +160,14 @@ class ADB {
160160 }
161161 }
162162
163+ async grantAllPermissions ( deviceId , packageId ) {
164+ await this . shell ( deviceId , `pm grant --all-permissions ${ packageId } ` ) ;
165+ }
166+
167+ async revokeAllPermissions ( deviceId , packageId ) {
168+ await this . shell ( deviceId , `pm revoke --all-permissions ${ packageId } ` ) ;
169+ }
170+
163171 async setLocation ( deviceId , lat , lon ) {
164172 // NOTE: QEMU for Android for the telnet part relies on C stdlib
165173 // function `strtod` which is locale-sensitive, meaning that depending
Original file line number Diff line number Diff line change @@ -429,4 +429,24 @@ describe('ADB', () => {
429429 await expect ( adb . clearAppData ( deviceId , 'com.example.app' ) ) . rejects . toThrowErrorMatchingSnapshot ( ) ;
430430 } ) ;
431431 } ) ;
432+
433+ describe ( 'grantAllPermissions' , ( ) => {
434+ it ( 'should invoke pm grant --all-permissions for given package' , async ( ) => {
435+ await adb . grantAllPermissions ( deviceId , 'com.example.app' ) ;
436+ expect ( execWithRetriesAndLogs ) . toHaveBeenCalledWith (
437+ expect . stringContaining ( `"${ adbBinPath } " -s ${ deviceId } shell "pm grant --all-permissions com.example.app"` ) ,
438+ expect . any ( Object )
439+ ) ;
440+ } ) ;
441+ } ) ;
442+
443+ describe ( 'revokeAllPermissions' , ( ) => {
444+ it ( 'should invoke pm revoke --all-permissions for given package' , async ( ) => {
445+ await adb . revokeAllPermissions ( deviceId , 'com.example.app' ) ;
446+ expect ( execWithRetriesAndLogs ) . toHaveBeenCalledWith (
447+ expect . stringContaining ( `"${ adbBinPath } " -s ${ deviceId } shell "pm revoke --all-permissions com.example.app"` ) ,
448+ expect . any ( Object )
449+ ) ;
450+ } ) ;
451+ } ) ;
432452} ) ;
Original file line number Diff line number Diff line change @@ -87,6 +87,7 @@ class AndroidDriver extends DeviceDriverBase {
8787 async resetAppState ( ...bundleIds ) {
8888 for ( const bundleId of bundleIds ) {
8989 await this . adb . clearAppData ( this . adbName , bundleId ) ;
90+ await this . adb . grantAllPermissions ( this . adbName , bundleId ) ;
9091 }
9192 }
9293
Original file line number Diff line number Diff line change @@ -496,6 +496,16 @@ describe('Android driver', () => {
496496 expect ( adb . clearAppData ) . toHaveBeenCalledWith ( adbName , bundleId1 ) ;
497497 expect ( adb . clearAppData ) . toHaveBeenCalledWith ( adbName , bundleId2 ) ;
498498 } ) ;
499+
500+ it ( 'should grant all permissions for the affected apps' , async ( ) => {
501+ const bundleId1 = 'com.example.app1' ;
502+ const bundleId2 = 'com.example.app2' ;
503+
504+ await uut . resetAppState ( bundleId1 , bundleId2 ) ;
505+
506+ expect ( adb . grantAllPermissions ) . toHaveBeenCalledWith ( adbName , bundleId1 ) ;
507+ expect ( adb . grantAllPermissions ) . toHaveBeenCalledWith ( adbName , bundleId2 ) ;
508+ } ) ;
499509 } ) ;
500510
501511 describe ( 'text-typing (global)' , ( ) => {
You can’t perform that action at this time.
0 commit comments