Merge "[Settings] Replace getSimCount() API"
This commit is contained in:
@@ -29,8 +29,6 @@ import android.os.Bundle;
|
|||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.telephony.SubscriptionInfo;
|
import android.telephony.SubscriptionInfo;
|
||||||
import android.telephony.SubscriptionManager;
|
|
||||||
import android.telephony.TelephonyManager;
|
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
@@ -55,6 +53,9 @@ import com.android.internal.telephony.CommandException;
|
|||||||
import com.android.internal.telephony.Phone;
|
import com.android.internal.telephony.Phone;
|
||||||
import com.android.internal.telephony.PhoneFactory;
|
import com.android.internal.telephony.PhoneFactory;
|
||||||
import com.android.internal.telephony.TelephonyIntents;
|
import com.android.internal.telephony.TelephonyIntents;
|
||||||
|
import com.android.settings.network.ProxySubscriptionManager;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements the preference screen to enable/disable ICC lock and
|
* Implements the preference screen to enable/disable ICC lock and
|
||||||
@@ -112,6 +113,7 @@ public class IccLockSettings extends SettingsPreferenceFragment
|
|||||||
private ListView mListView;
|
private ListView mListView;
|
||||||
|
|
||||||
private Phone mPhone;
|
private Phone mPhone;
|
||||||
|
private ProxySubscriptionManager mProxySubscriptionMgr;
|
||||||
|
|
||||||
private EditPinPreference mPinDialog;
|
private EditPinPreference mPinDialog;
|
||||||
private SwitchPreference mPinToggle;
|
private SwitchPreference mPinToggle;
|
||||||
@@ -129,7 +131,7 @@ public class IccLockSettings extends SettingsPreferenceFragment
|
|||||||
// For replies from IccCard interface
|
// For replies from IccCard interface
|
||||||
private Handler mHandler = new Handler() {
|
private Handler mHandler = new Handler() {
|
||||||
public void handleMessage(Message msg) {
|
public void handleMessage(Message msg) {
|
||||||
AsyncResult ar = (AsyncResult) msg.obj;
|
final AsyncResult ar = (AsyncResult) msg.obj;
|
||||||
switch (msg.what) {
|
switch (msg.what) {
|
||||||
case MSG_ENABLE_ICC_PIN_COMPLETE:
|
case MSG_ENABLE_ICC_PIN_COMPLETE:
|
||||||
iccLockChanged(ar.exception == null, msg.arg1, ar.exception);
|
iccLockChanged(ar.exception == null, msg.arg1, ar.exception);
|
||||||
@@ -161,8 +163,8 @@ public class IccLockSettings extends SettingsPreferenceFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
static String getSummary(Context context) {
|
static String getSummary(Context context) {
|
||||||
Resources res = context.getResources();
|
final Resources res = context.getResources();
|
||||||
String summary = isIccLockEnabled()
|
final String summary = isIccLockEnabled()
|
||||||
? res.getString(R.string.sim_lock_on)
|
? res.getString(R.string.sim_lock_on)
|
||||||
: res.getString(R.string.sim_lock_off);
|
: res.getString(R.string.sim_lock_off);
|
||||||
return summary;
|
return summary;
|
||||||
@@ -177,6 +179,11 @@ public class IccLockSettings extends SettingsPreferenceFragment
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// enable ProxySubscriptionMgr with Lifecycle support for all controllers
|
||||||
|
// live within this fragment
|
||||||
|
mProxySubscriptionMgr = ProxySubscriptionManager.getInstance(getContext());
|
||||||
|
mProxySubscriptionMgr.setLifecycle(getLifecycle());
|
||||||
|
|
||||||
addPreferencesFromResource(R.xml.sim_lock_settings);
|
addPreferencesFromResource(R.xml.sim_lock_settings);
|
||||||
|
|
||||||
mPinDialog = (EditPinPreference) findPreference(PIN_DIALOG);
|
mPinDialog = (EditPinPreference) findPreference(PIN_DIALOG);
|
||||||
@@ -217,14 +224,12 @@ public class IccLockSettings extends SettingsPreferenceFragment
|
|||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
|
|
||||||
final TelephonyManager tm =
|
final int numSims = mProxySubscriptionMgr.getActiveSubscriptionInfoCountMax();
|
||||||
(TelephonyManager) getContext().getSystemService(Context.TELEPHONY_SERVICE);
|
|
||||||
final int numSims = tm.getSimCount();
|
|
||||||
if (numSims > 1) {
|
if (numSims > 1) {
|
||||||
View view = inflater.inflate(R.layout.icc_lock_tabs, container, false);
|
final View view = inflater.inflate(R.layout.icc_lock_tabs, container, false);
|
||||||
final ViewGroup prefs_container = (ViewGroup) view.findViewById(R.id.prefs_container);
|
final ViewGroup prefs_container = (ViewGroup) view.findViewById(R.id.prefs_container);
|
||||||
Utils.prepareCustomPreferencesList(container, view, prefs_container, false);
|
Utils.prepareCustomPreferencesList(container, view, prefs_container, false);
|
||||||
View prefs = super.onCreateView(inflater, prefs_container, savedInstanceState);
|
final View prefs = super.onCreateView(inflater, prefs_container, savedInstanceState);
|
||||||
prefs_container.addView(prefs);
|
prefs_container.addView(prefs);
|
||||||
|
|
||||||
mTabHost = (TabHost) view.findViewById(android.R.id.tabhost);
|
mTabHost = (TabHost) view.findViewById(android.R.id.tabhost);
|
||||||
@@ -235,18 +240,19 @@ public class IccLockSettings extends SettingsPreferenceFragment
|
|||||||
mTabHost.setOnTabChangedListener(mTabListener);
|
mTabHost.setOnTabChangedListener(mTabListener);
|
||||||
mTabHost.clearAllTabs();
|
mTabHost.clearAllTabs();
|
||||||
|
|
||||||
SubscriptionManager sm = SubscriptionManager.from(getContext());
|
final List<SubscriptionInfo> subInfoList =
|
||||||
|
mProxySubscriptionMgr.getActiveSubscriptionsInfo();
|
||||||
for (int i = 0; i < numSims; ++i) {
|
for (int i = 0; i < numSims; ++i) {
|
||||||
final SubscriptionInfo subInfo = sm.getActiveSubscriptionInfoForSimSlotIndex(i);
|
final SubscriptionInfo subInfo =
|
||||||
|
getActiveSubscriptionInfoForSimSlotIndex(subInfoList, i);
|
||||||
mTabHost.addTab(buildTabSpec(String.valueOf(i),
|
mTabHost.addTab(buildTabSpec(String.valueOf(i),
|
||||||
String.valueOf(subInfo == null
|
String.valueOf(subInfo == null
|
||||||
? getContext().getString(R.string.sim_editor_title, i + 1)
|
? getContext().getString(R.string.sim_editor_title, i + 1)
|
||||||
: subInfo.getDisplayName())));
|
: subInfo.getDisplayName())));
|
||||||
}
|
}
|
||||||
final SubscriptionInfo sir = sm.getActiveSubscriptionInfoForSimSlotIndex(0);
|
final SubscriptionInfo sir = getActiveSubscriptionInfoForSimSlotIndex(subInfoList, 0);
|
||||||
|
|
||||||
mPhone = (sir == null) ? null
|
mPhone = (sir == null) ? null : PhoneFactory.getPhone(sir.getSimSlotIndex());
|
||||||
: PhoneFactory.getPhone(SubscriptionManager.getPhoneId(sir.getSubscriptionId()));
|
|
||||||
|
|
||||||
if (savedInstanceState != null && savedInstanceState.containsKey(CURRENT_TAB)) {
|
if (savedInstanceState != null && savedInstanceState.containsKey(CURRENT_TAB)) {
|
||||||
mTabHost.setCurrentTabByTag(savedInstanceState.getString(CURRENT_TAB));
|
mTabHost.setCurrentTabByTag(savedInstanceState.getString(CURRENT_TAB));
|
||||||
@@ -456,7 +462,7 @@ public class IccLockSettings extends SettingsPreferenceFragment
|
|||||||
private void tryChangeIccLockState() {
|
private void tryChangeIccLockState() {
|
||||||
// Try to change icc lock. If it succeeds, toggle the lock state and
|
// Try to change icc lock. If it succeeds, toggle the lock state and
|
||||||
// reset dialog state. Else inject error message and show dialog again.
|
// reset dialog state. Else inject error message and show dialog again.
|
||||||
Message callback = Message.obtain(mHandler, MSG_ENABLE_ICC_PIN_COMPLETE);
|
final Message callback = Message.obtain(mHandler, MSG_ENABLE_ICC_PIN_COMPLETE);
|
||||||
mPhone.getIccCard().setIccLockEnabled(mToState, mPin, callback);
|
mPhone.getIccCard().setIccLockEnabled(mToState, mPin, callback);
|
||||||
// Disable the setting till the response is received.
|
// Disable the setting till the response is received.
|
||||||
mPinToggle.setEnabled(false);
|
mPinToggle.setEnabled(false);
|
||||||
@@ -467,7 +473,8 @@ public class IccLockSettings extends SettingsPreferenceFragment
|
|||||||
mPinToggle.setChecked(mToState);
|
mPinToggle.setChecked(mToState);
|
||||||
} else {
|
} else {
|
||||||
if (exception instanceof CommandException) {
|
if (exception instanceof CommandException) {
|
||||||
CommandException.Error err = ((CommandException)(exception)).getCommandError();
|
final CommandException.Error err =
|
||||||
|
((CommandException) exception).getCommandError();
|
||||||
if (err == CommandException.Error.PASSWORD_INCORRECT) {
|
if (err == CommandException.Error.PASSWORD_INCORRECT) {
|
||||||
createCustomTextToast(getPinPasswordErrorMessage(attemptsRemaining));
|
createCustomTextToast(getPinPasswordErrorMessage(attemptsRemaining));
|
||||||
} else {
|
} else {
|
||||||
@@ -490,9 +497,9 @@ public class IccLockSettings extends SettingsPreferenceFragment
|
|||||||
// The window type of Toast is set by NotificationManagerService.
|
// The window type of Toast is set by NotificationManagerService.
|
||||||
// It can't be overwritten by LayoutParams.type.
|
// It can't be overwritten by LayoutParams.type.
|
||||||
// Ovarlay a custom window with LayoutParams (TYPE_STATUS_BAR_PANEL) on PUK unlock screen.
|
// Ovarlay a custom window with LayoutParams (TYPE_STATUS_BAR_PANEL) on PUK unlock screen.
|
||||||
View v = ((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE))
|
final View v = ((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE))
|
||||||
.inflate(com.android.internal.R.layout.transient_notification, null);
|
.inflate(com.android.internal.R.layout.transient_notification, null);
|
||||||
TextView tv = (TextView) v.findViewById(com.android.internal.R.id.message);
|
final TextView tv = (TextView) v.findViewById(com.android.internal.R.id.message);
|
||||||
tv.setText(errorMessage);
|
tv.setText(errorMessage);
|
||||||
|
|
||||||
final WindowManager.LayoutParams params = new WindowManager.LayoutParams();
|
final WindowManager.LayoutParams params = new WindowManager.LayoutParams();
|
||||||
@@ -521,7 +528,7 @@ public class IccLockSettings extends SettingsPreferenceFragment
|
|||||||
| WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
|
| WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
|
||||||
| WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
|
| WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
|
||||||
|
|
||||||
WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
|
final WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
|
||||||
wm.addView(v, params);
|
wm.addView(v, params);
|
||||||
|
|
||||||
mHandler.postDelayed(new Runnable() {
|
mHandler.postDelayed(new Runnable() {
|
||||||
@@ -545,7 +552,7 @@ public class IccLockSettings extends SettingsPreferenceFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void tryChangePin() {
|
private void tryChangePin() {
|
||||||
Message callback = Message.obtain(mHandler, MSG_CHANGE_ICC_PIN_COMPLETE);
|
final Message callback = Message.obtain(mHandler, MSG_CHANGE_ICC_PIN_COMPLETE);
|
||||||
mPhone.getIccCard().changeIccLockPassword(mOldPin,
|
mPhone.getIccCard().changeIccLockPassword(mOldPin,
|
||||||
mNewPin, callback);
|
mNewPin, callback);
|
||||||
}
|
}
|
||||||
@@ -583,15 +590,27 @@ public class IccLockSettings extends SettingsPreferenceFragment
|
|||||||
mDialogState = OFF_MODE;
|
mDialogState = OFF_MODE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static SubscriptionInfo getActiveSubscriptionInfoForSimSlotIndex(
|
||||||
|
List<SubscriptionInfo> subInfoList, int slotId) {
|
||||||
|
if (subInfoList == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
for (SubscriptionInfo subInfo : subInfoList) {
|
||||||
|
if (subInfo.getSimSlotIndex() == slotId) {
|
||||||
|
return subInfo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private OnTabChangeListener mTabListener = new OnTabChangeListener() {
|
private OnTabChangeListener mTabListener = new OnTabChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onTabChanged(String tabId) {
|
public void onTabChanged(String tabId) {
|
||||||
final int slotId = Integer.parseInt(tabId);
|
final int slotId = Integer.parseInt(tabId);
|
||||||
final SubscriptionInfo sir = SubscriptionManager.from(getActivity().getBaseContext())
|
final SubscriptionInfo sir = getActiveSubscriptionInfoForSimSlotIndex(
|
||||||
.getActiveSubscriptionInfoForSimSlotIndex(slotId);
|
mProxySubscriptionMgr.getActiveSubscriptionsInfo(), slotId);
|
||||||
|
|
||||||
mPhone = (sir == null) ? null
|
mPhone = (sir == null) ? null : PhoneFactory.getPhone(sir.getSimSlotIndex());
|
||||||
: PhoneFactory.getPhone(SubscriptionManager.getPhoneId(sir.getSubscriptionId()));
|
|
||||||
|
|
||||||
// The User has changed tab; update the body.
|
// The User has changed tab; update the body.
|
||||||
updatePreferences();
|
updatePreferences();
|
||||||
|
@@ -42,7 +42,7 @@ public class RoamingDialogFragment extends InstrumentedDialogFragment implements
|
|||||||
|
|
||||||
public static RoamingDialogFragment newInstance(int subId) {
|
public static RoamingDialogFragment newInstance(int subId) {
|
||||||
final RoamingDialogFragment dialogFragment = new RoamingDialogFragment();
|
final RoamingDialogFragment dialogFragment = new RoamingDialogFragment();
|
||||||
Bundle args = new Bundle();
|
final Bundle args = new Bundle();
|
||||||
args.putInt(SUB_ID_KEY, subId);
|
args.putInt(SUB_ID_KEY, subId);
|
||||||
dialogFragment.setArguments(args);
|
dialogFragment.setArguments(args);
|
||||||
|
|
||||||
@@ -52,17 +52,17 @@ public class RoamingDialogFragment extends InstrumentedDialogFragment implements
|
|||||||
@Override
|
@Override
|
||||||
public void onAttach(Context context) {
|
public void onAttach(Context context) {
|
||||||
super.onAttach(context);
|
super.onAttach(context);
|
||||||
Bundle args = getArguments();
|
final Bundle args = getArguments();
|
||||||
mSubId = args.getInt(SUB_ID_KEY);
|
mSubId = args.getInt(SUB_ID_KEY);
|
||||||
mCarrierConfigManager = new CarrierConfigManager(context);
|
mCarrierConfigManager = new CarrierConfigManager(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
|
final AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
|
||||||
int title = R.string.roaming_alert_title;
|
final int title = R.string.roaming_alert_title;
|
||||||
int message = R.string.roaming_warning;
|
int message = R.string.roaming_warning;
|
||||||
PersistableBundle carrierConfig = mCarrierConfigManager.getConfigForSubId(mSubId);
|
final PersistableBundle carrierConfig = mCarrierConfigManager.getConfigForSubId(mSubId);
|
||||||
if (carrierConfig != null && carrierConfig.getBoolean(
|
if (carrierConfig != null && carrierConfig.getBoolean(
|
||||||
CarrierConfigManager.KEY_CHECK_PRICING_WITH_CARRIER_FOR_DATA_ROAMING_BOOL)) {
|
CarrierConfigManager.KEY_CHECK_PRICING_WITH_CARRIER_FOR_DATA_ROAMING_BOOL)) {
|
||||||
message = R.string.roaming_check_price_warning;
|
message = R.string.roaming_check_price_warning;
|
||||||
@@ -84,8 +84,13 @@ public class RoamingDialogFragment extends InstrumentedDialogFragment implements
|
|||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
// let the host know that the positive button has been clicked
|
// let the host know that the positive button has been clicked
|
||||||
if (which == dialog.BUTTON_POSITIVE) {
|
if (which == dialog.BUTTON_POSITIVE) {
|
||||||
TelephonyManager.from(getContext()).createForSubscriptionId(
|
final TelephonyManager telephonyManager =
|
||||||
mSubId).setDataRoamingEnabled(true);
|
getContext().getSystemService(TelephonyManager.class)
|
||||||
|
.createForSubscriptionId(mSubId);
|
||||||
|
if (telephonyManager == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
telephonyManager.setDataRoamingEnabled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -17,22 +17,20 @@
|
|||||||
package com.android.settings.network.telephony;
|
package com.android.settings.network.telephony;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.database.ContentObserver;
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.Looper;
|
|
||||||
import android.os.PersistableBundle;
|
import android.os.PersistableBundle;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.telephony.CarrierConfigManager;
|
import android.telephony.CarrierConfigManager;
|
||||||
import android.telephony.SubscriptionManager;
|
import android.telephony.SubscriptionManager;
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
import androidx.fragment.app.FragmentManager;
|
import androidx.fragment.app.FragmentManager;
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
|
import com.android.settings.network.GlobalSettingsChangeListener;
|
||||||
import com.android.settingslib.RestrictedSwitchPreference;
|
import com.android.settingslib.RestrictedSwitchPreference;
|
||||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||||
import com.android.settingslib.core.lifecycle.events.OnStart;
|
import com.android.settingslib.core.lifecycle.events.OnStart;
|
||||||
@@ -44,31 +42,59 @@ import com.android.settingslib.core.lifecycle.events.OnStop;
|
|||||||
public class RoamingPreferenceController extends TelephonyTogglePreferenceController implements
|
public class RoamingPreferenceController extends TelephonyTogglePreferenceController implements
|
||||||
LifecycleObserver, OnStart, OnStop {
|
LifecycleObserver, OnStart, OnStop {
|
||||||
|
|
||||||
|
private static final String TAG = "RoamingController";
|
||||||
private static final String DIALOG_TAG = "MobileDataDialog";
|
private static final String DIALOG_TAG = "MobileDataDialog";
|
||||||
|
|
||||||
private RestrictedSwitchPreference mSwitchPreference;
|
private RestrictedSwitchPreference mSwitchPreference;
|
||||||
private TelephonyManager mTelephonyManager;
|
private TelephonyManager mTelephonyManager;
|
||||||
private CarrierConfigManager mCarrierConfigManager;
|
private CarrierConfigManager mCarrierConfigManager;
|
||||||
private DataContentObserver mDataContentObserver;
|
|
||||||
@VisibleForTesting
|
/**
|
||||||
boolean mNeedDialog;
|
* There're 2 listeners both activated at the same time.
|
||||||
|
* For project that access DATA_ROAMING, only first listener is functional.
|
||||||
|
* For project that access "DATA_ROAMING + subId", first listener will be stopped when receiving
|
||||||
|
* any onChange from second listener.
|
||||||
|
*/
|
||||||
|
private GlobalSettingsChangeListener mListener;
|
||||||
|
private GlobalSettingsChangeListener mListenerForSubId;
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
FragmentManager mFragmentManager;
|
FragmentManager mFragmentManager;
|
||||||
|
|
||||||
public RoamingPreferenceController(Context context, String key) {
|
public RoamingPreferenceController(Context context, String key) {
|
||||||
super(context, key);
|
super(context, key);
|
||||||
mCarrierConfigManager = context.getSystemService(CarrierConfigManager.class);
|
mCarrierConfigManager = context.getSystemService(CarrierConfigManager.class);
|
||||||
mDataContentObserver = new DataContentObserver(new Handler(Looper.getMainLooper()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
mDataContentObserver.register(mContext, mSubId);
|
if (mListener == null) {
|
||||||
|
mListener = new GlobalSettingsChangeListener(mContext,
|
||||||
|
Settings.Global.DATA_ROAMING) {
|
||||||
|
public void onChanged(String field) {
|
||||||
|
updateState(mSwitchPreference);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
stopMonitorSubIdSpecific();
|
||||||
|
|
||||||
|
if (mSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
mListenerForSubId = new GlobalSettingsChangeListener(mContext,
|
||||||
|
Settings.Global.DATA_ROAMING + mSubId) {
|
||||||
|
public void onChanged(String field) {
|
||||||
|
stopMonitor();
|
||||||
|
updateState(mSwitchPreference);
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStop() {
|
public void onStop() {
|
||||||
mDataContentObserver.unRegister(mContext);
|
stopMonitor();
|
||||||
|
stopMonitorSubIdSpecific();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -87,7 +113,7 @@ public class RoamingPreferenceController extends TelephonyTogglePreferenceContro
|
|||||||
@Override
|
@Override
|
||||||
public boolean handlePreferenceTreeClick(Preference preference) {
|
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||||
if (TextUtils.equals(preference.getKey(), getPreferenceKey())) {
|
if (TextUtils.equals(preference.getKey(), getPreferenceKey())) {
|
||||||
if (mNeedDialog) {
|
if (isDialogNeeded()) {
|
||||||
showDialog();
|
showDialog();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -98,9 +124,7 @@ public class RoamingPreferenceController extends TelephonyTogglePreferenceContro
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean setChecked(boolean isChecked) {
|
public boolean setChecked(boolean isChecked) {
|
||||||
mNeedDialog = isDialogNeeded();
|
if (!isDialogNeeded()) {
|
||||||
|
|
||||||
if (!mNeedDialog) {
|
|
||||||
// Update data directly if we don't need dialog
|
// Update data directly if we don't need dialog
|
||||||
mTelephonyManager.setDataRoamingEnabled(isChecked);
|
mTelephonyManager.setDataRoamingEnabled(isChecked);
|
||||||
return true;
|
return true;
|
||||||
@@ -141,7 +165,18 @@ public class RoamingPreferenceController extends TelephonyTogglePreferenceContro
|
|||||||
public void init(FragmentManager fragmentManager, int subId) {
|
public void init(FragmentManager fragmentManager, int subId) {
|
||||||
mFragmentManager = fragmentManager;
|
mFragmentManager = fragmentManager;
|
||||||
mSubId = subId;
|
mSubId = subId;
|
||||||
mTelephonyManager = TelephonyManager.from(mContext).createForSubscriptionId(mSubId);
|
mTelephonyManager = mContext.getSystemService(TelephonyManager.class);
|
||||||
|
if (mSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final TelephonyManager telephonyManager = mTelephonyManager
|
||||||
|
.createForSubscriptionId(mSubId);
|
||||||
|
if (telephonyManager == null) {
|
||||||
|
Log.w(TAG, "fail to init in sub" + mSubId);
|
||||||
|
mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mTelephonyManager = telephonyManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showDialog() {
|
private void showDialog() {
|
||||||
@@ -150,32 +185,17 @@ public class RoamingPreferenceController extends TelephonyTogglePreferenceContro
|
|||||||
dialogFragment.show(mFragmentManager, DIALOG_TAG);
|
dialogFragment.show(mFragmentManager, DIALOG_TAG);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private void stopMonitor() {
|
||||||
* Listener that listens data roaming change
|
if (mListener != null) {
|
||||||
*/
|
mListener.close();
|
||||||
public class DataContentObserver extends ContentObserver {
|
mListener = null;
|
||||||
|
}
|
||||||
public DataContentObserver(Handler handler) {
|
|
||||||
super(handler);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private void stopMonitorSubIdSpecific() {
|
||||||
public void onChange(boolean selfChange) {
|
if (mListenerForSubId != null) {
|
||||||
super.onChange(selfChange);
|
mListenerForSubId.close();
|
||||||
updateState(mSwitchPreference);
|
mListenerForSubId = null;
|
||||||
}
|
|
||||||
|
|
||||||
public void register(Context context, int subId) {
|
|
||||||
Uri uri = Settings.Global.getUriFor(Settings.Global.DATA_ROAMING);
|
|
||||||
if (TelephonyManager.getDefault().getSimCount() != 1) {
|
|
||||||
uri = Settings.Global.getUriFor(Settings.Global.DATA_ROAMING + subId);
|
|
||||||
}
|
|
||||||
context.getContentResolver().registerContentObserver(uri, false, this);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void unRegister(Context context) {
|
|
||||||
context.getContentResolver().unregisterContentObserver(this);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -80,7 +80,7 @@ public class RoamingPreferenceControllerTest {
|
|||||||
doReturn(mFragmentTransaction).when(mFragmentManager).beginTransaction();
|
doReturn(mFragmentTransaction).when(mFragmentManager).beginTransaction();
|
||||||
|
|
||||||
mPreference = spy(new RestrictedSwitchPreference(mContext));
|
mPreference = spy(new RestrictedSwitchPreference(mContext));
|
||||||
mController = new RoamingPreferenceController(mContext, "roaming");
|
mController = spy(new RoamingPreferenceController(mContext, "roaming"));
|
||||||
mController.init(mFragmentManager, SUB_ID);
|
mController.init(mFragmentManager, SUB_ID);
|
||||||
mPreference.setKey(mController.getPreferenceKey());
|
mPreference.setKey(mController.getPreferenceKey());
|
||||||
}
|
}
|
||||||
@@ -118,7 +118,7 @@ public class RoamingPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void handlePreferenceTreeClick_needDialog_showDialog() {
|
public void handlePreferenceTreeClick_needDialog_showDialog() {
|
||||||
mController.mNeedDialog = true;
|
doReturn(true).when(mController).isDialogNeeded();
|
||||||
|
|
||||||
mController.handlePreferenceTreeClick(mPreference);
|
mController.handlePreferenceTreeClick(mPreference);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user