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

Commit 8e24b0b1 authored by Ling Ma's avatar Ling Ma Committed by Automerger Merge Worker
Browse files

Merge "Migrate set network selection auto from legacy subscription" into...

Merge "Migrate set network selection auto from legacy subscription" into udc-dev am: f1002487 am: 21e6bd3b

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/opt/telephony/+/22798428



Change-Id: Iad0c867c72c7a3f119059f6d624e125cdee0ac48
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 0a162553 21e6bd3b
Loading
Loading
Loading
Loading
+35 −0
Original line number Diff line number Diff line
@@ -172,6 +172,8 @@ public class GsmCdmaPhone extends Phone {
    // Key used to read/write the SIM IMSI used for storing the voice mail
    private static final String VM_SIM_IMSI = "vm_sim_imsi_key";
    /** List of Registrants to receive Supplementary Service Notifications. */
    // Key used to read/write the current sub Id. Updated on SIM loaded.
    public static final String CURR_SUBID = "curr_subid";
    private RegistrantList mSsnRegistrants = new RegistrantList();

    //CDMA
@@ -420,6 +422,17 @@ public class GsmCdmaPhone extends Phone {
                int newPreferredTtyMode = intent.getIntExtra(
                        TelecomManager.EXTRA_TTY_PREFERRED_MODE, TelecomManager.TTY_MODE_OFF);
                updateUiTtyMode(newPreferredTtyMode);
            } else if (TelephonyManager.ACTION_SIM_APPLICATION_STATE_CHANGED.equals(action)) {
                if (mPhoneId == intent.getIntExtra(
                        SubscriptionManager.EXTRA_SLOT_INDEX,
                        SubscriptionManager.INVALID_SIM_SLOT_INDEX)) {
                    int simState = intent.getIntExtra(TelephonyManager.EXTRA_SIM_STATE,
                            TelephonyManager.SIM_STATE_UNKNOWN);
                    if (simState == TelephonyManager.SIM_STATE_LOADED
                            && currentSlotSubIdChanged()) {
                        setNetworkSelectionModeAutomatic(null);
                    }
                }
            }
        }
    };
@@ -482,6 +495,7 @@ public class GsmCdmaPhone extends Phone {
                CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED);
        filter.addAction(TelecomManager.ACTION_CURRENT_TTY_MODE_CHANGED);
        filter.addAction(TelecomManager.ACTION_TTY_PREFERRED_MODE_CHANGED);
        filter.addAction(TelephonyManager.ACTION_SIM_APPLICATION_STATE_CHANGED);
        mContext.registerReceiver(mBroadcastReceiver, filter,
                android.Manifest.permission.MODIFY_PHONE_STATE, null, Context.RECEIVER_EXPORTED);

