Skip to content

[garnet][13.1] SystemUI main thread blocks 23–75 s in BluetoothDevice.getBatteryLevel() when a BT headset/watch connects during an incoming call (fix exists on 16.0, missing on 17.0) #1285

Done

Description

@hanjungwoo3

Device codename

garnet

crDroid version

crDroid 13

Exact version / build date

13.1 / 2026-11-20 (crDroidAndroid-17.0-20261120-garnet-v13.1.zip, official)

What's wrong?

When a Bluetooth device that supports HFP (in my case an Amazfit Bip 6 watch; any headset that auto-connects on incoming calls should do) connects while a phone call is ringing, SystemUI's main thread blocks for 23–75 s inside BluetoothDevice.getBatteryLevel(). While it is blocked nothing in SystemUI runs: the keyguard occlude animation never finishes, NOTIFY_STARTED_WAKING_UP is not processed, NotificationShade is never drawn (WindowManager: Timeout waiting for drawn: undrawn=[Window{… NotificationShade}]), and the user sees a frozen uniform white/grey scrim (or a black screen) and cannot answer the call. In the worst case it ends in an ANR:

Subject: executing service com.android.systemui/.doze.DozeService, waited 74919ms
"main" prio=5 tid=1 Runnable
  at android.os.Parcel.nativeMarkForBinder(Native method)
  at android.bluetooth.IBluetooth$Stub$Proxy.getBatteryLevel(IBluetooth.java:2984)
  at android.bluetooth.BluetoothDevice.getBatteryLevel(BluetoothDevice.java:1892)
  at com.android.systemui.ax.AxPlatformObservers.access$broadcastBluetoothState(unavailable:99)
  at com.android.systemui.ax.AxPlatformObservers$bluetoothCallback$1.onBluetoothDevicesChanged(unavailable:6)
  at com.android.systemui.statusbar.policy.BluetoothControllerImpl$H.handleMessage(unavailable:76)
  at android.os.Looper.loop(Looper.java:397)

This is the real cause of #1221 (closed as fixed in 13.1). That report was mis-titled by me as a keyguard transition problem; the 13.1 "not reproducible" result was a false negative because the watch happened to be out of range during the test. Full analysis with per-incident evidence is in #1221 (comment). I am opening a new issue because the comments landed on an already closed issue.

Root cause (code): BluetoothControllerImpl dispatches onBluetoothDevicesChanged on the main looper (H(mainLooper)). AxPlatformObservers.broadcastBluetoothState() (from 5aca8c3a "SystemUI: Adding platform hooks") iterates all cached devices and calls device.getName() / device.getBatteryLevel() / connection-state getters, each a synchronous binder into com.android.bluetooth, which is busy setting up the HFP link and a BatteryService GATT client at exactly that moment. BluetoothControllerImpl.getBatteryLevel() / updateBattery() (06990a61 "SystemUI: Show bluetooth battery level") has the same pattern.

Steps to reproduce

  1. Pair a watch/headset that auto-connects HFP ("Phone calls" profile) when a call comes in, keep it in range.
  2. Lock the phone, screen off (dozing).
  3. Call the phone from another line.
  4. Observe: the screen wakes to a frozen white/grey (or black) frame, no in-call UI, no lockscreen, call cannot be answered for 20–75 s; logcat shows Choreographer: Skipped NNNN frames from the SystemUI pid or an ANR as above.
  5. Control: disable the watch's "Phone calls" profile in its Bluetooth device settings (HEADSET policy changed: 100 -> 0) → same call flow, in-call UI appears in <0.5 s, no frame skips, no ANR (verified 3 calls, #1221 (comment)).

Reproduced on 13.0 (2026-10-18) and 13.1 (2026-11-20) with both SKT T-phone and Google Phone as dialer; dialer does not matter.

Logs (logcat / build log)

Full ANR trace (PII redacted) and logcat -b all captures of four incidents: https://gist.github.com/hanjungwoo3/1031d9dbebc37642fc74764e9c540ab7 — systemui-anr-20261127-1210-dozeservice-redacted.txt is the ANR above.

incident BT device connected HFP during call? SystemUI main-thread block
11-02 12:26 (13.0, T-phone, white scrim 23 s) yes (HeadsetStateMachine … accept incoming connection 12:26:47) Skipped 2747 frames (~23 s @120 Hz)
11-06 15:19 (13.0, Google Phone, black screen) yes (bluetooth route added 15:19:03) Skipped 6691 / 7026 frames (~56–59 s)
11-19 01:10 (13.1 11-18, 2 test calls, no stall) no (watch out of range) max Skipped 155 frames
11-27 12:07 (13.1 11-20, white scrim) yes (12:07:31 HEADSET … STATE_CONNECTED) ANR, waited 74919ms
11-27 16:11 (13.1 11-20, watch HFP profile disabled, 3 calls) no (rejected by policy) none; in-call UI 0.07 s after START

Screenshots, videos, or extra context

Suggested fix — the patch already exists, it is only missing on 17.0:

  • Evolution-X ea5de6f58 "SystemUI: Fix UI freeze on Bluetooth state changes" (Onelots, 2026-08-23) debounces the Bluetooth callbacks (250 ms) and moves the per-device queries in broadcastBluetoothState() to a single background executor. Its commit message describes this exact symptom ("On BT toggles or incoming calls the adapter fires these callbacks in bursts while the BT service is busy, stalling SystemUI's main thread for seconds").
  • crDroid 16.0 already carries it: 14269cd24.
  • crDroid 17.0 does not: packages/SystemUI/src/com/android/systemui/ax/AxPlatformObservers.kt at 17.0 HEAD (26110be5e) still calls device.getBatteryLevel() synchronously inside broadcastBluetoothState(). The surrounding code is identical between the branches, so the cherry-pick should apply cleanly.

Please cherry-pick 14269cd24 from 16.0 to 17.0. Optionally also move BluetoothControllerImpl.getBatteryLevel() / updateBattery() off the main thread (or read the cached METADATA_MAIN_BATTERY value), since that path has the same pattern on both branches and could stall the same way with a slow Bluetooth service.

Workaround for affected users until then: disable the "Phone calls" (HFP) profile for the watch/headset in its Bluetooth device page. Note it also stops the watch from alerting on incoming calls, so it is not a long-term option. I can test a 17.0 build with the cherry-pick on garnet.

Before submitting

Metadata

Metadata

Labels

crDroid 13device:garnet

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions