From 6ff09a47a5f29a4efc47c988fbd05b8dc16ac9ae Mon Sep 17 00:00:00 2001 From: Adnan Date: Mon, 8 Dec 2014 10:39:37 -0800 Subject: Telephony: Always allow ignored sms packages for premium sms. Also clean up redundant code by creating a new method (resolvePackageName). Change-Id: I14eafe2c1ae007c1a8d9c1270a832a2c92f3a04e (cherry picked from commit 9e7b80a78a156b729e6fe92636494d900404d138) --- .../android/internal/telephony/SMSDispatcher.java | 38 ++++++++++++++++++---- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/src/java/com/android/internal/telephony/SMSDispatcher.java b/src/java/com/android/internal/telephony/SMSDispatcher.java index 3ae3de5e2..70aa7e97c 100644 --- a/src/java/com/android/internal/telephony/SMSDispatcher.java +++ b/src/java/com/android/internal/telephony/SMSDispatcher.java @@ -64,7 +64,9 @@ import com.android.internal.telephony.GsmAlphabet.TextEncodingDetails; import com.android.internal.telephony.ImsSMSDispatcher; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; +import java.util.List; import java.util.Random; import java.util.concurrent.atomic.AtomicInteger; @@ -364,13 +366,7 @@ public abstract class SMSDispatcher extends Handler { if (ar.exception == null) { 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(); - } + String packageName = resolvePackageName(tracker); if (SmsApplication.shouldWriteMessageForPackage( packageName, mContext)) { @@ -820,6 +816,15 @@ public abstract class SMSDispatcher extends Handler { * @return true if the destination is approved; false if user confirmation event was sent */ boolean checkDestination(SmsTracker tracker) { + List 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) == PackageManager.PERMISSION_GRANTED) { return true; // app is pre-approved to send to short codes @@ -922,6 +927,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. * @param tracker an SmsTracker for the current message. -- cgit v1.2.3