CVE-2026-59002 AI-generated analysis
platform/frameworks/base, services/usb (UsbDeviceManager, UsbHandler / UsbHandlerHal timeout handling)
Adds a lock-screen check to the two USB function-switch timeout handlers in UsbDeviceManager. When the screen is locked, the recovery path now sets UsbManager.FUNCTION_NONE (charging only) instead of the user's default unlocked USB functions (mScreenUnlockedFunctions).
Root cause
In services/usb/java/com/android/server/usb/UsbDeviceManager.java, two handlers recovered from a USB HAL function-switch timeout by unconditionally calling setEnabledFunctions(mScreenUnlockedFunctions, false, operationId): the MSG_SET_FUNCTIONS_TIMEOUT handler (when msg.arg1 != 1) and the MSG_FUNCTION_SWITCH_TIMEOUT handler (when mCurrentFunctions != UsbManager.FUNCTION_ACCESSORY). mScreenUnlockedFunctions holds the default USB configuration the user chose in Developer Options (for example PTP, MIDI, UVC or RNDIS). Neither handler consulted mScreenLocked, so a timeout while the device was locked would enable a data-transfer USB function without user interaction. The commit message calls this a follow-up to an incomplete fix for CVE-2024-43085.
How the fix works
- UsbDeviceManager.java, inner handler class (next to getScreenUnlockedFunctions()): adds a new protected helper isScreenLocked() that returns the existing mScreenLocked field.
- UsbDeviceManager.java, handleMessage case MSG_SET_FUNCTIONS_TIMEOUT: inside the existing `if (msg.arg1 != 1)` block, replaces the unconditional setEnabledFunctions(mScreenUnlockedFunctions, false, operationId). If !isScreenLocked(), it calls setEnabledFunctions(mScreenUnlockedFunctions, false, operationId); otherwise it calls setEnabledFunctions(UsbManager.FUNCTION_NONE, false, operationId).
- UsbDeviceManager.java, handleMessage case MSG_FUNCTION_SWITCH_TIMEOUT: in the else branch of `if (mCurrentFunctions == UsbManager.FUNCTION_ACCESSORY)`, applies the same isScreenLocked() gate and falls back to UsbManager.FUNCTION_NONE when locked. The accessory branch (notifyAccessoryModeExit) is unchanged.
- Single commit touching one file (18 insertions, 5 deletions). The commit message lists two Cherrypick-From sources.
Completeness
- Covers both timeout recovery paths named in the commit message: MSG_SET_FUNCTIONS_TIMEOUT with msg.arg1 != 1, and MSG_FUNCTION_SWITCH_TIMEOUT for non-accessory current functions.
- The locked-screen fallback is UsbManager.FUNCTION_NONE, not getChargingFunctions() (which per the context can return FUNCTION_ADB or FUNCTION_MTP). No data function is enabled on this path while locked.
- The fix is a point check at the two call sites. It does not change setEnabledFunctions itself or any other site that applies mScreenUnlockedFunctions. The material does not show those other sites, so it cannot tell whether they already gate on lock state.
- The MSG_SET_FUNCTIONS_TIMEOUT path with msg.arg1 == 1 and the accessory branch of MSG_FUNCTION_SWITCH_TIMEOUT are untouched. Neither applied mScreenUnlockedFunctions before the fix either.
- No test was added (Test: compile check only).
Behavior changes
- When a USB function switch times out while the screen is locked, the USB gadget is now set to FUNCTION_NONE (charging only) instead of the user's Developer Options default. The default is applied only when the screen is unlocked.
- No behavior change when the screen is unlocked, or when mScreenUnlockedFunctions is already FUNCTION_NONE.
- Adds a new protected method isScreenLocked() to the handler class.
Per major
- Android 14: Same fix: platform/frameworks/base 4b1deca64d0e in android-security-14.0.0_r31. The hunks are identical at different line offsets (isScreenLocked() at ~1531, timeout cases at ~2124 and ~2157).
- Android 15: Same fix: platform/frameworks/base 994982614367 in android-security-15.0.0_r19 (the reference commit analysed here).
- Android 16: Same fix: platform/frameworks/base d5498e6af80f in android-security-16.0.0_r10. The hunks are identical at different line offsets (~1762, ~2355, ~2388).
- Android 17: Same fix: platform/frameworks/base 7ae3d28551ae in android-security-17.0.0_r3. The hunks are identical at different line offsets (~1963, ~2554, ~2592).
Unknowns
- How mScreenLocked is kept up to date (the ScreenObserver callbacks), and whether other call sites that apply mScreenUnlockedFunctions already check it. Those parts of the file are not in the material.
- The exact host-side conditions that make the HAL function switch time out are not shown.
- The contents of the two internal Cherrypick-From commits are not shown.
- What the original CVE-2024-43085 fix changed, and why it was incomplete, is not in the material beyond the commit message statement.