Merge sc-v2-dev-plus-aosp-without-vendor@8084891
Bug: 214455710 Merged-In: I962c318f41adcf180b885f2052ce0ec4952edfb6 Change-Id: I77764eaf895ac3c13c7440adb5b3f597a516d690
This commit is contained in:
@@ -34,6 +34,7 @@ import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.AppOpsManager;
|
||||
import android.apphibernation.AppHibernationManager;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.provider.DeviceConfig;
|
||||
@@ -61,6 +62,8 @@ public class HibernationSwitchPreferenceControllerTest {
|
||||
@Mock
|
||||
private PackageManager mPackageManager;
|
||||
@Mock
|
||||
private AppHibernationManager mAppHibernationManager;
|
||||
@Mock
|
||||
private SwitchPreference mPreference;
|
||||
|
||||
private HibernationSwitchPreferenceController mController;
|
||||
@@ -71,6 +74,8 @@ public class HibernationSwitchPreferenceControllerTest {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||
when(mContext.getSystemService(Context.APP_OPS_SERVICE)).thenReturn(mAppOpsManager);
|
||||
when(mContext.getSystemService(AppHibernationManager.class))
|
||||
.thenReturn(mAppHibernationManager);
|
||||
when(mPackageManager.getPackageUid(eq(VALID_PACKAGE_NAME), anyInt()))
|
||||
.thenReturn(PACKAGE_UID);
|
||||
when(mPackageManager.getPackageUid(eq(INVALID_PACKAGE_NAME), anyInt()))
|
||||
@@ -109,6 +114,15 @@ public class HibernationSwitchPreferenceControllerTest {
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChange_unhibernatesWhenExempted() {
|
||||
mController.setPackage(VALID_PACKAGE_NAME);
|
||||
mController.onPreferenceChange(mPreference, false);
|
||||
|
||||
verify(mAppHibernationManager).setHibernatingForUser(VALID_PACKAGE_NAME, false);
|
||||
verify(mAppHibernationManager).setHibernatingGlobally(VALID_PACKAGE_NAME, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_exemptedByDefaultPackage_shouldNotCheck() {
|
||||
when(mAppOpsManager.unsafeCheckOpNoThrow(
|
||||
|
@@ -167,8 +167,8 @@ public class ParentalConsentHelperTest {
|
||||
}
|
||||
|
||||
// initial consent status
|
||||
final ParentalConsentHelper helper =
|
||||
new ParentalConsentHelper(requireFace, requireFingerprint, gkpw);
|
||||
final ParentalConsentHelper helper = new ParentalConsentHelper(gkpw);
|
||||
helper.setConsentRequirement(requireFace, requireFingerprint);
|
||||
assertThat(ParentalConsentHelper.hasFaceConsent(helper.getConsentResult()))
|
||||
.isFalse();
|
||||
assertThat(ParentalConsentHelper.hasFingerprintConsent(helper.getConsentResult()))
|
||||
|
@@ -119,6 +119,11 @@ public class TogglePreferenceControllerTest {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSliceHighlightMenuRes() {
|
||||
return 5678;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return AVAILABLE;
|
||||
|
@@ -33,6 +33,7 @@ import static com.android.settings.deviceinfo.simstatus.SimStatusDialogControlle
|
||||
import static com.android.settings.deviceinfo.simstatus.SimStatusDialogController.SIGNAL_STRENGTH_LABEL_ID;
|
||||
import static com.android.settings.deviceinfo.simstatus.SimStatusDialogController.SIGNAL_STRENGTH_VALUE_ID;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
@@ -78,12 +79,16 @@ import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class SimStatusDialogControllerTest {
|
||||
|
||||
@Mock
|
||||
private SimStatusDialogFragment mDialog;
|
||||
@Mock
|
||||
private TelephonyManager mTelephonyManager;
|
||||
@Mock
|
||||
private SubscriptionInfo mSubscriptionInfo;
|
||||
@@ -109,6 +114,9 @@ public class SimStatusDialogControllerTest {
|
||||
@Mock
|
||||
private LifecycleOwner mLifecycleOwner;
|
||||
private Lifecycle mLifecycle;
|
||||
private AtomicBoolean mEuiccEnabled;
|
||||
private AtomicReference<String> mEid;
|
||||
private AtomicInteger mUpdatePhoneNumberCount;
|
||||
|
||||
private static final String TEST_EID_FROM_CARD = "11111111111111111111111111111111";
|
||||
private static final String TEST_EID_FROM_MANAGER = "22222222222222222222222222222222";
|
||||
@@ -139,7 +147,26 @@ public class SimStatusDialogControllerTest {
|
||||
doReturn(2).when(mTelephonyManager).getCardIdForDefaultEuicc();
|
||||
doReturn(TelephonyManager.NETWORK_TYPE_LTE).when(mTelephonyManager).getDataNetworkType();
|
||||
|
||||
mController = spy(new SimStatusDialogController(mDialog, mLifecycle, 0 /* phone id */));
|
||||
mUpdatePhoneNumberCount = new AtomicInteger();
|
||||
mEuiccEnabled = new AtomicBoolean(false);
|
||||
mEid = new AtomicReference<String>("");
|
||||
mController = new SimStatusDialogController(mDialog, mLifecycle, 0 /* phone id */) {
|
||||
@Override
|
||||
public TelephonyManager getTelephonyManager() {
|
||||
return mTelephonyManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AtomicReference<String> getEid(int slotIndex) {
|
||||
return mEuiccEnabled.get() ? mEid : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePhoneNumber() {
|
||||
super.updatePhoneNumber();
|
||||
mUpdatePhoneNumberCount.incrementAndGet();
|
||||
}
|
||||
};
|
||||
// CellSignalStrength setup
|
||||
doReturn(0).when(mCellSignalStrengthCdma).getDbm();
|
||||
doReturn(0).when(mCellSignalStrengthCdma).getAsuLevel();
|
||||
@@ -157,7 +184,7 @@ public class SimStatusDialogControllerTest {
|
||||
.getLogicalToPhysicalSlotMapping();
|
||||
|
||||
when(mEuiccManager.isEnabled()).thenReturn(false);
|
||||
when(mEuiccManager.getEid()).thenReturn("");
|
||||
mEuiccEnabled.set(false);
|
||||
when(mEuiccManager.createForCardId(anyInt())).thenReturn(mEuiccManager);
|
||||
|
||||
mPersistableBundle = new PersistableBundle();
|
||||
@@ -183,7 +210,7 @@ public class SimStatusDialogControllerTest {
|
||||
public void initialize_shouldUpdatePhoneNumber() {
|
||||
mController.initialize();
|
||||
|
||||
verify(mController).updatePhoneNumber();
|
||||
assertTrue(mUpdatePhoneNumberCount.get() > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -426,10 +453,9 @@ public class SimStatusDialogControllerTest {
|
||||
when(mTelephonyManager.getLogicalToPhysicalSlotMapping()).thenReturn(slotMapping);
|
||||
|
||||
when(mEuiccManager.isEnabled()).thenReturn(true);
|
||||
when(mEuiccManager.getEid()).thenReturn(null);
|
||||
mEuiccEnabled.set(true);
|
||||
mEid.set(null);
|
||||
|
||||
doNothing().when(mController).requestForUpdateEid();
|
||||
mController.updateEid(mController.getEid(0));
|
||||
mController.initialize();
|
||||
|
||||
// Keep 'Not available' if neither the card nor the associated manager can provide EID.
|
||||
@@ -480,11 +506,10 @@ public class SimStatusDialogControllerTest {
|
||||
when(mTelephonyManager.getLogicalToPhysicalSlotMapping()).thenReturn(slotMapping);
|
||||
|
||||
when(mEuiccManager.isEnabled()).thenReturn(true);
|
||||
when(mEuiccManager.getEid()).thenReturn(TEST_EID_FROM_MANAGER);
|
||||
mEuiccEnabled.set(true);
|
||||
mEid.set(TEST_EID_FROM_CARD);
|
||||
when(mEuiccManager.createForCardId(0)).thenReturn(mEuiccManager);
|
||||
|
||||
doNothing().when(mController).requestForUpdateEid();
|
||||
mController.updateEid(mController.getEid(0));
|
||||
mController.initialize();
|
||||
|
||||
// Set EID retrieved from the card.
|
||||
@@ -538,13 +563,12 @@ public class SimStatusDialogControllerTest {
|
||||
when(mTelephonyManager.getLogicalToPhysicalSlotMapping()).thenReturn(slotMapping);
|
||||
|
||||
when(mEuiccManager.isEnabled()).thenReturn(true);
|
||||
when(mEuiccManager.getEid()).thenReturn(TEST_EID_FROM_MANAGER);
|
||||
mEuiccEnabled.set(true);
|
||||
mEid.set(TEST_EID_FROM_MANAGER);
|
||||
when(mEuiccManager.createForCardId(0)).thenThrow(
|
||||
new RuntimeException("Unexpected card ID was specified"));
|
||||
when(mEuiccManager.createForCardId(1)).thenReturn(mEuiccManager);
|
||||
|
||||
doNothing().when(mController).requestForUpdateEid();
|
||||
mController.updateEid(mController.getEid(0));
|
||||
mController.initialize();
|
||||
|
||||
// Set EID retrieved from the manager associated with the card which cannot provide EID.
|
||||
@@ -552,6 +576,7 @@ public class SimStatusDialogControllerTest {
|
||||
verify(mDialog, never()).removeSettingFromScreen(eq(EID_INFO_VALUE_ID));
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void initialize_updateEid_shouldRemoveEid() {
|
||||
when(mTelephonyManager.getActiveModemCount()).thenReturn(MAX_PHONE_COUNT_DUAL_SIM);
|
||||
@@ -597,9 +622,9 @@ public class SimStatusDialogControllerTest {
|
||||
when(mTelephonyManager.getLogicalToPhysicalSlotMapping()).thenReturn(slotMapping);
|
||||
|
||||
when(mEuiccManager.isEnabled()).thenReturn(true);
|
||||
when(mEuiccManager.getEid()).thenReturn(TEST_EID_FROM_MANAGER);
|
||||
mEuiccEnabled.set(true);
|
||||
mEid.set(TEST_EID_FROM_MANAGER);
|
||||
|
||||
doNothing().when(mController).requestForUpdateEid();
|
||||
mController.updateEid(mController.getEid(0));
|
||||
mController.initialize();
|
||||
|
||||
@@ -637,10 +662,9 @@ public class SimStatusDialogControllerTest {
|
||||
when(mTelephonyManager.getLogicalToPhysicalSlotMapping()).thenReturn(slotMapping);
|
||||
|
||||
when(mEuiccManager.isEnabled()).thenReturn(true);
|
||||
when(mEuiccManager.getEid()).thenReturn(null);
|
||||
mEuiccEnabled.set(true);
|
||||
mEid.set(null);
|
||||
|
||||
doNothing().when(mController).requestForUpdateEid();
|
||||
mController.updateEid(mController.getEid(0));
|
||||
mController.initialize();
|
||||
|
||||
// Keep 'Not available' if the default eUICC manager cannot provide EID in Single SIM mode.
|
||||
@@ -677,12 +701,11 @@ public class SimStatusDialogControllerTest {
|
||||
when(mTelephonyManager.getLogicalToPhysicalSlotMapping()).thenReturn(slotMapping);
|
||||
|
||||
when(mEuiccManager.isEnabled()).thenReturn(true);
|
||||
when(mEuiccManager.getEid()).thenReturn(TEST_EID_FROM_MANAGER);
|
||||
mEuiccEnabled.set(true);
|
||||
mEid.set(TEST_EID_FROM_MANAGER);
|
||||
when(mEuiccManager.createForCardId(anyInt())).thenThrow(
|
||||
new RuntimeException("EID shall be retrieved from the default eUICC manager"));
|
||||
|
||||
doNothing().when(mController).requestForUpdateEid();
|
||||
mController.updateEid(mController.getEid(0));
|
||||
mController.initialize();
|
||||
|
||||
// Set EID retrieved from the default eUICC manager in Single SIM mode.
|
||||
@@ -719,12 +742,11 @@ public class SimStatusDialogControllerTest {
|
||||
when(mTelephonyManager.getLogicalToPhysicalSlotMapping()).thenReturn(slotMapping);
|
||||
|
||||
when(mEuiccManager.isEnabled()).thenReturn(true);
|
||||
when(mEuiccManager.getEid()).thenReturn(TEST_EID_FROM_MANAGER);
|
||||
mEuiccEnabled.set(true);
|
||||
mEid.set(TEST_EID_FROM_MANAGER);
|
||||
when(mEuiccManager.createForCardId(anyInt())).thenThrow(
|
||||
new RuntimeException("EID shall be retrieved from the default eUICC manager"));
|
||||
|
||||
doNothing().when(mController).requestForUpdateEid();
|
||||
mController.updateEid(mController.getEid(0));
|
||||
mController.initialize();
|
||||
|
||||
// Set EID retrieved from the default eUICC manager in Single SIM mode.
|
||||
@@ -760,14 +782,12 @@ public class SimStatusDialogControllerTest {
|
||||
when(mTelephonyManager.getLogicalToPhysicalSlotMapping()).thenReturn(slotMapping);
|
||||
|
||||
when(mEuiccManager.isEnabled()).thenReturn(false);
|
||||
when(mEuiccManager.getEid()).thenReturn(null);
|
||||
mEuiccEnabled.set(false);
|
||||
mEid.set(null);
|
||||
|
||||
doNothing().when(mController).requestForUpdateEid();
|
||||
mController.updateEid(mController.getEid(0));
|
||||
mController.initialize();
|
||||
|
||||
// Remove EID if the default eUICC manager indicates that eSIM is not enabled.
|
||||
verify(mDialog, never()).setText(eq(EID_INFO_VALUE_ID), any());
|
||||
verify(mDialog).removeSettingFromScreen(eq(EID_INFO_LABEL_ID));
|
||||
verify(mDialog).removeSettingFromScreen(eq(EID_INFO_VALUE_ID));
|
||||
}
|
||||
|
@@ -70,7 +70,6 @@ public class CarrierWifiTogglePreferenceControllerTest {
|
||||
mController = new CarrierWifiTogglePreferenceController(mContext,
|
||||
CarrierWifiTogglePreferenceController.CARRIER_WIFI_TOGGLE_PREF_KEY);
|
||||
mController.init(mock(Lifecycle.class), SUB_ID);
|
||||
mController.mIsProviderModelEnabled = true;
|
||||
mController.mIsCarrierProvisionWifiEnabled = true;
|
||||
doReturn(true).when(mWifiPickerTrackerHelper).isCarrierNetworkActive();
|
||||
doReturn(SSID).when(mWifiPickerTrackerHelper).getCarrierNetworkSsid();
|
||||
@@ -92,13 +91,6 @@ public class CarrierWifiTogglePreferenceControllerTest {
|
||||
mController.mCarrierNetworkPreference = mNetworkPreference;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_providerModelDisable_returnUnavailable() {
|
||||
mController.mIsProviderModelEnabled = false;
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_carrierProvisionWifiEnabled_returnAvailable() {
|
||||
mController.mIsCarrierProvisionWifiEnabled = true;
|
||||
|
@@ -20,30 +20,24 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.spy;
|
||||
|
||||
import android.app.Instrumentation;
|
||||
import android.content.Context;
|
||||
import android.os.Looper;
|
||||
import android.provider.SearchIndexableResource;
|
||||
import android.util.FeatureFlagUtils;
|
||||
|
||||
import androidx.test.annotation.UiThreadTest;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import androidx.test.platform.app.InstrumentationRegistry;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class NetworkProviderCallsSmsFragmentTest {
|
||||
|
||||
private Context mContext;
|
||||
private NetworkProviderCallsSmsFragment mNetworkProviderCallsSmsFragment;
|
||||
private List<String> mPreferenceKeyList;
|
||||
|
||||
@Before
|
||||
@@ -55,14 +49,11 @@ public class NetworkProviderCallsSmsFragmentTest {
|
||||
if (Looper.myLooper() == null) {
|
||||
Looper.prepare();
|
||||
}
|
||||
|
||||
mNetworkProviderCallsSmsFragment = new NetworkProviderCallsSmsFragment();
|
||||
}
|
||||
|
||||
@Test
|
||||
@UiThreadTest
|
||||
public void isPageSearchEnabled_providerModelEnable_shouldIncludeFragmentXml() {
|
||||
FeatureFlagUtils.setEnabled(mContext, FeatureFlagUtils.SETTINGS_PROVIDER_MODEL, true);
|
||||
public void isPageSearchEnabled_shouldIncludeFragmentXml() {
|
||||
mPreferenceKeyList =
|
||||
NetworkProviderCallsSmsFragment.SEARCH_INDEX_DATA_PROVIDER
|
||||
.getNonIndexableKeys(mContext);
|
||||
@@ -71,17 +62,4 @@ public class NetworkProviderCallsSmsFragmentTest {
|
||||
assertThat(mPreferenceKeyList).doesNotContain(
|
||||
NetworkProviderCallsSmsFragment.KEY_PREFERENCE_SMS);
|
||||
}
|
||||
|
||||
@Test
|
||||
@UiThreadTest
|
||||
public void isPageSearchEnabled_providerModelDisable_shouldNotIncludeFragmentXml() {
|
||||
FeatureFlagUtils.setEnabled(mContext, FeatureFlagUtils.SETTINGS_PROVIDER_MODEL, false);
|
||||
mPreferenceKeyList =
|
||||
NetworkProviderCallsSmsFragment.SEARCH_INDEX_DATA_PROVIDER
|
||||
.getNonIndexableKeys(mContext);
|
||||
assertThat(mPreferenceKeyList).contains(NetworkProviderCallsSmsFragment
|
||||
.KEY_PREFERENCE_CALLS);
|
||||
assertThat(mPreferenceKeyList).contains(NetworkProviderCallsSmsFragment
|
||||
.KEY_PREFERENCE_SMS);
|
||||
}
|
||||
}
|
||||
|
@@ -302,6 +302,11 @@ public class ProviderModelSliceHelperTest {
|
||||
public Intent getIntent() {
|
||||
return new Intent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSliceHighlightMenuRes() {
|
||||
return NO_RES;
|
||||
}
|
||||
}
|
||||
|
||||
private class MockProviderModelSliceHelper extends ProviderModelSliceHelper {
|
||||
|
@@ -39,6 +39,7 @@ import android.graphics.drawable.Drawable;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.Network;
|
||||
import android.net.NetworkCapabilities;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Looper;
|
||||
import android.os.UserManager;
|
||||
import android.provider.Settings;
|
||||
@@ -102,6 +103,8 @@ public class SubscriptionsPreferenceControllerTest {
|
||||
private LifecycleOwner mLifecycleOwner;
|
||||
@Mock
|
||||
private WifiPickerTrackerHelper mWifiPickerTrackerHelper;
|
||||
@Mock
|
||||
private WifiManager mWifiManager;
|
||||
|
||||
private LifecycleRegistry mLifecycleRegistry;
|
||||
private int mOnChildUpdatedCount;
|
||||
@@ -132,6 +135,7 @@ public class SubscriptionsPreferenceControllerTest {
|
||||
when(mConnectivityManager.getNetworkCapabilities(mActiveNetwork))
|
||||
.thenReturn(mNetworkCapabilities);
|
||||
when(mUserManager.isAdminUser()).thenReturn(true);
|
||||
when(mContext.getSystemService(WifiManager.class)).thenReturn(mWifiManager);
|
||||
when(mLifecycleOwner.getLifecycle()).thenReturn(mLifecycleRegistry);
|
||||
|
||||
mPreferenceManager = new PreferenceManager(mContext);
|
||||
@@ -146,7 +150,6 @@ public class SubscriptionsPreferenceControllerTest {
|
||||
mUpdateListener = () -> mOnChildUpdatedCount++;
|
||||
|
||||
sInjector = spy(new SubsPrefCtrlInjector());
|
||||
initializeMethod(true, 1, 1, 1, false, false);
|
||||
mController = new FakeSubscriptionsPreferenceController(mContext, mLifecycle,
|
||||
mUpdateListener, KEY, 5);
|
||||
Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 0);
|
||||
@@ -157,41 +160,26 @@ public class SubscriptionsPreferenceControllerTest {
|
||||
SubscriptionUtil.setActiveSubscriptionsForTesting(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_oneSubscription_availableFalse() {
|
||||
setupMockSubscriptions(1);
|
||||
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_oneSubAndProviderOn_availableTrue() {
|
||||
doReturn(true).when(sInjector).isProviderModelEnabled(mContext);
|
||||
setupMockSubscriptions(1);
|
||||
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_twoSubscriptions_availableTrue() {
|
||||
setupMockSubscriptions(2);
|
||||
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_fiveSubscriptions_availableTrue() {
|
||||
doReturn(true).when(sInjector).canSubscriptionBeDisplayed(mContext, 0);
|
||||
setupMockSubscriptions(5);
|
||||
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_airplaneModeOn_availableFalse() {
|
||||
public void isAvailable_airplaneModeOnWifiOff_availableFalse() {
|
||||
setupMockSubscriptions(2);
|
||||
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
when(mWifiManager.isWifiEnabled()).thenReturn(false);
|
||||
|
||||
Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 1);
|
||||
|
||||
@@ -199,204 +187,47 @@ public class SubscriptionsPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@UiThreadTest
|
||||
public void onAirplaneModeChanged_airplaneModeTurnedOn_eventFired() {
|
||||
public void isAvailable_airplaneModeOnWifiOnWithNoCarrierNetwork_availableFalse() {
|
||||
setupMockSubscriptions(2);
|
||||
|
||||
mController.onResume();
|
||||
mController.displayPreference(mPreferenceScreen);
|
||||
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
when(mWifiManager.isWifiEnabled()).thenReturn(true);
|
||||
doReturn(false).when(mWifiPickerTrackerHelper).isCarrierNetworkActive();
|
||||
|
||||
final int updateCountBeforeModeChange = mOnChildUpdatedCount;
|
||||
Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 1);
|
||||
|
||||
mController.onAirplaneModeChanged(true);
|
||||
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
assertThat(mOnChildUpdatedCount).isEqualTo(updateCountBeforeModeChange + 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@UiThreadTest
|
||||
public void onAirplaneModeChanged_airplaneModeTurnedOff_eventFired() {
|
||||
public void isAvailable_airplaneModeOnWifiOffWithCarrierNetwork_availableTrue() {
|
||||
setupMockSubscriptions(1);
|
||||
|
||||
when(mWifiManager.isWifiEnabled()).thenReturn(false);
|
||||
doReturn(true).when(mWifiPickerTrackerHelper).isCarrierNetworkActive();
|
||||
|
||||
Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 1);
|
||||
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_airplaneModeOff_availableFalse() {
|
||||
setupMockSubscriptions(2);
|
||||
|
||||
mController.onResume();
|
||||
mController.displayPreference(mPreferenceScreen);
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
when(mWifiManager.isWifiEnabled()).thenReturn(true);
|
||||
doReturn(true).when(mWifiPickerTrackerHelper).isCarrierNetworkActive();
|
||||
|
||||
final int updateCountBeforeModeChange = mOnChildUpdatedCount;
|
||||
Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 0);
|
||||
|
||||
mController.onAirplaneModeChanged(true);
|
||||
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
assertThat(mOnChildUpdatedCount).isEqualTo(updateCountBeforeModeChange + 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@UiThreadTest
|
||||
public void onSubscriptionsChanged_countBecameTwo_eventFired() {
|
||||
final List<SubscriptionInfo> subs = setupMockSubscriptions(2);
|
||||
SubscriptionUtil.setActiveSubscriptionsForTesting(subs.subList(0, 1));
|
||||
|
||||
mController.onResume();
|
||||
mController.displayPreference(mPreferenceScreen);
|
||||
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
|
||||
final int updateCountBeforeSubscriptionChange = mOnChildUpdatedCount;
|
||||
SubscriptionUtil.setActiveSubscriptionsForTesting(subs);
|
||||
|
||||
mController.onSubscriptionsChanged();
|
||||
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
assertThat(mOnChildUpdatedCount).isEqualTo(updateCountBeforeSubscriptionChange + 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@UiThreadTest
|
||||
public void onSubscriptionsChanged_countBecameOne_eventFiredAndPrefsRemoved() {
|
||||
final List<SubscriptionInfo> subs = setupMockSubscriptions(2);
|
||||
|
||||
mController.onResume();
|
||||
mController.displayPreference(mPreferenceScreen);
|
||||
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
assertThat(mPreferenceCategory.getPreferenceCount()).isEqualTo(2);
|
||||
|
||||
final int updateCountBeforeSubscriptionChange = mOnChildUpdatedCount;
|
||||
SubscriptionUtil.setActiveSubscriptionsForTesting(subs.subList(0, 1));
|
||||
|
||||
mController.onSubscriptionsChanged();
|
||||
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
assertThat(mOnChildUpdatedCount).isEqualTo(updateCountBeforeSubscriptionChange + 1);
|
||||
assertThat(mPreferenceCategory.getPreferenceCount()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@UiThreadTest
|
||||
public void onSubscriptionsChanged_subscriptionReplaced_preferencesChanged() {
|
||||
final List<SubscriptionInfo> subs = setupMockSubscriptions(3);
|
||||
doReturn(subs).when(mSubscriptionManager).getAvailableSubscriptionInfoList();
|
||||
|
||||
// Start out with only sub1 and sub2.
|
||||
SubscriptionUtil.setActiveSubscriptionsForTesting(subs.subList(0, 2));
|
||||
mController.onResume();
|
||||
mController.displayPreference(mPreferenceScreen);
|
||||
|
||||
assertThat(mPreferenceCategory.getPreferenceCount()).isEqualTo(2);
|
||||
assertThat(mPreferenceCategory.getPreference(0).getTitle()).isEqualTo("sub2");
|
||||
assertThat(mPreferenceCategory.getPreference(1).getTitle()).isEqualTo("sub1");
|
||||
|
||||
// Now replace sub2 with sub3, and make sure the old preference was removed and the new
|
||||
// preference was added.
|
||||
final int updateCountBeforeSubscriptionChange = mOnChildUpdatedCount;
|
||||
SubscriptionUtil.setActiveSubscriptionsForTesting(Arrays.asList(subs.get(0), subs.get(2)));
|
||||
mController.onSubscriptionsChanged();
|
||||
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
assertThat(mOnChildUpdatedCount).isEqualTo(updateCountBeforeSubscriptionChange + 1);
|
||||
assertThat(mPreferenceCategory.getPreferenceCount()).isEqualTo(2);
|
||||
assertThat(mPreferenceCategory.getPreference(0).getTitle()).isEqualTo("sub3");
|
||||
assertThat(mPreferenceCategory.getPreference(1).getTitle()).isEqualTo("sub1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSummary_twoSubsOneDefaultForEverythingDataActive() {
|
||||
setupMockSubscriptions(2);
|
||||
|
||||
doReturn(11).when(sInjector).getDefaultSmsSubscriptionId();
|
||||
doReturn(11).when(sInjector).getDefaultVoiceSubscriptionId();
|
||||
when(mTelephonyManager.isDataEnabled()).thenReturn(true);
|
||||
doReturn(true).when(sInjector).isActiveCellularNetwork(mContext);
|
||||
|
||||
assertThat(mController.getSummary(11, true)).isEqualTo(
|
||||
ResourcesUtils.getResourcesString(mContext, "default_for_calls_and_sms")
|
||||
+ System.lineSeparator()
|
||||
+ ResourcesUtils.getResourcesString(mContext, "mobile_data_active"));
|
||||
|
||||
assertThat(mController.getSummary(22, false)).isEqualTo(
|
||||
ResourcesUtils.getResourcesString(mContext, "subscription_available"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSummary_twoSubsOneDefaultForEverythingDataNotActive() {
|
||||
setupMockSubscriptions(2, 1, true);
|
||||
|
||||
doReturn(1).when(sInjector).getDefaultSmsSubscriptionId();
|
||||
doReturn(1).when(sInjector).getDefaultVoiceSubscriptionId();
|
||||
|
||||
assertThat(mController.getSummary(1, true)).isEqualTo(
|
||||
ResourcesUtils.getResourcesString(mContext, "default_for_calls_and_sms")
|
||||
+ System.lineSeparator()
|
||||
+ ResourcesUtils.getResourcesString(mContext, "default_for_mobile_data"));
|
||||
|
||||
assertThat(mController.getSummary(2, false)).isEqualTo(
|
||||
ResourcesUtils.getResourcesString(mContext, "subscription_available"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSummary_twoSubsOneDefaultForEverythingDataDisabled() {
|
||||
setupMockSubscriptions(2);
|
||||
|
||||
doReturn(1).when(sInjector).getDefaultSmsSubscriptionId();
|
||||
doReturn(1).when(sInjector).getDefaultVoiceSubscriptionId();
|
||||
|
||||
assertThat(mController.getSummary(1, true)).isEqualTo(
|
||||
ResourcesUtils.getResourcesString(mContext, "default_for_calls_and_sms")
|
||||
+ System.lineSeparator()
|
||||
+ ResourcesUtils.getResourcesString(mContext, "mobile_data_off"));
|
||||
|
||||
assertThat(mController.getSummary(2, false)).isEqualTo(
|
||||
ResourcesUtils.getResourcesString(mContext, "subscription_available"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSummary_twoSubsOneForCallsAndDataOneForSms() {
|
||||
setupMockSubscriptions(2, 1, true);
|
||||
|
||||
doReturn(2).when(sInjector).getDefaultSmsSubscriptionId();
|
||||
doReturn(1).when(sInjector).getDefaultVoiceSubscriptionId();
|
||||
|
||||
assertThat(mController.getSummary(1, true)).isEqualTo(
|
||||
ResourcesUtils.getResourcesString(mContext, "default_for_calls")
|
||||
+ System.lineSeparator()
|
||||
+ ResourcesUtils.getResourcesString(mContext, "default_for_mobile_data"));
|
||||
|
||||
assertThat(mController.getSummary(2, false)).isEqualTo(
|
||||
ResourcesUtils.getResourcesString(mContext, "default_for_sms"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@UiThreadTest
|
||||
public void setIcon_greatSignal_correctLevels() {
|
||||
final List<SubscriptionInfo> subs = setupMockSubscriptions(2, 1, true);
|
||||
setMockSubSignalStrength(subs, 0, SIGNAL_STRENGTH_GREAT);
|
||||
setMockSubSignalStrength(subs, 1, SIGNAL_STRENGTH_GREAT);
|
||||
final Preference pref = new Preference(mContext);
|
||||
final Drawable greatDrawWithoutCutOff = mock(Drawable.class);
|
||||
doReturn(greatDrawWithoutCutOff).when(sInjector)
|
||||
.getIcon(any(), anyInt(), anyInt(), anyBoolean());
|
||||
|
||||
mController.setIcon(pref, 1, true /* isDefaultForData */);
|
||||
assertThat(pref.getIcon()).isEqualTo(greatDrawWithoutCutOff);
|
||||
|
||||
final Drawable greatDrawWithCutOff = mock(Drawable.class);
|
||||
doReturn(greatDrawWithCutOff).when(sInjector)
|
||||
.getIcon(any(), anyInt(), anyInt(), anyBoolean());
|
||||
mController.setIcon(pref, 2, false /* isDefaultForData */);
|
||||
assertThat(pref.getIcon()).isEqualTo(greatDrawWithCutOff);
|
||||
}
|
||||
|
||||
@Test
|
||||
@UiThreadTest
|
||||
public void displayPreference_providerAndHasSim_showPreference() {
|
||||
final List<SubscriptionInfo> sub = setupMockSubscriptions(1);
|
||||
doReturn(true).when(sInjector).isProviderModelEnabled(mContext);
|
||||
doReturn(sub.get(0)).when(mSubscriptionManager).getDefaultDataSubscriptionInfo();
|
||||
doReturn(sub).when(mSubscriptionManager).getAvailableSubscriptionInfoList();
|
||||
|
||||
@@ -411,7 +242,6 @@ public class SubscriptionsPreferenceControllerTest {
|
||||
@UiThreadTest
|
||||
public void displayPreference_providerAndHasMultiSim_showDataSubPreference() {
|
||||
final List<SubscriptionInfo> sub = setupMockSubscriptions(2);
|
||||
doReturn(true).when(sInjector).isProviderModelEnabled(mContext);
|
||||
doReturn(sub.get(0)).when(mSubscriptionManager).getDefaultDataSubscriptionInfo();
|
||||
doReturn(sub).when(mSubscriptionManager).getAvailableSubscriptionInfoList();
|
||||
|
||||
@@ -429,7 +259,6 @@ public class SubscriptionsPreferenceControllerTest {
|
||||
Html.fromHtml("Connected / 5G", Html.FROM_HTML_MODE_LEGACY);
|
||||
final String networkType = "5G";
|
||||
final List<SubscriptionInfo> sub = setupMockSubscriptions(2);
|
||||
doReturn(true).when(sInjector).isProviderModelEnabled(mContext);
|
||||
doReturn(sub.get(0)).when(mSubscriptionManager).getDefaultDataSubscriptionInfo();
|
||||
setupGetIconConditions(sub.get(0).getSubscriptionId(), true, true,
|
||||
true, ServiceState.STATE_IN_SERVICE);
|
||||
@@ -450,7 +279,6 @@ public class SubscriptionsPreferenceControllerTest {
|
||||
Html.fromHtml("Connected / W+", Html.FROM_HTML_MODE_LEGACY);
|
||||
final String networkType = "W+";
|
||||
final List<SubscriptionInfo> sub = setupMockSubscriptions(2);
|
||||
doReturn(true).when(sInjector).isProviderModelEnabled(mContext);
|
||||
doReturn(sub.get(0)).when(mSubscriptionManager).getDefaultDataSubscriptionInfo();
|
||||
setupGetIconConditions(sub.get(0).getSubscriptionId(), false, true,
|
||||
true, ServiceState.STATE_IN_SERVICE);
|
||||
@@ -475,7 +303,6 @@ public class SubscriptionsPreferenceControllerTest {
|
||||
Html.fromHtml(dataOffSummary, Html.FROM_HTML_MODE_LEGACY);
|
||||
final String networkType = "5G";
|
||||
final List<SubscriptionInfo> sub = setupMockSubscriptions(2);
|
||||
doReturn(true).when(sInjector).isProviderModelEnabled(mContext);
|
||||
doReturn(sub.get(0)).when(mSubscriptionManager).getDefaultDataSubscriptionInfo();
|
||||
setupGetIconConditions(sub.get(0).getSubscriptionId(), false, false,
|
||||
true, ServiceState.STATE_IN_SERVICE);
|
||||
@@ -495,7 +322,6 @@ public class SubscriptionsPreferenceControllerTest {
|
||||
final CharSequence expectedSummary = Html.fromHtml("5G", Html.FROM_HTML_MODE_LEGACY);
|
||||
final String networkType = "5G";
|
||||
final List<SubscriptionInfo> sub = setupMockSubscriptions(2);
|
||||
doReturn(true).when(sInjector).isProviderModelEnabled(mContext);
|
||||
doReturn(sub.get(0)).when(mSubscriptionManager).getDefaultDataSubscriptionInfo();
|
||||
setupGetIconConditions(sub.get(0).getSubscriptionId(), false, true,
|
||||
true, ServiceState.STATE_IN_SERVICE);
|
||||
@@ -512,7 +338,6 @@ public class SubscriptionsPreferenceControllerTest {
|
||||
@Test
|
||||
@UiThreadTest
|
||||
public void displayPreference_providerAndNoSim_noPreference() {
|
||||
doReturn(true).when(sInjector).isProviderModelEnabled(mContext);
|
||||
doReturn(null).when(mSubscriptionManager).getDefaultDataSubscriptionInfo();
|
||||
|
||||
mController.onResume();
|
||||
@@ -531,7 +356,6 @@ public class SubscriptionsPreferenceControllerTest {
|
||||
final TelephonyDisplayInfo telephonyDisplayInfo =
|
||||
new TelephonyDisplayInfo(TelephonyManager.NETWORK_TYPE_UNKNOWN,
|
||||
TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NONE);
|
||||
doReturn(true).when(sInjector).isProviderModelEnabled(mContext);
|
||||
doReturn(sub.get(0)).when(mSubscriptionManager).getDefaultDataSubscriptionInfo();
|
||||
setupGetIconConditions(sub.get(0).getSubscriptionId(), true, true,
|
||||
true, ServiceState.STATE_IN_SERVICE);
|
||||
@@ -557,7 +381,6 @@ public class SubscriptionsPreferenceControllerTest {
|
||||
final TelephonyDisplayInfo telephonyDisplayInfo =
|
||||
new TelephonyDisplayInfo(TelephonyManager.NETWORK_TYPE_UNKNOWN,
|
||||
TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NONE);
|
||||
doReturn(true).when(sInjector).isProviderModelEnabled(mContext);
|
||||
doReturn(sub.get(0)).when(mSubscriptionManager).getDefaultDataSubscriptionInfo();
|
||||
setupGetIconConditions(sub.get(0).getSubscriptionId(), false, true,
|
||||
true, ServiceState.STATE_IN_SERVICE);
|
||||
@@ -584,7 +407,6 @@ public class SubscriptionsPreferenceControllerTest {
|
||||
final TelephonyDisplayInfo telephonyDisplayInfo =
|
||||
new TelephonyDisplayInfo(TelephonyManager.NETWORK_TYPE_UNKNOWN,
|
||||
TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NONE);
|
||||
doReturn(true).when(sInjector).isProviderModelEnabled(mContext);
|
||||
doReturn(sub.get(0)).when(mSubscriptionManager).getDefaultDataSubscriptionInfo();
|
||||
setupGetIconConditions(sub.get(0).getSubscriptionId(), false, true,
|
||||
false, ServiceState.STATE_OUT_OF_SERVICE);
|
||||
@@ -603,7 +425,6 @@ public class SubscriptionsPreferenceControllerTest {
|
||||
@UiThreadTest
|
||||
public void onAirplaneModeChanged_providerAndHasSim_noPreference() {
|
||||
setupMockSubscriptions(1);
|
||||
doReturn(true).when(sInjector).isProviderModelEnabled(mContext);
|
||||
mController.onResume();
|
||||
mController.displayPreference(mPreferenceScreen);
|
||||
Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 1);
|
||||
@@ -618,7 +439,6 @@ public class SubscriptionsPreferenceControllerTest {
|
||||
@UiThreadTest
|
||||
public void dataSubscriptionChanged_providerAndHasMultiSim_showSubId1Preference() {
|
||||
final List<SubscriptionInfo> sub = setupMockSubscriptions(2);
|
||||
doReturn(true).when(sInjector).isProviderModelEnabled(mContext);
|
||||
doReturn(sub.get(0)).when(mSubscriptionManager).getDefaultDataSubscriptionInfo();
|
||||
doReturn(sub).when(mSubscriptionManager).getAvailableSubscriptionInfoList();
|
||||
Intent intent = new Intent(TelephonyManager.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED);
|
||||
@@ -637,7 +457,6 @@ public class SubscriptionsPreferenceControllerTest {
|
||||
public void dataSubscriptionChanged_providerAndHasMultiSim_showSubId2Preference() {
|
||||
final List<SubscriptionInfo> sub = setupMockSubscriptions(2);
|
||||
final int subId = sub.get(0).getSubscriptionId();
|
||||
doReturn(true).when(sInjector).isProviderModelEnabled(mContext);
|
||||
doReturn(sub.get(0)).when(mSubscriptionManager).getDefaultDataSubscriptionInfo();
|
||||
doReturn(sub).when(mSubscriptionManager).getAvailableSubscriptionInfoList();
|
||||
Intent intent = new Intent(TelephonyManager.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED);
|
||||
@@ -662,7 +481,6 @@ public class SubscriptionsPreferenceControllerTest {
|
||||
@UiThreadTest
|
||||
public void getIcon_cellularIsActive_iconColorIsAccentDefaultColor() {
|
||||
final List<SubscriptionInfo> sub = setupMockSubscriptions(1);
|
||||
doReturn(true).when(sInjector).isProviderModelEnabled(mContext);
|
||||
doReturn(sub.get(0)).when(mSubscriptionManager).getDefaultDataSubscriptionInfo();
|
||||
Drawable icon = mock(Drawable.class);
|
||||
when(mTelephonyManager.isDataEnabled()).thenReturn(true);
|
||||
@@ -681,7 +499,6 @@ public class SubscriptionsPreferenceControllerTest {
|
||||
public void getIcon_dataStateConnectedAndMobileDataOn_iconIsSignalIcon() {
|
||||
final List<SubscriptionInfo> subs = setupMockSubscriptions(1);
|
||||
final int subId = subs.get(0).getSubscriptionId();
|
||||
doReturn(true).when(sInjector).isProviderModelEnabled(mContext);
|
||||
doReturn(subs.get(0)).when(mSubscriptionManager).getDefaultDataSubscriptionInfo();
|
||||
Drawable icon = mock(Drawable.class);
|
||||
when(mTelephonyManager.isDataEnabled()).thenReturn(true);
|
||||
@@ -700,7 +517,6 @@ public class SubscriptionsPreferenceControllerTest {
|
||||
public void getIcon_voiceInServiceAndMobileDataOff_iconIsSignalIcon() {
|
||||
final List<SubscriptionInfo> subs = setupMockSubscriptions(1);
|
||||
final int subId = subs.get(0).getSubscriptionId();
|
||||
doReturn(true).when(sInjector).isProviderModelEnabled(mContext);
|
||||
doReturn(subs.get(0)).when(mSubscriptionManager).getDefaultDataSubscriptionInfo();
|
||||
Drawable icon = mock(Drawable.class);
|
||||
when(mTelephonyManager.isDataEnabled()).thenReturn(false);
|
||||
@@ -807,40 +623,6 @@ public class SubscriptionsPreferenceControllerTest {
|
||||
return infos;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to set the signal strength returned for a mock subscription
|
||||
* @param subs The list of subscriptions
|
||||
* @param index The index in of the subscription in |subs| to change
|
||||
* @param level The signal strength level to return for the subscription. Pass -1 to force
|
||||
* return of a null SignalStrength object for the subscription.
|
||||
*/
|
||||
private void setMockSubSignalStrength(List<SubscriptionInfo> subs, int index, int level) {
|
||||
final int subId = subs.get(index).getSubscriptionId();
|
||||
doReturn(mTelephonyManagerForSub).when(mTelephonyManager).createForSubscriptionId(subId);
|
||||
if (level == -1) {
|
||||
when(mTelephonyManagerForSub.getSignalStrength()).thenReturn(null);
|
||||
} else {
|
||||
final SignalStrength signalStrength = mock(SignalStrength.class);
|
||||
doReturn(signalStrength).when(mTelephonyManagerForSub).getSignalStrength();
|
||||
when(signalStrength.getLevel()).thenReturn(level);
|
||||
}
|
||||
}
|
||||
|
||||
private void initializeMethod(boolean isSubscriptionCanBeDisplayed,
|
||||
int defaultSmsSubscriptionId, int defaultVoiceSubscriptionId,
|
||||
int defaultDataSubscriptionId, boolean isActiveCellularNetwork,
|
||||
boolean isProviderModelEnabled) {
|
||||
doReturn(isSubscriptionCanBeDisplayed)
|
||||
.when(sInjector).canSubscriptionBeDisplayed(mContext, eq(anyInt()));
|
||||
doReturn(defaultSmsSubscriptionId).when(sInjector).getDefaultSmsSubscriptionId();
|
||||
doReturn(defaultVoiceSubscriptionId).when(sInjector).getDefaultVoiceSubscriptionId();
|
||||
doReturn(defaultDataSubscriptionId).when(sInjector).getDefaultDataSubscriptionId();
|
||||
doReturn(isActiveCellularNetwork).when(sInjector).isActiveCellularNetwork(mContext);
|
||||
doReturn(isProviderModelEnabled).when(sInjector).isProviderModelEnabled(mContext);
|
||||
doReturn(mock(Drawable.class))
|
||||
.when(sInjector).getIcon(any(), anyInt(), anyInt(), eq(false));
|
||||
}
|
||||
|
||||
private static class FakeSubscriptionsPreferenceController
|
||||
extends SubscriptionsPreferenceController {
|
||||
|
||||
|
@@ -89,13 +89,6 @@ public class DefaultSubscriptionControllerTest {
|
||||
SubscriptionUtil.setActiveSubscriptionsForTesting(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_onlyOneSubscription_notAvailable() {
|
||||
SubscriptionUtil.setActiveSubscriptionsForTesting(Arrays.asList(
|
||||
createMockSub(1, "sub1")));
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_twoSubscriptions_isAvailable() {
|
||||
SubscriptionUtil.setActiveSubscriptionsForTesting(Arrays.asList(
|
||||
@@ -248,7 +241,7 @@ public class DefaultSubscriptionControllerTest {
|
||||
mController.setDefaultSubscription(sub1.getSubscriptionId());
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
|
||||
// Now make two subs be active - the pref should become available, and the
|
||||
// onPreferenceChange callback should be properly wired up.
|
||||
@@ -289,12 +282,14 @@ public class DefaultSubscriptionControllerTest {
|
||||
mController.displayPreference(mScreen);
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
assertThat(mListPreference.isVisible()).isTrue();
|
||||
assertThat(mListPreference.isEnabled()).isTrue();
|
||||
|
||||
SubscriptionUtil.setActiveSubscriptionsForTesting(Arrays.asList(sub1));
|
||||
mController.onSubscriptionsChanged();
|
||||
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
assertThat(mListPreference.isVisible()).isFalse();
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
assertThat(mListPreference.isVisible()).isTrue();
|
||||
assertThat(mListPreference.isEnabled()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -306,8 +301,9 @@ public class DefaultSubscriptionControllerTest {
|
||||
mController.setDefaultSubscription(sub1.getSubscriptionId());
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
assertThat(mListPreference.isVisible()).isFalse();
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
assertThat(mListPreference.isVisible()).isTrue();
|
||||
assertThat(mListPreference.isEnabled()).isFalse();
|
||||
|
||||
SubscriptionUtil.setActiveSubscriptionsForTesting(Arrays.asList(sub1, sub2));
|
||||
when(mSubMgr.getAvailableSubscriptionInfoList()).thenReturn(Arrays.asList(sub1, sub2));
|
||||
@@ -315,6 +311,7 @@ public class DefaultSubscriptionControllerTest {
|
||||
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
assertThat(mListPreference.isVisible()).isTrue();
|
||||
assertThat(mListPreference.isEnabled()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -153,7 +153,6 @@ public class NetworkProviderBackupCallingGroupTest {
|
||||
@Test
|
||||
public void
|
||||
shouldShowBackupCallingForSub_crossSimDisabled_returnFalse() {
|
||||
FeatureFlagUtils.setEnabled(mContext, FeatureFlagUtils.SETTINGS_PROVIDER_MODEL, true);
|
||||
doReturn(false).when(mNetworkProviderBackupCallingGroup).isCrossSimEnabledByPlatform(
|
||||
mContext, SUB_ID_1);
|
||||
|
||||
@@ -163,7 +162,6 @@ public class NetworkProviderBackupCallingGroupTest {
|
||||
|
||||
@Test
|
||||
public void shouldBackupCallingForSub_crossSimEnabled_returnTrue() {
|
||||
FeatureFlagUtils.setEnabled(mContext, FeatureFlagUtils.SETTINGS_PROVIDER_MODEL, true);
|
||||
doReturn(true).when(mNetworkProviderBackupCallingGroup).isCrossSimEnabledByPlatform(
|
||||
mContext, SUB_ID_1);
|
||||
|
||||
|
@@ -147,7 +147,6 @@ public class NetworkProviderWifiCallingGroupTest {
|
||||
@Test
|
||||
public void
|
||||
shouldShowWifiCallingForSub_wifiCallingDisabledWithWifiCallingNotReady_returnFalse() {
|
||||
FeatureFlagUtils.setEnabled(mContext, FeatureFlagUtils.SETTINGS_PROVIDER_MODEL, true);
|
||||
setWifiCallingEnabled(false);
|
||||
doReturn(mMockQueryWfcState).when(mNetworkProviderWifiCallingGroup).queryImsState(SUB_ID);
|
||||
|
||||
@@ -157,7 +156,6 @@ public class NetworkProviderWifiCallingGroupTest {
|
||||
|
||||
@Test
|
||||
public void shouldShowWifiCallingForSub_wifiCallingEnabledWithWifiCallingIsReady_returnTrue() {
|
||||
FeatureFlagUtils.setEnabled(mContext, FeatureFlagUtils.SETTINGS_PROVIDER_MODEL, true);
|
||||
setWifiCallingEnabled(true);
|
||||
doReturn(mMockQueryWfcState).when(mNetworkProviderWifiCallingGroup).queryImsState(SUB_ID);
|
||||
|
||||
@@ -168,7 +166,6 @@ public class NetworkProviderWifiCallingGroupTest {
|
||||
@Test
|
||||
public void
|
||||
shouldShowWifiCallingForSub_wifiCallingDisabledWithNoActivityHandleIntent_returnFalse() {
|
||||
FeatureFlagUtils.setEnabled(mContext, FeatureFlagUtils.SETTINGS_PROVIDER_MODEL, true);
|
||||
buildPhoneAccountConfigureIntent(false);
|
||||
doReturn(mMockQueryWfcState).when(mNetworkProviderWifiCallingGroup).queryImsState(SUB_ID);
|
||||
doReturn(mPhoneAccountHandle).when(mNetworkProviderWifiCallingGroup)
|
||||
@@ -181,7 +178,6 @@ public class NetworkProviderWifiCallingGroupTest {
|
||||
@Test
|
||||
public void
|
||||
shouldShowWifiCallingForSub_wifiCallingEnabledWithActivityHandleIntent_returnTrue() {
|
||||
FeatureFlagUtils.setEnabled(mContext, FeatureFlagUtils.SETTINGS_PROVIDER_MODEL, true);
|
||||
buildPhoneAccountConfigureIntent(true);
|
||||
doReturn(mMockQueryWfcState).when(mNetworkProviderWifiCallingGroup).queryImsState(SUB_ID);
|
||||
doReturn(mPhoneAccountHandle).when(mNetworkProviderWifiCallingGroup)
|
||||
|
@@ -166,6 +166,19 @@ public class NetworkSelectSettingsTest {
|
||||
assertThat(mNetworkSelectSettings.doAggregation(testList)).isEqualTo(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doAggregation_hasDuplicateItemsDiffMccMncCase3_removeSamePlmnRatItem() {
|
||||
List<CellInfo> testList = Arrays.asList(
|
||||
createLteCellInfo(false, 123, "123", "232", "CarrierA"),
|
||||
createLteCellInfo(false, 124, "123", "233", "CarrierA"),
|
||||
createLteCellInfo(true, 125, "123", "234", "CarrierA"),
|
||||
createGsmCellInfo(false, 126, "456", "232", "CarrierA"));
|
||||
List<CellInfo> expected = Arrays.asList(
|
||||
createLteCellInfo(true, 125, "123", "234", "CarrierA"),
|
||||
createGsmCellInfo(false, 126, "456", "232", "CarrierA"));
|
||||
assertThat(mNetworkSelectSettings.doAggregation(testList)).isEqualTo(expected);
|
||||
}
|
||||
|
||||
private CellInfoLte createLteCellInfo(boolean registered, int cellId, String mcc, String mnc,
|
||||
String plmnName) {
|
||||
CellIdentityLte cil = new CellIdentityLte(
|
||||
|
@@ -80,7 +80,8 @@ public class NrAdvancedCallingPreferenceControllerTest {
|
||||
mTelephonyManager).setVoNrEnabled(anyBoolean());
|
||||
mCarrierConfig = new PersistableBundle();
|
||||
doReturn(mCarrierConfig).when(mCarrierConfigManager).getConfigForSubId(SUB_ID);
|
||||
mCarrierConfig.putBoolean(CarrierConfigManager.KEY_VONR_SETTING_VISIBILITY_BOOL, false);
|
||||
mCarrierConfig.putBoolean(CarrierConfigManager.KEY_VONR_ENABLED_BOOL, false);
|
||||
mCarrierConfig.putBoolean(CarrierConfigManager.KEY_VONR_SETTING_VISIBILITY_BOOL, true);
|
||||
mCarrierConfig.putIntArray(CarrierConfigManager.KEY_CARRIER_NR_AVAILABILITIES_INT_ARRAY,
|
||||
new int[]{1, 2});
|
||||
|
||||
@@ -92,7 +93,8 @@ public class NrAdvancedCallingPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_vonrDisabled_returnUnavailable() {
|
||||
public void getAvailabilityStatus_vonrEnabledAndVisibleDisable_returnUnavailable() {
|
||||
mCarrierConfig.putBoolean(CarrierConfigManager.KEY_VONR_ENABLED_BOOL, true);
|
||||
mCarrierConfig.putBoolean(CarrierConfigManager.KEY_VONR_SETTING_VISIBILITY_BOOL, false);
|
||||
|
||||
mController.init(SUB_ID);
|
||||
@@ -102,7 +104,30 @@ public class NrAdvancedCallingPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_vonrEnabled_returnAvailable() {
|
||||
public void getAvailabilityStatus_vonrDisabledAndVisibleDisable_returnUnavailable() {
|
||||
mCarrierConfig.putBoolean(CarrierConfigManager.KEY_VONR_ENABLED_BOOL, false);
|
||||
mCarrierConfig.putBoolean(CarrierConfigManager.KEY_VONR_SETTING_VISIBILITY_BOOL, false);
|
||||
|
||||
mController.init(SUB_ID);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||
BasePreferenceController.CONDITIONALLY_UNAVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_vonrDisabledAndVisibleEnable_returnUnavailable() {
|
||||
mCarrierConfig.putBoolean(CarrierConfigManager.KEY_VONR_ENABLED_BOOL, false);
|
||||
mCarrierConfig.putBoolean(CarrierConfigManager.KEY_VONR_SETTING_VISIBILITY_BOOL, true);
|
||||
|
||||
mController.init(SUB_ID);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||
BasePreferenceController.CONDITIONALLY_UNAVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_vonrEnabledAndVisibleEnable_returnAvailable() {
|
||||
mCarrierConfig.putBoolean(CarrierConfigManager.KEY_VONR_ENABLED_BOOL, true);
|
||||
mCarrierConfig.putBoolean(CarrierConfigManager.KEY_VONR_SETTING_VISIBILITY_BOOL, true);
|
||||
|
||||
mController.init(SUB_ID);
|
||||
|
@@ -35,6 +35,7 @@ class SliceTestUtils {
|
||||
public static final int FAKE_ICON = 1234;
|
||||
public static final String FAKE_FRAGMENT_NAME = FakeIndexProvider.class.getName();
|
||||
public static final String FAKE_CONTROLLER_NAME = FakeToggleController.class.getName();
|
||||
public static final int FAKE_HIGHLIGHT_MENU_RES = FakeToggleController.HIGHLIGHT_MENU_RES;
|
||||
|
||||
|
||||
public static void insertSliceToDb(Context context, String key) {
|
||||
@@ -75,6 +76,8 @@ class SliceTestUtils {
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.UNAVAILABLE_SLICE_SUBTITLE,
|
||||
customizedUnavailableSliceSubtitle);
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.PUBLIC_SLICE, isPublicSlice);
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.HIGHLIGHT_MENU_RESOURCE,
|
||||
FAKE_HIGHLIGHT_MENU_RES);
|
||||
|
||||
db.replaceOrThrow(SlicesDatabaseHelper.Tables.TABLE_SLICES_INDEX, null, values);
|
||||
db.close();
|
||||
|
@@ -143,5 +143,10 @@ public class SpecialCaseSliceManagerTest {
|
||||
public Intent getIntent() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSliceHighlightMenuRes() {
|
||||
return NO_RES;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -19,6 +19,7 @@ import static org.mockito.Mockito.mock;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.accessibility.AccessibilityMetricsFeatureProvider;
|
||||
import com.android.settings.accessibility.AccessibilitySearchFeatureProvider;
|
||||
import com.android.settings.accounts.AccountFeatureProvider;
|
||||
import com.android.settings.applications.ApplicationFeatureProvider;
|
||||
@@ -84,6 +85,7 @@ public class FakeFeatureFactory extends FeatureFactory {
|
||||
public SecuritySettingsFeatureProvider securitySettingsFeatureProvider;
|
||||
public GameSettingsFeatureProvider gameSettingsFeatureProvider;
|
||||
public AccessibilitySearchFeatureProvider mAccessibilitySearchFeatureProvider;
|
||||
public AccessibilityMetricsFeatureProvider mAccessibilityMetricsFeatureProvider;
|
||||
|
||||
/**
|
||||
* Call this in {@code @Before} method of the test class to use fake factory.
|
||||
@@ -124,6 +126,8 @@ public class FakeFeatureFactory extends FeatureFactory {
|
||||
extraAppInfoFeatureProvider = mock(ExtraAppInfoFeatureProvider.class);
|
||||
securitySettingsFeatureProvider = mock(SecuritySettingsFeatureProvider.class);
|
||||
gameSettingsFeatureProvider = mock(GameSettingsFeatureProvider.class);
|
||||
mAccessibilitySearchFeatureProvider = mock(AccessibilitySearchFeatureProvider.class);
|
||||
mAccessibilityMetricsFeatureProvider = mock(AccessibilityMetricsFeatureProvider.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -265,4 +269,9 @@ public class FakeFeatureFactory extends FeatureFactory {
|
||||
public AccessibilitySearchFeatureProvider getAccessibilitySearchFeatureProvider() {
|
||||
return mAccessibilitySearchFeatureProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AccessibilityMetricsFeatureProvider getAccessibilityMetricsFeatureProvider() {
|
||||
return mAccessibilityMetricsFeatureProvider;
|
||||
}
|
||||
}
|
||||
|
@@ -27,6 +27,7 @@ import com.android.settings.slices.SliceBackgroundWorker;
|
||||
public class FakeToggleController extends TogglePreferenceController {
|
||||
|
||||
public static final String AVAILABILITY_KEY = "fake_toggle_availability_key";
|
||||
public static final int HIGHLIGHT_MENU_RES = 5678;
|
||||
|
||||
public static final IntentFilter INTENT_FILTER = new IntentFilter(
|
||||
WifiManager.WIFI_AP_STATE_CHANGED_ACTION);
|
||||
@@ -70,6 +71,11 @@ public class FakeToggleController extends TogglePreferenceController {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSliceHighlightMenuRes() {
|
||||
return HIGHLIGHT_MENU_RES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends SliceBackgroundWorker> getBackgroundWorkerClass() {
|
||||
return TestWorker.class;
|
||||
|
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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.wifi;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.annotation.Nullable;
|
||||
import android.app.IActivityManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.RemoteException;
|
||||
|
||||
import androidx.test.core.app.ActivityScenario;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Spy;
|
||||
import org.mockito.junit.MockitoJUnit;
|
||||
import org.mockito.junit.MockitoRule;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class RequestToggleWiFiActivityTest {
|
||||
|
||||
@Rule
|
||||
public final MockitoRule mMockitoRule = MockitoJUnit.rule();
|
||||
@Spy
|
||||
private final Context mContext = ApplicationProvider.getApplicationContext();
|
||||
@Mock
|
||||
private WifiManager mWifiManager;
|
||||
@Mock
|
||||
private IActivityManager mIActivityManager;
|
||||
|
||||
private ActivityScenario<RequestToggleWiFiActivity> mActivityScenario;
|
||||
private RequestToggleWiFiActivity mActivity;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
when(mContext.getSystemService(WifiManager.class)).thenReturn(mWifiManager);
|
||||
when(mWifiManager.getWifiState()).thenReturn(WifiManager.WIFI_STATE_DISABLED);
|
||||
|
||||
mActivityScenario = ActivityScenario.launch(new Intent(WifiManager.ACTION_REQUEST_ENABLE));
|
||||
mActivityScenario.onActivity(activity -> mActivity = activity);
|
||||
|
||||
}
|
||||
|
||||
@After
|
||||
public void cleanUp() {
|
||||
mActivity = null;
|
||||
if (mActivityScenario != null) {
|
||||
mActivityScenario.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAppLabel_nullPackageName_returnNull() {
|
||||
fakeCallingPackage(null);
|
||||
|
||||
assertThat(mActivity.getAppLabel()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAppLabel_settingsPackageName_returnNotNull() {
|
||||
fakeCallingPackage("com.android.settings");
|
||||
|
||||
assertThat(mActivity.getAppLabel()).isNotNull();
|
||||
}
|
||||
|
||||
private void fakeCallingPackage(@Nullable String packageName) {
|
||||
assertThat(mActivity).isNotNull();
|
||||
mActivity.mActivityManager = mIActivityManager;
|
||||
try {
|
||||
when(mIActivityManager.getLaunchedFromPackage(any())).thenReturn(packageName);
|
||||
} catch (RemoteException e) {
|
||||
// Do nothing.
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user