Fix the ANR in panel when changing volume continuously
When users open volume panel and keep on changing the volume slider for
a while, the panel starts to defer the slider updating, and finally gets
stuck and causes an ANR.
Root cause:
Volume panel has four volume adjusting slices. Each of them registers
a broadcast receiver to listen to the volume changed and muted events.
However, when the media volume changes, AudioManager will send four
broadcasts (music, assistant, accessibility, tts) to every receiver, and
each of them will reload slice four times. Thus, one media volume
changed event will lead to 16 (4*4) UI updates. Consequently, keeping on
sliding the volume bar will trigger hundreds of broadcasts and UI
updates, which makes the system busy and getting stuck.
Solution:
Introduce a VolumeSliceHelper to integrate the broadcasts of the volume
slices specifically.
1. Only register one broadcast receiver to reduce the broadcast loading
since the four slices are listening to the same signal.
2. Filter the only one eligible broadcast among the multiple concurrent
ones, and then relay it to the registered slice.
3. Listen to one more action STREAM_DEVICES_CHANGED_ACTION to update the
volume panel when audio output device changes.
Test: robotest, visual
Bug: 144134209
Bug: 160489394
Change-Id: I780b9eee35802b19a5f0ab0a7d07bd3e081f5556
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 66f7207..6c8151e 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -3416,6 +3416,11 @@
android:permission="android.permission.MANAGE_SLICE_PERMISSIONS"
android:exported="true" />
+ <receiver
+ android:name=".slices.VolumeSliceRelayReceiver"
+ android:permission="android.permission.MANAGE_SLICE_PERMISSIONS"
+ android:exported="true" />
+
<!-- Couldn't be triggered from outside of settings. Statsd can trigger it because we send
PendingIntent to it-->
<receiver android:name=".fuelgauge.batterytip.AnomalyDetectionReceiver"