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

Commit ee4e0c08 authored by Grace Jia's avatar Grace Jia
Browse files

Exempt default SMS app from message send limit check

Test: Manually send a long message and see if alert show.
Bug: 153962883
Change-Id: I07e978c3a73e61e0f4938891ef3611927cc65ff3
parent 5aead18c
Loading
Loading
Loading
Loading
+12 −2
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.internal.telephony;

import android.app.role.RoleManager;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.ContentResolver;
import android.content.Context;
@@ -51,6 +52,7 @@ import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.regex.Pattern;
@@ -125,6 +127,8 @@ public class SmsUsageMonitor {
    /** Last modified time for pattern file */
    private long mPatternFileLastModified = 0;

    private RoleManager mRoleManager;

    /** Directory for per-app SMS permission XML file. */
    private static final String SMS_POLICY_FILE_DIRECTORY = "/data/misc/sms";

@@ -248,6 +252,7 @@ public class SmsUsageMonitor {
    public SmsUsageMonitor(Context context) {
        mContext = context;
        ContentResolver resolver = context.getContentResolver();
        mRoleManager = (RoleManager) mContext.getSystemService(Context.ROLE_SERVICE);

        mMaxAllowed = Settings.Global.getInt(resolver,
                Settings.Global.SMS_OUTGOING_CHECK_MAX_COUNT,
@@ -345,7 +350,7 @@ public class SmsUsageMonitor {
    /**
     * 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.
     * premium SMS short code or number. If the app is the default SMS app, there's no send limit.
     *
     * @param appName the package name of the app requesting to send an SMS
     * @param smsWaiting the number of new messages desired to send
@@ -363,9 +368,14 @@ public class SmsUsageMonitor {
                mSmsStamp.put(appName, sentList);
            }

            List<String> defaultApp = mRoleManager.getRoleHolders(RoleManager.ROLE_SMS);
            if (defaultApp.contains(appName)) {
                return true;
            } else {
                return isUnderLimit(sentList, smsWaiting);
            }
        }
    }

    /**
     * Check if the destination is a possible premium short code.