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

Commit 4e286c0d authored by Amit Mahajan's avatar Amit Mahajan
Browse files

Change the order of permission checks for READ_PHONE_STATE.

This is needed for 2 reasons:
1. If called as self, OP_READ_PHONE_STATE check should not be done.
2. If caller does not have permission, exception should be thrown
for READ_PHONE_STATE.

Bug: 22128902
Change-Id: Ibd4de0c5ba314700b6b3d7a59f502d2a21b7d86f
parent 7a4b136c
Loading
Loading
Loading
Loading
+4 −9
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@ import android.app.AppOpsManager;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Binder;
import android.os.RemoteException;
import android.telephony.PhoneNumberUtils;
import android.telephony.Rlog;

@@ -366,19 +365,15 @@ public class PhoneSubInfo {
    }

    private boolean checkReadPhoneState(String callingPackage, String message) {
        boolean failReadPhoneState = false;
        try {
            mContext.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
                    message);
        } catch (SecurityException e) {
            failReadPhoneState = true;
        }
        if (failReadPhoneState) {
            mContext.enforceCallingOrSelfPermission(
                    android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, message);

            // SKIP checking run-time OP_READ_PHONE_STATE since using PRIVILEDGED
            // SKIP checking run-time OP_READ_PHONE_STATE since self or using PRIVILEGED
            return true;
        } catch (SecurityException e) {
            mContext.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
                    message);
        }

        return mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
+4 −8
Original line number Diff line number Diff line
@@ -207,19 +207,15 @@ public class SubscriptionController extends ISub.Stub {
     * @throws SecurityException if the caller does not have READ_PHONE_STATE permission.
     */
    private boolean canReadPhoneState(String callingPackage, String message) {
        boolean failReadPhoneState = false;
        try {
            mContext.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
                    message);
        } catch (SecurityException e) {
            failReadPhoneState = true;
        }
        if (failReadPhoneState) {
            mContext.enforceCallingOrSelfPermission(
                    android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, message);

            // SKIP checking run-time permission since using PRIVILEDGED permission
            // SKIP checking run-time permission since self or using PRIVILEDGED permission
            return true;
        } catch (SecurityException e) {
            mContext.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
                    message);
        }

        return mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),