From 283075f219cff8dd0e3c1793934dfd745cca1fde Mon Sep 17 00:00:00 2001 From: Joanne Chung Date: Wed, 11 May 2022 13:14:10 +0800 Subject: [PATCH] Remove application package name from ContentCapture logging Bug: 231634467 Test: manual. build pass and local log doesn't pass the packagename. Change-Id: I35a103ac55f77a05a3700db34460aa8d98361e52 --- .../ContentCaptureManagerService.java | 5 +- .../ContentCaptureMetricsLogger.java | 58 ++++++------------- .../ContentCapturePerUserService.java | 10 ++-- .../RemoteContentCaptureService.java | 8 +-- 4 files changed, 27 insertions(+), 54 deletions(-) diff --git a/services/contentcapture/java/com/android/server/contentcapture/ContentCaptureManagerService.java b/services/contentcapture/java/com/android/server/contentcapture/ContentCaptureManagerService.java index 61d784ecb5f3f..ad6e7dbebae9a 100644 --- a/services/contentcapture/java/com/android/server/contentcapture/ContentCaptureManagerService.java +++ b/services/contentcapture/java/com/android/server/contentcapture/ContentCaptureManagerService.java @@ -730,7 +730,7 @@ public final class ContentCaptureManagerService extends String serviceName = mServiceNameResolver.getServiceName(userId); ContentCaptureMetricsLogger.writeServiceEvent( EVENT__DATA_SHARE_ERROR_CONCURRENT_REQUEST, - serviceName, request.getPackageName()); + serviceName); clientAdapter.error( ContentCaptureManager.DATA_SHARE_ERROR_CONCURRENT_REQUEST); } catch (RemoteException e) { @@ -1303,8 +1303,7 @@ public final class ContentCaptureManagerService extends private void logServiceEvent(int eventType) { int userId = UserHandle.getCallingUserId(); String serviceName = mParentService.mServiceNameResolver.getServiceName(userId); - ContentCaptureMetricsLogger.writeServiceEvent(eventType, serviceName, - mDataShareRequest.getPackageName()); + ContentCaptureMetricsLogger.writeServiceEvent(eventType, serviceName); } } } diff --git a/services/contentcapture/java/com/android/server/contentcapture/ContentCaptureMetricsLogger.java b/services/contentcapture/java/com/android/server/contentcapture/ContentCaptureMetricsLogger.java index 7ea4eff3381c0..db3db4ec01494 100644 --- a/services/contentcapture/java/com/android/server/contentcapture/ContentCaptureMetricsLogger.java +++ b/services/contentcapture/java/com/android/server/contentcapture/ContentCaptureMetricsLogger.java @@ -34,72 +34,48 @@ public final class ContentCaptureMetricsLogger { } /** @hide */ - public static void writeServiceEvent(int eventType, @NonNull String serviceName, - @Nullable String targetPackage) { + public static void writeServiceEvent(int eventType, @NonNull String serviceName) { + // we should not logging the application package name FrameworkStatsLog.write(FrameworkStatsLog.CONTENT_CAPTURE_SERVICE_EVENTS, eventType, - serviceName, targetPackage); - } - - /** @hide */ - public static void writeServiceEvent(int eventType, @NonNull ComponentName service, - @Nullable ComponentName target) { - writeServiceEvent(eventType, ComponentName.flattenToShortString(service), - ComponentName.flattenToShortString(target)); - } - - /** @hide */ - public static void writeServiceEvent(int eventType, @NonNull ComponentName service, - @Nullable String targetPackage) { - writeServiceEvent(eventType, ComponentName.flattenToShortString(service), targetPackage); + serviceName, /* componentName= */ null); } /** @hide */ public static void writeServiceEvent(int eventType, @NonNull ComponentName service) { - writeServiceEvent(eventType, ComponentName.flattenToShortString(service), null); + writeServiceEvent(eventType, ComponentName.flattenToShortString(service)); } /** @hide */ public static void writeSetWhitelistEvent(@Nullable ComponentName service, @Nullable List packages, @Nullable List activities) { final String serviceName = ComponentName.flattenToShortString(service); - StringBuilder stringBuilder = new StringBuilder(); - if (packages != null && packages.size() > 0) { - final int size = packages.size(); - stringBuilder.append(packages.get(0)); - for (int i = 1; i < size; i++) { - stringBuilder.append(" "); - stringBuilder.append(packages.get(i)); - } - } - if (activities != null && activities.size() > 0) { - stringBuilder.append(" "); - stringBuilder.append(activities.get(0).flattenToShortString()); - final int size = activities.size(); - for (int i = 1; i < size; i++) { - stringBuilder.append(" "); - stringBuilder.append(activities.get(i).flattenToShortString()); - } - } + // TODO: log allow list count. + int packageCount = packages != null ? packages.size() : 0; + int activityCount = activities != null ? activities.size() : 0; + // we should not logging the application package name + // log the allow list package and activity count instead FrameworkStatsLog.write(FrameworkStatsLog.CONTENT_CAPTURE_SERVICE_EVENTS, FrameworkStatsLog.CONTENT_CAPTURE_SERVICE_EVENTS__EVENT__SET_WHITELIST, - serviceName, stringBuilder.toString()); + serviceName, /* allowListStr= */ null); } /** @hide */ public static void writeSessionEvent(int sessionId, int event, int flags, - @NonNull ComponentName service, @Nullable ComponentName app, boolean isChildSession) { + @NonNull ComponentName service, boolean isChildSession) { + // we should not logging the application package name FrameworkStatsLog.write(FrameworkStatsLog.CONTENT_CAPTURE_SESSION_EVENTS, sessionId, event, flags, ComponentName.flattenToShortString(service), - ComponentName.flattenToShortString(app), isChildSession); + /* componentName= */ null, isChildSession); } /** @hide */ public static void writeSessionFlush(int sessionId, @NonNull ComponentName service, - @Nullable ComponentName app, @NonNull FlushMetrics fm, - @NonNull ContentCaptureOptions options, int flushReason) { + @NonNull FlushMetrics fm, @NonNull ContentCaptureOptions options, + int flushReason) { + // we should not logging the application package name FrameworkStatsLog.write(FrameworkStatsLog.CONTENT_CAPTURE_FLUSHED, sessionId, ComponentName.flattenToShortString(service), - ComponentName.flattenToShortString(app), fm.sessionStarted, fm.sessionFinished, + /* componentName= */ null, fm.sessionStarted, fm.sessionFinished, fm.viewAppearedCount, fm.viewDisappearedCount, fm.viewTextChangedCount, options.maxBufferSize, options.idleFlushingFrequencyMs, options.textChangeFlushingFrequencyMs, flushReason); diff --git a/services/contentcapture/java/com/android/server/contentcapture/ContentCapturePerUserService.java b/services/contentcapture/java/com/android/server/contentcapture/ContentCapturePerUserService.java index 822a42bf50cf2..9bc1cee2aa05f 100644 --- a/services/contentcapture/java/com/android/server/contentcapture/ContentCapturePerUserService.java +++ b/services/contentcapture/java/com/android/server/contentcapture/ContentCapturePerUserService.java @@ -330,7 +330,7 @@ final class ContentCapturePerUserService writeSessionEvent(sessionId, FrameworkStatsLog.CONTENT_CAPTURE_SESSION_EVENTS__EVENT__SESSION_NOT_CREATED, STATE_DISABLED | STATE_NO_SERVICE, serviceComponentName, - componentName, /* isChildSession= */ false); + /* isChildSession= */ false); return; } if (serviceComponentName == null) { @@ -354,7 +354,7 @@ final class ContentCapturePerUserService writeSessionEvent(sessionId, FrameworkStatsLog.CONTENT_CAPTURE_SESSION_EVENTS__EVENT__SESSION_NOT_CREATED, STATE_DISABLED | STATE_NOT_WHITELISTED, serviceComponentName, - componentName, /* isChildSession= */ false); + /* isChildSession= */ false); return; } @@ -368,7 +368,7 @@ final class ContentCapturePerUserService writeSessionEvent(sessionId, FrameworkStatsLog.CONTENT_CAPTURE_SESSION_EVENTS__EVENT__SESSION_NOT_CREATED, STATE_DISABLED | STATE_DUPLICATED_ID, - serviceComponentName, componentName, /* isChildSession= */ false); + serviceComponentName, /* isChildSession= */ false); return; } @@ -385,7 +385,7 @@ final class ContentCapturePerUserService writeSessionEvent(sessionId, FrameworkStatsLog.CONTENT_CAPTURE_SESSION_EVENTS__EVENT__SESSION_NOT_CREATED, STATE_DISABLED | STATE_NO_SERVICE, serviceComponentName, - componentName, /* isChildSession= */ false); + /* isChildSession= */ false); return; } @@ -740,7 +740,7 @@ final class ContentCapturePerUserService @Override public void writeSessionFlush(int sessionId, ComponentName app, FlushMetrics flushMetrics, ContentCaptureOptions options, int flushReason) { - ContentCaptureMetricsLogger.writeSessionFlush(sessionId, getServiceComponentName(), app, + ContentCaptureMetricsLogger.writeSessionFlush(sessionId, getServiceComponentName(), flushMetrics, options, flushReason); } diff --git a/services/contentcapture/java/com/android/server/contentcapture/RemoteContentCaptureService.java b/services/contentcapture/java/com/android/server/contentcapture/RemoteContentCaptureService.java index 08e6a0550f692..1efe55aa07677 100644 --- a/services/contentcapture/java/com/android/server/contentcapture/RemoteContentCaptureService.java +++ b/services/contentcapture/java/com/android/server/contentcapture/RemoteContentCaptureService.java @@ -119,8 +119,7 @@ final class RemoteContentCaptureService // Metrics logging. writeSessionEvent(sessionId, FrameworkStatsLog.CONTENT_CAPTURE_SESSION_EVENTS__EVENT__ON_SESSION_STARTED, - initialState, getComponentName(), context.getActivityComponent(), - /* is_child_session= */ false); + initialState, getComponentName(), /* is_child_session= */ false); } /** @@ -132,8 +131,7 @@ final class RemoteContentCaptureService // Metrics logging. writeSessionEvent(sessionId, FrameworkStatsLog.CONTENT_CAPTURE_SESSION_EVENTS__EVENT__ON_SESSION_FINISHED, - /* flags= */ 0, getComponentName(), /* app= */ null, - /* is_child_session= */ false); + /* flags= */ 0, getComponentName(), /* is_child_session= */ false); } /** @@ -158,7 +156,7 @@ final class RemoteContentCaptureService scheduleAsyncRequest((s) -> s.onDataShared(request, dataShareCallback)); writeServiceEvent( FrameworkStatsLog.CONTENT_CAPTURE_SERVICE_EVENTS__EVENT__ON_DATA_SHARE_REQUEST, - mComponentName, request.getPackageName()); + mComponentName); } /**