READ_SMS allows getLine1Number() [2/3]

Bug 22862050

Change-Id: I7ecaf1dd1f3c76e8f801282590247d3303fe483c
diff --git a/src/com/android/phone/PhoneInterfaceManager.java b/src/com/android/phone/PhoneInterfaceManager.java
index fdf16d2..93d369c 100644
--- a/src/com/android/phone/PhoneInterfaceManager.java
+++ b/src/com/android/phone/PhoneInterfaceManager.java
@@ -2725,10 +2725,19 @@
      * Besides READ_PHONE_STATE, WRITE_SMS also allows apps to get phone numbers.
      */
     private boolean canReadPhoneNumber(String callingPackage, String message) {
-        // Note canReadPhoneState() may throw, so we need to do the appops check first.
-        return (mAppOps.noteOp(AppOpsManager.OP_WRITE_SMS,
-                        Binder.getCallingUid(), callingPackage) == AppOpsManager.MODE_ALLOWED)
-                || canReadPhoneState(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 canReadPhoneState(callingPackage, message);
+        } catch (SecurityException e) {
+            // Can be read with READ_SMS too.
+            mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_SMS, message);
+            return mAppOps.noteOp(AppOpsManager.OP_READ_SMS,
+                    Binder.getCallingUid(), callingPackage) == AppOpsManager.MODE_ALLOWED;
+        }
     }
 
     @Override