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

Commit 39d6cf93 authored by Jack Yu's avatar Jack Yu
Browse files

Properly support service state override

In addition to override the general service state,
also override the inner NetworkRegistrationInfo.

Bug: 244064524
Test: Manual
Change-Id: I7f3e04e4be8bb10d50df2bbfaccd13980b633114
parent f48cc83a
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -325,7 +325,7 @@ public abstract class Phone extends Handler implements PhoneInternalInterface {
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
    protected AtomicReference<UiccCardApplication> mUiccApplication =
            new AtomicReference<UiccCardApplication>();
    TelephonyTester mTelephonyTester;
    private TelephonyTester mTelephonyTester;
    private String mName;
    private final String mActionDetached;
    private final String mActionAttached;
@@ -4875,6 +4875,13 @@ public abstract class Phone extends Handler implements PhoneInternalInterface {
    public void setTerminalBasedCallWaitingSupported(boolean supported) {
    }

    /**
     * @return Telephony tester instance.
     */
    public @Nullable TelephonyTester getTelephonyTester() {
        return mTelephonyTester;
    }

    public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
        pw.println("Phone: subId=" + getSubId());
        pw.println(" mPhoneId=" + mPhoneId);
+2 −2
Original line number Diff line number Diff line
@@ -3400,8 +3400,8 @@ public class ServiceStateTracker extends Handler {
        updateNrFrequencyRangeFromPhysicalChannelConfigs(mLastPhysicalChannelConfigList, mNewSS);
        updateNrStateFromPhysicalChannelConfigs(mLastPhysicalChannelConfigList, mNewSS);

        if (TelephonyUtils.IS_DEBUGGABLE && mPhone.mTelephonyTester != null) {
            mPhone.mTelephonyTester.overrideServiceState(mNewSS);
        if (TelephonyUtils.IS_DEBUGGABLE && mPhone.getTelephonyTester() != null) {
            mPhone.getTelephonyTester().overrideServiceState(mNewSS);
        }

        NetworkRegistrationInfo networkRegState = mNewSS.getNetworkRegistrationInfo(
+40 −7
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.internal.telephony;

import android.annotation.NonNull;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@@ -200,11 +201,7 @@ public class TelephonyTester {
                    sendTestSuppServiceNotification(intent);
                } else if (action.equals(ACTION_TEST_SERVICE_STATE)) {
                    log("handle test service state changed intent");
                    // Trigger the service state update. The replacement will be done in
                    // overrideServiceState().
                    mServiceStateTestIntent = intent;
                    mPhone.getServiceStateTracker().sendEmptyMessage(
                            ServiceStateTracker.EVENT_NETWORK_STATE_CHANGED);
                    setServiceStateTestIntent(intent);
                } else if (action.equals(ACTION_TEST_IMS_E_CALL)) {
                    log("handle test IMS ecall intent");
                    testImsECall();
@@ -388,6 +385,19 @@ public class TelephonyTester {
        }
    }

    /**
     * Set the service state test intent.
     *
     * @param intent The service state test intent.
     */
    public void setServiceStateTestIntent(@NonNull Intent intent) {
        mServiceStateTestIntent = intent;
        // Trigger the service state update. The replacement will be done in
        // overrideServiceState().
        mPhone.getServiceStateTracker().sendEmptyMessage(
                ServiceStateTracker.EVENT_NETWORK_STATE_CHANGED);
    }

    void overrideServiceState(ServiceState ss) {
        if (mServiceStateTestIntent == null || ss == null) return;
        if (mPhone.getPhoneId() != mServiceStateTestIntent.getIntExtra(
@@ -401,13 +411,36 @@ public class TelephonyTester {
        }

        if (mServiceStateTestIntent.hasExtra(EXTRA_VOICE_REG_STATE)) {
            int state = mServiceStateTestIntent.getIntExtra(EXTRA_DATA_REG_STATE,
                    ServiceState.STATE_OUT_OF_SERVICE);
            ss.setVoiceRegState(mServiceStateTestIntent.getIntExtra(EXTRA_VOICE_REG_STATE,
                    ServiceState.STATE_OUT_OF_SERVICE));
            NetworkRegistrationInfo nri = ss.getNetworkRegistrationInfo(
                    NetworkRegistrationInfo.DOMAIN_CS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN);
            NetworkRegistrationInfo.Builder builder = new NetworkRegistrationInfo.Builder(nri);
            if (state == ServiceState.STATE_IN_SERVICE) {
                builder.setRegistrationState(NetworkRegistrationInfo.REGISTRATION_STATE_HOME);
            } else {
                builder.setRegistrationState(
                        NetworkRegistrationInfo.REGISTRATION_STATE_NOT_REGISTERED_OR_SEARCHING);
            }
            ss.addNetworkRegistrationInfo(builder.build());
            log("Override voice service state with " + ss.getState());
        }
        if (mServiceStateTestIntent.hasExtra(EXTRA_DATA_REG_STATE)) {
            ss.setDataRegState(mServiceStateTestIntent.getIntExtra(EXTRA_DATA_REG_STATE,
                    ServiceState.STATE_OUT_OF_SERVICE));
            int state = mServiceStateTestIntent.getIntExtra(EXTRA_DATA_REG_STATE,
                    ServiceState.STATE_OUT_OF_SERVICE);
            ss.setDataRegState(state);
            NetworkRegistrationInfo nri = ss.getNetworkRegistrationInfo(
                    NetworkRegistrationInfo.DOMAIN_PS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN);
            NetworkRegistrationInfo.Builder builder = new NetworkRegistrationInfo.Builder(nri);
            if (state == ServiceState.STATE_IN_SERVICE) {
                builder.setRegistrationState(NetworkRegistrationInfo.REGISTRATION_STATE_HOME);
            } else {
                builder.setRegistrationState(
                        NetworkRegistrationInfo.REGISTRATION_STATE_NOT_REGISTERED_OR_SEARCHING);
            }
            ss.addNetworkRegistrationInfo(builder.build());
            log("Override data service state with " + ss.getDataRegistrationState());
        }
        if (mServiceStateTestIntent.hasExtra(EXTRA_OPERATOR)) {