ChooseDataSim: Use the extra data from the intent to validate the sub
Instead of waiting for the telephony stack to catch up to the default, take advantage of the fact that the intent already carries the ID as an extra. Also, we were using slotId and phoneId interchangeably, and they're not the same thing. While it's likely they'll match on a freshly reset phone, don't assume that. Index everything to subId for consistency. Ref CYNGNOS-3126 Change-Id: Ibcd767d0124b05d669886190f5d9a98f1a6e5bd7
This commit is contained in:
parent
07c44c4467
commit
3ebea2fb6d
@ -43,6 +43,7 @@ import android.widget.ImageView;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.internal.telephony.PhoneConstants;
|
||||
import com.android.internal.telephony.TelephonyIntents;
|
||||
|
||||
import com.cyanogenmod.setupwizard.R;
|
||||
@ -107,12 +108,12 @@ public class ChooseDataSimPage extends SetupPage {
|
||||
private Context mContext;
|
||||
private SubscriptionManager mSubscriptionManager;
|
||||
|
||||
private int mCurrentDataPhoneId;
|
||||
private int mCurrentDataSubId;
|
||||
|
||||
// This is static because a user can click back mid operation.
|
||||
// We want to persist what the user was changing to because of the
|
||||
// async callback can sometimes take a long time.
|
||||
private static int sChangingToDataPhoneId = -1;
|
||||
private static int sChangingToDataSubId = -1;
|
||||
|
||||
private boolean mDisabledForSwitch = false;
|
||||
|
||||
@ -133,8 +134,7 @@ public class ChooseDataSimPage extends SetupPage {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
SubscriptionInfo subInfoRecord = (SubscriptionInfo)view.getTag();
|
||||
if (subInfoRecord != null &&
|
||||
subInfoRecord.getSimSlotIndex() != mCurrentDataPhoneId) {
|
||||
if (subInfoRecord != null) {
|
||||
changeDataSub(subInfoRecord);
|
||||
}
|
||||
}
|
||||
@ -188,9 +188,9 @@ public class ChooseDataSimPage extends SetupPage {
|
||||
super.onCreate(savedInstanceState);
|
||||
mContext = getActivity().getApplicationContext();
|
||||
mSubscriptionManager = SubscriptionManager.from(mContext);
|
||||
mCurrentDataPhoneId = mSubscriptionManager.getDefaultDataPhoneId();
|
||||
if (sChangingToDataPhoneId == -1) {
|
||||
sChangingToDataPhoneId = mCurrentDataPhoneId;
|
||||
mCurrentDataSubId = mSubscriptionManager.getDefaultDataSubId();
|
||||
if (sChangingToDataSubId == -1) {
|
||||
sChangingToDataSubId = mCurrentDataSubId;
|
||||
}
|
||||
}
|
||||
|
||||
@ -230,9 +230,8 @@ public class ChooseDataSimPage extends SetupPage {
|
||||
getActivity().unregisterReceiver(mIntentReceiver);
|
||||
}
|
||||
|
||||
private void ddsHasChanged() {
|
||||
mCurrentDataPhoneId = mSubscriptionManager.getDefaultDataPhoneId();
|
||||
if (mCurrentDataPhoneId == sChangingToDataPhoneId) {
|
||||
private void ddsHasChanged(int subId) {
|
||||
if (subId == sChangingToDataSubId) {
|
||||
hideProgress();
|
||||
enableViews(true);
|
||||
}
|
||||
@ -257,16 +256,16 @@ public class ChooseDataSimPage extends SetupPage {
|
||||
|
||||
@Override
|
||||
public void onDataConnectionStateChanged(int state) {
|
||||
final int dataPhoneId = mSubscriptionManager.getDefaultDataPhoneId();
|
||||
final int dataSubId = mSubscriptionManager.getDefaultDataSubId();
|
||||
// In case the default sub changes from elsewhere. This shouldn't happen,
|
||||
// but testcases can induce this.
|
||||
if (dataPhoneId != mCurrentDataPhoneId &&
|
||||
dataPhoneId != sChangingToDataPhoneId) {
|
||||
sChangingToDataPhoneId = dataPhoneId;
|
||||
if (dataSubId != mCurrentDataSubId &&
|
||||
dataSubId != sChangingToDataSubId) {
|
||||
sChangingToDataSubId = dataSubId;
|
||||
updateCurrentDataSub();
|
||||
}
|
||||
if (mCurrentDataPhoneId != dataPhoneId) {
|
||||
mCurrentDataPhoneId = dataPhoneId;
|
||||
if (mCurrentDataSubId != dataSubId) {
|
||||
mCurrentDataSubId = dataSubId;
|
||||
updateCurrentDataSub();
|
||||
}
|
||||
checkSimChangingState();
|
||||
@ -331,9 +330,9 @@ public class ChooseDataSimPage extends SetupPage {
|
||||
}
|
||||
|
||||
private void changeDataSub(SubscriptionInfo subInfoRecord) {
|
||||
if (sChangingToDataPhoneId != subInfoRecord.getSimSlotIndex()) {
|
||||
sChangingToDataPhoneId = subInfoRecord.getSimSlotIndex();
|
||||
mSubscriptionManager.setDefaultDataSubId(subInfoRecord.getSubscriptionId());
|
||||
if (sChangingToDataSubId != subInfoRecord.getSubscriptionId()) {
|
||||
sChangingToDataSubId = subInfoRecord.getSubscriptionId();
|
||||
mSubscriptionManager.setDefaultDataSubId(sChangingToDataSubId);
|
||||
setDataSubChecked(subInfoRecord);
|
||||
}
|
||||
checkSimChangingState();
|
||||
@ -341,7 +340,7 @@ public class ChooseDataSimPage extends SetupPage {
|
||||
|
||||
private void checkSimChangingState() {
|
||||
if (mIsAttached && mRadioReady) {
|
||||
if (mCurrentDataPhoneId != sChangingToDataPhoneId) {
|
||||
if (mCurrentDataSubId != sChangingToDataSubId) {
|
||||
showProgress();
|
||||
enableViews(false);
|
||||
} else {
|
||||
@ -371,8 +370,8 @@ public class ChooseDataSimPage extends SetupPage {
|
||||
if (mIsAttached) {
|
||||
for (int i = 0; i < mSubInfoRecords.size(); i++) {
|
||||
SubscriptionInfo subInfoRecord = mSubInfoRecords.valueAt(i);
|
||||
mCheckBoxes.get(i).setChecked(mSubscriptionManager.getDefaultDataPhoneId()
|
||||
== subInfoRecord.getSimSlotIndex());
|
||||
mCheckBoxes.get(i).setChecked(mSubscriptionManager.getDefaultDataSubId()
|
||||
== subInfoRecord.getSubscriptionId());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -487,7 +486,7 @@ public class ChooseDataSimPage extends SetupPage {
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
final Activity activity = getActivity();
|
||||
if (activity != null) {
|
||||
ddsHasChanged();
|
||||
ddsHasChanged(intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY, -1));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user