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

Commit e4c2f93c authored by Makoto Onuki's avatar Makoto Onuki
Browse files

Allow default SMS app to get self phone number

Apps with WRITE_SMS app op can now call TelephonyManager.getLine1Number().
(Note we no longer have the WRITE_SMS permission.)

Bug 22031904

Change-Id: Iee616fa54e4c28e1bf6b17dbec01db2e1fe34a7e
parent a7269524
Loading
Loading
Loading
Loading
+13 −1
Original line number Diff line number Diff line
@@ -141,7 +141,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();
@@ -384,4 +385,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);
    }
}