Skip to content

Add a Wear OS frontend for the Magisk app - #10275

Open
jmcjm wants to merge 12 commits into
topjohnwu:masterfrom
jmcjm:wear-pr
Open

jmcjm wants to merge 12 commits into
topjohnwu:masterfrom
jmcjm:wear-pr

Conversation

@jmcjm

@jmcjm jmcjm commented Nov 23, 2026

Copy link
Copy Markdown

Summary

This adds :wear, a second frontend for the Magisk app, written for round Wear OS screens with
Wear Compose Material 3. The phone UI is unusable on a ~1.4" round display, and there is no
reasonable workaround: a global wm density change breaks the system UI, and per-app DPI hooks
can't reach the Magisk app because Zygisk deliberately skips it.

:wear is a separate APK with the same application ID, namespace, ABI list and signing as the
phone app (it goes through setupMainApk()), so magiskd treats it as the manager and either APK
can manage the same install. It reuses :core and the phone app's view models unchanged; only the
screens are new.

Tested on a Samsung Galaxy Watch 4 (SM-R870, 450×450 round, One UI 6 Watch / Wear OS 5, API 34,
32-bit userspace).

Architecture

The series is 13 commits, each of which compiles on its own:

  1. :shared library, extracted from :apk (Move app view models to a shared module).
    View models, the view model factory, Route, the terminal emulator, FlashUtils and the small
    UI state types they need move from :apk to a new Android library. This is a pure move:
    packages and class names are unchanged, the view models are 100% renames in git, and
    AppSortBy / ThemeState are split out of their Compose files so :shared does not pull in
    phone Material 3. The only code edit is that FlashUtils targets the component of the app's
    own launch intent instead of referencing :apk's MainActivity. :apk behaves exactly as
    before.
  2. :wear module (Add Wear OS app module), depending on :core and :shared. Wear Compose
    1.7.2 (foundation, material3, navigation3) and androidx.wear:wear-input are added to the
    version catalog, plus junit for JVM unit tests. minSdk is 25 for this module only, because
    Wear Compose requires it.
  3. build.py wear (Build the Wear OS app in build.py): a new action that writes
    out/app-wear-<debug|release>.apk. all now builds it as well, so CI produces both APKs; the
    workflow uploads the Wear mapping and native debug symbols as a separate artifact.
    docs/build.md mentions the new action. ./build.py app is unchanged.
  4. Shared security-relevant code (Share display name and startup checks): the sanitizer and
    timed provider query for the display name of an external flash request, and the
    unsupported-install startup checks, move from the phone MainActivity to :shared, so the
    Wear app runs the same code instead of a copy. The sanitizer gets JVM tests. The phone app keeps
    its dialogs and behaves as before.
  5. Wear screens (8 commits): theme, Navigation3 back stack with the Wear swipe-to-dismiss scene
    strategy, file picker, then Home, Superuser, Grant, Logs, Modules, Install/Flash/Restore,
    Settings and DenyList.
  6. Update APK selection in :core (Pick the update APK for the kind of device).

The one non-string change in :core

Apart from new strings (English and Polish in app/core/src/main/res, a few non-translatable ones
in resources.xml), the only change to :core is the update asset selector in NetworkService.
Without it, the existing selector takes the first non-debug APK of a release, so as soon as a
release carries both APKs:

  • the Wear app would offer the phone APK as its own update (including through the background update
    job and its notification), and
  • the phone app could pick the Wear APK.

With the change, a device with FEATURE_WATCH only accepts an asset whose name contains wear
(case-insensitive), and every other device skips such assets. If a release has no APK for the
device, no update is offered (an empty UpdateInfo) instead of the previous !! failure, and the
stable-to-beta auto switch only happens for a real version code. The debug channel looks for
app-wear-debug.apk on watches and app-debug.apk elsewhere. This can't live in :wear, because
update checking, the update job and the download subject are all in :core.

