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

Commit 406c3db3 authored by Makoto Onuki's avatar Makoto Onuki Committed by Android (Google) Code Review
Browse files

Merge "Allow default SMS app to get self phone number" into mnc-dev

parents 44b45f6f e4c2f93c
Loading
Loading
Loading
Loading
+13 −1
Original line number Diff line number Diff line
@@ -140,7 +140,8 @@ public class PhoneSubInfo {
     * Retrieves the phone number string for line 1.
     */
    public String getLine1Number(String callingPackage) {
        if (!checkReadPhoneState(callingPackage, "getLine1Number")) {
        // This is open to apps with WRITE_SMS.
        if (!checkReadPhoneNumber(callingPackage, "getLine1Number")) {
            return null;
        }
        return mPhone.getLine1Number();
@@ -379,4 +380,15 @@ public class PhoneSubInfo {
        return mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
            callingPackage) == AppOpsManager.MODE_ALLOWED;
    }


    /**
     * Besides READ_PHONE_STATE, WRITE_SMS also allows apps to get phone numbers.
     */
    private boolean checkReadPhoneNumber(String callingPackage, String message) {
        // Note checkReadPhoneState() may throw, so we need to do the appops check first.
        return (mAppOps.noteOp(AppOpsManager.OP_WRITE_SMS,
                        Binder.getCallingUid(), callingPackage) == AppOpsManager.MODE_ALLOWED)
                || checkReadPhoneState(callingPackage, message);
    }
}