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:
Ricardo Cerqueira 2016-07-12 15:13:28 +01:00 committed by Gerrit Code Review
parent 07c44c4467
commit 3ebea2fb6d

View File

@ -43,6 +43,7 @@ import android.widget.ImageView;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
import com.android.internal.telephony.PhoneConstants;
import com.android.internal.telephony.TelephonyIntents; import com.android.internal.telephony.TelephonyIntents;
import com.cyanogenmod.setupwizard.R; import com.cyanogenmod.setupwizard.R;
@ -107,12 +108,12 @@ public class ChooseDataSimPage extends SetupPage {
private Context mContext; private Context mContext;
private SubscriptionManager mSubscriptionManager; private SubscriptionManager mSubscriptionManager;
private int mCurrentDataPhoneId; private int mCurrentDataSubId;
// This is static because a user can click back mid operation. // This is static because a user can click back mid operation.
// We want to persist what the user was changing to because of the // We want to persist what the user was changing to because of the
// async callback can sometimes take a long time. // async callback can sometimes take a long time.
private static int sChangingToDataPhoneId = -1; private static int sChangingToDataSubId = -1;
private boolean mDisabledForSwitch = false; private boolean mDisabledForSwitch = false;
@ -133,8 +134,7 @@ public class ChooseDataSimPage extends SetupPage {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
SubscriptionInfo subInfoRecord = (SubscriptionInfo)view.getTag(); SubscriptionInfo subInfoRecord = (SubscriptionInfo)view.getTag();
if (subInfoRecord != null && if (subInfoRecord != null) {
subInfoRecord.getSimSlotIndex() != mCurrentDataPhoneId) {
changeDataSub(subInfoRecord); changeDataSub(subInfoRecord);
} }
} }
@ -188,9 +188,9 @@ public class ChooseDataSimPage extends SetupPage {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
mContext = getActivity().getApplicationContext(); mContext = getActivity().getApplicationContext();
mSubscriptionManager = SubscriptionManager.from(mContext); mSubscriptionManager = SubscriptionManager.from(mContext);
mCurrentDataPhoneId = mSubscriptionManager.getDefaultDataPhoneId(); mCurrentDataSubId = mSubscriptionManager.getDefaultDataSubId();
if (sChangingToDataPhoneId == -1) { if (sChangingToDataSubId == -1) {
sChangingToDataPhoneId = mCurrentDataPhoneId; sChangingToDataSubId = mCurrentDataSubId;
} }
} }
@ -230,9 +230,8 @@ public class ChooseDataSimPage extends SetupPage {
getActivity().unregisterReceiver(mIntentReceiver); getActivity().unregisterReceiver(mIntentReceiver);
} }
private void ddsHasChanged() { private void ddsHasChanged(int subId) {
mCurrentDataPhoneId = mSubscriptionManager.getDefaultDataPhoneId(); if (subId == sChangingToDataSubId) {
if (mCurrentDataPhoneId == sChangingToDataPhoneId) {
hideProgress(); hideProgress();
enableViews(true); enableViews(true);
} }
@ -257,16 +256,16 @@ public class ChooseDataSimPage extends SetupPage {
@Override @Override
public void onDataConnectionStateChanged(int state) { 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, // In case the default sub changes from elsewhere. This shouldn't happen,
// but testcases can induce this. // but testcases can induce this.
if (dataPhoneId != mCurrentDataPhoneId && if (dataSubId != mCurrentDataSubId &&
dataPhoneId != sChangingToDataPhoneId) { dataSubId != sChangingToDataSubId) {
sChangingToDataPhoneId = dataPhoneId; sChangingToDataSubId = dataSubId;
updateCurrentDataSub(); updateCurrentDataSub();
} }
if (mCurrentDataPhoneId != dataPhoneId) { if (mCurrentDataSubId != dataSubId) {
mCurrentDataPhoneId = dataPhoneId; mCurrentDataSubId = dataSubId;
updateCurrentDataSub(); updateCurrentDataSub();
} }
checkSimChangingState(); checkSimChangingState();
@ -331,9 +330,9 @@ public class ChooseDataSimPage extends SetupPage {
} }
private void changeDataSub(SubscriptionInfo subInfoRecord) { private void changeDataSub(SubscriptionInfo subInfoRecord) {
if (sChangingToDataPhoneId != subInfoRecord.getSimSlotIndex()) { if (sChangingToDataSubId != subInfoRecord.getSubscriptionId()) {
sChangingToDataPhoneId = subInfoRecord.getSimSlotIndex(); sChangingToDataSubId = subInfoRecord.getSubscriptionId();
mSubscriptionManager.setDefaultDataSubId(subInfoRecord.getSubscriptionId()); mSubscriptionManager.setDefaultDataSubId(sChangingToDataSubId);
setDataSubChecked(subInfoRecord); setDataSubChecked(subInfoRecord);
} }
checkSimChangingState(); checkSimChangingState();
@ -341,7 +340,7 @@ public class ChooseDataSimPage extends SetupPage {
private void checkSimChangingState() { private void checkSimChangingState() {
if (mIsAttached && mRadioReady) { if (mIsAttached && mRadioReady) {
if (mCurrentDataPhoneId != sChangingToDataPhoneId) { if (mCurrentDataSubId != sChangingToDataSubId) {
showProgress(); showProgress();
enableViews(false); enableViews(false);
} else { } else {
@ -371,8 +370,8 @@ public class ChooseDataSimPage extends SetupPage {
if (mIsAttached) { if (mIsAttached) {
for (int i = 0; i < mSubInfoRecords.size(); i++) { for (int i = 0; i < mSubInfoRecords.size(); i++) {
SubscriptionInfo subInfoRecord = mSubInfoRecords.valueAt(i); SubscriptionInfo subInfoRecord = mSubInfoRecords.valueAt(i);
mCheckBoxes.get(i).setChecked(mSubscriptionManager.getDefaultDataPhoneId() mCheckBoxes.get(i).setChecked(mSubscriptionManager.getDefaultDataSubId()
== subInfoRecord.getSimSlotIndex()); == subInfoRecord.getSubscriptionId());
} }
} }
} }
@ -487,7 +486,7 @@ public class ChooseDataSimPage extends SetupPage {
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
final Activity activity = getActivity(); final Activity activity = getActivity();
if (activity != null) { if (activity != null) {
ddsHasChanged(); ddsHasChanged(intent.getIntExtra(PhoneConstants.SUBSCRIPTION_KEY, -1));
} }
} }
}; };