Add telephony commands about SMS apps

- Also add a new broadcast that's sent after the default SMS app
changes.

- Also fix on which user ACTION_DEFAULT_SMS_PACKAGE_CHANGED is sent.

New commands:
- cmd phone sms get-apps [--user USER_ID]
  Print all SMS apps on a user.

- cmd phone sms get-default-app [--user USER_ID]
  Get the default SMS app.

- cmd phone sms set-default-app [--user USER_ID] PACKAGE_NAME
  Set PACKAGE_NAME as the default SMS app.

Bug: 109809543
Test: With a secondary user (user 10) running and "com.textra" installed on
user-0 and selected as the default:

--------------------------------------------------------
- Test get-apps

$ cmd phone sms get-apps
com.textra
com.google.android.apps.messaging

$ cmd phone sms get-apps --user 0
com.textra
com.google.android.apps.messaging

$ cmd phone sms get-apps --user 10
com.google.android.apps.messaging

--------------------------------------------------------
- Test get-deafult-app

$ cmd phone sms get-default-app
com.textra

$ cmd phone sms get-default-app --user 0
com.textra

$ cmd phone sms get-default-app --user 10
com.google.android.apps.messaging

--------------------------------------------------------
- Change the default app

$ cmd phone sms set-default-app --use0 com.google.android.apps.messaging
SMS app set to com.google.android.apps.messaging

$ cmd phone sms get-default-app --user 0
com.google.android.apps.messaging

$ cmd phone sms get-default-app --user 10
com.google.android.apps.messaging

- Change again
$ cmd phone sms set-default-app com.textra
SMS app set to com.textra

$ cmd phone sms get-default-app
com.textra

$ cmd phone sms get-default-app --user 10
com.google.android.apps.messaging

--------------------------------------------------------
- Package doesn't exist

$ cmd phone sms set-default-app a.b.c

Exception occurred while executing:
java.lang.IllegalArgumentException: Package a.b.c is not an SMS app
    at com.android.phone.PhoneInterfaceManager.setDefaultSmsApp(PhoneInterfaceManager.java:5420)
    at com.android.phone.TelephonyShellCommand.handleSmsSetDefaultApp(TelephonyShellCommand.java:398)
    at com.android.phone.TelephonyShellCommand.handleSmsCommand(TelephonyShellCommand.java:338)
    at com.android.phone.TelephonyShellCommand.onCommand(TelephonyShellCommand.java:72)
    at android.os.ShellCommand.exec(ShellCommand.java:103)
    at com.android.phone.PhoneInterfaceManager.onShellCommand(PhoneInterfaceManager.java:4896)
    at android.os.Binder.shellCommand(Binder.java:677)
    at android.os.Binder.onTransact(Binder.java:561)
    at com.android.internal.telephony.ITelephony$Stub.onTransact(ITelephony.java:4985)
    at android.os.Binder.execTransact(Binder.java:776)

--------------------------------------------------------
- User doesn't exist

$ cmd phone sms get-apps --user 123

Exception occurred while executing:
java.lang.IllegalStateException: User 123 does not exist or not running
    at com.android.phone.PhoneInterfaceManager.ensureUserRunning(PhoneInterfaceManager.java:5366)
    at com.android.phone.PhoneInterfaceManager.getSmsApps(PhoneInterfaceManager.java:5376)
    at com.android.phone.TelephonyShellCommand.handleSmsGetApps(TelephonyShellCommand.java:375)
    at com.android.phone.TelephonyShellCommand.handleSmsCommand(TelephonyShellCommand.java:332)
    at com.android.phone.TelephonyShellCommand.onCommand(TelephonyShellCommand.java:72)
    at android.os.ShellCommand.exec(ShellCommand.java:103)
    at com.android.phone.PhoneInterfaceManager.onShellCommand(PhoneInterfaceManager.java:4896)
    at android.os.Binder.shellCommand(Binder.java:677)
    at android.os.Binder.onTransact(Binder.java:561)
    at com.android.internal.telephony.ITelephony$Stub.onTransact(ITelephony.java:4985)
    at android.os.Binder.execTransact(Binder.java:776)

$ cmd phone sms get-default-app --user 123

Exception occurred while executing:
java.lang.IllegalStateException: User 123 does not exist or not running
    at com.android.phone.PhoneInterfaceManager.ensureUserRunning(PhoneInterfaceManager.java:5366)
    at com.android.phone.PhoneInterfaceManager.getDefaultSmsApp(PhoneInterfaceManager.java:5396)
    at com.android.phone.TelephonyShellCommand.handleSmsGetDefaultApp(TelephonyShellCommand.java:387)
    at com.android.phone.TelephonyShellCommand.handleSmsCommand(TelephonyShellCommand.java:335)
    at com.android.phone.TelephonyShellCommand.onCommand(TelephonyShellCommand.java:72)
    at android.os.ShellCommand.exec(ShellCommand.java:103)
    at com.android.phone.PhoneInterfaceManager.onShellCommand(PhoneInterfaceManager.java:4896)
    at android.os.Binder.shellCommand(Binder.java:677)
    at android.os.Binder.onTransact(Binder.java:561)
    at com.android.internal.telephony.ITelephony$Stub.onTransact(ITelephony.java:4985)
    at android.os.Binder.execTransact(Binder.java:776)

$ cmd phone sms set-default-app --user 123 a.b.c

Exception occurred while executing:
java.lang.IllegalStateException: User 123 does not exist or not running
    at com.android.phone.PhoneInterfaceManager.ensureUserRunning(PhoneInterfaceManager.java:5366)
    at com.android.phone.PhoneInterfaceManager.setDefaultSmsApp(PhoneInterfaceManager.java:5410)
    at com.android.phone.TelephonyShellCommand.handleSmsSetDefaultApp(TelephonyShellCommand.java:398)
    at com.android.phone.TelephonyShellCommand.handleSmsCommand(TelephonyShellCommand.java:338)
    at com.android.phone.TelephonyShellCommand.onCommand(TelephonyShellCommand.java:72)
    at android.os.ShellCommand.exec(ShellCommand.java:103)
    at com.android.phone.PhoneInterfaceManager.onShellCommand(PhoneInterfaceManager.java:4896)
    at android.os.Binder.shellCommand(Binder.java:677)
    at android.os.Binder.onTransact(Binder.java:561)
    at com.android.internal.telephony.ITelephony$Stub.onTransact(ITelephony.java:4985)
    at android.os.Binder.execTransact(Binder.java:776)

Change-Id: I8e01ae3d18f6e58963a39977dccb64a607cfb55d
2 files changed