Enable Carrier-Config cache for Settings
- Since the "Mobile-Data Details Settings" (NETWORK_OPERATOR_SETTINGS) will query Carrier-Config around 70 times during launching, use the Carrier-Config cache to reduce 69 times to speed up the launching time. - It takes about 3ms to query a Carrier-Config each time. - Create a singleton class to share the Carrier-Config for all sub-settings. Bug: 204135235 Test: manual test atest -c ApnPreferenceControllerTest \ AutoSelectPreferenceControllerTest \ BackupCallingPreferenceControllerTest \ CarrierConfigCacheTest \ CarrierPreferenceControllerTest \ CarrierSettingsVersionPreferenceControllerTest \ DataServiceSetupPreferenceControllerTest \ Enable2gPreferenceControllerTest \ EnabledNetworkModePreferenceControllerTest \ Enhanced4gBasePreferenceControllerTest \ MobileNetworkUtilsTest \ NetworkProviderBackupCallingGroupTest \ NrAdvancedCallingPreferenceControllerTest \ PreferredNetworkModePreferenceControllerTest \ TelephonyTogglePreferenceControllerTest \ WifiPickerTrackerHelperTest make RunSettingsRoboTests \ ROBOTEST_FILTER=ContactDiscoveryPreferenceControllerTest make RunSettingsRoboTests \ ROBOTEST_FILTER=VideoCallingPreferenceControllerTest Change-Id: I26f9ac115a754910b5d59e820703f1a0e701bb7f
This commit is contained in:
182
src/com/android/settings/network/CarrierConfigCache.java
Normal file
182
src/com/android/settings/network/CarrierConfigCache.java
Normal file
@@ -0,0 +1,182 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2022 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.network;
|
||||||
|
|
||||||
|
import static android.telephony.CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED;
|
||||||
|
import static android.telephony.SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX;
|
||||||
|
import static android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
||||||
|
|
||||||
|
import android.annotation.NonNull;
|
||||||
|
import android.annotation.TestApi;
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
|
import android.os.PersistableBundle;
|
||||||
|
import android.telephony.CarrierConfigManager;
|
||||||
|
import android.telephony.SubscriptionManager;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import androidx.annotation.GuardedBy;
|
||||||
|
import androidx.annotation.VisibleForTesting;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is a singleton class for Carrier-Configuration cache.
|
||||||
|
*/
|
||||||
|
public class CarrierConfigCache {
|
||||||
|
private static final String TAG = "CarrConfCache";
|
||||||
|
|
||||||
|
private static final Object sInstanceLock = new Object();
|
||||||
|
/**
|
||||||
|
* A singleton {@link CarrierConfigCache} object is used to share with all sub-settings.
|
||||||
|
*/
|
||||||
|
@GuardedBy("sInstanceLock")
|
||||||
|
private static CarrierConfigCache sInstance;
|
||||||
|
@TestApi
|
||||||
|
@GuardedBy("sInstanceLock")
|
||||||
|
private static Map<Context, CarrierConfigCache> sTestInstances;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manages mapping data from the subscription ID to the Carrier-Configuration
|
||||||
|
* {@link PersistableBundle} object.
|
||||||
|
*
|
||||||
|
* The Carrier-Configurations are used to share with all sub-settings.
|
||||||
|
*/
|
||||||
|
@VisibleForTesting
|
||||||
|
protected static final Map<Integer, PersistableBundle> sCarrierConfigs =
|
||||||
|
new ConcurrentHashMap<>();
|
||||||
|
@VisibleForTesting
|
||||||
|
protected static CarrierConfigManager sCarrierConfigManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static method to create a singleton class for Carrier-Configuration cache.
|
||||||
|
*
|
||||||
|
* @param context The Context this is associated with.
|
||||||
|
* @return an instance of {@link CarrierConfigCache} object.
|
||||||
|
*/
|
||||||
|
@NonNull
|
||||||
|
public static CarrierConfigCache getInstance(@NonNull Context context) {
|
||||||
|
synchronized (sInstanceLock) {
|
||||||
|
if (sTestInstances != null && sTestInstances.containsKey(context)) {
|
||||||
|
CarrierConfigCache testInstance = sTestInstances.get(context);
|
||||||
|
Log.w(TAG, "The context owner try to use a test instance:" + testInstance);
|
||||||
|
return testInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sInstance != null) return sInstance;
|
||||||
|
|
||||||
|
sInstance = new CarrierConfigCache();
|
||||||
|
final CarrierConfigChangeReceiver receiver = new CarrierConfigChangeReceiver();
|
||||||
|
final Context appContext = context.getApplicationContext();
|
||||||
|
sCarrierConfigManager = appContext.getSystemService(CarrierConfigManager.class);
|
||||||
|
appContext.registerReceiver(receiver, new IntentFilter(ACTION_CARRIER_CONFIG_CHANGED));
|
||||||
|
return sInstance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A convenience method to set pre-prepared instance or mock(CarrierConfigCache.class) for
|
||||||
|
* testing.
|
||||||
|
*
|
||||||
|
* @param context The Context this is associated with.
|
||||||
|
* @param instance of {@link CarrierConfigCache} object.
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
@TestApi
|
||||||
|
@VisibleForTesting
|
||||||
|
public static void setTestInstance(@NonNull Context context, CarrierConfigCache instance) {
|
||||||
|
synchronized (sInstanceLock) {
|
||||||
|
if (sTestInstances == null) sTestInstances = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
Log.w(TAG, "Try to set a test instance by context:" + context);
|
||||||
|
sTestInstances.put(context, instance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The constructor can only be accessed from static method inside the class itself, this is
|
||||||
|
* to avoid creating a class by adding a private constructor.
|
||||||
|
*/
|
||||||
|
private CarrierConfigCache() {
|
||||||
|
// Do nothing.
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the boolean If the system service is successfully obtained.
|
||||||
|
*
|
||||||
|
* @return true value, if the system service is successfully obtained.
|
||||||
|
*/
|
||||||
|
public boolean hasCarrierConfigManager() {
|
||||||
|
return (sCarrierConfigManager != null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the Carrier-Configuration for a particular subscription, which is associated with a
|
||||||
|
* specific SIM card. If an invalid subId is used, the returned config will contain default
|
||||||
|
* values.
|
||||||
|
*
|
||||||
|
* @param subId the subscription ID, normally obtained from {@link SubscriptionManager}.
|
||||||
|
* @return A {@link PersistableBundle} containing the config for the given subId, or default
|
||||||
|
* values for an invalid subId.
|
||||||
|
*/
|
||||||
|
public PersistableBundle getConfigForSubId(int subId) {
|
||||||
|
if (sCarrierConfigManager == null) return null;
|
||||||
|
|
||||||
|
synchronized (sCarrierConfigs) {
|
||||||
|
if (sCarrierConfigs.containsKey(subId)) {
|
||||||
|
return sCarrierConfigs.get(subId);
|
||||||
|
}
|
||||||
|
final PersistableBundle config = sCarrierConfigManager.getConfigForSubId(subId);
|
||||||
|
if (config == null) {
|
||||||
|
Log.e(TAG, "Could not get carrier config, subId:" + subId);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
sCarrierConfigs.put(subId, config);
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the Carrier-Configuration for the default subscription.
|
||||||
|
*
|
||||||
|
* @see #getConfigForSubId
|
||||||
|
*/
|
||||||
|
public PersistableBundle getConfig() {
|
||||||
|
if (sCarrierConfigManager == null) return null;
|
||||||
|
|
||||||
|
return getConfigForSubId(SubscriptionManager.getDefaultSubscriptionId());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class CarrierConfigChangeReceiver extends BroadcastReceiver {
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
if (!ACTION_CARRIER_CONFIG_CHANGED.equals(intent.getAction())) return;
|
||||||
|
|
||||||
|
final int subId = intent.getIntExtra(EXTRA_SUBSCRIPTION_INDEX, INVALID_SUBSCRIPTION_ID);
|
||||||
|
synchronized (sCarrierConfigs) {
|
||||||
|
if (SubscriptionManager.isValidSubscriptionId(subId)) {
|
||||||
|
sCarrierConfigs.remove(subId);
|
||||||
|
} else {
|
||||||
|
sCarrierConfigs.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -32,6 +32,7 @@ import androidx.preference.Preference;
|
|||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
import com.android.settings.SettingsActivity;
|
import com.android.settings.SettingsActivity;
|
||||||
|
import com.android.settings.network.CarrierConfigCache;
|
||||||
import com.android.settings.network.apn.ApnSettings;
|
import com.android.settings.network.apn.ApnSettings;
|
||||||
import com.android.settingslib.RestrictedLockUtilsInternal;
|
import com.android.settingslib.RestrictedLockUtilsInternal;
|
||||||
import com.android.settingslib.RestrictedPreference;
|
import com.android.settingslib.RestrictedPreference;
|
||||||
@@ -46,19 +47,19 @@ public class ApnPreferenceController extends TelephonyBasePreferenceController i
|
|||||||
LifecycleObserver, OnStart, OnStop {
|
LifecycleObserver, OnStart, OnStop {
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
CarrierConfigManager mCarrierConfigManager;
|
CarrierConfigCache mCarrierConfigCache;
|
||||||
private Preference mPreference;
|
private Preference mPreference;
|
||||||
private DpcApnEnforcedObserver mDpcApnEnforcedObserver;
|
private DpcApnEnforcedObserver mDpcApnEnforcedObserver;
|
||||||
|
|
||||||
public ApnPreferenceController(Context context, String key) {
|
public ApnPreferenceController(Context context, String key) {
|
||||||
super(context, key);
|
super(context, key);
|
||||||
mCarrierConfigManager = context.getSystemService(CarrierConfigManager.class);
|
mCarrierConfigCache = CarrierConfigCache.getInstance(context);
|
||||||
mDpcApnEnforcedObserver = new DpcApnEnforcedObserver(new Handler(Looper.getMainLooper()));
|
mDpcApnEnforcedObserver = new DpcApnEnforcedObserver(new Handler(Looper.getMainLooper()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getAvailabilityStatus(int subId) {
|
public int getAvailabilityStatus(int subId) {
|
||||||
final PersistableBundle carrierConfig = mCarrierConfigManager.getConfigForSubId(subId);
|
final PersistableBundle carrierConfig = mCarrierConfigCache.getConfigForSubId(subId);
|
||||||
final boolean isCdmaApn = MobileNetworkUtils.isCdmaOptions(mContext, subId)
|
final boolean isCdmaApn = MobileNetworkUtils.isCdmaOptions(mContext, subId)
|
||||||
&& carrierConfig != null
|
&& carrierConfig != null
|
||||||
&& carrierConfig.getBoolean(CarrierConfigManager.KEY_SHOW_APN_SETTING_CDMA_BOOL);
|
&& carrierConfig.getBoolean(CarrierConfigManager.KEY_SHOW_APN_SETTING_CDMA_BOOL);
|
||||||
|
@@ -28,17 +28,19 @@ import android.telephony.SubscriptionManager;
|
|||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
|
|
||||||
|
import com.android.settings.network.CarrierConfigCache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Preference controller for "Carrier Settings"
|
* Preference controller for "Carrier Settings"
|
||||||
*/
|
*/
|
||||||
public class CarrierPreferenceController extends TelephonyBasePreferenceController {
|
public class CarrierPreferenceController extends TelephonyBasePreferenceController {
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
CarrierConfigManager mCarrierConfigManager;
|
CarrierConfigCache mCarrierConfigCache;
|
||||||
|
|
||||||
public CarrierPreferenceController(Context context, String key) {
|
public CarrierPreferenceController(Context context, String key) {
|
||||||
super(context, key);
|
super(context, key);
|
||||||
mCarrierConfigManager = context.getSystemService(CarrierConfigManager.class);
|
mCarrierConfigCache = CarrierConfigCache.getInstance(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init(int subId) {
|
public void init(int subId) {
|
||||||
@@ -47,7 +49,7 @@ public class CarrierPreferenceController extends TelephonyBasePreferenceControll
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getAvailabilityStatus(int subId) {
|
public int getAvailabilityStatus(int subId) {
|
||||||
final PersistableBundle carrierConfig = mCarrierConfigManager.getConfigForSubId(subId);
|
final PersistableBundle carrierConfig = mCarrierConfigCache.getConfigForSubId(subId);
|
||||||
|
|
||||||
// Return available if it is in CDMA or GSM mode, and the flag is on
|
// Return available if it is in CDMA or GSM mode, and the flag is on
|
||||||
return carrierConfig != null
|
return carrierConfig != null
|
||||||
@@ -72,7 +74,7 @@ public class CarrierPreferenceController extends TelephonyBasePreferenceControll
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Intent getCarrierSettingsActivityIntent(int subId) {
|
private Intent getCarrierSettingsActivityIntent(int subId) {
|
||||||
final PersistableBundle config = mCarrierConfigManager.getConfigForSubId(subId);
|
final PersistableBundle config = mCarrierConfigCache.getConfigForSubId(subId);
|
||||||
final ComponentName cn = ComponentName.unflattenFromString(
|
final ComponentName cn = ComponentName.unflattenFromString(
|
||||||
config == null ? "" : config.getString(
|
config == null ? "" : config.getString(
|
||||||
CarrierConfigManager.KEY_CARRIER_SETTINGS_ACTIVITY_COMPONENT_NAME_STRING,
|
CarrierConfigManager.KEY_CARRIER_SETTINGS_ACTIVITY_COMPONENT_NAME_STRING,
|
||||||
|
@@ -23,15 +23,16 @@ import android.telephony.SubscriptionManager;
|
|||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import com.android.settings.core.BasePreferenceController;
|
import com.android.settings.core.BasePreferenceController;
|
||||||
|
import com.android.settings.network.CarrierConfigCache;
|
||||||
|
|
||||||
public class CarrierSettingsVersionPreferenceController extends BasePreferenceController {
|
public class CarrierSettingsVersionPreferenceController extends BasePreferenceController {
|
||||||
|
|
||||||
private int mSubscriptionId;
|
private int mSubscriptionId;
|
||||||
private CarrierConfigManager mManager;
|
private CarrierConfigCache mCarrierConfigCache;
|
||||||
|
|
||||||
public CarrierSettingsVersionPreferenceController(Context context, String preferenceKey) {
|
public CarrierSettingsVersionPreferenceController(Context context, String preferenceKey) {
|
||||||
super(context, preferenceKey);
|
super(context, preferenceKey);
|
||||||
mManager = context.getSystemService(CarrierConfigManager.class);
|
mCarrierConfigCache = CarrierConfigCache.getInstance(context);
|
||||||
mSubscriptionId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
mSubscriptionId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,7 +42,7 @@ public class CarrierSettingsVersionPreferenceController extends BasePreferenceCo
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CharSequence getSummary() {
|
public CharSequence getSummary() {
|
||||||
final PersistableBundle config = mManager.getConfigForSubId(mSubscriptionId);
|
final PersistableBundle config = mCarrierConfigCache.getConfigForSubId(mSubscriptionId);
|
||||||
if (config == null) {
|
if (config == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@@ -35,6 +35,7 @@ import androidx.preference.Preference;
|
|||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
import androidx.preference.SwitchPreference;
|
import androidx.preference.SwitchPreference;
|
||||||
|
|
||||||
|
import com.android.settings.network.CarrierConfigCache;
|
||||||
import com.android.settings.network.SubscriptionUtil;
|
import com.android.settings.network.SubscriptionUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -47,7 +48,7 @@ public class ContactDiscoveryPreferenceController extends TelephonyTogglePrefere
|
|||||||
Telephony.SimInfo.COLUMN_IMS_RCS_UCE_ENABLED);
|
Telephony.SimInfo.COLUMN_IMS_RCS_UCE_ENABLED);
|
||||||
|
|
||||||
private ImsManager mImsManager;
|
private ImsManager mImsManager;
|
||||||
private CarrierConfigManager mCarrierConfigManager;
|
private CarrierConfigCache mCarrierConfigCache;
|
||||||
private ContentObserver mUceSettingObserver;
|
private ContentObserver mUceSettingObserver;
|
||||||
private FragmentManager mFragmentManager;
|
private FragmentManager mFragmentManager;
|
||||||
|
|
||||||
@@ -57,7 +58,7 @@ public class ContactDiscoveryPreferenceController extends TelephonyTogglePrefere
|
|||||||
public ContactDiscoveryPreferenceController(Context context, String key) {
|
public ContactDiscoveryPreferenceController(Context context, String key) {
|
||||||
super(context, key);
|
super(context, key);
|
||||||
mImsManager = mContext.getSystemService(ImsManager.class);
|
mImsManager = mContext.getSystemService(ImsManager.class);
|
||||||
mCarrierConfigManager = mContext.getSystemService(CarrierConfigManager.class);
|
mCarrierConfigCache = CarrierConfigCache.getInstance(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ContactDiscoveryPreferenceController init(FragmentManager fragmentManager, int subId,
|
public ContactDiscoveryPreferenceController init(FragmentManager fragmentManager, int subId,
|
||||||
@@ -96,7 +97,7 @@ public class ContactDiscoveryPreferenceController extends TelephonyTogglePrefere
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getAvailabilityStatus(int subId) {
|
public int getAvailabilityStatus(int subId) {
|
||||||
PersistableBundle bundle = mCarrierConfigManager.getConfigForSubId(subId);
|
PersistableBundle bundle = mCarrierConfigCache.getConfigForSubId(subId);
|
||||||
boolean shouldShowPresence = bundle != null
|
boolean shouldShowPresence = bundle != null
|
||||||
&& (bundle.getBoolean(
|
&& (bundle.getBoolean(
|
||||||
CarrierConfigManager.KEY_USE_RCS_PRESENCE_BOOL, false /*default*/)
|
CarrierConfigManager.KEY_USE_RCS_PRESENCE_BOOL, false /*default*/)
|
||||||
|
@@ -28,18 +28,20 @@ import android.text.TextUtils;
|
|||||||
|
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
|
|
||||||
|
import com.android.settings.network.CarrierConfigCache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Preference controller for "Data service setup"
|
* Preference controller for "Data service setup"
|
||||||
*/
|
*/
|
||||||
public class DataServiceSetupPreferenceController extends TelephonyBasePreferenceController {
|
public class DataServiceSetupPreferenceController extends TelephonyBasePreferenceController {
|
||||||
|
|
||||||
private CarrierConfigManager mCarrierConfigManager;
|
private CarrierConfigCache mCarrierConfigCache;
|
||||||
private TelephonyManager mTelephonyManager;
|
private TelephonyManager mTelephonyManager;
|
||||||
private String mSetupUrl;
|
private String mSetupUrl;
|
||||||
|
|
||||||
public DataServiceSetupPreferenceController(Context context, String key) {
|
public DataServiceSetupPreferenceController(Context context, String key) {
|
||||||
super(context, key);
|
super(context, key);
|
||||||
mCarrierConfigManager = context.getSystemService(CarrierConfigManager.class);
|
mCarrierConfigCache = CarrierConfigCache.getInstance(context);
|
||||||
mTelephonyManager = context.getSystemService(TelephonyManager.class);
|
mTelephonyManager = context.getSystemService(TelephonyManager.class);
|
||||||
mSetupUrl = Settings.Global.getString(mContext.getContentResolver(),
|
mSetupUrl = Settings.Global.getString(mContext.getContentResolver(),
|
||||||
Settings.Global.SETUP_PREPAID_DATA_SERVICE_URL);
|
Settings.Global.SETUP_PREPAID_DATA_SERVICE_URL);
|
||||||
@@ -47,7 +49,7 @@ public class DataServiceSetupPreferenceController extends TelephonyBasePreferenc
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getAvailabilityStatus(int subId) {
|
public int getAvailabilityStatus(int subId) {
|
||||||
final PersistableBundle carrierConfig = mCarrierConfigManager.getConfigForSubId(subId);
|
final PersistableBundle carrierConfig = mCarrierConfigCache.getConfigForSubId(subId);
|
||||||
return subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID
|
return subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID
|
||||||
&& carrierConfig != null
|
&& carrierConfig != null
|
||||||
&& !carrierConfig.getBoolean(
|
&& !carrierConfig.getBoolean(
|
||||||
|
@@ -27,6 +27,7 @@ import android.util.Log;
|
|||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.network.CarrierConfigCache;
|
||||||
import com.android.settings.network.SubscriptionUtil;
|
import com.android.settings.network.SubscriptionUtil;
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||||
@@ -45,7 +46,7 @@ public class Enable2gPreferenceController extends TelephonyTogglePreferenceContr
|
|||||||
|
|
||||||
private final MetricsFeatureProvider mMetricsFeatureProvider;
|
private final MetricsFeatureProvider mMetricsFeatureProvider;
|
||||||
|
|
||||||
private CarrierConfigManager mCarrierConfigManager;
|
private CarrierConfigCache mCarrierConfigCache;
|
||||||
private SubscriptionManager mSubscriptionManager;
|
private SubscriptionManager mSubscriptionManager;
|
||||||
private TelephonyManager mTelephonyManager;
|
private TelephonyManager mTelephonyManager;
|
||||||
|
|
||||||
@@ -57,7 +58,7 @@ public class Enable2gPreferenceController extends TelephonyTogglePreferenceContr
|
|||||||
*/
|
*/
|
||||||
public Enable2gPreferenceController(Context context, String key) {
|
public Enable2gPreferenceController(Context context, String key) {
|
||||||
super(context, key);
|
super(context, key);
|
||||||
mCarrierConfigManager = context.getSystemService(CarrierConfigManager.class);
|
mCarrierConfigCache = CarrierConfigCache.getInstance(context);
|
||||||
mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider();
|
mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider();
|
||||||
mSubscriptionManager = context.getSystemService(SubscriptionManager.class);
|
mSubscriptionManager = context.getSystemService(SubscriptionManager.class);
|
||||||
}
|
}
|
||||||
@@ -81,7 +82,7 @@ public class Enable2gPreferenceController extends TelephonyTogglePreferenceContr
|
|||||||
if (preference == null || !SubscriptionManager.isUsableSubscriptionId(mSubId)) {
|
if (preference == null || !SubscriptionManager.isUsableSubscriptionId(mSubId)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final PersistableBundle carrierConfig = mCarrierConfigManager.getConfigForSubId(mSubId);
|
final PersistableBundle carrierConfig = mCarrierConfigCache.getConfigForSubId(mSubId);
|
||||||
boolean isDisabledByCarrier =
|
boolean isDisabledByCarrier =
|
||||||
carrierConfig != null
|
carrierConfig != null
|
||||||
&& carrierConfig.getBoolean(CarrierConfigManager.KEY_HIDE_ENABLE_2G);
|
&& carrierConfig.getBoolean(CarrierConfigManager.KEY_HIDE_ENABLE_2G);
|
||||||
@@ -107,7 +108,7 @@ public class Enable2gPreferenceController extends TelephonyTogglePreferenceContr
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getAvailabilityStatus(int subId) {
|
public int getAvailabilityStatus(int subId) {
|
||||||
final PersistableBundle carrierConfig = mCarrierConfigManager.getConfigForSubId(subId);
|
final PersistableBundle carrierConfig = mCarrierConfigCache.getConfigForSubId(subId);
|
||||||
if (mTelephonyManager == null) {
|
if (mTelephonyManager == null) {
|
||||||
Log.w(LOG_TAG, "Telephony manager not yet initialized");
|
Log.w(LOG_TAG, "Telephony manager not yet initialized");
|
||||||
mTelephonyManager = mContext.getSystemService(TelephonyManager.class);
|
mTelephonyManager = mContext.getSystemService(TelephonyManager.class);
|
||||||
|
@@ -37,6 +37,7 @@ import androidx.preference.PreferenceScreen;
|
|||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.network.AllowedNetworkTypesListener;
|
import com.android.settings.network.AllowedNetworkTypesListener;
|
||||||
|
import com.android.settings.network.CarrierConfigCache;
|
||||||
import com.android.settings.network.SubscriptionsChangeListener;
|
import com.android.settings.network.SubscriptionsChangeListener;
|
||||||
import com.android.settings.network.telephony.TelephonyConstants.TelephonyManagerConstants;
|
import com.android.settings.network.telephony.TelephonyConstants.TelephonyManagerConstants;
|
||||||
|
|
||||||
@@ -58,7 +59,7 @@ public class EnabledNetworkModePreferenceController extends
|
|||||||
private Preference mPreference;
|
private Preference mPreference;
|
||||||
private PreferenceScreen mPreferenceScreen;
|
private PreferenceScreen mPreferenceScreen;
|
||||||
private TelephonyManager mTelephonyManager;
|
private TelephonyManager mTelephonyManager;
|
||||||
private CarrierConfigManager mCarrierConfigManager;
|
private CarrierConfigCache mCarrierConfigCache;
|
||||||
private PreferenceEntriesBuilder mBuilder;
|
private PreferenceEntriesBuilder mBuilder;
|
||||||
private SubscriptionsChangeListener mSubscriptionsListener;
|
private SubscriptionsChangeListener mSubscriptionsListener;
|
||||||
private int mCallState = TelephonyManager.CALL_STATE_IDLE;
|
private int mCallState = TelephonyManager.CALL_STATE_IDLE;
|
||||||
@@ -67,7 +68,7 @@ public class EnabledNetworkModePreferenceController extends
|
|||||||
public EnabledNetworkModePreferenceController(Context context, String key) {
|
public EnabledNetworkModePreferenceController(Context context, String key) {
|
||||||
super(context, key);
|
super(context, key);
|
||||||
mSubscriptionsListener = new SubscriptionsChangeListener(context, this);
|
mSubscriptionsListener = new SubscriptionsChangeListener(context, this);
|
||||||
mCarrierConfigManager = mContext.getSystemService(CarrierConfigManager.class);
|
mCarrierConfigCache = CarrierConfigCache.getInstance(context);
|
||||||
if (mTelephonyCallback == null) {
|
if (mTelephonyCallback == null) {
|
||||||
mTelephonyCallback = new PhoneCallStateTelephonyCallback();
|
mTelephonyCallback = new PhoneCallStateTelephonyCallback();
|
||||||
}
|
}
|
||||||
@@ -80,7 +81,7 @@ public class EnabledNetworkModePreferenceController extends
|
|||||||
return AVAILABLE_UNSEARCHABLE;
|
return AVAILABLE_UNSEARCHABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
final PersistableBundle carrierConfig = mCarrierConfigManager.getConfigForSubId(subId);
|
final PersistableBundle carrierConfig = mCarrierConfigCache.getConfigForSubId(subId);
|
||||||
if (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
|
if (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
|
||||||
visible = false;
|
visible = false;
|
||||||
} else if (carrierConfig == null) {
|
} else if (carrierConfig == null) {
|
||||||
@@ -202,7 +203,7 @@ public class EnabledNetworkModePreferenceController extends
|
|||||||
}
|
}
|
||||||
|
|
||||||
private final class PreferenceEntriesBuilder {
|
private final class PreferenceEntriesBuilder {
|
||||||
private CarrierConfigManager mCarrierConfigManager;
|
private CarrierConfigCache mCarrierConfigCache;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private TelephonyManager mTelephonyManager;
|
private TelephonyManager mTelephonyManager;
|
||||||
|
|
||||||
@@ -221,7 +222,7 @@ public class EnabledNetworkModePreferenceController extends
|
|||||||
PreferenceEntriesBuilder(Context context, int subId) {
|
PreferenceEntriesBuilder(Context context, int subId) {
|
||||||
this.mContext = context;
|
this.mContext = context;
|
||||||
this.mSubId = subId;
|
this.mSubId = subId;
|
||||||
mCarrierConfigManager = mContext.getSystemService(CarrierConfigManager.class);
|
mCarrierConfigCache = CarrierConfigCache.getInstance(context);
|
||||||
mTelephonyManager = mContext.getSystemService(TelephonyManager.class)
|
mTelephonyManager = mContext.getSystemService(TelephonyManager.class)
|
||||||
.createForSubscriptionId(mSubId);
|
.createForSubscriptionId(mSubId);
|
||||||
updateConfig();
|
updateConfig();
|
||||||
@@ -229,7 +230,7 @@ public class EnabledNetworkModePreferenceController extends
|
|||||||
|
|
||||||
public void updateConfig() {
|
public void updateConfig() {
|
||||||
mTelephonyManager = mTelephonyManager.createForSubscriptionId(mSubId);
|
mTelephonyManager = mTelephonyManager.createForSubscriptionId(mSubId);
|
||||||
final PersistableBundle carrierConfig = mCarrierConfigManager.getConfigForSubId(mSubId);
|
final PersistableBundle carrierConfig = mCarrierConfigCache.getConfigForSubId(mSubId);
|
||||||
mAllowed5gNetworkType = checkSupportedRadioBitmask(
|
mAllowed5gNetworkType = checkSupportedRadioBitmask(
|
||||||
mTelephonyManager.getAllowedNetworkTypesForReason(
|
mTelephonyManager.getAllowedNetworkTypesForReason(
|
||||||
TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_CARRIER),
|
TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_CARRIER),
|
||||||
@@ -413,7 +414,7 @@ public class EnabledNetworkModePreferenceController extends
|
|||||||
private EnabledNetworks getEnabledNetworkType() {
|
private EnabledNetworks getEnabledNetworkType() {
|
||||||
EnabledNetworks enabledNetworkType = EnabledNetworks.ENABLED_NETWORKS_UNKNOWN;
|
EnabledNetworks enabledNetworkType = EnabledNetworks.ENABLED_NETWORKS_UNKNOWN;
|
||||||
final int phoneType = mTelephonyManager.getPhoneType();
|
final int phoneType = mTelephonyManager.getPhoneType();
|
||||||
final PersistableBundle carrierConfig = mCarrierConfigManager.getConfigForSubId(mSubId);
|
final PersistableBundle carrierConfig = mCarrierConfigCache.getConfigForSubId(mSubId);
|
||||||
|
|
||||||
if (phoneType == TelephonyManager.PHONE_TYPE_CDMA) {
|
if (phoneType == TelephonyManager.PHONE_TYPE_CDMA) {
|
||||||
final int lteForced = android.provider.Settings.Global.getInt(
|
final int lteForced = android.provider.Settings.Global.getInt(
|
||||||
|
@@ -75,6 +75,7 @@ import com.android.settings.R;
|
|||||||
import com.android.settings.Utils;
|
import com.android.settings.Utils;
|
||||||
import com.android.settings.core.BasePreferenceController;
|
import com.android.settings.core.BasePreferenceController;
|
||||||
import com.android.settings.core.SubSettingLauncher;
|
import com.android.settings.core.SubSettingLauncher;
|
||||||
|
import com.android.settings.network.CarrierConfigCache;
|
||||||
import com.android.settings.network.SubscriptionUtil;
|
import com.android.settings.network.SubscriptionUtil;
|
||||||
import com.android.settings.network.ims.WifiCallingQueryImsState;
|
import com.android.settings.network.ims.WifiCallingQueryImsState;
|
||||||
import com.android.settings.network.telephony.TelephonyConstants.TelephonyManagerConstants;
|
import com.android.settings.network.telephony.TelephonyConstants.TelephonyManagerConstants;
|
||||||
@@ -204,13 +205,12 @@ public class MobileNetworkUtils {
|
|||||||
* should be shown to the user, false if the option should be hidden.
|
* should be shown to the user, false if the option should be hidden.
|
||||||
*/
|
*/
|
||||||
public static boolean isContactDiscoveryVisible(Context context, int subId) {
|
public static boolean isContactDiscoveryVisible(Context context, int subId) {
|
||||||
CarrierConfigManager carrierConfigManager = context.getSystemService(
|
CarrierConfigCache carrierConfigCache = CarrierConfigCache.getInstance(context);
|
||||||
CarrierConfigManager.class);
|
if (!carrierConfigCache.hasCarrierConfigManager()) {
|
||||||
if (carrierConfigManager == null) {
|
|
||||||
Log.w(TAG, "isContactDiscoveryVisible: Could not resolve carrier config");
|
Log.w(TAG, "isContactDiscoveryVisible: Could not resolve carrier config");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
PersistableBundle bundle = carrierConfigManager.getConfigForSubId(subId);
|
PersistableBundle bundle = carrierConfigCache.getConfigForSubId(subId);
|
||||||
return bundle.getBoolean(
|
return bundle.getBoolean(
|
||||||
CarrierConfigManager.KEY_USE_RCS_PRESENCE_BOOL, false /*default*/)
|
CarrierConfigManager.KEY_USE_RCS_PRESENCE_BOOL, false /*default*/)
|
||||||
|| bundle.getBoolean(CarrierConfigManager.Ims.KEY_RCS_BULK_CAPABILITY_EXCHANGE_BOOL,
|
|| bundle.getBoolean(CarrierConfigManager.Ims.KEY_RCS_BULK_CAPABILITY_EXCHANGE_BOOL,
|
||||||
@@ -358,9 +358,8 @@ public class MobileNetworkUtils {
|
|||||||
if (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
|
if (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
final PersistableBundle carrierConfig =
|
||||||
final PersistableBundle carrierConfig = context.getSystemService(
|
CarrierConfigCache.getInstance(context).getConfigForSubId(subId);
|
||||||
CarrierConfigManager.class).getConfigForSubId(subId);
|
|
||||||
if (carrierConfig != null
|
if (carrierConfig != null
|
||||||
&& !carrierConfig.getBoolean(
|
&& !carrierConfig.getBoolean(
|
||||||
CarrierConfigManager.KEY_HIDE_CARRIER_NETWORK_SETTINGS_BOOL)
|
CarrierConfigManager.KEY_HIDE_CARRIER_NETWORK_SETTINGS_BOOL)
|
||||||
@@ -424,8 +423,8 @@ public class MobileNetworkUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isGsmBasicOptions(Context context, int subId) {
|
private static boolean isGsmBasicOptions(Context context, int subId) {
|
||||||
final PersistableBundle carrierConfig = context.getSystemService(
|
final PersistableBundle carrierConfig =
|
||||||
CarrierConfigManager.class).getConfigForSubId(subId);
|
CarrierConfigCache.getInstance(context).getConfigForSubId(subId);
|
||||||
if (carrierConfig != null
|
if (carrierConfig != null
|
||||||
&& !carrierConfig.getBoolean(
|
&& !carrierConfig.getBoolean(
|
||||||
CarrierConfigManager.KEY_HIDE_CARRIER_NETWORK_SETTINGS_BOOL)
|
CarrierConfigManager.KEY_HIDE_CARRIER_NETWORK_SETTINGS_BOOL)
|
||||||
@@ -447,8 +446,8 @@ public class MobileNetworkUtils {
|
|||||||
* settings
|
* settings
|
||||||
*/
|
*/
|
||||||
public static boolean isWorldMode(Context context, int subId) {
|
public static boolean isWorldMode(Context context, int subId) {
|
||||||
final PersistableBundle carrierConfig = context.getSystemService(
|
final PersistableBundle carrierConfig =
|
||||||
CarrierConfigManager.class).getConfigForSubId(subId);
|
CarrierConfigCache.getInstance(context).getConfigForSubId(subId);
|
||||||
return carrierConfig == null
|
return carrierConfig == null
|
||||||
? false
|
? false
|
||||||
: carrierConfig.getBoolean(CarrierConfigManager.KEY_WORLD_MODE_ENABLED_BOOL);
|
: carrierConfig.getBoolean(CarrierConfigManager.KEY_WORLD_MODE_ENABLED_BOOL);
|
||||||
@@ -460,8 +459,8 @@ public class MobileNetworkUtils {
|
|||||||
public static boolean shouldDisplayNetworkSelectOptions(Context context, int subId) {
|
public static boolean shouldDisplayNetworkSelectOptions(Context context, int subId) {
|
||||||
final TelephonyManager telephonyManager = context.getSystemService(TelephonyManager.class)
|
final TelephonyManager telephonyManager = context.getSystemService(TelephonyManager.class)
|
||||||
.createForSubscriptionId(subId);
|
.createForSubscriptionId(subId);
|
||||||
final PersistableBundle carrierConfig = context.getSystemService(
|
final PersistableBundle carrierConfig =
|
||||||
CarrierConfigManager.class).getConfigForSubId(subId);
|
CarrierConfigCache.getInstance(context).getConfigForSubId(subId);
|
||||||
if (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID
|
if (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID
|
||||||
|| carrierConfig == null
|
|| carrierConfig == null
|
||||||
|| !carrierConfig.getBoolean(
|
|| !carrierConfig.getBoolean(
|
||||||
@@ -502,8 +501,7 @@ public class MobileNetworkUtils {
|
|||||||
|
|
||||||
//TODO(b/117651939): move it to telephony
|
//TODO(b/117651939): move it to telephony
|
||||||
private static boolean isTdscdmaSupported(Context context, TelephonyManager telephonyManager) {
|
private static boolean isTdscdmaSupported(Context context, TelephonyManager telephonyManager) {
|
||||||
final PersistableBundle carrierConfig = context.getSystemService(
|
final PersistableBundle carrierConfig = CarrierConfigCache.getInstance(context).getConfig();
|
||||||
CarrierConfigManager.class).getConfig();
|
|
||||||
|
|
||||||
if (carrierConfig == null) {
|
if (carrierConfig == null) {
|
||||||
return false;
|
return false;
|
||||||
|
@@ -26,6 +26,7 @@ import androidx.preference.ListPreference;
|
|||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.network.CarrierConfigCache;
|
||||||
import com.android.settings.network.telephony.TelephonyConstants.TelephonyManagerConstants;
|
import com.android.settings.network.telephony.TelephonyConstants.TelephonyManagerConstants;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -34,19 +35,18 @@ import com.android.settings.network.telephony.TelephonyConstants.TelephonyManage
|
|||||||
public class PreferredNetworkModePreferenceController extends TelephonyBasePreferenceController
|
public class PreferredNetworkModePreferenceController extends TelephonyBasePreferenceController
|
||||||
implements ListPreference.OnPreferenceChangeListener {
|
implements ListPreference.OnPreferenceChangeListener {
|
||||||
|
|
||||||
private CarrierConfigManager mCarrierConfigManager;
|
private CarrierConfigCache mCarrierConfigCache;
|
||||||
private TelephonyManager mTelephonyManager;
|
private TelephonyManager mTelephonyManager;
|
||||||
private PersistableBundle mPersistableBundle;
|
|
||||||
private boolean mIsGlobalCdma;
|
private boolean mIsGlobalCdma;
|
||||||
|
|
||||||
public PreferredNetworkModePreferenceController(Context context, String key) {
|
public PreferredNetworkModePreferenceController(Context context, String key) {
|
||||||
super(context, key);
|
super(context, key);
|
||||||
mCarrierConfigManager = context.getSystemService(CarrierConfigManager.class);
|
mCarrierConfigCache = CarrierConfigCache.getInstance(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getAvailabilityStatus(int subId) {
|
public int getAvailabilityStatus(int subId) {
|
||||||
final PersistableBundle carrierConfig = mCarrierConfigManager.getConfigForSubId(subId);
|
final PersistableBundle carrierConfig = mCarrierConfigCache.getConfigForSubId(subId);
|
||||||
boolean visible;
|
boolean visible;
|
||||||
if (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
|
if (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
|
||||||
visible = false;
|
visible = false;
|
||||||
@@ -90,7 +90,7 @@ public class PreferredNetworkModePreferenceController extends TelephonyBasePrefe
|
|||||||
|
|
||||||
public void init(int subId) {
|
public void init(int subId) {
|
||||||
mSubId = subId;
|
mSubId = subId;
|
||||||
final PersistableBundle carrierConfig = mCarrierConfigManager.getConfigForSubId(mSubId);
|
final PersistableBundle carrierConfig = mCarrierConfigCache.getConfigForSubId(mSubId);
|
||||||
mTelephonyManager = mContext.getSystemService(TelephonyManager.class)
|
mTelephonyManager = mContext.getSystemService(TelephonyManager.class)
|
||||||
.createForSubscriptionId(mSubId);
|
.createForSubscriptionId(mSubId);
|
||||||
|
|
||||||
|
@@ -19,10 +19,10 @@ package com.android.settings.network.telephony;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.os.PersistableBundle;
|
import android.os.PersistableBundle;
|
||||||
import android.telephony.CarrierConfigManager;
|
|
||||||
import android.telephony.SubscriptionManager;
|
import android.telephony.SubscriptionManager;
|
||||||
|
|
||||||
import com.android.settings.core.TogglePreferenceController;
|
import com.android.settings.core.TogglePreferenceController;
|
||||||
|
import com.android.settings.network.CarrierConfigCache;
|
||||||
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
@@ -82,9 +82,7 @@ public abstract class TelephonyTogglePreferenceController extends TogglePreferen
|
|||||||
if (!SubscriptionManager.isValidSubscriptionId(subId)) {
|
if (!SubscriptionManager.isValidSubscriptionId(subId)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final CarrierConfigManager carrierConfigMgr =
|
return CarrierConfigCache.getInstance(mContext).getConfigForSubId(subId);
|
||||||
mContext.getSystemService(CarrierConfigManager.class);
|
|
||||||
return carrierConfigMgr.getConfigForSubId(subId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -30,6 +30,7 @@ import androidx.preference.Preference;
|
|||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
import androidx.preference.SwitchPreference;
|
import androidx.preference.SwitchPreference;
|
||||||
|
|
||||||
|
import com.android.settings.network.CarrierConfigCache;
|
||||||
import com.android.settings.network.MobileDataEnabledListener;
|
import com.android.settings.network.MobileDataEnabledListener;
|
||||||
import com.android.settings.network.ims.VolteQueryImsState;
|
import com.android.settings.network.ims.VolteQueryImsState;
|
||||||
import com.android.settings.network.ims.VtQueryImsState;
|
import com.android.settings.network.ims.VtQueryImsState;
|
||||||
@@ -48,7 +49,6 @@ public class VideoCallingPreferenceController extends TelephonyTogglePreferenceC
|
|||||||
private static final String TAG = "VideoCallingPreference";
|
private static final String TAG = "VideoCallingPreference";
|
||||||
|
|
||||||
private Preference mPreference;
|
private Preference mPreference;
|
||||||
private CarrierConfigManager mCarrierConfigManager;
|
|
||||||
private PhoneTelephonyCallback mTelephonyCallback;
|
private PhoneTelephonyCallback mTelephonyCallback;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
Integer mCallState;
|
Integer mCallState;
|
||||||
@@ -56,7 +56,6 @@ public class VideoCallingPreferenceController extends TelephonyTogglePreferenceC
|
|||||||
|
|
||||||
public VideoCallingPreferenceController(Context context, String key) {
|
public VideoCallingPreferenceController(Context context, String key) {
|
||||||
super(context, key);
|
super(context, key);
|
||||||
mCarrierConfigManager = context.getSystemService(CarrierConfigManager.class);
|
|
||||||
mDataContentObserver = new MobileDataEnabledListener(context, this);
|
mDataContentObserver = new MobileDataEnabledListener(context, this);
|
||||||
mTelephonyCallback = new PhoneTelephonyCallback();
|
mTelephonyCallback = new PhoneTelephonyCallback();
|
||||||
}
|
}
|
||||||
@@ -142,17 +141,8 @@ public class VideoCallingPreferenceController extends TelephonyTogglePreferenceC
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// When called within Settings Search, this variable may still be null.
|
final PersistableBundle carrierConfig =
|
||||||
if (mCarrierConfigManager == null) {
|
CarrierConfigCache.getInstance(mContext).getConfigForSubId(subId);
|
||||||
Log.e(TAG, "CarrierConfigManager set to null.");
|
|
||||||
mCarrierConfigManager = mContext.getSystemService(CarrierConfigManager.class);
|
|
||||||
if (mCarrierConfigManager == null) {
|
|
||||||
Log.e(TAG, "Unable to reinitialize CarrierConfigManager.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final PersistableBundle carrierConfig = mCarrierConfigManager.getConfigForSubId(subId);
|
|
||||||
if (carrierConfig == null) {
|
if (carrierConfig == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@@ -43,6 +43,7 @@ import androidx.preference.SwitchPreference;
|
|||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.network.AllowedNetworkTypesListener;
|
import com.android.settings.network.AllowedNetworkTypesListener;
|
||||||
|
import com.android.settings.network.CarrierConfigCache;
|
||||||
import com.android.settings.network.telephony.MobileNetworkUtils;
|
import com.android.settings.network.telephony.MobileNetworkUtils;
|
||||||
import com.android.settings.network.telephony.TelephonyTogglePreferenceController;
|
import com.android.settings.network.telephony.TelephonyTogglePreferenceController;
|
||||||
import com.android.settingslib.utils.ThreadUtils;
|
import com.android.settingslib.utils.ThreadUtils;
|
||||||
@@ -191,8 +192,8 @@ public class AutoSelectPreferenceController extends TelephonyTogglePreferenceCon
|
|||||||
mSubId = subId;
|
mSubId = subId;
|
||||||
mTelephonyManager = mContext.getSystemService(TelephonyManager.class)
|
mTelephonyManager = mContext.getSystemService(TelephonyManager.class)
|
||||||
.createForSubscriptionId(mSubId);
|
.createForSubscriptionId(mSubId);
|
||||||
final PersistableBundle carrierConfig = mContext.getSystemService(
|
final PersistableBundle carrierConfig =
|
||||||
CarrierConfigManager.class).getConfigForSubId(mSubId);
|
CarrierConfigCache.getInstance(mContext).getConfigForSubId(mSubId);
|
||||||
mOnlyAutoSelectInHome = carrierConfig != null
|
mOnlyAutoSelectInHome = carrierConfig != null
|
||||||
? carrierConfig.getBoolean(
|
? carrierConfig.getBoolean(
|
||||||
CarrierConfigManager.KEY_ONLY_AUTO_SELECT_IN_HOME_NETWORK_BOOL)
|
CarrierConfigManager.KEY_ONLY_AUTO_SELECT_IN_HOME_NETWORK_BOOL)
|
||||||
|
@@ -35,6 +35,7 @@ import androidx.lifecycle.LifecycleObserver;
|
|||||||
import androidx.lifecycle.OnLifecycleEvent;
|
import androidx.lifecycle.OnLifecycleEvent;
|
||||||
|
|
||||||
import com.android.internal.annotations.VisibleForTesting;
|
import com.android.internal.annotations.VisibleForTesting;
|
||||||
|
import com.android.settings.network.CarrierConfigCache;
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
import com.android.wifitrackerlib.MergedCarrierEntry;
|
import com.android.wifitrackerlib.MergedCarrierEntry;
|
||||||
import com.android.wifitrackerlib.WifiEntry;
|
import com.android.wifitrackerlib.WifiEntry;
|
||||||
@@ -64,7 +65,7 @@ public class WifiPickerTrackerHelper implements LifecycleObserver {
|
|||||||
protected HandlerThread mWorkerThread;
|
protected HandlerThread mWorkerThread;
|
||||||
|
|
||||||
protected final WifiManager mWifiManager;
|
protected final WifiManager mWifiManager;
|
||||||
protected final CarrierConfigManager mCarrierConfigManager;
|
protected final CarrierConfigCache mCarrierConfigCache;
|
||||||
|
|
||||||
public WifiPickerTrackerHelper(@NonNull Lifecycle lifecycle, @NonNull Context context,
|
public WifiPickerTrackerHelper(@NonNull Lifecycle lifecycle, @NonNull Context context,
|
||||||
@Nullable WifiPickerTracker.WifiPickerTrackerCallback listener) {
|
@Nullable WifiPickerTracker.WifiPickerTrackerCallback listener) {
|
||||||
@@ -88,7 +89,7 @@ public class WifiPickerTrackerHelper implements LifecycleObserver {
|
|||||||
listener);
|
listener);
|
||||||
|
|
||||||
mWifiManager = context.getSystemService(WifiManager.class);
|
mWifiManager = context.getSystemService(WifiManager.class);
|
||||||
mCarrierConfigManager = context.getSystemService(CarrierConfigManager.class);
|
mCarrierConfigCache = CarrierConfigCache.getInstance(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @OnLifecycleEvent(ON_DESTROY) */
|
/** @OnLifecycleEvent(ON_DESTROY) */
|
||||||
@@ -104,7 +105,7 @@ public class WifiPickerTrackerHelper implements LifecycleObserver {
|
|||||||
|
|
||||||
/** Return the enabled/disabled state of the carrier network provision */
|
/** Return the enabled/disabled state of the carrier network provision */
|
||||||
public boolean isCarrierNetworkProvisionEnabled(int subId) {
|
public boolean isCarrierNetworkProvisionEnabled(int subId) {
|
||||||
final PersistableBundle config = mCarrierConfigManager.getConfigForSubId(subId);
|
final PersistableBundle config = mCarrierConfigCache.getConfigForSubId(subId);
|
||||||
if (config == null) {
|
if (config == null) {
|
||||||
Log.e(TAG, "Could not get carrier config, subId:" + subId);
|
Log.e(TAG, "Could not get carrier config, subId:" + subId);
|
||||||
return false;
|
return false;
|
||||||
|
@@ -48,6 +48,7 @@ import androidx.fragment.app.FragmentTransaction;
|
|||||||
import androidx.lifecycle.LifecycleOwner;
|
import androidx.lifecycle.LifecycleOwner;
|
||||||
import androidx.preference.SwitchPreference;
|
import androidx.preference.SwitchPreference;
|
||||||
|
|
||||||
|
import com.android.settings.network.CarrierConfigCache;
|
||||||
import com.android.settings.network.SubscriptionUtil;
|
import com.android.settings.network.SubscriptionUtil;
|
||||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||||
|
|
||||||
@@ -72,7 +73,7 @@ public class ContactDiscoveryPreferenceControllerTest {
|
|||||||
@Mock private ImsManager mImsManager;
|
@Mock private ImsManager mImsManager;
|
||||||
@Mock private ImsRcsManager mImsRcsManager;
|
@Mock private ImsRcsManager mImsRcsManager;
|
||||||
@Mock private RcsUceAdapter mRcsUceAdapter;
|
@Mock private RcsUceAdapter mRcsUceAdapter;
|
||||||
@Mock private CarrierConfigManager mCarrierConfigManager;
|
@Mock private CarrierConfigCache mCarrierConfigCache;
|
||||||
@Mock private ContentResolver mContentResolver;
|
@Mock private ContentResolver mContentResolver;
|
||||||
@Mock private FragmentManager mFragmentManager;
|
@Mock private FragmentManager mFragmentManager;
|
||||||
@Mock private FragmentTransaction mFragmentTransaction;
|
@Mock private FragmentTransaction mFragmentTransaction;
|
||||||
@@ -93,8 +94,8 @@ public class ContactDiscoveryPreferenceControllerTest {
|
|||||||
doReturn(mImsManager).when(mContext).getSystemService(ImsManager.class);
|
doReturn(mImsManager).when(mContext).getSystemService(ImsManager.class);
|
||||||
doReturn(mImsRcsManager).when(mImsManager).getImsRcsManager(anyInt());
|
doReturn(mImsRcsManager).when(mImsManager).getImsRcsManager(anyInt());
|
||||||
doReturn(mRcsUceAdapter).when(mImsRcsManager).getUceAdapter();
|
doReturn(mRcsUceAdapter).when(mImsRcsManager).getUceAdapter();
|
||||||
doReturn(mCarrierConfigManager).when(mContext).getSystemService(CarrierConfigManager.class);
|
CarrierConfigCache.setTestInstance(mContext, mCarrierConfigCache);
|
||||||
doReturn(mCarrierConfig).when(mCarrierConfigManager).getConfigForSubId(eq(TEST_SUB_ID));
|
doReturn(mCarrierConfig).when(mCarrierConfigCache).getConfigForSubId(eq(TEST_SUB_ID));
|
||||||
// Start all tests with presence being disabled.
|
// Start all tests with presence being disabled.
|
||||||
setRcsPresenceConfig(false);
|
setRcsPresenceConfig(false);
|
||||||
doReturn(mContentResolver).when(mContext).getContentResolver();
|
doReturn(mContentResolver).when(mContext).getContentResolver();
|
||||||
|
@@ -31,6 +31,7 @@ import android.telephony.ims.ProvisioningManager;
|
|||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
import androidx.preference.SwitchPreference;
|
import androidx.preference.SwitchPreference;
|
||||||
|
|
||||||
|
import com.android.settings.network.CarrierConfigCache;
|
||||||
import com.android.settings.network.ims.MockVolteQueryImsState;
|
import com.android.settings.network.ims.MockVolteQueryImsState;
|
||||||
import com.android.settings.network.ims.MockVtQueryImsState;
|
import com.android.settings.network.ims.MockVtQueryImsState;
|
||||||
|
|
||||||
@@ -51,7 +52,7 @@ public class VideoCallingPreferenceControllerTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private ProvisioningManager mProvisioningManager;
|
private ProvisioningManager mProvisioningManager;
|
||||||
@Mock
|
@Mock
|
||||||
private CarrierConfigManager mCarrierConfigManager;
|
private CarrierConfigCache mCarrierConfigCache;
|
||||||
@Mock
|
@Mock
|
||||||
private PreferenceScreen mPreferenceScreen;
|
private PreferenceScreen mPreferenceScreen;
|
||||||
|
|
||||||
@@ -69,14 +70,13 @@ public class VideoCallingPreferenceControllerTest {
|
|||||||
|
|
||||||
mContext = spy(RuntimeEnvironment.application);
|
mContext = spy(RuntimeEnvironment.application);
|
||||||
doReturn(mTelephonyManager).when(mContext).getSystemService(TelephonyManager.class);
|
doReturn(mTelephonyManager).when(mContext).getSystemService(TelephonyManager.class);
|
||||||
doReturn(mCarrierConfigManager).when(mContext)
|
CarrierConfigCache.setTestInstance(mContext, mCarrierConfigCache);
|
||||||
.getSystemService(CarrierConfigManager.class);
|
|
||||||
doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(SUB_ID);
|
doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(SUB_ID);
|
||||||
|
|
||||||
mCarrierConfig = new PersistableBundle();
|
mCarrierConfig = new PersistableBundle();
|
||||||
mCarrierConfig.putBoolean(
|
mCarrierConfig.putBoolean(
|
||||||
CarrierConfigManager.KEY_IGNORE_DATA_ENABLED_CHANGED_FOR_VIDEO_CALLS, true);
|
CarrierConfigManager.KEY_IGNORE_DATA_ENABLED_CHANGED_FOR_VIDEO_CALLS, true);
|
||||||
doReturn(mCarrierConfig).when(mCarrierConfigManager).getConfigForSubId(SUB_ID);
|
doReturn(mCarrierConfig).when(mCarrierConfigCache).getConfigForSubId(SUB_ID);
|
||||||
|
|
||||||
mQueryImsState = new MockVtQueryImsState(mContext, SUB_ID);
|
mQueryImsState = new MockVtQueryImsState(mContext, SUB_ID);
|
||||||
mQueryImsState.setIsEnabledByUser(true);
|
mQueryImsState.setIsEnabledByUser(true);
|
||||||
|
@@ -0,0 +1,101 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2022 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.network;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.spy;
|
||||||
|
import static org.mockito.Mockito.times;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.PersistableBundle;
|
||||||
|
import android.os.UserHandle;
|
||||||
|
import android.telephony.CarrierConfigManager;
|
||||||
|
|
||||||
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Rule;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.junit.MockitoJUnit;
|
||||||
|
import org.mockito.junit.MockitoRule;
|
||||||
|
|
||||||
|
@RunWith(AndroidJUnit4.class)
|
||||||
|
public class CarrierConfigCacheTest {
|
||||||
|
|
||||||
|
static final int ONCE_SUB_ID = 11;
|
||||||
|
static final int TWICE_SUB_ID = 12;
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public final MockitoRule mMockitoRule = MockitoJUnit.rule();
|
||||||
|
@Mock
|
||||||
|
CarrierConfigManager mCarrierConfigManager;
|
||||||
|
|
||||||
|
Context mContext;
|
||||||
|
CarrierConfigCache mCarrierConfigCache;
|
||||||
|
PersistableBundle mCarrierConfig = new PersistableBundle();
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||||
|
|
||||||
|
mCarrierConfigCache = CarrierConfigCache.getInstance(mContext);
|
||||||
|
mCarrierConfigCache.sCarrierConfigManager = mCarrierConfigManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getInstance_diffContext_getSameInstance() {
|
||||||
|
Context context = mContext.createContextAsUser(UserHandle.ALL, 0 /* flags */);
|
||||||
|
CarrierConfigCache instance = CarrierConfigCache.getInstance(context);
|
||||||
|
|
||||||
|
assertThat(mContext).isNotEqualTo(context);
|
||||||
|
assertThat(mCarrierConfigCache).isEqualTo(instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void hasCarrierConfigManager_getSystemService_returnTrue() {
|
||||||
|
assertThat(mCarrierConfigCache.hasCarrierConfigManager()).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getConfigForSubId_getOnce_onlyGetOnceFromManager() {
|
||||||
|
when(mCarrierConfigManager.getConfigForSubId(ONCE_SUB_ID)).thenReturn(mCarrierConfig);
|
||||||
|
|
||||||
|
PersistableBundle config = mCarrierConfigCache.getConfigForSubId(ONCE_SUB_ID);
|
||||||
|
|
||||||
|
assertThat(config).isEqualTo(mCarrierConfig);
|
||||||
|
verify(mCarrierConfigManager, times(1)).getConfigForSubId(ONCE_SUB_ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getConfigForSubId_getTwice_onlyGetOnceFromManager() {
|
||||||
|
when(mCarrierConfigManager.getConfigForSubId(TWICE_SUB_ID)).thenReturn(mCarrierConfig);
|
||||||
|
|
||||||
|
mCarrierConfigCache.getConfigForSubId(TWICE_SUB_ID);
|
||||||
|
|
||||||
|
verify(mCarrierConfigManager, times(1)).getConfigForSubId(TWICE_SUB_ID);
|
||||||
|
|
||||||
|
mCarrierConfigCache.getConfigForSubId(TWICE_SUB_ID);
|
||||||
|
|
||||||
|
verify(mCarrierConfigManager, times(1)).getConfigForSubId(TWICE_SUB_ID);
|
||||||
|
}
|
||||||
|
}
|
@@ -54,6 +54,7 @@ import androidx.test.annotation.UiThreadTest;
|
|||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
|
|
||||||
|
import com.android.settings.network.CarrierConfigCache;
|
||||||
import com.android.settings.network.telephony.TelephonyConstants.TelephonyManagerConstants;
|
import com.android.settings.network.telephony.TelephonyConstants.TelephonyManagerConstants;
|
||||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||||
|
|
||||||
@@ -76,7 +77,7 @@ public class EnabledNetworkModePreferenceControllerTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private TelephonyManager mInvalidTelephonyManager;
|
private TelephonyManager mInvalidTelephonyManager;
|
||||||
@Mock
|
@Mock
|
||||||
private CarrierConfigManager mCarrierConfigManager;
|
private CarrierConfigCache mCarrierConfigCache;
|
||||||
@Mock
|
@Mock
|
||||||
private ServiceState mServiceState;
|
private ServiceState mServiceState;
|
||||||
|
|
||||||
@@ -95,8 +96,7 @@ public class EnabledNetworkModePreferenceControllerTest {
|
|||||||
mLifecycle = new Lifecycle(mLifecycleOwner);
|
mLifecycle = new Lifecycle(mLifecycleOwner);
|
||||||
mContext = spy(ApplicationProvider.getApplicationContext());
|
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||||
|
|
||||||
when(mContext.getSystemService(CarrierConfigManager.class)).thenReturn(
|
CarrierConfigCache.setTestInstance(mContext, mCarrierConfigCache);
|
||||||
mCarrierConfigManager);
|
|
||||||
when(mContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager);
|
when(mContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager);
|
||||||
when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
|
when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
|
||||||
doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(SUB_ID);
|
doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(SUB_ID);
|
||||||
@@ -104,8 +104,8 @@ public class EnabledNetworkModePreferenceControllerTest {
|
|||||||
SubscriptionManager.INVALID_SUBSCRIPTION_ID);
|
SubscriptionManager.INVALID_SUBSCRIPTION_ID);
|
||||||
doReturn(mServiceState).when(mTelephonyManager).getServiceState();
|
doReturn(mServiceState).when(mTelephonyManager).getServiceState();
|
||||||
mPersistableBundle = new PersistableBundle();
|
mPersistableBundle = new PersistableBundle();
|
||||||
doReturn(mPersistableBundle).when(mCarrierConfigManager).getConfig();
|
doReturn(mPersistableBundle).when(mCarrierConfigCache).getConfig();
|
||||||
doReturn(mPersistableBundle).when(mCarrierConfigManager).getConfigForSubId(SUB_ID);
|
doReturn(mPersistableBundle).when(mCarrierConfigCache).getConfigForSubId(SUB_ID);
|
||||||
mPreference = new ListPreference(mContext);
|
mPreference = new ListPreference(mContext);
|
||||||
mController = new EnabledNetworkModePreferenceController(mContext, KEY);
|
mController = new EnabledNetworkModePreferenceController(mContext, KEY);
|
||||||
mockAllowedNetworkTypes(ALLOWED_ALL_NETWORK_TYPE);
|
mockAllowedNetworkTypes(ALLOWED_ALL_NETWORK_TYPE);
|
||||||
|
@@ -37,6 +37,7 @@ import android.telephony.TelephonyManager;
|
|||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
|
|
||||||
|
import com.android.settings.network.CarrierConfigCache;
|
||||||
import com.android.settings.network.apn.ApnSettings;
|
import com.android.settings.network.apn.ApnSettings;
|
||||||
import com.android.settingslib.RestrictedPreference;
|
import com.android.settingslib.RestrictedPreference;
|
||||||
|
|
||||||
@@ -58,7 +59,7 @@ public class ApnPreferenceControllerTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private SubscriptionManager mSubscriptionManager;
|
private SubscriptionManager mSubscriptionManager;
|
||||||
@Mock
|
@Mock
|
||||||
private CarrierConfigManager mCarrierConfigManager;
|
private CarrierConfigCache mCarrierConfigCache;
|
||||||
|
|
||||||
private ApnPreferenceController mController;
|
private ApnPreferenceController mController;
|
||||||
private RestrictedPreference mPreference;
|
private RestrictedPreference mPreference;
|
||||||
@@ -71,8 +72,7 @@ public class ApnPreferenceControllerTest {
|
|||||||
mContext = spy(ApplicationProvider.getApplicationContext());
|
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||||
when(mContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager);
|
when(mContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager);
|
||||||
when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager);
|
when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager);
|
||||||
when(mContext.getSystemService(CarrierConfigManager.class)).thenReturn(
|
CarrierConfigCache.setTestInstance(mContext, mCarrierConfigCache);
|
||||||
mCarrierConfigManager);
|
|
||||||
doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(SUB_ID);
|
doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(SUB_ID);
|
||||||
doReturn(mInvalidTelephonyManager).when(mTelephonyManager).createForSubscriptionId(
|
doReturn(mInvalidTelephonyManager).when(mTelephonyManager).createForSubscriptionId(
|
||||||
SubscriptionManager.INVALID_SUBSCRIPTION_ID);
|
SubscriptionManager.INVALID_SUBSCRIPTION_ID);
|
||||||
@@ -81,7 +81,6 @@ public class ApnPreferenceControllerTest {
|
|||||||
mController = new ApnPreferenceController(mContext, "mobile_data");
|
mController = new ApnPreferenceController(mContext, "mobile_data");
|
||||||
mController.init(SUB_ID);
|
mController.init(SUB_ID);
|
||||||
mController.setPreference(mPreference);
|
mController.setPreference(mPreference);
|
||||||
mController.mCarrierConfigManager = mCarrierConfigManager;
|
|
||||||
mPreference.setKey(mController.getPreferenceKey());
|
mPreference.setKey(mController.getPreferenceKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,7 +89,7 @@ public class ApnPreferenceControllerTest {
|
|||||||
doReturn(TelephonyManager.PHONE_TYPE_CDMA).when(mTelephonyManager).getPhoneType();
|
doReturn(TelephonyManager.PHONE_TYPE_CDMA).when(mTelephonyManager).getPhoneType();
|
||||||
final PersistableBundle bundle = new PersistableBundle();
|
final PersistableBundle bundle = new PersistableBundle();
|
||||||
bundle.putBoolean(CarrierConfigManager.KEY_SHOW_APN_SETTING_CDMA_BOOL, false);
|
bundle.putBoolean(CarrierConfigManager.KEY_SHOW_APN_SETTING_CDMA_BOOL, false);
|
||||||
doReturn(bundle).when(mCarrierConfigManager).getConfigForSubId(SUB_ID);
|
doReturn(bundle).when(mCarrierConfigCache).getConfigForSubId(SUB_ID);
|
||||||
|
|
||||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
|
assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
|
||||||
}
|
}
|
||||||
@@ -100,7 +99,7 @@ public class ApnPreferenceControllerTest {
|
|||||||
doReturn(TelephonyManager.PHONE_TYPE_CDMA).when(mTelephonyManager).getPhoneType();
|
doReturn(TelephonyManager.PHONE_TYPE_CDMA).when(mTelephonyManager).getPhoneType();
|
||||||
final PersistableBundle bundle = new PersistableBundle();
|
final PersistableBundle bundle = new PersistableBundle();
|
||||||
bundle.putBoolean(CarrierConfigManager.KEY_SHOW_APN_SETTING_CDMA_BOOL, true);
|
bundle.putBoolean(CarrierConfigManager.KEY_SHOW_APN_SETTING_CDMA_BOOL, true);
|
||||||
doReturn(bundle).when(mCarrierConfigManager).getConfigForSubId(SUB_ID);
|
doReturn(bundle).when(mCarrierConfigCache).getConfigForSubId(SUB_ID);
|
||||||
|
|
||||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
||||||
}
|
}
|
||||||
@@ -110,7 +109,7 @@ public class ApnPreferenceControllerTest {
|
|||||||
doReturn(TelephonyManager.PHONE_TYPE_GSM).when(mTelephonyManager).getPhoneType();
|
doReturn(TelephonyManager.PHONE_TYPE_GSM).when(mTelephonyManager).getPhoneType();
|
||||||
final PersistableBundle bundle = new PersistableBundle();
|
final PersistableBundle bundle = new PersistableBundle();
|
||||||
bundle.putBoolean(CarrierConfigManager.KEY_APN_EXPAND_BOOL, true);
|
bundle.putBoolean(CarrierConfigManager.KEY_APN_EXPAND_BOOL, true);
|
||||||
doReturn(bundle).when(mCarrierConfigManager).getConfigForSubId(SUB_ID);
|
doReturn(bundle).when(mCarrierConfigCache).getConfigForSubId(SUB_ID);
|
||||||
|
|
||||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
||||||
}
|
}
|
||||||
@@ -118,7 +117,7 @@ public class ApnPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void getAvailabilityStatus_carrierConfigNull_returnUnavailable() {
|
public void getAvailabilityStatus_carrierConfigNull_returnUnavailable() {
|
||||||
doReturn(TelephonyManager.PHONE_TYPE_GSM).when(mTelephonyManager).getPhoneType();
|
doReturn(TelephonyManager.PHONE_TYPE_GSM).when(mTelephonyManager).getPhoneType();
|
||||||
when(mCarrierConfigManager.getConfigForSubId(SUB_ID)).thenReturn(null);
|
when(mCarrierConfigCache.getConfigForSubId(SUB_ID)).thenReturn(null);
|
||||||
|
|
||||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
|
assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
|
||||||
}
|
}
|
||||||
@@ -129,7 +128,7 @@ public class ApnPreferenceControllerTest {
|
|||||||
final PersistableBundle bundle = new PersistableBundle();
|
final PersistableBundle bundle = new PersistableBundle();
|
||||||
bundle.putBoolean(CarrierConfigManager.KEY_APN_EXPAND_BOOL, true);
|
bundle.putBoolean(CarrierConfigManager.KEY_APN_EXPAND_BOOL, true);
|
||||||
bundle.putBoolean(CarrierConfigManager.KEY_HIDE_CARRIER_NETWORK_SETTINGS_BOOL, true);
|
bundle.putBoolean(CarrierConfigManager.KEY_HIDE_CARRIER_NETWORK_SETTINGS_BOOL, true);
|
||||||
doReturn(bundle).when(mCarrierConfigManager).getConfigForSubId(SUB_ID);
|
doReturn(bundle).when(mCarrierConfigCache).getConfigForSubId(SUB_ID);
|
||||||
|
|
||||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
|
assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
|
||||||
}
|
}
|
||||||
|
@@ -43,6 +43,7 @@ import android.telephony.TelephonyManager;
|
|||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
|
|
||||||
|
import com.android.settings.network.CarrierConfigCache;
|
||||||
import com.android.settingslib.RestrictedPreference;
|
import com.android.settingslib.RestrictedPreference;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -65,7 +66,7 @@ public class CarrierPreferenceControllerTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private SubscriptionManager mSubscriptionManager;
|
private SubscriptionManager mSubscriptionManager;
|
||||||
@Mock
|
@Mock
|
||||||
private CarrierConfigManager mCarrierConfigManager;
|
private CarrierConfigCache mCarrierConfigCache;
|
||||||
|
|
||||||
private CarrierPreferenceController mController;
|
private CarrierPreferenceController mController;
|
||||||
private RestrictedPreference mPreference;
|
private RestrictedPreference mPreference;
|
||||||
@@ -81,13 +82,11 @@ public class CarrierPreferenceControllerTest {
|
|||||||
doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(SUB_ID);
|
doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(SUB_ID);
|
||||||
doReturn(mInvalidTelephonyManager).when(mTelephonyManager).createForSubscriptionId(
|
doReturn(mInvalidTelephonyManager).when(mTelephonyManager).createForSubscriptionId(
|
||||||
SubscriptionManager.INVALID_SUBSCRIPTION_ID);
|
SubscriptionManager.INVALID_SUBSCRIPTION_ID);
|
||||||
when(mContext.getSystemService(CarrierConfigManager.class)).thenReturn(
|
CarrierConfigCache.setTestInstance(mContext, mCarrierConfigCache);
|
||||||
mCarrierConfigManager);
|
|
||||||
|
|
||||||
mPreference = new RestrictedPreference(mContext);
|
mPreference = new RestrictedPreference(mContext);
|
||||||
mController = new CarrierPreferenceController(mContext, "mobile_data");
|
mController = new CarrierPreferenceController(mContext, "mobile_data");
|
||||||
mController.init(SUB_ID);
|
mController.init(SUB_ID);
|
||||||
mController.mCarrierConfigManager = mCarrierConfigManager;
|
|
||||||
mPreference.setKey(mController.getPreferenceKey());
|
mPreference.setKey(mController.getPreferenceKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,7 +95,7 @@ public class CarrierPreferenceControllerTest {
|
|||||||
doReturn(TelephonyManager.PHONE_TYPE_CDMA).when(mTelephonyManager).getPhoneType();
|
doReturn(TelephonyManager.PHONE_TYPE_CDMA).when(mTelephonyManager).getPhoneType();
|
||||||
final PersistableBundle bundle = new PersistableBundle();
|
final PersistableBundle bundle = new PersistableBundle();
|
||||||
bundle.putBoolean(CarrierConfigManager.KEY_CARRIER_SETTINGS_ENABLE_BOOL, false);
|
bundle.putBoolean(CarrierConfigManager.KEY_CARRIER_SETTINGS_ENABLE_BOOL, false);
|
||||||
doReturn(bundle).when(mCarrierConfigManager).getConfigForSubId(SUB_ID);
|
doReturn(bundle).when(mCarrierConfigCache).getConfigForSubId(SUB_ID);
|
||||||
|
|
||||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
|
assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
|
||||||
}
|
}
|
||||||
@@ -106,7 +105,7 @@ public class CarrierPreferenceControllerTest {
|
|||||||
doReturn(TelephonyManager.PHONE_TYPE_CDMA).when(mTelephonyManager).getPhoneType();
|
doReturn(TelephonyManager.PHONE_TYPE_CDMA).when(mTelephonyManager).getPhoneType();
|
||||||
final PersistableBundle bundle = new PersistableBundle();
|
final PersistableBundle bundle = new PersistableBundle();
|
||||||
bundle.putBoolean(CarrierConfigManager.KEY_CARRIER_SETTINGS_ENABLE_BOOL, true);
|
bundle.putBoolean(CarrierConfigManager.KEY_CARRIER_SETTINGS_ENABLE_BOOL, true);
|
||||||
doReturn(bundle).when(mCarrierConfigManager).getConfigForSubId(SUB_ID);
|
doReturn(bundle).when(mCarrierConfigCache).getConfigForSubId(SUB_ID);
|
||||||
|
|
||||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
||||||
}
|
}
|
||||||
@@ -116,7 +115,7 @@ public class CarrierPreferenceControllerTest {
|
|||||||
doReturn(TelephonyManager.PHONE_TYPE_GSM).when(mTelephonyManager).getPhoneType();
|
doReturn(TelephonyManager.PHONE_TYPE_GSM).when(mTelephonyManager).getPhoneType();
|
||||||
final PersistableBundle bundle = new PersistableBundle();
|
final PersistableBundle bundle = new PersistableBundle();
|
||||||
bundle.putBoolean(CarrierConfigManager.KEY_CARRIER_SETTINGS_ENABLE_BOOL, true);
|
bundle.putBoolean(CarrierConfigManager.KEY_CARRIER_SETTINGS_ENABLE_BOOL, true);
|
||||||
doReturn(bundle).when(mCarrierConfigManager).getConfigForSubId(SUB_ID);
|
doReturn(bundle).when(mCarrierConfigCache).getConfigForSubId(SUB_ID);
|
||||||
|
|
||||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
||||||
}
|
}
|
||||||
@@ -127,7 +126,7 @@ public class CarrierPreferenceControllerTest {
|
|||||||
bundle.putString(
|
bundle.putString(
|
||||||
CarrierConfigManager.KEY_CARRIER_SETTINGS_ACTIVITY_COMPONENT_NAME_STRING,
|
CarrierConfigManager.KEY_CARRIER_SETTINGS_ACTIVITY_COMPONENT_NAME_STRING,
|
||||||
CARRIER_SETTINGS_COMPONENT);
|
CARRIER_SETTINGS_COMPONENT);
|
||||||
doReturn(bundle).when(mCarrierConfigManager).getConfigForSubId(SUB_ID);
|
doReturn(bundle).when(mCarrierConfigCache).getConfigForSubId(SUB_ID);
|
||||||
PackageManager pm = Mockito.mock(PackageManager.class);
|
PackageManager pm = Mockito.mock(PackageManager.class);
|
||||||
doReturn(pm).when(mContext).getPackageManager();
|
doReturn(pm).when(mContext).getPackageManager();
|
||||||
doReturn(new ResolveInfo()).when(pm).resolveActivity(any(Intent.class), anyInt());
|
doReturn(new ResolveInfo()).when(pm).resolveActivity(any(Intent.class), anyInt());
|
||||||
@@ -148,7 +147,7 @@ public class CarrierPreferenceControllerTest {
|
|||||||
bundle.putString(
|
bundle.putString(
|
||||||
CarrierConfigManager.KEY_CARRIER_SETTINGS_ACTIVITY_COMPONENT_NAME_STRING,
|
CarrierConfigManager.KEY_CARRIER_SETTINGS_ACTIVITY_COMPONENT_NAME_STRING,
|
||||||
CARRIER_SETTINGS_COMPONENT);
|
CARRIER_SETTINGS_COMPONENT);
|
||||||
doReturn(bundle).when(mCarrierConfigManager).getConfigForSubId(SUB_ID);
|
doReturn(bundle).when(mCarrierConfigCache).getConfigForSubId(SUB_ID);
|
||||||
PackageManager pm = Mockito.mock(PackageManager.class);
|
PackageManager pm = Mockito.mock(PackageManager.class);
|
||||||
doReturn(pm).when(mContext).getPackageManager();
|
doReturn(pm).when(mContext).getPackageManager();
|
||||||
doReturn(null).when(pm).resolveActivity(any(Intent.class), anyInt());
|
doReturn(null).when(pm).resolveActivity(any(Intent.class), anyInt());
|
||||||
@@ -162,7 +161,7 @@ public class CarrierPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void handlePreferenceClick_activityNotConfigured_DoNothing() {
|
public void handlePreferenceClick_activityNotConfigured_DoNothing() {
|
||||||
final PersistableBundle bundle = new PersistableBundle();
|
final PersistableBundle bundle = new PersistableBundle();
|
||||||
doReturn(bundle).when(mCarrierConfigManager).getConfigForSubId(SUB_ID);
|
doReturn(bundle).when(mCarrierConfigCache).getConfigForSubId(SUB_ID);
|
||||||
PackageManager pm = Mockito.mock(PackageManager.class);
|
PackageManager pm = Mockito.mock(PackageManager.class);
|
||||||
doReturn(pm).when(mContext).getPackageManager();
|
doReturn(pm).when(mContext).getPackageManager();
|
||||||
doReturn(new ResolveInfo()).when(pm).resolveActivity(any(Intent.class), anyInt());
|
doReturn(new ResolveInfo()).when(pm).resolveActivity(any(Intent.class), anyInt());
|
||||||
|
@@ -20,14 +20,16 @@ import static com.google.common.truth.Truth.assertThat;
|
|||||||
|
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.PersistableBundle;
|
import android.os.PersistableBundle;
|
||||||
import android.telephony.CarrierConfigManager;
|
import android.telephony.CarrierConfigManager;
|
||||||
|
|
||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
|
|
||||||
|
import com.android.settings.network.CarrierConfigCache;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@@ -37,7 +39,7 @@ import org.mockito.MockitoAnnotations;
|
|||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
public class CarrierSettingsVersionPreferenceControllerTest {
|
public class CarrierSettingsVersionPreferenceControllerTest {
|
||||||
@Mock
|
@Mock
|
||||||
private CarrierConfigManager mCarrierConfigManager;
|
private CarrierConfigCache mCarrierConfigCache;
|
||||||
|
|
||||||
private CarrierSettingsVersionPreferenceController mController;
|
private CarrierSettingsVersionPreferenceController mController;
|
||||||
private int mSubscriptionId = 1234;
|
private int mSubscriptionId = 1234;
|
||||||
@@ -46,21 +48,21 @@ public class CarrierSettingsVersionPreferenceControllerTest {
|
|||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
Context context = spy(ApplicationProvider.getApplicationContext());
|
Context context = spy(ApplicationProvider.getApplicationContext());
|
||||||
when(context.getSystemService(CarrierConfigManager.class)).thenReturn(mCarrierConfigManager);
|
CarrierConfigCache.setTestInstance(context, mCarrierConfigCache);
|
||||||
mController = new CarrierSettingsVersionPreferenceController(context, "mock_key");
|
mController = new CarrierSettingsVersionPreferenceController(context, "mock_key");
|
||||||
mController.init(mSubscriptionId);
|
mController.init(mSubscriptionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getSummary_nullConfig_noCrash() {
|
public void getSummary_nullConfig_noCrash() {
|
||||||
doReturn(null).when(mCarrierConfigManager).getConfigForSubId(mSubscriptionId);
|
doReturn(null).when(mCarrierConfigCache).getConfigForSubId(mSubscriptionId);
|
||||||
|
|
||||||
assertThat(mController.getSummary()).isNull();
|
assertThat(mController.getSummary()).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getSummary_nullVersionString_noCrash() {
|
public void getSummary_nullVersionString_noCrash() {
|
||||||
doReturn(new PersistableBundle()).when(mCarrierConfigManager)
|
doReturn(new PersistableBundle()).when(mCarrierConfigCache)
|
||||||
.getConfigForSubId(mSubscriptionId);
|
.getConfigForSubId(mSubscriptionId);
|
||||||
assertThat(mController.getSummary()).isNull();
|
assertThat(mController.getSummary()).isNull();
|
||||||
}
|
}
|
||||||
@@ -70,7 +72,7 @@ public class CarrierSettingsVersionPreferenceControllerTest {
|
|||||||
final PersistableBundle bundle = new PersistableBundle();
|
final PersistableBundle bundle = new PersistableBundle();
|
||||||
bundle.putString(CarrierConfigManager.KEY_CARRIER_CONFIG_VERSION_STRING,
|
bundle.putString(CarrierConfigManager.KEY_CARRIER_CONFIG_VERSION_STRING,
|
||||||
"test_version_123");
|
"test_version_123");
|
||||||
doReturn(bundle).when(mCarrierConfigManager).getConfigForSubId(mSubscriptionId);
|
doReturn(bundle).when(mCarrierConfigCache).getConfigForSubId(mSubscriptionId);
|
||||||
|
|
||||||
assertThat(mController.getSummary()).isEqualTo("test_version_123");
|
assertThat(mController.getSummary()).isEqualTo("test_version_123");
|
||||||
}
|
}
|
||||||
|
@@ -40,6 +40,7 @@ import androidx.preference.Preference;
|
|||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
|
|
||||||
|
import com.android.settings.network.CarrierConfigCache;
|
||||||
import com.android.settingslib.RestrictedPreference;
|
import com.android.settingslib.RestrictedPreference;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -60,7 +61,7 @@ public class DataServiceSetupPreferenceControllerTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private TelephonyManager mInvalidTelephonyManager;
|
private TelephonyManager mInvalidTelephonyManager;
|
||||||
@Mock
|
@Mock
|
||||||
private CarrierConfigManager mCarrierConfigManager;
|
private CarrierConfigCache mCarrierConfigCache;
|
||||||
|
|
||||||
private PersistableBundle mCarrierConfig;
|
private PersistableBundle mCarrierConfig;
|
||||||
private DataServiceSetupPreferenceController mController;
|
private DataServiceSetupPreferenceController mController;
|
||||||
@@ -73,7 +74,7 @@ public class DataServiceSetupPreferenceControllerTest {
|
|||||||
|
|
||||||
mContext = spy(ApplicationProvider.getApplicationContext());
|
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||||
when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
|
when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
|
||||||
when(mContext.getSystemService(CarrierConfigManager.class)).thenReturn(mCarrierConfigManager);
|
CarrierConfigCache.setTestInstance(mContext, mCarrierConfigCache);
|
||||||
doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(SUB_ID);
|
doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(SUB_ID);
|
||||||
doReturn(mInvalidTelephonyManager).when(mTelephonyManager).createForSubscriptionId(
|
doReturn(mInvalidTelephonyManager).when(mTelephonyManager).createForSubscriptionId(
|
||||||
SubscriptionManager.INVALID_SUBSCRIPTION_ID);
|
SubscriptionManager.INVALID_SUBSCRIPTION_ID);
|
||||||
@@ -81,7 +82,7 @@ public class DataServiceSetupPreferenceControllerTest {
|
|||||||
Settings.Global.SETUP_PREPAID_DATA_SERVICE_URL, SETUP_URL);
|
Settings.Global.SETUP_PREPAID_DATA_SERVICE_URL, SETUP_URL);
|
||||||
|
|
||||||
mCarrierConfig = new PersistableBundle();
|
mCarrierConfig = new PersistableBundle();
|
||||||
doReturn(mCarrierConfig).when(mCarrierConfigManager).getConfigForSubId(SUB_ID);
|
doReturn(mCarrierConfig).when(mCarrierConfigCache).getConfigForSubId(SUB_ID);
|
||||||
|
|
||||||
mPreference = new RestrictedPreference(mContext);
|
mPreference = new RestrictedPreference(mContext);
|
||||||
mController = new DataServiceSetupPreferenceController(mContext, "data_service_setup");
|
mController = new DataServiceSetupPreferenceController(mContext, "data_service_setup");
|
||||||
|
@@ -35,6 +35,8 @@ import android.telephony.TelephonyManager;
|
|||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
|
|
||||||
|
import com.android.settings.network.CarrierConfigCache;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@@ -46,7 +48,7 @@ public final class Enable2gPreferenceControllerTest {
|
|||||||
private static final int SUB_ID = 2;
|
private static final int SUB_ID = 2;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private CarrierConfigManager mCarrierConfigManager;
|
private CarrierConfigCache mCarrierConfigCache;
|
||||||
@Mock
|
@Mock
|
||||||
private TelephonyManager mTelephonyManager;
|
private TelephonyManager mTelephonyManager;
|
||||||
@Mock
|
@Mock
|
||||||
@@ -63,16 +65,15 @@ public final class Enable2gPreferenceControllerTest {
|
|||||||
mContext = spy(ApplicationProvider.getApplicationContext());
|
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||||
when(mContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager);
|
when(mContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager);
|
||||||
when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
|
when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
|
||||||
when(mContext.getSystemService(CarrierConfigManager.class))
|
CarrierConfigCache.setTestInstance(mContext, mCarrierConfigCache);
|
||||||
.thenReturn(mCarrierConfigManager);
|
|
||||||
|
|
||||||
doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(SUB_ID);
|
doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(SUB_ID);
|
||||||
doReturn(mInvalidTelephonyManager).when(mTelephonyManager).createForSubscriptionId(
|
doReturn(mInvalidTelephonyManager).when(mTelephonyManager).createForSubscriptionId(
|
||||||
SubscriptionManager.INVALID_SUBSCRIPTION_ID);
|
SubscriptionManager.INVALID_SUBSCRIPTION_ID);
|
||||||
|
|
||||||
mPersistableBundle = new PersistableBundle();
|
mPersistableBundle = new PersistableBundle();
|
||||||
doReturn(mPersistableBundle).when(mCarrierConfigManager).getConfigForSubId(SUB_ID);
|
doReturn(mPersistableBundle).when(mCarrierConfigCache).getConfigForSubId(SUB_ID);
|
||||||
doReturn(mPersistableBundle).when(mCarrierConfigManager).getConfigForSubId(
|
doReturn(mPersistableBundle).when(mCarrierConfigCache).getConfigForSubId(
|
||||||
SubscriptionManager.INVALID_SUBSCRIPTION_ID);
|
SubscriptionManager.INVALID_SUBSCRIPTION_ID);
|
||||||
mController = new Enable2gPreferenceController(mContext, "mobile_data");
|
mController = new Enable2gPreferenceController(mContext, "mobile_data");
|
||||||
mController.init(SUB_ID);
|
mController.init(SUB_ID);
|
||||||
@@ -99,7 +100,7 @@ public final class Enable2gPreferenceControllerTest {
|
|||||||
mTelephonyManager.CAPABILITY_USES_ALLOWED_NETWORK_TYPES_BITMASK);
|
mTelephonyManager.CAPABILITY_USES_ALLOWED_NETWORK_TYPES_BITMASK);
|
||||||
mPersistableBundle.putBoolean(CarrierConfigManager.KEY_HIDE_ENABLE_2G,
|
mPersistableBundle.putBoolean(CarrierConfigManager.KEY_HIDE_ENABLE_2G,
|
||||||
false);
|
false);
|
||||||
doReturn(null).when(mCarrierConfigManager);
|
doReturn(null).when(mCarrierConfigCache).getConfigForSubId(SUB_ID);
|
||||||
|
|
||||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
|
assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
|
||||||
}
|
}
|
||||||
|
@@ -35,6 +35,7 @@ import androidx.test.core.app.ApplicationProvider;
|
|||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
|
|
||||||
import com.android.settings.core.BasePreferenceController;
|
import com.android.settings.core.BasePreferenceController;
|
||||||
|
import com.android.settings.network.CarrierConfigCache;
|
||||||
import com.android.settings.network.ims.MockVolteQueryImsState;
|
import com.android.settings.network.ims.MockVolteQueryImsState;
|
||||||
import com.android.settingslib.RestrictedSwitchPreference;
|
import com.android.settingslib.RestrictedSwitchPreference;
|
||||||
|
|
||||||
@@ -55,7 +56,7 @@ public class Enhanced4gBasePreferenceControllerTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private SubscriptionManager mSubscriptionManager;
|
private SubscriptionManager mSubscriptionManager;
|
||||||
@Mock
|
@Mock
|
||||||
private CarrierConfigManager mCarrierConfigManager;
|
private CarrierConfigCache mCarrierConfigCache;
|
||||||
@Mock
|
@Mock
|
||||||
private ProvisioningManager mProvisioningManager;
|
private ProvisioningManager mProvisioningManager;
|
||||||
|
|
||||||
@@ -73,15 +74,14 @@ public class Enhanced4gBasePreferenceControllerTest {
|
|||||||
mContext = spy(ApplicationProvider.getApplicationContext());
|
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||||
when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
|
when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
|
||||||
when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager);
|
when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager);
|
||||||
when(mContext.getSystemService(CarrierConfigManager.class))
|
CarrierConfigCache.setTestInstance(mContext, mCarrierConfigCache);
|
||||||
.thenReturn(mCarrierConfigManager);
|
|
||||||
|
|
||||||
doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(SUB_ID);
|
doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(SUB_ID);
|
||||||
doReturn(mInvalidTelephonyManager).when(mTelephonyManager).createForSubscriptionId(
|
doReturn(mInvalidTelephonyManager).when(mTelephonyManager).createForSubscriptionId(
|
||||||
SubscriptionManager.INVALID_SUBSCRIPTION_ID);
|
SubscriptionManager.INVALID_SUBSCRIPTION_ID);
|
||||||
|
|
||||||
mCarrierConfig = new PersistableBundle();
|
mCarrierConfig = new PersistableBundle();
|
||||||
doReturn(mCarrierConfig).when(mCarrierConfigManager).getConfigForSubId(SUB_ID);
|
doReturn(mCarrierConfig).when(mCarrierConfigCache).getConfigForSubId(SUB_ID);
|
||||||
mCarrierConfig.putBoolean(CarrierConfigManager.KEY_HIDE_ENHANCED_4G_LTE_BOOL, false);
|
mCarrierConfig.putBoolean(CarrierConfigManager.KEY_HIDE_ENHANCED_4G_LTE_BOOL, false);
|
||||||
mCarrierConfig.putBoolean(CarrierConfigManager.KEY_EDITABLE_ENHANCED_4G_LTE_BOOL, true);
|
mCarrierConfig.putBoolean(CarrierConfigManager.KEY_EDITABLE_ENHANCED_4G_LTE_BOOL, true);
|
||||||
mCarrierConfig.putInt(CarrierConfigManager.KEY_ENHANCED_4G_LTE_TITLE_VARIANT_INT, 1);
|
mCarrierConfig.putInt(CarrierConfigManager.KEY_ENHANCED_4G_LTE_TITLE_VARIANT_INT, 1);
|
||||||
|
@@ -56,6 +56,7 @@ import android.telephony.TelephonyManager;
|
|||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
|
|
||||||
|
import com.android.settings.network.CarrierConfigCache;
|
||||||
import com.android.settings.network.ims.MockWfcQueryImsState;
|
import com.android.settings.network.ims.MockWfcQueryImsState;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -92,7 +93,7 @@ public class MobileNetworkUtilsTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private ResolveInfo mResolveInfo;
|
private ResolveInfo mResolveInfo;
|
||||||
@Mock
|
@Mock
|
||||||
private CarrierConfigManager mCarrierConfigManager;
|
private CarrierConfigCache mCarrierConfigCache;
|
||||||
@Mock
|
@Mock
|
||||||
private ConnectivityManager mConnectivityManager;
|
private ConnectivityManager mConnectivityManager;
|
||||||
@Mock
|
@Mock
|
||||||
@@ -117,11 +118,9 @@ public class MobileNetworkUtilsTest {
|
|||||||
when(mTelephonyManager.createForSubscriptionId(SUB_ID_2)).thenReturn(mTelephonyManager2);
|
when(mTelephonyManager.createForSubscriptionId(SUB_ID_2)).thenReturn(mTelephonyManager2);
|
||||||
when(mContext.getPackageManager()).thenReturn(mPackageManager);
|
when(mContext.getPackageManager()).thenReturn(mPackageManager);
|
||||||
|
|
||||||
when(mContext.getSystemService(CarrierConfigManager.class)).thenReturn(
|
CarrierConfigCache.setTestInstance(mContext, mCarrierConfigCache);
|
||||||
mCarrierConfigManager);
|
|
||||||
|
|
||||||
mCarrierConfig = new PersistableBundle();
|
mCarrierConfig = new PersistableBundle();
|
||||||
when(mCarrierConfigManager.getConfigForSubId(SUB_ID_1)).thenReturn(mCarrierConfig);
|
when(mCarrierConfigCache.getConfigForSubId(SUB_ID_1)).thenReturn(mCarrierConfig);
|
||||||
|
|
||||||
mNetwork = mock(Network.class, CALLS_REAL_METHODS);
|
mNetwork = mock(Network.class, CALLS_REAL_METHODS);
|
||||||
when(mContext.getSystemService(ConnectivityManager.class)).thenReturn(mConnectivityManager);
|
when(mContext.getSystemService(ConnectivityManager.class)).thenReturn(mConnectivityManager);
|
||||||
@@ -264,7 +263,7 @@ public class MobileNetworkUtilsTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldSpeciallyUpdateGsmCdma_supportTdscdma_returnFalse() {
|
public void shouldSpeciallyUpdateGsmCdma_supportTdscdma_returnFalse() {
|
||||||
when(mCarrierConfigManager.getConfig()).thenReturn(mCarrierConfig);
|
when(mCarrierConfigCache.getConfig()).thenReturn(mCarrierConfig);
|
||||||
mCarrierConfig.putBoolean(CarrierConfigManager.KEY_WORLD_MODE_ENABLED_BOOL, true);
|
mCarrierConfig.putBoolean(CarrierConfigManager.KEY_WORLD_MODE_ENABLED_BOOL, true);
|
||||||
mCarrierConfig.putBoolean(CarrierConfigManager.KEY_SUPPORT_TDSCDMA_BOOL, true);
|
mCarrierConfig.putBoolean(CarrierConfigManager.KEY_SUPPORT_TDSCDMA_BOOL, true);
|
||||||
|
|
||||||
|
@@ -28,10 +28,7 @@ import android.telephony.CarrierConfigManager;
|
|||||||
import android.telephony.SubscriptionInfo;
|
import android.telephony.SubscriptionInfo;
|
||||||
import android.telephony.SubscriptionManager;
|
import android.telephony.SubscriptionManager;
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
import android.util.FeatureFlagUtils;
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import androidx.preference.Preference;
|
|
||||||
import androidx.preference.PreferenceGroup;
|
import androidx.preference.PreferenceGroup;
|
||||||
import androidx.preference.PreferenceManager;
|
import androidx.preference.PreferenceManager;
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
@@ -39,8 +36,7 @@ import androidx.preference.SwitchPreference;
|
|||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
|
|
||||||
import com.android.settings.network.CarrierWifiTogglePreferenceController;
|
import com.android.settings.network.CarrierConfigCache;
|
||||||
import com.android.settings.testutils.ResourcesUtils;
|
|
||||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -65,7 +61,7 @@ public class NetworkProviderBackupCallingGroupTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private PreferenceGroup mPreferenceGroup;
|
private PreferenceGroup mPreferenceGroup;
|
||||||
@Mock
|
@Mock
|
||||||
private CarrierConfigManager mCarrierConfigManager;
|
private CarrierConfigCache mCarrierConfigCache;
|
||||||
@Mock
|
@Mock
|
||||||
private Lifecycle mLifecycle;
|
private Lifecycle mLifecycle;
|
||||||
@Mock
|
@Mock
|
||||||
@@ -112,11 +108,12 @@ public class NetworkProviderBackupCallingGroupTest {
|
|||||||
when(mSubscriptionManager.getActiveSubscriptionInfoList()).thenReturn(
|
when(mSubscriptionManager.getActiveSubscriptionInfoList()).thenReturn(
|
||||||
mSubscriptionInfoList);
|
mSubscriptionInfoList);
|
||||||
|
|
||||||
|
CarrierConfigCache.setTestInstance(mContext, mCarrierConfigCache);
|
||||||
mCarrierConfig = new PersistableBundle();
|
mCarrierConfig = new PersistableBundle();
|
||||||
doReturn(mCarrierConfig).when(mCarrierConfigManager).getConfigForSubId(SUB_ID_1);
|
doReturn(mCarrierConfig).when(mCarrierConfigCache).getConfigForSubId(SUB_ID_1);
|
||||||
mCarrierConfig.putBoolean(CarrierConfigManager.KEY_CARRIER_CROSS_SIM_IMS_AVAILABLE_BOOL,
|
mCarrierConfig.putBoolean(CarrierConfigManager.KEY_CARRIER_CROSS_SIM_IMS_AVAILABLE_BOOL,
|
||||||
true);
|
true);
|
||||||
doReturn(mCarrierConfig).when(mCarrierConfigManager).getConfigForSubId(SUB_ID_2);
|
doReturn(mCarrierConfig).when(mCarrierConfigCache).getConfigForSubId(SUB_ID_2);
|
||||||
mCarrierConfig.putBoolean(CarrierConfigManager.KEY_CARRIER_CROSS_SIM_IMS_AVAILABLE_BOOL,
|
mCarrierConfig.putBoolean(CarrierConfigManager.KEY_CARRIER_CROSS_SIM_IMS_AVAILABLE_BOOL,
|
||||||
true);
|
true);
|
||||||
|
|
||||||
|
@@ -34,6 +34,7 @@ import androidx.test.core.app.ApplicationProvider;
|
|||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
|
|
||||||
import com.android.settings.core.BasePreferenceController;
|
import com.android.settings.core.BasePreferenceController;
|
||||||
|
import com.android.settings.network.CarrierConfigCache;
|
||||||
import com.android.settingslib.RestrictedSwitchPreference;
|
import com.android.settingslib.RestrictedSwitchPreference;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -53,7 +54,7 @@ public class NrAdvancedCallingPreferenceControllerTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private SubscriptionManager mSubscriptionManager;
|
private SubscriptionManager mSubscriptionManager;
|
||||||
@Mock
|
@Mock
|
||||||
private CarrierConfigManager mCarrierConfigManager;
|
private CarrierConfigCache mCarrierConfigCache;
|
||||||
|
|
||||||
private NrAdvancedCallingPreferenceController mController;
|
private NrAdvancedCallingPreferenceController mController;
|
||||||
private SwitchPreference mPreference;
|
private SwitchPreference mPreference;
|
||||||
@@ -67,8 +68,7 @@ public class NrAdvancedCallingPreferenceControllerTest {
|
|||||||
mContext = spy(ApplicationProvider.getApplicationContext());
|
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||||
when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
|
when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
|
||||||
when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager);
|
when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager);
|
||||||
when(mContext.getSystemService(CarrierConfigManager.class))
|
CarrierConfigCache.setTestInstance(mContext, mCarrierConfigCache);
|
||||||
.thenReturn(mCarrierConfigManager);
|
|
||||||
|
|
||||||
doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(SUB_ID);
|
doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(SUB_ID);
|
||||||
doReturn(mInvalidTelephonyManager).when(mTelephonyManager).createForSubscriptionId(
|
doReturn(mInvalidTelephonyManager).when(mTelephonyManager).createForSubscriptionId(
|
||||||
@@ -79,7 +79,7 @@ public class NrAdvancedCallingPreferenceControllerTest {
|
|||||||
doReturn(TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED).when(
|
doReturn(TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED).when(
|
||||||
mTelephonyManager).setVoNrEnabled(anyBoolean());
|
mTelephonyManager).setVoNrEnabled(anyBoolean());
|
||||||
mCarrierConfig = new PersistableBundle();
|
mCarrierConfig = new PersistableBundle();
|
||||||
doReturn(mCarrierConfig).when(mCarrierConfigManager).getConfigForSubId(SUB_ID);
|
doReturn(mCarrierConfig).when(mCarrierConfigCache).getConfigForSubId(SUB_ID);
|
||||||
mCarrierConfig.putBoolean(CarrierConfigManager.KEY_VONR_ENABLED_BOOL, false);
|
mCarrierConfig.putBoolean(CarrierConfigManager.KEY_VONR_ENABLED_BOOL, false);
|
||||||
mCarrierConfig.putBoolean(CarrierConfigManager.KEY_VONR_SETTING_VISIBILITY_BOOL, true);
|
mCarrierConfig.putBoolean(CarrierConfigManager.KEY_VONR_SETTING_VISIBILITY_BOOL, true);
|
||||||
mCarrierConfig.putIntArray(CarrierConfigManager.KEY_CARRIER_NR_AVAILABILITIES_INT_ARRAY,
|
mCarrierConfig.putIntArray(CarrierConfigManager.KEY_CARRIER_NR_AVAILABILITIES_INT_ARRAY,
|
||||||
|
@@ -41,6 +41,7 @@ import androidx.preference.ListPreference;
|
|||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
|
|
||||||
|
import com.android.settings.network.CarrierConfigCache;
|
||||||
import com.android.settings.network.telephony.TelephonyConstants.TelephonyManagerConstants;
|
import com.android.settings.network.telephony.TelephonyConstants.TelephonyManagerConstants;
|
||||||
import com.android.settings.testutils.ResourcesUtils;
|
import com.android.settings.testutils.ResourcesUtils;
|
||||||
|
|
||||||
@@ -59,7 +60,7 @@ public class PreferredNetworkModePreferenceControllerTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private TelephonyManager mInvalidTelephonyManager;
|
private TelephonyManager mInvalidTelephonyManager;
|
||||||
@Mock
|
@Mock
|
||||||
private CarrierConfigManager mCarrierConfigManager;
|
private CarrierConfigCache mCarrierConfigCache;
|
||||||
@Mock
|
@Mock
|
||||||
private ServiceState mServiceState;
|
private ServiceState mServiceState;
|
||||||
|
|
||||||
@@ -75,15 +76,14 @@ public class PreferredNetworkModePreferenceControllerTest {
|
|||||||
mContext = spy(ApplicationProvider.getApplicationContext());
|
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||||
when(mContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager);
|
when(mContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager);
|
||||||
when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
|
when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
|
||||||
when(mContext.getSystemService(CarrierConfigManager.class)).thenReturn(
|
CarrierConfigCache.setTestInstance(mContext, mCarrierConfigCache);
|
||||||
mCarrierConfigManager);
|
|
||||||
|
|
||||||
doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(SUB_ID);
|
doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(SUB_ID);
|
||||||
doReturn(mInvalidTelephonyManager).when(mTelephonyManager).createForSubscriptionId(
|
doReturn(mInvalidTelephonyManager).when(mTelephonyManager).createForSubscriptionId(
|
||||||
SubscriptionManager.INVALID_SUBSCRIPTION_ID);
|
SubscriptionManager.INVALID_SUBSCRIPTION_ID);
|
||||||
doReturn(mServiceState).when(mTelephonyManager).getServiceState();
|
doReturn(mServiceState).when(mTelephonyManager).getServiceState();
|
||||||
mPersistableBundle = new PersistableBundle();
|
mPersistableBundle = new PersistableBundle();
|
||||||
doReturn(mPersistableBundle).when(mCarrierConfigManager).getConfigForSubId(SUB_ID);
|
doReturn(mPersistableBundle).when(mCarrierConfigCache).getConfigForSubId(SUB_ID);
|
||||||
|
|
||||||
mPreference = new ListPreference(mContext);
|
mPreference = new ListPreference(mContext);
|
||||||
mController = new PreferredNetworkModePreferenceController(mContext, "mobile_data");
|
mController = new PreferredNetworkModePreferenceController(mContext, "mobile_data");
|
||||||
|
@@ -36,6 +36,7 @@ import androidx.preference.SwitchPreference;
|
|||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
|
|
||||||
|
import com.android.settings.network.CarrierConfigCache;
|
||||||
import com.android.settings.testutils.ResourcesUtils;
|
import com.android.settings.testutils.ResourcesUtils;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -58,7 +59,7 @@ public class AutoSelectPreferenceControllerTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private SubscriptionManager mSubscriptionManager;
|
private SubscriptionManager mSubscriptionManager;
|
||||||
@Mock
|
@Mock
|
||||||
private CarrierConfigManager mCarrierConfigManager;
|
private CarrierConfigCache mCarrierConfigCache;
|
||||||
@Mock
|
@Mock
|
||||||
private ProgressDialog mProgressDialog;
|
private ProgressDialog mProgressDialog;
|
||||||
@Mock
|
@Mock
|
||||||
@@ -78,14 +79,13 @@ public class AutoSelectPreferenceControllerTest {
|
|||||||
|
|
||||||
when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
|
when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
|
||||||
when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager);
|
when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager);
|
||||||
when(mContext.getSystemService(CarrierConfigManager.class)).thenReturn(
|
CarrierConfigCache.setTestInstance(mContext, mCarrierConfigCache);
|
||||||
mCarrierConfigManager);
|
|
||||||
when(mTelephonyManager.createForSubscriptionId(SUB_ID)).thenReturn(mTelephonyManager);
|
when(mTelephonyManager.createForSubscriptionId(SUB_ID)).thenReturn(mTelephonyManager);
|
||||||
|
|
||||||
mCarrierConfig = new PersistableBundle();
|
mCarrierConfig = new PersistableBundle();
|
||||||
mCarrierConfig.putBoolean(CarrierConfigManager.KEY_ONLY_AUTO_SELECT_IN_HOME_NETWORK_BOOL,
|
mCarrierConfig.putBoolean(CarrierConfigManager.KEY_ONLY_AUTO_SELECT_IN_HOME_NETWORK_BOOL,
|
||||||
true);
|
true);
|
||||||
when(mCarrierConfigManager.getConfigForSubId(SUB_ID)).thenReturn(mCarrierConfig);
|
when(mCarrierConfigCache.getConfigForSubId(SUB_ID)).thenReturn(mCarrierConfig);
|
||||||
|
|
||||||
mSwitchPreference = new SwitchPreference(mContext);
|
mSwitchPreference = new SwitchPreference(mContext);
|
||||||
mController = new AutoSelectPreferenceController(mContext, "auto_select");
|
mController = new AutoSelectPreferenceController(mContext, "auto_select");
|
||||||
@@ -136,7 +136,7 @@ public class AutoSelectPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void init_carrierConfigNull_shouldNotCrash() {
|
public void init_carrierConfigNull_shouldNotCrash() {
|
||||||
when(mCarrierConfigManager.getConfigForSubId(SUB_ID)).thenReturn(null);
|
when(mCarrierConfigCache.getConfigForSubId(SUB_ID)).thenReturn(null);
|
||||||
|
|
||||||
// Should not crash
|
// Should not crash
|
||||||
mController.init(mLifecycle, SUB_ID);
|
mController.init(mLifecycle, SUB_ID);
|
||||||
|
@@ -37,6 +37,7 @@ import androidx.lifecycle.Lifecycle;
|
|||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
|
|
||||||
|
import com.android.settings.network.CarrierConfigCache;
|
||||||
import com.android.settings.testutils.FakeFeatureFactory;
|
import com.android.settings.testutils.FakeFeatureFactory;
|
||||||
import com.android.wifitrackerlib.MergedCarrierEntry;
|
import com.android.wifitrackerlib.MergedCarrierEntry;
|
||||||
import com.android.wifitrackerlib.WifiEntry;
|
import com.android.wifitrackerlib.WifiEntry;
|
||||||
@@ -60,7 +61,7 @@ public class WifiPickerTrackerHelperTest {
|
|||||||
@Mock
|
@Mock
|
||||||
public WifiManager mWifiManager;
|
public WifiManager mWifiManager;
|
||||||
@Mock
|
@Mock
|
||||||
public CarrierConfigManager mCarrierConfigManager;
|
public CarrierConfigCache mCarrierConfigCache;
|
||||||
@Mock
|
@Mock
|
||||||
public WifiPickerTracker mWifiPickerTracker;
|
public WifiPickerTracker mWifiPickerTracker;
|
||||||
@Mock
|
@Mock
|
||||||
@@ -77,10 +78,9 @@ public class WifiPickerTrackerHelperTest {
|
|||||||
public void setUp() {
|
public void setUp() {
|
||||||
final Context context = spy(ApplicationProvider.getApplicationContext());
|
final Context context = spy(ApplicationProvider.getApplicationContext());
|
||||||
when(context.getSystemService(WifiManager.class)).thenReturn(mWifiManager);
|
when(context.getSystemService(WifiManager.class)).thenReturn(mWifiManager);
|
||||||
when(context.getSystemService(CarrierConfigManager.class))
|
|
||||||
.thenReturn(mCarrierConfigManager);
|
|
||||||
mCarrierConfig = new PersistableBundle();
|
mCarrierConfig = new PersistableBundle();
|
||||||
doReturn(mCarrierConfig).when(mCarrierConfigManager).getConfigForSubId(SUB_ID);
|
when(mCarrierConfigCache.getConfigForSubId(SUB_ID)).thenReturn(mCarrierConfig);
|
||||||
|
CarrierConfigCache.setTestInstance(context, mCarrierConfigCache);
|
||||||
|
|
||||||
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||||
when(mFeatureFactory.wifiTrackerLibProvider
|
when(mFeatureFactory.wifiTrackerLibProvider
|
||||||
@@ -108,7 +108,7 @@ public class WifiPickerTrackerHelperTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isCarrierNetworkProvisionEnabled_getNullConfig_returnFalse() {
|
public void isCarrierNetworkProvisionEnabled_getNullConfig_returnFalse() {
|
||||||
doReturn(null).when(mCarrierConfigManager).getConfigForSubId(SUB_ID);
|
when(mCarrierConfigCache.getConfigForSubId(SUB_ID)).thenReturn(null);
|
||||||
|
|
||||||
assertThat(mWifiPickerTrackerHelper.isCarrierNetworkProvisionEnabled(SUB_ID)).isFalse();
|
assertThat(mWifiPickerTrackerHelper.isCarrierNetworkProvisionEnabled(SUB_ID)).isFalse();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user