Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d756a6bc authored by Amit Mahajan's avatar Amit Mahajan
Browse files

Change to append subId to network selection related sharedPreferences.

Bug: 19023266
Change-Id: Ia7b2ac5b37d5abb1231288caf923336bf0bec9e1
parent 45736edd
Loading
Loading
Loading
Loading
+17 −11
Original line number Diff line number Diff line
@@ -906,17 +906,23 @@ public abstract class PhoneBase extends Handler implements Phone {
    }

    private void updateSavedNetworkOperator(NetworkSelectMessage nsm) {
        int subId = getSubId();
        if (SubscriptionManager.isValidSubscriptionId(subId)) {
            // open the shared preferences editor, and write the value.
            // nsm.operatorNumeric is "" if we're in automatic.selection.
            SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext());
            SharedPreferences.Editor editor = sp.edit();
        editor.putString(NETWORK_SELECTION_KEY, nsm.operatorNumeric);
        editor.putString(NETWORK_SELECTION_NAME_KEY, nsm.operatorAlphaLong);
            editor.putString(NETWORK_SELECTION_KEY + subId, nsm.operatorNumeric);
            editor.putString(NETWORK_SELECTION_NAME_KEY + subId, nsm.operatorAlphaLong);

            // commit and log the result.
            if (!editor.commit()) {
                Rlog.e(LOG_TAG, "failed to commit network selection preference");
            }
        } else {
            Rlog.e(LOG_TAG, "Cannot update network selection preference due to invalid subId " +
                    subId);
        }
    }

    /**
@@ -946,7 +952,7 @@ public abstract class PhoneBase extends Handler implements Phone {
    private String getSavedNetworkSelection() {
        // open the shared preferences and search with our key.
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext());
        return sp.getString(NETWORK_SELECTION_KEY, "");
        return sp.getString(NETWORK_SELECTION_KEY + getSubId(), "");
    }

    /**
+32 −2
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import static com.android.internal.telephony.TelephonyProperties.PROPERTY_ICC_OP
import android.app.PendingIntent;
import android.content.Context;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.os.AsyncResult;
import android.os.Handler;
import android.os.Message;
@@ -28,6 +29,7 @@ import android.os.Registrant;
import android.os.RegistrantList;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.preference.PreferenceManager;
import android.telephony.CellInfo;
import android.telephony.Rlog;
import android.telephony.ServiceState;
@@ -251,12 +253,19 @@ public abstract class ServiceStateTracker extends Handler {
            if (previousSubId != subId) {
                previousSubId = subId;
                if (SubscriptionManager.isValidSubscriptionId(subId)) {
                    int networkType = PhoneFactory.calculatePreferredNetworkType(
                            mPhoneBase.getContext(), subId);
                    Context context = mPhoneBase.getContext();
                    int networkType = PhoneFactory.calculatePreferredNetworkType(context, subId);
                    mCi.setPreferredNetworkType(networkType, null);

                    mPhoneBase.notifyCallForwardingIndicator();

                    boolean skipRestoringSelection = context.getResources().getBoolean(
                            com.android.internal.R.bool.skip_restoring_network_selection);
                    if (!skipRestoringSelection) {
                        // restore the previous network selection.
                        mPhoneBase.restoreSavedNetworkSelection(null);
                    }

                    mPhoneBase.setSystemProperty(TelephonyProperties.PROPERTY_DATA_NETWORK_TYPE,
                        ServiceState.rilRadioTechnologyToString(mSS.getRilDataRadioTechnology()));

@@ -265,6 +274,27 @@ public abstract class ServiceStateTracker extends Handler {
                                mCurPlmn, mCurShowSpn, mCurSpn);
                        mSpnUpdatePending = false;
                    }

                    // Remove old network selection sharedPreferences since SP key names are now
                    // changed to include subId. This will be done only once when upgrading from an
                    // older build that did not include subId in the names.
                    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(
                            context);
                    String oldNetworkSelectionName = sp.getString(PhoneBase.
                            NETWORK_SELECTION_NAME_KEY, "");
                    String oldNetworkSelection = sp.getString(PhoneBase.NETWORK_SELECTION_KEY,
                            "");
                    if (!TextUtils.isEmpty(oldNetworkSelectionName) ||
                            !TextUtils.isEmpty(oldNetworkSelection)) {
                        SharedPreferences.Editor editor = sp.edit();
                        editor.putString(PhoneBase.NETWORK_SELECTION_NAME_KEY + subId,
                                oldNetworkSelectionName);
                        editor.putString(PhoneBase.NETWORK_SELECTION_KEY + subId,
                                oldNetworkSelection);
                        editor.remove(PhoneBase.NETWORK_SELECTION_NAME_KEY);
                        editor.remove(PhoneBase.NETWORK_SELECTION_KEY);
                        editor.commit();
                    }
                }
            }
        }
+0 −7
Original line number Diff line number Diff line
@@ -315,13 +315,6 @@ final class GsmServiceStateTracker extends ServiceStateTracker {
                break;

            case EVENT_SIM_READY:
                boolean skipRestoringSelection = mPhone.getContext().getResources().getBoolean(
                        com.android.internal.R.bool.skip_restoring_network_selection);

                if (!skipRestoringSelection) {
                    // restore the previous network selection.
                    mPhone.restoreSavedNetworkSelection(null);
                }
                pollState();
                // Signal strength polling stops when radio is off
                queueNextSignalStrengthPoll();