Merge "Add adb command for setting and getting SIMs" into qt-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
b3c874492f
@@ -20,16 +20,21 @@ import android.content.ComponentName;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.IUserManager;
|
import android.os.IUserManager;
|
||||||
|
import android.os.Process;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.ServiceManager;
|
import android.os.ServiceManager;
|
||||||
|
import android.os.SystemProperties;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.telecom.Log;
|
import android.telecom.Log;
|
||||||
import android.telecom.PhoneAccount;
|
import android.telecom.PhoneAccount;
|
||||||
import android.telecom.PhoneAccountHandle;
|
import android.telecom.PhoneAccountHandle;
|
||||||
|
import android.telephony.TelephonyManager;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import com.android.internal.os.BaseCommand;
|
import com.android.internal.os.BaseCommand;
|
||||||
import com.android.internal.telecom.ITelecomService;
|
import com.android.internal.telecom.ITelecomService;
|
||||||
|
import com.android.internal.telephony.ITelephony;
|
||||||
|
import com.android.internal.telephony.TelephonyProperties;
|
||||||
|
|
||||||
import java.io.PrintStream;
|
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_DEFAULT_DIALER = "get-default-dialer";
|
||||||
private static final String COMMAND_GET_SYSTEM_DIALER = "get-system-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_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 ComponentName mComponent;
|
||||||
private String mAccountId;
|
private String mAccountId;
|
||||||
private ITelecomService mTelecomService;
|
private ITelecomService mTelecomService;
|
||||||
|
private ITelephony mTelephonyService;
|
||||||
private IUserManager mUserManager;
|
private IUserManager mUserManager;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -88,11 +97,14 @@ public final class Telecom extends BaseCommand {
|
|||||||
+ "usage: telecom get-default-dialer\n"
|
+ "usage: telecom get-default-dialer\n"
|
||||||
+ "usage: telecom get-system-dialer\n"
|
+ "usage: telecom get-system-dialer\n"
|
||||||
+ "usage: telecom wait-on-handlers\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"
|
+ "\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"
|
+ " already been registered with Telecom.\n"
|
||||||
+ "\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"
|
+ " has already been registered with telecom.\n"
|
||||||
+ "\n"
|
+ "\n"
|
||||||
+ "telecom set-default-dialer: Sets the override default dialer to the given"
|
+ "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"
|
+ "telecom get-system-dialer: Displays the current system dialer.\n"
|
||||||
+ "\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?");
|
showError("Error: Could not access the Telecom Manager. Is the system running?");
|
||||||
return;
|
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
|
mUserManager = IUserManager.Stub
|
||||||
.asInterface(ServiceManager.getService(Context.USER_SERVICE));
|
.asInterface(ServiceManager.getService(Context.USER_SERVICE));
|
||||||
if (mUserManager == null) {
|
if (mUserManager == null) {
|
||||||
@@ -170,6 +199,15 @@ public final class Telecom extends BaseCommand {
|
|||||||
case COMMAND_WAIT_ON_HANDLERS:
|
case COMMAND_WAIT_ON_HANDLERS:
|
||||||
runWaitOnHandler();
|
runWaitOnHandler();
|
||||||
break;
|
break;
|
||||||
|
case COMMAND_SET_SIM_COUNT:
|
||||||
|
runSetSimCount();
|
||||||
|
break;
|
||||||
|
case COMMAND_GET_SIM_CONFIG:
|
||||||
|
runGetSimConfig();
|
||||||
|
break;
|
||||||
|
case COMMAND_GET_MAX_PHONES:
|
||||||
|
runGetMaxPhones();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
Log.w(this, "onRun: unknown command: %s", command);
|
Log.w(this, "onRun: unknown command: %s", command);
|
||||||
throw new IllegalArgumentException ("unknown command '" + 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 {
|
private PhoneAccountHandle getPhoneAccountHandleFromArgs() throws RemoteException {
|
||||||
if (TextUtils.isEmpty(mArgs.peekNextArg())) {
|
if (TextUtils.isEmpty(mArgs.peekNextArg())) {
|
||||||
return null;
|
return null;
|
||||||
@@ -289,6 +356,10 @@ public final class Telecom extends BaseCommand {
|
|||||||
return new PhoneAccountHandle(component, accountId, userHandle);
|
return new PhoneAccountHandle(component, accountId, userHandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean callerIsRoot() {
|
||||||
|
return Process.ROOT_UID == Process.myUid();
|
||||||
|
}
|
||||||
|
|
||||||
private ComponentName parseComponentName(String component) {
|
private ComponentName parseComponentName(String component) {
|
||||||
ComponentName cn = ComponentName.unflattenFromString(component);
|
ComponentName cn = ComponentName.unflattenFromString(component);
|
||||||
if (cn == null) {
|
if (cn == null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user