packages/apps/Settings
リビジョン | 0968b8603e156f2f60f05f348c0a2982fe85493b (tree) |
---|---|
日時 | 2020-12-18 00:27:46 |
作者 | Bonian Chen <bonianchen@goog...> |
コミッター | Android (Google) Code Review |
Merge changes from topic "eSIM with same group UUID" into rvc-qpr-dev
* changes:
@@ -52,6 +52,7 @@ import com.android.settingslib.core.AbstractPreferenceController; | ||
52 | 52 | import com.android.settingslib.net.SignalStrengthUtil; |
53 | 53 | |
54 | 54 | import java.util.Collections; |
55 | +import java.util.List; | |
55 | 56 | import java.util.Map; |
56 | 57 | import java.util.Set; |
57 | 58 |
@@ -166,6 +167,12 @@ public class SubscriptionsPreferenceController extends AbstractPreferenceControl | ||
166 | 167 | final int dataDefaultSubId = SubscriptionManager.getDefaultDataSubscriptionId(); |
167 | 168 | for (SubscriptionInfo info : SubscriptionUtil.getActiveSubscriptions(mManager)) { |
168 | 169 | 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 | + } | |
169 | 176 | activeSubIds.add(subId); |
170 | 177 | Preference pref = existingPrefs.remove(subId); |
171 | 178 | if (pref == null) { |
@@ -292,7 +299,17 @@ public class SubscriptionsPreferenceController extends AbstractPreferenceControl | ||
292 | 299 | if (mSubscriptionsListener.isAirplaneModeOn()) { |
293 | 300 | return false; |
294 | 301 | } |
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; | |
296 | 313 | } |
297 | 314 | |
298 | 315 | @Override |
@@ -330,4 +347,10 @@ public class SubscriptionsPreferenceController extends AbstractPreferenceControl | ||
330 | 347 | public void onSignalStrengthChanged() { |
331 | 348 | update(); |
332 | 349 | } |
350 | + | |
351 | + @VisibleForTesting | |
352 | + boolean canSubscriptionBeDisplayed(Context context, int subId) { | |
353 | + return (SubscriptionUtil.getAvailableSubscription(context, | |
354 | + ProxySubscriptionManager.getInstance(context), subId) != null); | |
355 | + } | |
333 | 356 | } |
@@ -37,11 +37,9 @@ import static org.mockito.Mockito.times; | ||
37 | 37 | import static org.mockito.Mockito.verify; |
38 | 38 | import static org.mockito.Mockito.when; |
39 | 39 | |
40 | -import android.app.Activity; | |
41 | 40 | import android.content.Context; |
42 | 41 | import android.content.Intent; |
43 | 42 | import android.graphics.drawable.Drawable; |
44 | -import android.graphics.drawable.LayerDrawable; | |
45 | 43 | import android.net.ConnectivityManager; |
46 | 44 | import android.net.Network; |
47 | 45 | import android.net.NetworkCapabilities; |
@@ -51,9 +49,13 @@ import android.telephony.SubscriptionInfo; | ||
51 | 49 | import android.telephony.SubscriptionManager; |
52 | 50 | import android.telephony.TelephonyManager; |
53 | 51 | |
52 | +import androidx.lifecycle.LifecycleOwner; | |
53 | +import androidx.preference.Preference; | |
54 | +import androidx.preference.PreferenceCategory; | |
55 | +import androidx.preference.PreferenceScreen; | |
56 | + | |
54 | 57 | import com.android.settings.R; |
55 | 58 | import com.android.settingslib.core.lifecycle.Lifecycle; |
56 | -import com.android.settingslib.graph.SignalDrawable; | |
57 | 59 | |
58 | 60 | import org.junit.After; |
59 | 61 | import org.junit.Before; |
@@ -62,7 +64,6 @@ import org.junit.runner.RunWith; | ||
62 | 64 | import org.mockito.ArgumentCaptor; |
63 | 65 | import org.mockito.Mock; |
64 | 66 | import org.mockito.MockitoAnnotations; |
65 | -import org.robolectric.Robolectric; | |
66 | 67 | import org.robolectric.RobolectricTestRunner; |
67 | 68 | import org.robolectric.RuntimeEnvironment; |
68 | 69 | import org.robolectric.annotation.Config; |
@@ -72,11 +73,6 @@ import java.util.ArrayList; | ||
72 | 73 | import java.util.Arrays; |
73 | 74 | import java.util.List; |
74 | 75 | |
75 | -import androidx.lifecycle.LifecycleOwner; | |
76 | -import androidx.preference.Preference; | |
77 | -import androidx.preference.PreferenceCategory; | |
78 | -import androidx.preference.PreferenceScreen; | |
79 | - | |
80 | 76 | @RunWith(RobolectricTestRunner.class) |
81 | 77 | @Config(shadows = ShadowSubscriptionManager.class) |
82 | 78 | public class SubscriptionsPreferenceControllerTest { |
@@ -126,6 +122,7 @@ public class SubscriptionsPreferenceControllerTest { | ||
126 | 122 | mController = spy( |
127 | 123 | new SubscriptionsPreferenceController(mContext, mLifecycle, mUpdateListener, |
128 | 124 | KEY, 5)); |
125 | + doReturn(true).when(mController).canSubscriptionBeDisplayed(any(), anyInt()); | |
129 | 126 | doReturn(mSignalStrengthIcon).when(mController).getIcon(anyInt(), anyInt(), anyBoolean()); |
130 | 127 | } |
131 | 128 |
@@ -459,6 +456,17 @@ public class SubscriptionsPreferenceControllerTest { | ||
459 | 456 | eq(true)); |
460 | 457 | } |
461 | 458 | |
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 | + } | |
462 | 470 | |
463 | 471 | @Test |
464 | 472 | public void onMobileDataEnabledChange_mobileDataTurnedOff_bothSubsHaveCutOut() { |