Merge changes I7d29b58c,I2f1d22fb,I55e0fa2c into sc-v2-dev
* changes: [Provider Model] Internal cleanup - remove Provider Model flag and deprecated legacy UI part.3 [Provider Model] Internal cleanup - remove Provider Model flag and deprecated legacy UI part.2 [Provider Model] Internal cleanup - remove Provider Model flag and deprecated legacy UI
This commit is contained in:
@@ -13,7 +13,8 @@
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<!-- @deprecated This class will be removed in Android U, use {@link network_provider_sims_list.xml}
|
||||
instead.-->
|
||||
<PreferenceScreen
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:settings="http://schemas.android.com/apk/res-auto"
|
||||
|
@@ -13,7 +13,8 @@
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<!-- @deprecated This class will be removed in Android U, use {@link network_provider_internet.xml}
|
||||
instead.-->
|
||||
<PreferenceScreen
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:settings="http://schemas.android.com/apk/res-auto"
|
||||
|
@@ -39,7 +39,6 @@ public class CarrierWifiTogglePreferenceController extends TogglePreferenceContr
|
||||
protected static final String CARRIER_WIFI_NETWORK_PREF_KEY = "carrier_wifi_network";
|
||||
|
||||
protected final Context mContext;
|
||||
protected boolean mIsProviderModelEnabled;
|
||||
protected int mSubId;
|
||||
protected WifiPickerTrackerHelper mWifiPickerTrackerHelper;
|
||||
protected boolean mIsCarrierProvisionWifiEnabled;
|
||||
@@ -49,7 +48,6 @@ public class CarrierWifiTogglePreferenceController extends TogglePreferenceContr
|
||||
String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
mContext = context;
|
||||
mIsProviderModelEnabled = Utils.isProviderModelEnabled(context);
|
||||
}
|
||||
|
||||
/** Initialize related properties */
|
||||
@@ -62,9 +60,6 @@ public class CarrierWifiTogglePreferenceController extends TogglePreferenceContr
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
if (!mIsProviderModelEnabled) {
|
||||
return CONDITIONALLY_UNAVAILABLE;
|
||||
}
|
||||
return mIsCarrierProvisionWifiEnabled ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
|
||||
}
|
||||
|
||||
|
@@ -45,7 +45,12 @@ import java.util.Map;
|
||||
* This populates the entries on a page which lists all available mobile subscriptions. Each entry
|
||||
* has the name of the subscription with some subtext giving additional detail, and clicking on the
|
||||
* entry brings you to a details page for that network.
|
||||
*
|
||||
* @deprecated This class will be removed in Android U, use
|
||||
* {@link NetworkProviderSimsCategoryController} and
|
||||
* {@link NetworkProviderDownloadedSimsCategoryController} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public class MobileNetworkListController extends AbstractPreferenceController implements
|
||||
LifecycleObserver, SubscriptionsChangeListener.SubscriptionsChangeListenerClient {
|
||||
private static final String TAG = "MobileNetworkListCtlr";
|
||||
|
@@ -44,9 +44,7 @@ public class MobileNetworkListFragment extends DashboardFragment {
|
||||
|
||||
@Override
|
||||
protected int getPreferenceScreenResId() {
|
||||
return Utils.isProviderModelEnabled(getContext())
|
||||
? R.xml.network_provider_sims_list
|
||||
: R.xml.mobile_network_list;
|
||||
return R.xml.network_provider_sims_list;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -63,18 +61,14 @@ public class MobileNetworkListFragment extends DashboardFragment {
|
||||
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
|
||||
final List<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||
|
||||
if (Utils.isProviderModelEnabled(getContext())) {
|
||||
NetworkProviderSimsCategoryController simCategoryPrefCtrl =
|
||||
new NetworkProviderSimsCategoryController(context, KEY_PREFERENCE_CATEGORY_SIM,
|
||||
getSettingsLifecycle());
|
||||
controllers.add(simCategoryPrefCtrl);
|
||||
NetworkProviderDownloadedSimsCategoryController downloadedSimsCategoryCtrl =
|
||||
new NetworkProviderDownloadedSimsCategoryController(context,
|
||||
KEY_PREFERENCE_CATEGORY_DOWNLOADED_SIM, getSettingsLifecycle());
|
||||
controllers.add(downloadedSimsCategoryCtrl);
|
||||
} else {
|
||||
controllers.add(new MobileNetworkListController(getContext(), getLifecycle()));
|
||||
}
|
||||
NetworkProviderSimsCategoryController simCategoryPrefCtrl =
|
||||
new NetworkProviderSimsCategoryController(context, KEY_PREFERENCE_CATEGORY_SIM,
|
||||
getSettingsLifecycle());
|
||||
controllers.add(simCategoryPrefCtrl);
|
||||
NetworkProviderDownloadedSimsCategoryController downloadedSimsCategoryCtrl =
|
||||
new NetworkProviderDownloadedSimsCategoryController(context,
|
||||
KEY_PREFERENCE_CATEGORY_DOWNLOADED_SIM, getSettingsLifecycle());
|
||||
controllers.add(downloadedSimsCategoryCtrl);
|
||||
|
||||
return controllers;
|
||||
}
|
||||
@@ -87,9 +81,7 @@ public class MobileNetworkListFragment extends DashboardFragment {
|
||||
boolean enabled) {
|
||||
final ArrayList<SearchIndexableResource> result = new ArrayList<>();
|
||||
final SearchIndexableResource sir = new SearchIndexableResource(context);
|
||||
sir.xmlResId = Utils.isProviderModelEnabled(context)
|
||||
? R.xml.network_provider_sims_list
|
||||
: R.xml.mobile_network_list;
|
||||
sir.xmlResId = R.xml.network_provider_sims_list;
|
||||
result.add(sir);
|
||||
return result;
|
||||
}
|
||||
|
@@ -126,22 +126,13 @@ public class MobileNetworkSummaryController extends AbstractPreferenceController
|
||||
}
|
||||
return mContext.getString(R.string.mobile_network_tap_to_activate, displayName);
|
||||
} else {
|
||||
if (com.android.settings.Utils.isProviderModelEnabled(mContext)) {
|
||||
return getSummaryForProviderModel(subs);
|
||||
}
|
||||
final int count = subs.size();
|
||||
return mContext.getResources().getQuantityString(R.plurals.mobile_network_summary_count,
|
||||
count, count);
|
||||
return subs.stream()
|
||||
.mapToInt(SubscriptionAnnotation::getSubscriptionId)
|
||||
.mapToObj(subId -> mStatusCache.getDisplayName(subId))
|
||||
.collect(Collectors.joining(", "));
|
||||
}
|
||||
}
|
||||
|
||||
private CharSequence getSummaryForProviderModel(List<SubscriptionAnnotation> subs) {
|
||||
return subs.stream()
|
||||
.mapToInt(SubscriptionAnnotation::getSubscriptionId)
|
||||
.mapToObj(subId -> mStatusCache.getDisplayName(subId))
|
||||
.collect(Collectors.joining(", "));
|
||||
}
|
||||
|
||||
private void logPreferenceClick(Preference preference) {
|
||||
mMetricsFeatureProvider.logClickedPreference(preference,
|
||||
preference.getExtras().getInt(DashboardFragment.CATEGORY));
|
||||
|
@@ -32,9 +32,9 @@ import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
* are two or more active mobile subscriptions. It shows an overview of available network
|
||||
* connections with an entry for wifi (if connected) and an entry for each subscription.
|
||||
*
|
||||
* TODO(tomhsu) when provider model is completed, this class will be replaced
|
||||
* by {@link NetworkMobileProviderController}
|
||||
* @deprecated This class will be removed in Android U, there is no networks header anymore.
|
||||
*/
|
||||
@Deprecated
|
||||
public class MultiNetworkHeaderController extends BasePreferenceController implements
|
||||
WifiConnectionPreferenceController.UpdateListener,
|
||||
SubscriptionsPreferenceController.UpdateListener {
|
||||
|
@@ -60,20 +60,13 @@ public class NetworkDashboardFragment extends DashboardFragment implements
|
||||
|
||||
@Override
|
||||
protected int getPreferenceScreenResId() {
|
||||
if (Utils.isProviderModelEnabled(getContext())) {
|
||||
return R.xml.network_provider_internet;
|
||||
} else {
|
||||
return R.xml.network_and_internet;
|
||||
}
|
||||
return R.xml.network_provider_internet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
|
||||
if (!Utils.isProviderModelEnabled(context)) {
|
||||
use(MultiNetworkHeaderController.class).init(getSettingsLifecycle());
|
||||
}
|
||||
use(AirplaneModePreferenceController.class).setFragment(this);
|
||||
getSettingsLifecycle().addObserver(use(AllInOneTetherPreferenceController.class));
|
||||
}
|
||||
@@ -100,16 +93,8 @@ public class NetworkDashboardFragment extends DashboardFragment implements
|
||||
MobilePlanPreferenceHost mobilePlanHost) {
|
||||
final MobilePlanPreferenceController mobilePlanPreferenceController =
|
||||
new MobilePlanPreferenceController(context, mobilePlanHost);
|
||||
final WifiPrimarySwitchPreferenceController wifiPreferenceController =
|
||||
Utils.isProviderModelEnabled(context)
|
||||
? null
|
||||
: new WifiPrimarySwitchPreferenceController(
|
||||
context,
|
||||
metricsFeatureProvider);
|
||||
final InternetPreferenceController internetPreferenceController =
|
||||
Utils.isProviderModelEnabled(context)
|
||||
? new InternetPreferenceController(context, lifecycle)
|
||||
: null;
|
||||
new InternetPreferenceController(context, lifecycle);
|
||||
|
||||
final VpnPreferenceController vpnPreferenceController =
|
||||
new VpnPreferenceController(context);
|
||||
@@ -118,9 +103,6 @@ public class NetworkDashboardFragment extends DashboardFragment implements
|
||||
|
||||
if (lifecycle != null) {
|
||||
lifecycle.addObserver(mobilePlanPreferenceController);
|
||||
if (wifiPreferenceController != null) {
|
||||
lifecycle.addObserver(wifiPreferenceController);
|
||||
}
|
||||
lifecycle.addObserver(vpnPreferenceController);
|
||||
lifecycle.addObserver(privateDnsPreferenceController);
|
||||
}
|
||||
@@ -132,9 +114,6 @@ public class NetworkDashboardFragment extends DashboardFragment implements
|
||||
controllers.add(vpnPreferenceController);
|
||||
controllers.add(new ProxyPreferenceController(context));
|
||||
controllers.add(mobilePlanPreferenceController);
|
||||
if (wifiPreferenceController != null) {
|
||||
controllers.add(wifiPreferenceController);
|
||||
}
|
||||
if (internetPreferenceController != null) {
|
||||
controllers.add(internetPreferenceController);
|
||||
}
|
||||
|
@@ -100,8 +100,7 @@ public class NetworkProviderCallsSmsFragment extends DashboardFragment {
|
||||
|
||||
@Override
|
||||
protected boolean isPageSearchEnabled(Context context) {
|
||||
return Utils.isProviderModelEnabled(context) &&
|
||||
context.getSystemService(UserManager.class).isAdminUser();
|
||||
return context.getSystemService(UserManager.class).isAdminUser();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@@ -60,7 +60,6 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||
import com.android.settings.AirplaneModeEnabler;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.RestrictedSettingsFragment;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.core.FeatureFlags;
|
||||
import com.android.settings.core.SubSettingLauncher;
|
||||
import com.android.settings.datausage.DataUsagePreference;
|
||||
@@ -279,17 +278,6 @@ public class NetworkProviderSettings extends RestrictedSettingsFragment
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
if (!Utils.isProviderModelEnabled(getContext())) {
|
||||
final Intent intent = new Intent(getContext(), WifiSettingsActivity.class);
|
||||
final Bundle extras = getActivity().getIntent().getExtras();
|
||||
if (extras != null) {
|
||||
intent.putExtras(extras);
|
||||
}
|
||||
getContext().startActivity(intent);
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
mAirplaneModeEnabler = new AirplaneModeEnabler(getContext(), this);
|
||||
|
||||
// TODO(b/37429702): Add animations and preference comparator back after initial screen is
|
||||
@@ -1187,10 +1175,6 @@ public class NetworkProviderSettings extends RestrictedSettingsFragment
|
||||
|
||||
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider(R.xml.network_provider_settings) {
|
||||
@Override
|
||||
protected boolean isPageSearchEnabled(Context context) {
|
||||
return Utils.isProviderModelEnabled(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getNonIndexableKeys(Context context) {
|
||||
|
@@ -74,15 +74,8 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* If the provider model is not enabled, this controller manages a set of Preferences it places into
|
||||
* a PreferenceGroup owned by some parent
|
||||
* controller class - one for each available subscription. This controller is only considered
|
||||
* available if there are 2 or more subscriptions.
|
||||
*
|
||||
* If the provider model is enabled, this controller manages preference with data subscription
|
||||
* information and make its state display on preference.
|
||||
* TODO this class will clean up the multiple subscriptions functionality after the provider
|
||||
* model is released.
|
||||
* This controller manages preference with data subscription information and make its state
|
||||
* display on preference.
|
||||
*/
|
||||
public class SubscriptionsPreferenceController extends AbstractPreferenceController implements
|
||||
LifecycleObserver, SubscriptionsChangeListener.SubscriptionsChangeListenerClient,
|
||||
@@ -228,14 +221,6 @@ public class SubscriptionsPreferenceController extends AbstractPreferenceControl
|
||||
return;
|
||||
}
|
||||
|
||||
if (mSubsPrefCtrlInjector.isProviderModelEnabled(mContext)) {
|
||||
updateForProvider();
|
||||
} else {
|
||||
updateForBase();
|
||||
}
|
||||
}
|
||||
|
||||
private void updateForProvider() {
|
||||
SubscriptionInfo subInfo = mSubscriptionManager.getDefaultDataSubscriptionInfo();
|
||||
if (subInfo == null) {
|
||||
mPreferenceGroup.removeAll();
|
||||
@@ -349,50 +334,6 @@ public class SubscriptionsPreferenceController extends AbstractPreferenceControl
|
||||
mSubsGearPref.setSummary("");
|
||||
}
|
||||
|
||||
private void updateForBase() {
|
||||
final Map<Integer, Preference> existingPrefs = mSubscriptionPreferences;
|
||||
mSubscriptionPreferences = new ArrayMap<>();
|
||||
|
||||
int order = mStartOrder;
|
||||
final Set<Integer> activeSubIds = new ArraySet<>();
|
||||
final int dataDefaultSubId = mSubsPrefCtrlInjector.getDefaultDataSubscriptionId();
|
||||
for (SubscriptionInfo info :
|
||||
SubscriptionUtil.getActiveSubscriptions(mSubscriptionManager)) {
|
||||
final int subId = info.getSubscriptionId();
|
||||
// Avoid from showing subscription(SIM)s which has been marked as hidden
|
||||
// For example, only one subscription will be shown when there're multiple
|
||||
// subscriptions with same group UUID.
|
||||
if (!mSubsPrefCtrlInjector.canSubscriptionBeDisplayed(mContext, subId)) {
|
||||
continue;
|
||||
}
|
||||
activeSubIds.add(subId);
|
||||
Preference pref = existingPrefs.remove(subId);
|
||||
if (pref == null) {
|
||||
pref = new Preference(mPreferenceGroup.getContext());
|
||||
mPreferenceGroup.addPreference(pref);
|
||||
}
|
||||
pref.setTitle(SubscriptionUtil.getUniqueSubscriptionDisplayName(info, mContext));
|
||||
final boolean isDefaultForData = (subId == dataDefaultSubId);
|
||||
pref.setSummary(getSummary(subId, isDefaultForData));
|
||||
setIcon(pref, subId, isDefaultForData);
|
||||
pref.setOrder(order++);
|
||||
|
||||
pref.setOnPreferenceClickListener(clickedPref -> {
|
||||
startMobileNetworkActivity(mContext, subId);
|
||||
return true;
|
||||
});
|
||||
|
||||
mSubscriptionPreferences.put(subId, pref);
|
||||
}
|
||||
mSignalStrengthListener.updateSubscriptionIds(activeSubIds);
|
||||
|
||||
// Remove any old preferences that no longer map to a subscription.
|
||||
for (Preference pref : existingPrefs.values()) {
|
||||
mPreferenceGroup.removePreference(pref);
|
||||
}
|
||||
mUpdateListener.onChildrenUpdated();
|
||||
}
|
||||
|
||||
private static void startMobileNetworkActivity(Context context, int subId) {
|
||||
final Intent intent = new Intent(context, MobileNetworkActivity.class);
|
||||
intent.putExtra(Settings.EXTRA_SUB_ID, subId);
|
||||
@@ -472,8 +413,7 @@ public class SubscriptionsPreferenceController extends AbstractPreferenceControl
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if there are at least 2 available subscriptions,
|
||||
* or if there is at least 1 available subscription for provider model.
|
||||
* @return true if there is at least 1 available subscription.
|
||||
*/
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
@@ -492,7 +432,7 @@ public class SubscriptionsPreferenceController extends AbstractPreferenceControl
|
||||
.filter(subInfo ->
|
||||
mSubsPrefCtrlInjector.canSubscriptionBeDisplayed(mContext,
|
||||
subInfo.getSubscriptionId()))
|
||||
.count() >= (mSubsPrefCtrlInjector.isProviderModelEnabled(mContext) ? 1 : 2);
|
||||
.count() >= 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -537,12 +477,6 @@ public class SubscriptionsPreferenceController extends AbstractPreferenceControl
|
||||
update();
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
boolean canSubscriptionBeDisplayed(Context context, int subId) {
|
||||
return (SubscriptionUtil.getAvailableSubscription(context,
|
||||
ProxySubscriptionManager.getInstance(context), subId) != null);
|
||||
}
|
||||
|
||||
public void setWifiPickerTrackerHelper(WifiPickerTrackerHelper helper) {
|
||||
mWifiPickerTrackerHelper = helper;
|
||||
}
|
||||
@@ -602,13 +536,6 @@ public class SubscriptionsPreferenceController extends AbstractPreferenceControl
|
||||
return MobileNetworkUtils.activeNetworkIsCellular(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Confirms the flag of Provider Model switch is turned on or not.
|
||||
*/
|
||||
public boolean isProviderModelEnabled(Context context) {
|
||||
return Utils.isProviderModelEnabled(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets config for carrier customization.
|
||||
*/
|
||||
|
@@ -156,7 +156,7 @@ public class VpnPreferenceController extends AbstractPreferenceController
|
||||
summary = getNameForVpnConfig(vpn, UserHandle.of(uid));
|
||||
}
|
||||
// Optionally add warning icon if an insecure VPN is present.
|
||||
if (Utils.isProviderModelEnabled(mContext) && mPreference instanceof VpnInfoPreference) {
|
||||
if (mPreference instanceof VpnInfoPreference) {
|
||||
final int insecureVpnCount = getInsecureVpnCount();
|
||||
boolean isInsecureVPN = insecureVpnCount > 0;
|
||||
((VpnInfoPreference) mPreference).setInsecureVpn(isInsecureVPN);
|
||||
|
@@ -45,10 +45,6 @@ public class CallsDefaultSubscriptionController extends DefaultSubscriptionContr
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
if (Utils.isProviderModelEnabled(mContext)) {
|
||||
return MobileNetworkUtils.getPreferredStatus(isRtlMode(), mContext, mManager, true);
|
||||
} else {
|
||||
return super.getSummary();
|
||||
}
|
||||
return MobileNetworkUtils.getPreferredStatus(isRtlMode(), mContext, mManager, true);
|
||||
}
|
||||
}
|
||||
|
@@ -94,12 +94,7 @@ public abstract class DefaultSubscriptionController extends TelephonyBasePrefere
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus(int subId) {
|
||||
final List<SubscriptionInfo> subs = SubscriptionUtil.getActiveSubscriptions(mManager);
|
||||
if (subs.size() > 1 || Utils.isProviderModelEnabled(mContext)) {
|
||||
return AVAILABLE;
|
||||
} else {
|
||||
return CONDITIONALLY_UNAVAILABLE;
|
||||
}
|
||||
return AVAILABLE;
|
||||
}
|
||||
|
||||
@OnLifecycleEvent(ON_RESUME)
|
||||
@@ -162,7 +157,7 @@ public abstract class DefaultSubscriptionController extends TelephonyBasePrefere
|
||||
final ArrayList<CharSequence> displayNames = new ArrayList<>();
|
||||
final ArrayList<CharSequence> subscriptionIds = new ArrayList<>();
|
||||
|
||||
if (Utils.isProviderModelEnabled(mContext) && subs.size() == 1) {
|
||||
if (subs.size() == 1) {
|
||||
mPreference.setEnabled(false);
|
||||
mPreference.setSummary(SubscriptionUtil.getUniqueSubscriptionDisplayName(
|
||||
subs.get(0), mContext));
|
||||
@@ -190,6 +185,7 @@ public abstract class DefaultSubscriptionController extends TelephonyBasePrefere
|
||||
subscriptionIds.add(Integer.toString(SubscriptionManager.INVALID_SUBSCRIPTION_ID));
|
||||
}
|
||||
|
||||
mPreference.setEnabled(true);
|
||||
mPreference.setEntries(displayNames.toArray(new CharSequence[0]));
|
||||
mPreference.setEntryValues(subscriptionIds.toArray(new CharSequence[0]));
|
||||
|
||||
|
@@ -61,10 +61,6 @@ public class SmsDefaultSubscriptionController extends DefaultSubscriptionControl
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
if (Utils.isProviderModelEnabled(mContext)) {
|
||||
return MobileNetworkUtils.getPreferredStatus(isRtlMode(), mContext, mManager, false);
|
||||
} else {
|
||||
return super.getSummary();
|
||||
}
|
||||
return MobileNetworkUtils.getPreferredStatus(isRtlMode(), mContext, mManager, false);
|
||||
}
|
||||
}
|
||||
|
@@ -158,7 +158,6 @@ public class NetworkProviderSettingsTest {
|
||||
.when(mFirstWifiEntryPreferenceCategory).getKey();
|
||||
mNetworkProviderSettings.mFirstWifiEntryPreferenceCategory =
|
||||
mFirstWifiEntryPreferenceCategory;
|
||||
FeatureFlagUtils.setEnabled(mContext, FeatureFlagUtils.SETTINGS_PROVIDER_MODEL, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
@@ -146,7 +146,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,31 +156,15 @@ 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();
|
||||
@@ -198,205 +181,10 @@ public class SubscriptionsPreferenceControllerTest {
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@UiThreadTest
|
||||
public void onAirplaneModeChanged_airplaneModeTurnedOn_eventFired() {
|
||||
setupMockSubscriptions(2);
|
||||
|
||||
mController.onResume();
|
||||
mController.displayPreference(mPreferenceScreen);
|
||||
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
|
||||
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() {
|
||||
Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 1);
|
||||
setupMockSubscriptions(2);
|
||||
|
||||
mController.onResume();
|
||||
mController.displayPreference(mPreferenceScreen);
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
|
||||
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 +199,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 +216,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 +236,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 +260,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 +279,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 +295,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 +313,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 +338,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 +364,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 +382,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 +396,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 +414,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 +438,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 +456,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 +474,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 +580,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
|
||||
|
Reference in New Issue
Block a user