From 3a685cceedebeda5a241616be30c0f2bc4941ba8 Mon Sep 17 00:00:00 2001 From: Oliver Scott Date: Thu, 9 Nov 2023 13:59:05 -0500 Subject: [PATCH] Fix PhoneMonitor unregistered receiver crash Fix crash caused by attempting to unregister an unregistered broadcast receiver when the instance is registered but the broadcast receiver is not during setup finish Change-Id: I0e85492fe5c3a273ed6a2d16fe41bdd7539ffb4b --- .../setupwizard/util/PhoneMonitor.java | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/org/lineageos/setupwizard/util/PhoneMonitor.java b/src/org/lineageos/setupwizard/util/PhoneMonitor.java index de9467c2..f117f7b7 100644 --- a/src/org/lineageos/setupwizard/util/PhoneMonitor.java +++ b/src/org/lineageos/setupwizard/util/PhoneMonitor.java @@ -85,19 +85,7 @@ public class PhoneMonitor { private int mChangingToDataSubId = -1; - private final BroadcastReceiver mIntentReceiver = new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - if (intent.getAction().equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) { - final int sub = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY, -1); - final int state = mTelephony.getSimState(sub); - simStateChanged(sub, state); - } else if (intent.getAction() - .equals(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED)) { - ddsHasChanged(intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY, -1)); - } - } - }; + private final BroadcastReceiver mIntentReceiver; private class SubscriptionStateTracker extends PhoneStateListener { @@ -173,6 +161,19 @@ public class PhoneMonitor { mSubscriptionManager.addOnSubscriptionsChangedListener(mOnSubscriptionsChangedListener); updatePhoneStateTrackers(); } + mIntentReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + if (intent.getAction().equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) { + final int sub = intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY, -1); + final int state = mTelephony.getSimState(sub); + simStateChanged(sub, state); + } else if (intent.getAction() + .equals(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED)) { + ddsHasChanged(intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY, -1)); + } + } + }; // Register for DDS changes IntentFilter filter = new IntentFilter(); filter.addAction(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED);