1 /* 2 * Copyright (C) 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.server.contentcapture; 17 18 import android.annotation.NonNull; 19 import android.annotation.Nullable; 20 import android.content.ComponentName; 21 import android.content.ContentCaptureOptions; 22 import android.service.contentcapture.FlushMetrics; 23 24 import com.android.internal.util.FrameworkStatsLog; 25 26 import java.util.List; 27 28 /** @hide */ 29 public final class ContentCaptureMetricsLogger { 30 /** 31 * Class only contains static utility functions, and should not be instantiated 32 */ ContentCaptureMetricsLogger()33 private ContentCaptureMetricsLogger() { 34 } 35 36 /** @hide */ writeServiceEvent(int eventType, @NonNull String serviceName)37 public static void writeServiceEvent(int eventType, @NonNull String serviceName) { 38 // we should not logging the application package name 39 FrameworkStatsLog.write(FrameworkStatsLog.CONTENT_CAPTURE_SERVICE_EVENTS, eventType, 40 serviceName, /* componentName= */ null, 0, 0); 41 } 42 43 /** @hide */ writeServiceEvent(int eventType, @NonNull ComponentName service)44 public static void writeServiceEvent(int eventType, @NonNull ComponentName service) { 45 writeServiceEvent(eventType, ComponentName.flattenToShortString(service)); 46 } 47 48 /** @hide */ writeSetWhitelistEvent(@ullable ComponentName service, @Nullable List<String> packages, @Nullable List<ComponentName> activities)49 public static void writeSetWhitelistEvent(@Nullable ComponentName service, 50 @Nullable List<String> packages, @Nullable List<ComponentName> activities) { 51 final String serviceName = ComponentName.flattenToShortString(service); 52 int packageCount = packages != null ? packages.size() : 0; 53 int activityCount = activities != null ? activities.size() : 0; 54 // we should not logging the application package name 55 // log the allow list package and activity count instead 56 FrameworkStatsLog.write(FrameworkStatsLog.CONTENT_CAPTURE_SERVICE_EVENTS, 57 FrameworkStatsLog.CONTENT_CAPTURE_SERVICE_EVENTS__EVENT__SET_WHITELIST, 58 serviceName, /* allowListStr= */ null, packageCount, activityCount); 59 } 60 61 /** @hide */ writeSessionEvent(int sessionId, int event, int flags, @NonNull ComponentName service, boolean isChildSession)62 public static void writeSessionEvent(int sessionId, int event, int flags, 63 @NonNull ComponentName service, boolean isChildSession) { 64 // we should not logging the application package name 65 FrameworkStatsLog.write(FrameworkStatsLog.CONTENT_CAPTURE_SESSION_EVENTS, sessionId, event, 66 flags, ComponentName.flattenToShortString(service), 67 /* componentName= */ null, isChildSession); 68 } 69 70 /** @hide */ writeSessionFlush(int sessionId, @NonNull ComponentName service, @NonNull FlushMetrics fm, @NonNull ContentCaptureOptions options, int flushReason)71 public static void writeSessionFlush(int sessionId, @NonNull ComponentName service, 72 @NonNull FlushMetrics fm, @NonNull ContentCaptureOptions options, 73 int flushReason) { 74 // we should not logging the application package name 75 FrameworkStatsLog.write(FrameworkStatsLog.CONTENT_CAPTURE_FLUSHED, sessionId, 76 ComponentName.flattenToShortString(service), 77 /* componentName= */ null, fm.sessionStarted, fm.sessionFinished, 78 fm.viewAppearedCount, fm.viewDisappearedCount, fm.viewTextChangedCount, 79 options.maxBufferSize, options.idleFlushingFrequencyMs, 80 options.textChangeFlushingFrequencyMs, flushReason); 81 } 82 } 83