What is deliberately not shared

  • Screens and components. Wear Material 3 and phone Material 3 are different component sets
    with different layout models (scaling/transforming lazy columns, edge buttons, curved time text,
    swipe-to-dismiss instead of a back button). Sharing composables would mean if (watch) in every
    screen, which is the thing this split avoids. AppIcon is a small, separate implementation on
    Wear because it draws each icon once at its small display size and caches the bitmap.
  • Navigator and LeaveInterruptedScreen. WearNavigator keeps the phone Navigator's
    push/pop/save behaviour (same duplicate-push guard, same root protection, same saver), but it
    also owns Wear-only state: results of the in-app file picker screen, and the stack of screens
    that currently block swipe-to-dismiss. Back from NavDisplay goes through that stack, so a
    running module action or flash asks for confirmation deterministically instead of depending on
    the order of back handlers; on the root, swipe is left to the system, which closes the app.
    Moving Navigator to :shared would put this Wear state and back semantics into the phone
    class, or need an extra abstraction layer over a small class. LeaveInterruptedScreen is a
    5-line private composable typed on the navigator; it is duplicated rather than routed through a
    new common interface.
  • Dialogs. The phone app's dialog helpers are phone Material 3; Wear uses AlertDialog with
    an EdgeButton. The behaviour is the same (external flash confirmation with sanitized name and
    source, unsupported-install messages shown one by one, env fix confirmation, exit confirmation
    for a running job).

Feature parity with the phone app

Area Phone app Wear app
Home: version, state, Zygisk, ramdisk Yes Yes
Env fix prompt Yes Yes
Unsupported-install messages, external flash confirmation Yes Yes (shared code)
Superuser list, per-app details (restrict, notifications, logs, revoke) Yes Yes
Grant root ahead of time Yes Yes, with a full/restricted chip
Biometric su authentication setting Yes No (UI-only gate, default off)
Superuser and Magisk logs, clear Yes Yes
Save logs to a file Yes No
Modules: enable/disable, remove/restore, action, install from zip Yes Yes
Module online updates Yes No
Install: patch file, direct install, inactive slot (A/B) Yes Yes
Install: Pixel firmware suggestions, Googlebook recovery images, USB output Yes No (not relevant on a watch)
Restore images (uninstall) Yes Yes, with backup SHA1 and long-press to start
Settings: Zygisk, DenyList, systemless hosts, restrict new grants, su notification, mount namespace, update check/channel/custom URL, DoH Yes Yes
Settings: language, theme/colour, download path, multi-user mode Yes No
DenyList Per process Whole app (toggleAll); per-process picking stays on the phone
App self-update download from Home Yes No dialog; the background update job and notification come from :core
Reactive su request prompt Removed upstream in v31.1 Not present either

Wear-specific bits:

  • File picker. Most watches have no real document picker. On Wear OS, ACTION_OPEN_DOCUMENT
    resolves to com.google.android.wearable.frameworkpackagestubs, a stub that only says that no
    app can handle the action. The picker therefore resolves the handlers itself, skips known stub
    packages (the Wear and AOSP framework package stubs), and pins the intent to a real picker if
    one exists. Otherwise it opens an in-app screen that lists matching files in the Download folder
    through the root shell. The app creates the destination file in its cache and root only writes
    into it, because a file created by the root shell gets an SELinux level without the app's
    categories, and the app could neither open nor delete it.
  • Custom update channel URL is typed through RemoteInput (system keyboard).
  • Flashing and restore keep the screen on, so the app stays in the foreground and is not killed
    halfway through. A boot image flash or patch can't be left; a module zip or a module action can be
    left after confirming, like on the phone.

Testing

Builds (JDK 25, ONDK r30.2, on this branch):

  • compileDebugKotlin for :apk, :shared and :wear at each of the 13 commits: all pass.
  • ./build.py app, ./build.py wear, ./build.py -r wear: pass. The release Wear APK goes
    through R8 and has uses-feature android.hardware.type.watch; the phone APK does not.
  • ./gradlew test: 27 JVM tests, 0 failures (:shared DisplayNameTest; :wear DocumentPicker,
    RootFiles, HomeStatus, BackupInfo, RootLabel).
  • ./gradlew lint: fails on master already. Compared with master, the only new errors are
    MissingTranslation for the new strings (English and Polish only, as new strings are usually
    added).

