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

Commit 3b1b77ec authored by terrycrhuang's avatar terrycrhuang Committed by jimsun
Browse files

Add API for MockModemService overriding mechanism

The following operations will be used in shell commands during testing only
- setModemService
- getModemService

Bug: 203241555
Test: make
Change-Id: Id27d89c23d1fef4c1848c091183991384e8871c1
Merged-In: Id27d89c23d1fef4c1848c091183991384e8871c1
parent 6d42fa3a
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -2679,6 +2679,25 @@ public interface CommandsInterface {
     */
    default void getSlicingConfig(Message result) {};

    /**
     * Request to enable/disable the mock modem service.
     * This is used in shell commands during CTS testing only.
     *
     * @param serviceName the service name which telephony wants to bind to
     */
    default boolean setModemService(String serviceName) {
        return true;
    };

   /**
     * Return the class name of the currently bound modem service.
     *
     * @return the class name of the modem service.
     */
    default String getModemService() {
        return "default";
    };

   /**
     * Request the SIM phonebook records of all activated UICC applications
     *
+47 −0
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ public class PhoneConfigurationManager {
    public static final String DSDS = "dsds";
    public static final String TSTS = "tsts";
    public static final String SSSS = "";
    public static final String CTS_MOCK_MODEM_SERVICE = "android.telephony.cts.MockModemService";
    private static final String LOG_TAG = "PhoneCfgMgr";
    private static final int EVENT_SWITCH_DSDS_CONFIG_DONE = 100;
    private static final int EVENT_GET_MODEM_STATUS = 101;
@@ -444,6 +445,52 @@ public class PhoneConfigurationManager {
        intent.putExtra(EXTRA_ACTIVE_SIM_SUPPORTED_COUNT, numOfActiveModems);
        mContext.sendBroadcast(intent);
    }
    /**
     * This is invoked from shell commands during CTS testing only.
     * @return true if the modem service is set successfully, false otherwise.
     */
    public boolean setModemService(String serviceName) {
        if (mRadioConfig == null || mPhones[0] == null) {
            return false;
        }

        log("setModemService: " + serviceName);
        boolean statusRadioConfig = false;
        boolean statusRil = false;

        if (serviceName != null) {
            // Only CTS mock modem service is allowed to swith.
            if (!serviceName.equals(CTS_MOCK_MODEM_SERVICE)) {
                loge(serviceName + " is not allowed to switch");
                return false;
            }

            statusRadioConfig = mRadioConfig.setModemService(serviceName);

            //TODO: consider multi-sim case (b/210073692)
            statusRil = mPhones[0].mCi.setModemService(serviceName);
        } else {
            statusRadioConfig = mRadioConfig.setModemService(null);

            //TODO: consider multi-sim case
            statusRil = mPhones[0].mCi.setModemService(null);
        }

        return statusRadioConfig && statusRil;
    }

     /**
     * This is invoked from shell commands to query during CTS testing only.
     * @return the service name of the connected service.
     */
    public String getModemService() {
        //TODO: consider multi-sim case
        if (mPhones[0] == null) {
            return "";
        }

        return mPhones[0].mCi.getModemService();
    }

    /**
     * A wrapper class that wraps some methods so that they can be replaced or mocked in unit-tests.
+29 −0
Original line number Diff line number Diff line
@@ -456,6 +456,35 @@ public class RIL extends BaseCommands implements CommandsInterface {
        }
    }

    /**
     * Request to enable/disable the mock modem service.
     * This is invoked from shell commands during CTS testing only.
     *
     * @param serviceName the service name we want to bind to
     */
    public boolean setModemService(String serviceName) {

        if (serviceName != null) {
            riljLoge("Overriding connected service to MockModemService");
            // TODO: binding to mockmodem service for testing only

            for (int service = MIN_SERVICE_IDX; service <= MAX_SERVICE_IDX; service++) {
                resetProxyAndRequestList(service);
            }
        } else {
            // TODO: unbinding mockmodem service
        }
        return true;
    }

    /**
     * Get current bound service in Radio Module
     */
    public String getModemService() {
        //TODO: return the bound service based on connected proxy
        return "default";
    }

    /** Set a radio HAL fallback compatibility override. */
    @VisibleForTesting
    public void setCompatVersion(int rilRequest, @NonNull HalVersion halVersion) {
+11 −0
Original line number Diff line number Diff line
@@ -215,6 +215,17 @@ public class RadioConfig extends Handler {
        return mRadioConfigProxy;
    }

    /**
     * Request to enable/disable the mock modem service.
     * This is invoked from shell commands during CTS testing only.
     *
     * @param serviceName the service name we want to bind to
     */
    public boolean setModemService(String serviceName) {
        loge("Overriding connected service to MockModemService");
        return true;
    }

    private void updateRadioConfigProxy() {
        IBinder service = ServiceManager.waitForDeclaredService(
                android.hardware.radio.config.IRadioConfig.DESCRIPTOR + "/default");