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
This commit is contained in:
parent
c924af3b33
commit
4ef509ac48
|
@ -51,8 +51,6 @@ public class ChooseDataSimPage extends SetupPage {
|
||||||
|
|
||||||
public static final String TAG = "ChooseDataSimPage";
|
public static final String TAG = "ChooseDataSimPage";
|
||||||
|
|
||||||
private static final String CHANGE_DATA_SIM_ID_EXTRA = ".changingToId";
|
|
||||||
|
|
||||||
public ChooseDataSimPage(Context context, SetupDataCallbacks callbacks) {
|
public ChooseDataSimPage(Context context, SetupDataCallbacks callbacks) {
|
||||||
super(context, callbacks);
|
super(context, callbacks);
|
||||||
}
|
}
|
||||||
|
@ -104,7 +102,13 @@ public class ChooseDataSimPage extends SetupPage {
|
||||||
private SubscriptionManager mSubscriptionManager;
|
private SubscriptionManager mSubscriptionManager;
|
||||||
|
|
||||||
private int mCurrentDataPhoneId;
|
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();
|
private final Handler mHandler = new Handler();
|
||||||
|
|
||||||
|
@ -179,9 +183,9 @@ public class ChooseDataSimPage extends SetupPage {
|
||||||
mContext = getActivity().getApplicationContext();
|
mContext = getActivity().getApplicationContext();
|
||||||
mSubscriptionManager = SubscriptionManager.from(mContext);
|
mSubscriptionManager = SubscriptionManager.from(mContext);
|
||||||
mCurrentDataPhoneId = mSubscriptionManager.getDefaultDataPhoneId();
|
mCurrentDataPhoneId = mSubscriptionManager.getDefaultDataPhoneId();
|
||||||
mChangingToDataPhoneId = (savedInstanceState == null) ?
|
if (sChangingToDataPhoneId == -1) {
|
||||||
mCurrentDataPhoneId :
|
sChangingToDataPhoneId = mCurrentDataPhoneId;
|
||||||
savedInstanceState.getInt(CHANGE_DATA_SIM_ID_EXTRA, mCurrentDataPhoneId);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -205,11 +209,6 @@ public class ChooseDataSimPage extends SetupPage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSaveInstanceState(Bundle outState) {
|
|
||||||
outState.putInt(CHANGE_DATA_SIM_ID_EXTRA, mChangingToDataPhoneId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPause() {
|
public void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
|
@ -238,7 +237,18 @@ public class ChooseDataSimPage extends SetupPage {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDataConnectionStateChanged(int state) {
|
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();
|
checkSimChangingState();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -247,15 +257,14 @@ public class ChooseDataSimPage extends SetupPage {
|
||||||
private void checkForRadioReady() {
|
private void checkForRadioReady() {
|
||||||
if (mRadioReady) {
|
if (mRadioReady) {
|
||||||
mHandler.removeCallbacks(mRadioReadyRunnable);
|
mHandler.removeCallbacks(mRadioReadyRunnable);
|
||||||
hideProgress();
|
|
||||||
mNextButton.setEnabled(true);
|
|
||||||
showPage();
|
showPage();
|
||||||
|
checkSimChangingState();
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
if (mTitleView != null) {
|
if (mTitleView != null) {
|
||||||
mTitleView.setText(R.string.loading);
|
mTitleView.setText(R.string.loading);
|
||||||
}
|
}
|
||||||
mNextButton.setEnabled(false);
|
enableViews(false);
|
||||||
showProgress();
|
showProgress();
|
||||||
if (!mHandler.hasCallbacks(mRadioReadyRunnable)) {
|
if (!mHandler.hasCallbacks(mRadioReadyRunnable)) {
|
||||||
mHandler.postDelayed(mRadioReadyRunnable, SetupWizardApp.RADIO_READY_TIMEOUT);
|
mHandler.postDelayed(mRadioReadyRunnable, SetupWizardApp.RADIO_READY_TIMEOUT);
|
||||||
|
@ -302,8 +311,8 @@ public class ChooseDataSimPage extends SetupPage {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void changeDataSub(SubscriptionInfo subInfoRecord) {
|
private void changeDataSub(SubscriptionInfo subInfoRecord) {
|
||||||
if (mChangingToDataPhoneId != subInfoRecord.getSimSlotIndex()) {
|
if (sChangingToDataPhoneId != subInfoRecord.getSimSlotIndex()) {
|
||||||
mChangingToDataPhoneId = subInfoRecord.getSimSlotIndex();
|
sChangingToDataPhoneId = subInfoRecord.getSimSlotIndex();
|
||||||
mSubscriptionManager.setDefaultDataSubId(subInfoRecord.getSubscriptionId());
|
mSubscriptionManager.setDefaultDataSubId(subInfoRecord.getSubscriptionId());
|
||||||
setDataSubChecked(subInfoRecord);
|
setDataSubChecked(subInfoRecord);
|
||||||
}
|
}
|
||||||
|
@ -312,14 +321,12 @@ public class ChooseDataSimPage extends SetupPage {
|
||||||
|
|
||||||
private void checkSimChangingState() {
|
private void checkSimChangingState() {
|
||||||
if (mIsAttached && mRadioReady) {
|
if (mIsAttached && mRadioReady) {
|
||||||
if (mCurrentDataPhoneId != mChangingToDataPhoneId) {
|
if (mCurrentDataPhoneId != sChangingToDataPhoneId) {
|
||||||
showProgress();
|
showProgress();
|
||||||
mNextButton.setEnabled(false);
|
enableViews(false);
|
||||||
enableRows(false);
|
|
||||||
} else {
|
} else {
|
||||||
hideProgress();
|
hideProgress();
|
||||||
mNextButton.setEnabled(true);
|
enableViews(true);
|
||||||
enableRows(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) {
|
private void enableRows(boolean enabled) {
|
||||||
for (int i = 0; i < mRows.size(); i++) {
|
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) {
|
if (mIsAttached) {
|
||||||
String name = mPhone.getNetworkOperatorName(subInfoRecord.getSubscriptionId());
|
String name = mPhone.getNetworkOperatorName(subInfoRecord.getSubscriptionId());
|
||||||
ServiceState serviceState = mServiceStates.get(subInfoRecord.getSimSlotIndex());
|
ServiceState serviceState = mServiceStates.get(subInfoRecord.getSimSlotIndex());
|
||||||
|
final int slot = subInfoRecord.getSimSlotIndex();
|
||||||
|
final View v = mRows.get(slot);
|
||||||
if (TextUtils.isEmpty(name)) {
|
if (TextUtils.isEmpty(name)) {
|
||||||
if (serviceState != null && serviceState.isEmergencyOnly()) {
|
if (serviceState != null && serviceState.isEmergencyOnly()) {
|
||||||
name = getString(R.string.setup_mobile_data_emergency_only);
|
name = getString(R.string.setup_mobile_data_emergency_only);
|
||||||
} else {
|
} else {
|
||||||
name = getString(R.string.setup_mobile_data_no_service);
|
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 =
|
String formattedName =
|
||||||
getString(R.string.data_sim_name,
|
getString(R.string.data_sim_name,
|
||||||
subInfoRecord.getSimSlotIndex() + 1, name);
|
slot + 1, name);
|
||||||
mNameViews.get(subInfoRecord.getSimSlotIndex()).setText(formattedName);
|
mNameViews.get(slot).setText(formattedName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue