READ_SMS allows getLine1Number() [3/3]
Makoto Onuki [Mon, 3 Aug 2015 22:12:34 +0000 (15:12 -0700)]
Bug 22862050

Change-Id: I0cb90152b64508a173f51dd2b6dbaa79f4df8849

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

index 91909a2..71222ae 100755 (executable)
@@ -386,9 +386,18 @@ public class PhoneSubInfo {
      * Besides READ_PHONE_STATE, WRITE_SMS also allows apps to get phone numbers.
      */
     private boolean checkReadPhoneNumber(String callingPackage, String message) {
-        // Note checkReadPhoneState() may throw, so we need to do the appops check first.
-        return (mAppOps.noteOp(AppOpsManager.OP_WRITE_SMS,
-                        Binder.getCallingUid(), callingPackage) == AppOpsManager.MODE_ALLOWED)
-                || checkReadPhoneState(callingPackage, message);
+        // Default SMS app can always read it.
+        if (mAppOps.noteOp(AppOpsManager.OP_WRITE_SMS,
+                Binder.getCallingUid(), callingPackage) == AppOpsManager.MODE_ALLOWED) {
+            return true;
+        }
+        try {
+            return checkReadPhoneState(callingPackage, message);
+        } catch (SecurityException e) {
+            // Can be read with READ_SMS too.
+            mContext.enforceCallingOrSelfPermission(android.Manifest.permission.READ_SMS, message);
+            return mAppOps.noteOp(AppOpsManager.OP_READ_SMS,
+                    Binder.getCallingUid(), callingPackage) == AppOpsManager.MODE_ALLOWED;
+        }
     }
 }