@@ -3541,6 +3555,27 @@ public class GsmCdmaPhone extends Phone {
        }
    }

    /**
     * Check if a different SIM is inserted at this slot from the last time. Storing last subId
     * in SharedPreference for now to detect SIM change.
     *
     * @return {@code true} if current slot mapping changed; {@code false} otherwise.
     */
    private boolean currentSlotSubIdChanged() {
        SharedPreferences sp =
                PreferenceManager.getDefaultSharedPreferences(mContext);
        int storedSubId = sp.getInt(CURR_SUBID + mPhoneId, -1);
        boolean changed = storedSubId != getSubId();
        if (changed) {
            // Update stored subId
            SharedPreferences.Editor editor = sp.edit();
            editor.putInt(CURR_SUBID + mPhoneId, getSubId());
            editor.apply();
        }
        Rlog.d(LOG_TAG, "currentSlotSubIdChanged: changed=" + changed);
        return changed;
    }

    public UiccCardApplication getUiccCardApplication() {
        if (isPhoneTypeGsm()) {
            return mUiccController.getUiccCardApplication(mPhoneId, UiccController.APP_FAM_3GPP);
+3 −2
Original line number Diff line number Diff line
@@ -1437,8 +1437,8 @@ public abstract class Phone extends Handler implements PhoneInternalInterface {
    @UnsupportedAppUsage
    public void setNetworkSelectionModeAutomatic(Message response) {
        Rlog.d(LOG_TAG, "setNetworkSelectionModeAutomatic, querying current mode");
        // we don't want to do this unecesarily - it acutally causes
        // the radio to repeate network selection and is costly
        // we don't want to do this unnecessarily - it actually causes
        // the radio to repeat network selection and is costly
        // first check if we're already in automatic mode
        Message msg = obtainMessage(EVENT_CHECK_FOR_NETWORK_AUTOMATIC);
        msg.obj = response;
@@ -1471,6 +1471,7 @@ public abstract class Phone extends Handler implements PhoneInternalInterface {
        nsm.operatorAlphaShort = "";

        if (doAutomatic) {
            Rlog.d(LOG_TAG, "setNetworkSelectionModeAutomatic - set network selection auto");
            Message msg = obtainMessage(EVENT_SET_NETWORK_AUTOMATIC_COMPLETE, nsm);
            mCi.setNetworkSelectionModeAutomatic(msg);
        } else {
+1 −1
Original line number Diff line number Diff line
@@ -957,7 +957,7 @@ public class UiccController extends Handler {
            log("updateSimState: phoneId=" + phoneId + ", state=" + state + ", reason="
                    + reason);
            if (!SubscriptionManager.isValidPhoneId(phoneId)) {
                Rlog.e(LOG_TAG, "updateInternalIccState: Invalid phone id " + phoneId);
                Rlog.e(LOG_TAG, "updateSimState: Invalid phone id " + phoneId);
                return;
            }

+19 −0
Original line number Diff line number Diff line
@@ -2556,4 +2556,23 @@ public class GsmCdmaPhoneTest extends TelephonyTest {
                .getSubscriptionUserHandle(anyInt());
        assertNull(mPhoneUT.getUserHandle());
    }

    @Test
    public void testResetNetworkSelectionModeOnSimSwap() {
        // Set current network selection manual mode.
        mSimulatedCommands.setNetworkSelectionModeManual("123", 0, null);
        clearInvocations(mSimulatedCommandsVerifier);

        // SIM loaded.
        Intent simLoadedIntent = new Intent(TelephonyManager.ACTION_SIM_APPLICATION_STATE_CHANGED);
        simLoadedIntent.putExtra(SubscriptionManager.EXTRA_SLOT_INDEX, mPhone.getPhoneId());
        simLoadedIntent.putExtra(TelephonyManager.EXTRA_SIM_STATE,
                TelephonyManager.SIM_STATE_LOADED);
        mContext.sendBroadcast(simLoadedIntent);

        processAllFutureMessages();
        // Verify set network selection mode to be AUTO
        verify(mSimulatedCommandsVerifier).getNetworkSelectionMode(any(Message.class));
        verify(mSimulatedCommandsVerifier).setNetworkSelectionModeAutomatic(any(Message.class));
    }
}
+11 −3
Original line number Diff line number Diff line
@@ -1500,12 +1500,17 @@ public class SimulatedCommands extends BaseCommands
    }

    @Override
    public void setNetworkSelectionModeAutomatic(Message result) {unimplemented(result);}
    public void setNetworkSelectionModeAutomatic(Message result) {
        SimulatedCommandsVerifier.getInstance().setNetworkSelectionModeAutomatic(result);
        mMockNetworkSelectionMode = 0;
    }
    @Override
    public void exitEmergencyCallbackMode(Message result) {unimplemented(result);}
    @Override
    public void setNetworkSelectionModeManual(String operatorNumeric, int ran, Message result) {
        unimplemented(result);
        SimulatedCommandsVerifier.getInstance().setNetworkSelectionModeManual(
                operatorNumeric, ran, result);
        mMockNetworkSelectionMode = 1;
    }

    /**
@@ -1522,10 +1527,13 @@ public class SimulatedCommands extends BaseCommands
        getNetworkSelectionModeCallCount.incrementAndGet();
        int ret[] = new int[1];

        ret[0] = 0;
        ret[0] = mMockNetworkSelectionMode;
        resultSuccess(result, ret);
    }

    /** 0 for automatic selection and a 1 for manual selection. */
    private int mMockNetworkSelectionMode = 0;

    private final AtomicInteger getNetworkSelectionModeCallCount = new AtomicInteger(0);

    @VisibleForTesting