diff --git a/services/contentcapture/Android.bp b/services/contentcapture/Android.bp index 434f239dbddce..5392c2cde3b86 100644 --- a/services/contentcapture/Android.bp +++ b/services/contentcapture/Android.bp @@ -17,6 +17,9 @@ filegroup { java_library_static { name: "services.contentcapture", defaults: ["platform_service_defaults"], - srcs: [":services.contentcapture-sources"], + srcs: [ + ":services.contentcapture-sources", + "java/**/*.logtags", + ], libs: ["services.core"], } diff --git a/services/contentcapture/java/com/android/server/contentcapture/ContentCapturePerUserService.java b/services/contentcapture/java/com/android/server/contentcapture/ContentCapturePerUserService.java index 41a7592549093..c503a5a89afd6 100644 --- a/services/contentcapture/java/com/android/server/contentcapture/ContentCapturePerUserService.java +++ b/services/contentcapture/java/com/android/server/contentcapture/ContentCapturePerUserService.java @@ -60,6 +60,7 @@ import android.service.contentcapture.SnapshotData; import android.service.voice.VoiceInteractionManagerInternal; import android.util.ArrayMap; import android.util.ArraySet; +import android.util.EventLog; import android.util.Slog; import android.util.SparseArray; import android.util.SparseBooleanArray; @@ -69,6 +70,7 @@ import android.view.contentcapture.DataShareRequest; import com.android.internal.annotations.GuardedBy; import com.android.internal.os.IResultReceiver; +import com.android.internal.util.CollectionUtils; import com.android.internal.util.FrameworkStatsLog; import com.android.server.LocalServices; import com.android.server.contentcapture.RemoteContentCaptureService.ContentCaptureServiceCallbacks; @@ -88,6 +90,10 @@ final class ContentCapturePerUserService private static final String TAG = ContentCapturePerUserService.class.getSimpleName(); + private static final int EVENT_LOG_CONNECT_STATE_DIED = 0; + static final int EVENT_LOG_CONNECT_STATE_CONNECTED = 1; + static final int EVENT_LOG_CONNECT_STATE_DISCONNECTED = 2; + @GuardedBy("mLock") private final SparseArray mSessions = new SparseArray<>(); @@ -190,9 +196,12 @@ final class ContentCapturePerUserService Slog.w(TAG, "remote service died: " + service); synchronized (mLock) { mZombie = true; + ComponentName serviceComponent = getServiceComponentName(); writeServiceEvent( FrameworkStatsLog.CONTENT_CAPTURE_SERVICE_EVENTS__EVENT__ON_REMOTE_SERVICE_DIED, - getServiceComponentName()); + serviceComponent); + EventLog.writeEvent(EventLogTags.CC_CONNECT_STATE_CHANGED, mUserId, + EVENT_LOG_CONNECT_STATE_DIED, 0); } } @@ -529,6 +538,15 @@ final class ContentCapturePerUserService return mConditionsByPkg.get(packageName); } + @Nullable + ArraySet getContentCaptureAllowlist() { + ArraySet allowPackages; + synchronized (mLock) { + allowPackages = mMaster.mGlobalContentCaptureOptions.getWhitelistedPackages(mUserId); + } + return allowPackages; + } + @GuardedBy("mLock") void onActivityEventLocked(@NonNull ComponentName componentName, @ActivityEventType int type) { if (mRemoteService == null) { @@ -617,8 +635,12 @@ final class ContentCapturePerUserService ArraySet oldList = mMaster.mGlobalContentCaptureOptions.getWhitelistedPackages(mUserId); + EventLog.writeEvent(EventLogTags.CC_CURRENT_ALLOWLIST, mUserId, + CollectionUtils.size(oldList)); mMaster.mGlobalContentCaptureOptions.setWhitelist(mUserId, packages, activities); + EventLog.writeEvent(EventLogTags.CC_SET_ALLOWLIST, mUserId, + CollectionUtils.size(packages), CollectionUtils.size(activities)); writeSetWhitelistEvent(getServiceComponentName(), packages, activities); updateContentCaptureOptions(oldList); @@ -699,13 +721,15 @@ final class ContentCapturePerUserService private void updateContentCaptureOptions(@Nullable ArraySet oldList) { ArraySet adding = mMaster.mGlobalContentCaptureOptions .getWhitelistedPackages(mUserId); + int addingCount = CollectionUtils.size(adding); + EventLog.writeEvent(EventLogTags.CC_CURRENT_ALLOWLIST, mUserId, addingCount); if (oldList != null && adding != null) { adding.removeAll(oldList); } - int N = adding != null ? adding.size() : 0; - for (int i = 0; i < N; i++) { + EventLog.writeEvent(EventLogTags.CC_UPDATE_OPTIONS, mUserId, addingCount); + for (int i = 0; i < addingCount; i++) { String packageName = adding.valueAt(i); ContentCaptureOptions options = mMaster.mGlobalContentCaptureOptions .getOptions(mUserId, packageName); diff --git a/services/contentcapture/java/com/android/server/contentcapture/EventLogTags.logtags b/services/contentcapture/java/com/android/server/contentcapture/EventLogTags.logtags new file mode 100644 index 0000000000000..5218b26397df6 --- /dev/null +++ b/services/contentcapture/java/com/android/server/contentcapture/EventLogTags.logtags @@ -0,0 +1,13 @@ +# See system/logging/logcat/event.logtags for a description of the format of this file. + +option java_package com.android.server.contentcapture + +# ContentCaptureService connection state change, refer to ContentCapturePerUserService +# for type definition +53200 cc_connect_state_changed (user|1|5),(type|1|5),(package_count|1|1) +# Set the package and activity allowlist +53201 cc_set_allowlist (user|1|5),(package_count|1|1),(activity_count|1|1) +# Get the current allowlist +53202 cc_current_allowlist (user|1|5),(count|1|1) +# update content capture client option with new allow list count +53203 cc_update_options (user|1|5),(count|1) diff --git a/services/contentcapture/java/com/android/server/contentcapture/RemoteContentCaptureService.java b/services/contentcapture/java/com/android/server/contentcapture/RemoteContentCaptureService.java index 1efe55aa07677..3907de4d903aa 100644 --- a/services/contentcapture/java/com/android/server/contentcapture/RemoteContentCaptureService.java +++ b/services/contentcapture/java/com/android/server/contentcapture/RemoteContentCaptureService.java @@ -31,6 +31,7 @@ import android.service.contentcapture.IContentCaptureService; import android.service.contentcapture.IContentCaptureServiceCallback; import android.service.contentcapture.IDataShareCallback; import android.service.contentcapture.SnapshotData; +import android.util.EventLog; import android.util.Slog; import android.view.contentcapture.ContentCaptureContext; import android.view.contentcapture.DataRemovalRequest; @@ -38,6 +39,7 @@ import android.view.contentcapture.DataShareRequest; import com.android.internal.infra.AbstractMultiplePendingRequestsRemoteService; import com.android.internal.os.IResultReceiver; +import com.android.internal.util.CollectionUtils; import com.android.internal.util.FrameworkStatsLog; final class RemoteContentCaptureService @@ -88,6 +90,10 @@ final class RemoteContentCaptureService writeServiceEvent( FrameworkStatsLog.CONTENT_CAPTURE_SERVICE_EVENTS__EVENT__ON_CONNECTED, mComponentName); + EventLog.writeEvent(EventLogTags.CC_CONNECT_STATE_CHANGED, + mPerUserService.getUserId(), + ContentCapturePerUserService.EVENT_LOG_CONNECT_STATE_CONNECTED, + CollectionUtils.size(mPerUserService.getContentCaptureAllowlist())); } finally { // Update the system-service state, in case the service reconnected after // dying @@ -98,6 +104,9 @@ final class RemoteContentCaptureService writeServiceEvent( FrameworkStatsLog.CONTENT_CAPTURE_SERVICE_EVENTS__EVENT__ON_DISCONNECTED, mComponentName); + EventLog.writeEvent(EventLogTags.CC_CONNECT_STATE_CHANGED, + mPerUserService.getUserId(), + ContentCapturePerUserService.EVENT_LOG_CONNECT_STATE_DISCONNECTED, 0); } } catch (Exception e) { Slog.w(mTag, "Exception calling onConnectedStateChanged(" + connected + "): " + e);