Skip to content

Android app: the programmer after a reboot, with nobody at the device - #99

Merged
compot-dev merged 1 commit into
mainfrom
android-usb-boot
Nov 17, 2026
Merged

compot-dev merged 1 commit into
mainfrom
android-usb-boot

Conversation

@compot-dev

Copy link
Copy Markdown
Collaborator

A programmer that stays plugged in was not the app's after a reboot, so remote access needed somebody at the device to replug it.

Cause. Android finds the programmer early in the boot, before the user's storage is unlocked. Then it sees only direct-boot-aware components, so it did not find UsbAttachActivity, the app chosen with Always, and did not grant the programmer.

Fix.

  • UsbAttachActivity is android:directBootAware="true". Before the unlock it only finishes (the system has granted the programmer by then; the settings are not readable yet). The service comes with BOOT_COMPLETED, as before.
  • README (en, ru, zh-CN): after an update of the app Android takes the programmer back until a replug or a reboot (adb reboot will do).
  • RemoteService: the addresses() comment back over its method (Qodo on Android app: remote access (web mode, camex tunnel, optional password) #98).

Checked.

  • TV box with Android 10, CH341A with a BY25Q64AS plugged in, the app updated over adb (grant gone), then a reboot. Android started UsbAttachActivity at the attach, and a Detect through a camex 4.0.0 tunnel found "CH341A with BY25Q64AS, 8 MB", nobody at the device. Before the fix the same steps gave "no access".
  • tests/run.sh, Android assembleDebug lintDebug assembleRelease, tests/android/remote-e2e.sh on API 34 and 21: 11/11.

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

Restore Android USB programmer access after reboot

🐞 Bug fix 📝 Documentation 🕐 10-20 Minutes

Grey Divider

AI Description

• Make the USB attach activity visible during direct boot so Android restores the programmer grant
 after reboot.
• Avoid reading locked user settings; the existing boot receiver starts remote access later.
• Document the temporary loss of access after app updates in three languages.
Merge Risk 🟡 Medium

Evidence: Partial. The provider did not establish the exact full-PR diff revisions. The exact full-PR diff revisions are unavailable. The report lists 18 more gaps.

Blast radius 🔴 High 💥 2 capabilities

  • 2 affected capabilities span independent functional scopes: Android remote programmer access, Firmware and application version reporting.
  • The changed manifest/activity path preserves Android's USB association and connects to the existing BOOT_COMPLETED-to-RemoteService path.
  • These are execution hops for one bounded outcome: an operator reaches the app's remote page and operates the attached programmer without someone at the device, rather than independent capabilities.
  • The changed constant feeds two presentation/reporting surfaces for the same bounded outcome: identifying the running software version.
  • These are consumers of one version-reporting capability, independent of the Android USB attach and remote-access lifecycle.
Sources

android/app/src/main/AndroidManifest.xml[76-76]

            android:directBootAware="true"

src/main.c[45-47]

#define _VER	"1.47.4"

const char *ms_version = _VER;

android/app/src/main/java/org/openipc/microsnander/UsbAttachActivity.java[26-29]

        if (Build.VERSION.SDK_INT >= 24 && !getSystemService(UserManager.class).isUserUnlocked()) {
            finish();		// granted already by Android, which started this
            return;
        }
Behavioral complexity 🟡 Medium 🧩 Interacting branches

  • Before: UsbAttachActivity handled the USB attach event through one settings-dependent path.
  • After: the activity is eligible during the pre-unlock direct-boot state and takes an early return, while the post-unlock/boot-completed state uses the existing Settings.active and RemoteService path.
  • Before condition: one attach path could read settings and start the service or open the app.
  • After condition: correctness requires the pre-unlock branch to preserve the USB grant, avoid credential-protected settings access, and coordinate with BOOT_COMPLETED so the enabled service starts exactly after the user becomes available.
  • This is a new interaction between Android user-unlock state, USB association, and boot startup; it is not merely routine use of UserManager.
  • The relevant branch is new, while the service and boot receiver behavior are existing infrastructure.
Sources

android/app/src/main/AndroidManifest.xml[76-76]

            android:directBootAware="true"

android/app/src/main/java/org/openipc/microsnander/UsbAttachActivity.java[15-20]

 *
 * A programmer that stays plugged in is found early in a boot, before the
 * user's storage is unlocked: Android then sees only direct-boot-aware
 * components, so this one is, or the default would not be found and the
 * programmer would not be granted. At that time it only finishes (the
 * settings are not readable yet); the service comes with BOOT_COMPLETED.

android/app/src/main/java/org/openipc/microsnander/UsbAttachActivity.java[26-29]

        if (Build.VERSION.SDK_INT >= 24 && !getSystemService(UserManager.class).isUserUnlocked()) {
            finish();		// granted already by Android, which started this
            return;
        }
Potential damage 🟡 Medium 🩹 Temporary loss

  • The plausible failure is loss of remote programmer access after reboot, not corruption of flash contents or an external financial effect.
  • Replugging or rebooting is documented as restoring the Android grant after an app update; a code rollback alone does not necessarily repair the Android grant state.
  • The service-start condition also requires the user-enabled setting.
  • The remote page can operate the programmer when the service is running, as shown by the service's documented programmer access path.
  • Recoverable after a supported replug or reboot, or after restoring the app and repeating the Android association.
  • Existing persistent programmer state is not shown to be modified by this change.
  • Manual intervention may be required if boot delivery or grant persistence fails.
Sources

README.md[506-508]

- Plug the programmer in once and choose the app with **Always**: from then on Android gives
  it to the app on every plug-in and after a reboot, with nobody at the device. After an update
  of the app Android takes it back until a replug or a reboot (`adb reboot` will do).
Assessed commit 36ca657 > Snapshot assessment: the current PR revision could not be verified.
Diagram

graph TD
  USB["USB programmer"] --> Resolver["Android USB resolver"] --> Attach["USB attach activity"] --> Unlocked{"User unlocked?"}
  Unlocked -- "No" --> Finish["Finish; retain grant"]
  Unlocked -- "Yes" --> Normal["Existing attach handling"]
  Boot["Boot receiver"] --> Remote["Remote service"]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Start remote access during direct boot
  • ➕ Could make remote access available before user unlock.
  • ➖ Requires device-protected settings and a direct-boot-capable service path.
  • ➖ Expands security and lifecycle scope beyond restoring the USB grant.

Recommendation: Keep the PR's narrow approach: make only the USB handler direct-boot-aware, then rely on the existing BOOT_COMPLETED path for the service. Pre-unlock remote access is a separate capability with substantially more risk.

Files changed (8) +29 / -4

Bug fix (2) +13 / -0
AndroidManifest.xmlExpose the USB attach activity during direct boot +1/-0

Expose the USB attach activity during direct boot

• Marks UsbAttachActivity as direct-boot-aware so Android can find the default handler for a programmer detected before user unlock.

android/app/src/main/AndroidManifest.xml

UsbAttachActivity.javaSkip settings-dependent attach handling before unlock +12/-0

Skip settings-dependent attach handling before unlock

• On Android 7.0 and later, the activity finishes when the user is locked, avoiding credential-protected settings access after Android grants the USB device. After unlock, the existing service-or-app behavior remains unchanged.

android/app/src/main/java/org/openipc/microsnander/UsbAttachActivity.java

Documentation (5) +15 / -3
CHANGELOG.mdRecord the Android reboot-access fix in 1.47.4 +9/-0

Record the Android reboot-access fix in 1.47.4

• Adds release notes explaining why the USB grant was lost after reboot, how the fix restores it, and why app updates still require a replug or reboot.

CHANGELOG.md

README.mdClarify USB access after app updates +2/-1

Clarify USB access after app updates

• Explains that an app update temporarily revokes programmer access until a replug or reboot, including 'adb reboot'.

README.md

README.ru.mdAdd the app-update access caveat in Russian +2/-0

Add the app-update access caveat in Russian

• Documents the need to replug or reboot after an app update to regain programmer access.

README.ru.md

README.zh-CN.mdAdd the app-update access caveat in Chinese +1/-1

Add the app-update access caveat in Chinese

• Documents the temporary loss of programmer access after an app update and the replug or reboot remedies.

README.zh-CN.md

RemoteService.javaPlace the address comment on its method +1/-1

Place the address comment on its method

• Moves the IPv4 address documentation from listening() to addresses(), the method it describes. Runtime behavior is unchanged.

android/app/src/main/java/org/openipc/microsnander/RemoteService.java

Other (1) +1 / -1
main.cBump the release version to 1.47.4 +1/-1

Bump the release version to 1.47.4

• Changes the version constant from 1.47.3 to 1.47.4 for this release.

src/main.c

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Tip of the day
💡 Did you know, you can enable the Remediation agent and Qodo fixes findings in a dedicated fix PR

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@compot-dev
compot-dev merged commit 471e47d into main Nov 17, 2026
9 checks passed
@compot-dev
compot-dev deleted the android-usb-boot branch November 17, 2026 19:46
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.

1 participant