Skip to content

Automation and Intents

kerneldroid edited this page Nov 30, 2026 · 1 revision

Automation and Intents

Nightzuku includes an authenticated control plane for starting, stopping, restarting, querying, and configuring the service from automation apps (Tasker, MacroDroid, Automate), ADB scripts, or third-party apps.

It is disabled by default. Enable and manage it in Settings → Automation & Intents.


For users

Enable and configure

  1. Open Settings → Automation & Intents and toggle the feature ON.
  2. Review the security options:
    • Broadcast Intents — disable this if you only want app-to-app ContentProvider control.
    • Require HMAC-SHA256 (recommended, on by default) — requires replay-protected signed requests and rejects raw keys.
    • Strict sender check (Android 14+) — requires package-bound keys to match the actual sending app's package and signing certificate.
  3. Tap New key to create an isolated 256-bit key:
    • Choose a profile name (for example, Tasker).
    • Select only the scopes you need (start, stop, restart, status, nightdog).
    • Optionally bind the key to a specific package name.
    • Uncheck HMAC-SHA256 only only if your automation tool cannot compute HMAC-SHA256 and you also disabled Require HMAC-SHA256 globally.
  4. Copy the generated secret immediately — Nightzuku stores it encrypted with Android Keystore and will not show it again. You can rotate or revoke any key at any time.
  5. Tap Reload after changing external state or to clear rate-limit lockouts and re-sync the broadcast receiver.

Example: Tasker / MacroDroid / ADB

Action: kerneldroid.nightzuku.action.CONTROL
Component: kerneldroid.nightzuku/moe.shizuku.manager.control.NightControlReceiver

Supported command values: start, stop, restart, toggle, status, nightdog_enable, nightdog_disable.
Optional extras:

  • mode: auto (default), root, or adb
  • pause_nightdog: true (default) or false — pauses NightDog when stopping so the watchdog does not fight manual stops.

ADB example (scoped-key mode, when HMAC-only is disabled):

adb shell am broadcast \
  -a kerneldroid.nightzuku.action.CONTROL \
  -n kerneldroid.nightzuku/moe.shizuku.manager.control.NightControlReceiver \
  --es command status \
  --es key_id nk_xxxxxxxxxxxx \
  --es key <your_secret>

For developers

1. Request access from the user

Prefer the Control ContentProvider (content://kerneldroid.nightzuku.control) over broadcast intents. Binder enforces your app's UID and package name at the kernel level, and Nightzuku pins your grant to your APK signing certificate SHA-256.

Launch the consent Activity:

val intent = Intent("kerneldroid.nightzuku.intent.action.REQUEST_CONTROL_ACCESS").apply {
    putStringArrayListExtra("scopes", arrayListOf("start", "stop", "status"))
    putExtra("request_key", true) // optional: also issue a one-time 256-bit HMAC key
    putExtra("reason", "Start Nightzuku automatically when needed")
}
launcher.launch(intent)

When the user approves (RESULT_OK), the result Intent contains:

  • granted (Boolean)
  • key_id (String)
  • scopes (ArrayList<String>)
  • provider_authority ("kerneldroid.nightzuku.control")
  • action_control ("kerneldroid.nightzuku.action.CONTROL")
  • client_key (String, returned once if request_key = true was approved)

2. Call the Control ContentProvider

val uri = Uri.parse("content://kerneldroid.nightzuku.control")

// Inspect authorization state
val info = contentResolver.call(uri, "describe", null, null)

// Execute a command
val extras = Bundle().apply {
    putString("command", "start")
    putString("mode", "auto")
}
val reply = contentResolver.call(uri, "execute", null, extras)
val ok = reply?.getBoolean("ok") == true
val code = reply?.getString("code")
val running = reply?.getBoolean("running") == true

For challenge-response HMAC via Provider:

  1. Call "challenge" → receive nonce (single-use, 30 s TTL) and expires_at.
  2. Sign canonical payload "<command>|<timestamp>|<nonce>|<mode>" with HMAC-SHA256(client_key).
  3. Call "execute" with command, mode, key_id, timestamp, nonce, and lowercase hex signature.

3. HMAC-SHA256 Broadcast Intents

For apps or scripts sending kerneldroid.nightzuku.action.CONTROL:

  • Extras: command, mode (optional, default auto), key_id, timestamp (epoch seconds, ±60 s window), nonce (unique, ≥ 8 chars), signature (hex HMAC-SHA256).
  • Canonical string: "${command.lowercase()}|$timestamp|$nonce|${mode.lowercase()}".
  • On Android 14+, call BroadcastOptions.makeBasic().setShareIdentityEnabled(true) if using a package-bound key.
  • Use sendOrderedBroadcast to receive resultCode (RESULT_OK / RESULT_CANCELED) and structured resultExtras (ok, code, message, running, uid, version, nightdog_enabled).

See the full protocol specification in docs/automation-and-intents.md.