public class SmsUsageMonitor extends Object
SMSDispatcher
, and has been moved
into a separate class to support instantiation of multiple SMSDispatchers on
dual-mode devices that require support for both 3GPP and 3GPP2 format messages.Modifier and Type | Field and Description |
---|---|
static int |
PREMIUM_SMS_PERMISSION_ALWAYS_ALLOW
Premium SMS permission when the owner has allowed the app to send premium SMS.
|
static int |
PREMIUM_SMS_PERMISSION_ASK_USER
Default premium SMS permission (ask user for each premium SMS sent).
|
static int |
PREMIUM_SMS_PERMISSION_NEVER_ALLOW
Premium SMS permission when the owner has denied the app from sending premium SMS.
|
static int |
PREMIUM_SMS_PERMISSION_UNKNOWN
Premium SMS permission for a new package (ask user when first premium SMS sent).
|
Constructor and Description |
---|
SmsUsageMonitor(Context context)
Create SMS usage monitor.
|
Modifier and Type | Method and Description |
---|---|
boolean |
check(String appName,
int smsWaiting)
Check to see if an application is allowed to send new SMS messages, and confirm with
user if the send limit was reached or if a non-system app is potentially sending to a
premium SMS short code or number.
|
int |
checkDestination(String destAddress,
String countryIso)
Check if the destination is a possible premium short code.
|
int |
getPremiumSmsPermission(String packageName)
Returns the premium SMS permission for the specified package.
|
static int |
mergeShortCodeCategories(int type1,
int type2) |
void |
setPremiumSmsPermission(String packageName,
int permission)
Sets the premium SMS permission for the specified package and save the value asynchronously
to persistent storage.
|
public static final int PREMIUM_SMS_PERMISSION_UNKNOWN
public static final int PREMIUM_SMS_PERMISSION_ASK_USER
public static final int PREMIUM_SMS_PERMISSION_NEVER_ALLOW
public static final int PREMIUM_SMS_PERMISSION_ALWAYS_ALLOW
public SmsUsageMonitor(Context context)
context
- the context to use to load resources and get TelephonyManager servicepublic static int mergeShortCodeCategories(int type1, int type2)
public boolean check(String appName, int smsWaiting)
appName
- the package name of the app requesting to send an SMSsmsWaiting
- the number of new messages desired to sendpublic int checkDestination(String destAddress, String countryIso)
PhoneNumberUtils.extractNetworkPortion(java.lang.String)
before calling this method.
This happens in SMSDispatcher.sendRawPdu(com.android.internal.telephony.SMSDispatcher.SmsTracker)
so that we use the same phone number
for testing and in the user confirmation dialog if the user needs to confirm the number.
This makes it difficult for malware to fool the user or the short code pattern matcher
by using non-ASCII characters to make the number appear to be different from the real
destination phone number.destAddress
- the destination address to test for possible short codeCATEGORY_NOT_SHORT_CODE
, CATEGORY_FREE_SHORT_CODE
,
CATEGORY_POSSIBLE_PREMIUM_SHORT_CODE
, or CATEGORY_PREMIUM_SHORT_CODE
.public int getPremiumSmsPermission(String packageName)
PREMIUM_SMS_PERMISSION_ASK_USER
will be returned.packageName
- the name of the package to query permissionPREMIUM_SMS_PERMISSION_UNKNOWN
,
PREMIUM_SMS_PERMISSION_ASK_USER
,
PREMIUM_SMS_PERMISSION_NEVER_ALLOW
, or
PREMIUM_SMS_PERMISSION_ALWAYS_ALLOW
SecurityException
- if the caller is not a system processpublic void setPremiumSmsPermission(String packageName, int permission)
packageName
- the name of the package to set permissionpermission
- one of PREMIUM_SMS_PERMISSION_ASK_USER
,
PREMIUM_SMS_PERMISSION_NEVER_ALLOW
, or
PREMIUM_SMS_PERMISSION_ALWAYS_ALLOW
SecurityException
- if the caller is not a system process