Solved ANR when carrier config changed broadcast arrives
Moved broadcast receiver code into a different thread and kept
the receiver alive for a little bit longer. This will allow
onReceive to return earlier to prevent 10-seconds ANR.
Fix: 221214206
Test: Manual
Change-Id: Ie3899dce0eef12650598a3b292b938e3a06fd8d8
diff --git a/src/com/android/phone/otasp/OtaspSimStateReceiver.java b/src/com/android/phone/otasp/OtaspSimStateReceiver.java
index bb4022a..a47ab67 100644
--- a/src/com/android/phone/otasp/OtaspSimStateReceiver.java
+++ b/src/com/android/phone/otasp/OtaspSimStateReceiver.java
@@ -92,14 +92,22 @@
mContext = context;
if(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED.equals(intent.getAction())) {
if (DBG) logd("Received intent: " + intent.getAction());
- if (PhoneGlobals.getPhone().getIccRecordsLoaded() && isCarrierSupported()) {
- registerOtaspChangedHandler();
- }
+ // Allow the receiver to keep active after returning from onReceive().
+ final PendingResult result = goAsync();
+ // Do the actual work on another thread to prevent ANR.
+ new Thread(() -> {
+ if (DBG) logd("Start to process ACTION_CARRIER_CONFIG_CHANGED.");
+ if (PhoneGlobals.getPhone().getIccRecordsLoaded() && isCarrierSupported()) {
+ registerOtaspChangedHandler();
+ }
+ result.finish();
+ }).start();
}
}
- // It's fine to call mutiple times, as the registrants are de-duped by Handler object.
+ // It's fine to call multiple times, as the registrants are de-duped by Handler object.
private void registerOtaspChangedHandler() {
+ if (DBG) logd("registerOtaspChangedHandler");
final Phone phone = PhoneGlobals.getPhone();
phone.registerForOtaspChange(mOtaspHandler, EVENT_OTASP_CHANGED, null);
}