From 078ecbd765abca3a2a78c5af16b80796b82d3a90 Mon Sep 17 00:00:00 2001 From: SongFerngWang Date: Tue, 27 Sep 2022 20:45:17 +0800 Subject: [PATCH] [MEP] psim->esim, don't skip carrierConfigChanged with subId -1 After simSlotMapping from psim to esim, since the esim can not be enabled by the modem, the UI start to enable the esim. Therefore, when receiver receive the first carrier config changed, UI can exit waiting state, and then start to enable esim. Bug: 246556280 Test: Build pass. Verify by QA Change-Id: I4b8b2f3d1dd014fc1ddb92ebffa614d6daf9d142 --- .../network/CarrierConfigChangedReceiver.java | 16 ++++++++++++++-- .../android/settings/network/UiccSlotUtil.java | 11 +++++++---- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/com/android/settings/network/CarrierConfigChangedReceiver.java b/src/com/android/settings/network/CarrierConfigChangedReceiver.java index 8a6d47d96fc..d9ff03efb6a 100644 --- a/src/com/android/settings/network/CarrierConfigChangedReceiver.java +++ b/src/com/android/settings/network/CarrierConfigChangedReceiver.java @@ -32,9 +32,20 @@ public class CarrierConfigChangedReceiver extends BroadcastReceiver { CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED; private final CountDownLatch mLatch; + private final boolean mIsWaitingForValidSubId; - public CarrierConfigChangedReceiver(CountDownLatch latch) { + /** + * This is the CarrierConfigChanged receiver. If it receives the carrier config changed, then it + * call the CountDownLatch.countDown(). + * If the "isWaitingForValidSubId" is true, then the receiver skip the carrier config changed + * with the subId = -1. The receiver executes the countDown when the CarrierConfigChanged + * with valid subId. + * If the "isWaitingForValidSubId" is false, then the receiver executes the countDown when + * receiving any CarrierConfigChanged. + */ + public CarrierConfigChangedReceiver(CountDownLatch latch, boolean isWaitingForValidSubId) { mLatch = latch; + mIsWaitingForValidSubId = isWaitingForValidSubId; } public void registerOn(Context context) { @@ -53,7 +64,8 @@ public class CarrierConfigChangedReceiver extends BroadcastReceiver { } private void checkSubscriptionIndex(Intent intent) { - if (intent.hasExtra(CarrierConfigManager.EXTRA_SUBSCRIPTION_INDEX)) { + if (intent.hasExtra(CarrierConfigManager.EXTRA_SUBSCRIPTION_INDEX) + || !mIsWaitingForValidSubId) { int subId = intent.getIntExtra(CarrierConfigManager.EXTRA_SUBSCRIPTION_INDEX, -1); Log.i(TAG, "subId from config changed: " + subId); mLatch.countDown(); diff --git a/src/com/android/settings/network/UiccSlotUtil.java b/src/com/android/settings/network/UiccSlotUtil.java index 7ba2e0f8ed0..7d8295b7822 100644 --- a/src/com/android/settings/network/UiccSlotUtil.java +++ b/src/com/android/settings/network/UiccSlotUtil.java @@ -141,7 +141,8 @@ public class UiccSlotUtil { inactiveRemovableSlot, /*removable sim's port Id*/ TelephonyManager.DEFAULT_PORT_INDEX, excludedLogicalSlotIndex), - context); + context, + /*isWaitingForValidSubId=*/ true); } /** @@ -179,7 +180,8 @@ public class UiccSlotUtil { performSwitchToSlot(telMgr, prepareUiccSlotMappings(uiccSlotMappings, /*slot is not psim*/ false, physicalSlotId, port, excludedLogicalSlotIndex), - context); + context, + /*isWaitingForValidSubId=*/ false); } /** @@ -231,7 +233,8 @@ public class UiccSlotUtil { } private static void performSwitchToSlot(TelephonyManager telMgr, - Collection uiccSlotMappings, Context context) + Collection uiccSlotMappings, Context context, + boolean isWaitingForValidSubId) throws UiccSlotsException { CarrierConfigChangedReceiver receiver = null; long waitingTimeMillis = @@ -241,7 +244,7 @@ public class UiccSlotUtil { DEFAULT_WAIT_AFTER_SWITCH_TIMEOUT_MILLIS); try { CountDownLatch latch = new CountDownLatch(1); - receiver = new CarrierConfigChangedReceiver(latch); + receiver = new CarrierConfigChangedReceiver(latch, isWaitingForValidSubId); receiver.registerOn(context); telMgr.setSimSlotMapping(uiccSlotMappings); latch.await(waitingTimeMillis, TimeUnit.MILLISECONDS);