Merge "Use PermissionChecker.checkPermissionForDataDeliveryFromDataSource to check MANAGE_ONGOING_CALLS in InCallController" into sc-dev am: 1ad3b5eb8e
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/services/Telecomm/+/14134237
Change-Id: Ie955d5f1c922be6a3554a002e074844558670a16
diff --git a/src/com/android/server/telecom/InCallController.java b/src/com/android/server/telecom/InCallController.java
index c7c5ede..eed341e 100644
--- a/src/com/android/server/telecom/InCallController.java
+++ b/src/com/android/server/telecom/InCallController.java
@@ -23,6 +23,7 @@
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 @@
}
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) {
diff --git a/src/com/android/server/telecom/TelecomServiceImpl.java b/src/com/android/server/telecom/TelecomServiceImpl.java
index 0f48e44..c342350 100644
--- a/src/com/android/server/telecom/TelecomServiceImpl.java
+++ b/src/com/android/server/telecom/TelecomServiceImpl.java
@@ -32,6 +32,7 @@
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 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();
}
diff --git a/tests/src/com/android/server/telecom/tests/ComponentContextFixture.java b/tests/src/com/android/server/telecom/tests/ComponentContextFixture.java
index 1b15039..f4c77f3 100644
--- a/tests/src/com/android/server/telecom/tests/ComponentContextFixture.java
+++ b/tests/src/com/android/server/telecom/tests/ComponentContextFixture.java
@@ -32,6 +32,7 @@
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;
@@ -263,6 +264,11 @@
}
@Override
+ public AttributionSource getAttributionSource() {
+ return mAttributionSource;
+ }
+
+ @Override
public ContentResolver getContentResolver() {
return new ContentResolver(mApplicationContextSpy) {
@Override
@@ -450,6 +456,11 @@
}
}
+ 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<>();
diff --git a/tests/src/com/android/server/telecom/tests/InCallControllerTests.java b/tests/src/com/android/server/telecom/tests/InCallControllerTests.java
index 8ae823e..8b71974 100644
--- a/tests/src/com/android/server/telecom/tests/InCallControllerTests.java
+++ b/tests/src/com/android/server/telecom/tests/InCallControllerTests.java
@@ -45,6 +45,7 @@
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 @@
@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 @@
.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);