• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

packages/apps/Settings


Commit MetaInfo

Revisión0968b8603e156f2f60f05f348c0a2982fe85493b (tree)
Tiempo2020-12-18 00:27:46
AutorBonian Chen <bonianchen@goog...>
CommiterAndroid (Google) Code Review

Log Message

Merge changes from topic "eSIM with same group UUID" into rvc-qpr-dev

* changes:

[Settings] code refactor - rename isSubscriptionCanBeDisplayed
[Settings] Only display 1 SIM UI when multiple with same group UUID

Cambiar Resumen

Diferencia incremental

--- a/src/com/android/settings/network/SubscriptionsPreferenceController.java
+++ b/src/com/android/settings/network/SubscriptionsPreferenceController.java
@@ -52,6 +52,7 @@ import com.android.settingslib.core.AbstractPreferenceController;
5252 import com.android.settingslib.net.SignalStrengthUtil;
5353
5454 import java.util.Collections;
55+import java.util.List;
5556 import java.util.Map;
5657 import java.util.Set;
5758
@@ -166,6 +167,12 @@ public class SubscriptionsPreferenceController extends AbstractPreferenceControl
166167 final int dataDefaultSubId = SubscriptionManager.getDefaultDataSubscriptionId();
167168 for (SubscriptionInfo info : SubscriptionUtil.getActiveSubscriptions(mManager)) {
168169 final int subId = info.getSubscriptionId();
170+ // Avoid from showing subscription(SIM)s which has been marked as hidden
171+ // For example, only one subscription will be shown when there're multiple
172+ // subscriptions with same group UUID.
173+ if (!canSubscriptionBeDisplayed(mContext, subId)) {
174+ continue;
175+ }
169176 activeSubIds.add(subId);
170177 Preference pref = existingPrefs.remove(subId);
171178 if (pref == null) {
@@ -292,7 +299,17 @@ public class SubscriptionsPreferenceController extends AbstractPreferenceControl
292299 if (mSubscriptionsListener.isAirplaneModeOn()) {
293300 return false;
294301 }
295- return SubscriptionUtil.getActiveSubscriptions(mManager).size() >= 2;
302+ List<SubscriptionInfo> subInfoList = SubscriptionUtil.getActiveSubscriptions(mManager);
303+ if (subInfoList == null) {
304+ return false;
305+ }
306+ return subInfoList.stream()
307+ // Avoid from showing subscription(SIM)s which has been marked as hidden
308+ // For example, only one subscription will be shown when there're multiple
309+ // subscriptions with same group UUID.
310+ .filter(subInfo ->
311+ canSubscriptionBeDisplayed(mContext, subInfo.getSubscriptionId()))
312+ .count() >= 2;
296313 }
297314
298315 @Override
@@ -330,4 +347,10 @@ public class SubscriptionsPreferenceController extends AbstractPreferenceControl
330347 public void onSignalStrengthChanged() {
331348 update();
332349 }
350+
351+ @VisibleForTesting
352+ boolean canSubscriptionBeDisplayed(Context context, int subId) {
353+ return (SubscriptionUtil.getAvailableSubscription(context,
354+ ProxySubscriptionManager.getInstance(context), subId) != null);
355+ }
333356 }
--- a/tests/robotests/src/com/android/settings/network/SubscriptionsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/SubscriptionsPreferenceControllerTest.java
@@ -37,11 +37,9 @@ import static org.mockito.Mockito.times;
3737 import static org.mockito.Mockito.verify;
3838 import static org.mockito.Mockito.when;
3939
40-import android.app.Activity;
4140 import android.content.Context;
4241 import android.content.Intent;
4342 import android.graphics.drawable.Drawable;
44-import android.graphics.drawable.LayerDrawable;
4543 import android.net.ConnectivityManager;
4644 import android.net.Network;
4745 import android.net.NetworkCapabilities;
@@ -51,9 +49,13 @@ import android.telephony.SubscriptionInfo;
5149 import android.telephony.SubscriptionManager;
5250 import android.telephony.TelephonyManager;
5351
52+import androidx.lifecycle.LifecycleOwner;
53+import androidx.preference.Preference;
54+import androidx.preference.PreferenceCategory;
55+import androidx.preference.PreferenceScreen;
56+
5457 import com.android.settings.R;
5558 import com.android.settingslib.core.lifecycle.Lifecycle;
56-import com.android.settingslib.graph.SignalDrawable;
5759
5860 import org.junit.After;
5961 import org.junit.Before;
@@ -62,7 +64,6 @@ import org.junit.runner.RunWith;
6264 import org.mockito.ArgumentCaptor;
6365 import org.mockito.Mock;
6466 import org.mockito.MockitoAnnotations;
65-import org.robolectric.Robolectric;
6667 import org.robolectric.RobolectricTestRunner;
6768 import org.robolectric.RuntimeEnvironment;
6869 import org.robolectric.annotation.Config;
@@ -72,11 +73,6 @@ import java.util.ArrayList;
7273 import java.util.Arrays;
7374 import java.util.List;
7475
75-import androidx.lifecycle.LifecycleOwner;
76-import androidx.preference.Preference;
77-import androidx.preference.PreferenceCategory;
78-import androidx.preference.PreferenceScreen;
79-
8076 @RunWith(RobolectricTestRunner.class)
8177 @Config(shadows = ShadowSubscriptionManager.class)
8278 public class SubscriptionsPreferenceControllerTest {
@@ -126,6 +122,7 @@ public class SubscriptionsPreferenceControllerTest {
126122 mController = spy(
127123 new SubscriptionsPreferenceController(mContext, mLifecycle, mUpdateListener,
128124 KEY, 5));
125+ doReturn(true).when(mController).canSubscriptionBeDisplayed(any(), anyInt());
129126 doReturn(mSignalStrengthIcon).when(mController).getIcon(anyInt(), anyInt(), anyBoolean());
130127 }
131128
@@ -459,6 +456,17 @@ public class SubscriptionsPreferenceControllerTest {
459456 eq(true));
460457 }
461458
459+ @Test
460+ public void displayPreference_subscriptionsWithSameGroupUUID_onlyOneWillBeSeen() {
461+ doReturn(false).when(mController).canSubscriptionBeDisplayed(any(), eq(3));
462+ final List<SubscriptionInfo> subs = setupMockSubscriptions(3);
463+ SubscriptionUtil.setActiveSubscriptionsForTesting(subs.subList(0, 3));
464+
465+ mController.onResume();
466+ mController.displayPreference(mScreen);
467+
468+ verify(mPreferenceCategory, times(2)).addPreference(any(Preference.class));
469+ }
462470
463471 @Test
464472 public void onMobileDataEnabledChange_mobileDataTurnedOff_bothSubsHaveCutOut() {