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-utilities-and-widgets

Manager Utilities and Widgets

Overview

This area is the manager app's small shared Android support layer: Kotlin extensions in manager/src/main/java/moe/shizuku/manager/ktx/**, app/system helpers in manager/src/main/java/moe/shizuku/manager/utils/**, and reusable view helpers in manager/src/main/java/moe/shizuku/manager/widget/**. These files do not own a screen; instead they normalize framework edge cases used by feature code elsewhere in the manager app.

The ktx extensions wrap common Android framework calls. manager/…/Context.kt exposes Context.application as the process ShizukuApplication and provides device-protected storage context helpers, including a locked-user variant that only switches storage when UserManager.isUserUnlocked is not true. manager/…/PackageManager.kt changes component enabled state with PackageManager.DONT_KILL_APP and reads explicit/default component state with a caller-supplied default. manager/…/String.kt funnels HTML parsing through rikka.html.text.HtmlCompat, and manager/…/Log.kt provides short Android log tags derived from the reified receiver type plus direct Log.v/i/w/d/e wrappers.

manager/…/RecyclerView.kt contains FixedAlwaysClipToPaddingEdgeEffectFactory, a RecyclerView.EdgeEffectFactory that manually sizes and translates each glow edge using fixed padding values. It exists for lists whose overscroll effect must behave as though padding is always clipped even when the RecyclerView layout configuration would otherwise draw the edge effect across padded space.

The utils package groups system and persistence wrappers. manager/…/ShizukuSystemApis.kt is the bridge from manager UI code to hidden package/user/permission APIs over Shizuku: its initializer wraps system service binders with ShizukuBinderWrapper, getUsers() caches UserInfoCompat records, package listing calls PackageManagerApis.getInstalledPackages, and permission checks/grants/revokes delegate to PermissionManagerApis only when Shizuku.pingBinder() succeeds. Without a live Shizuku binder it returns safe fallbacks: owner/unknown user info, empty package lists, denied permission checks, and no-op permission mutations.

User identity helpers are intentionally simple. manager/…/UserHandleCompat.java derives user id and app id from Android's PER_USER_RANGE of 100000, caching myUserId() from Os.getuid() at class load. manager/…/UserInfoCompat.java is the two-field value object consumed by ShizukuSystemApis.kt.

App environment and settings fallbacks live in manager/…/EnvironmentUtils.kt and manager/…/EmptySharedPreferencesImpl.java. EnvironmentUtils checks watch UI mode, detects root by scanning every directory in PATH for an su binary, and reads ADB-over-TCP ports from service.adb.tcp.port then persist.adb.tcp.port. EmptySharedPreferencesImpl is a non-persistent SharedPreferences implementation: every read returns the caller's default, contains() is false, getAll() is empty, and editor operations are fluent no-ops with commit() returning true. It is used by ShizukuSettings when protected storage is unavailable before unlock.

Locale and browser helpers sit in the same utility layer. manager/…/MultiLocaleEntity.java extends LinkedHashMap<String, String> and resolves the best string for ShizukuSettings.getLocale() by trying exact language-region matches, language-only keys, language-prefixed regional keys, then en, default, and finally the first non-overwrite_default entry. manager/…/CustomTabsHelper.java creates title-showing custom tabs, lets app setup inject styling through an OnCreateIntentBuilderListener, appends night=1 to help URLs when the current configuration is night mode, and falls back from custom tabs to an ACTION_VIEW browser intent, then to copying the URL and showing a Material dialog if no browser can open it.

manager/…/AppIconCache.kt owns asynchronous app-icon loading for list rows. It is a main-dispatcher CoroutineScope backed by an LruCache<Triple<String, Int, Int>, Bitmap> keyed by package name, user id, and pixel size. Cache size is one quarter of available runtime memory measured in KiB. Icon decoding runs on a fixed thread pool sized to at least one thread and otherwise half of available processors; loadIconBitmapAsync() computes the target size from ImageView.measuredWidth or R.dimen.default_app_icon_size, sets cached bitmaps immediately on the main thread, and otherwise loads with AppIconLoader off-main before applying the bitmap or a default icon/null fallback.

Logging has two forms. manager/…/Log.kt is idiomatic Kotlin and truncates receiver-derived tags to Android's 23-character legacy limit, throwing if the class simple name is blank. manager/…/Logger.java is a Java-friendly logger with a singleton LOGGER tagged ShizukuManager; all levels are currently loggable, and formatted methods use Locale.ENGLISH before delegating to android.util.Log.

The reusable widgets are small state/drawing adapters. manager/…/CheckedImageView.java adds Checkable state to an ImageView and merges android.R.attr.state_checked into the drawable state when checked, so selectors can react to selection state. manager/…/VerticalPaddingDecoration.java adds density-scaled top padding to the first adapter item and bottom padding to the last, with setters to disable either edge; it exits early if no adapter is attached.

Coupling

  • If code changes ShizukuSystemApis.getUsers() or getUserInfo() in manager/…/ShizukuSystemApis.kt, verify callers tolerate both cached data and the fallback identities created from manager/…/UserHandleCompat.java; the cache is only refreshed when useCache is false or empty, so stale user names/ids can persist for the process.
  • If the manager's settings storage or startup locale behavior changes, update manager/…/EmptySharedPreferencesImpl.java and manager/…/MultiLocaleEntity.java together with ShizukuSettings: EmptySharedPreferencesImpl makes locked-storage reads silently return defaults, and MultiLocaleEntity.DEFAULT_LOCAL_PROVIDER resolves through ShizukuSettings.getLocale().
  • If help/documentation URLs require stable query strings, check manager/…/CustomTabsHelper.java; launchHelp() always rebuilds the URI and may append night=1 based on UI mode before trying custom tabs or browser fallback.
  • If app-list rows recycle ImageViews while icons are loading, callers of manager/…/AppIconCache.kt should retain and cancel the returned Job; loadIconBitmapAsync() sets the bitmap on the passed view when the coroutine completes and does not verify that the view is still bound to the same package/user.
  • If component aliases or launchers are toggled through manager/…/PackageManager.kt, verify the desired process behavior: setComponentEnabled() uses PackageManager.DONT_KILL_APP, so state changes avoid restarting the app even when components become enabled or disabled.

Risks

  • manager/…/AppIconCache.kt keys icons by package name, user id, and size, but not by application version or icon resource state. If an app updates its icon while the manager process lives, cached bitmaps can remain stale until the cache entry is evicted or the process restarts.
  • manager/…/ShizukuSystemApis.kt converts RemoteException from package and permission APIs into RuntimeException. If these methods are called directly from UI paths without their own error boundary, a transient Shizuku/system-service failure can crash the manager rather than producing an empty or denied result.
  • manager/…/RecyclerView.kt captures padding values in the FixedAlwaysClipToPaddingEdgeEffectFactory constructor. If a list changes padding after installing the factory, overscroll sizing and translation can become visually misaligned because the edge effect continues using the old fixed values.