summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Joanne <joannechung@google.com> 2022-08-31 16:04:05 +0800
committer Joanne Chung <joannechung@google.com> 2022-09-20 11:25:27 +0000
commit37daac447b2082dad42d7cb4fc92ec6d17b6c9e0 (patch)
treef5b890cac16da4e853bc63c06692fbab5c261473
parentd5d35fb282d5b8cefebeb2c51fc164faf5590e1c (diff)
Add event log for content capture
Add event log for content capute connect and set allowlist to help the debugging. Some examples: I cc_connect_state_changed( 1762): [com.google.android.as/com.google .android.apps.miphone.aiai.app.AiAiContentCaptureService,1] I cc_set_allowlist: [14,0] Doesn't have MemoryOnBoot regression for com.google.intelligence.sense after this change. The reason is caused by the crash when the service calling set allowlist. This change fixes the NPE when calling set allowlist, the result is as below: before: go/cc_eventlog_memtest_before after: go/cc_eventlog_memtest_after issue: go/cc_eventlog_memtest_issue Bug: 233040086 Test: manual. To watch event log Test: atest CtsContentCaptureServiceTestCases BYPASS_INCLUSIVE_LANGUAGE_REASON=existing APIs Change-Id: I9b3a97b808c65902d8ff346e6aa890be852fa598
-rw-r--r--services/contentcapture/Android.bp5
-rw-r--r--services/contentcapture/java/com/android/server/contentcapture/ContentCapturePerUserService.java30
-rw-r--r--services/contentcapture/java/com/android/server/contentcapture/EventLogTags.logtags13
-rw-r--r--services/contentcapture/java/com/android/server/contentcapture/RemoteContentCaptureService.java9
4 files changed, 53 insertions, 4 deletions
diff --git a/services/contentcapture/Android.bp b/services/contentcapture/Android.bp
index 434f239dbddc..5392c2cde3b8 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 41a759254909..c503a5a89afd 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<ContentCaptureServerSession> 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<String> getContentCaptureAllowlist() {
+ ArraySet<String> 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<String> 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<String> oldList) {
ArraySet<String> 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 000000000000..5218b26397df
--- /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 1efe55aa0767..3907de4d903a 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);