Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8367627f authored by Jake Hamby's avatar Jake Hamby
Browse files

Allow apps with SEND_SMS_NO_CONFIRMATION to bypass short code check.

Change SMSDispatcher to bypass SMS premium short code confirmation
dialog when caller has "android.permission.SEND_SMS_NO_CONFIRMATION"
permission (instead of checking package name against hardcoded list).

This permission is only available to system apps or those signed with
the same certificates as those in the system image.

Bug: 6502817
Change-Id: I6098d448892cc5e842ba6dc10cf494295e7226af
parent 18afc622
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -78,6 +78,10 @@ public abstract class SMSDispatcher extends Handler {
    public static final String RECEIVE_EMERGENCY_BROADCAST_PERMISSION =
            "android.permission.RECEIVE_EMERGENCY_BROADCAST";

    /** Permission required to send SMS to short codes without user confirmation. */
    private static final String SEND_SMS_NO_CONFIRMATION_PERMISSION =
            "android.permission.SEND_SMS_NO_CONFIRMATION";

    /** Query projection for checking for duplicate message segments. */
    private static final String[] PDU_PROJECTION = new String[] {
            "pdu"
@@ -944,7 +948,8 @@ public abstract class SMSDispatcher extends Handler {
     * @return true if the destination is approved; false if user confirmation event was sent
     */
    boolean checkDestination(SmsTracker tracker) {
        if (mUsageMonitor.isApprovedShortCodeSender(tracker.mAppPackage)) {
        if (mContext.checkCallingOrSelfPermission(SEND_SMS_NO_CONFIRMATION_PERMISSION)
                == PackageManager.PERMISSION_GRANTED) {
            return true;            // app is pre-approved to send to short codes
        } else {
            String countryIso = mTelephonyManager.getSimCountryIso();
+0 −31
Original line number Diff line number Diff line
@@ -81,12 +81,6 @@ public class SmsUsageMonitor {
    private final HashMap<String, ArrayList<Long>> mSmsStamp =
            new HashMap<String, ArrayList<Long>>();

    /**
     * Hash of package names that are allowed to send to short codes.
     * TODO: persist this across reboots.
     */
    private final HashSet<String> mApprovedShortCodeSenders = new HashSet<String>();

    /** Context for retrieving regexes from XML resource. */
    private final Context mContext;

@@ -248,9 +242,6 @@ public class SmsUsageMonitor {
                DEFAULT_SMS_CHECK_PERIOD);

        mSettingsObserverHandler = new SettingsObserverHandler();

        // system MMS app is always allowed to send to short codes
        mApprovedShortCodeSenders.add("com.android.mms");
    }

    /**
@@ -357,28 +348,6 @@ public class SmsUsageMonitor {
        }
    }

    /**
     * Return whether the app is approved to send to any short code.
     * @param appName the package name of the app requesting to send an SMS
     * @return true if the app is approved; false if we need to confirm short code destinations
     */
    public boolean isApprovedShortCodeSender(String appName) {
        synchronized (mApprovedShortCodeSenders) {
            return mApprovedShortCodeSenders.contains(appName);
        }
    }

    /**
     * Add app package name to the list of approved short code senders.
     * @param appName the package name of the app to add
     */
    public void addApprovedShortCodeSender(String appName) {
        if (DBG) log("Adding " + appName + " to list of approved short code senders.");
        synchronized (mApprovedShortCodeSenders) {
            mApprovedShortCodeSenders.add(appName);
        }
    }

    /**
     * Check if the destination is a possible premium short code.
     * NOTE: the caller is expected to strip non-digits from the destination number with