Re-use CdmaOptions and GsmUmtsOptions instances.
When updating Mobile network settings UI page, we now reuse instances
of CdmaOptions / GsmUmtsOptions and preferences inside them, if
possible, instead of always creating them. This is more efficient.
And it eliminates issues where dialog and service could link to
deprecated instances.
Show progress bar when turning "Automatically select network" on.
Bug: 63538855
Test: manual
Change-Id: If84c742bb498f36187c4460025dc5675e5ce906c
diff --git a/res/xml/cdma_options.xml b/res/xml/cdma_options.xml
index c86787b..8a41f87 100644
--- a/res/xml/cdma_options.xml
+++ b/res/xml/cdma_options.xml
@@ -33,21 +33,23 @@
android:entryValues="@array/cdma_subscription_values"
android:dialogTitle="@string/cdma_subscription_dialogtitle" />
- <PreferenceScreen
- android:key="button_apn_key_cdma"
- android:title="@string/apn_settings"
- android:persistent="false">
-
+ <!--We want separate APN setting from reset of settings because-->
+ <!--we want user to change it with caution.-->
+ <PreferenceCategory
+ android:key="category_cdma_apn_key">
<!-- The launching Intent will be defined thru code as we need to pass some Extra -->
+ <Preference
+ android:key="button_cdma_apn_key"
+ android:title="@string/apn_settings"
+ android:persistent="false"/>
+ </PreferenceCategory>
- </PreferenceScreen>
-
- <PreferenceScreen
+ <Preference
android:key="carrier_settings_key"
android:title="@string/carrier_settings_title">
<intent android:action="android.intent.action.MAIN"
android:targetPackage="@string/carrier_settings"
android:targetClass="@string/carrier_settings_menu" />
- </PreferenceScreen>
+ </Preference>
</PreferenceScreen>
diff --git a/res/xml/gsm_umts_options.xml b/res/xml/gsm_umts_options.xml
index 3b054d6..e6ddc37 100644
--- a/res/xml/gsm_umts_options.xml
+++ b/res/xml/gsm_umts_options.xml
@@ -36,9 +36,9 @@
<!--We want separate APN setting from reset of settings because-->
<!--we want user to change it with caution.-->
<PreferenceCategory
- android:key="category_apn_key">
+ android:key="category_gsm_apn_key">
<Preference
- android:key="button_apn_key"
+ android:key="button_gsm_apn_key"
android:title="@string/apn_settings"
android:persistent="false" />
</PreferenceCategory>
diff --git a/src/com/android/phone/CdmaOptions.java b/src/com/android/phone/CdmaOptions.java
index a760cda..8749565 100644
--- a/src/com/android/phone/CdmaOptions.java
+++ b/src/com/android/phone/CdmaOptions.java
@@ -27,7 +27,6 @@
import android.text.TextUtils;
import com.android.internal.telephony.Phone;
-import com.android.internal.telephony.TelephonyProperties;
/**
* List of Phone-specific settings screens.
@@ -37,12 +36,15 @@
private CdmaSystemSelectListPreference mButtonCdmaSystemSelect;
private CdmaSubscriptionListPreference mButtonCdmaSubscription;
- private PreferenceScreen mButtonAPNExpand;
+ private Preference mButtonAPNExpand;
+ private Preference mCategoryAPNExpand;
+ private Preference mButtonCarrierSettings;
private static final String BUTTON_CDMA_SYSTEM_SELECT_KEY = "cdma_system_select_key";
private static final String BUTTON_CDMA_SUBSCRIPTION_KEY = "cdma_subscription_key";
private static final String BUTTON_CARRIER_SETTINGS_KEY = "carrier_settings_key";
- private static final String BUTTON_APN_EXPAND_KEY = "button_apn_key_cdma";
+ private static final String BUTTON_APN_EXPAND_KEY = "button_cdma_apn_key";
+ private static final String CATEGORY_APN_EXPAND_KEY = "category_cdma_apn_key";
private PreferenceFragment mPrefFragment;
private PreferenceScreen mPrefScreen;
@@ -51,24 +53,44 @@
public CdmaOptions(PreferenceFragment prefFragment, PreferenceScreen prefScreen, Phone phone) {
mPrefFragment = prefFragment;
mPrefScreen = prefScreen;
- mPhone = phone;
- create();
- }
-
- protected void create() {
mPrefFragment.addPreferencesFromResource(R.xml.cdma_options);
- mButtonAPNExpand = (PreferenceScreen) mPrefScreen.findPreference(BUTTON_APN_EXPAND_KEY);
- boolean removedAPNExpand = false;
+ // Initialize preferences.
+ mButtonCdmaSystemSelect = (CdmaSystemSelectListPreference) mPrefScreen
+ .findPreference(BUTTON_CDMA_SYSTEM_SELECT_KEY);
+ mButtonCdmaSubscription = (CdmaSubscriptionListPreference) mPrefScreen
+ .findPreference(BUTTON_CDMA_SUBSCRIPTION_KEY);
+ mButtonCarrierSettings = mPrefScreen.findPreference(BUTTON_CARRIER_SETTINGS_KEY);
+ mButtonAPNExpand = mPrefScreen.findPreference(BUTTON_APN_EXPAND_KEY);
+ mCategoryAPNExpand = mPrefScreen.findPreference(CATEGORY_APN_EXPAND_KEY);
+
+ update(phone);
+ }
+
+ // Unlike mPrefFragment or mPrefScreen, mPhone may change during lifecycle of CdmaOptions.
+ // For example, a new sim card is inserted. When that happens, we update CdmaOptions with new
+ // phone.
+ protected void update(Phone phone) {
+ mPhone = phone;
+
PersistableBundle carrierConfig =
PhoneGlobals.getInstance().getCarrierConfigForSubId(mPhone.getSubId());
// Some CDMA carriers want the APN settings.
- if (!carrierConfig.getBoolean(CarrierConfigManager.KEY_SHOW_APN_SETTING_CDMA_BOOL)
- && mButtonAPNExpand != null) {
- mPrefScreen.removePreference(mButtonAPNExpand);
- removedAPNExpand = true;
- }
- if (!removedAPNExpand) {
+ boolean addAPNExpand =
+ carrierConfig.getBoolean(CarrierConfigManager.KEY_SHOW_APN_SETTING_CDMA_BOOL);
+ boolean addCdmaSubscription =
+ deviceSupportsNvAndRuim();
+ // Read platform settings for carrier settings
+ boolean addCarrierSettings =
+ carrierConfig.getBoolean(CarrierConfigManager.KEY_CARRIER_SETTINGS_ENABLE_BOOL);
+
+ mPrefScreen.addPreference(mButtonCdmaSystemSelect);
+ mButtonCdmaSystemSelect.setEnabled(true);
+
+ // Making no assumptions of whether they are added or removed at this point.
+ // Calling add or remove explicitly to make sure they are updated.
+
+ if (addAPNExpand) {
mButtonAPNExpand.setOnPreferenceClickListener(
new Preference.OnPreferenceClickListener() {
@Override
@@ -83,33 +105,25 @@
mPrefFragment.startActivity(intent);
return true;
}
- });
+ });
+ mPrefScreen.addPreference(mCategoryAPNExpand);
+ } else {
+ mPrefScreen.removePreference(mCategoryAPNExpand);
}
- mButtonCdmaSystemSelect = (CdmaSystemSelectListPreference)mPrefScreen
- .findPreference(BUTTON_CDMA_SYSTEM_SELECT_KEY);
-
- mButtonCdmaSubscription = (CdmaSubscriptionListPreference)mPrefScreen
- .findPreference(BUTTON_CDMA_SUBSCRIPTION_KEY);
-
- mButtonCdmaSystemSelect.setEnabled(true);
- if(deviceSupportsNvAndRuim()) {
+ if (addCdmaSubscription) {
log("Both NV and Ruim supported, ENABLE subscription type selection");
+ mPrefScreen.addPreference(mButtonCdmaSubscription);
mButtonCdmaSubscription.setEnabled(true);
} else {
log("Both NV and Ruim NOT supported, REMOVE subscription type selection");
- mPrefScreen.removePreference(mPrefScreen
- .findPreference(BUTTON_CDMA_SUBSCRIPTION_KEY));
+ mPrefScreen.removePreference(mButtonCdmaSubscription);
}
- // Read platform settings for carrier settings
- final boolean isCarrierSettingsEnabled = carrierConfig.getBoolean(
- CarrierConfigManager.KEY_CARRIER_SETTINGS_ENABLE_BOOL);
- if (!isCarrierSettingsEnabled) {
- Preference pref = mPrefScreen.findPreference(BUTTON_CARRIER_SETTINGS_KEY);
- if (pref != null) {
- mPrefScreen.removePreference(pref);
- }
+ if (addCarrierSettings) {
+ mPrefScreen.addPreference(mButtonCarrierSettings);
+ } else {
+ mPrefScreen.removePreference(mButtonCarrierSettings);
}
}
diff --git a/src/com/android/phone/GsmUmtsOptions.java b/src/com/android/phone/GsmUmtsOptions.java
index 909e9bd..f08aa06 100644
--- a/src/com/android/phone/GsmUmtsOptions.java
+++ b/src/com/android/phone/GsmUmtsOptions.java
@@ -17,12 +17,10 @@
package com.android.phone;
import android.content.Intent;
-import android.content.res.Resources;
import android.os.PersistableBundle;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.preference.PreferenceScreen;
-import android.preference.TwoStatePreference;
import android.provider.Settings;
import android.telephony.CarrierConfigManager;
@@ -37,50 +35,48 @@
private Preference mButtonAPNExpand;
private Preference mCategoryAPNExpand;
- private TwoStatePreference mButtonAutoSelect;
- private NetworkSelectListPreference mButtonOperatorSelection;
+ Preference mCarrierSettingPref;
private NetworkOperators mNetworkOperator;
- private static final String BUTTON_APN_EXPAND_KEY = "button_apn_key";
- private static final String CATEGORY_APN_EXPAND_KEY = "category_apn_key";
+ private static final String BUTTON_APN_EXPAND_KEY = "button_gsm_apn_key";
+ private static final String CATEGORY_APN_EXPAND_KEY = "category_gsm_apn_key";
private static final String BUTTON_CARRIER_SETTINGS_KEY = "carrier_settings_key";
public static final String EXTRA_SUB_ID = "sub_id";
private PreferenceFragment mPrefFragment;
private PreferenceScreen mPrefScreen;
- INetworkQueryService mNetworkQueryService;
- private int mSubId;
public GsmUmtsOptions(PreferenceFragment prefFragment, PreferenceScreen prefScreen,
final int subId, INetworkQueryService queryService) {
mPrefFragment = prefFragment;
mPrefScreen = prefScreen;
- mSubId = subId;
- mNetworkQueryService = queryService;
- create();
- }
-
- protected void create() {
mPrefFragment.addPreferencesFromResource(R.xml.gsm_umts_options);
mButtonAPNExpand = mPrefScreen.findPreference(BUTTON_APN_EXPAND_KEY);
mCategoryAPNExpand = mPrefScreen.findPreference(CATEGORY_APN_EXPAND_KEY);
-
mNetworkOperator = (NetworkOperators) mPrefScreen
.findPreference(NetworkOperators.CATEGORY_NETWORK_OPERATORS_KEY);
- mNetworkOperator.initialize(mPrefScreen, mSubId, mNetworkQueryService);
+ mCarrierSettingPref = mPrefScreen.findPreference(BUTTON_CARRIER_SETTINGS_KEY);
- boolean removedAPNExpand = false;
- boolean removedNetworkOperatorsCategory = false;
+ mNetworkOperator.initialize();
+
+ update(subId, queryService);
+ }
+
+ // Unlike mPrefFragment or mPrefScreen, subId or queryService may change during lifecycle of
+ // GsmUmtsOptions. When that happens, we update GsmUmtsOptions with new parameters.
+ protected void update(final int subId, INetworkQueryService queryService) {
+ boolean addAPNExpand = true;
+ boolean addNetworkOperatorsCategory = true;
+ boolean addCarrierSettings = true;
if (PhoneFactory.getDefaultPhone().getPhoneType() != PhoneConstants.PHONE_TYPE_GSM) {
log("Not a GSM phone");
mCategoryAPNExpand.setEnabled(false);
mNetworkOperator.setEnabled(false);
} else {
log("Not a CDMA phone");
- Resources res = mPrefFragment.getResources();
PersistableBundle carrierConfig =
- PhoneGlobals.getInstance().getCarrierConfigForSubId(mSubId);
+ PhoneGlobals.getInstance().getCarrierConfigForSubId(subId);
// Determine which options to display. For GSM these are defaulted to true in
// CarrierConfigManager, but they maybe overriden by DefaultCarrierConfigService or a
@@ -89,13 +85,11 @@
// Telephony/res/values/config.xml
if (!carrierConfig.getBoolean(CarrierConfigManager.KEY_APN_EXPAND_BOOL)
&& mCategoryAPNExpand != null) {
- removedAPNExpand = true;
+ addAPNExpand = false;
}
if (!carrierConfig.getBoolean(
CarrierConfigManager.KEY_OPERATOR_SELECTION_EXPAND_BOOL)) {
- mPrefScreen.removePreference(mPrefScreen
- .findPreference(NetworkOperators.CATEGORY_NETWORK_OPERATORS_KEY));
- removedNetworkOperatorsCategory = true;
+ addNetworkOperatorsCategory = false;
}
if (carrierConfig.getBoolean(CarrierConfigManager.KEY_CSP_ENABLED_BOOL)) {
@@ -104,23 +98,19 @@
mNetworkOperator.setEnabled(true);
} else {
log("[CSP] Disabling Operator Selection menu.");
- mPrefScreen.removePreference(mPrefScreen
- .findPreference(NetworkOperators.CATEGORY_NETWORK_OPERATORS_KEY));
- removedNetworkOperatorsCategory = true;
+ addNetworkOperatorsCategory = false;
}
}
// Read platform settings for carrier settings
- final boolean isCarrierSettingsEnabled = carrierConfig.getBoolean(
- CarrierConfigManager.KEY_CARRIER_SETTINGS_ENABLE_BOOL);
- if (!isCarrierSettingsEnabled) {
- Preference pref = mPrefScreen.findPreference(BUTTON_CARRIER_SETTINGS_KEY);
- if (pref != null) {
- mPrefScreen.removePreference(pref);
- }
- }
+ addCarrierSettings = carrierConfig.getBoolean(
+ CarrierConfigManager.KEY_CARRIER_SETTINGS_ENABLE_BOOL);
}
- if (!removedAPNExpand) {
+
+ // Making no assumptions of whether they are added or removed at this point.
+ // Calling add or remove explicitly to make sure they are updated.
+
+ if (addAPNExpand) {
mButtonAPNExpand.setOnPreferenceClickListener(
new Preference.OnPreferenceClickListener() {
@Override
@@ -131,30 +121,33 @@
final Intent intent = new Intent(Settings.ACTION_APN_SETTINGS);
// This will setup the Home and Search affordance
intent.putExtra(":settings:show_fragment_as_subsetting", true);
- intent.putExtra(EXTRA_SUB_ID, mSubId);
+ intent.putExtra(EXTRA_SUB_ID, subId);
mPrefFragment.startActivity(intent);
return true;
}
- });
+ });
+ mPrefScreen.addPreference(mCategoryAPNExpand);
} else {
mPrefScreen.removePreference(mCategoryAPNExpand);
}
- if (!removedNetworkOperatorsCategory) {
- mButtonAutoSelect = (TwoStatePreference) mPrefScreen
- .findPreference(NetworkOperators.BUTTON_AUTO_SELECT_KEY);
- mButtonOperatorSelection = (NetworkSelectListPreference) mPrefScreen
- .findPreference(NetworkOperators.BUTTON_NETWORK_SELECT_KEY);
+ if (addNetworkOperatorsCategory) {
+ mPrefScreen.addPreference(mNetworkOperator);
+ mNetworkOperator.update(subId, queryService);
+ } else {
+ mPrefScreen.removePreference(mNetworkOperator);
}
+
+ if (addCarrierSettings) {
+ mPrefScreen.addPreference(mCarrierSettingPref);
+ } else {
+ mPrefScreen.removePreference(mCarrierSettingPref);
+ }
+
}
- public boolean preferenceTreeClick(Preference preference) {
- if (preference == mButtonAutoSelect || preference == mButtonOperatorSelection) {
- return true;
- } else {
- log("preferenceTreeClick: return false");
- return false;
- }
+ protected boolean preferenceTreeClick(Preference preference) {
+ return mNetworkOperator.preferenceTreeClick(preference);
}
protected void log(String s) {
diff --git a/src/com/android/phone/MobileNetworkSettings.java b/src/com/android/phone/MobileNetworkSettings.java
index a969cc1..1af0c6e 100644
--- a/src/com/android/phone/MobileNetworkSettings.java
+++ b/src/com/android/phone/MobileNetworkSettings.java
@@ -191,7 +191,8 @@
private static final String BUTTON_DATA_USAGE_KEY = "data_usage_summary";
private static final String BUTTON_ADVANCED_OPTIONS_KEY = "advanced_options";
private static final String CATEGORY_CALLING_KEY = "calling";
- private static final String CATEGORY_APN_EXPAND_KEY = "category_apn_key";
+ private static final String CATEGORY_GSM_APN_EXPAND_KEY = "category_gsm_apn_key";
+ private static final String CATEGORY_CDMA_APN_EXPAND_KEY = "category_cdma_apn_key";
private final BroadcastReceiver mPhoneChangeReceiver = new PhoneChangeReceiver();
@@ -677,8 +678,6 @@
public void onReceive(Context context, Intent intent) {
Log.i(LOG_TAG, "onReceive:");
// When the radio changes (ex: CDMA->GSM), refresh all options.
- mGsmUmtsOptions = null;
- mCdmaOptions = null;
updateBody();
}
}
@@ -846,14 +845,9 @@
final int phoneType = mPhone.getPhoneType();
if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
- mCdmaOptions = new CdmaOptions(this, prefSet, mPhone);
- // In World mode force a refresh of GSM Options.
- if (isWorldMode()) {
- mGsmUmtsOptions = null;
- }
+ updateCdmaOptions(this, prefSet, mPhone);
} else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
- mGsmUmtsOptions = new GsmUmtsOptions(this, prefSet, phoneSubId,
- mNetworkQueryService);
+ updateGsmUmtsOptions(this, prefSet, phoneSubId, mNetworkQueryService);
} else {
throw new IllegalStateException("Unexpected phone type: " + phoneType);
}
@@ -868,9 +862,8 @@
// change Preferred Network Mode.
mButtonPreferredNetworkMode.setOnPreferenceChangeListener(this);
- mCdmaOptions = new CdmaOptions(this, prefSet, mPhone);
- mGsmUmtsOptions = new GsmUmtsOptions(this, prefSet, phoneSubId,
- mNetworkQueryService);
+ updateCdmaOptions(this, prefSet, mPhone);
+ updateGsmUmtsOptions(this, prefSet, phoneSubId, mNetworkQueryService);
} else {
prefSet.removePreference(mButtonPreferredNetworkMode);
final int phoneType = mPhone.getPhoneType();
@@ -914,12 +907,8 @@
}
}
}
- mCdmaOptions = new CdmaOptions(this, prefSet, mPhone);
+ updateCdmaOptions(this, prefSet, mPhone);
- // In World mode force a refresh of GSM Options.
- if (isWorldMode()) {
- mGsmUmtsOptions = null;
- }
} else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
if (isSupportTdscdma()) {
mButtonEnabledNetworks.setEntries(
@@ -956,8 +945,7 @@
mButtonEnabledNetworks.setEntryValues(
R.array.enabled_networks_values);
}
- mGsmUmtsOptions = new GsmUmtsOptions(this, prefSet, phoneSubId,
- mNetworkQueryService);
+ updateGsmUmtsOptions(this, prefSet, phoneSubId, mNetworkQueryService);
} else {
throw new IllegalStateException("Unexpected phone type: " + phoneType);
}
@@ -1048,7 +1036,11 @@
if (ps != null) {
ps.setEnabled(hasActiveSubscriptions);
}
- ps = findPreference(CATEGORY_APN_EXPAND_KEY);
+ ps = findPreference(CATEGORY_GSM_APN_EXPAND_KEY);
+ if (ps != null) {
+ ps.setEnabled(hasActiveSubscriptions);
+ }
+ ps = findPreference(CATEGORY_CDMA_APN_EXPAND_KEY);
if (ps != null) {
ps.setEnabled(hasActiveSubscriptions);
}
@@ -1701,12 +1693,10 @@
return;
}
- if (mGsmUmtsOptions == null) {
- mGsmUmtsOptions = new GsmUmtsOptions(this, prefSet, mPhone.getSubId(),
- mNetworkQueryService);
- }
+ updateGsmUmtsOptions(this, prefSet, mPhone.getSubId(), mNetworkQueryService);
+
PreferenceCategory apnExpand =
- (PreferenceCategory) prefSet.findPreference(CATEGORY_APN_EXPAND_KEY);
+ (PreferenceCategory) prefSet.findPreference(CATEGORY_GSM_APN_EXPAND_KEY);
PreferenceCategory networkOperatorCategory =
(PreferenceCategory) prefSet.findPreference(
NetworkOperators.CATEGORY_NETWORK_OPERATORS_KEY);
@@ -1732,9 +1722,7 @@
if (prefSet == null) {
return;
}
- if (enable && mCdmaOptions == null) {
- mCdmaOptions = new CdmaOptions(this, prefSet, mPhone);
- }
+ updateCdmaOptions(this, prefSet, mPhone);
CdmaSystemSelectListPreference systemSelect =
(CdmaSystemSelectListPreference)prefSet.findPreference
(BUTTON_CDMA_SYSTEM_SELECT_KEY);
@@ -1795,6 +1783,29 @@
mAdvancedOptions.setSummary(summary.toString());
}
+ private void updateGsmUmtsOptions(PreferenceFragment prefFragment,
+ PreferenceScreen prefScreen, final int subId, INetworkQueryService queryService) {
+ // We don't want to re-create GsmUmtsOptions if already exists. Otherwise, the
+ // preferences inside it will also be re-created which causes unexpected behavior.
+ // For example, the open dialog gets dismissed or detached after pause / resume.
+ if (mGsmUmtsOptions == null) {
+ mGsmUmtsOptions = new GsmUmtsOptions(prefFragment, prefScreen, subId, queryService);
+ } else {
+ mGsmUmtsOptions.update(subId, queryService);
+ }
+ }
+
+ private void updateCdmaOptions(PreferenceFragment prefFragment, PreferenceScreen prefScreen,
+ Phone phone) {
+ // We don't want to re-create CdmaOptions if already exists. Otherwise, the preferences
+ // inside it will also be re-created which causes unexpected behavior. For example,
+ // the open dialog gets dismissed or detached after pause / resume.
+ if (mCdmaOptions == null) {
+ mCdmaOptions = new CdmaOptions(prefFragment, prefScreen, phone);
+ } else {
+ mCdmaOptions.update(phone);
+ }
+ }
}
}
diff --git a/src/com/android/phone/NetworkOperators.java b/src/com/android/phone/NetworkOperators.java
index c01db91..4ac5c84 100644
--- a/src/com/android/phone/NetworkOperators.java
+++ b/src/com/android/phone/NetworkOperators.java
@@ -16,13 +16,13 @@
package com.android.phone;
+import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncResult;
import android.os.Handler;
import android.os.Message;
import android.preference.Preference;
import android.preference.PreferenceCategory;
-import android.preference.PreferenceScreen;
import android.preference.TwoStatePreference;
import android.telephony.ServiceState;
import android.telephony.SubscriptionManager;
@@ -58,15 +58,7 @@
private TwoStatePreference mAutoSelect;
private int mSubId;
-
- public NetworkOperators(
- Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
- super(context, attrs, defStyleAttr, defStyleRes);
- }
-
- public NetworkOperators(Context context, AttributeSet attrs, int defStyleAttr) {
- super(context, attrs, defStyleAttr);
- }
+ private ProgressDialog mProgressDialog;
public NetworkOperators(Context context, AttributeSet attrs) {
super(context, attrs);
@@ -77,30 +69,32 @@
}
/**
- * Initialize NetworkOperators instance with information like subId, queryService.
- * It is required to have preferences work properly.
+ * Initialize NetworkOperators instance.
+ */
+ public void initialize() {
+ mNetworkSelect =
+ (NetworkSelectListPreference) findPreference(BUTTON_NETWORK_SELECT_KEY);
+ mAutoSelect =
+ (TwoStatePreference) findPreference(BUTTON_AUTO_SELECT_KEY);
+ mProgressDialog = new ProgressDialog(getContext());
+ }
+
+ /**
+ * Update NetworkOperators instance if like subId or queryService are updated.
*
- * @param prefScreen prefScreen this category is in.
* @param subId Corresponding subscription ID of this network.
* @param queryService The service to do network queries.
*/
- public void initialize(PreferenceScreen prefScreen,
- final int subId, INetworkQueryService queryService) {
+ protected void update(final int subId, INetworkQueryService queryService) {
mSubId = subId;
-
- mNetworkSelect =
- (NetworkSelectListPreference) prefScreen.findPreference(BUTTON_NETWORK_SELECT_KEY);
- mAutoSelect =
- (TwoStatePreference) prefScreen.findPreference(BUTTON_AUTO_SELECT_KEY);
-
mPhoneId = SubscriptionManager.getPhoneId(mSubId);
if (mAutoSelect != null) {
mAutoSelect.setOnPreferenceChangeListener(this);
}
- if (mAutoSelect != null) {
- mNetworkSelect.initialize(mSubId, queryService, this);
+ if (mNetworkSelect != null) {
+ mNetworkSelect.initialize(mSubId, queryService, this, mProgressDialog);
}
getNetworkSelectionMode();
@@ -130,6 +124,7 @@
switch (msg.what) {
case EVENT_AUTO_SELECT_DONE:
mAutoSelect.setEnabled(true);
+ dismissProgressBar();
ar = (AsyncResult) msg.obj;
if (ar.exception != null) {
@@ -210,6 +205,7 @@
}
if (autoSelect) {
if (DBG) logd("select network automatically...");
+ showAutoSelectProgressBar();
mAutoSelect.setEnabled(false);
Message msg = mHandler.obtainMessage(EVENT_AUTO_SELECT_DONE);
Phone phone = PhoneFactory.getPhone(mPhoneId);
@@ -230,6 +226,25 @@
}
}
+ private void dismissProgressBar() {
+ if (mProgressDialog != null && mProgressDialog.isShowing()) {
+ mProgressDialog.dismiss();
+ }
+ }
+
+ private void showAutoSelectProgressBar() {
+ mProgressDialog.setMessage(
+ getContext().getResources().getString(R.string.register_automatically));
+ mProgressDialog.setCanceledOnTouchOutside(false);
+ mProgressDialog.setCancelable(false);
+ mProgressDialog.setIndeterminate(true);
+ mProgressDialog.show();
+ }
+
+ protected boolean preferenceTreeClick(Preference preference) {
+ return (preference == mAutoSelect || preference == mNetworkSelect);
+ }
+
private void logd(String msg) {
Log.d(LOG_TAG, "[NetworksList] " + msg);
}
diff --git a/src/com/android/phone/NetworkSelectListPreference.java b/src/com/android/phone/NetworkSelectListPreference.java
index a0d81fc..946856a 100644
--- a/src/com/android/phone/NetworkSelectListPreference.java
+++ b/src/com/android/phone/NetworkSelectListPreference.java
@@ -22,6 +22,8 @@
import android.os.AsyncResult;
import android.os.Handler;
import android.os.Message;
+import android.os.Parcel;
+import android.os.Parcelable;
import android.os.RemoteException;
import android.preference.ListPreference;
import android.preference.Preference;
@@ -61,7 +63,7 @@
private int mPhoneId = SubscriptionManager.INVALID_PHONE_INDEX;
private List<OperatorInfo> mOperatorInfoList;
- private OperatorInfo mOperatorInfo;
+ private OperatorInfo mOperatorInfo;
private int mSubId;
private NetworkOperators mNetworkOperators;
@@ -179,10 +181,12 @@
// This initialize method needs to be called for this preference to work properly.
protected void initialize(int subId, INetworkQueryService queryService,
- NetworkOperators networkOperators) {
+ NetworkOperators networkOperators, ProgressDialog progressDialog) {
mSubId = subId;
mNetworkQueryService = queryService;
mNetworkOperators = networkOperators;
+ // This preference should share the same progressDialog with networkOperators category.
+ mProgressDialog = progressDialog;
if (SubscriptionManager.isValidSubscriptionId(mSubId)) {
mPhoneId = SubscriptionManager.getPhoneId(mSubId);
@@ -227,7 +231,7 @@
NotificationMgr.NETWORK_SELECTION_NOTIFICATION, status);
}
- private void displayNetworkSeletionInProgress() {
+ private void displayNetworkSelectionInProgress() {
showProgressBar(DIALOG_NETWORK_SELECTION);
}
@@ -357,14 +361,21 @@
}
private void showProgressBar(int id) {
- if ((id == DIALOG_NETWORK_SELECTION) || (id == DIALOG_NETWORK_LIST_LOAD)) {
+ if (mProgressDialog == null) {
mProgressDialog = new ProgressDialog(getContext());
+ } else {
+ // Dismiss progress bar if it's showing now.
+ dismissProgressBar();
+ }
+
+ if ((id == DIALOG_NETWORK_SELECTION) || (id == DIALOG_NETWORK_LIST_LOAD)) {
switch (id) {
case DIALOG_NETWORK_SELECTION:
final String networkSelectMsg = getContext().getResources()
.getString(R.string.register_on_network,
getNetworkTitle(mOperatorInfo));
mProgressDialog.setMessage(networkSelectMsg);
+ mProgressDialog.setCanceledOnTouchOutside(false);
mProgressDialog.setCancelable(false);
mProgressDialog.setIndeterminate(true);
break;
@@ -372,6 +383,8 @@
mProgressDialog.setMessage(
getContext().getResources().getString(R.string.load_networks_progress));
mProgressDialog.setCanceledOnTouchOutside(false);
+ mProgressDialog.setCancelable(true);
+ mProgressDialog.setIndeterminate(false);
mProgressDialog.setOnCancelListener(this);
break;
default:
@@ -397,7 +410,7 @@
Phone phone = PhoneFactory.getPhone(mPhoneId);
if (phone != null) {
phone.selectNetworkManually(mOperatorInfo, true, msg);
- displayNetworkSeletionInProgress();
+ displayNetworkSelectionInProgress();
} else {
loge("Error selecting network. phone is null.");
}
@@ -405,6 +418,87 @@
return true;
}
+ @Override
+ protected Parcelable onSaveInstanceState() {
+ final Parcelable superState = super.onSaveInstanceState();
+ if (isPersistent()) {
+ // No need to save instance state since it's persistent
+ return superState;
+ }
+
+ final SavedState myState = new SavedState(superState);
+ myState.mDialogListEntries = getEntries();
+ myState.mDialogListEntryValues = getEntryValues();
+ myState.mOperatorInfoList = mOperatorInfoList;
+ return myState;
+ }
+
+ @Override
+ protected void onRestoreInstanceState(Parcelable state) {
+ if (state == null || !state.getClass().equals(SavedState.class)) {
+ // Didn't save state for us in onSaveInstanceState
+ super.onRestoreInstanceState(state);
+ return;
+ }
+
+ SavedState myState = (SavedState) state;
+
+ if (getEntries() == null && myState.mDialogListEntries != null) {
+ setEntries(myState.mDialogListEntries);
+ }
+ if (getEntryValues() == null && myState.mDialogListEntryValues != null) {
+ setEntryValues(myState.mDialogListEntryValues);
+ }
+ if (mOperatorInfoList == null && myState.mOperatorInfoList != null) {
+ mOperatorInfoList = myState.mOperatorInfoList;
+ }
+
+ super.onRestoreInstanceState(myState.getSuperState());
+ }
+
+ /**
+ * We save entries, entryValues and operatorInfoList into bundle.
+ * At onCreate of fragment, dialog will be restored if it was open. In this case,
+ * we need to restore entries, entryValues and operatorInfoList. Without those information,
+ * onPreferenceChange will fail if user select network from the dialog.
+ */
+ private static class SavedState extends BaseSavedState {
+ CharSequence[] mDialogListEntries;
+ CharSequence[] mDialogListEntryValues;
+ List<OperatorInfo> mOperatorInfoList;
+
+ SavedState(Parcel source) {
+ super(source);
+ final ClassLoader boot = Object.class.getClassLoader();
+ mDialogListEntries = source.readCharSequenceArray();
+ mDialogListEntryValues = source.readCharSequenceArray();
+ mOperatorInfoList = source.readParcelableList(mOperatorInfoList, boot);
+ }
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ super.writeToParcel(dest, flags);
+ dest.writeCharSequenceArray(mDialogListEntries);
+ dest.writeCharSequenceArray(mDialogListEntryValues);
+ dest.writeParcelableList(mOperatorInfoList, flags);
+ }
+
+ SavedState(Parcelable superState) {
+ super(superState);
+ }
+
+ public static final Parcelable.Creator<SavedState> CREATOR =
+ new Parcelable.Creator<SavedState>() {
+ public SavedState createFromParcel(Parcel in) {
+ return new SavedState(in);
+ }
+
+ public SavedState[] newArray(int size) {
+ return new SavedState[size];
+ }
+ };
+ }
+
private void logd(String msg) {
Log.d(LOG_TAG, "[NetworksList] " + msg);
}