summaryrefslogtreecommitdiffstats
path: root/src/com/cyanogenmod/setupwizard/setup
diff options
context:
space:
mode:
authorcretin45 <cretin45@gmail.com>2015-08-19 11:57:53 -0700
committercretin45 <cretin45@gmail.com>2015-08-19 12:01:08 -0700
commit4ef509ac489465cb0a7a9679b39f2b029634a869 (patch)
treec2916b95addea44c44f0ed855e5bacca15ce8768 /src/com/cyanogenmod/setupwizard/setup
parentc924af3b3314056d02c3a8cd81b0ac8f53b9ea60 (diff)
downloadpackages_apps_SetupWizard-4ef509ac489465cb0a7a9679b39f2b029634a869.zip
packages_apps_SetupWizard-4ef509ac489465cb0a7a9679b39f2b029634a869.tar.gz
packages_apps_SetupWizard-4ef509ac489465cb0a7a9679b39f2b029634a869.tar.bz2
SetupWizard: Improve wait for data sim change logic
Invalid sims and bad connections causes huge delays when switching. This disallows switching to invalid sims. It also fixes a bug were the next button would get enabled while waiting on a switch. CRACKLING-503 Change-Id: I6cf7391910cc23554bb418c3083e736a3f06e037
Diffstat (limited to 'src/com/cyanogenmod/setupwizard/setup')
-rw-r--r--src/com/cyanogenmod/setupwizard/setup/ChooseDataSimPage.java77
1 files changed, 52 insertions, 25 deletions
diff --git a/src/com/cyanogenmod/setupwizard/setup/ChooseDataSimPage.java b/src/com/cyanogenmod/setupwizard/setup/ChooseDataSimPage.java
index e053399..082913d 100644
--- a/src/com/cyanogenmod/setupwizard/setup/ChooseDataSimPage.java
+++ b/src/com/cyanogenmod/setupwizard/setup/ChooseDataSimPage.java
@@ -51,8 +51,6 @@ public class ChooseDataSimPage extends SetupPage {
public static final String TAG = "ChooseDataSimPage";
- private static final String CHANGE_DATA_SIM_ID_EXTRA = ".changingToId";
-
public ChooseDataSimPage(Context context, SetupDataCallbacks callbacks) {
super(context, callbacks);
}
@@ -104,7 +102,13 @@ public class ChooseDataSimPage extends SetupPage {
private SubscriptionManager mSubscriptionManager;
private int mCurrentDataPhoneId;
- private int mChangingToDataPhoneId;
+
+ // 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 boolean mDisabledForSwitch = false;
private final Handler mHandler = new Handler();
@@ -179,9 +183,9 @@ public class ChooseDataSimPage extends SetupPage {
mContext = getActivity().getApplicationContext();
mSubscriptionManager = SubscriptionManager.from(mContext);
mCurrentDataPhoneId = mSubscriptionManager.getDefaultDataPhoneId();
- mChangingToDataPhoneId = (savedInstanceState == null) ?
- mCurrentDataPhoneId :
- savedInstanceState.getInt(CHANGE_DATA_SIM_ID_EXTRA, mCurrentDataPhoneId);
+ if (sChangingToDataPhoneId == -1) {
+ sChangingToDataPhoneId = mCurrentDataPhoneId;
+ }
}
@Override
@@ -206,11 +210,6 @@ public class ChooseDataSimPage extends SetupPage {
}
@Override
- public void onSaveInstanceState(Bundle outState) {
- outState.putInt(CHANGE_DATA_SIM_ID_EXTRA, mChangingToDataPhoneId);
- }
-
- @Override
public void onPause() {
super.onPause();
mIsAttached = false;
@@ -238,7 +237,18 @@ public class ChooseDataSimPage extends SetupPage {
@Override
public void onDataConnectionStateChanged(int state) {
- mCurrentDataPhoneId = mSubscriptionManager.getDefaultDataPhoneId();
+ final int dataPhoneId = mSubscriptionManager.getDefaultDataPhoneId();
+ // In case the default sub changes from elsewhere. This shouldn't happen,
+ // but testcases can induce this.
+ if (dataPhoneId != mCurrentDataPhoneId &&
+ dataPhoneId != sChangingToDataPhoneId) {
+ sChangingToDataPhoneId = dataPhoneId;
+ updateCurrentDataSub();
+ }
+ if (mCurrentDataPhoneId != dataPhoneId) {
+ mCurrentDataPhoneId = dataPhoneId;
+ updateCurrentDataSub();
+ }
checkSimChangingState();
}
};
@@ -247,15 +257,14 @@ public class ChooseDataSimPage extends SetupPage {
private void checkForRadioReady() {
if (mRadioReady) {
mHandler.removeCallbacks(mRadioReadyRunnable);
- hideProgress();
- mNextButton.setEnabled(true);
showPage();
+ checkSimChangingState();
return;
} else {
if (mTitleView != null) {
mTitleView.setText(R.string.loading);
}
- mNextButton.setEnabled(false);
+ enableViews(false);
showProgress();
if (!mHandler.hasCallbacks(mRadioReadyRunnable)) {
mHandler.postDelayed(mRadioReadyRunnable, SetupWizardApp.RADIO_READY_TIMEOUT);
@@ -302,8 +311,8 @@ public class ChooseDataSimPage extends SetupPage {
}
private void changeDataSub(SubscriptionInfo subInfoRecord) {
- if (mChangingToDataPhoneId != subInfoRecord.getSimSlotIndex()) {
- mChangingToDataPhoneId = subInfoRecord.getSimSlotIndex();
+ if (sChangingToDataPhoneId != subInfoRecord.getSimSlotIndex()) {
+ sChangingToDataPhoneId = subInfoRecord.getSimSlotIndex();
mSubscriptionManager.setDefaultDataSubId(subInfoRecord.getSubscriptionId());
setDataSubChecked(subInfoRecord);
}
@@ -312,14 +321,12 @@ public class ChooseDataSimPage extends SetupPage {
private void checkSimChangingState() {
if (mIsAttached && mRadioReady) {
- if (mCurrentDataPhoneId != mChangingToDataPhoneId) {
+ if (mCurrentDataPhoneId != sChangingToDataPhoneId) {
showProgress();
- mNextButton.setEnabled(false);
- enableRows(false);
+ enableViews(false);
} else {
hideProgress();
- mNextButton.setEnabled(true);
- enableRows(true);
+ enableViews(true);
}
}
}
@@ -350,9 +357,20 @@ public class ChooseDataSimPage extends SetupPage {
}
}
+ private void enableViews(boolean enabled) {
+ mDisabledForSwitch = !enabled;
+ enableRows(enabled);
+ mNextButton.setEnabled(enabled);
+ }
+
private void enableRows(boolean enabled) {
for (int i = 0; i < mRows.size(); i++) {
- mRows.get(i).setEnabled(enabled);
+ final View v = mRows.get(i);
+ v.setEnabled(enabled);
+ final SubscriptionInfo subInfoRecord = (SubscriptionInfo)v.getTag();
+ if (subInfoRecord != null) {
+ updateCarrierText(subInfoRecord);
+ }
}
}
@@ -360,17 +378,26 @@ public class ChooseDataSimPage extends SetupPage {
if (mIsAttached) {
String name = mPhone.getNetworkOperatorName(subInfoRecord.getSubscriptionId());
ServiceState serviceState = mServiceStates.get(subInfoRecord.getSimSlotIndex());
+ final int slot = subInfoRecord.getSimSlotIndex();
+ final View v = mRows.get(slot);
if (TextUtils.isEmpty(name)) {
if (serviceState != null && serviceState.isEmergencyOnly()) {
name = getString(R.string.setup_mobile_data_emergency_only);
} else {
name = getString(R.string.setup_mobile_data_no_service);
}
+ if (v != null) {
+ v.setEnabled(false);
+ }
+ } else {
+ if (v != null && !mDisabledForSwitch) {
+ v.setEnabled(true);
+ }
}
String formattedName =
getString(R.string.data_sim_name,
- subInfoRecord.getSimSlotIndex() + 1, name);
- mNameViews.get(subInfoRecord.getSimSlotIndex()).setText(formattedName);
+ slot + 1, name);
+ mNameViews.get(slot).setText(formattedName);
}
}