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

Commit f5bd5e9b authored by Robert Greenwalt's avatar Robert Greenwalt
Browse files

Check permissions on getDeviceId.

bug:25778215
Change-Id: I93c79170dc9639f9c7ea3529b3770c75f97c354a
parent e85e5d34
Loading
Loading
Loading
Loading
+53 −7
Original line number Diff line number Diff line
@@ -18,6 +18,9 @@

package com.android.internal.telephony;

import android.app.AppOpsManager;
import android.content.Context;
import android.os.Binder;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.telephony.SubscriptionManager;
@@ -28,21 +31,64 @@ import java.lang.NullPointerException;

public class PhoneSubInfoController extends IPhoneSubInfo.Stub {
    private static final String TAG = "PhoneSubInfoController";
    private Phone[] mPhone;

    public PhoneSubInfoController(Phone[] phone) {
        mPhone = phone;
    private final Phone[] mPhone;
    private final Context mContext;
    private final AppOpsManager mAppOps;

    public PhoneSubInfoController(Phone[] phones) {
        mPhone = phones;
        Context context = null;
        AppOpsManager appOpsManager = null;
        for (Phone phone : mPhone) {
            if (phone != null) {
                context = phone.getContext();
                appOpsManager = context.getSystemService(AppOpsManager.class);
                break;
            }
        }
        mContext = context;
        mAppOps = appOpsManager;
        if (ServiceManager.getService("iphonesubinfo") == null) {
            ServiceManager.addService("iphonesubinfo", this);
        }
    }

    // try-state
    // either have permission (true), don't (exception), or explicitly turned off (false)
    private boolean canReadPhoneState(String callingPackage, String message) {
        if (mContext == null) return false;
        try {
            mContext.enforceCallingOrSelfPermission(
                    android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, message);

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



        if (mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
                callingPackage) != AppOpsManager.MODE_ALLOWED) {
            return false;
        }

        return true;
    }

    public String getDeviceId(String callingPackage) {
        return getDeviceIdForPhone(SubscriptionManager.getPhoneId(getDefaultSubscription()));
        return getDeviceIdForPhone(SubscriptionManager.getPhoneId(getDefaultSubscription()),
                callingPackage);
    }

    public String getDeviceIdForPhone(int phoneId, String callingPackage) {
        if (!canReadPhoneState(callingPackage, "getDeviceId")) {
            return null;
        }

    public String getDeviceIdForPhone(int phoneId) {
        Phone phone = getPhone(phoneId);
        final Phone phone = getPhone(phoneId);
        if (phone != null) {
            return phone.getDeviceId();
        } else {
+1 −1
Original line number Diff line number Diff line
@@ -152,7 +152,7 @@ public class PhoneSubInfoProxy extends IPhoneSubInfo.Stub {
    }

    @Override
    public String getDeviceIdForPhone(int phoneId) throws RemoteException {
    public String getDeviceIdForPhone(int phoneId, String callingPackage) throws RemoteException {
        // FIXME: getDeviceIdForPhone
        return null;
    }