Adding permissions to hooked app?

Search This thread

Lawiusz

Member
Oct 2, 2010
34
60
Hi everyone!
In my Xposed module I modified hooked package (SystemUI) so that it needs some additional permissions that it normally wouldn't use (especially "android.permission.RECORD_AUDIO" and "android.permission.MODIFY_AUDIO_SETTINGS"). It seems that having both those perms in module's manifest is not enough. Any ideas how to grant them to SystemUI?
 

rovo89

Senior Recognized Developer
Jan 4, 2012
2,585
81,353
An app can't grant itself more permissions, and a module basically becomes a part of the app it hooks. You would have to hook the PackageManagerService for this as it handles permissions, but I'm afraid I can't give you a step by step tutorial.
 

Lawiusz

Member
Oct 2, 2010
34
60
An app can't grant itself more permissions, and a module basically becomes a part of the app it hooks. You would have to hook the PackageManagerService for this as it handles permissions, but I'm afraid I can't give you a step by step tutorial.
After a small fight with PackageManagerService's grantPermissionsLPw method I finally managed to grant necessary permissions. :D
Huge thanks @rovo89 !
 

yylou

Member
Feb 13, 2017
7
0
After a small fight with PackageManagerService's grantPermissionsLPw method I finally managed to grant necessary permissions. :D
Huge thanks @rovo89 !

Hi, I would like to do the similar thing like you did.
But I had no idea where to start, could you give me some hints or reference source code ?
Thank you very much !!!
 

yylou

Member
Feb 13, 2017
7
0
After a small fight with PackageManagerService's grantPermissionsLPw method I finally managed to grant necessary permissions. :D
Huge thanks @rovo89 !

After I refer to your source code, I encounter this error

Code:
03-09 16:04:51.430 I/Xposed  ( 2740): Package: com.example.yylou.speechrecognition
03-09 16:04:51.430 E/Xposed  ( 2740): java.lang.NoSuchFieldError: com.android.server.pm.PackageSetting#grantedPermissions
03-09 16:04:51.430 E/Xposed  ( 2740): 	at de.robv.android.xposed.XposedHelpers.findField(XposedHelpers.java:102)
03-09 16:04:51.430 E/Xposed  ( 2740): 	at de.robv.android.xposed.XposedHelpers.getObjectField(XposedHelpers.java:848)
03-09 16:04:51.430 E/Xposed  ( 2740): 	at com.example.yylou.vlh._Speech$1.afterHookedMethod(_Speech.java:68)
03-09 16:04:51.430 E/Xposed  ( 2740): 	at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBridge.java:348)
03-09 16:04:51.430 E/Xposed  ( 2740): 	at com.android.server.pm.PackageManagerService.grantPermissionsLPw(<Xposed>)
03-09 16:04:51.430 E/Xposed  ( 2740): 	at com.android.server.pm.PackageManagerService.updatePermissionsLPw(PackageManagerService.java:8334)
03-09 16:04:51.430 E/Xposed  ( 2740): 	at com.android.server.pm.PackageManagerService.updatePermissionsLPw(PackageManagerService.java:8247)
03-09 16:04:51.430 E/Xposed  ( 2740): 	at com.android.server.pm.PackageManagerService.updateSettingsLI(PackageManagerService.java:12173)
03-09 16:04:51.430 E/Xposed  ( 2740): 	at com.android.server.pm.PackageManagerService.replaceNonSystemPackageLI(PackageManagerService.java:11933)
03-09 16:04:51.430 E/Xposed  ( 2740): 	at com.android.server.pm.PackageManagerService.replacePackageLI(PackageManagerService.java:11886)
03-09 16:04:51.430 E/Xposed  ( 2740): 	at com.android.server.pm.PackageManagerService.installPackageLI(PackageManagerService.java:12469)
03-09 16:04:51.430 E/Xposed  ( 2740): 	at com.android.server.pm.PackageManagerService.-wrap25(PackageManagerService.java)
03-09 16:04:51.430 E/Xposed  ( 2740): 	at com.android.server.pm.PackageManagerService$9.run(PackageManagerService.java:10170)
03-09 16:04:51.430 E/Xposed  ( 2740): 	at android.os.Handler.handleCallback(Handler.java:739)
03-09 16:04:51.430 E/Xposed  ( 2740): 	at android.os.Handler.dispatchMessage(Handler.java:95)
03-09 16:04:51.430 E/Xposed  ( 2740): 	at android.os.Looper.loop(Looper.java:148)
03-09 16:04:51.430 E/Xposed  ( 2740): 	at android.os.HandlerThread.run(HandlerThread.java:61)
03-09 16:04:51.430 E/Xposed  ( 2740): 	at com.android.server.ServiceThread.run(ServiceThread.java:46)

_Speech.java:68
Code:
Set<String> grantedPerms = ( Set<String> ) XposedHelpers.getObjectField( extras, "grantedPermissions");

Does anybody knows the solution ? I counldn't find any no related discussion after I GOOGLE it. Orz
 

Top Liked Posts