Merge "Read KEY_DISABLE_CDMA_ACTIVATION_CODE_BOOL from carrier config." into mnc-dev
diff --git a/src/com/android/phone/PhoneInterfaceManager.java b/src/com/android/phone/PhoneInterfaceManager.java
index de794de..0e82b99 100644
--- a/src/com/android/phone/PhoneInterfaceManager.java
+++ b/src/com/android/phone/PhoneInterfaceManager.java
@@ -2393,7 +2393,8 @@
 
     @Override
     public String getLine1NumberForDisplay(int subId, String callingPackage) {
-        if (!canReadPhoneState(callingPackage, "getLine1NumberForDisplay")) {
+        // This is open to apps with WRITE_SMS.
+        if (!canReadPhoneNumber(callingPackage, "getLine1NumberForDisplay")) {
             return null;
         }
 
@@ -2670,6 +2671,16 @@
         return true;
     }
 
+    /**
+     * 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);
+    }
+
     @Override
     public void factoryReset(int subId) {
         enforceConnectivityInternalPermission();