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

Commit 1ad3b5eb authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Use PermissionChecker.checkPermissionForDataDeliveryFromDataSource to...

Merge "Use PermissionChecker.checkPermissionForDataDeliveryFromDataSource to check MANAGE_ONGOING_CALLS in InCallController" into sc-dev
parents 9ef8cb0c e3f82cc7
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.annotation.NonNull;
import android.app.AppOpsManager;
import android.app.Notification;
import android.app.NotificationManager;
import android.content.AttributionSource;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
@@ -2133,9 +2134,13 @@ public class InCallController extends CallsManagerListenerBase {
    }

    private boolean isAppOpsPermittedManageOngoingCalls(int uid, String callingPackage) {
        return PermissionChecker.checkPermissionForPreflight(mContext,
                Manifest.permission.MANAGE_ONGOING_CALLS, PermissionChecker.PID_UNKNOWN, uid,
                        callingPackage) == PermissionChecker.PERMISSION_GRANTED;
        return PermissionChecker.checkPermissionForDataDeliveryFromDataSource(mContext,
                Manifest.permission.MANAGE_ONGOING_CALLS, PermissionChecker.PID_UNKNOWN,
                        new AttributionSource(mContext.getAttributionSource(),
                                new AttributionSource(uid, callingPackage,
                                        /*attributionTag*/ null)), "Checking whether the app has"
                                                + " MANAGE_ONGOING_CALLS permission")
                                                        == PermissionChecker.PERMISSION_GRANTED;
    }

    private void sendCrashedInCallServiceNotification(String packageName) {
+9 −4
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import android.app.ActivityManager;
import android.app.AppOpsManager;
import android.app.UiModeManager;
import android.app.compat.CompatChanges;
import android.content.AttributionSource;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
@@ -839,10 +840,14 @@ public class TelecomServiceImpl {
        public boolean hasManageOngoingCallsPermission(String callingPackage) {
            try {
                Log.startSession("TSI.hMOCP");
                return PermissionChecker.checkPermissionForPreflight(mContext,
                        Manifest.permission.MANAGE_ONGOING_CALLS,
                                PermissionChecker.PID_UNKNOWN, Binder.getCallingUid(),
                                        callingPackage) == PermissionChecker.PERMISSION_GRANTED;
                return PermissionChecker.checkPermissionForDataDeliveryFromDataSource(
                        mContext, Manifest.permission.MANAGE_ONGOING_CALLS,
                        Binder.getCallingPid(),
                        new AttributionSource(mContext.getAttributionSource(),
                                new AttributionSource(Binder.getCallingUid(),
                                        callingPackage, /*attributionTag*/ null)),
                        "Checking whether the caller has MANAGE_ONGOING_CALLS permission")
                                == PermissionChecker.PERMISSION_GRANTED;
            } finally {
                Log.endSession();
            }
+11 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import android.app.NotificationManager;
import android.app.StatusBarManager;
import android.app.UiModeManager;
import android.app.role.RoleManager;
import android.content.AttributionSource;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.ContentResolver;
@@ -262,6 +263,11 @@ public class ComponentContextFixture implements TestFixture<Context> {
            return mTestApplicationInfo;
        }

        @Override
        public AttributionSource getAttributionSource() {
            return mAttributionSource;
        }

        @Override
        public ContentResolver getContentResolver() {
            return new ContentResolver(mApplicationContextSpy) {
@@ -450,6 +456,11 @@ public class ComponentContextFixture implements TestFixture<Context> {
        }
    }

    private static final int UID = 123;
    private static final String PACKAGE_NAME = "com.android.server.telecom.tests";
    private final AttributionSource mAttributionSource =
            new AttributionSource.Builder(UID).setPackageName(PACKAGE_NAME).build();

    private final Multimap<String, ComponentName> mComponentNamesByAction =
            ArrayListMultimap.create();
    private final Map<ComponentName, IInterface> mServiceByComponentName = new HashMap<>();
+3 −0
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ import android.app.AppOpsManager;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.UiModeManager;
import android.content.AttributionSource;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
@@ -124,6 +125,7 @@ public class InCallControllerTests extends TelecomTestCase {
    @Mock Analytics.CallInfoImpl mCallInfo;
    @Mock NotificationManager mNotificationManager;
    @Mock PermissionInfo mMockPermissionInfo;
    @Mock AttributionSource mAttributionSource;

    private static final int CURRENT_USER_ID = 900973;
    private static final String DEF_PKG = "defpkg";
@@ -180,6 +182,7 @@ public class InCallControllerTests extends TelecomTestCase {
                .thenReturn(mNotificationManager);
        when(mMockPackageManager.getPermissionInfo(anyString(), anyInt())).thenReturn(
                mMockPermissionInfo);
        when(mMockContext.getAttributionSource()).thenReturn(mAttributionSource);
        mInCallController = new InCallController(mMockContext, mLock, mMockCallsManager,
                mMockSystemStateHelper, mDefaultDialerCache, mTimeoutsAdapter,
                mEmergencyCallHelper, mCarModeTracker, mClockProxy);