Add implementation for SliceMetrics
Bug: 76150975
Test: atest cts/tests/tests/slice
Change-Id: Ide07b6b490434841978df86794b048b997d523be
diff --git a/core/java/android/app/slice/SliceMetrics.java b/core/java/android/app/slice/SliceMetrics.java
index 20c1390..746beaf 100644
--- a/core/java/android/app/slice/SliceMetrics.java
+++ b/core/java/android/app/slice/SliceMetrics.java
@@ -18,9 +18,11 @@
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 @@
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 @@
* @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 e33ef1f..50c5853 100644
--- a/proto/src/metrics_constants.proto
+++ b/proto/src/metrics_constants.proto
@@ -5717,6 +5717,24 @@
// 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