On the watch (Galaxy Watch 4 SM-R870, One UI 6 Watch, API 34), with Magisk built from this tree
and the boot image patched with its binaries:

  • Install of the Wear APK; magiskd accepts it as the manager (no signature mismatch).
  • Home status (version, Zygisk, ramdisk) and the shortcuts.
  • Superuser: list, per-app details, granting root ahead of time from the Grant screen; root
    requests from granted apps work, ungranted ones are rejected as in v31.1.
  • Logs: su log and Magisk log, switching between them.
  • Modules: list and details, including long names and descriptions.
  • Install and module zip: "Patch firmware / image" and Modules "+" reach the in-app storage list
    instead of the framework stub.
  • Settings and DenyList screens, update channel dialog.

Not exercised on the device: an actual patch or direct install through the app (the boot image on
the test watch is built by an external pipeline), restore images (no stock backup on that watch),
and module action output.

Screenshots

Galaxy Watch 4, round-masked. The version string in the first screenshot comes from a local
config.prop.

Home
Home
Superuser
Superuser
Grant
Grant
Logs
Logs
Modules
Modules
Module details
Module details
Install
Install
Settings
Settings

Notes for maintainers

  • Release assets. To let the Wear app update itself, a release needs an extra APK whose name
    contains wear, for example Magisk-Wear-v31.2.apk, next to the phone APK (whose name must
    not contain wear). Canary/debug releases need app-wear-debug.apk next to app-debug.apk.
    Releases without a Wear asset simply offer no update on watches.
  • Custom channels keep using the single link from the update JSON, so a custom channel used
    on a watch must point at a Wear APK.
  • CI. .github/workflows/build.yml runs ./build.py -vr all and ./build.py -v all, and the
    Windows/Linux test builds run build.py ... all, so :wear is built in every existing job
    without new steps. The only workflow change is the extra symbols artifact for app/wear. The
    AVD tests still install and test the phone APK only.
  • Strings. New strings are in app/core/src/main/res/values/strings.xml (prefixed wear_)
    with Polish translations; other locales fall back to English.

AI disclosure

Written with AI assistance (Claude Opus 5.5), reviewed, built and tested on the device by me.
Each commit carries an Assisted-by: Claude Opus 5.5 trailer, as AGENTS.md asks.

@canyie

canyie commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

Is it possible to merge the wear os edition into the phone version so just a single app works on both setup?

@jmcjm

jmcjm commented Nov 27, 2026 •

Copy link
Copy Markdown
Author

Yes, that's doable, and it would actually simplify the PR: the asset selector change in NetworkService, the second release asset and build.py wear would all go away, and hiding/stub updates keep working unchanged since there's still one APK.

The plan would be to turn :wear into a library module included by :apk, with MainActivity choosing the UI tree at startup (FEATURE_WATCH). The screens stay separate, only the entry point branches. Wear Compose needs minSdk 25 while the app is on 24, so I'd use tools:overrideLibrary and gate on SDK_INT >= 25 before touching any Wear class. uses-feature watch goes away (it only matters for Play).

The cost is small: in a quick spike with :wear as a library of :apk, the release APK goes from 10,933,049 to 11,227,961 bytes (+288 KiB, +2.7%), almost all of it in classes.dex. Most of the Compose stack is already shared, so R8 only adds the Wear-specific parts.

jmcjm added 12 commits November 27, 2026 04:04
Prepare for a second frontend (Wear OS) by moving the non-UI parts of
the app out of :apk into a new :shared Android library: view models,
the view model factory, navigation routes, the terminal emulator,
flash helpers and the small UI state types they depend on. AppSortBy
and ThemeState are split out of their Compose files so :shared does
not need Material 3.

FlashUtils now targets the component of the app's own launch intent
instead of referencing MainActivity, which stays in :apk.

Packages and class names are unchanged and there is no change in
behavior.

Assisted-by: Claude Opus 5.5
Add :wear, a Wear OS frontend for the Magisk app built on the Wear
Compose Material 3 libraries. It is a library of :apk, so a single APK
serves both phones and watches; it shares :core and :shared with the
phone UI.

