From e11d9e9ef3f53def5ef85e0655cbc18f3478309a Mon Sep 17 00:00:00 2001 From: Stanley Wang Date: Tue, 1 Mar 2022 19:28:30 +0800 Subject: [PATCH 1/4] Fix the problem that the autofill could be searched. PreferenceCategory will not be indexed by default. The auto fill category use the AutofillPreferenceCategory class in the xml so it will be indexed. The solution is to create a controller to replace AutofillPreferenceCategory. Fix: 185914894 Test: manual adb test to see the log Change-Id: Id0e3bcc33a3132434a6bd1fe91e1c6915116d06d --- res/xml/development_settings.xml | 4 +- .../DevelopmentSettingsDashboardFragment.java | 2 + ...y.java => AutofillCategoryController.java} | 73 ++++++++++++------- 3 files changed, 49 insertions(+), 30 deletions(-) rename src/com/android/settings/development/autofill/{AutofillPreferenceCategory.java => AutofillCategoryController.java} (54%) diff --git a/res/xml/development_settings.xml b/res/xml/development_settings.xml index f29930c8bd4..86544cd7b72 100644 --- a/res/xml/development_settings.xml +++ b/res/xml/development_settings.xml @@ -648,7 +648,7 @@ android:title="@string/reset_shortcut_manager_throttling" /> - - + notifyDependencyChange(shouldDisableDependents()), + mHandler.postDelayed( + () -> mPreference.notifyDependencyChange(shouldDisableDependents()), DELAYED_MESSAGE_TIME_MS); } }; @@ -53,32 +69,33 @@ public final class AutofillPreferenceCategory extends PreferenceCategory { } @Override - public void onAttached() { - super.onAttached(); - - mContentResolver.registerContentObserver( - Settings.Secure.getUriFor(Settings.Secure.AUTOFILL_SERVICE), false, - mSettingsObserver); + public String getPreferenceKey() { + return CATEGORY_KEY; } @Override - public void onDetached() { - mContentResolver.unregisterContentObserver(mSettingsObserver); + public void onStart() { + mContentResolver.registerContentObserver( + Settings.Secure.getUriFor(Settings.Secure.AUTOFILL_SERVICE), false, + mSettingsObserver); - super.onDetached(); + } + + @Override + public void onStop() { + mContentResolver.unregisterContentObserver(mSettingsObserver); } // PreferenceCategory.isEnabled() always return false, so we rather not change that logic // decide whether the children should be shown using isAutofillEnabled() instead. private boolean isAutofillEnabled() { - final AutofillManager afm = getContext().getSystemService(AutofillManager.class); + final AutofillManager afm = mContext.getSystemService(AutofillManager.class); final boolean enabled = afm != null && afm.isEnabled(); Log.v(TAG, "isAutofillEnabled(): " + enabled); return enabled; } - @Override - public boolean shouldDisableDependents() { + private boolean shouldDisableDependents() { final boolean shouldIt = !isAutofillEnabled(); Log.v(TAG, "shouldDisableDependents(): " + shouldIt); return shouldIt; From 78a0f6f98ebbb54a4aae4003b608c473683d5e25 Mon Sep 17 00:00:00 2001 From: Jimmy Chen Date: Wed, 23 Feb 2022 16:12:01 +0800 Subject: [PATCH 2/4] p2p: Close the channel when onStop is called. P2P dialog is moved to an indenpendent activity, it will push Settings to background and trigger onPause(). As P2P dialog is a Dialog Activity, it won't trigger onStop, but SoftAp and NAN activity will. Moving channel closing to onStop to adapt to new P2P dialog design. Bug: 219406778 Test: make RunSettingsRoboTests ROBOTEST_FILTER=WifiP2pSettingsTest create a p2p connection between 2 devices with this build. Change-Id: I2fab5aa1021ec1a993f811c7310079db9d7f03c0 --- src/com/android/settings/wifi/p2p/WifiP2pSettings.java | 9 ++++++++- .../android/settings/wifi/p2p/WifiP2pSettingsTest.java | 9 +++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/com/android/settings/wifi/p2p/WifiP2pSettings.java b/src/com/android/settings/wifi/p2p/WifiP2pSettings.java index a926360bd9e..404cdd31a66 100644 --- a/src/com/android/settings/wifi/p2p/WifiP2pSettings.java +++ b/src/com/android/settings/wifi/p2p/WifiP2pSettings.java @@ -375,13 +375,20 @@ public class WifiP2pSettings extends DashboardFragment super.onPause(); if (mWifiP2pManager != null && mChannel != null) { mWifiP2pManager.stopPeerDiscovery(mChannel, null); + } + getActivity().unregisterReceiver(mReceiver); + } + + @Override + public void onStop() { + super.onStop(); + if (mWifiP2pManager != null && mChannel != null) { if (!mLastGroupFormed) { // Close the channel when p2p doesn't connected. mChannel.close(); mChannel = null; } } - getActivity().unregisterReceiver(mReceiver); } @Override diff --git a/tests/robotests/src/com/android/settings/wifi/p2p/WifiP2pSettingsTest.java b/tests/robotests/src/com/android/settings/wifi/p2p/WifiP2pSettingsTest.java index 332cf14c40c..448c109388b 100644 --- a/tests/robotests/src/com/android/settings/wifi/p2p/WifiP2pSettingsTest.java +++ b/tests/robotests/src/com/android/settings/wifi/p2p/WifiP2pSettingsTest.java @@ -319,12 +319,18 @@ public class WifiP2pSettingsTest { assertThat(mFragment.onCreateDialog(-1 /* id */)).isNull(); } + @Test + public void onStop_notLastGroupFormed_shouldCloseChannel() { + mFragment.onStop(); + + assertThat(mFragment.mChannel).isNull(); + } + @Test public void peerDiscovery_whenOnPause_shouldStop() { mFragment.onPause(); verify(mWifiP2pManager, times(1)).stopPeerDiscovery(any(), any()); - assertThat(mFragment.mChannel).isNull(); } @Test @@ -332,7 +338,6 @@ public class WifiP2pSettingsTest { mFragment.onPause(); verify(mWifiP2pManager, times(1)).stopPeerDiscovery(any(), any()); - assertThat(mFragment.mChannel).isNull(); mFragment.onResume(); assertThat(mFragment.mChannel).isNotNull(); From 68cfaafe732e2aa76713c731df324572b5e10bcd Mon Sep 17 00:00:00 2001 From: SongFerngWang Date: Mon, 7 Mar 2022 01:50:27 +0800 Subject: [PATCH 3/4] In E+E, the user can't enable the PSIM In the E+E and there is the empty slot, the user can't enable PSIM. Since the settings can't set the correct simSlotMapping. Bug: 222231991 Test: atest UiccSlotUtilTest (All passes) and Build pass Change-Id: Ia261e3b41c6c4a43a5429815d93ae9f6ff16f0ec --- .../settings/network/UiccSlotUtil.java | 169 +++++---- .../settings/network/UiccSlotUtilTest.java | 357 ++++++++++++++++-- 2 files changed, 429 insertions(+), 97 deletions(-) diff --git a/src/com/android/settings/network/UiccSlotUtil.java b/src/com/android/settings/network/UiccSlotUtil.java index c4f495c904f..9a157d6ea05 100644 --- a/src/com/android/settings/network/UiccSlotUtil.java +++ b/src/com/android/settings/network/UiccSlotUtil.java @@ -20,6 +20,7 @@ import android.annotation.IntDef; import android.content.Context; import android.provider.Settings; import android.telephony.SubscriptionInfo; +import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; import android.telephony.UiccSlotInfo; import android.telephony.UiccSlotMapping; @@ -47,6 +48,7 @@ public class UiccSlotUtil { private static final long DEFAULT_WAIT_AFTER_SWITCH_TIMEOUT_MILLIS = 25 * 1000L; + public static final int INVALID_LOGICAL_SLOT_ID = -1; public static final int INVALID_PHYSICAL_SLOT_ID = -1; public static final int INVALID_PORT_ID = -1; @@ -115,24 +117,27 @@ public class UiccSlotUtil { } TelephonyManager telMgr = context.getSystemService(TelephonyManager.class); int inactiveRemovableSlot = getInactiveRemovableSlot(telMgr.getUiccSlotsInfo(), slotId); - Log.i(TAG, "The InactiveRemovableSlot: " + inactiveRemovableSlot); - - Collection uiccSlotMappings = telMgr.getSimSlotMapping(); - Log.i(TAG, "The SimSlotMapping: " + uiccSlotMappings); - + Log.d(TAG, "The InactiveRemovableSlot: " + inactiveRemovableSlot); if (inactiveRemovableSlot == INVALID_PHYSICAL_SLOT_ID) { // The slot is invalid slot id, then to skip this. // The slot is active, then the sim can enable directly. return; } + Collection uiccSlotMappings = telMgr.getSimSlotMapping(); + Log.d(TAG, "The SimSlotMapping: " + uiccSlotMappings); + + SubscriptionManager subscriptionManager = context.getSystemService( + SubscriptionManager.class); + int excludedLogicalSlotIndex = getExcludedLogicalSlotIndex(uiccSlotMappings, + SubscriptionUtil.getActiveSubscriptions(subscriptionManager), removedSubInfo, + telMgr.isMultiSimEnabled()); performSwitchToSlot(telMgr, prepareUiccSlotMappings(uiccSlotMappings, /*slot is psim*/ true, inactiveRemovableSlot, /*removable sim's port Id*/ TelephonyManager.DEFAULT_PORT_INDEX, - removedSubInfo, - telMgr.isMultiSimEnabled()), + excludedLogicalSlotIndex), context); } @@ -156,16 +161,21 @@ public class UiccSlotUtil { } TelephonyManager telMgr = context.getSystemService(TelephonyManager.class); Collection uiccSlotMappings = telMgr.getSimSlotMapping(); - Log.i(TAG, "The SimSlotMapping: " + uiccSlotMappings); + Log.d(TAG, "The SimSlotMapping: " + uiccSlotMappings); if (isTargetSlotActive(uiccSlotMappings, physicalSlotId, port)) { - Log.i(TAG, "The slot is active, then the sim can enable directly."); + Log.d(TAG, "The slot is active, then the sim can enable directly."); return; } + SubscriptionManager subscriptionManager = context.getSystemService( + SubscriptionManager.class); + int excludedLogicalSlotIndex = getExcludedLogicalSlotIndex(uiccSlotMappings, + SubscriptionUtil.getActiveSubscriptions(subscriptionManager), removedSubInfo, + telMgr.isMultiSimEnabled()); performSwitchToSlot(telMgr, prepareUiccSlotMappings(uiccSlotMappings, /*slot is not psim*/ false, - physicalSlotId, port, removedSubInfo, telMgr.isMultiSimEnabled()), + physicalSlotId, port, excludedLogicalSlotIndex), context); } @@ -276,74 +286,91 @@ public class UiccSlotUtil { @VisibleForTesting static Collection prepareUiccSlotMappings( Collection uiccSlotMappings, boolean isPsim, int physicalSlotId, - int port, SubscriptionInfo removedSubInfo, boolean isMultiSimEnabled) { + int port, int removedLogicalSlotId) { + if (removedLogicalSlotId == INVALID_LOGICAL_SLOT_ID) { + Log.d(TAG, "There is no removedLogicalSlotId. Do nothing."); + return uiccSlotMappings; + } + Log.d(TAG, + String.format( + "Create new SimSlotMapping. Remove the UiccSlotMapping of logicalSlot%d" + + ", and insert PhysicalSlotId%d-Port%d", + removedLogicalSlotId, physicalSlotId, port)); Collection newUiccSlotMappings = new ArrayList<>(); - if (!isMultiSimEnabled) { - // In the 'SS mode', the port is 0. - newUiccSlotMappings.add(new UiccSlotMapping(port, physicalSlotId, 0)); - } else if (removedSubInfo != null) { - // DSDS+MEP - // The target slot+port is not active, but the all of logical slots are full. It - // needs to replace one of logical slots. - Log.i(TAG, - String.format( - "Start to set SimSlotMapping from subId%d(LogicalSlot%d-Port%d) to " - + "PhysicalSlotId%d-Port%d", - removedSubInfo.getSubscriptionId(), removedSubInfo.getSimSlotIndex(), - removedSubInfo.getPortIndex(), physicalSlotId, port)); - - int logicalSlotIndex = 0; - if (isPsim) { - // The target slot is psim - newUiccSlotMappings.add( - new UiccSlotMapping(port, physicalSlotId, logicalSlotIndex++)); - } - Collection tempUiccSlotMappings = - uiccSlotMappings.stream() - .sorted(Comparator.comparingInt(UiccSlotMapping::getLogicalSlotIndex)) - .collect(Collectors.toList()); - for (UiccSlotMapping uiccSlotMapping : tempUiccSlotMappings) { - if (isSubInfoMappingIntoUiccSlotMapping(uiccSlotMapping, removedSubInfo)) { - if (!isPsim) { - // Replace this uiccSlotMapping - newUiccSlotMappings.add(new UiccSlotMapping(port, physicalSlotId, - uiccSlotMapping.getLogicalSlotIndex())); - } - continue; + int logicalSlotIndex = 0; + if (isPsim) { + // The target slot is psim. The psim is always the first index at LogicalSlot. + newUiccSlotMappings.add( + new UiccSlotMapping(port, physicalSlotId, logicalSlotIndex++)); + } + Collection tempUiccSlotMappings = + uiccSlotMappings.stream() + .sorted(Comparator.comparingInt(UiccSlotMapping::getLogicalSlotIndex)) + .collect(Collectors.toList()); + for (UiccSlotMapping uiccSlotMapping : tempUiccSlotMappings) { + if (uiccSlotMapping.getLogicalSlotIndex() == removedLogicalSlotId) { + if (!isPsim) { + // Replace this uiccSlotMapping + newUiccSlotMappings.add(new UiccSlotMapping(port, physicalSlotId, + uiccSlotMapping.getLogicalSlotIndex())); } - - // If the psim is inserted, then change the - // logicalSlotIndex for another uiccSlotMappings. - newUiccSlotMappings.add(isPsim - ? new UiccSlotMapping( - uiccSlotMapping.getPortIndex(), - uiccSlotMapping.getPhysicalSlotIndex(), - logicalSlotIndex++ - ) : uiccSlotMapping); + continue; } - } else { - // For no inserted psim case in DSDS+MEP, there is only one esim in device and - // then user inserts another esim in DSDS+MEP. - // If the target is esim, then replace the psim. - Log.i(TAG, "The removedSubInfo is null"); - newUiccSlotMappings = - uiccSlotMappings.stream().map(uiccSlotMapping -> { - if (!isPsim && uiccSlotMapping.getPhysicalSlotIndex() != physicalSlotId) { - return new UiccSlotMapping(port, physicalSlotId, - uiccSlotMapping.getLogicalSlotIndex()); - } - return uiccSlotMapping; - }).collect(Collectors.toList()); + + // If the psim is inserted, then change the logicalSlotIndex for another + // uiccSlotMappings. + newUiccSlotMappings.add(isPsim + ? new UiccSlotMapping(uiccSlotMapping.getPortIndex(), + uiccSlotMapping.getPhysicalSlotIndex(), logicalSlotIndex++) + : uiccSlotMapping); } - Log.i(TAG, "The SimSlotMapping: " + newUiccSlotMappings); + Log.d(TAG, "The new SimSlotMapping: " + newUiccSlotMappings); return newUiccSlotMappings; } - private static boolean isSubInfoMappingIntoUiccSlotMapping(UiccSlotMapping uiccSlotMapping, - SubscriptionInfo subscriptionInfo) { - return uiccSlotMapping != null - && uiccSlotMapping.getLogicalSlotIndex() == subscriptionInfo.getSimSlotIndex() - && uiccSlotMapping.getPortIndex() == subscriptionInfo.getPortIndex(); + /** + * To get the excluded logical slot index from uiccSlotMapping list. If the sim which is + * enabled by user does not have the corresponding slot, then it needs to do the + * SimSlotMapping changed. This method can find the logical slot index of the corresponding slot + * before the Frameworks do the SimSlotMapping changed. + * + * @param uiccSlotMappings The uiccSlotMapping list from the Telephony Frameworks. + * @param activeSubInfos The active subscriptionInfo list. + * @param removedSubInfo The removed sim card which is selected by the user. If the user + * don't select removed sim , then the value is null. + * @param isMultiSimEnabled whether the device is in the DSDS mode or not. + * @return The logical slot index of removed slot. If it can't find the removed slot, it + * returns {@link #INVALID_LOGICAL_SLOT_ID}. + */ + @VisibleForTesting + static int getExcludedLogicalSlotIndex(Collection uiccSlotMappings, + Collection activeSubInfos, SubscriptionInfo removedSubInfo, + boolean isMultiSimEnabled) { + if (!isMultiSimEnabled) { + Log.i(TAG, "In the ss mode."); + return 0; + } + if (removedSubInfo != null) { + // Use removedSubInfo's logicalSlotIndex + Log.i(TAG, "The removedSubInfo is not null"); + return removedSubInfo.getSimSlotIndex(); + } + // If it needs to do simSlotMapping when user enables sim and there is an empty slot which + // there is no enabled sim in this slot, then the empty slot can be removed. + Log.i(TAG, "The removedSubInfo is null"); + return uiccSlotMappings.stream() + .filter(uiccSlotMapping -> { + // find the empty slots. + for (SubscriptionInfo subInfo : activeSubInfos) { + if (subInfo.getSimSlotIndex() == uiccSlotMapping.getLogicalSlotIndex()) { + return false; + } + } + return true; + }) + .mapToInt(uiccSlotMapping -> uiccSlotMapping.getLogicalSlotIndex()) + .findFirst() + .orElse(INVALID_LOGICAL_SLOT_ID); } } diff --git a/tests/unit/src/com/android/settings/network/UiccSlotUtilTest.java b/tests/unit/src/com/android/settings/network/UiccSlotUtilTest.java index 8a0a4b0d3b9..cc9bdfc62e0 100644 --- a/tests/unit/src/com/android/settings/network/UiccSlotUtilTest.java +++ b/tests/unit/src/com/android/settings/network/UiccSlotUtilTest.java @@ -116,9 +116,10 @@ public class UiccSlotUtilTest { Collection uiccSlotMappings = createUiccSlotMappingSsModePsimActive(); Collection verifyUiccSlotMappings = createUiccSlotMappingSsModeEsimPort0Active(); + int removedLogicalSlotIndex = 0; Collection testUiccSlotMappings = UiccSlotUtil.prepareUiccSlotMappings( - uiccSlotMappings, false, ESIM_PHYSICAL_SLOT, 0, null, false); + uiccSlotMappings, false, ESIM_PHYSICAL_SLOT, 0, removedLogicalSlotIndex); compareTwoUiccSlotMappings(testUiccSlotMappings, verifyUiccSlotMappings); } @@ -129,9 +130,10 @@ public class UiccSlotUtilTest { createUiccSlotMappingSsModeEsimPort0Active(); Collection verifyUiccSlotMappings = createUiccSlotMappingSsModePsimActive(); + int removedLogicalSlotIndex = 0; Collection testUiccSlotMappings = UiccSlotUtil.prepareUiccSlotMappings( - uiccSlotMappings, true, PSIM_PHYSICAL_SLOT, 0, null, false); + uiccSlotMappings, true, PSIM_PHYSICAL_SLOT, 0, removedLogicalSlotIndex); compareTwoUiccSlotMappings(testUiccSlotMappings, verifyUiccSlotMappings); } @@ -141,9 +143,10 @@ public class UiccSlotUtilTest { Collection uiccSlotMappings = createUiccSlotMappingPsimAndPort0(); Collection verifyUiccSlotMappings = createUiccSlotMappingPsimAndPort1(); - SubscriptionInfo subInfo = createSubscriptionInfo(1, 0); + int removedLogicalSlotIndex = 1; + Collection testUiccSlotMappings = UiccSlotUtil.prepareUiccSlotMappings( - uiccSlotMappings, false, ESIM_PHYSICAL_SLOT, 1, subInfo, true); + uiccSlotMappings, false, ESIM_PHYSICAL_SLOT, 1, removedLogicalSlotIndex); compareTwoUiccSlotMappings(testUiccSlotMappings, verifyUiccSlotMappings); } @@ -153,10 +156,10 @@ public class UiccSlotUtilTest { Collection uiccSlotMappings = createUiccSlotMappingPsimAndPort1(); Collection verifyUiccSlotMappings = createUiccSlotMappingPsimAndPort0(); + int removedLogicalSlotIndex = 1; - SubscriptionInfo subInfo = createSubscriptionInfo(1, 1); Collection testUiccSlotMappings = UiccSlotUtil.prepareUiccSlotMappings( - uiccSlotMappings, false, ESIM_PHYSICAL_SLOT, 0, subInfo, true); + uiccSlotMappings, false, ESIM_PHYSICAL_SLOT, 0, removedLogicalSlotIndex); compareTwoUiccSlotMappings(testUiccSlotMappings, verifyUiccSlotMappings); } @@ -166,10 +169,10 @@ public class UiccSlotUtilTest { Collection uiccSlotMappings = createUiccSlotMappingPsimAndPort0(); Collection verifyUiccSlotMappings = createUiccSlotMappingDualPortsB(); + int removedLogicalSlotIndex = 0; - SubscriptionInfo subInfo = createSubscriptionInfo(0, 0); Collection testUiccSlotMappings = UiccSlotUtil.prepareUiccSlotMappings( - uiccSlotMappings, false, ESIM_PHYSICAL_SLOT, 1, subInfo, true); + uiccSlotMappings, false, ESIM_PHYSICAL_SLOT, 1, removedLogicalSlotIndex); compareTwoUiccSlotMappings(testUiccSlotMappings, verifyUiccSlotMappings); } @@ -179,10 +182,10 @@ public class UiccSlotUtilTest { Collection uiccSlotMappings = createUiccSlotMappingPsimAndPort1(); Collection verifyUiccSlotMappings = createUiccSlotMappingDualPortsA(); + int removedLogicalSlotIndex = 0; - SubscriptionInfo subInfo = createSubscriptionInfo(0, 0); Collection testUiccSlotMappings = UiccSlotUtil.prepareUiccSlotMappings( - uiccSlotMappings, false, ESIM_PHYSICAL_SLOT, 0, subInfo, true); + uiccSlotMappings, false, ESIM_PHYSICAL_SLOT, 0, removedLogicalSlotIndex); compareTwoUiccSlotMappings(testUiccSlotMappings, verifyUiccSlotMappings); } @@ -192,9 +195,10 @@ public class UiccSlotUtilTest { Collection uiccSlotMappings = createUiccSlotMappingPsimAndPort0(); Collection verifyUiccSlotMappings = createUiccSlotMappingDualPortsB(); + int removedLogicalSlotIndex = 0; Collection testUiccSlotMappings = UiccSlotUtil.prepareUiccSlotMappings( - uiccSlotMappings, false, ESIM_PHYSICAL_SLOT, 1, null, true); + uiccSlotMappings, false, ESIM_PHYSICAL_SLOT, 1, removedLogicalSlotIndex); compareTwoUiccSlotMappings(testUiccSlotMappings, verifyUiccSlotMappings); } @@ -204,9 +208,66 @@ public class UiccSlotUtilTest { Collection uiccSlotMappings = createUiccSlotMappingPsimAndPort1(); Collection verifyUiccSlotMappings = createUiccSlotMappingDualPortsA(); + int removedLogicalSlotIndex = 0; Collection testUiccSlotMappings = UiccSlotUtil.prepareUiccSlotMappings( - uiccSlotMappings, false, ESIM_PHYSICAL_SLOT, 0, null, true); + uiccSlotMappings, false, ESIM_PHYSICAL_SLOT, 0, removedLogicalSlotIndex); + + compareTwoUiccSlotMappings(testUiccSlotMappings, verifyUiccSlotMappings); + } + + @Test + public void prepareUiccSlotMappings_oneEsimAndFromDualPortsAToPsimAndPort1_psimAndPort1() { + // There is only one enabled esimPort1 before user enables the psim. + Collection uiccSlotMappings = createUiccSlotMappingDualPortsA(); + Collection verifyUiccSlotMappings = + createUiccSlotMappingPsimAndPort1(); + int removedLogicalSlotIndex = 0; + + Collection testUiccSlotMappings = UiccSlotUtil.prepareUiccSlotMappings( + uiccSlotMappings, true, PSIM_PHYSICAL_SLOT, 0, removedLogicalSlotIndex); + + compareTwoUiccSlotMappings(testUiccSlotMappings, verifyUiccSlotMappings); + } + + @Test + public void prepareUiccSlotMappings_oneEsimAndFromDualPortsAToPsimAndPort0_psimAndPort0() { + // There is only one enabled esimPort0 before user enables the psim. + Collection uiccSlotMappings = createUiccSlotMappingDualPortsA(); + Collection verifyUiccSlotMappings = + createUiccSlotMappingPsimAndPort0(); + int removedLogicalSlotIndex = 1; + + Collection testUiccSlotMappings = UiccSlotUtil.prepareUiccSlotMappings( + uiccSlotMappings, true, PSIM_PHYSICAL_SLOT, 0, removedLogicalSlotIndex); + + compareTwoUiccSlotMappings(testUiccSlotMappings, verifyUiccSlotMappings); + } + + @Test + public void prepareUiccSlotMappings_oneEsimAndFromDualPortsBToPsimAndPort1_psimAndPort1() { + // There is only one enabled esimPort1 before user enables the psim. + Collection uiccSlotMappings = createUiccSlotMappingDualPortsB(); + Collection verifyUiccSlotMappings = + createUiccSlotMappingPsimAndPort1(); + int removedLogicalSlotIndex = 1; + + Collection testUiccSlotMappings = UiccSlotUtil.prepareUiccSlotMappings( + uiccSlotMappings, true, PSIM_PHYSICAL_SLOT, 0, removedLogicalSlotIndex); + + compareTwoUiccSlotMappings(testUiccSlotMappings, verifyUiccSlotMappings); + } + + @Test + public void prepareUiccSlotMappings_oneEsimAndFromDualPortsBToPsimAndPort0_psimAndPort0() { + // There is only one enabled esimPort0 before user enables the psim. + Collection uiccSlotMappings = createUiccSlotMappingDualPortsB(); + Collection verifyUiccSlotMappings = + createUiccSlotMappingPsimAndPort0(); + int removedLogicalSlotIndex = 0; + + Collection testUiccSlotMappings = UiccSlotUtil.prepareUiccSlotMappings( + uiccSlotMappings, true, PSIM_PHYSICAL_SLOT, 0, removedLogicalSlotIndex); compareTwoUiccSlotMappings(testUiccSlotMappings, verifyUiccSlotMappings); } @@ -216,10 +277,10 @@ public class UiccSlotUtilTest { Collection uiccSlotMappings = createUiccSlotMappingDualPortsA(); Collection verifyUiccSlotMappings = createUiccSlotMappingPsimAndPort1(); + int removedLogicalSlotIndex = 0; - SubscriptionInfo subInfo = createSubscriptionInfo(0, 0); Collection testUiccSlotMappings = UiccSlotUtil.prepareUiccSlotMappings( - uiccSlotMappings, true, PSIM_PHYSICAL_SLOT, 0, subInfo, true); + uiccSlotMappings, true, PSIM_PHYSICAL_SLOT, 0, removedLogicalSlotIndex); compareTwoUiccSlotMappings(testUiccSlotMappings, verifyUiccSlotMappings); } @@ -229,10 +290,10 @@ public class UiccSlotUtilTest { Collection uiccSlotMappings = createUiccSlotMappingDualPortsA(); Collection verifyUiccSlotMappings = createUiccSlotMappingPsimAndPort0(); + int removedLogicalSlotIndex = 1; - SubscriptionInfo subInfo = createSubscriptionInfo(1, 1); Collection testUiccSlotMappings = UiccSlotUtil.prepareUiccSlotMappings( - uiccSlotMappings, true, PSIM_PHYSICAL_SLOT, 0, subInfo, true); + uiccSlotMappings, true, PSIM_PHYSICAL_SLOT, 0, removedLogicalSlotIndex); compareTwoUiccSlotMappings(testUiccSlotMappings, verifyUiccSlotMappings); } @@ -242,10 +303,10 @@ public class UiccSlotUtilTest { Collection uiccSlotMappings = createUiccSlotMappingDualPortsB(); Collection verifyUiccSlotMappings = createUiccSlotMappingPsimAndPort1(); + int removedLogicalSlotIndex = 1; - SubscriptionInfo subInfo = createSubscriptionInfo(1, 0); Collection testUiccSlotMappings = UiccSlotUtil.prepareUiccSlotMappings( - uiccSlotMappings, true, PSIM_PHYSICAL_SLOT, 0, subInfo, true); + uiccSlotMappings, true, PSIM_PHYSICAL_SLOT, 0, removedLogicalSlotIndex); compareTwoUiccSlotMappings(testUiccSlotMappings, verifyUiccSlotMappings); } @@ -255,20 +316,240 @@ public class UiccSlotUtilTest { Collection uiccSlotMappings = createUiccSlotMappingDualPortsB(); Collection verifyUiccSlotMappings = createUiccSlotMappingPsimAndPort0(); + int removedLogicalSlotIndex = 0; - SubscriptionInfo subInfo = createSubscriptionInfo(0, 1); Collection testUiccSlotMappings = UiccSlotUtil.prepareUiccSlotMappings( - uiccSlotMappings, true, PSIM_PHYSICAL_SLOT, 0, subInfo, true); + uiccSlotMappings, true, PSIM_PHYSICAL_SLOT, 0, removedLogicalSlotIndex); compareTwoUiccSlotMappings(testUiccSlotMappings, verifyUiccSlotMappings); } - private SubscriptionInfo createSubscriptionInfo(int logicalSlotIndex, int portIndex) { - return new SubscriptionInfo( - 0, "", logicalSlotIndex, "", "", 0, 0, "", 0, null, "", "", "", - true /* isEmbedded */, - null, "", 25, - false, null, false, 0, 0, 0, null, null, true, portIndex); + @Test + public void getExcludedLogicalSlotIndex_fromPsimActiveToEsimPort0Active_logicalSlot0() { + Collection uiccSlotMappings = createUiccSlotMappingSsModePsimActive(); + Collection activeSubscriptionInfoList = + createActiveSubscriptionInfoListOneSim(0, 0); + SubscriptionInfo removedSubInfo = null; + int verifyExcludedLogicalSlotIndex = 0; + + int testExcludedLogicalSlotIndex = UiccSlotUtil.getExcludedLogicalSlotIndex( + uiccSlotMappings, activeSubscriptionInfoList, removedSubInfo, false); + + assertThat(testExcludedLogicalSlotIndex).isEqualTo(verifyExcludedLogicalSlotIndex); + } + + @Test + public void getExcludedLogicalSlotIndex_fromEsimPort0ActiveToPsimActive_logicalSlot0() { + Collection uiccSlotMappings = createUiccSlotMappingSsModeEsimPort0Active(); + Collection activeSubscriptionInfoList = + createActiveSubscriptionInfoListOneSim(0, 0); + SubscriptionInfo removedSubInfo = null; + int verifyExcludedLogicalSlotIndex = 0; + + int testExcludedLogicalSlotIndex = UiccSlotUtil.getExcludedLogicalSlotIndex( + uiccSlotMappings, activeSubscriptionInfoList, removedSubInfo, false); + + assertThat(testExcludedLogicalSlotIndex).isEqualTo(verifyExcludedLogicalSlotIndex); + } + + @Test + public void getExcludedLogicalSlotIndex_fromPsimAndPort0ToPsimAndPort1_logicalSlot1() { + Collection uiccSlotMappings = createUiccSlotMappingPsimAndPort0(); + Collection activeSubscriptionInfoList = + createActiveSubscriptionInfoListTwoSims(0, 0, 1, 0); + SubscriptionInfo removedSubInfo = createSubscriptionInfo(1, 0); + int verifyExcludedLogicalSlotIndex = 1; + + int testExcludedLogicalSlotIndex = UiccSlotUtil.getExcludedLogicalSlotIndex( + uiccSlotMappings, activeSubscriptionInfoList, removedSubInfo, true); + + assertThat(testExcludedLogicalSlotIndex).isEqualTo(verifyExcludedLogicalSlotIndex); + } + + @Test + public void getExcludedLogicalSlotIndex_fromPsimAndPort1ToPsimAndPort0_logicalSlot1() { + Collection uiccSlotMappings = createUiccSlotMappingPsimAndPort1(); + Collection activeSubscriptionInfoList = + createActiveSubscriptionInfoListTwoSims(0, 0, 1, 1); + SubscriptionInfo removedSubInfo = createSubscriptionInfo(1, 1); + int verifyExcludedLogicalSlotIndex = 1; + + int testExcludedLogicalSlotIndex = UiccSlotUtil.getExcludedLogicalSlotIndex( + uiccSlotMappings, activeSubscriptionInfoList, removedSubInfo, true); + + assertThat(testExcludedLogicalSlotIndex).isEqualTo(verifyExcludedLogicalSlotIndex); + } + + @Test + public void getExcludedLogicalSlotIndex_fromPsimAndPort0ToDualPortsB_logicalSlot0() { + Collection uiccSlotMappings = createUiccSlotMappingPsimAndPort0(); + Collection activeSubscriptionInfoList = + createActiveSubscriptionInfoListTwoSims(0, 0, 1, 0); + SubscriptionInfo removedSubInfo = createSubscriptionInfo(0, 0); + int verifyExcludedLogicalSlotIndex = 0; + + int testExcludedLogicalSlotIndex = UiccSlotUtil.getExcludedLogicalSlotIndex( + uiccSlotMappings, activeSubscriptionInfoList, removedSubInfo, true); + + assertThat(testExcludedLogicalSlotIndex).isEqualTo(verifyExcludedLogicalSlotIndex); + } + + @Test + public void getExcludedLogicalSlotIndex_fromPsimAndPort1ToDualPortsA_logicalSlot0() { + Collection uiccSlotMappings = createUiccSlotMappingPsimAndPort1(); + Collection activeSubscriptionInfoList = + createActiveSubscriptionInfoListTwoSims(0, 0, 1, 1); + SubscriptionInfo removedSubInfo = createSubscriptionInfo(0, 0); + int verifyExcludedLogicalSlotIndex = 0; + + int testExcludedLogicalSlotIndex = UiccSlotUtil.getExcludedLogicalSlotIndex( + uiccSlotMappings, activeSubscriptionInfoList, removedSubInfo, true); + + assertThat(testExcludedLogicalSlotIndex).isEqualTo(verifyExcludedLogicalSlotIndex); + } + + @Test + public void getExcludedLogicalSlotIndex_noPsimAndFromPsimAndPort0ToDualPortsB_logicalSlot0() { + Collection uiccSlotMappings = createUiccSlotMappingPsimAndPort0(); + Collection activeSubscriptionInfoList = + createActiveSubscriptionInfoListOneSim(1, 0); + SubscriptionInfo removedSubInfo = null; + int verifyExcludedLogicalSlotIndex = 0; + + int testExcludedLogicalSlotIndex = UiccSlotUtil.getExcludedLogicalSlotIndex( + uiccSlotMappings, activeSubscriptionInfoList, removedSubInfo, true); + + assertThat(testExcludedLogicalSlotIndex).isEqualTo(verifyExcludedLogicalSlotIndex); + } + + @Test + public void getExcludedLogicalSlotIndex_noPsimAndFromPsimAndPort1ToDualPortsA_logicalSlot0() { + Collection uiccSlotMappings = createUiccSlotMappingPsimAndPort1(); + Collection activeSubscriptionInfoList = + createActiveSubscriptionInfoListOneSim(1, 1); + SubscriptionInfo removedSubInfo = null; + int verifyExcludedLogicalSlotIndex = 0; + + int testExcludedLogicalSlotIndex = UiccSlotUtil.getExcludedLogicalSlotIndex( + uiccSlotMappings, activeSubscriptionInfoList, removedSubInfo, true); + + assertThat(testExcludedLogicalSlotIndex).isEqualTo(verifyExcludedLogicalSlotIndex); + } + + @Test + public void getExcludedLogicalSlotIndex_oneEsimAndFromDualPortsAToPsimAndPort1_logicalSlot0() { + // There is only one enabled esimPort1 before user enables the psim. + Collection uiccSlotMappings = createUiccSlotMappingDualPortsA(); + Collection activeSubscriptionInfoList = + createActiveSubscriptionInfoListOneSim(1, 1); + SubscriptionInfo removedSubInfo = null; + int verifyExcludedLogicalSlotIndex = 0; + + int testExcludedLogicalSlotIndex = UiccSlotUtil.getExcludedLogicalSlotIndex( + uiccSlotMappings, activeSubscriptionInfoList, removedSubInfo, true); + + assertThat(testExcludedLogicalSlotIndex).isEqualTo(verifyExcludedLogicalSlotIndex); + } + + @Test + public void getExcludedLogicalSlotIndex_oneEsimAndFromDualPortsAToPsimAndPort0_logicalSlot1() { + // There is only one enabled esimPort0 before user enables the psim. + Collection uiccSlotMappings = createUiccSlotMappingPsimAndPort1(); + Collection activeSubscriptionInfoList = + createActiveSubscriptionInfoListOneSim(0, 0); + SubscriptionInfo removedSubInfo = null; + int verifyExcludedLogicalSlotIndex = 1; + + int testExcludedLogicalSlotIndex = UiccSlotUtil.getExcludedLogicalSlotIndex( + uiccSlotMappings, activeSubscriptionInfoList, removedSubInfo, true); + + assertThat(testExcludedLogicalSlotIndex).isEqualTo(verifyExcludedLogicalSlotIndex); + } + + @Test + public void getExcludedLogicalSlotIndex_oneEsimAndFromDualPortsBToPsimAndPort1_logicalSlot1() { + // There is only one enabled esimPort1 before user enables the psim. + Collection uiccSlotMappings = createUiccSlotMappingPsimAndPort1(); + Collection activeSubscriptionInfoList = + createActiveSubscriptionInfoListOneSim(0, 1); + SubscriptionInfo removedSubInfo = null; + int verifyExcludedLogicalSlotIndex = 1; + + int testExcludedLogicalSlotIndex = UiccSlotUtil.getExcludedLogicalSlotIndex( + uiccSlotMappings, activeSubscriptionInfoList, removedSubInfo, true); + + assertThat(testExcludedLogicalSlotIndex).isEqualTo(verifyExcludedLogicalSlotIndex); + } + + @Test + public void getExcludedLogicalSlotIndex_oneEsimAndFromDualPortsBToPsimAndPort0_logicalSlot0() { + // There is only one enabled esimPort0 before user enables the psim. + Collection uiccSlotMappings = createUiccSlotMappingPsimAndPort1(); + Collection activeSubscriptionInfoList = + createActiveSubscriptionInfoListOneSim(1, 0); + SubscriptionInfo removedSubInfo = null; + int verifyExcludedLogicalSlotIndex = 0; + + int testExcludedLogicalSlotIndex = UiccSlotUtil.getExcludedLogicalSlotIndex( + uiccSlotMappings, activeSubscriptionInfoList, removedSubInfo, true); + + assertThat(testExcludedLogicalSlotIndex).isEqualTo(verifyExcludedLogicalSlotIndex); + } + + @Test + public void getExcludedLogicalSlotIndex_fromDualPortsAToPsimAndPort1_logicalSlot0() { + Collection uiccSlotMappings = createUiccSlotMappingDualPortsA(); + Collection activeSubscriptionInfoList = + createActiveSubscriptionInfoListTwoSims(0, 0, 1, 1); + SubscriptionInfo removedSubInfo = createSubscriptionInfo(0, 0); + int verifyExcludedLogicalSlotIndex = 0; + + int testExcludedLogicalSlotIndex = UiccSlotUtil.getExcludedLogicalSlotIndex( + uiccSlotMappings, activeSubscriptionInfoList, removedSubInfo, true); + + assertThat(testExcludedLogicalSlotIndex).isEqualTo(verifyExcludedLogicalSlotIndex); + } + + @Test + public void getExcludedLogicalSlotIndex_fromDualPortsAToPsimAndPort0_logicalSlot1() { + Collection uiccSlotMappings = createUiccSlotMappingDualPortsA(); + Collection activeSubscriptionInfoList = + createActiveSubscriptionInfoListTwoSims(0, 0, 1, 1); + SubscriptionInfo removedSubInfo = createSubscriptionInfo(1, 1); + int verifyExcludedLogicalSlotIndex = 1; + + int testExcludedLogicalSlotIndex = UiccSlotUtil.getExcludedLogicalSlotIndex( + uiccSlotMappings, activeSubscriptionInfoList, removedSubInfo, true); + + assertThat(testExcludedLogicalSlotIndex).isEqualTo(verifyExcludedLogicalSlotIndex); + } + + @Test + public void getExcludedLogicalSlotIndex_fromDualPortsBToPsimAndPort1_logicalSlot1() { + Collection uiccSlotMappings = createUiccSlotMappingDualPortsB(); + Collection activeSubscriptionInfoList = + createActiveSubscriptionInfoListTwoSims(0, 1, 1, 0); + SubscriptionInfo removedSubInfo = createSubscriptionInfo(1, 0); + int verifyExcludedLogicalSlotIndex = 1; + + int testExcludedLogicalSlotIndex = UiccSlotUtil.getExcludedLogicalSlotIndex( + uiccSlotMappings, activeSubscriptionInfoList, removedSubInfo, true); + + assertThat(testExcludedLogicalSlotIndex).isEqualTo(verifyExcludedLogicalSlotIndex); + } + + @Test + public void getExcludedLogicalSlotIndex_fromDualPortsBToPsimAndPort0_logicalSlot0() { + Collection uiccSlotMappings = createUiccSlotMappingDualPortsB(); + Collection activeSubscriptionInfoList = + createActiveSubscriptionInfoListTwoSims(0, 1, 1, 0); + SubscriptionInfo removedSubInfo = createSubscriptionInfo(0, 1); + int verifyExcludedLogicalSlotIndex = 0; + + int testExcludedLogicalSlotIndex = UiccSlotUtil.getExcludedLogicalSlotIndex( + uiccSlotMappings, activeSubscriptionInfoList, removedSubInfo, true); + + assertThat(testExcludedLogicalSlotIndex).isEqualTo(verifyExcludedLogicalSlotIndex); } private void compareTwoUiccSlotMappings(Collection testUiccSlotMappings, @@ -288,6 +569,30 @@ public class UiccSlotUtilTest { } } + private SubscriptionInfo createSubscriptionInfo(int logicalSlotIndex, int portIndex) { + return new SubscriptionInfo( + 0, "", logicalSlotIndex, "", "", 0, 0, "", 0, null, "", "", "", + true /* isEmbedded */, + null, "", 25, + false, null, false, 0, 0, 0, null, null, true, portIndex); + } + + private List createActiveSubscriptionInfoListOneSim(int logicalSlotIndex, + int portIndex) { + List subscriptionInfoList = new ArrayList<>(); + subscriptionInfoList.add(createSubscriptionInfo(logicalSlotIndex, portIndex)); + + return subscriptionInfoList; + } + + private List createActiveSubscriptionInfoListTwoSims(int logicalSlotIndex1, + int portIndex1, int logicalSlotIndex2, int portIndex2) { + List subscriptionInfoList = new ArrayList<>(); + subscriptionInfoList.add(createSubscriptionInfo(logicalSlotIndex1, portIndex1)); + subscriptionInfoList.add(createSubscriptionInfo(logicalSlotIndex2, portIndex2)); + return subscriptionInfoList; + } + // Device | |Slot | // Working| |Mapping| // State |Type |Mode |Friendly name From 71f2d6d44cddea34a53f1f4cf8f0b7b0e4143b0e Mon Sep 17 00:00:00 2001 From: Chaohui Wang Date: Mon, 7 Mar 2022 09:36:10 +0000 Subject: [PATCH 4/4] Fix Other default preferences alignment Bug: 222333696 Change-Id: Icdcfff728c891b81d3976f3d625aa93b5154198c Test: Manual on Pixel device --- res/layout/app_preferred_settings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/res/layout/app_preferred_settings.xml b/res/layout/app_preferred_settings.xml index b3343f5e394..126b9d84d02 100644 --- a/res/layout/app_preferred_settings.xml +++ b/res/layout/app_preferred_settings.xml @@ -18,7 +18,7 @@ xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" - android:paddingStart="@dimen/preference_no_icon_padding_start" + android:paddingStart="?android:attr/listPreferredItemPaddingStart" android:paddingEnd="?android:attr/listPreferredItemPaddingEnd" android:paddingBottom="5dip" android:orientation="vertical">