diff options
| -rw-r--r-- | api/test-current.txt | 9 | ||||
| -rw-r--r-- | telephony/java/android/telephony/SmsManager.java | 84 | ||||
| -rw-r--r-- | telephony/java/com/android/internal/telephony/ISms.aidl | 7 | ||||
| -rw-r--r-- | telephony/java/com/android/internal/telephony/ISmsImplBase.java | 6 |
4 files changed, 106 insertions, 0 deletions
diff --git a/api/test-current.txt b/api/test-current.txt index 6c0b92853673..56c5e989f737 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -2663,6 +2663,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 checkCarrierPrivilegesForPackage(String); method public int getCarrierIdListVersion(); diff --git a/telephony/java/android/telephony/SmsManager.java b/telephony/java/android/telephony/SmsManager.java index 07ffaac01b0f..dde805777a0b 100644 --- a/telephony/java/android/telephony/SmsManager.java +++ b/telephony/java/android/telephony/SmsManager.java @@ -17,11 +17,13 @@ package android.telephony; import android.annotation.CallbackExecutor; +import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; 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; @@ -50,6 +52,8 @@ import com.android.internal.telephony.IMms; import com.android.internal.telephony.ISms; 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; @@ -2327,4 +2331,84 @@ public final class SmsManager { 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 b51eda3f1b34..c34feeda6b50 100644 --- a/telephony/java/com/android/internal/telephony/ISms.aidl +++ b/telephony/java/com/android/internal/telephony/ISms.aidl @@ -588,4 +588,11 @@ interface ISms { */ void getSmsMessagesForFinancialApp( int subId, String callingPkg, in Bundle params, in IFinancialSmsCallback callback); + + /** + * 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 12c5c308739a..aa1f94f2355a 100644 --- a/telephony/java/com/android/internal/telephony/ISmsImplBase.java +++ b/telephony/java/com/android/internal/telephony/ISmsImplBase.java @@ -202,4 +202,10 @@ public class ISmsImplBase extends ISms.Stub { int subId, String callingPkg, Bundle params, IFinancialSmsCallback callback) { throw new UnsupportedOperationException(); } + + @Override + public int checkSmsShortCodeDestination( + int subid, String callingApk, String destAddress, String countryIso) { + throw new UnsupportedOperationException(); + } } |