ibilux / MobyDroid

Android Device Manager with a Graphic User Interface (GUI) – Manage Android on Linux, Windows and MacOS.
Apache License 2.0
140 stars 19 forks source link

App Manager breaks when having a work profile and/or secure folder. #18

Open My1 opened 5 months ago

My1 commented 5 months ago

According to this section https://github.com/ibilux/MobyDroid/blob/master/src/com/hq/mobydroid/device/TaskPackageMangerList.java#L41

the app manager invokes adb shell pm list packages

however that command basically fails completely when you have multiple users like Samsung's Secure Folder or an Android Enterprise Work Profile.

Exception occurred while executing 'list':
java.lang.SecurityException: Shell does not have permission to access user 11
 com.android.server.am.ActivityManagerService.handleIncomingUser:14999 android.app.ActivityManager.handleIncomingUser:4805 com.android.server.pm.PackageManagerShellCommand.translateUserId:3517 
        at com.android.server.am.UserController.handleIncomingUser(UserController.java:2680)
        at com.android.server.am.ActivityManagerService.handleIncomingUser(ActivityManagerService.java:14999)
        at android.app.ActivityManager.handleIncomingUser(ActivityManager.java:4805)
        at com.android.server.pm.PackageManagerShellCommand.translateUserId(PackageManagerShellCommand.java:3517)
        at com.android.server.pm.PackageManagerShellCommand.runListPackages(PackageManagerShellCommand.java:969)
        at com.android.server.pm.PackageManagerShellCommand.runListPackages(PackageManagerShellCommand.java:865)
        at com.android.server.pm.PackageManagerShellCommand.runList(PackageManagerShellCommand.java:724)
        at com.android.server.pm.PackageManagerShellCommand.onCommand(PackageManagerShellCommand.java:226)
        at com.android.modules.utils.BasicShellCommandHandler.exec(BasicShellCommandHandler.java:97)
        at android.os.ShellCommand.exec(ShellCommand.java:38)
        at com.android.server.pm.PackageManagerService$IPackageManagerImpl.onShellCommand(PackageManagerService.java:7071)
        at android.os.Binder.shellCommand(Binder.java:1085)
        at android.os.Binder.onTransact(Binder.java:903)
        at android.content.pm.IPackageManager$Stub.onTransact(IPackageManager.java:4962)
        at com.android.server.pm.PackageManagerService$IPackageManagerImpl.onTransact(PackageManagerService.java:7055)
        at android.os.Binder.execTransactInternal(Binder.java:1321)
        at android.os.Binder.execTransact(Binder.java:1280)

users can be pulled like this:

adb shell pm list users

Users:
        UserInfo{0:MY-NAME:c13} running
        UserInfo{11:Arbeitsprofil:1030} running       ----> workprofile
        UserInfo{151:Secure Folder:10061030} running

now when you use adb shell pm list packages --user 0 to only query the normal user, it works fine in the shell.

so you could query who the current user is with adb shell am get-current-user and only list that user's app or invoke for each user on its own.

ibilux commented 5 months ago

good catch & even better diagnostic @My1. I'll look into this.

My1 commented 5 months ago

thanks no problem, I have used my decent share of adb and I basically just traced back the code from the app manager java file (which was pretty easy thanks to github's auto tracer), because I knew somewhere it has to invoke adb and then I was able to just test stuff out via the good old terminal

ibilux commented 5 months ago

@My1 I have implemented the user id for pm commands in v0.7. It seem to work in my end (but i didn't had a problem before). I'll appreciate if you can also test the enable/disable apps in the App Manager because it invokes pm command too.