Introducing a new way to review your PRs.

Read the announcement

rikkaapps / shizuku

Using system APIs directly with adb/root privileges from normal apps through a Java process started with app_process.

View on GitHub

12 documents · Updated Nov 16, 2026

docs / manager-authorization-and-app-management

Manager Authorization and App Management

Overview

The manager authorization flow has two entry points under manager/src/main/java/moe/shizuku/manager/authorization/. RequestPermissionActivity.kt is launched by the Shizuku permission-confirmation path with uid, pid, requestCode, and applicationInfo extras. Before showing UI, it waits up to five seconds for the Shizuku binder via Shizuku.addBinderReceivedListenerSticky; if the binder is unavailable, or the request extras are invalid, the activity finishes without granting. It also checks whether the manager process has android.permission.GRANT_RUNTIME_PERMISSIONS through Shizuku.checkRemotePermission; when ADB mode is too limited, it shows the ADB-limited help dialog and sends a denied, one-time result back through Shizuku.dispatchPermissionConfirmationResult.

When the request can be handled, RequestPermissionActivity.kt inflates manager/…/confirmation_dialog.xml, labels the requesting app from ApplicationInfo.loadLabel, and presents a non-cancelable Material dialog. The allow button dispatches REQUEST_PERMISSION_REPLY_ALLOWED=true and REQUEST_PERMISSION_REPLY_IS_ONETIME=false; the deny button dispatches REQUEST_PERMISSION_REPLY_ALLOWED=false and REQUEST_PERMISSION_REPLY_IS_ONETIME=true. Dialog dismissal always finishes the activity, so the only persisted state change comes from the Shizuku server receiving the dispatched result.

AuthorizationManager.kt centralizes the manager-side authorization state. For Shizuku pre-v11 servers it reads and writes Android runtime permission state for moe.shizuku.manager.Manifest.permission.API_V23 through ShizukuSystemApis.checkPermission, grantRuntimePermission, and revokeRuntimePermission, deriving the user id as uid / 100000. For v11+ servers it reads and writes Shizuku UID flags through Shizuku.getFlagsForUid and Shizuku.updateFlagsForUid, using FLAG_ALLOWED and FLAG_DENIED as MASK_PERMISSION. Installed app discovery is version-dependent too: pre-v11, and v11 servers before patch 3, enumerate each user through ShizukuSystemApis.getUsers and filter installed packages to apps with moe.shizuku.client.V3_SUPPORT metadata and the API v23 permission; newer servers call the Shizuku binder transaction ServerConstants.BINDER_TRANSACTION_getApplications and unpack a ParcelableListSlice<PackageInfo>.

The app-management UI is rooted at manager/…/ApplicationManagementActivity.kt. It exits immediately if Shizuku.pingBinder() fails and registers a binder-death listener that finishes the screen when the service dies. The activity inflates manager/…/apps_activity.xml, observes AppsViewModel.packages, and hands successful lists to AppsAdapter.updateData; load errors finish the activity and display a toast with the thrown error. On first creation it calls AppsViewModel.load(), and the RecyclerView uses AppsAdapter with edge effects and spacing.

AppsViewModel.kt loads application data on Dispatchers.IO. Each load asks AuthorizationManager.getPackages() for candidates, counts how many are currently granted via AuthorizationManager.granted(packageName, uid), posts the package list to packages unless onlyCount is true, and always posts the count to grantedCount. CancellationException is intentionally ignored; other failures are posted as Resource.error to both LiveData objects. ApplicationManagementActivity.kt registers an AdapterDataObserver so item-level changes call viewModel.load(true), refreshing only grantedCount after a grant/revoke toggle without rebuilding the list.

AppsAdapter.java maps PackageInfo rows to AppViewHolder.kt and a plain Object sentinel to EmptyViewHolder.kt. updateData clears the adapter, inserts the sentinel when the package list is empty, or inserts all packages otherwise, then calls notifyDataSetChanged; stable IDs are the row object's hashCode(). EmptyViewHolder.kt only inflates manager/…/app_list_empty.xml, which displays the empty-state hint.

AppViewHolder.kt owns each installed-app row. It filters obscured touches, toggles authorization on row click by calling AuthorizationManager.revoke when already granted or AuthorizationManager.grant otherwise, and then notifies the adapter with a payload so the switch can rebind. If a grant/revoke throws SecurityException while Shizuku is running as a non-root UID, it shows the same ADB-limited help dialog used by permission handling. Full binds populate the icon, display name, package name, granted switch state, and the V3_REQUIRES_ROOT warning from ApplicationInfo.metaData; apps from another user append the user name and id from ShizukuSystemApis.getUserInfo. Icons are first loaded synchronously from ApplicationInfo.loadIcon, then refreshed asynchronously through AppIconCache.loadIconBitmapAsync, and any active icon job is canceled on recycle.

Coupling

  • If the Shizuku server permission reply contract changes, update RequestPermissionActivity.kt and the server-side consumer together: the activity hardcodes the intent extras uid, pid, requestCode, and applicationInfo, and replies with REQUEST_PERMISSION_REPLY_ALLOWED plus REQUEST_PERMISSION_REPLY_IS_ONETIME via Shizuku.dispatchPermissionConfirmationResult.
  • If the meaning of Shizuku authorization flags changes, update AuthorizationManager.kt before changing UI behavior: v11+ grant state is determined only by MASK_PERMISSION containing FLAG_ALLOWED, while revoke writes 0 for the whole permission mask.
  • If the legacy package eligibility contract changes, keep AuthorizationManager.kt in sync with client manifests: the pre-v11 path filters by moe.shizuku.client.V3_SUPPORT metadata and Manifest.permission.API_V23, so missing either silently removes an app from ApplicationManagementActivity.kt's list.
  • If row payload behavior changes in AppViewHolder.kt or AppsAdapter.java, verify ApplicationManagementActivity.kt's AdapterDataObserver: item changes are also the trigger for AppsViewModel.load(true), which refreshes grantedCount after toggles without reloading packages.
  • If manager/…/app_list_item.xml changes switch clickability or focusability, recheck AppViewHolder.kt: the row click handler owns grant/revoke, while the MaterialSwitch is currently display-only and rebound from AuthorizationManager.granted.

Risks

  • RequestPermissionActivity.kt is sensitive to binder timing. Git history includes 0451f9f Wait for Binder in RequestPermissionActivity followed by 583931b Fix RequestPermissionActivity takes forever to show up; if waitForBinder() blocking or listener removal changes, permission prompts can either fail before Shizuku connects or stall before showing UI.
  • AppsViewModel.kt and ApplicationManagementActivity.kt have recent fixes around count refresh and crashes (1d43a05 Fix granted count, 4d88dbe Fix crash). If load(onlyCount = true) starts posting package-list errors or rebuilding packages, a simple grant/revoke from AppViewHolder.kt can unexpectedly finish the activity or reorder the list while the adapter is handling an item change.
  • AuthorizationManager.kt derives legacy user ids with uid / 100000 in granted, grant, and revoke. If Android UID layout handling changes elsewhere, the pre-v11 runtime-permission path can grant or revoke Manifest.permission.API_V23 for the wrong user while v11+ flag handling still works.