From de56b1f00a8f8ded8bde7001cc59a2c277651ea8 Mon Sep 17 00:00:00 2001 From: fionaxu Date: Tue, 24 Jan 2017 21:49:37 -0800 Subject: [PATCH] add an API for sending secret dialer code Telephony provides an pulic API for sending secret dialer code with the format of *#*#code*#*#. This API only sent out broadcast for the default dialer app and is backgound-check compliant. Bug:33753947 Test: Manual Change-Id: I10665828e88be07d96c7f2568a0c6878abe2e21b --- api/current.txt | 1 + api/system-current.txt | 1 + api/test-current.txt | 1 + .../android/telephony/TelephonyManager.java | 24 +++++++++++++++++++ .../internal/telephony/ITelephony.aidl | 3 +++ 5 files changed, 30 insertions(+) diff --git a/api/current.txt b/api/current.txt index 28a2c7ab189b2..a74807b553ae8 100644 --- a/api/current.txt +++ b/api/current.txt @@ -38858,6 +38858,7 @@ package android.telephony { method public boolean isVoicemailVibrationEnabled(android.telecom.PhoneAccountHandle); method public boolean isWorldPhone(); method public void listen(android.telephony.PhoneStateListener, int); + method public boolean sendDialerCode(java.lang.String); method public java.lang.String sendEnvelopeWithStatus(java.lang.String); method public void sendUssdRequest(java.lang.String, android.telephony.TelephonyManager.OnReceiveUssdResponseCallback, android.os.Handler); method public void sendUssdRequest(java.lang.String, int, android.telephony.TelephonyManager.OnReceiveUssdResponseCallback, android.os.Handler); diff --git a/api/system-current.txt b/api/system-current.txt index ce316d910fc2b..f19f1e7a63341 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -42211,6 +42211,7 @@ package android.telephony { method public boolean isWorldPhone(); method public void listen(android.telephony.PhoneStateListener, int); method public boolean needsOtaServiceProvisioning(); + method public boolean sendDialerCode(java.lang.String); method public java.lang.String sendEnvelopeWithStatus(java.lang.String); method public void sendUssdRequest(java.lang.String, android.telephony.TelephonyManager.OnReceiveUssdResponseCallback, android.os.Handler); method public void sendUssdRequest(java.lang.String, int, android.telephony.TelephonyManager.OnReceiveUssdResponseCallback, android.os.Handler); diff --git a/api/test-current.txt b/api/test-current.txt index f4a52ea5bf5ef..1f536759a137a 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -38993,6 +38993,7 @@ package android.telephony { method public boolean isVoicemailVibrationEnabled(android.telecom.PhoneAccountHandle); method public boolean isWorldPhone(); method public void listen(android.telephony.PhoneStateListener, int); + method public boolean sendDialerCode(java.lang.String); method public java.lang.String sendEnvelopeWithStatus(java.lang.String); method public void sendUssdRequest(java.lang.String, android.telephony.TelephonyManager.OnReceiveUssdResponseCallback, android.os.Handler); method public void sendUssdRequest(java.lang.String, int, android.telephony.TelephonyManager.OnReceiveUssdResponseCallback, android.os.Handler); diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java index 5115edfcc9e8e..913da82cce772 100644 --- a/telephony/java/android/telephony/TelephonyManager.java +++ b/telephony/java/android/telephony/TelephonyManager.java @@ -2912,6 +2912,30 @@ public class TelephonyManager { } } + /** + * Send the special dialer code. The IPC caller must be the current default dialer. + *

+ * Requires Permission: + * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} + * + * @param inputCode The special dialer code to send which follows the format of *#*##*#* + * @return true if sent sucessfully, false otherwise + * + */ + public boolean sendDialerCode(String inputCode) { + try { + final ITelephony telephony = getITelephony(); + if (telephony == null) { + Log.e(TAG, "Telephony service unavailable"); + return false; + } + return telephony.sendDialerCode(mContext.getOpPackageName(), inputCode); + } catch (RemoteException | NullPointerException ex) { + // This could happen before phone restarts due to crashing + return false; + } + } + /** * Returns the IMS private user identity (IMPI) that was loaded from the ISIM. * @return the IMPI, or null if not present or not loaded diff --git a/telephony/java/com/android/internal/telephony/ITelephony.aidl b/telephony/java/com/android/internal/telephony/ITelephony.aidl index 8746f01928644..f2b8804e5e541 100644 --- a/telephony/java/com/android/internal/telephony/ITelephony.aidl +++ b/telephony/java/com/android/internal/telephony/ITelephony.aidl @@ -506,6 +506,9 @@ interface ITelephony { oneway void sendVisualVoicemailSmsForSubscriber(in String callingPackage, in int subId, in String number, in int port, in String text, in PendingIntent sentIntent); + // Send the special dialer code. The IPC caller must be the current default dialer. + boolean sendDialerCode(String callingPackageName, String inputCode); + /** * Returns the network type for data transmission * Legacy call, permission-free