Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(android): list installed packages on some Samsung devices #5713

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rigor789
Copy link
Member

PR Checklist

What is the current behavior?

On some devices listing installed packages via adb shell breaks due to a permission error - and makes other parts of the CLI fail because we can't verify whether or not the app has been installed.

What is the new behavior?

In case listing the packages fails - we try an alternative (slower) method:

  • list all users
  • list all packages per user and concatenate them
  • continue with the rest of the logic...

@cla-bot cla-bot bot added the cla: yes label Jan 20, 2023
@rigor789
Copy link
Member Author

rigor789 commented Feb 13, 2023

Update: draft state because errors are part of stderr but not caught in the catch block - need to parse command result for output like this:

./adb shell "pm list packages"

Exception occurred while executing 'list':
java.lang.SecurityException: Shell does not have permission to access user 150
 com.android.server.am.ActivityManagerService.handleIncomingUser:14872 android.app.ActivityManager.handleIncomingUser:4802 com.android.server.pm.PackageManagerShellCommand.translateUserId:3499
        at com.android.server.am.UserController.handleIncomingUser(UserController.java:2672)
        at com.android.server.am.ActivityManagerService.handleIncomingUser(ActivityManagerService.java:14872)
        at android.app.ActivityManager.handleIncomingUser(ActivityManager.java:4802)
        at com.android.server.pm.PackageManagerShellCommand.translateUserId(PackageManagerShellCommand.java:3499)
        at com.android.server.pm.PackageManagerShellCommand.runListPackages(PackageManagerShellCommand.java:965)
        at com.android.server.pm.PackageManagerShellCommand.runListPackages(PackageManagerShellCommand.java:861)
        at com.android.server.pm.PackageManagerShellCommand.runList(PackageManagerShellCommand.java:720)
        at com.android.server.pm.PackageManagerShellCommand.onCommand(PackageManagerShellCommand.java:222)
        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:6922)
        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:4909)
        at com.android.server.pm.PackageManagerService$IPackageManagerImpl.onTransact(PackageManagerService.java:6906)
        at android.os.Binder.execTransactInternal(Binder.java:1321)
        at android.os.Binder.execTransact(Binder.java:1280)
Exit code is: 255

Temporary fix was to modify the android-debug-bridge -> executeCommand() function to concat stderr to output + parse/check for the specific string:

result.stdout.concat(result.stderr)

// ...

if(result.includes('Exception occurred while executing')) {
  throw result
}

@rigor789 rigor789 added this to the 8.5 milestone Mar 15, 2023
@NathanWalker NathanWalker modified the milestones: 8.5, 9.0 Oct 23, 2023
@rigor789 rigor789 removed this from the 9.0 milestone Apr 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants