--- /dev/null
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.network.telephony;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.os.PersistableBundle;
+import android.provider.Settings;
+import android.telephony.CarrierConfigManager;
+import android.telephony.ServiceState;
+import android.telephony.SubscriptionManager;
+import android.telephony.TelephonyManager;
+
+import androidx.annotation.VisibleForTesting;
+import androidx.preference.ListPreference;
+import androidx.preference.Preference;
+
+import com.android.internal.telephony.Phone;
+import com.android.internal.telephony.PhoneConstants;
+import com.android.settings.R;
+import com.android.settings.core.BasePreferenceController;
+
+/**
+ * Preference controller for "Enabled network mode"
+ */
+public class EnabledNetworkModePreferenceController extends BasePreferenceController implements
+ ListPreference.OnPreferenceChangeListener {
+
+ private CarrierConfigManager mCarrierConfigManager;
+ private TelephonyManager mTelephonyManager;
+ private PersistableBundle mPersistableBundle;
+ private int mSubId;
+ private boolean mIsGlobalCdma;
+ private boolean mShow4GForLTE;
+
+ public EnabledNetworkModePreferenceController(Context context, String key) {
+ super(context, key);
+ mCarrierConfigManager = context.getSystemService(CarrierConfigManager.class);
+ mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ boolean visible;
+ if (mSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
+ visible = false;
+ } else if (mPersistableBundle == null) {
+ visible = false;
+ } else if (mPersistableBundle.getBoolean(
+ CarrierConfigManager.KEY_HIDE_CARRIER_NETWORK_SETTINGS_BOOL)) {
+ visible = false;
+ } else if (mPersistableBundle.getBoolean(
+ CarrierConfigManager.KEY_HIDE_PREFERRED_NETWORK_TYPE_BOOL)
+ && !mTelephonyManager.getServiceState().getRoaming()
+ && mTelephonyManager.getServiceState().getDataRegState()
+ == ServiceState.STATE_IN_SERVICE) {
+ visible = false;
+ } else if (mPersistableBundle.getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL)) {
+ visible = false;
+ } else {
+ visible = true;
+ }
+
+ return visible ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ super.updateState(preference);
+ final ListPreference listPreference = (ListPreference) preference;
+ final int networkMode = getPreferredNetworkMode();
+ updatePreferenceEntries(listPreference);
+ updatePreferenceValueAndSummary(listPreference, networkMode);
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object object) {
+ final int settingsMode = Integer.parseInt((String) object);
+
+ if (mTelephonyManager.setPreferredNetworkType(mSubId, settingsMode)) {
+ Settings.Global.putInt(mContext.getContentResolver(),
+ Settings.Global.PREFERRED_NETWORK_MODE + mSubId,
+ settingsMode);
+ updatePreferenceValueAndSummary((ListPreference) preference, settingsMode);
+ return true;
+ }
+
+ return false;
+ }
+
+ public void init(int subId) {
+ mSubId = subId;
+ mPersistableBundle = mCarrierConfigManager.getConfigForSubId(mSubId);
+ mTelephonyManager = TelephonyManager.from(mContext).createForSubscriptionId(mSubId);
+
+ final boolean isLteOnCdma =
+ mTelephonyManager.getLteOnCdmaMode() == PhoneConstants.LTE_ON_CDMA_TRUE;
+ mIsGlobalCdma = isLteOnCdma
+ && mPersistableBundle.getBoolean(CarrierConfigManager.KEY_SHOW_CDMA_CHOICES_BOOL);
+ initShow4GForLTE();
+ }
+
+ @VisibleForTesting
+ void initShow4GForLTE() {
+ mShow4GForLTE = MobileNetworkUtils.isShow4GForLTE(mContext);
+ }
+
+ private int getPreferredNetworkMode() {
+ return Settings.Global.getInt(mContext.getContentResolver(),
+ Settings.Global.PREFERRED_NETWORK_MODE + mSubId,
+ Phone.PREFERRED_NT_MODE);
+ }
+
+ private void updatePreferenceEntries(ListPreference preference) {
+ final int phoneType = mTelephonyManager.getPhoneType();
+ final Resources resources = mContext.getResources();
+ final PersistableBundle carrierConfig = mCarrierConfigManager.getConfigForSubId(mSubId);
+ if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
+ final int lteForced = android.provider.Settings.Global.getInt(
+ mContext.getContentResolver(),
+ android.provider.Settings.Global.LTE_SERVICE_FORCED + mSubId,
+ 0);
+ final boolean isLteOnCdma = mTelephonyManager.getLteOnCdmaMode()
+ == PhoneConstants.LTE_ON_CDMA_TRUE;
+ final int settingsNetworkMode = android.provider.Settings.Global.getInt(
+ mContext.getContentResolver(),
+ android.provider.Settings.Global.PREFERRED_NETWORK_MODE + mSubId,
+ Phone.PREFERRED_NT_MODE);
+ if (isLteOnCdma) {
+ if (lteForced == 0) {
+ preference.setEntries(
+ R.array.enabled_networks_cdma_choices);
+ preference.setEntryValues(
+ R.array.enabled_networks_cdma_values);
+ } else {
+ switch (settingsNetworkMode) {
+ case TelephonyManager.NETWORK_MODE_CDMA_EVDO:
+ case TelephonyManager.NETWORK_MODE_CDMA_NO_EVDO:
+ case TelephonyManager.NETWORK_MODE_EVDO_NO_CDMA:
+ preference.setEntries(
+ R.array.enabled_networks_cdma_no_lte_choices);
+ preference.setEntryValues(
+ R.array.enabled_networks_cdma_no_lte_values);
+ break;
+ case TelephonyManager.NETWORK_MODE_GLOBAL:
+ case TelephonyManager.NETWORK_MODE_LTE_CDMA_EVDO:
+ case TelephonyManager.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA:
+ case TelephonyManager.NETWORK_MODE_LTE_ONLY:
+ preference.setEntries(
+ R.array.enabled_networks_cdma_only_lte_choices);
+ preference.setEntryValues(
+ R.array.enabled_networks_cdma_only_lte_values);
+ break;
+ default:
+ preference.setEntries(
+ R.array.enabled_networks_cdma_choices);
+ preference.setEntryValues(
+ R.array.enabled_networks_cdma_values);
+ break;
+ }
+ }
+ }
+ } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
+ if (MobileNetworkUtils.isTdscdmaSupported(mContext, mSubId)) {
+ preference.setEntries(
+ R.array.enabled_networks_tdscdma_choices);
+ preference.setEntryValues(
+ R.array.enabled_networks_tdscdma_values);
+ } else if (!carrierConfig.getBoolean(CarrierConfigManager.KEY_PREFER_2G_BOOL)
+ && !resources.getBoolean(R.bool.config_enabled_lte)) {
+ preference.setEntries(R.array.enabled_networks_except_gsm_lte_choices);
+ preference.setEntryValues(R.array.enabled_networks_except_gsm_lte_values);
+ } else if (!carrierConfig.getBoolean(CarrierConfigManager.KEY_PREFER_2G_BOOL)) {
+ int select = mShow4GForLTE
+ ? R.array.enabled_networks_except_gsm_4g_choices
+ : R.array.enabled_networks_except_gsm_choices;
+ preference.setEntries(select);
+ preference.setEntryValues(
+ R.array.enabled_networks_except_gsm_values);
+ } else if (!resources.getBoolean(R.bool.config_enabled_lte)) {
+ preference.setEntries(
+ R.array.enabled_networks_except_lte_choices);
+ preference.setEntryValues(
+ R.array.enabled_networks_except_lte_values);
+ } else if (mIsGlobalCdma) {
+ preference.setEntries(R.array.enabled_networks_cdma_choices);
+ preference.setEntryValues(R.array.enabled_networks_cdma_values);
+ } else {
+ int select = mShow4GForLTE ? R.array.enabled_networks_4g_choices
+ : R.array.enabled_networks_choices;
+ preference.setEntries(select);
+ preference.setEntryValues(R.array.enabled_networks_values);
+ }
+ }
+ //TODO(b/117881708): figure out what world mode is, then we can optimize code. Otherwise
+ // I prefer to keep this old code
+ if (MobileNetworkUtils.isWorldMode(mContext, mSubId)) {
+ preference.setEntries(
+ R.array.preferred_network_mode_choices_world_mode);
+ preference.setEntryValues(
+ R.array.preferred_network_mode_values_world_mode);
+ }
+ }
+
+ private void updatePreferenceValueAndSummary(ListPreference preference, int networkMode) {
+ switch (networkMode) {
+ case TelephonyManager.NETWORK_MODE_TDSCDMA_WCDMA:
+ case TelephonyManager.NETWORK_MODE_TDSCDMA_GSM_WCDMA:
+ case TelephonyManager.NETWORK_MODE_TDSCDMA_GSM:
+ preference.setValue(
+ Integer.toString(TelephonyManager.NETWORK_MODE_TDSCDMA_GSM_WCDMA));
+ preference.setSummary(R.string.network_3G);
+ break;
+ case TelephonyManager.NETWORK_MODE_WCDMA_ONLY:
+ case TelephonyManager.NETWORK_MODE_GSM_UMTS:
+ case TelephonyManager.NETWORK_MODE_WCDMA_PREF:
+ if (!mIsGlobalCdma) {
+ preference.setValue(Integer.toString(TelephonyManager.NETWORK_MODE_WCDMA_PREF));
+ preference.setSummary(R.string.network_3G);
+ } else {
+ preference.setValue(Integer.toString(TelephonyManager
+ .NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA));
+ preference.setSummary(R.string.network_global);
+ }
+ break;
+ case TelephonyManager.NETWORK_MODE_GSM_ONLY:
+ if (!mIsGlobalCdma) {
+ preference.setValue(
+ Integer.toString(TelephonyManager.NETWORK_MODE_GSM_ONLY));
+ preference.setSummary(R.string.network_2G);
+ } else {
+ preference.setValue(
+ Integer.toString(TelephonyManager
+ .NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA));
+ preference.setSummary(R.string.network_global);
+ }
+ break;
+ case TelephonyManager.NETWORK_MODE_LTE_GSM_WCDMA:
+ if (MobileNetworkUtils.isWorldMode(mContext, mSubId)) {
+ preference.setSummary(
+ R.string.preferred_network_mode_lte_gsm_umts_summary);
+ break;
+ }
+ case TelephonyManager.NETWORK_MODE_LTE_ONLY:
+ case TelephonyManager.NETWORK_MODE_LTE_WCDMA:
+ if (!mIsGlobalCdma) {
+ preference.setValue(
+ Integer.toString(TelephonyManager.NETWORK_MODE_LTE_GSM_WCDMA));
+ preference.setSummary(
+ mShow4GForLTE ? R.string.network_4G : R.string.network_lte);
+ } else {
+ preference.setValue(
+ Integer.toString(TelephonyManager
+ .NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA));
+ preference.setSummary(R.string.network_global);
+ }
+ break;
+ case TelephonyManager.NETWORK_MODE_LTE_CDMA_EVDO:
+ if (MobileNetworkUtils.isWorldMode(mContext, mSubId)) {
+ preference.setSummary(
+ R.string.preferred_network_mode_lte_cdma_summary);
+ } else {
+ preference.setValue(
+ Integer.toString(TelephonyManager.NETWORK_MODE_LTE_CDMA_EVDO));
+ preference.setSummary(R.string.network_lte);
+ }
+ break;
+ case TelephonyManager.NETWORK_MODE_TDSCDMA_CDMA_EVDO_GSM_WCDMA:
+ preference.setValue(Integer.toString(TelephonyManager
+ .NETWORK_MODE_TDSCDMA_CDMA_EVDO_GSM_WCDMA));
+ preference.setSummary(R.string.network_3G);
+ break;
+ case TelephonyManager.NETWORK_MODE_CDMA_EVDO:
+ case TelephonyManager.NETWORK_MODE_EVDO_NO_CDMA:
+ case TelephonyManager.NETWORK_MODE_GLOBAL:
+ preference.setValue(
+ Integer.toString(TelephonyManager.NETWORK_MODE_CDMA_EVDO));
+ preference.setSummary(R.string.network_3G);
+ break;
+ case TelephonyManager.NETWORK_MODE_CDMA_NO_EVDO:
+ preference.setValue(
+ Integer.toString(TelephonyManager.NETWORK_MODE_CDMA_NO_EVDO));
+ preference.setSummary(R.string.network_1x);
+ break;
+ case TelephonyManager.NETWORK_MODE_TDSCDMA_ONLY:
+ preference.setValue(
+ Integer.toString(TelephonyManager.NETWORK_MODE_TDSCDMA_ONLY));
+ preference.setSummary(R.string.network_3G);
+ break;
+ case TelephonyManager.NETWORK_MODE_LTE_TDSCDMA_GSM:
+ case TelephonyManager.NETWORK_MODE_LTE_TDSCDMA_GSM_WCDMA:
+ case TelephonyManager.NETWORK_MODE_LTE_TDSCDMA:
+ case TelephonyManager.NETWORK_MODE_LTE_TDSCDMA_WCDMA:
+ case TelephonyManager.NETWORK_MODE_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA:
+ case TelephonyManager.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA:
+ if (MobileNetworkUtils.isTdscdmaSupported(mContext, mSubId)) {
+ preference.setValue(
+ Integer.toString(TelephonyManager
+ .NETWORK_MODE_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA));
+ preference.setSummary(R.string.network_lte);
+ } else {
+ preference.setValue(
+ Integer.toString(TelephonyManager
+ .NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA));
+ if (mTelephonyManager.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA
+ || mIsGlobalCdma
+ || MobileNetworkUtils.isWorldMode(mContext, mSubId)) {
+ preference.setSummary(R.string.network_global);
+ } else {
+ preference.setSummary(mShow4GForLTE
+ ? R.string.network_4G : R.string.network_lte);
+ }
+ }
+ break;
+ default:
+ preference.setSummary(
+ mContext.getString(R.string.mobile_network_mode_error, networkMode));
+ }
+ }
+}
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
-import android.os.Handler;
import android.os.Message;
import android.os.PersistableBundle;
import android.os.UserManager;
import android.view.MenuItem;
import androidx.fragment.app.FragmentActivity;
-import androidx.preference.ListPreference;
import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceFragmentCompat;
private int mSubId;
//UI objects
- private ListPreference mButtonEnabledNetworks;
private SwitchPreference mButton4glte;
private Preference mLteDataServicePref;
private Preference mEuiccSettingsPref;
private UserManager mUm;
private ImsManager mImsMgr;
- private MyHandler mHandler;
private boolean mOkClicked;
//GsmUmts options and Cdma options
android.util.Log.e(LOG_TAG, "Missing SETUP_PREPAID_DATA_SERVICE_URL");
}
return true;
- } else if (preference == mButtonEnabledNetworks) {
- int settingsNetworkMode = android.provider.Settings.Global.getInt(
- getContext().getContentResolver(),
- android.provider.Settings.Global.PREFERRED_NETWORK_MODE + mSubId,
- preferredNetworkMode);
- mButtonEnabledNetworks.setValue(Integer.toString(settingsNetworkMode));
- return true;
} else if (preference == mEuiccSettingsPref) {
Intent intent = new Intent(EuiccManager.ACTION_MANAGE_EMBEDDED_SUBSCRIPTIONS);
startActivity(intent);
use(CarrierPreferenceController.class).init(mSubId);
use(DataUsagePreferenceController.class).init(mSubId);
use(PreferredNetworkModePreferenceController.class).init(mSubId);
+ use(EnabledNetworkModePreferenceController.class).init(mSubId);
mCdmaSystemSelectPreferenceController = use(CdmaSystemSelectPreferenceController.class);
mCdmaSystemSelectPreferenceController.init(getPreferenceManager(), mSubId);
return;
}
- mHandler = new MyHandler();
mUm = (UserManager) context.getSystemService(Context.USER_SERVICE);
mSubscriptionManager = SubscriptionManager.from(context);
mTelephonyManager = (TelephonyManager) context.getSystemService(
//get UI object references
PreferenceScreen prefSet = getPreferenceScreen();
- mButtonEnabledNetworks = (ListPreference) prefSet.findPreference(
- BUTTON_ENABLED_NETWORKS_KEY);
mLteDataServicePref = prefSet.findPreference(BUTTON_CDMA_LTE_DATA_SERVICE_KEY);
mActiveSubInfos = mSubscriptionManager.getActiveSubscriptionInfoList();
updatePhone();
- if (hasActiveSubscriptions()) {
- updateEnabledNetworksEntries();
- }
Log.i(LOG_TAG, "onCreate:-");
}
// preferences.
getPreferenceScreen().setEnabled(true);
- if (getPreferenceScreen().findPreference(BUTTON_PREFERED_NETWORK_MODE) != null
- || getPreferenceScreen().findPreference(BUTTON_ENABLED_NETWORKS_KEY) != null) {
- updatePreferredNetworkUIFromDb();
- }
-
mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
// NOTE: Buttons will be enabled/disabled in mPhoneStateListener
if (DBG) {
log("updateBody: isLteOnCdma=" + isLteOnCdma + " phoneSubId=" + phoneSubId);
}
- prefSet.addPreference(mButtonEnabledNetworks);
prefSet.addPreference(mButton4glte);
if (MobileNetworkUtils.showEuiccSettings(getContext())) {
&& carrierConfig.getBoolean(CarrierConfigManager.KEY_SHOW_CDMA_CHOICES_BOOL);
if (carrierConfig.getBoolean(
CarrierConfigManager.KEY_HIDE_CARRIER_NETWORK_SETTINGS_BOOL)) {
- prefSet.removePreference(mButtonEnabledNetworks);
prefSet.removePreference(mLteDataServicePref);
} else if (carrierConfig.getBoolean(CarrierConfigManager
.KEY_HIDE_PREFERRED_NETWORK_TYPE_BOOL)
&& !mTelephonyManager.getServiceState().getRoaming()
&& mTelephonyManager.getServiceState().getDataRegState()
== ServiceState.STATE_IN_SERVICE) {
- prefSet.removePreference(mButtonEnabledNetworks);
final int phoneType = mTelephonyManager.getPhoneType();
if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
settingsNetworkMode = preferredNetworkMode;
} else if (carrierConfig.getBoolean(
CarrierConfigManager.KEY_WORLD_PHONE_BOOL) == true) {
- prefSet.removePreference(mButtonEnabledNetworks);
// set the listener for the mButtonPreferredNetworkMode list preference so we can issue
// change Preferred Network Mode.
updateCdmaOptions(this, prefSet, mSubId);
updateGsmUmtsOptions(this, prefSet, phoneSubId);
- } else {
- updateEnabledNetworksEntries();
- mButtonEnabledNetworks.setOnPreferenceChangeListener(this);
- if (DBG) log("settingsNetworkMode: " + settingsNetworkMode);
}
final boolean missingDataServiceUrl = TextUtils.isEmpty(
}
}
- // Get the networkMode from Settings.System and displays it
- mButtonEnabledNetworks.setValue(Integer.toString(settingsNetworkMode));
- UpdateEnabledNetworksValueAndSummary(settingsNetworkMode);
- // Display preferred network type based on what modem returns b/18676277
- new SetPreferredNetworkAsyncTask(
- mTelephonyManager,
- mSubId,
- settingsNetworkMode,
- mHandler.obtainMessage(MyHandler.MESSAGE_SET_PREFERRED_NETWORK_TYPE))
- .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
-
/**
* Enable/disable depending upon if there are any active subscriptions.
*
}
}
- // Requires that mSubId is up to date
- void updateEnabledNetworksEntries() {
- final int phoneType = mTelephonyManager.getPhoneType();
- final PersistableBundle carrierConfig = mCarrierConfigManager.getConfigForSubId(mSubId);
- if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
- final int lteForced = android.provider.Settings.Global.getInt(
- getContext().getContentResolver(),
- android.provider.Settings.Global.LTE_SERVICE_FORCED + mSubId,
- 0);
- final boolean isLteOnCdma = mTelephonyManager.getLteOnCdmaMode()
- == PhoneConstants.LTE_ON_CDMA_TRUE;
- final int settingsNetworkMode = android.provider.Settings.Global.getInt(
- getContext().getContentResolver(),
- android.provider.Settings.Global.PREFERRED_NETWORK_MODE + mSubId,
- preferredNetworkMode);
- if (isLteOnCdma) {
- if (lteForced == 0) {
- mButtonEnabledNetworks.setEntries(
- R.array.enabled_networks_cdma_choices);
- mButtonEnabledNetworks.setEntryValues(
- R.array.enabled_networks_cdma_values);
- } else {
- switch (settingsNetworkMode) {
- case TelephonyManager.NETWORK_MODE_CDMA_EVDO:
- case TelephonyManager.NETWORK_MODE_CDMA_NO_EVDO:
- case TelephonyManager.NETWORK_MODE_EVDO_NO_CDMA:
- mButtonEnabledNetworks.setEntries(
- R.array.enabled_networks_cdma_no_lte_choices);
- mButtonEnabledNetworks.setEntryValues(
- R.array.enabled_networks_cdma_no_lte_values);
- break;
- case TelephonyManager.NETWORK_MODE_GLOBAL:
- case TelephonyManager.NETWORK_MODE_LTE_CDMA_EVDO:
- case TelephonyManager.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA:
- case TelephonyManager.NETWORK_MODE_LTE_ONLY:
- mButtonEnabledNetworks.setEntries(
- R.array.enabled_networks_cdma_only_lte_choices);
- mButtonEnabledNetworks.setEntryValues(
- R.array.enabled_networks_cdma_only_lte_values);
- break;
- default:
- mButtonEnabledNetworks.setEntries(
- R.array.enabled_networks_cdma_choices);
- mButtonEnabledNetworks.setEntryValues(
- R.array.enabled_networks_cdma_values);
- break;
- }
- }
- }
- updateCdmaOptions(this, getPreferenceScreen(), mSubId);
-
- } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
- if (isSupportTdscdma()) {
- mButtonEnabledNetworks.setEntries(
- R.array.enabled_networks_tdscdma_choices);
- mButtonEnabledNetworks.setEntryValues(
- R.array.enabled_networks_tdscdma_values);
- } else if (!carrierConfig.getBoolean(CarrierConfigManager.KEY_PREFER_2G_BOOL)
- && !getResources().getBoolean(R.bool.config_enabled_lte)) {
- mButtonEnabledNetworks.setEntries(
- R.array.enabled_networks_except_gsm_lte_choices);
- mButtonEnabledNetworks.setEntryValues(
- R.array.enabled_networks_except_gsm_lte_values);
- } else if (!carrierConfig.getBoolean(CarrierConfigManager.KEY_PREFER_2G_BOOL)) {
- int select = mShow4GForLTE
- ? R.array.enabled_networks_except_gsm_4g_choices
- : R.array.enabled_networks_except_gsm_choices;
- mButtonEnabledNetworks.setEntries(select);
- mButtonEnabledNetworks.setEntryValues(
- R.array.enabled_networks_except_gsm_values);
- } else if (!getResources().getBoolean(R.bool.config_enabled_lte)) {
- mButtonEnabledNetworks.setEntries(
- R.array.enabled_networks_except_lte_choices);
- mButtonEnabledNetworks.setEntryValues(
- R.array.enabled_networks_except_lte_values);
- } else if (mIsGlobalCdma) {
- mButtonEnabledNetworks.setEntries(
- R.array.enabled_networks_cdma_choices);
- mButtonEnabledNetworks.setEntryValues(
- R.array.enabled_networks_cdma_values);
- } else {
- int select = mShow4GForLTE ? R.array.enabled_networks_4g_choices
- : R.array.enabled_networks_choices;
- mButtonEnabledNetworks.setEntries(select);
- mButtonEnabledNetworks.setEntryValues(
- R.array.enabled_networks_values);
- }
- updateGsmUmtsOptions(this, getPreferenceScreen(), mSubId);
- } else {
- throw new IllegalStateException("Unexpected phone type: " + phoneType);
- }
- if (isWorldMode()) {
- mButtonEnabledNetworks.setEntries(
- R.array.preferred_network_mode_choices_world_mode);
- mButtonEnabledNetworks.setEntryValues(
- R.array.preferred_network_mode_values_world_mode);
- }
- }
-
@Override
public void onPause() {
super.onPause();
sendMetricsEventPreferenceChanged(getPreferenceScreen(), preference, objValue);
final int phoneSubId = mSubId;
- if (preference == mButtonEnabledNetworks) {
- mButtonEnabledNetworks.setValue((String) objValue);
- int buttonNetworkMode;
- buttonNetworkMode = Integer.parseInt((String) objValue);
- if (DBG) log("buttonNetworkMode: " + buttonNetworkMode);
- int settingsNetworkMode = android.provider.Settings.Global.getInt(
- getContext().getContentResolver(),
- android.provider.Settings.Global.PREFERRED_NETWORK_MODE + phoneSubId,
- preferredNetworkMode);
- if (buttonNetworkMode != settingsNetworkMode) {
- int modemNetworkMode;
- // if new mode is invalid ignore it
- switch (buttonNetworkMode) {
- case TelephonyManager.NETWORK_MODE_WCDMA_PREF:
- case TelephonyManager.NETWORK_MODE_GSM_ONLY:
- case TelephonyManager.NETWORK_MODE_LTE_GSM_WCDMA:
- case TelephonyManager.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA:
- case TelephonyManager.NETWORK_MODE_CDMA_EVDO:
- case TelephonyManager.NETWORK_MODE_CDMA_NO_EVDO:
- case TelephonyManager.NETWORK_MODE_LTE_CDMA_EVDO:
- case TelephonyManager.NETWORK_MODE_TDSCDMA_ONLY:
- case TelephonyManager.NETWORK_MODE_TDSCDMA_WCDMA:
- case TelephonyManager.NETWORK_MODE_LTE_TDSCDMA:
- case TelephonyManager.NETWORK_MODE_TDSCDMA_GSM:
- case TelephonyManager.NETWORK_MODE_LTE_TDSCDMA_GSM:
- case TelephonyManager.NETWORK_MODE_TDSCDMA_GSM_WCDMA:
- case TelephonyManager.NETWORK_MODE_LTE_TDSCDMA_WCDMA:
- case TelephonyManager.NETWORK_MODE_LTE_TDSCDMA_GSM_WCDMA:
- case TelephonyManager.NETWORK_MODE_TDSCDMA_CDMA_EVDO_GSM_WCDMA:
- case TelephonyManager.NETWORK_MODE_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA:
- // This is one of the modes we recognize
- modemNetworkMode = buttonNetworkMode;
- break;
- default:
- loge("Invalid Network Mode (" +buttonNetworkMode+ ") chosen. Ignore.");
- return true;
- }
-
- UpdateEnabledNetworksValueAndSummary(buttonNetworkMode);
-
- android.provider.Settings.Global.putInt(
- getContext().getContentResolver(),
- android.provider.Settings.Global.PREFERRED_NETWORK_MODE + phoneSubId,
- buttonNetworkMode );
- //Set the modem network mode
- new SetPreferredNetworkAsyncTask(
- mTelephonyManager,
- mSubId,
- modemNetworkMode,
- mHandler.obtainMessage(MyHandler.MESSAGE_SET_PREFERRED_NETWORK_TYPE))
- .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
- }
- } else if (preference == mButton4glte) {
+ if (preference == mButton4glte) {
boolean enhanced4gMode = !mButton4glte.isChecked();
mButton4glte.setChecked(enhanced4gMode);
mImsMgr.setEnhanced4gLteModeSetting(mButton4glte.isChecked());
CarrierConfigManager.KEY_EDITABLE_ENHANCED_4G_LTE_BOOL);
}
- private class MyHandler extends Handler {
-
- static final int MESSAGE_SET_PREFERRED_NETWORK_TYPE = 0;
-
- @Override
- public void handleMessage(Message msg) {
- switch (msg.what) {
- case MESSAGE_SET_PREFERRED_NETWORK_TYPE:
- handleSetPreferredNetworkTypeResponse(msg);
- break;
- }
- }
-
- private void handleSetPreferredNetworkTypeResponse(Message msg) {
- final FragmentActivity activity = getActivity();
- if (activity == null || activity.isDestroyed()) {
- // Access preferences of activity only if it is not destroyed
- // or if fragment is not attached to an activity.
- return;
- }
-
- boolean success = (boolean) msg.obj;
-
- if (success) {
- int networkMode;
- if (getPreferenceScreen().findPreference(BUTTON_ENABLED_NETWORKS_KEY) != null) {
- networkMode = Integer.parseInt(mButtonEnabledNetworks.getValue());
- android.provider.Settings.Global.putInt(
- getContext().getContentResolver(),
- android.provider.Settings.Global.PREFERRED_NETWORK_MODE
- + mSubId,
- networkMode );
- }
- } else {
- Log.i(LOG_TAG, "handleSetPreferredNetworkTypeResponse:" +
- "exception in setting network mode.");
- updatePreferredNetworkUIFromDb();
- }
- }
- }
-
- private void updatePreferredNetworkUIFromDb() {
- int settingsNetworkMode = android.provider.Settings.Global.getInt(
- getContext().getContentResolver(),
- android.provider.Settings.Global.PREFERRED_NETWORK_MODE + mSubId,
- preferredNetworkMode);
-
- if (DBG) {
- log("updatePreferredNetworkUIFromDb: settingsNetworkMode = " +
- settingsNetworkMode);
- }
-
- UpdateEnabledNetworksValueAndSummary(settingsNetworkMode);
- }
-
- private void UpdateEnabledNetworksValueAndSummary(int NetworkMode) {
- switch (NetworkMode) {
- case TelephonyManager.NETWORK_MODE_TDSCDMA_WCDMA:
- case TelephonyManager.NETWORK_MODE_TDSCDMA_GSM_WCDMA:
- case TelephonyManager.NETWORK_MODE_TDSCDMA_GSM:
- mButtonEnabledNetworks.setValue(
- Integer.toString(TelephonyManager.NETWORK_MODE_TDSCDMA_GSM_WCDMA));
- mButtonEnabledNetworks.setSummary(R.string.network_3G);
- break;
- case TelephonyManager.NETWORK_MODE_WCDMA_ONLY:
- case TelephonyManager.NETWORK_MODE_GSM_UMTS:
- case TelephonyManager.NETWORK_MODE_WCDMA_PREF:
- if (!mIsGlobalCdma) {
- mButtonEnabledNetworks.setValue(
- Integer.toString(TelephonyManager.NETWORK_MODE_WCDMA_PREF));
- mButtonEnabledNetworks.setSummary(R.string.network_3G);
- } else {
- mButtonEnabledNetworks.setValue(
- Integer.toString(TelephonyManager
- .NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA));
- mButtonEnabledNetworks.setSummary(R.string.network_global);
- }
- break;
- case TelephonyManager.NETWORK_MODE_GSM_ONLY:
- if (!mIsGlobalCdma) {
- mButtonEnabledNetworks.setValue(
- Integer.toString(TelephonyManager.NETWORK_MODE_GSM_ONLY));
- mButtonEnabledNetworks.setSummary(R.string.network_2G);
- } else {
- mButtonEnabledNetworks.setValue(
- Integer.toString(TelephonyManager
- .NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA));
- mButtonEnabledNetworks.setSummary(R.string.network_global);
- }
- break;
- case TelephonyManager.NETWORK_MODE_LTE_GSM_WCDMA:
- if (isWorldMode()) {
- mButtonEnabledNetworks.setSummary(
- R.string.preferred_network_mode_lte_gsm_umts_summary);
- controlCdmaOptions(false);
- controlGsmOptions(true);
- break;
- }
- case TelephonyManager.NETWORK_MODE_LTE_ONLY:
- case TelephonyManager.NETWORK_MODE_LTE_WCDMA:
- if (!mIsGlobalCdma) {
- mButtonEnabledNetworks.setValue(
- Integer.toString(TelephonyManager.NETWORK_MODE_LTE_GSM_WCDMA));
- mButtonEnabledNetworks.setSummary((mShow4GForLTE == true)
- ? R.string.network_4G : R.string.network_lte);
- } else {
- mButtonEnabledNetworks.setValue(
- Integer.toString(TelephonyManager
- .NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA));
- mButtonEnabledNetworks.setSummary(R.string.network_global);
- }
- break;
- case TelephonyManager.NETWORK_MODE_LTE_CDMA_EVDO:
- if (isWorldMode()) {
- mButtonEnabledNetworks.setSummary(
- R.string.preferred_network_mode_lte_cdma_summary);
- controlCdmaOptions(true);
- controlGsmOptions(false);
- } else {
- mButtonEnabledNetworks.setValue(
- Integer.toString(TelephonyManager.NETWORK_MODE_LTE_CDMA_EVDO));
- mButtonEnabledNetworks.setSummary(R.string.network_lte);
- }
- break;
- case TelephonyManager.NETWORK_MODE_TDSCDMA_CDMA_EVDO_GSM_WCDMA:
- mButtonEnabledNetworks.setValue(
- Integer.toString(TelephonyManager
- .NETWORK_MODE_TDSCDMA_CDMA_EVDO_GSM_WCDMA));
- mButtonEnabledNetworks.setSummary(R.string.network_3G);
- break;
- case TelephonyManager.NETWORK_MODE_CDMA_EVDO:
- case TelephonyManager.NETWORK_MODE_EVDO_NO_CDMA:
- case TelephonyManager.NETWORK_MODE_GLOBAL:
- mButtonEnabledNetworks.setValue(
- Integer.toString(TelephonyManager.NETWORK_MODE_CDMA_EVDO));
- mButtonEnabledNetworks.setSummary(R.string.network_3G);
- break;
- case TelephonyManager.NETWORK_MODE_CDMA_NO_EVDO:
- mButtonEnabledNetworks.setValue(
- Integer.toString(TelephonyManager.NETWORK_MODE_CDMA_NO_EVDO));
- mButtonEnabledNetworks.setSummary(R.string.network_1x);
- break;
- case TelephonyManager.NETWORK_MODE_TDSCDMA_ONLY:
- mButtonEnabledNetworks.setValue(
- Integer.toString(TelephonyManager.NETWORK_MODE_TDSCDMA_ONLY));
- mButtonEnabledNetworks.setSummary(R.string.network_3G);
- break;
- case TelephonyManager.NETWORK_MODE_LTE_TDSCDMA_GSM:
- case TelephonyManager.NETWORK_MODE_LTE_TDSCDMA_GSM_WCDMA:
- case TelephonyManager.NETWORK_MODE_LTE_TDSCDMA:
- case TelephonyManager.NETWORK_MODE_LTE_TDSCDMA_WCDMA:
- case TelephonyManager.NETWORK_MODE_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA:
- case TelephonyManager.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA:
- if (isSupportTdscdma()) {
- mButtonEnabledNetworks.setValue(
- Integer.toString(TelephonyManager
- .NETWORK_MODE_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA));
- mButtonEnabledNetworks.setSummary(R.string.network_lte);
- } else {
- if (isWorldMode()) {
- controlCdmaOptions(true);
- controlGsmOptions(false);
- }
- mButtonEnabledNetworks.setValue(
- Integer.toString(TelephonyManager
- .NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA));
- if (mTelephonyManager.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA
- || mIsGlobalCdma
- || isWorldMode()) {
- mButtonEnabledNetworks.setSummary(R.string.network_global);
- } else {
- mButtonEnabledNetworks.setSummary((mShow4GForLTE == true)
- ? R.string.network_4G : R.string.network_lte);
- }
- }
- break;
- default:
- String errMsg = "Invalid Network Mode (" + NetworkMode + "). Ignore.";
- loge(errMsg);
- mButtonEnabledNetworks.setSummary(errMsg);
- }
- }
-
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
mSubId) == TelephonyManager.CALL_STATE_IDLE
&& hasActiveSubscriptions();
Log.i(LOG_TAG, "updatePreferredNetworkType: " + enabled);
- // TODO: Disentangle enabled networks vs preferred network mode, it looks like
- // both buttons are shown to the user as "Preferred network type" and the options change
- // based on what looks like World mode.
- if (mButtonEnabledNetworks != null) {
- mButtonEnabledNetworks.setEnabled(enabled);
- }
}
private void updateCallingCategory() {
if (preference == mLteDataServicePref
|| preference == mEuiccSettingsPref
|| preference == mWiFiCallingPref
- || preference == mButtonEnabledNetworks
|| preference == preferenceScreen.findPreference(BUTTON_CDMA_SYSTEM_SELECT_KEY)
|| preference == preferenceScreen.findPreference(BUTTON_CDMA_SUBSCRIPTION_KEY)
|| preference == preferenceScreen.findPreference(BUTTON_GSM_APN_EXPAND_KEY)
// MetricsEvent logging with new value, for SwitchPreferences and ListPreferences.
if (preference == mButton4glte || preference == mVideoCallingPref) {
MetricsLogger.action(getContext(), category, (Boolean) newValue);
- } else if (preference == mButtonEnabledNetworks
- || preference == preferenceScreen
+ } else if (preference == preferenceScreen
.findPreference(BUTTON_CDMA_SYSTEM_SELECT_KEY)
|| preference == preferenceScreen
.findPreference(BUTTON_CDMA_SUBSCRIPTION_KEY)) {
return MetricsProto.MetricsEvent.ACTION_MOBILE_NETWORK_SET_UP_DATA_SERVICE;
} else if (preference == mButton4glte) {
return MetricsProto.MetricsEvent.ACTION_MOBILE_ENHANCED_4G_LTE_MODE_TOGGLE;
- } else if (preference == mButtonEnabledNetworks) {
- return MetricsProto.MetricsEvent.ACTION_MOBILE_NETWORK_SELECT_ENABLED_NETWORK;
} else if (preference == mEuiccSettingsPref) {
return MetricsProto.MetricsEvent.ACTION_MOBILE_NETWORK_EUICC_SETTING;
} else if (preference == mWiFiCallingPref) {
--- /dev/null
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.network.telephony;
+
+import static com.android.settings.core.BasePreferenceController.AVAILABLE;
+import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
+
+import android.content.Context;
+import android.os.PersistableBundle;
+import android.provider.Settings;
+import android.telephony.CarrierConfigManager;
+import android.telephony.SubscriptionManager;
+import android.telephony.TelephonyManager;
+
+import androidx.preference.ListPreference;
+
+import com.android.settings.R;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+public class EnabledNetworkModePreferenceControllerTest {
+ private static final int SUB_ID = 2;
+
+ @Mock
+ private TelephonyManager mTelephonyManager;
+ @Mock
+ private TelephonyManager mInvalidTelephonyManager;
+ @Mock
+ private CarrierConfigManager mCarrierConfigManager;
+
+ private PersistableBundle mPersistableBundle;
+ private EnabledNetworkModePreferenceController mController;
+ private ListPreference mPreference;
+ private Context mContext;
+
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+
+ mContext = spy(RuntimeEnvironment.application);
+ doReturn(mTelephonyManager).when(mContext).getSystemService(Context.TELEPHONY_SERVICE);
+ doReturn(mTelephonyManager).when(mContext).getSystemService(TelephonyManager.class);
+ doReturn(mCarrierConfigManager).when(mContext).getSystemService(CarrierConfigManager.class);
+ doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(SUB_ID);
+ doReturn(mInvalidTelephonyManager).when(mTelephonyManager).createForSubscriptionId(
+ SubscriptionManager.INVALID_SUBSCRIPTION_ID);
+ doReturn(mContext).when(mContext).createPackageContext(anyString(), anyInt());
+ mPersistableBundle = new PersistableBundle();
+ doReturn(mPersistableBundle).when(mCarrierConfigManager).getConfigForSubId(SUB_ID);
+
+ mPreference = new ListPreference(mContext);
+ mPreference.setEntries(R.array.enabled_networks_choices);
+ mPreference.setEntryValues(R.array.enabled_networks_values);
+ mController = spy(new EnabledNetworkModePreferenceController(mContext, "enabled_network"));
+ doNothing().when(mController).initShow4GForLTE();
+ mController.init(SUB_ID);
+ mPreference.setKey(mController.getPreferenceKey());
+ }
+
+ @Test
+ public void getAvailabilityStatus_hideCarrierNetworkSettings_returnUnavailable() {
+ mPersistableBundle.putBoolean(CarrierConfigManager.KEY_HIDE_CARRIER_NETWORK_SETTINGS_BOOL,
+ true);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
+ }
+
+ @Test
+ public void getAvailabilityStatus_notWorldPhone_returnAvailable() {
+ mPersistableBundle.putBoolean(CarrierConfigManager.KEY_HIDE_CARRIER_NETWORK_SETTINGS_BOOL,
+ false);
+ mPersistableBundle.putBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL, false);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
+ }
+
+ @Test
+ public void updateState_updateByNetworkMode() {
+ Settings.Global.putInt(mContext.getContentResolver(),
+ Settings.Global.PREFERRED_NETWORK_MODE + SUB_ID,
+ TelephonyManager.NETWORK_MODE_TDSCDMA_GSM_WCDMA);
+
+ mController.updateState(mPreference);
+
+ assertThat(mPreference.getValue()).isEqualTo(
+ String.valueOf(TelephonyManager.NETWORK_MODE_TDSCDMA_GSM_WCDMA));
+ assertThat(mPreference.getSummary()).isEqualTo("3G");
+ }
+
+ @Test
+ public void onPreferenceChange_updateSuccess() {
+ doReturn(true).when(mTelephonyManager).setPreferredNetworkType(SUB_ID,
+ TelephonyManager.NETWORK_MODE_LTE_GSM_WCDMA);
+
+ mController.onPreferenceChange(mPreference,
+ String.valueOf(TelephonyManager.NETWORK_MODE_LTE_GSM_WCDMA));
+
+ assertThat(Settings.Global.getInt(mContext.getContentResolver(),
+ Settings.Global.PREFERRED_NETWORK_MODE + SUB_ID, 0)).isEqualTo(
+ TelephonyManager.NETWORK_MODE_LTE_GSM_WCDMA);
+ }
+
+ @Test
+ public void onPreferenceChange_updateFail() {
+ doReturn(false).when(mTelephonyManager).setPreferredNetworkType(SUB_ID,
+ TelephonyManager.NETWORK_MODE_LTE_GSM_WCDMA);
+
+ mController.onPreferenceChange(mPreference,
+ String.valueOf(TelephonyManager.NETWORK_MODE_LTE_GSM_WCDMA));
+
+ assertThat(Settings.Global.getInt(mContext.getContentResolver(),
+ Settings.Global.PREFERRED_NETWORK_MODE + SUB_ID, 0)).isNotEqualTo(
+ TelephonyManager.NETWORK_MODE_LTE_GSM_WCDMA);
+ }
+
+}