Repository navigation
feat(install): let install() and installRemote() take pm install flags - #595
Merged
Merged
Conversation
install() and installRemote() always ran pm install -r <apk>, so there was no way to downgrade an app (-d), grant its runtime permissions (-g) or install a test-only apk (-t). Both now take an optional InstallOptions object: allowDowngrade, grantPermissions and allowTestPackages add -d, -g and -t, reinstall: false leaves out -r, and args passes anything else, each quoted like the apk path. Without options the command is still exactly pm install -r <apk>. Anything but an object, such as a callback the README used to list, means no options. Closes #239 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Karol Wrótniak <karol.wrotniak@droidsonroids.pl>
…or showed them On Android 16 the device reports a failure as [INSTALL_FAILED_VERSION_DOWNGRADE: Downgrade detected: ...], so the error's code starts with the reason code instead of being only that. The same device also replaces an installed app without -r, so reinstall: false makes no difference there. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Karol Wrótniak <karol.wrotniak@droidsonroids.pl>
- Check options before anything is sent. An array as options, or args that isn't an array of strings, now rejects with a TypeError and ends the connection; before, it threw synchronously, so installRemote() left the temp apk on the device and the socket open. - Single-quote args, as startActivity() does, so '!' reaches pm unchanged instead of as '\!'. - Docs: replacing is the default, not a given (reinstall: false); an unknown flag on older Android rejects without .code; the TypeError. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Karol Wrótniak <karol.wrotniak@droidsonroids.pl>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #239
device.install()anddevice.installRemote()always ranpm install -r <apk>, so there was no way to downgrade an app (-d), grant its runtime permissions (-g) or install a test-only apk (-t). Both now take an optionalInstallOptionsobject. Without it, the command is still exactlypm install -r <apk>.allowDowngrade,grantPermissionsandallowTestPackagesadd-d,-gand-t. They're all off by default.reinstalldefaults totrue.reinstall: falseleaves out-r.argspasses any otherpm installarguments. Each one is quoted with the same helper as the apk path, so it stays a single argument and can't run another shell command.null.callbackbullets are removed from both methods.On the first part of the issue: a failed install already rejects in a way the caller can catch, with an
Errorwhosecodeholds the device's reason. The emulator run below confirms it.Testing
npm run lint,npm run compileandnpm testpass (390 passing).{}, each flag, every flag at once,reinstall: false,args, and escaping of spaces,$( ), backticks,"and\;nullpassed as options;install()handing its options toinstallRemote(), andinstallRemote()sending them and still removing the apk.-ralways on,-ralways off,argsignored,argsunescaped, the object guard, both forwardings, and flag order.userbuild) emulator through the local adb server:install(v2)installed with CAMERA not granted.install(v2, { grantPermissions: true })installed with CAMERA granted.install(v1)over v2 rejected witherr.code=INSTALL_FAILED_VERSION_DOWNGRADE: Downgrade detected: ..., caught in atry/catch.install(v1, { allowDowngrade: true })installed version 1 over version 2 for a debuggable app. For a non-debuggable app, this user build still refused it, as the docs now say.testOnlyapk was rejected withINSTALL_FAILED_TEST_ONLYwithout-t, and installed withallowTestPackages: true.args: ['--user', '0']installed.args: ['--user', '0; touch /data/local/tmp/pwned']reachedpmas one argument (Bad user number: 0; touch /data/local/tmp/pwned), and no file was created.reinstall: falseover an installed app still succeeded, because Android 16 replaces the app without-r. The docs say so.🤖 Generated with Claude Code