Skip to content

AppOps: warn before modifying AppOps for shared system UIDs (#2030) - #2073

Open
AndrewWangDev wants to merge 1 commit into
MuntashirAkon:masterfrom
AndrewWangDev:warn-shared-system-uid
Open

AndrewWangDev wants to merge 1 commit into
MuntashirAkon:masterfrom
AndrewWangDev:warn-shared-system-uid

Conversation

@AndrewWangDev

Copy link
Copy Markdown

Please check before submitting a PR

  • I have read and understood CONTRIBUTING.
  • I am developing against the latest version of App Manager's source code.
  • I have been assigned to work on this feature/issue.
  • I know that generating a PR or its code, in whole or in part, using AI/LLM is prohibited.

Describe the feature or issue

In Android 6.0+ (API 23+), AppOpsManagerCompat.setMode delegates to AppOpsManager.setUidMode. Since Android enforces AppOps boundaries per UID rather than per package, changing or resetting AppOps for an application that shares a UID with core system packages (most notably android.uid.system / UID 1000, which includes Settings, System UI, and core framework components) modifies those permissions globally across all packages sharing that UID.
For example, inadvertently revoking or resetting GET_USAGE_STATS on a vendor system tool sharing UID 1000 can cause the Android Settings app or system services to crash immediately with a SecurityException.

Related Issues

Resolves #2030

Describe the solution you've implemented

Introduced UidWarningHelper and added tiered confirmation dialogs before executing dangerous AppOps modifications:

  1. Warning Strategy:

    • System Shared UIDs (App ID < 10000): Displays a high-visibility warning dialog (ic_caution) detailing the critical risk to system stability and explicitly enumerates the affected co-located packages.
    • Non-System Shared UIDs (App ID >= 10000): Displays a standard informational confirmation dialog explaining that the change will affect multiple packages sharing the UID.
    • Non-Shared / Independent UIDs: Proceeds directly.
  2. Intercepted Operations:

    • App Details Permissions: Single op mode modification (tap / long-press), reset all AppOps, and deny dangerous AppOps. A per-fragment dismissal flag (mSharedUidWarningDismissed) avoids redundant prompts within the same session.
    • Backup & Restore: Batch AppOps restoration.
    • One-Click Ops: Debloat and batch AppOps application.
    • Rules: Batch rules import across multi-user environments (with parallel cartesian product package/user mapping) and clear all rules confirmation.
  3. Lifecycle, Concurrency & Performance Guards:

    • Safely unwraps ContextThemeWrapper/ContextWrapper to retrieve the underlying Activity, with explicit isFinishing() and isDestroyed() checks.
    • Fallback for non-Activity contexts.
    • Optimizes IPC Binder calls via UID deduplication (checkedUids) and early-break traversal once a critical system UID is encountered.
    • Guards against uninstalled external APKs in AppDetailsViewModel.getUid(), avoiding false UID 0 (root) detections.
  4. Tests & Localization:

    • Added 9 Robolectric unit tests in UidWarningHelperTest covering boundary conditions, destroyed activities, non-activity contexts, and multi-user resolution.

Describe alternatives you've considered

  • Hard-blocking AppOps modifications for system UIDs: Considered, but rejected because advanced users may legitimately need to tune or debug system services. A warning dialog provides the balance between safety and user control.

Additional context

  • Passed ./gradlew :app:testDebugUnitTest --tests io.github.muntashirakon.AppManager.utils.UidWarningHelperTest (9/9 passed).
  • Passed ./gradlew :app:lintDebug.
  • Passed ./gradlew assembleDebug.

…rAkon#2030)

In Android M (API 23)+, AppOpsManagerCompat.setMode delegates to setUidMode. While consistent with Android's UID security domain, modifying AppOps on an app that shares a core system UID (e.g. UID 1000 with the system framework) can inadvertently strip permissions like GET_USAGE_STATS globally, causing system stability issues.

This commit introduces a tiered confirmation dialog before executing dangerous AppOps modifications:
- For apps sharing a system UID (< 10000), a high-visibility warning dialog is displayed highlighting the affected system packages.
- For non-system shared UIDs, a general multi-package notice is shown.
- Adds comprehensive unit tests and multi-language support (English and Simplified Chinese).

Resolves: MuntashirAkon#2030
Signed-off-by: Andrew Wang Dev <me@andrewwangdev.com>

This branch has not been deployed

No deployments
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.

Warn users before batch modifying AppOps for shared system UIDs (< 10000) to prevent silent collateral permission loss

1 participant