Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 37daac44 authored by Joanne's avatar Joanne Committed by Joanne Chung
Browse files

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
parent d5d35fb2
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -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"],
}
+27 −3
Original line number Diff line number Diff line
@@ -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);
+13 −0
Original line number Diff line number Diff line
# 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)
+9 −0
Original line number Diff line number Diff line
@@ -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);