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

Commit 0104ce52 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

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

parents 593bd91f 06b07e9e
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -161,7 +161,7 @@ public class Build {
        try {
        try {
            Application application = ActivityThread.currentApplication();
            Application application = ActivityThread.currentApplication();
            String callingPackage = application != null ? application.getPackageName() : null;
            String callingPackage = application != null ? application.getPackageName() : null;
            return service.getSerialForPackage(callingPackage);
            return service.getSerialForPackage(callingPackage, null);
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            e.rethrowFromSystemServer();
            e.rethrowFromSystemServer();
        }
        }
+2 −2
Original line number Original line Diff line number Diff line
@@ -21,5 +21,5 @@ package android.os;
 */
 */
interface IDeviceIdentifiersPolicyService {
interface IDeviceIdentifiersPolicyService {
    String getSerial();
    String getSerial();
    String getSerialForPackage(in String callingPackage);
    String getSerialForPackage(in String callingPackage, String callingFeatureId);
}
}
+3 −2
Original line number Original line Diff line number Diff line
@@ -118,7 +118,8 @@ public class TelephonyRegistryManager {
        };
        };
        mSubscriptionChangedListenerMap.put(listener, callback);
        mSubscriptionChangedListenerMap.put(listener, callback);
        try {
        try {
            sRegistry.addOnSubscriptionsChangedListener(mContext.getOpPackageName(), callback);
            sRegistry.addOnSubscriptionsChangedListener(mContext.getOpPackageName(),
                    null, callback);
        } catch (RemoteException ex) {
        } catch (RemoteException ex) {
            // system server crash
            // system server crash
        }
        }
@@ -177,7 +178,7 @@ public class TelephonyRegistryManager {
        mOpportunisticSubscriptionChangedListenerMap.put(listener, callback);
        mOpportunisticSubscriptionChangedListenerMap.put(listener, callback);
        try {
        try {
            sRegistry.addOnOpportunisticSubscriptionsChangedListener(mContext.getOpPackageName(),
            sRegistry.addOnOpportunisticSubscriptionsChangedListener(mContext.getOpPackageName(),
                    callback);
                    null, callback);
        } catch (RemoteException ex) {
        } catch (RemoteException ex) {
            // system server crash
            // system server crash
        }
        }
+9 −3
Original line number Original line Diff line number Diff line
@@ -33,16 +33,22 @@ import com.android.internal.telephony.IPhoneStateListener;
import com.android.internal.telephony.IOnSubscriptionsChangedListener;
import com.android.internal.telephony.IOnSubscriptionsChangedListener;


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


import static java.util.Arrays.copyOf;
import static java.util.Arrays.copyOf;


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


        String callingPackage;
        String callingPackage;
        String callingFeatureId;


        IBinder binder;
        IBinder binder;


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


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


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


    @Deprecated
    @Override
    @Override
    public void listen(String pkgForDebug, IPhoneStateListener callback, int events,
    public void listen(String callingPackage, IPhoneStateListener callback, int events,
            boolean notifyNow) {
            boolean notifyNow) {
        listenForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, pkgForDebug, callback,
        listenWithFeature(callingPackage, null, callback, events, notifyNow);
                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
    @Override
    public void listenForSubscriber(int subId, String pkgForDebug, IPhoneStateListener callback,
    public void listenForSubscriber(int subId, String callingPackage, String callingFeatureId,
            int events, boolean notifyNow) {
            IPhoneStateListener callback, int events, boolean notifyNow) {
        listen(pkgForDebug, callback, events, notifyNow, subId);
        listen(callingPackage, callingFeatureId, callback, events, notifyNow, subId);
    }
    }


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


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


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


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