Allocate and de-allocate objects upon multi_config_change.
For class CarrierConfigLoader and RadioOnHelper
Bug: 142514392
Test: unittest
Merged-In: Ie58e842d1dc26e49528760e4ff3a6e50e3f8e7da
Change-Id: Ie58e842d1dc26e49528760e4ff3a6e50e3f8e7da
(cherry picked from commit 5acb9cf878c631e003d471afd5896d7f705cdf42)
diff --git a/src/com/android/phone/CarrierConfigLoader.java b/src/com/android/phone/CarrierConfigLoader.java
index 1d0138b..9582dd0 100644
--- a/src/com/android/phone/CarrierConfigLoader.java
+++ b/src/com/android/phone/CarrierConfigLoader.java
@@ -141,6 +141,8 @@
private static final int EVENT_FETCH_CARRIER_TIMEOUT = 15;
// SubscriptionInfoUpdater has finished updating the sub for the carrier config.
private static final int EVENT_SUBSCRIPTION_INFO_UPDATED = 16;
+ // Multi-SIM config changed.
+ private static final int EVENT_MULTI_SIM_CONFIG_CHANGED = 17;
private static final int BIND_TIMEOUT_MILLIS = 30000;
@@ -174,28 +176,21 @@
public void handleMessage(Message msg) {
final int phoneId = msg.arg1;
logWithLocalLog("mHandler: " + msg.what + " phoneId: " + phoneId);
+ if (!SubscriptionManager.isValidPhoneId(phoneId)
+ && msg.what != EVENT_MULTI_SIM_CONFIG_CHANGED) {
+ return;
+ }
switch (msg.what) {
case EVENT_CLEAR_CONFIG:
{
- /* Ignore clear configuration request if device is being shutdown. */
- Phone phone = PhoneFactory.getPhone(phoneId);
- if (phone != null) {
- if (phone.isShuttingDown()) {
- break;
- }
- }
-
- mConfigFromDefaultApp[phoneId] = null;
- mConfigFromCarrierApp[phoneId] = null;
- mServiceConnection[phoneId] = null;
- broadcastConfigChangedIntent(phoneId, false);
+ clearConfigForPhone(phoneId, true);
break;
}
case EVENT_SYSTEM_UNLOCKED:
{
- for (int i = 0; i < TelephonyManager.from(mContext)
- .getSupportedModemCount(); ++i) {
+ for (int i = 0; i < TelephonyManager.from(mContext).getActiveModemCount();
+ ++i) {
// When user unlock device, we should only try to send broadcast again if we
// have sent it before unlock. This will avoid we try to load carrier config
// when SIM is still loading when unlock happens.
@@ -212,8 +207,7 @@
// Only update if there are cached config removed to avoid updating config for
// unrelated packages.
if (clearCachedConfigForPackage(carrierPackageName)) {
- int numPhones = TelephonyManager.from(mContext)
- .getSupportedModemCount();
+ int numPhones = TelephonyManager.from(mContext).getActiveModemCount();
for (int i = 0; i < numPhones; ++i) {
updateConfigForPhoneId(i);
}
@@ -496,6 +490,9 @@
case EVENT_SUBSCRIPTION_INFO_UPDATED:
broadcastConfigChangedIntent(phoneId);
break;
+ case EVENT_MULTI_SIM_CONFIG_CHANGED:
+ onMultiSimConfigChanged();
+ break;
}
}
}
@@ -555,6 +552,23 @@
}
}
+ private void clearConfigForPhone(int phoneId, boolean sendBroadcast) {
+ /* Ignore clear configuration request if device is being shutdown. */
+ Phone phone = PhoneFactory.getPhone(phoneId);
+ if (phone != null) {
+ if (phone.isShuttingDown()) {
+ return;
+ }
+ }
+
+ mConfigFromDefaultApp[phoneId] = null;
+ mConfigFromCarrierApp[phoneId] = null;
+ mServiceConnection[phoneId] = null;
+ mHasSentConfigChange[phoneId] = false;
+
+ if (sendBroadcast) broadcastConfigChangedIntent(phoneId, false);
+ }
+
private void notifySubscriptionInfoUpdater(int phoneId) {
String configPackagename;
PersistableBundle configToSend;
@@ -919,6 +933,13 @@
mHandler.sendMessage(mHandler.obtainMessage(EVENT_DO_FETCH_DEFAULT, phoneId, -1));
}
+ private void onMultiSimConfigChanged() {
+ for (int i = TelephonyManager.from(mContext).getActiveModemCount();
+ i < mConfigFromDefaultApp.length; i++) {
+ clearConfigForPhone(i, false);
+ }
+ }
+
@Override
public @NonNull PersistableBundle getConfigForSubId(int subId, String callingPackage) {
if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
diff --git a/src/com/android/services/telephony/RadioOnHelper.java b/src/com/android/services/telephony/RadioOnHelper.java
index 741a6c5..981dc96 100644
--- a/src/com/android/services/telephony/RadioOnHelper.java
+++ b/src/com/android/services/telephony/RadioOnHelper.java
@@ -49,13 +49,19 @@
}
private void setupListeners() {
- if (mListeners != null) {
- return;
+ if (mListeners == null) {
+ mListeners = new ArrayList<>(2);
}
- mListeners = new ArrayList<>(2);
- for (int i = 0; i < TelephonyManager.getDefault().getSupportedModemCount(); i++) {
+ int activeModems = TelephonyManager.from(mContext).getActiveModemCount();
+ // Add new listeners if active modem count increased.
+ while (mListeners.size() < activeModems) {
mListeners.add(new RadioOnStateListener());
}
+ // Clean up listeners if active modem count decreased.
+ while (mListeners.size() > activeModems) {
+ mListeners.get(mListeners.size() - 1).cleanup();
+ mListeners.remove(mListeners.size() - 1);
+ }
}
/**
* Starts the "turn on radio" sequence. This is the (single) external API of the
@@ -76,7 +82,7 @@
mCallback = callback;
mInProgressListeners.clear();
mIsRadioOnCallingEnabled = false;
- for (int i = 0; i < TelephonyManager.getDefault().getSupportedModemCount(); i++) {
+ for (int i = 0; i < TelephonyManager.from(mContext).getActiveModemCount(); i++) {
Phone phone = PhoneFactory.getPhone(i);
if (phone == null) {
continue;
diff --git a/src/com/android/services/telephony/RadioOnStateListener.java b/src/com/android/services/telephony/RadioOnStateListener.java
index 729f6a9..52bd9cf 100644
--- a/src/com/android/services/telephony/RadioOnStateListener.java
+++ b/src/com/android/services/telephony/RadioOnStateListener.java
@@ -231,7 +231,7 @@
* Note we don't call this method simply after a successful call to placeCall(), since it's
* still possible the call will disconnect very quickly with an OUT_OF_SERVICE error.
*/
- private void cleanup() {
+ public void cleanup() {
Log.d(this, "cleanup()");
// This will send a failure call back if callback has yet to be invoked. If the callback