Disable "Mobile data" in "Data usage" if no SIM.
If SIM is taken out, we disable "Mobile data" button in "Data usage" page. Bug: 67408951 Test: manual Change-Id: I9f8937eadd5494f4f7710b9d5431176a13324bdd
This commit is contained in:
@@ -25,6 +25,7 @@ import android.os.Looper;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.provider.Settings.Global;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.support.v4.content.res.TypedArrayUtils;
|
||||
import android.support.v7.preference.PreferenceViewHolder;
|
||||
import android.telephony.SubscriptionInfo;
|
||||
@@ -51,7 +52,8 @@ public class CellDataPreference extends CustomDialogPreference implements Templa
|
||||
public boolean mChecked;
|
||||
public boolean mMultiSimDialog;
|
||||
private TelephonyManager mTelephonyManager;
|
||||
private SubscriptionManager mSubscriptionManager;
|
||||
@VisibleForTesting
|
||||
SubscriptionManager mSubscriptionManager;
|
||||
|
||||
public CellDataPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs, TypedArrayUtils.getAttr(context,
|
||||
@@ -85,12 +87,19 @@ public class CellDataPreference extends CustomDialogPreference implements Templa
|
||||
@Override
|
||||
public void onAttached() {
|
||||
super.onAttached();
|
||||
mListener.setListener(true, mSubId, getContext());
|
||||
mDataStateListener.setListener(true, mSubId, getContext());
|
||||
if (mSubscriptionManager!= null) {
|
||||
mSubscriptionManager.addOnSubscriptionsChangedListener(mOnSubscriptionsChangeListener);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetached() {
|
||||
mListener.setListener(false, mSubId, getContext());
|
||||
mDataStateListener.setListener(false, mSubId, getContext());
|
||||
if (mSubscriptionManager!= null) {
|
||||
mSubscriptionManager.removeOnSubscriptionsChangedListener(
|
||||
mOnSubscriptionsChangeListener);
|
||||
}
|
||||
super.onDetached();
|
||||
}
|
||||
|
||||
@@ -101,10 +110,14 @@ public class CellDataPreference extends CustomDialogPreference implements Templa
|
||||
}
|
||||
mSubscriptionManager = SubscriptionManager.from(getContext());
|
||||
mTelephonyManager = TelephonyManager.from(getContext());
|
||||
|
||||
mSubscriptionManager.addOnSubscriptionsChangedListener(mOnSubscriptionsChangeListener);
|
||||
|
||||
if (mSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
|
||||
mSubId = subId;
|
||||
setKey(getKey() + subId);
|
||||
}
|
||||
updateEnabled();
|
||||
updateChecked();
|
||||
}
|
||||
|
||||
@@ -112,6 +125,12 @@ public class CellDataPreference extends CustomDialogPreference implements Templa
|
||||
setChecked(mTelephonyManager.getDataEnabled(mSubId));
|
||||
}
|
||||
|
||||
private void updateEnabled() {
|
||||
// If this subscription is not active, for example, SIM card is taken out, we disable
|
||||
// the button.
|
||||
setEnabled(mSubscriptionManager.getActiveSubscriptionInfo(mSubId) != null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void performClick(View view) {
|
||||
final Context context = getContext();
|
||||
@@ -237,7 +256,19 @@ public class CellDataPreference extends CustomDialogPreference implements Templa
|
||||
}
|
||||
}
|
||||
|
||||
private final DataStateListener mListener = new DataStateListener() {
|
||||
@VisibleForTesting
|
||||
final SubscriptionManager.OnSubscriptionsChangedListener mOnSubscriptionsChangeListener
|
||||
= new SubscriptionManager.OnSubscriptionsChangedListener() {
|
||||
@Override
|
||||
public void onSubscriptionsChanged() {
|
||||
if (DataUsageSummary.LOGD) {
|
||||
Log.d(TAG, "onSubscriptionsChanged");
|
||||
}
|
||||
updateEnabled();
|
||||
}
|
||||
};
|
||||
|
||||
private final DataStateListener mDataStateListener = new DataStateListener() {
|
||||
@Override
|
||||
public void onChange(boolean selfChange) {
|
||||
updateChecked();
|
||||
|
Reference in New Issue
Block a user