diff options
author | Tony Mak <tonymak@google.com> | 2016-01-11 14:38:11 +0000 |
---|---|---|
committer | Tony Mak <tonymak@google.com> | 2016-01-19 19:32:18 +0000 |
commit | 6390bd8d698e75232bf42f27e70e9702051e8a8a (patch) | |
tree | 7135943dbf6b5b54a9358dbdf34fdbbc5b627a42 /cmds/telecom/src | |
parent | 3dbb412c94b91a2f8f130c32417621d138c3f7ec (diff) |
Telecom shell command accepts userhandle as argument of phone account
We need a sort of way to enable phone account in managed profile for
writing cts running in managed profile.
Change-Id: I2e869e792c6e145c93a314f64a5de98e2f6e315f
Diffstat (limited to 'cmds/telecom/src')
-rw-r--r-- | cmds/telecom/src/com/android/commands/telecom/Telecom.java | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/cmds/telecom/src/com/android/commands/telecom/Telecom.java b/cmds/telecom/src/com/android/commands/telecom/Telecom.java index b7c729b4834b..63f6c9267f45 100644 --- a/cmds/telecom/src/com/android/commands/telecom/Telecom.java +++ b/cmds/telecom/src/com/android/commands/telecom/Telecom.java @@ -19,11 +19,13 @@ package com.android.commands.telecom; 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.UserHandle; import android.telecom.PhoneAccount; import android.telecom.PhoneAccountHandle; -import android.text.TextUtils; import com.android.internal.os.BaseCommand; import com.android.internal.telecom.ITelecomService; @@ -53,16 +55,17 @@ public final class Telecom extends BaseCommand { private ComponentName mComponent; private String mAccountId; private ITelecomService mTelecomService; + private IUserManager mUserManager; @Override public void onShowUsage(PrintStream out) { out.println( "usage: telecom [subcommand] [options]\n" + - "usage: telecom set-phone-account-enabled <COMPONENT> <ID>\n" + - "usage: telecom set-phone-account-disabled <COMPONENT> <ID>\n" + - "usage: telecom register-phone-account <COMPONENT> <ID> <LABEL>\n" + - "usage: telecom register-sim-phone-account <COMPONENT> <ID> <LABEL> <ADDRESS>\n" + - "usage: telecom unregister-phone-account <COMPONENT> <ID>\n" + + "usage: telecom set-phone-account-enabled <COMPONENT> <ID> <USER_SN>\n" + + "usage: telecom set-phone-account-disabled <COMPONENT> <ID> <USER_SN>\n" + + "usage: telecom register-phone-account <COMPONENT> <ID> <USER_SN> <LABEL>\n" + + "usage: telecom register-sim-phone-account <COMPONENT> <ID> <USER_SN> <LABEL> <ADDRESS>\n" + + "usage: telecom unregister-phone-account <COMPONENT> <ID> <USER_SN>\n" + "usage: telecom set-default-dialer <PACKAGE>\n" + "usage: telecom get-default-dialer\n" + "usage: telecom get-system-dialer\n" + @@ -89,6 +92,12 @@ public final class Telecom extends BaseCommand { showError("Error: Could not access the Telecom Manager. Is the system running?"); return; } + mUserManager = IUserManager.Stub + .asInterface(ServiceManager.getService(Context.USER_SERVICE)); + if (mUserManager == null) { + showError("Error: Could not access the User Manager. Is the system running?"); + return; + } String command = nextArgRequired(); switch (command) { @@ -183,10 +192,18 @@ public final class Telecom extends BaseCommand { System.out.println(mTelecomService.getSystemDialerPackage()); } - private PhoneAccountHandle getPhoneAccountHandleFromArgs() { + private PhoneAccountHandle getPhoneAccountHandleFromArgs() throws RemoteException{ final ComponentName component = parseComponentName(nextArgRequired()); final String accountId = nextArgRequired(); - return new PhoneAccountHandle(component, accountId); + final String userSnInStr = nextArgRequired(); + UserHandle userHandle; + try { + final int userSn = Integer.parseInt(userSnInStr); + userHandle = UserHandle.of(mUserManager.getUserHandle(userSn)); + } catch (NumberFormatException ex) { + throw new IllegalArgumentException ("Invalid user serial number " + userSnInStr); + } + return new PhoneAccountHandle(component, accountId, userHandle); } private ComponentName parseComponentName(String component) { |