From 0276e13b9637665266d75a3072ff382503a302c8 Mon Sep 17 00:00:00 2001 From: chen xu Date: Mon, 25 Mar 2019 10:43:28 -0700 Subject: [PATCH] move short code definitions to SmsManager Test API Bug: 127560420 Test: cts Change-Id: I6a5ba2439713105b25913ba8eb081abfaafd1a2e (cherry picked from commit 9c7fad923561869ae2a09f7d79d168e86c5718a1) Merged-in: I6a5ba2439713105b25913ba8eb081abfaafd1a2e --- api/test-current.txt | 9 ++ .../java/android/telephony/SmsManager.java | 85 +++++++++++++++++++ .../com/android/internal/telephony/ISms.aidl | 7 ++ .../internal/telephony/ISmsImplBase.java | 6 ++ 4 files changed, 107 insertions(+) diff --git a/api/test-current.txt b/api/test-current.txt index 075963ef5efd4..144e5f5c8f53a 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -1532,6 +1532,15 @@ package android.telephony { method public void setVoiceRoamingType(int); } + public final class SmsManager { + method @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public int checkSmsShortCodeDestination(String, String); + field public static final int SMS_CATEGORY_FREE_SHORT_CODE = 1; // 0x1 + field public static final int SMS_CATEGORY_NOT_SHORT_CODE = 0; // 0x0 + field public static final int SMS_CATEGORY_POSSIBLE_PREMIUM_SHORT_CODE = 3; // 0x3 + field public static final int SMS_CATEGORY_PREMIUM_SHORT_CODE = 4; // 0x4 + field public static final int SMS_CATEGORY_STANDARD_SHORT_CODE = 2; // 0x2 + } + public class TelephonyManager { method public int getCarrierIdListVersion(); method @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public String getLine1AlphaTag(); diff --git a/telephony/java/android/telephony/SmsManager.java b/telephony/java/android/telephony/SmsManager.java index 63e3801a9b4fc..d4ea29fe1463a 100644 --- a/telephony/java/android/telephony/SmsManager.java +++ b/telephony/java/android/telephony/SmsManager.java @@ -16,9 +16,11 @@ package android.telephony; +import android.annotation.IntDef; import android.annotation.RequiresPermission; import android.annotation.SuppressAutoDoc; import android.annotation.SystemApi; +import android.annotation.TestApi; import android.annotation.UnsupportedAppUsage; import android.app.ActivityThread; import android.app.PendingIntent; @@ -43,6 +45,8 @@ import com.android.internal.telephony.ISms; import com.android.internal.telephony.ITelephony; import com.android.internal.telephony.SmsRawData; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -2798,4 +2802,85 @@ public final class SmsManager { config.getBoolean(MMS_CONFIG_SUPPORT_HTTP_CHARSET_HEADER)); return filtered; } + + /** @hide */ + @Retention(RetentionPolicy.SOURCE) + @IntDef(prefix = {"SMS_CATEGORY_"}, + value = { + SmsManager.SMS_CATEGORY_NOT_SHORT_CODE, + SmsManager.SMS_CATEGORY_FREE_SHORT_CODE, + SmsManager.SMS_CATEGORY_STANDARD_SHORT_CODE, + SmsManager.SMS_CATEGORY_POSSIBLE_PREMIUM_SHORT_CODE, + SmsManager.SMS_CATEGORY_PREMIUM_SHORT_CODE}) + public @interface SmsShortCodeCategory {} + + /** + * Return value from {@link #checkSmsShortCodeDestination(String, String)} ()} for regular + * phone numbers. + * @hide + */ + @TestApi + public static final int SMS_CATEGORY_NOT_SHORT_CODE = 0; + /** + * Return value from {@link #checkSmsShortCodeDestination(String, String)} ()} for free + * (no cost) short codes. + * @hide + */ + @TestApi + public static final int SMS_CATEGORY_FREE_SHORT_CODE = 1; + /** + * Return value from {@link #checkSmsShortCodeDestination(String, String)} ()} for + * standard rate (non-premium) + * short codes. + * @hide + */ + @TestApi + public static final int SMS_CATEGORY_STANDARD_SHORT_CODE = 2; + /** + * Return value from {@link #checkSmsShortCodeDestination(String, String)} ()} for possible + * premium short codes. + * @hide + */ + @TestApi + public static final int SMS_CATEGORY_POSSIBLE_PREMIUM_SHORT_CODE = 3; + /** + * Return value from {@link #checkSmsShortCodeDestination(String, String)} ()} for + * premium short codes. + * @hide + */ + @TestApi + public static final int SMS_CATEGORY_PREMIUM_SHORT_CODE = 4; + + /** + * Check if the destination address is a possible premium short code. + * NOTE: the caller is expected to strip non-digits from the destination number with + * {@link PhoneNumberUtils#extractNetworkPortion} before calling this method. + * + * @param destAddress the destination address to test for possible short code + * @param countryIso the ISO country code + * + * @return + * {@link SmsManager#SMS_CATEGORY_NOT_SHORT_CODE}, + * {@link SmsManager#SMS_CATEGORY_FREE_SHORT_CODE}, + * {@link SmsManager#SMS_CATEGORY_POSSIBLE_PREMIUM_SHORT_CODE}, + * {@link SmsManager#SMS_CATEGORY_PREMIUM_SHORT_CODE}, or + * {@link SmsManager#SMS_CATEGORY_STANDARD_SHORT_CODE} + * + * @hide + */ + @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) + @TestApi + public @SmsShortCodeCategory int checkSmsShortCodeDestination( + String destAddress, String countryIso) { + try { + ISms iccISms = getISmsServiceOrThrow(); + if (iccISms != null) { + return iccISms.checkSmsShortCodeDestination(getSubscriptionId(), + ActivityThread.currentPackageName(), destAddress, countryIso); + } + } catch (RemoteException e) { + Log.e(TAG, "checkSmsShortCodeDestination() RemoteException", e); + } + return SmsManager.SMS_CATEGORY_NOT_SHORT_CODE; + } } diff --git a/telephony/java/com/android/internal/telephony/ISms.aidl b/telephony/java/com/android/internal/telephony/ISms.aidl index c3dcc3db7d450..87aff8a57e27f 100644 --- a/telephony/java/com/android/internal/telephony/ISms.aidl +++ b/telephony/java/com/android/internal/telephony/ISms.aidl @@ -551,4 +551,11 @@ interface ISms { * @param intent PendingIntent to be sent when an SMS is received containing the token. */ String createAppSpecificSmsToken(int subId, String callingPkg, in PendingIntent intent); + + /** + * Check if the destination is a possible premium short code. + * + * @param destAddress the destination address to test for possible short code + */ + int checkSmsShortCodeDestination(int subId, String callingApk, String destAddress, String countryIso); } diff --git a/telephony/java/com/android/internal/telephony/ISmsImplBase.java b/telephony/java/com/android/internal/telephony/ISmsImplBase.java index 1cdf44d897b21..194f46195c55a 100644 --- a/telephony/java/com/android/internal/telephony/ISmsImplBase.java +++ b/telephony/java/com/android/internal/telephony/ISmsImplBase.java @@ -188,4 +188,10 @@ public class ISmsImplBase extends ISms.Stub { public String createAppSpecificSmsToken(int subId, String callingPkg, PendingIntent intent) { throw new UnsupportedOperationException(); } + + @Override + public int checkSmsShortCodeDestination( + int subid, String callingApk, String destAddress, String countryIso) { + throw new UnsupportedOperationException(); + } }