The main activity stays the only activity. Where useWearUi() is true
(a watch on API 25 or later, the minimum of Wear Compose), it hands its
content to WearUi instead of setting up the phone UI, and keeps running
the common splash and initialization sequence. The check matches the
watch-v25 resource qualifier, which replaces the activity theme and the
splash background on those devices. Since Wear Compose is never used
below API 25, :apk overrides the minimum SDK of those libraries.

For now the Wear UI only shows the time on a black screen; the screens
follow in later changes. JUnit is added to the version catalog for the
module's JVM unit tests.

Assisted-by: Claude Opus 5.5
Move the sanitizer and the timed provider query for the display name
of an external flash request, and the startup checks for an
unsupported install, from the phone MainActivity to :shared, so the
Wear UI runs the same security-relevant code instead of a copy. The
phone UI keeps its dialogs and behaves as before.

rememberBiometricAuth, which asks for the device credential before a
Superuser change when the setting requires it, moves to :shared as
well. It only depends on the activity result API, not on a UI kit.

The sanitizer gets JVM unit tests for control, bidi and tag
characters, the length cap and trimming.

Assisted-by: Claude Opus 5.5
Give the Wear UI its color scheme and a Navigation3 back stack shown
with the Wear swipe-to-dismiss scene strategy. WearRoute adds the
screens that only exist on Wear next to the shared Route, and
WearNavigator saves the stack like the phone UI does. Screens that are
not written yet show a placeholder.

WearUi follows the phone UI's startup and handles the flash intent.
Our own module downloads go straight to flashing; requests from other
apps are confirmed with a Wear AlertDialog like on the phone: the
display name is queried with a timeout and sanitized, its source is
shown, and overlays are hidden while it is up.

Most watches have no app for ACTION_OPEN_DOCUMENT, so the file picker
falls back to listing the download folder through the root shell. It
is also used when only a non-system app handles the action: the picker
is started without a chooser, and any installed app could otherwise
register for it and supply the file to install. The
app creates the copy in its cache and root only writes into it: a file
created by the root shell would get its SELinux level without the
app's categories, and the app could neither open nor delete it.

Assisted-by: Claude Opus 5.5
Replace the home placeholder with a screen that shows the installed
Magisk version and code, whether it is running, and the Zygisk and
ramdisk status, followed by shortcuts to Superuser, Modules, Logs,
Settings, Install and Uninstall. Without an active Magisk only Install
is offered. It reuses HomeViewModel from :shared and reloads it each
time the screen is shown, as the phone UI does for its home tab.

The screen also shows the environment fix confirmation raised by
HomeViewModel's check: it runs fixEnv, or opens Install when only a
reinstall can fix it, and shows a progress indicator while it runs.

HomeStatus.of applies the Info.Env rule (supported version code and
root) to raw values, so it is unit tested without touching Info, whose
initializer cannot run on the JVM. HomeStatus.from is the production
entry and delegates to it.

Assisted-by: Claude Opus 5.5
Replace the Superuser placeholders with a list of apps that have a
policy and a per-app detail screen. Each row shows the app icon, its
name and the kind of root it gets, with a switch that flips the policy
between Allow and Deny; tapping the row opens the details. The header
links to the grant screen and the list ends with a link to the logs.

The details toggle restricted root, notifications and logging, and
revoke the policy after a confirmation, then return to the list. Like
on the phone, changing a policy asks for authentication first when the
Superuser setting requires it, which then replaces the confirmation of
a revoke. Both
screens use one activity-scoped SuperuserViewModel, as the phone UI
does, so edits made in the details show up in the list immediately.

App icons are drawn once at their small display size and cached.
rootLabel picks the root kind label and is covered by unit tests.

Assisted-by: Claude Opus 5.5
Replace the grant placeholder with a list of apps that had no policy
when the screen opened. Tapping a row grants root and its "+" turns
into a check mark with the kind of root it got; tapping again undoes
the grant. The list ends with a switch that shows system apps.

