nativescript-cli
nativescript-cli copied to clipboard
fix(android): list installed packages on some Samsung devices
PR Checklist
- [x] The PR title follows our guidelines: https://github.com/NativeScript/NativeScript/blob/master/tools/notes/CONTRIBUTING.md#commit-messages.
- [ ] There is an issue for the bug/feature this PR is for. To avoid wasting your time, it's best to open a suggestion issue first and wait for approval before working on it.
- [x] You have signed the CLA.
- [x] All existing tests are passing: https://github.com/NativeScript/nativescript-cli/blob/master/CONTRIBUTING.md#contribute-to-the-code-base
- [ ] Tests for the changes are included.
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...
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
}