Skip to content

Conversation

@noomorph
Copy link
Collaborator

@noomorph noomorph commented Oct 3, 2025

Caution

The PR is not ready. The --all-permissions flag does not work on all Android environments, so we need to add a fallback, too.

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.

We'll use this PR as a base:

@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
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

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

4 participants