From f7488d087441fafd1279f3e6158cd3d197a9c5e3 Mon Sep 17 00:00:00 2001 From: Taesu Lee Date: Tue, 16 Jul 2019 14:13:05 +0900 Subject: [PATCH] New APIs for SMSC address Added getSmscAddress() and setSmscAddress() to access SMSC address in (U)SIM through the SmsManager. getSmscAddress() requires that the calling app is the default SMS app, or has READ_PRIVILEGED_PHONE_STATE or the carrier privileges. setSmscAddress() requires that the calling app is the default SMS app, or has MODIFY_PHONE_STATE or the carrier privileges. Test: Manual Change-Id: Icb21aff450f71b30ef6a1181834014bf7b85b8e1 Signed-off-by: Taesu Lee --- api/current.txt | 2 + .../java/android/telephony/SmsManager.java | 70 +++++++++++++++++++ .../com/android/internal/telephony/ISms.aidl | 19 +++++ .../internal/telephony/ISmsImplBase.java | 11 +++ 4 files changed, 102 insertions(+) diff --git a/api/current.txt b/api/current.txt index 8b06719dfad57..95338e882b850 100644 --- a/api/current.txt +++ b/api/current.txt @@ -44726,6 +44726,7 @@ package android.telephony { method public static int getDefaultSmsSubscriptionId(); method public static android.telephony.SmsManager getSmsManagerForSubscriptionId(int); method @RequiresPermission(android.Manifest.permission.SMS_FINANCIAL_TRANSACTIONS) public void getSmsMessagesForFinancialApp(android.os.Bundle, @NonNull java.util.concurrent.Executor, @NonNull android.telephony.SmsManager.FinancialSmsCallback); + method @Nullable @RequiresPermission("android.permission.READ_PRIVILEGED_PHONE_STATE") public String getSmscAddress(); method public int getSubscriptionId(); method public void injectSmsPdu(byte[], String, android.app.PendingIntent); method public void sendDataMessage(String, String, short, byte[], android.app.PendingIntent, android.app.PendingIntent); @@ -44733,6 +44734,7 @@ package android.telephony { method public void sendMultipartTextMessage(String, String, java.util.ArrayList, java.util.ArrayList, java.util.ArrayList); method public void sendTextMessage(String, String, String, android.app.PendingIntent, android.app.PendingIntent); method @RequiresPermission(allOf={android.Manifest.permission.MODIFY_PHONE_STATE, android.Manifest.permission.SEND_SMS}) public void sendTextMessageWithoutPersisting(String, String, String, android.app.PendingIntent, android.app.PendingIntent); + method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public boolean setSmscAddress(@NonNull String); field public static final String EXTRA_MMS_DATA = "android.telephony.extra.MMS_DATA"; field public static final String EXTRA_MMS_HTTP_STATUS = "android.telephony.extra.MMS_HTTP_STATUS"; field public static final String MMS_CONFIG_ALIAS_ENABLED = "aliasEnabled"; diff --git a/telephony/java/android/telephony/SmsManager.java b/telephony/java/android/telephony/SmsManager.java index 209d46253a075..f661bba4425fd 100644 --- a/telephony/java/android/telephony/SmsManager.java +++ b/telephony/java/android/telephony/SmsManager.java @@ -3049,4 +3049,74 @@ public final class SmsManager { } return SmsManager.SMS_CATEGORY_NOT_SHORT_CODE; } + + /** + * Gets the SMSC address from (U)SIM. + * + *

Note: Using this method requires that your app is the + * default SMS application, or READ_PRIVILEGED_PHONE_STATE permission, or has the carrier + * privileges.

+ * + *

Note: This method will never trigger an SMS disambiguation + * dialog. If this method is called on a device that has multiple active subscriptions, this + * {@link SmsManager} instance has been created with {@link #getDefault()}, and no user-defined + * default subscription is defined, the subscription ID associated with this method will be + * INVALID, which will result in the operation being completed on the subscription associated + * with logical slot 0. Use {@link #getSmsManagerForSubscriptionId(int)} to ensure the operation + * is performed on the correct subscription. + *

+ * + * @return the SMSC address string, null if failed. + */ + @SuppressAutoDoc // for carrier privileges and default SMS application. + @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) + @Nullable + public String getSmscAddress() { + String smsc = null; + + try { + ISms iSms = getISmsService(); + if (iSms != null) { + smsc = iSms.getSmscAddressFromIccEfForSubscriber( + getSubscriptionId(), ActivityThread.currentPackageName()); + } + } catch (RemoteException ex) { + // ignore it + } + return smsc; + } + + /** + * Sets the SMSC address on (U)SIM. + * + *

Note: Using this method requires that your app is the + * default SMS application, or has {@link android.Manifest.permission#MODIFY_PHONE_STATE} + * permission, or has the carrier privileges.

+ * + *

Note: This method will never trigger an SMS disambiguation + * dialog. If this method is called on a device that has multiple active subscriptions, this + * {@link SmsManager} instance has been created with {@link #getDefault()}, and no user-defined + * default subscription is defined, the subscription ID associated with this method will be + * INVALID, which will result in the operation being completed on the subscription associated + * with logical slot 0. Use {@link #getSmsManagerForSubscriptionId(int)} to ensure the operation + * is performed on the correct subscription. + *

+ * + * @param smsc the SMSC address string. + * @return true for success, false otherwise. + */ + @SuppressAutoDoc // for carrier privileges and default SMS application. + @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) + public boolean setSmscAddress(@NonNull String smsc) { + try { + ISms iSms = getISmsService(); + if (iSms != null) { + return iSms.setSmscAddressOnIccEfForSubscriber( + smsc, getSubscriptionId(), ActivityThread.currentPackageName()); + } + } catch (RemoteException ex) { + // ignore it + } + return false; + } } diff --git a/telephony/java/com/android/internal/telephony/ISms.aidl b/telephony/java/com/android/internal/telephony/ISms.aidl index 7441c26a8061f..c1d700a2d190d 100644 --- a/telephony/java/com/android/internal/telephony/ISms.aidl +++ b/telephony/java/com/android/internal/telephony/ISms.aidl @@ -586,4 +586,23 @@ interface ISms { * @param destAddress the destination address to test for possible short code */ int checkSmsShortCodeDestination(int subId, String callingApk, String destAddress, String countryIso); + + /** + * Gets the SMSC address from (U)SIM. + * + * @param subId the subscription Id. + * @param callingPackage the package name of the calling app. + * @return the SMSC address string, null if failed. + */ + String getSmscAddressFromIccEfForSubscriber(int subId, String callingPackage); + + /** + * Sets the SMSC address on (U)SIM. + * + * @param smsc the SMSC address string. + * @param subId the subscription Id. + * @param callingPackage the package name of the calling app. + * @return true for success, false otherwise. + */ + boolean setSmscAddressOnIccEfForSubscriber(String smsc, int subId, String callingPackage); } diff --git a/telephony/java/com/android/internal/telephony/ISmsImplBase.java b/telephony/java/com/android/internal/telephony/ISmsImplBase.java index aa1f94f2355aa..ff816f24667e4 100644 --- a/telephony/java/com/android/internal/telephony/ISmsImplBase.java +++ b/telephony/java/com/android/internal/telephony/ISmsImplBase.java @@ -208,4 +208,15 @@ public class ISmsImplBase extends ISms.Stub { int subid, String callingApk, String destAddress, String countryIso) { throw new UnsupportedOperationException(); } + + @Override + public String getSmscAddressFromIccEfForSubscriber(int subId, String callingPackage) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean setSmscAddressOnIccEfForSubscriber( + String smsc, int subId, String callingPackage) { + throw new UnsupportedOperationException(); + } }