Skip to content
Snippets Groups Projects
Commit 1047ecc8 authored by Jordan Liu's avatar Jordan Liu
Browse files

Add adb command for setting and getting SIMs

Test: manually verified adb commands work
Bug: 123643264
Change-Id: I5a9e42c23dfe217f9271b1b4d8b940375c04edc9
parent 51525408
No related branches found
No related tags found
No related merge requests found
......@@ -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,21 +97,32 @@ 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"
+ " already been registered with Telecom.\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"
+ " has already been registered with telecom.\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 "
+ "component; this will override whatever the dialer role is set to. \n"
+ "telecom set-default-dialer: Sets the override default dialer to the given"
+ " component; this will override whatever the dialer role is set to.\n"
+ "\n"
+ "telecom get-default-dialer: Displays the current default dialer. \n"
+ "telecom get-default-dialer: Displays the current default dialer.\n"
+ "\n"
+ "telecom get-system-dialer: Displays the current system dialer. \n"
+ "telecom get-system-dialer: Displays the current system dialer.\n"
+ "\n"
+ "telecom wait-on-handlers: Wait until all handlers finish their work. \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) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment