SetupWizard: Only update network state when resumed
Change-Id: Id018bf0ed4d9c54a1d6d57d53749c265b1d0e269
This commit is contained in:
parent
77fce341b1
commit
f66c56b62f
@ -86,6 +86,8 @@ public class ChooseDataSimPage extends SetupPage {
|
||||
private SparseArray<ServiceState> mServiceStates;
|
||||
private SparseArray<PhoneStateListener> mPhoneStateListeners;
|
||||
|
||||
private boolean mIsAttached = false;
|
||||
|
||||
private View.OnClickListener mSetDataSimClickListener = new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
@ -121,12 +123,6 @@ public class ChooseDataSimPage extends SetupPage {
|
||||
mPhoneStateListeners.put(i, createPhoneStateListener(subInfoRecord));
|
||||
mPageView.addView(inflater.inflate(R.layout.divider, null));
|
||||
}
|
||||
mPhone = (TelephonyManager)getActivity().getSystemService(Context.TELEPHONY_SERVICE);
|
||||
for (int i = 0; i < mPhoneStateListeners.size(); i++) {
|
||||
mPhone.listen(mPhoneStateListeners.get(i),
|
||||
PhoneStateListener.LISTEN_SERVICE_STATE
|
||||
| PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
|
||||
}
|
||||
updateSignalStrengths();
|
||||
updateCurrentDataSub();
|
||||
}
|
||||
@ -139,16 +135,24 @@ public class ChooseDataSimPage extends SetupPage {
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
mIsAttached = true;
|
||||
mPhone = (TelephonyManager)getActivity().getSystemService(Context.TELEPHONY_SERVICE);
|
||||
for (int i = 0; i < mPhoneStateListeners.size(); i++) {
|
||||
mPhone.listen(mPhoneStateListeners.get(i),
|
||||
PhoneStateListener.LISTEN_SERVICE_STATE
|
||||
| PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
|
||||
}
|
||||
updateSignalStrengths();
|
||||
updateCurrentDataSub();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetach() {
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
mIsAttached = false;
|
||||
for (int i = 0; i < mPhoneStateListeners.size(); i++) {
|
||||
mPhone.listen(mPhoneStateListeners.get(i), PhoneStateListener.LISTEN_NONE);
|
||||
}
|
||||
super.onDetach();
|
||||
}
|
||||
|
||||
private PhoneStateListener createPhoneStateListener(final SubInfoRecord subInfoRecord) {
|
||||
@ -156,29 +160,32 @@ public class ChooseDataSimPage extends SetupPage {
|
||||
|
||||
@Override
|
||||
public void onSignalStrengthsChanged(SignalStrength signalStrength) {
|
||||
if (isDetached()) return;
|
||||
if (mIsAttached) {
|
||||
mSignalStrengths.put(subInfoRecord.slotId, signalStrength);
|
||||
updateSignalStrength(subInfoRecord);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceStateChanged(ServiceState state) {
|
||||
if (isDetached()) return;
|
||||
if (mIsAttached) {
|
||||
mServiceStates.put(subInfoRecord.slotId, state);
|
||||
updateSignalStrength(subInfoRecord);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void updateSignalStrengths() {
|
||||
if (isDetached()) return;
|
||||
if (mIsAttached) {
|
||||
for (int i = 0; i < mSubInfoRecords.size(); i++) {
|
||||
updateSignalStrength(mSubInfoRecords.get(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setDataSubChecked(SubInfoRecord subInfoRecord) {
|
||||
if (isDetached()) return;
|
||||
if (mIsAttached) {
|
||||
for (int i = 0; i < mCheckBoxes.size(); i++) {
|
||||
if (subInfoRecord.slotId == i) {
|
||||
mCheckBoxes.get(i).setChecked(true);
|
||||
@ -191,9 +198,10 @@ public class ChooseDataSimPage extends SetupPage {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateCurrentDataSub() {
|
||||
if (isDetached()) return;
|
||||
if (mIsAttached) {
|
||||
for (int i = 0; i < mSubInfoRecords.size(); i++) {
|
||||
SubInfoRecord subInfoRecord = mSubInfoRecords.get(i);
|
||||
mCheckBoxes.get(i).setChecked(SubscriptionManager.getDefaultDataSubId()
|
||||
@ -201,9 +209,10 @@ public class ChooseDataSimPage extends SetupPage {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateCarrierText(SubInfoRecord subInfoRecord) {
|
||||
if (isDetached()) return;
|
||||
if (mIsAttached) {
|
||||
String name = mPhone.getNetworkOperatorName(subInfoRecord.subId);
|
||||
ServiceState serviceState = mServiceStates.get(subInfoRecord.slotId);
|
||||
if (TextUtils.isEmpty(name)) {
|
||||
@ -217,9 +226,10 @@ public class ChooseDataSimPage extends SetupPage {
|
||||
getString(R.string.data_sim_name, subInfoRecord.slotId + 1, name);
|
||||
mNameViews.get(subInfoRecord.slotId).setText(formattedName);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateSignalStrength(SubInfoRecord subInfoRecord) {
|
||||
if (isDetached()) return;
|
||||
if (mIsAttached) {
|
||||
ImageView signalView = mSignalViews.get(subInfoRecord.slotId);
|
||||
SignalStrength signalStrength = mSignalStrengths.get(subInfoRecord.slotId);
|
||||
if (!hasService(subInfoRecord)) {
|
||||
@ -249,6 +259,7 @@ public class ChooseDataSimPage extends SetupPage {
|
||||
}
|
||||
updateCarrierText(subInfoRecord);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean hasService(SubInfoRecord subInfoRecord) {
|
||||
boolean retVal;
|
||||
|
@ -16,7 +16,6 @@
|
||||
|
||||
package com.cyanogenmod.setupwizard.setup;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Fragment;
|
||||
import android.app.FragmentManager;
|
||||
import android.content.Context;
|
||||
@ -79,22 +78,26 @@ public class MobileDataPage extends SetupPage {
|
||||
private SignalStrength mSignalStrength;
|
||||
private ServiceState mServiceState;
|
||||
|
||||
private boolean mIsAttached = false;
|
||||
|
||||
private PhoneStateListener mPhoneStateListener =
|
||||
new PhoneStateListener(SubscriptionManager.getDefaultDataSubId()) {
|
||||
|
||||
@Override
|
||||
public void onSignalStrengthsChanged(SignalStrength signalStrength) {
|
||||
if (isDetached()) return;
|
||||
if (mIsAttached) {
|
||||
mSignalStrength = signalStrength;
|
||||
updateSignalStrength();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceStateChanged(ServiceState state) {
|
||||
if (isDetached()) return;
|
||||
if (mIsAttached) {
|
||||
mServiceState = state;
|
||||
updateSignalStrength();
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@ -129,28 +132,26 @@ public class MobileDataPage extends SetupPage {
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
mIsAttached = true;
|
||||
mPhone = (TelephonyManager)getActivity().getSystemService(Context.TELEPHONY_SERVICE);
|
||||
mPhone.listen(mPhoneStateListener,
|
||||
PhoneStateListener.LISTEN_SERVICE_STATE
|
||||
| PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
|
||||
updateDataConnectionStatus();
|
||||
updateSignalStrength();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
mPhone = (TelephonyManager)getActivity().getSystemService(Context.TELEPHONY_SERVICE);
|
||||
mPhone.listen(mPhoneStateListener,
|
||||
PhoneStateListener.LISTEN_SERVICE_STATE
|
||||
| PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetach() {
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
mIsAttached = false;
|
||||
mPhone.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);
|
||||
super.onDetach();
|
||||
}
|
||||
|
||||
private void updateCarrierText() {
|
||||
if (isDetached()) return;
|
||||
String name = mPhone.getNetworkOperatorName(SubscriptionManager.getDefaultDataSubId());
|
||||
if (mIsAttached) {
|
||||
String name =
|
||||
mPhone.getNetworkOperatorName(SubscriptionManager.getDefaultDataSubId());
|
||||
if (TextUtils.isEmpty(name)) {
|
||||
if (mServiceState != null && mServiceState.isEmergencyOnly()) {
|
||||
name = getString(R.string.setup_mobile_data_emergency_only);
|
||||
@ -160,9 +161,10 @@ public class MobileDataPage extends SetupPage {
|
||||
}
|
||||
mNameView.setText(name);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateSignalStrength() {
|
||||
if (isDetached()) return;
|
||||
if (mIsAttached) {
|
||||
if (!hasService()) {
|
||||
mSignalView.setImageResource(R.drawable.ic_signal_no_signal);
|
||||
} else {
|
||||
@ -190,6 +192,7 @@ public class MobileDataPage extends SetupPage {
|
||||
}
|
||||
updateCarrierText();
|
||||
}
|
||||
}
|
||||
|
||||
private void updateDataConnectionStatus() {
|
||||
mEnableMobileData.setChecked(SetupWizardUtils.isMobileDataEnabled(getActivity()));
|
||||
|
Loading…
Reference in New Issue
Block a user