Merge "Refactor CdmaSystemSelectListPreference"
This commit is contained in:
committed by
Android (Google) Code Review
commit
0d0eec6d4e
@@ -43,7 +43,6 @@ public class CdmaOptions {
|
||||
private static final String LOG_TAG = "CdmaOptions";
|
||||
|
||||
private CarrierConfigManager mCarrierConfigManager;
|
||||
private CdmaSystemSelectListPreference mButtonCdmaSystemSelect;
|
||||
private CdmaSubscriptionListPreference mButtonCdmaSubscription;
|
||||
private RestrictedPreference mButtonAPNExpand;
|
||||
private Preference mCategoryAPNExpand;
|
||||
@@ -66,8 +65,6 @@ public class CdmaOptions {
|
||||
mCarrierConfigManager = new CarrierConfigManager(prefFragment.getContext());
|
||||
|
||||
// Initialize preferences.
|
||||
mButtonCdmaSystemSelect = (CdmaSystemSelectListPreference) mPrefScreen
|
||||
.findPreference(BUTTON_CDMA_SYSTEM_SELECT_KEY);
|
||||
mButtonCdmaSubscription = (CdmaSubscriptionListPreference) mPrefScreen
|
||||
.findPreference(BUTTON_CDMA_SUBSCRIPTION_KEY);
|
||||
mButtonCarrierSettings = mPrefScreen.findPreference(BUTTON_CARRIER_SETTINGS_KEY);
|
||||
@@ -91,9 +88,6 @@ public class CdmaOptions {
|
||||
boolean addCarrierSettings =
|
||||
carrierConfig.getBoolean(CarrierConfigManager.KEY_CARRIER_SETTINGS_ENABLE_BOOL);
|
||||
|
||||
mPrefScreen.addPreference(mButtonCdmaSystemSelect);
|
||||
mButtonCdmaSystemSelect.setEnabled(true);
|
||||
|
||||
// Making no assumptions of whether they are added or removed at this point.
|
||||
// Calling add or remove explicitly to make sure they are updated.
|
||||
|
||||
@@ -191,9 +185,7 @@ public class CdmaOptions {
|
||||
}
|
||||
|
||||
public void showDialog(Preference preference) {
|
||||
if (preference.getKey().equals(BUTTON_CDMA_SYSTEM_SELECT_KEY)) {
|
||||
mButtonCdmaSystemSelect.showDialog(null);
|
||||
} else if (preference.getKey().equals(BUTTON_CDMA_SUBSCRIPTION_KEY)) {
|
||||
if (preference.getKey().equals(BUTTON_CDMA_SUBSCRIPTION_KEY)) {
|
||||
mButtonCdmaSubscription.showDialog(null);
|
||||
}
|
||||
}
|
||||
|
@@ -1,186 +0,0 @@
|
||||
/*
|
||||
* 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.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.provider.Settings;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.settingslib.utils.ThreadUtils;
|
||||
|
||||
import androidx.preference.ListPreference;
|
||||
|
||||
public class CdmaSystemSelectListPreference extends ListPreference {
|
||||
|
||||
private static final String LOG_TAG = "CdmaRoamingListPref";
|
||||
private static final boolean DBG = false;
|
||||
|
||||
private TelephonyManager mTelephonyManager;
|
||||
private MyHandler mHandler = new MyHandler();
|
||||
|
||||
public CdmaSystemSelectListPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
||||
mHandler = new MyHandler();
|
||||
mTelephonyManager = TelephonyManager.from(context);
|
||||
}
|
||||
|
||||
public CdmaSystemSelectListPreference(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the subscription id associated with this preference.
|
||||
*
|
||||
* @param subId the subscription id.
|
||||
*/
|
||||
public void setSubscriptionId(int subId) {
|
||||
mTelephonyManager = TelephonyManager.from(getContext()).createForSubscriptionId(subId);
|
||||
queryCdmaRoamingMode();
|
||||
}
|
||||
|
||||
//TODO(b/114749736): Move this to preference controller
|
||||
protected void showDialog(Bundle state) {
|
||||
if (!mTelephonyManager.getEmergencyCallbackMode()) {
|
||||
// show Dialog
|
||||
}
|
||||
}
|
||||
|
||||
//TODO(b/114749736): Move this to preference controller
|
||||
protected void onDialogClosed(boolean positiveResult) {
|
||||
if (positiveResult && (getValue() != null)) {
|
||||
int buttonCdmaRoamingMode = Integer.parseInt(getValue());
|
||||
int settingsCdmaRoamingMode = Settings.Global.getInt(
|
||||
getContext().getContentResolver(),
|
||||
Settings.Global.CDMA_ROAMING_MODE,
|
||||
TelephonyManager.CDMA_ROAMING_MODE_HOME);
|
||||
if (buttonCdmaRoamingMode != settingsCdmaRoamingMode) {
|
||||
int cdmaRoamingMode = TelephonyManager.CDMA_ROAMING_MODE_ANY;
|
||||
if (buttonCdmaRoamingMode != TelephonyManager.CDMA_ROAMING_MODE_ANY) {
|
||||
cdmaRoamingMode = TelephonyManager.CDMA_ROAMING_MODE_HOME;
|
||||
}
|
||||
//Set the Settings.Secure network mode
|
||||
Settings.Global.putInt(
|
||||
getContext().getContentResolver(),
|
||||
Settings.Global.CDMA_ROAMING_MODE,
|
||||
buttonCdmaRoamingMode);
|
||||
//Set the roaming preference mode
|
||||
setCdmaRoamingMode(cdmaRoamingMode);
|
||||
}
|
||||
} else {
|
||||
Log.d(LOG_TAG, String.format("onDialogClosed: positiveResult=%b value=%s -- do nothing",
|
||||
positiveResult, getValue()));
|
||||
}
|
||||
}
|
||||
|
||||
private class MyHandler extends Handler {
|
||||
|
||||
static final int MESSAGE_GET_ROAMING_PREFERENCE = 0;
|
||||
static final int MESSAGE_SET_ROAMING_PREFERENCE = 1;
|
||||
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
switch (msg.what) {
|
||||
case MESSAGE_GET_ROAMING_PREFERENCE:
|
||||
handleQueryCdmaRoamingPreference(msg);
|
||||
break;
|
||||
|
||||
case MESSAGE_SET_ROAMING_PREFERENCE:
|
||||
handleSetCdmaRoamingPreference(msg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void handleQueryCdmaRoamingPreference(Message msg) {
|
||||
int cdmaRoamingMode = msg.arg1;
|
||||
|
||||
if (cdmaRoamingMode != TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT) {
|
||||
int settingsRoamingMode = Settings.Global.getInt(
|
||||
getContext().getContentResolver(),
|
||||
Settings.Global.CDMA_ROAMING_MODE,
|
||||
TelephonyManager.CDMA_ROAMING_MODE_HOME);
|
||||
|
||||
//check that statusCdmaRoamingMode is from an accepted value
|
||||
if (cdmaRoamingMode == TelephonyManager.CDMA_ROAMING_MODE_HOME
|
||||
|| cdmaRoamingMode == TelephonyManager.CDMA_ROAMING_MODE_ANY) {
|
||||
//check changes in statusCdmaRoamingMode and updates settingsRoamingMode
|
||||
if (cdmaRoamingMode != settingsRoamingMode) {
|
||||
settingsRoamingMode = cdmaRoamingMode;
|
||||
//changes the Settings.Secure accordingly to statusCdmaRoamingMode
|
||||
Settings.Global.putInt(
|
||||
getContext().getContentResolver(),
|
||||
Settings.Global.CDMA_ROAMING_MODE,
|
||||
settingsRoamingMode);
|
||||
}
|
||||
//changes the mButtonPreferredNetworkMode accordingly to modemNetworkMode
|
||||
setValue(Integer.toString(cdmaRoamingMode));
|
||||
}
|
||||
else {
|
||||
if(DBG) Log.i(LOG_TAG, "reset cdma roaming mode to default" );
|
||||
resetCdmaRoamingModeToDefault();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void handleSetCdmaRoamingPreference(Message msg) {
|
||||
boolean isSuccessed = (boolean) msg.obj;
|
||||
|
||||
if (isSuccessed && (getValue() != null)) {
|
||||
int cdmaRoamingMode = Integer.parseInt(getValue());
|
||||
Settings.Global.putInt(
|
||||
getContext().getContentResolver(),
|
||||
Settings.Global.CDMA_ROAMING_MODE,
|
||||
cdmaRoamingMode );
|
||||
} else {
|
||||
queryCdmaRoamingMode();
|
||||
}
|
||||
}
|
||||
|
||||
private void resetCdmaRoamingModeToDefault() {
|
||||
//set the mButtonCdmaRoam
|
||||
setValue(Integer.toString(TelephonyManager.CDMA_ROAMING_MODE_ANY));
|
||||
//set the Settings.System
|
||||
Settings.Global.putInt(
|
||||
getContext().getContentResolver(),
|
||||
Settings.Global.CDMA_ROAMING_MODE,
|
||||
TelephonyManager.CDMA_ROAMING_MODE_ANY);
|
||||
//Set the Status
|
||||
setCdmaRoamingMode(TelephonyManager.CDMA_ROAMING_MODE_ANY);
|
||||
}
|
||||
}
|
||||
|
||||
private void queryCdmaRoamingMode() {
|
||||
ThreadUtils.postOnBackgroundThread(() -> {
|
||||
Message msg = mHandler.obtainMessage(MyHandler.MESSAGE_GET_ROAMING_PREFERENCE);
|
||||
msg.arg1 = mTelephonyManager.getCdmaRoamingMode();
|
||||
msg.sendToTarget();
|
||||
});
|
||||
}
|
||||
|
||||
private void setCdmaRoamingMode(int mode) {
|
||||
ThreadUtils.postOnBackgroundThread(() -> {
|
||||
Message msg = mHandler.obtainMessage(MyHandler.MESSAGE_SET_ROAMING_PREFERENCE);
|
||||
msg.obj = mTelephonyManager.setCdmaRoamingMode(mode);
|
||||
msg.sendToTarget();
|
||||
});
|
||||
}
|
||||
}
|
@@ -49,6 +49,14 @@ import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
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;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.preference.SwitchPreference;
|
||||
|
||||
import com.android.ims.ImsConfig;
|
||||
import com.android.ims.ImsManager;
|
||||
import com.android.internal.logging.MetricsLogger;
|
||||
@@ -58,6 +66,7 @@ import com.android.internal.telephony.PhoneConstants;
|
||||
import com.android.internal.telephony.TelephonyIntents;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.network.telephony.cdma.CdmaSystemSelectPreferenceController;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settings.search.Indexable;
|
||||
import com.android.settingslib.RestrictedLockUtilsInternal;
|
||||
@@ -68,14 +77,6 @@ import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.preference.ListPreference;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceCategory;
|
||||
import androidx.preference.PreferenceFragmentCompat;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.preference.SwitchPreference;
|
||||
|
||||
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
|
||||
public class MobileNetworkFragment extends DashboardFragment implements
|
||||
Preference.OnPreferenceChangeListener, RoamingDialogFragment.RoamingDialogListener {
|
||||
@@ -160,6 +161,8 @@ public class MobileNetworkFragment extends DashboardFragment implements
|
||||
private NetworkSelectListPreference mButtonNetworkSelect;
|
||||
private DataUsagePreference mDataUsagePref;
|
||||
|
||||
private CdmaSystemSelectPreferenceController mCdmaSystemSelectPreferenceController;
|
||||
|
||||
private static final String iface = "rmnet0"; //TODO: this will go away
|
||||
private List<SubscriptionInfo> mActiveSubInfos;
|
||||
|
||||
@@ -394,6 +397,9 @@ public class MobileNetworkFragment extends DashboardFragment implements
|
||||
SubscriptionManager.INVALID_SUBSCRIPTION_ID);
|
||||
|
||||
use(MobileDataPreferenceController.class).init(getFragmentManager(), mSubId);
|
||||
|
||||
mCdmaSystemSelectPreferenceController = use(CdmaSystemSelectPreferenceController.class);
|
||||
mCdmaSystemSelectPreferenceController.init(getPreferenceManager(), mSubId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -721,10 +727,6 @@ public class MobileNetworkFragment extends DashboardFragment implements
|
||||
/**
|
||||
* Listen to extra preference changes that need as Metrics events logging.
|
||||
*/
|
||||
if (prefSet.findPreference(BUTTON_CDMA_SYSTEM_SELECT_KEY) != null) {
|
||||
prefSet.findPreference(BUTTON_CDMA_SYSTEM_SELECT_KEY)
|
||||
.setOnPreferenceChangeListener(this);
|
||||
}
|
||||
|
||||
if (prefSet.findPreference(BUTTON_CDMA_SUBSCRIPTION_KEY) != null) {
|
||||
prefSet.findPreference(BUTTON_CDMA_SUBSCRIPTION_KEY)
|
||||
@@ -784,10 +786,6 @@ public class MobileNetworkFragment extends DashboardFragment implements
|
||||
if (ps != null) {
|
||||
ps.setEnabled(hasActiveSubscriptions);
|
||||
}
|
||||
ps = findPreference(BUTTON_CDMA_SYSTEM_SELECT_KEY);
|
||||
if (ps != null) {
|
||||
ps.setEnabled(hasActiveSubscriptions);
|
||||
}
|
||||
ps = findPreference(CATEGORY_CALLING_KEY);
|
||||
if (ps != null) {
|
||||
ps.setEnabled(hasActiveSubscriptions);
|
||||
@@ -1096,8 +1094,6 @@ public class MobileNetworkFragment extends DashboardFragment implements
|
||||
return false;
|
||||
}
|
||||
} else if (preference == getPreferenceScreen()
|
||||
.findPreference(BUTTON_CDMA_SYSTEM_SELECT_KEY)
|
||||
|| preference == getPreferenceScreen()
|
||||
.findPreference(BUTTON_CDMA_SUBSCRIPTION_KEY)) {
|
||||
return true;
|
||||
}
|
||||
@@ -1429,13 +1425,18 @@ public class MobileNetworkFragment extends DashboardFragment implements
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
switch(requestCode) {
|
||||
switch (requestCode) {
|
||||
case REQUEST_CODE_EXIT_ECM:
|
||||
Boolean isChoiceYes = data.getBooleanExtra(
|
||||
EXTRA_EXIT_ECM_RESULT, false);
|
||||
if (isChoiceYes) {
|
||||
// If the phone exits from ECM mode, show the CDMA Options
|
||||
mCdmaOptions.showDialog(mClickedPreference);
|
||||
if (TextUtils.equals(mClickedPreference.getKey(),
|
||||
mCdmaSystemSelectPreferenceController.getPreferenceKey())) {
|
||||
mCdmaSystemSelectPreferenceController.showDialog();
|
||||
} else {
|
||||
mCdmaOptions.showDialog(mClickedPreference);
|
||||
}
|
||||
} else {
|
||||
// do nothing
|
||||
}
|
||||
@@ -1665,13 +1666,6 @@ public class MobileNetworkFragment extends DashboardFragment implements
|
||||
return;
|
||||
}
|
||||
updateCdmaOptions(this, prefSet, mSubId);
|
||||
CdmaSystemSelectListPreference systemSelect =
|
||||
(CdmaSystemSelectListPreference)prefSet.findPreference
|
||||
(BUTTON_CDMA_SYSTEM_SELECT_KEY);
|
||||
systemSelect.setSubscriptionId(mSubId);
|
||||
if (systemSelect != null) {
|
||||
systemSelect.setEnabled(enable);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isSupportTdscdma() {
|
||||
|
@@ -41,6 +41,9 @@ import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import com.android.ims.ImsException;
|
||||
import com.android.ims.ImsManager;
|
||||
import com.android.internal.telephony.Phone;
|
||||
import com.android.internal.telephony.PhoneConstants;
|
||||
import com.android.settings.R;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -238,4 +241,86 @@ public class MobileNetworkUtils {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return {@code true} if show CDMA category
|
||||
*/
|
||||
public static boolean isCdmaOptions(Context context, int subId) {
|
||||
if (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
|
||||
return false;
|
||||
}
|
||||
final TelephonyManager telephonyManager = TelephonyManager.from(context)
|
||||
.createForSubscriptionId(subId);
|
||||
|
||||
if (telephonyManager.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isWorldMode(context, subId)) {
|
||||
final int settingsNetworkMode = android.provider.Settings.Global.getInt(
|
||||
context.getContentResolver(),
|
||||
android.provider.Settings.Global.PREFERRED_NETWORK_MODE + subId,
|
||||
Phone.PREFERRED_NT_MODE);
|
||||
if (settingsNetworkMode == TelephonyManager.NETWORK_MODE_LTE_GSM_WCDMA
|
||||
|| settingsNetworkMode == TelephonyManager.NETWORK_MODE_LTE_CDMA_EVDO) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (settingsNetworkMode == TelephonyManager.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA
|
||||
&& !isTdscdmaSupported(context, telephonyManager)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return {@code true} if it is world mode, and we may show advanced options in telephony
|
||||
* settings
|
||||
*/
|
||||
public static boolean isWorldMode(Context context, int subId) {
|
||||
final TelephonyManager telephonyManager = TelephonyManager.from(context)
|
||||
.createForSubscriptionId(subId);
|
||||
boolean worldModeOn = false;
|
||||
final String configString = context.getString(R.string.config_world_mode);
|
||||
|
||||
if (!TextUtils.isEmpty(configString)) {
|
||||
String[] configArray = configString.split(";");
|
||||
// Check if we have World mode configuration set to True only or config is set to True
|
||||
// and SIM GID value is also set and matches to the current SIM GID.
|
||||
if (configArray != null &&
|
||||
((configArray.length == 1 && configArray[0].equalsIgnoreCase("true"))
|
||||
|| (configArray.length == 2 && !TextUtils.isEmpty(configArray[1])
|
||||
&& telephonyManager != null
|
||||
&& configArray[1].equalsIgnoreCase(
|
||||
telephonyManager.getGroupIdLevel1())))) {
|
||||
worldModeOn = true;
|
||||
}
|
||||
}
|
||||
|
||||
Log.d(TAG, "isWorldMode=" + worldModeOn);
|
||||
|
||||
return worldModeOn;
|
||||
}
|
||||
|
||||
//TODO(b/117651939): move it to telephony
|
||||
private static boolean isTdscdmaSupported(Context context, TelephonyManager telephonyManager) {
|
||||
if (context.getResources().getBoolean(R.bool.config_support_tdscdma)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
String operatorNumeric = telephonyManager.getServiceState().getOperatorNumeric();
|
||||
String[] numericArray = context.getResources().getStringArray(
|
||||
R.array.config_support_tdscdma_roaming_on_networks);
|
||||
if (numericArray.length == 0 || operatorNumeric == null) {
|
||||
return false;
|
||||
}
|
||||
for (String numeric : numericArray) {
|
||||
if (operatorNumeric.equals(numeric)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@@ -0,0 +1,155 @@
|
||||
/*
|
||||
* 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.cdma;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.ContentObserver;
|
||||
import android.net.Uri;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.provider.Settings;
|
||||
import android.telephony.TelephonyManager;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.ListPreference;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceManager;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.network.telephony.MobileNetworkUtils;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStart;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStop;
|
||||
|
||||
/**
|
||||
* Preference controller for "System Select"
|
||||
*/
|
||||
public class CdmaSystemSelectPreferenceController extends BasePreferenceController
|
||||
implements LifecycleObserver, OnStart, OnStop, ListPreference.OnPreferenceChangeListener {
|
||||
|
||||
@VisibleForTesting
|
||||
ListPreference mPreference;
|
||||
private TelephonyManager mTelephonyManager;
|
||||
private PreferenceManager mPreferenceManager;
|
||||
private DataContentObserver mDataContentObserver;
|
||||
private int mSubId;
|
||||
|
||||
public CdmaSystemSelectPreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
mDataContentObserver = new DataContentObserver(new Handler(Looper.getMainLooper()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
mDataContentObserver.register(mContext, mSubId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
mDataContentObserver.unRegister(mContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return MobileNetworkUtils.isCdmaOptions(mContext, mSubId)
|
||||
? AVAILABLE
|
||||
: CONDITIONALLY_UNAVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mPreference = (ListPreference) screen.findPreference(getPreferenceKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
super.updateState(preference);
|
||||
final ListPreference listPreference = (ListPreference) preference;
|
||||
listPreference.setVisible(getAvailabilityStatus() == AVAILABLE);
|
||||
final int mode = mTelephonyManager.getCdmaRoamingMode();
|
||||
if (mode != TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT) {
|
||||
if (mode == TelephonyManager.CDMA_ROAMING_MODE_HOME
|
||||
|| mode == TelephonyManager.CDMA_ROAMING_MODE_ANY) {
|
||||
listPreference.setValue(Integer.toString(mode));
|
||||
} else {
|
||||
resetCdmaRoamingModeToDefault();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object object) {
|
||||
int newMode = Integer.parseInt((String) object);
|
||||
//TODO(b/117611981): only set it in one place
|
||||
if (mTelephonyManager.setCdmaRoamingMode(newMode)) {
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.CDMA_ROAMING_MODE, newMode);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void init(PreferenceManager preferenceManager, int subId) {
|
||||
mPreferenceManager = preferenceManager;
|
||||
mSubId = subId;
|
||||
mTelephonyManager = TelephonyManager.from(mContext).createForSubscriptionId(mSubId);
|
||||
}
|
||||
|
||||
public void showDialog() {
|
||||
if (!mTelephonyManager.getEmergencyCallbackMode()) {
|
||||
mPreferenceManager.showDialog(mPreference);
|
||||
}
|
||||
}
|
||||
|
||||
private void resetCdmaRoamingModeToDefault() {
|
||||
//set the mButtonCdmaRoam
|
||||
mPreference.setValue(Integer.toString(TelephonyManager.CDMA_ROAMING_MODE_ANY));
|
||||
//set the Settings.System
|
||||
Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.CDMA_ROAMING_MODE,
|
||||
TelephonyManager.CDMA_ROAMING_MODE_ANY);
|
||||
//Set the Status
|
||||
mTelephonyManager.setCdmaRoamingMode(TelephonyManager.CDMA_ROAMING_MODE_ANY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Listener that listens mobile data state change.
|
||||
*/
|
||||
public class DataContentObserver extends ContentObserver {
|
||||
|
||||
public DataContentObserver(Handler handler) {
|
||||
super(handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChange(boolean selfChange) {
|
||||
super.onChange(selfChange);
|
||||
updateState(mPreference);
|
||||
}
|
||||
|
||||
public void register(Context context, int subId) {
|
||||
Uri uri = Settings.Global.getUriFor(Settings.Global.PREFERRED_NETWORK_MODE + subId);
|
||||
context.getContentResolver().registerContentObserver(uri, false, this);
|
||||
}
|
||||
|
||||
public void unRegister(Context context) {
|
||||
context.getContentResolver().unregisterContentObserver(this);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user