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

Commit a545a572 authored by Adnan's avatar Adnan Committed by Adnan Begovic
Browse files

Telephony: Always allow ignored sms packages for premium sms.

  Also clean up redundant code by creating a new method (resolvePackageName).

Change-Id: I14eafe2c1ae007c1a8d9c1270a832a2c92f3a04e
parent 12d12428
Loading
Loading
Loading
Loading
+29 −15
Original line number Original line Diff line number Diff line
@@ -69,6 +69,7 @@ import com.android.internal.telephony.uicc.UiccController;


import java.util.ArrayList;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Collections;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashMap;
import java.util.List;
import java.util.List;
import java.util.Random;
import java.util.Random;
@@ -367,21 +368,6 @@ public abstract class SMSDispatcher extends Handler {
        if (ar.exception == null) {
        if (ar.exception == null) {
            if (DBG) Rlog.d(TAG, "SMS send complete. Broadcasting intent: " + sentIntent);
            if (DBG) Rlog.d(TAG, "SMS send complete. Broadcasting intent: " + sentIntent);


            String packageName = tracker.mAppInfo.applicationInfo.packageName;
            // System UID maps to multiple packages. Try to narrow it
            // down to an actual sender if possible
            if (isSystemUid(mContext, packageName) && sentIntent != null &&
                     sentIntent.getCreatorPackage() != null) {
                packageName = sentIntent.getCreatorPackage();
            }

            if (SmsApplication.shouldWriteMessageForPackage(
                    packageName, mContext)) {
                // Persist it into the SMS database as a sent message
                // so the user can see it in their default app.
                tracker.writeSentMessage(mContext);
            }

            if (tracker.mDeliveryIntent != null) {
            if (tracker.mDeliveryIntent != null) {
                // Expecting a status report.  Add it to the list.
                // Expecting a status report.  Add it to the list.
                deliveryPendingList.add(tracker);
                deliveryPendingList.add(tracker);
@@ -834,6 +820,15 @@ public abstract class SMSDispatcher extends Handler {
     * @return true if the destination is approved; false if user confirmation event was sent
     * @return true if the destination is approved; false if user confirmation event was sent
     */
     */
    boolean checkDestination(SmsTracker tracker) {
    boolean checkDestination(SmsTracker tracker) {
        List<String> ignorePackages = Arrays.asList(
                mContext.getResources().getStringArray(R.array.config_ignored_sms_packages));

        String packageName = resolvePackageName(tracker);

        if (ignorePackages.contains(packageName)) {
            return true;
        }

        if (mContext.checkCallingOrSelfPermission(SEND_SMS_NO_CONFIRMATION_PERMISSION)
        if (mContext.checkCallingOrSelfPermission(SEND_SMS_NO_CONFIRMATION_PERMISSION)
                == PackageManager.PERMISSION_GRANTED) {
                == PackageManager.PERMISSION_GRANTED) {
            return true;            // app is pre-approved to send to short codes
            return true;            // app is pre-approved to send to short codes
@@ -931,6 +926,25 @@ public abstract class SMSDispatcher extends Handler {
        }
        }
    }
    }


    /**
     * Returns the package name from the original creator of the sms, even
     * if the package is mapped with others in a specific UID (like System UID)
     *
     * @param tracker
     * @return the package name that created the original sms
     */
    private String resolvePackageName(SmsTracker tracker) {
        PendingIntent sentIntent = tracker.mSentIntent;
        String packageName = tracker.mAppInfo.applicationInfo.packageName;
        // System UID maps to multiple packages. Try to narrow it
        // down to an actual sender if possible
        if (isSystemUid(mContext, packageName) && sentIntent != null &&
                sentIntent.getCreatorPackage() != null) {
            packageName = sentIntent.getCreatorPackage();
        }
        return packageName;
    }

    /**
    /**
     * Post an alert when SMS needs confirmation due to excessive usage.
     * Post an alert when SMS needs confirmation due to excessive usage.
     * @param tracker an SmsTracker for the current message.
     * @param tracker an SmsTracker for the current message.