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

Commit 06b07e9e authored by Philip P. Moltmann's avatar Philip P. Moltmann
Browse files

(Backport) Pipe through featureId from caller to permission checks in telephony

code

Test: atest FrameworksTelephonyTests CtsAppOpsTestCases
Bug: 136595429
Fixes: 146350559
Change-Id: Ie58007cf2a4e4a39cdfd72822150efce71dfbe84
Merged-In: I7ef41e8961e48d40e5685c4a521e83cb20953e48
parent 6a2dab68
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -161,7 +161,7 @@ public class Build {
        try {
            Application application = ActivityThread.currentApplication();
            String callingPackage = application != null ? application.getPackageName() : null;
            return service.getSerialForPackage(callingPackage);
            return service.getSerialForPackage(callingPackage, null);
        } catch (RemoteException e) {
            e.rethrowFromSystemServer();
        }
+2 −2
Original line number Diff line number Diff line
@@ -21,5 +21,5 @@ package android.os;
 */
interface IDeviceIdentifiersPolicyService {
    String getSerial();
    String getSerialForPackage(in String callingPackage);
    String getSerialForPackage(in String callingPackage, String callingFeatureId);
}
+3 −2
Original line number Diff line number Diff line
@@ -116,7 +116,8 @@ public class TelephonyRegistryManager {
        };
        mSubscriptionChangedListenerMap.put(listener, callback);
        try {
            sRegistry.addOnSubscriptionsChangedListener(mContext.getOpPackageName(), callback);
            sRegistry.addOnSubscriptionsChangedListener(mContext.getOpPackageName(),
                    null, callback);
        } catch (RemoteException ex) {
            // system server crash
        }
@@ -175,7 +176,7 @@ public class TelephonyRegistryManager {
        mOpportunisticSubscriptionChangedListenerMap.put(listener, callback);
        try {
            sRegistry.addOnOpportunisticSubscriptionsChangedListener(mContext.getOpPackageName(),
                    callback);
                    null, callback);
        } catch (RemoteException ex) {
            // system server crash
        }
+9 −3
Original line number Diff line number Diff line
@@ -33,16 +33,22 @@ import com.android.internal.telephony.IPhoneStateListener;
import com.android.internal.telephony.IOnSubscriptionsChangedListener;

interface ITelephonyRegistry {
    void addOnSubscriptionsChangedListener(String pkg,
    void addOnSubscriptionsChangedListener(String pkg, String featureId,
            IOnSubscriptionsChangedListener callback);
    void addOnOpportunisticSubscriptionsChangedListener(String pkg,
    void addOnOpportunisticSubscriptionsChangedListener(String pkg, String featureId,
            IOnSubscriptionsChangedListener callback);
    void removeOnSubscriptionsChangedListener(String pkg,
            IOnSubscriptionsChangedListener callback);
    /**
      * @deprecated Use {@link #listenWithFeature(String, String, IPhoneStateListener, int,
      * boolean) instead
      */
    @UnsupportedAppUsage
    void listen(String pkg, IPhoneStateListener callback, int events, boolean notifyNow);
    void listenForSubscriber(in int subId, String pkg, IPhoneStateListener callback, int events,
    void listenWithFeature(String pkg, String featureId, IPhoneStateListener callback, int events,
            boolean notifyNow);
    void listenForSubscriber(in int subId, String pkg, String featureId,
            IPhoneStateListener callback, int events, boolean notifyNow);
    @UnsupportedAppUsage
    void notifyCallStateForAllSubs(int state, String incomingNumber);
    void notifyCallState(in int phoneId, in int subId, int state, String incomingNumber);
+28 −15
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import static android.telephony.TelephonyRegistryManager.SIM_ACTIVATION_TYPE_VOI

import static java.util.Arrays.copyOf;

import android.annotation.Nullable;
import android.app.ActivityManager;
import android.app.AppOpsManager;
import android.content.BroadcastReceiver;
@@ -112,6 +113,7 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
        Context context;

        String callingPackage;
        String callingFeatureId;

        IBinder binder;

@@ -145,7 +147,7 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
        boolean canReadCallLog() {
            try {
                return TelephonyPermissions.checkReadCallLog(
                        context, subId, callerPid, callerUid, callingPackage);
                        context, subId, callerPid, callerUid, callingPackage, callingFeatureId);
            } catch (SecurityException e) {
                return false;
            }
@@ -568,7 +570,7 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
    }

    @Override
    public void addOnSubscriptionsChangedListener(String callingPackage,
    public void addOnSubscriptionsChangedListener(String callingPackage, String callingFeatureId,
            IOnSubscriptionsChangedListener callback) {
        int callerUserId = UserHandle.getCallingUserId();
        mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
@@ -590,6 +592,7 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
            r.context = mContext;
            r.onSubscriptionsChangedListenerCallback = callback;
            r.callingPackage = callingPackage;
            r.callingFeatureId = callingFeatureId;
            r.callerUid = Binder.getCallingUid();
            r.callerPid = Binder.getCallingPid();
            r.events = 0;
@@ -622,7 +625,7 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {

    @Override
    public void addOnOpportunisticSubscriptionsChangedListener(String callingPackage,
            IOnSubscriptionsChangedListener callback) {
            String callingFeatureId, IOnSubscriptionsChangedListener callback) {
        int callerUserId = UserHandle.getCallingUserId();
        mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
        if (VDBG) {
@@ -643,6 +646,7 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
            r.context = mContext;
            r.onOpportunisticSubscriptionsChangedListenerCallback = callback;
            r.callingPackage = callingPackage;
            r.callingFeatureId = callingFeatureId;
            r.callerUid = Binder.getCallingUid();
            r.callerPid = Binder.getCallingPid();
            r.events = 0;
@@ -718,21 +722,28 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
        }
    }

    @Deprecated
    @Override
    public void listen(String pkgForDebug, IPhoneStateListener callback, int events,
    public void listen(String callingPackage, IPhoneStateListener callback, int events,
            boolean notifyNow) {
        listenForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, pkgForDebug, callback,
                events, notifyNow);
        listenWithFeature(callingPackage, null, callback, events, notifyNow);
    }

    @Override
    public void listenWithFeature(String callingPackage, String callingFeatureId,
            IPhoneStateListener callback, int events, boolean notifyNow) {
        listenForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, callingPackage,
                callingFeatureId, callback, events, notifyNow);
    }

    @Override
    public void listenForSubscriber(int subId, String pkgForDebug, IPhoneStateListener callback,
            int events, boolean notifyNow) {
        listen(pkgForDebug, callback, events, notifyNow, subId);
    public void listenForSubscriber(int subId, String callingPackage, String callingFeatureId,
            IPhoneStateListener callback, int events, boolean notifyNow) {
        listen(callingPackage, callingFeatureId, callback, events, notifyNow, subId);
    }

    private void listen(String callingPackage, IPhoneStateListener callback, int events,
            boolean notifyNow, int subId) {
    private void listen(String callingPackage, @Nullable String callingFeatureId,
            IPhoneStateListener callback, int events, boolean notifyNow, int subId) {
        int callerUserId = UserHandle.getCallingUserId();
        mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
        String str = "listen: E pkg=" + callingPackage + " events=0x" + Integer.toHexString(events)
@@ -747,7 +758,8 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
            // Checks permission and throws SecurityException for disallowed operations. For pre-M
            // apps whose runtime permission has been revoked, we return immediately to skip sending
            // events to the app without crashing it.
            if (!checkListenerPermission(events, subId, callingPackage, "listen")) {
            if (!checkListenerPermission(events, subId, callingPackage, callingFeatureId,
                    "listen")) {
                return;
            }

@@ -764,6 +776,7 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
                r.context = mContext;
                r.callback = callback;
                r.callingPackage = callingPackage;
                r.callingFeatureId = callingFeatureId;
                r.callerUid = Binder.getCallingUid();
                r.callerPid = Binder.getCallingPid();
                // Legacy applications pass SubscriptionManager.DEFAULT_SUB_ID,
@@ -2282,8 +2295,8 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {
                == PackageManager.PERMISSION_GRANTED;
    }

    private boolean checkListenerPermission(
            int events, int subId, String callingPackage, String message) {
    private boolean checkListenerPermission(int events, int subId, String callingPackage,
            @Nullable String callingFeatureId, String message) {
        LocationAccessPolicy.LocationPermissionQuery.Builder locationQueryBuilder =
                new LocationAccessPolicy.LocationPermissionQuery.Builder()
                .setCallingPackage(callingPackage)
@@ -2318,7 +2331,7 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub {

        if ((events & ENFORCE_PHONE_STATE_PERMISSION_MASK) != 0) {
            if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
                    mContext, subId, callingPackage, message)) {
                    mContext, subId, callingPackage, callingFeatureId, message)) {
                return false;
            }
        }
Loading