Clear calling identity in getCarrierImsPackage()
Nathan Harold [Wed, 7 Jun 2017 23:10:21 +0000 (16:10 -0700)]
When the calling package has SEND_SMS but not READ_PHONE_STATE
the check currently errors out. This clears the calling package
so that we can still query the CarrierConfig to see if there is
an ImsPackage that should be checked for a CarrierSms intercept.
CarrierConfig expects READ_PHONE_STATE to check keys.

Bug: 37570992
Test: manual
Change-Id: I56a8336f9ab1fe0ad33e0e304431df125bbdeeec
Merged-In: I56a8336f9ab1fe0ad33e0e304431df125bbdeeec
(cherry picked from commit 02f1fc594ae1bff8b5128760587f264b86491d33)

src/java/com/android/internal/telephony/CarrierSmsUtils.java

index 845860c..a64aea7 100644 (file)
@@ -21,6 +21,7 @@ import android.content.Context;
 import android.content.Intent;
 import android.content.pm.PackageManager;
 import android.content.pm.ResolveInfo;
+import android.os.Binder;
 import android.os.PersistableBundle;
 import android.telephony.CarrierConfigManager;
 import android.telephony.Rlog;
@@ -78,13 +79,17 @@ public class CarrierSmsUtils {
             return null;
         }
 
-        PersistableBundle config = cm.getConfigForSubId(phone.getSubId());
-        if (config == null) {
-            if (VDBG) Rlog.v(TAG, "No CarrierConfig for subId:" + phone.getSubId());
-            return null;
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            PersistableBundle config = cm.getConfigForSubId(phone.getSubId());
+            if (config == null) {
+                if (VDBG) Rlog.v(TAG, "No CarrierConfig for subId:" + phone.getSubId());
+                return null;
+            }
+            return config.getString(CARRIER_IMS_PACKAGE_KEY, null);
+        } finally {
+            Binder.restoreCallingIdentity(identity);
         }
-
-        return config.getString(CARRIER_IMS_PACKAGE_KEY, null);
     }
 
     private CarrierSmsUtils() {}