Merge "Remove on/off toggle for physical SIMs" into qt-dev am: 5836158f2e am: 5d186f5346

am: f0e3ac6f27

Change-Id: I4dd3e2855de57f1a3e3001fa8cda3206e8e045f4
This commit is contained in:
Antony Sargent
2019-06-11 13:27:54 -07:00
committed by android-build-merger
11 changed files with 261 additions and 29 deletions

View File

@@ -21,6 +21,8 @@ import static android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
@@ -32,6 +34,7 @@ import android.content.Context;
import android.content.Intent;
import android.provider.Settings;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.telephony.euicc.EuiccManager;
@@ -54,9 +57,11 @@ import androidx.preference.PreferenceScreen;
@RunWith(RobolectricTestRunner.class)
public class MobileNetworkListControllerTest {
@Mock
TelephonyManager mTelephonyManager;
private TelephonyManager mTelephonyManager;
@Mock
EuiccManager mEuiccManager;
private EuiccManager mEuiccManager;
@Mock
private SubscriptionManager mSubscriptionManager;
@Mock
private Lifecycle mLifecycle;
@@ -74,6 +79,7 @@ public class MobileNetworkListControllerTest {
mContext = spy(Robolectric.setupActivity(Activity.class));
when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
when(mContext.getSystemService(EuiccManager.class)).thenReturn(mEuiccManager);
when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager);
Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.EUICC_PROVISIONED, 1);
when(mPreferenceScreen.getContext()).thenReturn(mContext);
mAddMorePreference = new Preference(mContext);
@@ -114,6 +120,8 @@ public class MobileNetworkListControllerTest {
public void displayPreference_twoSubscriptions_correctlySetup() {
final SubscriptionInfo sub1 = createMockSubscription(1, "sub1");
final SubscriptionInfo sub2 = createMockSubscription(2, "sub2");
doReturn(true).when(mSubscriptionManager).isActiveSubscriptionId(eq(1));
doReturn(true).when(mSubscriptionManager).isActiveSubscriptionId(eq(2));
SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(sub1, sub2));
mController.displayPreference(mPreferenceScreen);
mController.onResume();
@@ -138,6 +146,33 @@ public class MobileNetworkListControllerTest {
assertThat(intent2.getIntExtra(EXTRA_SUB_ID, INVALID_SUBSCRIPTION_ID)).isEqualTo(2);
}
@Test
public void displayPreference_oneActiveESimOneInactivePSim_correctlySetup() {
final SubscriptionInfo sub1 = createMockSubscription(1, "sub1");
final SubscriptionInfo sub2 = createMockSubscription(2, "sub2");
when(sub1.isEmbedded()).thenReturn(true);
doReturn(true).when(mSubscriptionManager).isActiveSubscriptionId(eq(1));
doReturn(false).when(mSubscriptionManager).isActiveSubscriptionId(eq(2));
when(sub2.isEmbedded()).thenReturn(false);
SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(sub1, sub2));
mController.displayPreference(mPreferenceScreen);
mController.onResume();
// Check that the preferences get created with the correct summaries.
final ArgumentCaptor<Preference> preferenceCaptor = ArgumentCaptor.forClass(
Preference.class);
verify(mPreferenceScreen, times(2)).addPreference(preferenceCaptor.capture());
final Preference pref1 = preferenceCaptor.getAllValues().get(0);
final Preference pref2 = preferenceCaptor.getAllValues().get(1);
assertThat(pref1.getSummary()).isEqualTo("Active / Downloaded SIM");
assertThat(pref2.getSummary()).isEqualTo("Tap to activate sub2");
pref2.getOnPreferenceClickListener().onPreferenceClick(pref2);
verify(mSubscriptionManager).setSubscriptionEnabled(eq(2), eq(true));
}
@Test
public void onSubscriptionsChanged_twoSubscriptionsOneChangesName_preferenceUpdated() {
final SubscriptionInfo sub1 = createMockSubscription(1, "sub1");

View File

@@ -18,6 +18,7 @@ package com.android.settings.network;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.notNull;
import static org.mockito.Mockito.atLeastOnce;
@@ -64,6 +65,8 @@ public class MobileNetworkSummaryControllerTest {
@Mock
private TelephonyManager mTelephonyManager;
@Mock
private SubscriptionManager mSubscriptionManager;
@Mock
private EuiccManager mEuiccManager;
@Mock
private PreferenceScreen mPreferenceScreen;
@@ -79,9 +82,11 @@ public class MobileNetworkSummaryControllerTest {
MockitoAnnotations.initMocks(this);
mContext = spy(Robolectric.setupActivity(Activity.class));
when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager);
when(mContext.getSystemService(EuiccManager.class)).thenReturn(mEuiccManager);
when(mContext.getSystemService(UserManager.class)).thenReturn(mUserManager);
when(mTelephonyManager.getNetworkCountryIso()).thenReturn("");
when(mSubscriptionManager.isActiveSubscriptionId(anyInt())).thenReturn(true);
when(mEuiccManager.isEnabled()).thenReturn(true);
Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.EUICC_PROVISIONED, 1);
@@ -159,6 +164,24 @@ public class MobileNetworkSummaryControllerTest {
SubscriptionManager.INVALID_SUBSCRIPTION_ID)).isEqualTo(sub1.getSubscriptionId());
}
@Test
public void getSummary_oneInactivePSim_correctSummaryAndClickHandler() {
final SubscriptionInfo sub1 = mock(SubscriptionInfo.class);
when(sub1.getSubscriptionId()).thenReturn(1);
when(sub1.getDisplayName()).thenReturn("sub1");
SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(sub1));
when(mSubscriptionManager.isActiveSubscriptionId(eq(1))).thenReturn(false);
mController.displayPreference(mPreferenceScreen);
mController.onResume();
assertThat(mController.getSummary()).isEqualTo("Tap to activate sub1");
assertThat(mPreference.getFragment()).isNull();
mPreference.getOnPreferenceClickListener().onPreferenceClick(mPreference);
verify(mSubscriptionManager).setSubscriptionEnabled(eq(sub1.getSubscriptionId()), eq(true));
}
@Test
public void getSummary_twoSubscriptions_correctSummaryAndFragment() {
final SubscriptionInfo sub1 = mock(SubscriptionInfo.class);

View File

@@ -0,0 +1,77 @@
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.network.telephony;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.telephony.SubscriptionInfo;
import com.android.settings.network.SubscriptionUtil;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import java.util.Arrays;
@RunWith(RobolectricTestRunner.class)
public class DisableSimFooterPreferenceControllerTest {
private static final String PREF_KEY = "pref_key";
private static final int SUB_ID = 111;
@Mock
private SubscriptionInfo mInfo;
private Context mContext;
private DisableSimFooterPreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
when(mInfo.getSubscriptionId()).thenReturn(SUB_ID);
SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(mInfo));
mController = new DisableSimFooterPreferenceController(mContext, PREF_KEY);
}
@Test
public void isAvailable_noInit_notAvailable() {
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void isAvailable_eSIM_notAvailable() {
when(mInfo.isEmbedded()).thenReturn(true);
mController.init(SUB_ID);
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void isAvailable_pSIM_available() {
when(mInfo.isEmbedded()).thenReturn(false);
mController.init(SUB_ID);
assertThat(mController.isAvailable()).isTrue();
}
}

View File

@@ -79,13 +79,14 @@ public class MobileNetworkSwitchControllerTest {
mLifecycleOwner = () -> mLifecycle;
mLifecycle = new Lifecycle(mLifecycleOwner);
when(mSubscription.isEmbedded()).thenReturn(true);
when(mSubscription.getSubscriptionId()).thenReturn(mSubId);
// Most tests want to have 2 available subscriptions so that the switch bar will show.
SubscriptionInfo sub2 = mock(SubscriptionInfo.class);
final SubscriptionInfo sub2 = mock(SubscriptionInfo.class);
when(sub2.getSubscriptionId()).thenReturn(456);
SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(mSubscription, sub2));
String key = "prefKey";
final String key = "prefKey";
mController = new MobileNetworkSwitchController(mContext, key);
mController.init(mLifecycle, mSubscription.getSubscriptionId());
@@ -100,11 +101,18 @@ public class MobileNetworkSwitchControllerTest {
}
@Test
public void displayPreference_oneEnabledSubscription_switchBarHidden() {
public void isAvailable_pSIM_isNotAvailable() {
when(mSubscription.isEmbedded()).thenReturn(false);
mController.displayPreference(mScreen);
assertThat(mSwitchBar.isShowing()).isFalse();
}
@Test
public void displayPreference_oneEnabledSubscription_switchBarNotHidden() {
doReturn(true).when(mSubscriptionManager).isSubscriptionEnabled(mSubId);
SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(mSubscription));
mController.displayPreference(mScreen);
assertThat(mSwitchBar.isShowing()).isFalse();
assertThat(mSwitchBar.isShowing()).isTrue();
}
@Test