Skip to content

fix(android): grant all permissions after resetting app state#4844

Merged
noomorph merged 5 commits intomasterfrom
fix/reset-app-state-permissions
Jan 12, 2026
Merged

fix(android): grant all permissions after resetting app state#4844
noomorph merged 5 commits intomasterfrom
fix/reset-app-state-permissions

Conversation

@noomorph
Copy link
Collaborator

@noomorph noomorph commented Oct 3, 2025

Description

In this pull request, I have added extra calls to adb shell pm grant --all-permissions to imitate our adb install -g calls for normal case.

@noomorph noomorph requested a review from d4vidi as a code owner October 3, 2025 12:26
@noomorph noomorph force-pushed the fix/reset-app-state-permissions branch from e1fb2a2 to e22443c Compare October 3, 2025 13:01
@noomorph noomorph marked this pull request as draft October 3, 2025 16:22
@noomorph noomorph force-pushed the fix/reset-app-state-permissions branch from e22443c to f29156c Compare October 4, 2025 11:22
@d4vidi d4vidi self-assigned this Nov 10, 2025
Copy link
Collaborator

@d4vidi d4vidi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is all really cool so it makes it more difficult to be breaking the bad news -

In where Detox for Android is right now, we just always install apps with all permissions granted in advance (see the -g flag in the ADB install function) -

Image

So it's really great we can allow for permissions granularity within a reasonable effort but unfortunately, first we're going to have to undo the full-permissions as a default (thus addressing a years outstanding long feature request).

I suggest that for this specific scenario, we'd just stick to just granting all permissions right after the reset, keeping things as seamless as possible.

@d4vidi d4vidi assigned noomorph and unassigned d4vidi Nov 13, 2025
@erdemkiiliic
Copy link

Is there an update on this issue? @noomorph

@noomorph
Copy link
Collaborator Author

Mmm, I suggest this approach, @d4vidi

  • If app config has a permissions map:
    Do not use -g with adb install.
    Instead, explicitly grant each permission using adb shell pm grant.
  • If app config has no permissions:
    Use -g (grant all permissions upon install).
    In resetAppState, run adb shell pm grant --all-permissions as a fallback.

Speaking Bash:

if [ -n "$APP_PERMISSIONS_MAP" ]; then
  # Install without -g
  adb install "$APK_PATH"
  # Grant each permission explicitly
  for perm in $APP_PERMISSIONS_MAP; do
    adb shell pm grant "$PACKAGE_NAME" "$perm"
  done
else
  # Install with -g
  adb install -g "$APK_PATH"
  # Fallback: grant all permissions in resetAppState
  adb shell pm grant "$PACKAGE_NAME" --all-permissions
fi
  • We'll have compatibility with the previous logic
  • Officially we won't recommend it as a a way to go, because click on system dialog may be a bit challenging (ui automator perhaps?)
  • If someone needs device.resetAppState() with older device, they'll have to do some legwork and add permissions as a map

@noomorph noomorph force-pushed the fix/reset-app-state-permissions branch from f29156c to ad5b655 Compare January 7, 2026 18:45
@noomorph noomorph marked this pull request as ready for review January 7, 2026 18:46
@noomorph noomorph force-pushed the fix/reset-app-state-permissions branch 2 times, most recently from 3e6efad to 6cbf373 Compare January 7, 2026 18:49
@noomorph noomorph force-pushed the fix/reset-app-state-permissions branch from 6cbf373 to e7356f2 Compare January 7, 2026 19:01
@noomorph noomorph merged commit 9fc96a2 into master Jan 12, 2026
1 check passed
@noomorph noomorph deleted the fix/reset-app-state-permissions branch January 12, 2026 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

App permission not longer persist when resetAppState() or launchApp({resetAppState: true}) was specified

3 participants