Skip to content

feat(reboot): let reboot() take a target such as bootloader or recovery - #584

Merged
koral-- merged 2 commits into
masterfrom
feat/reboot-target
Nov 7, 2026
Merged

koral-- merged 2 commits into
masterfrom
feat/reboot-target

Conversation

@koral--

@koral-- koral-- commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

Feature

device.reboot() always sent reboot:, so there was no way to do adb reboot bootloader, recovery, sideload or fastboot. It now takes an optional target and sends reboot:<target>, which adbd passes to the device as is. Without an argument it still sends exactly reboot:, so existing callers (stf among them) are unaffected.

await device.reboot();             // reboot:
await device.reboot('bootloader'); // reboot:bootloader

Caveat, documented in the README and JSDoc: if the device refuses the target, adbd keeps the connection open and the promise doesn't settle. adb reboot <target> doesn't return either. I didn't add a timeout or AbortSignal, since that's more than the issue asks for.

Fixes #235

Verification

  • Unit tests: reboot:bootloader, reboot:recovery and reboot:sideload are sent as is, a FAIL rejects, and device.reboot() / device.reboot('recovery') send exactly reboot: / reboot:recovery. npm test: 290 passing. npm run lint is clean.
  • What each target actually did on the emulators, with this branch (adb get-state and sys.boot_completed polled every 2 s):
emulator call result
API 30 reboot() resolved true; offline at +0 s, device at +17 s, booted at +24 s; sys.boot.reason=reboot,shell
API 30 reboot('bootloader') resolved true; offline, back at +15 s, booted at +19 s, back into Android; sys.boot.reason=bootloader (an emulator has no bootloader)
API 36 reboot('bootloader') resolved true; back at +10 s, booted at +22 s, into Android; sys.boot.reason=bootloader
API 30 reboot('recovery') didn't reboot, and the promise never settled. init logged Received sys.powerctl='reboot,recovery' and then Failed to set bootloader message: failed to find /misc partition. adb -s emulator-5620 reboot recovery also hung (still running after 20 s).
  • stf (DeviceFarmer/stf master, stf local emulator-5620, adbkit from this branch's npm pack): Advanced, then Restart Device, then OK, driven with Playwright. tx.done success: true, stf logged Rebooting, the device's uptime went from 1048 s to 16 s (sys.boot.reason=reboot,shell), and stf's device unit was Fully operational again 25 s later.

Merge order

#545 (a contributor's JSDoc fix, waiting for their sign-off) rewrites the description line of the same reboot() JSDoc block. This PR leaves that line alone and adds a @param line below it, and the two merge cleanly in either order (checked with a test merge). Merging #545 first keeps the history tidier.

Review follow-up (commit 38152de)

The README still listed callback(err) for reboot(), so a JavaScript caller doing reboot(fn) would have sent the function's source as the target (reboot:() => undefined). Only a string is used as the target now. Anything else, such as undefined or a function, sends plain reboot:. The stale callback line is gone from the README, which now says reboot() takes no callback.

  • Tests: reboot(undefined) and reboot(fn) send exactly reboot:. Without the fix the function case sent reboot:() => undefined. npm test 292 passing, lint clean.
  • Emulator: reboot(function cb(err) {}) on API 36 resolved true; the device came back with uptime 9.6 s and sys.boot.reason=reboot,shell.
  • The "Puts the device into root mode" JSDoc line is still untouched, for Fix JSDoc for device.reboot() #545.

🤖 Generated with Claude Code

koral-- and others added 2 commits November 7, 2026 01:16
device.reboot() always sent reboot:, so there was no way to do
adb reboot bootloader, recovery, sideload or fastboot. It now takes an
optional target and sends reboot:<target>, which adbd hands to the
device as is. Without a target it still sends exactly reboot:.

Fixes #235

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Karol Wrótniak <karol.wrotniak@droidsonroids.pl>
The README still listed a callback as reboot()'s argument, so a
JavaScript caller doing reboot(fn) would now send the function's
source as the target. Only a string is used as the target now;
anything else sends plain reboot: as before. The stale callback line
is removed from the README.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Karol Wrótniak <karol.wrotniak@droidsonroids.pl>
@koral--
koral-- merged commit 746cc27 into master Nov 7, 2026
6 checks passed
@koral--
koral-- deleted the feat/reboot-target branch November 7, 2026 12:07
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.

Allow specifying what state the device should reboot into when calling reboot()

1 participant