The mode chip at the top picks between full and restricted root for
the next grant. It starts at the "restrict root capabilities" setting,
which stays unchanged: toggleGrant now takes the mode, decided when the
row is tapped, since the write happens later in the background and
must not depend on what the setting is by then. A grant asks for
authentication first when the Superuser setting requires it.

New policies reach the Superuser list through the policy change event,
as on the phone.

Assisted-by: Claude Opus 5.5
Show the Superuser log grouped by day, with a dot telling granted from
denied requests, and the Magisk log as one monospace item per parsed
entry, so long logs stay cheap to scroll. A switch at the top picks
the log; without root only the Magisk log exists, like on the phone.
Both logs list the newest entries first and can be cleared after a
confirmation.

Define the error colour in the Wear theme, so denied requests and
destructive actions share one red.

Assisted-by: Claude Opus 5.5
List the installed modules with a switch each, open their details to
remove or restore them and run their action, and install a module zip
picked from storage after a confirmation, like the phone UI. The
confirmation shows the provider of a picked file next to its name, as
for a request from another app. A reboot
button shows up once a module differs from its state when first
loaded, since changes only apply after a reboot.

The action output is shown as plain monospace text read from the
terminal emulator. A horizontal swipe dismisses the screen on Wear, so
there is no horizontal scrolling: the emulator is sized to the width
that fits and wraps long lines itself. TerminalText is reused by the
flash screen.

While the action runs, BlockDismiss turns swipe-to-dismiss off and
registers the screen's back callback with the navigator. NavDisplay's
onBack hands back to the latest blocker instead of popping, so the
exit confirmation does not depend on the order of back handlers and a
hung script can always be left. From API 36 the swipe is predictive
back, and turning it off in the scene strategy would swallow back
entirely, so it stays on there and reaches the same callback.

Assisted-by: Claude Opus 5.5
Install offers patching an image picked from storage, direct install
and, with root on A/B devices, the inactive slot with the phone UI's
warning, plus the patching options that apply to the device. Direct
install asks for confirmation first.

The flash screen shows the installer output with a progress ring on
the screen edge. While a boot image is flashed or patched it cannot be
left; a module zip can be left after confirming, like on the phone.

Restoring the images warns first and shows the SHA1 of the stock boot
backup read from Magisk's config. It only starts on a long press, and
only when the backup exists. The home view model is now owned by the
activity, so the restore screen shares it and its loading state with
the home screen.

Flashing and restoring keep the screen on, so the app stays in the
foreground and is not killed for memory halfway through.

Assisted-by: Claude Opus 5.5
Settings shows the phone UI's Magisk, Superuser and update settings
that make sense on a watch, under the same conditions and through the
same SettingsViewModel calls. Choices open a list of radio buttons in
a dialog, and the custom channel URL is typed with the system keyboard
through RemoteInput (androidx.wear:wear-input).

The DenyList switches whole apps with toggleAll; picking single
processes is left to the phone UI.

Assisted-by: Claude Opus 5.5
The app modules now have JVM unit tests (:shared and :wear), but CI
only assembles the APKs. Run testDebugUnitTest after the debug build,
which already generated the files the build reads.

Assisted-by: Claude Opus 5.5
@jmcjm

jmcjm commented Nov 27, 2026

Copy link
Copy Markdown
Author

:wear is now a library included by :apk, and MainActivity stays the only activity. On a watch (API 25+, UI_MODE_TYPE_WATCH) it hands its content and new intents to WearUi; everywhere else nothing changes. The Wear theme and splash color come from values-watch-v25, which matches that check. minSdk stays at 24, with tools:overrideLibrary for the Wear Compose libraries, since they only run behind that check.

Compared with the original version build.py wear, the extra CI artifact, the second release asset and the asset selector change in NetworkService are all gone., :core only gets new strings. The release APK grows by about 296 KiB.

While at it, I also fixed a few things in the Wear screens: the grant screen now passes the selected root mode to toggleGrant instead of temporarily changing Config.suRestrict, the file picker only uses a system document picker, and the Superuser screens ask for authentication like the phone UI.

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.

2 participants