From 028d0905987e045e5d789647f7e36ff87f2af119 Mon Sep 17 00:00:00 2001 From: Alex Kershaw Date: Sat, 15 Feb 2020 19:59:02 +0000 Subject: [PATCH] Log more cross-profile metrics Log metrics for the new app-op permission INTERACT_ACROSS_PROFILES and each of the new app-facing and DPC-facing APIs where possible. This is the second CL which adds server-side metrics that were previously attempted client-side. Bug: 136249261 Bug: 149370554 Bug: 149318411 Bug: 149370875 Bug: 149370515 Test: atest com.android.cts.devicepolicy.CrossProfileAppsPermissionHostSideTest#testCreateRequestInteractAcrossProfilesIntent_canRequestInteraction_returnsIntent_isLogged Change-Id: Ib1064ad793f6e93bc1fea665991011de7ffd8675 --- .../com/android/server/am/ActiveServices.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/services/core/java/com/android/server/am/ActiveServices.java b/services/core/java/com/android/server/am/ActiveServices.java index 430a5b950f14e..50f43b5c1bae8 100644 --- a/services/core/java/com/android/server/am/ActiveServices.java +++ b/services/core/java/com/android/server/am/ActiveServices.java @@ -49,6 +49,7 @@ import android.app.NotificationManager; import android.app.PendingIntent; import android.app.Service; import android.app.ServiceStartArgs; +import android.app.admin.DevicePolicyEventLogger; import android.appwidget.AppWidgetManagerInternal; import android.content.ComponentName; import android.content.ComponentName.WithComponentName; @@ -79,6 +80,7 @@ import android.os.SystemProperties; import android.os.TransactionTooLargeException; import android.os.UserHandle; import android.provider.Settings; +import android.stats.devicepolicy.DevicePolicyEnums; import android.text.TextUtils; import android.util.ArrayMap; import android.util.ArraySet; @@ -1912,6 +1914,8 @@ public final class ActiveServices { requestServiceBindingLocked(s, b.intent, callerFg, false); } + maybeLogBindCrossProfileService(userId, callingPackage, callerApp.info.uid); + getServiceMapLocked(s.userId).ensureNotStartingBackgroundLocked(s); } finally { @@ -1921,6 +1925,21 @@ public final class ActiveServices { return 1; } + private void maybeLogBindCrossProfileService( + int userId, String callingPackage, int callingUid) { + if (UserHandle.isCore(callingUid)) { + return; + } + final int callingUserId = UserHandle.getCallingUserId(); + if (callingUserId == userId + || !mAm.mUserController.isSameProfileGroup(callingUserId, userId)) { + return; + } + DevicePolicyEventLogger.createEvent(DevicePolicyEnums.BIND_CROSS_PROFILE_SERVICE) + .setStrings(callingPackage) + .write(); + } + void publishServiceLocked(ServiceRecord r, Intent intent, IBinder service) { final long origId = Binder.clearCallingIdentity(); try {