Loading src/com/android/settings/network/UiccSlotUtil.java +47 −4 Original line number Diff line number Diff line Loading @@ -17,7 +17,10 @@ package com.android.settings.network; import android.annotation.IntDef; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.provider.Settings; import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; Loading Loading @@ -54,6 +57,28 @@ public class UiccSlotUtil { public static final int INVALID_PHYSICAL_SLOT_ID = -1; public static final int INVALID_PORT_ID = -1; @VisibleForTesting static class SimSlotChangeReceiver extends BroadcastReceiver{ private final CountDownLatch mLatch; SimSlotChangeReceiver(CountDownLatch latch) { mLatch = latch; } public void registerOn(Context context) { context.registerReceiver(this, new IntentFilter(TelephonyManager.ACTION_SIM_SLOT_STATUS_CHANGED), Context.RECEIVER_EXPORTED/*UNAUDITED*/); } @Override public void onReceive(Context context, Intent intent) { Log.i(TAG, "Action: " + intent.getAction()); if (TelephonyManager.ACTION_SIM_SLOT_STATUS_CHANGED.equals(intent.getAction())) { mLatch.countDown(); } } } /** * Mode for switching to eSIM slot which decides whether there is cleanup process, e.g. * disabling test profile, after eSIM slot is activated and whether we will wait it finished. Loading Loading @@ -229,19 +254,27 @@ public class UiccSlotUtil { && uiccSlotMapping.getPortIndex() == port); } private static void performSwitchToSlot(TelephonyManager telMgr, @VisibleForTesting static void performSwitchToSlot(TelephonyManager telMgr, Collection<UiccSlotMapping> uiccSlotMappings, Context context) throws UiccSlotsException { CarrierConfigChangedReceiver receiver = null; BroadcastReceiver receiver = null; long waitingTimeMillis = Settings.Global.getLong( context.getContentResolver(), Settings.Global.EUICC_SWITCH_SLOT_TIMEOUT_MILLIS, DEFAULT_WAIT_AFTER_SWITCH_TIMEOUT_MILLIS); Log.d(TAG, "Set waitingTime as " + waitingTimeMillis); try { CountDownLatch latch = new CountDownLatch(1); if (isMultipleEnabledProfilesSupported(telMgr)) { receiver = new SimSlotChangeReceiver(latch); ((SimSlotChangeReceiver) receiver).registerOn(context); } else { receiver = new CarrierConfigChangedReceiver(latch); receiver.registerOn(context); ((CarrierConfigChangedReceiver) receiver).registerOn(context); } telMgr.setSimSlotMapping(uiccSlotMappings); latch.await(waitingTimeMillis, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { Loading Loading @@ -435,4 +468,14 @@ public class UiccSlotUtil { Log.i(TAG, "isRemovableSimEnabled: " + isRemovableSimEnabled); return isRemovableSimEnabled; } private static boolean isMultipleEnabledProfilesSupported(TelephonyManager telMgr) { List<UiccCardInfo> cardInfos = telMgr.getUiccCardsInfo(); if (cardInfos == null) { Log.w(TAG, "UICC cards info list is empty."); return false; } return cardInfos.stream().anyMatch( cardInfo -> cardInfo.isMultipleEnabledProfilesSupported()); } } tests/unit/src/com/android/settings/network/UiccSlotUtilTest.java +23 −0 Original line number Diff line number Diff line Loading @@ -20,10 +20,13 @@ import static android.telephony.UiccSlotInfo.CARD_STATE_INFO_PRESENT; import static com.google.common.truth.Truth.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.content.Context; import android.content.Intent; import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; Loading @@ -49,6 +52,7 @@ import java.util.Collection; import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.concurrent.CountDownLatch; @RunWith(AndroidJUnit4.class) public class UiccSlotUtilTest { Loading Loading @@ -738,6 +742,25 @@ public class UiccSlotUtilTest { assertThat(testSlot).isFalse(); } @Test public void performSwitchToSlot_setSimSlotMapping() throws UiccSlotsException { Collection<UiccSlotMapping> uiccSlotMappings = createUiccSlotMappingDualPortsBNoOrding(); UiccSlotUtil.performSwitchToSlot(mTelephonyManager, uiccSlotMappings, mContext); verify(mTelephonyManager).setSimSlotMapping(any()); } @Test public void onReceiveSimSlotChangeReceiver_receiveAction_timerCountDown() { CountDownLatch latch = spy(new CountDownLatch(1)); UiccSlotUtil.SimSlotChangeReceiver receive = new UiccSlotUtil.SimSlotChangeReceiver(latch); receive.onReceive(mContext, new Intent(TelephonyManager.ACTION_SIM_SLOT_STATUS_CHANGED)); verify(latch).countDown(); } private void compareTwoUiccSlotMappings(Collection<UiccSlotMapping> testUiccSlotMappings, Collection<UiccSlotMapping> verifyUiccSlotMappings) { assertThat(testUiccSlotMappings.size()).isEqualTo(verifyUiccSlotMappings.size()); Loading Loading
src/com/android/settings/network/UiccSlotUtil.java +47 −4 Original line number Diff line number Diff line Loading @@ -17,7 +17,10 @@ package com.android.settings.network; import android.annotation.IntDef; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.provider.Settings; import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; Loading Loading @@ -54,6 +57,28 @@ public class UiccSlotUtil { public static final int INVALID_PHYSICAL_SLOT_ID = -1; public static final int INVALID_PORT_ID = -1; @VisibleForTesting static class SimSlotChangeReceiver extends BroadcastReceiver{ private final CountDownLatch mLatch; SimSlotChangeReceiver(CountDownLatch latch) { mLatch = latch; } public void registerOn(Context context) { context.registerReceiver(this, new IntentFilter(TelephonyManager.ACTION_SIM_SLOT_STATUS_CHANGED), Context.RECEIVER_EXPORTED/*UNAUDITED*/); } @Override public void onReceive(Context context, Intent intent) { Log.i(TAG, "Action: " + intent.getAction()); if (TelephonyManager.ACTION_SIM_SLOT_STATUS_CHANGED.equals(intent.getAction())) { mLatch.countDown(); } } } /** * Mode for switching to eSIM slot which decides whether there is cleanup process, e.g. * disabling test profile, after eSIM slot is activated and whether we will wait it finished. Loading Loading @@ -229,19 +254,27 @@ public class UiccSlotUtil { && uiccSlotMapping.getPortIndex() == port); } private static void performSwitchToSlot(TelephonyManager telMgr, @VisibleForTesting static void performSwitchToSlot(TelephonyManager telMgr, Collection<UiccSlotMapping> uiccSlotMappings, Context context) throws UiccSlotsException { CarrierConfigChangedReceiver receiver = null; BroadcastReceiver receiver = null; long waitingTimeMillis = Settings.Global.getLong( context.getContentResolver(), Settings.Global.EUICC_SWITCH_SLOT_TIMEOUT_MILLIS, DEFAULT_WAIT_AFTER_SWITCH_TIMEOUT_MILLIS); Log.d(TAG, "Set waitingTime as " + waitingTimeMillis); try { CountDownLatch latch = new CountDownLatch(1); if (isMultipleEnabledProfilesSupported(telMgr)) { receiver = new SimSlotChangeReceiver(latch); ((SimSlotChangeReceiver) receiver).registerOn(context); } else { receiver = new CarrierConfigChangedReceiver(latch); receiver.registerOn(context); ((CarrierConfigChangedReceiver) receiver).registerOn(context); } telMgr.setSimSlotMapping(uiccSlotMappings); latch.await(waitingTimeMillis, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { Loading Loading @@ -435,4 +468,14 @@ public class UiccSlotUtil { Log.i(TAG, "isRemovableSimEnabled: " + isRemovableSimEnabled); return isRemovableSimEnabled; } private static boolean isMultipleEnabledProfilesSupported(TelephonyManager telMgr) { List<UiccCardInfo> cardInfos = telMgr.getUiccCardsInfo(); if (cardInfos == null) { Log.w(TAG, "UICC cards info list is empty."); return false; } return cardInfos.stream().anyMatch( cardInfo -> cardInfo.isMultipleEnabledProfilesSupported()); } }
tests/unit/src/com/android/settings/network/UiccSlotUtilTest.java +23 −0 Original line number Diff line number Diff line Loading @@ -20,10 +20,13 @@ import static android.telephony.UiccSlotInfo.CARD_STATE_INFO_PRESENT; import static com.google.common.truth.Truth.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.content.Context; import android.content.Intent; import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; Loading @@ -49,6 +52,7 @@ import java.util.Collection; import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.concurrent.CountDownLatch; @RunWith(AndroidJUnit4.class) public class UiccSlotUtilTest { Loading Loading @@ -738,6 +742,25 @@ public class UiccSlotUtilTest { assertThat(testSlot).isFalse(); } @Test public void performSwitchToSlot_setSimSlotMapping() throws UiccSlotsException { Collection<UiccSlotMapping> uiccSlotMappings = createUiccSlotMappingDualPortsBNoOrding(); UiccSlotUtil.performSwitchToSlot(mTelephonyManager, uiccSlotMappings, mContext); verify(mTelephonyManager).setSimSlotMapping(any()); } @Test public void onReceiveSimSlotChangeReceiver_receiveAction_timerCountDown() { CountDownLatch latch = spy(new CountDownLatch(1)); UiccSlotUtil.SimSlotChangeReceiver receive = new UiccSlotUtil.SimSlotChangeReceiver(latch); receive.onReceive(mContext, new Intent(TelephonyManager.ACTION_SIM_SLOT_STATUS_CHANGED)); verify(latch).countDown(); } private void compareTwoUiccSlotMappings(Collection<UiccSlotMapping> testUiccSlotMappings, Collection<UiccSlotMapping> verifyUiccSlotMappings) { assertThat(testUiccSlotMappings.size()).isEqualTo(verifyUiccSlotMappings.size()); Loading