am 8d1b9741: am 65c38dcd: am 9176bb0f: am 24714352: Merge "READ_SMS allows getLine1Number() [2/3]" into mnc-dev

* commit '8d1b97412f056697805f16d2e7a58e25e38e45c8':
  READ_SMS allows getLine1Number() [2/3]
diff --git a/src/com/android/phone/PhoneInterfaceManager.java b/src/com/android/phone/PhoneInterfaceManager.java
index c59f60d..8606a3c 100644
--- a/src/com/android/phone/PhoneInterfaceManager.java
+++ b/src/com/android/phone/PhoneInterfaceManager.java
@@ -2732,10 +2732,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