Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bc672734 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add READ_PHONE_NUMBER permission"

parents 7f91cfd7 6ec64312
Loading
Loading
Loading
Loading
+31 −11
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import com.android.internal.telephony.uicc.UiccCard;
import com.android.internal.telephony.uicc.UiccCardApplication;

import static android.Manifest.permission.CALL_PRIVILEGED;
import static android.Manifest.permission.READ_PHONE_NUMBER;
import static android.Manifest.permission.READ_PHONE_STATE;
import static android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE;
import static android.Manifest.permission.READ_SMS;
@@ -434,7 +435,8 @@ public class PhoneSubInfoController extends IPhoneSubInfo.Stub {
    }

    /**
     * Besides READ_PHONE_STATE, WRITE_SMS and READ_SMS also allow apps to get phone numbers.
     * Besides READ_PHONE_STATE, READ_PHONE_NUMBER, WRITE_SMS and READ_SMS also allow apps to get
     * phone numbers.
     */
    private boolean checkReadPhoneNumber(String callingPackage, String message) {
        // Default SMS app can always read it.
@@ -445,18 +447,36 @@ public class PhoneSubInfoController extends IPhoneSubInfo.Stub {
        try {
            return checkReadPhoneState(callingPackage, message);
        } catch (SecurityException readPhoneStateSecurityException) {
        }
        try {
            // Can be read with READ_SMS too.
            mContext.enforceCallingOrSelfPermission(READ_SMS, message);
                return mAppOps.noteOp(AppOpsManager.OP_READ_SMS,
                        Binder.getCallingUid(), callingPackage) == AppOpsManager.MODE_ALLOWED;
            int opCode = mAppOps.permissionToOpCode(READ_SMS);
            if (opCode != AppOpsManager.OP_NONE) {
                return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage)
                        == AppOpsManager.MODE_ALLOWED;
            } else {
                return true;
            }
        } catch (SecurityException readSmsSecurityException) {
                // Throw exception with message including both READ_PHONE_STATE and READ_SMS
                // permissions
                throw new SecurityException(message + ": Neither user " + Binder.getCallingUid() +
                        " nor current process has " + READ_PHONE_STATE + " or " + READ_SMS + ".");
        }
        try {
            // Can be read with READ_PHONE_NUMBER too.
            mContext.enforceCallingOrSelfPermission(READ_PHONE_NUMBER, message);
            int opCode = mAppOps.permissionToOpCode(READ_PHONE_NUMBER);
            if (opCode != AppOpsManager.OP_NONE) {
                return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage)
                        == AppOpsManager.MODE_ALLOWED;
            } else {
                return true;
            }
        } catch (SecurityException readPhoneNumberSecurityException) {
        }
        // Throw exception with message including READ_PHONE_STATE, READ_SMS, and READ_PHONE_NUMBER
        // permissions
        throw new SecurityException(message + ": Neither user " + Binder.getCallingUid() +
                " nor current process has " + READ_PHONE_STATE + ", " +
                READ_SMS + ", or " + READ_PHONE_STATE + ".");
    }

    private void log(String s) {