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

Commit ea5f45c2 authored by Jordan Liu's avatar Jordan Liu Committed by android-build-merger
Browse files

Merge "Add adb command for setting and getting SIMs" into qt-dev am: b3c87449

am: 624189ba

Change-Id: I0f39cba6b2995ea9ca3292d3c7a4f29cf868c7a0
parents 7a52e503 624189ba
Loading
Loading
Loading
Loading
+80 −9
Original line number Diff line number Diff line
@@ -20,16 +20,21 @@ import android.content.ComponentName;
import android.content.Context;
import android.net.Uri;
import android.os.IUserManager;
import android.os.Process;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.telecom.Log;
import android.telecom.PhoneAccount;
import android.telecom.PhoneAccountHandle;
import android.telephony.TelephonyManager;
import android.text.TextUtils;

import com.android.internal.os.BaseCommand;
import com.android.internal.telecom.ITelecomService;
import com.android.internal.telephony.ITelephony;
import com.android.internal.telephony.TelephonyProperties;

import java.io.PrintStream;

@@ -62,10 +67,14 @@ public final class Telecom extends BaseCommand {
    private static final String COMMAND_GET_DEFAULT_DIALER = "get-default-dialer";
    private static final String COMMAND_GET_SYSTEM_DIALER = "get-system-dialer";
    private static final String COMMAND_WAIT_ON_HANDLERS = "wait-on-handlers";
    private static final String COMMAND_SET_SIM_COUNT = "set-sim-count";
    private static final String COMMAND_GET_SIM_CONFIG = "get-sim-config";
    private static final String COMMAND_GET_MAX_PHONES = "get-max-phones";

    private ComponentName mComponent;
    private String mAccountId;
    private ITelecomService mTelecomService;
    private ITelephony mTelephonyService;
    private IUserManager mUserManager;

    @Override
@@ -88,11 +97,14 @@ public final class Telecom extends BaseCommand {
                + "usage: telecom get-default-dialer\n"
                + "usage: telecom get-system-dialer\n"
                + "usage: telecom wait-on-handlers\n"
                + "usage: telecom set-sim-count <COUNT>\n"
                + "usage: telecom get-sim-config\n"
                + "usage: telecom get-max-phones\n"
                + "\n"
                + "telecom set-phone-account-enabled: Enables the given phone account, if it has \n"
                + "telecom set-phone-account-enabled: Enables the given phone account, if it has"
                        + " already been registered with Telecom.\n"
                + "\n"
                + "telecom set-phone-account-disabled: Disables the given phone account, if it \n"
                + "telecom set-phone-account-disabled: Disables the given phone account, if it"
                        + " has already been registered with telecom.\n"
                + "\n"
                + "telecom set-default-dialer: Sets the override default dialer to the given"
@@ -103,6 +115,14 @@ public final class Telecom extends BaseCommand {
                + "telecom get-system-dialer: Displays the current system dialer.\n"
                + "\n"
                + "telecom wait-on-handlers: Wait until all handlers finish their work.\n"
                + "\n"
                + "telecom set-sim-count: Set num SIMs (2 for DSDS, 1 for single SIM."
                        + " This may restart the device.\n"
                + "\n"
                + "telecom get-sim-config: Get the mSIM config string. \"DSDS\" for DSDS mode,"
                        + " or \"\" for single SIM\n"
                + "\n"
                + "telecom get-max-phones: Get the max supported phones from the modem.\n"
        );
    }

@@ -115,6 +135,15 @@ public final class Telecom extends BaseCommand {
            showError("Error: Could not access the Telecom Manager. Is the system running?");
            return;
        }

        mTelephonyService = ITelephony.Stub.asInterface(
                ServiceManager.getService(Context.TELEPHONY_SERVICE));
        if (mTelephonyService == null) {
            Log.w(this, "onRun: Can't access telephony service.");
            showError("Error: Could not access the Telephony Service. Is the system running?");
            return;
        }

        mUserManager = IUserManager.Stub
                .asInterface(ServiceManager.getService(Context.USER_SERVICE));
        if (mUserManager == null) {
@@ -170,6 +199,15 @@ public final class Telecom extends BaseCommand {
            case COMMAND_WAIT_ON_HANDLERS:
                runWaitOnHandler();
                break;
            case COMMAND_SET_SIM_COUNT:
                runSetSimCount();
                break;
            case COMMAND_GET_SIM_CONFIG:
                runGetSimConfig();
                break;
            case COMMAND_GET_MAX_PHONES:
                runGetMaxPhones();
                break;
            default:
                Log.w(this, "onRun: unknown command: %s", command);
                throw new IllegalArgumentException ("unknown command '" + command + "'");
@@ -271,6 +309,35 @@ public final class Telecom extends BaseCommand {

    }

    private void runSetSimCount() throws RemoteException {
        if (!callerIsRoot()) {
            System.out.println("set-sim-count requires adb root");
            return;
        }
        int numSims = Integer.parseInt(nextArgRequired());
        System.out.println("Setting sim count to " + numSims + ". Device may reboot");
        mTelephonyService.switchMultiSimConfig(numSims);
    }

    /**
     * Prints the mSIM config to the console.
     * "DSDS" for a phone in DSDS mode
     * "" (empty string) for a phone in SS mode
     */
    private void runGetSimConfig() throws RemoteException {
        System.out.println(SystemProperties.get(TelephonyProperties.PROPERTY_MULTI_SIM_CONFIG));
    }

    private void runGetMaxPhones() throws RemoteException {
        // This assumes the max number of SIMs is 2, which it currently is
        if (TelephonyManager.MULTISIM_ALLOWED
                == mTelephonyService.isMultiSimSupported("com.android.commands.telecom")) {
            System.out.println("2");
        } else {
            System.out.println("1");
        }
    }

    private PhoneAccountHandle getPhoneAccountHandleFromArgs() throws RemoteException {
        if (TextUtils.isEmpty(mArgs.peekNextArg())) {
            return null;
@@ -289,6 +356,10 @@ public final class Telecom extends BaseCommand {
        return new PhoneAccountHandle(component, accountId, userHandle);
    }

    private boolean callerIsRoot() {
        return Process.ROOT_UID == Process.myUid();
    }

    private ComponentName parseComponentName(String component) {
        ComponentName cn = ComponentName.unflattenFromString(component);
        if (cn == null) {