From d63dffd8cdf35010ac0f37b791560e99278e43c2 Mon Sep 17 00:00:00 2001 From: Chris Wren Date: Thu, 19 Apr 2018 11:12:46 -0400 Subject: [PATCH] Add implementation for SliceMetrics Bug: 76150975 Test: atest cts/tests/tests/slice Change-Id: Ide07b6b490434841978df86794b048b997d523be --- core/java/android/app/slice/SliceMetrics.java | 23 +++++++++++++++++++ proto/src/metrics_constants.proto | 18 +++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/core/java/android/app/slice/SliceMetrics.java b/core/java/android/app/slice/SliceMetrics.java index 20c1390b25ff7..746beaf939d9e 100644 --- a/core/java/android/app/slice/SliceMetrics.java +++ b/core/java/android/app/slice/SliceMetrics.java @@ -18,9 +18,11 @@ package android.app.slice; import android.annotation.NonNull; import android.content.Context; +import android.metrics.LogMaker; import android.net.Uri; import com.android.internal.logging.MetricsLogger; +import com.android.internal.logging.nano.MetricsProto.MetricsEvent; /** * Metrics interface for slices. @@ -34,24 +36,38 @@ public class SliceMetrics { private static final String TAG = "SliceMetrics"; private MetricsLogger mMetricsLogger; + private LogMaker mLogMaker; /** * An object to be used throughout the life of a slice to register events. */ public SliceMetrics(@NonNull Context context, @NonNull Uri uri) { mMetricsLogger = new MetricsLogger(); + mLogMaker = new LogMaker(MetricsEvent.VIEW_UNKNOWN); + mLogMaker.addTaggedData(MetricsEvent.FIELD_SLICE_AUTHORITY, uri.getAuthority()); + mLogMaker.addTaggedData(MetricsEvent.FIELD_SLICE_PATH, uri.getPath()); } /** * To be called whenever the slice becomes visible to the user. */ public void logVisible() { + synchronized (mLogMaker) { + mLogMaker.setCategory(MetricsEvent.SLICE) + .setType(MetricsEvent.TYPE_OPEN); + mMetricsLogger.write(mLogMaker); + } } /** * To be called whenever the slice becomes invisible to the user. */ public void logHidden() { + synchronized (mLogMaker) { + mLogMaker.setCategory(MetricsEvent.SLICE) + .setType(MetricsEvent.TYPE_CLOSE); + mMetricsLogger.write(mLogMaker); + } } /** @@ -68,5 +84,12 @@ public class SliceMetrics { * @param subSlice The URI of the sub-slice that is the subject of the interaction. */ public void logTouch(int actionType, @NonNull Uri subSlice) { + synchronized (mLogMaker) { + mLogMaker.setCategory(MetricsEvent.SLICE) + .setType(MetricsEvent.TYPE_ACTION) + .addTaggedData(MetricsEvent.FIELD_SUBSLICE_AUTHORITY, subSlice.getAuthority()) + .addTaggedData(MetricsEvent.FIELD_SUBSLICE_PATH, subSlice.getPath()); + mMetricsLogger.write(mLogMaker); + } } } diff --git a/proto/src/metrics_constants.proto b/proto/src/metrics_constants.proto index e33ef1fc8a6c9..50c58535627c5 100644 --- a/proto/src/metrics_constants.proto +++ b/proto/src/metrics_constants.proto @@ -5717,6 +5717,24 @@ message MetricsEvent { // OS: P SETTINGS_ZEN_NOTIFICATIONS = 1400; + // An event category for slices. + // OPEN: Slice became visible. + // CLOSE: Slice became invisible. + // ACTION: Slice was tapped. + SLICE = 1401; + + // The authority part of the slice URI + FIELD_SLICE_AUTHORITY = 1402; + + // The path part of the slice URI + FIELD_SLICE_PATH = 1403; + + // The authority part of the subslice URI + FIELD_SUBSLICE_AUTHORITY = 1404; + + // The path part of the subslice URI + FIELD_SUBSLICE_PATH = 1405; + // ---- End P Constants, all P constants go above this line ---- // Add new aosp constants above this line. // END OF AOSP CONSTANTS