Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
Add implementation for SliceMetrics
Browse files Browse the repository at this point in the history
Bug: 76150975
Test: atest cts/tests/tests/slice
Change-Id: Ide07b6b490434841978df86794b048b997d523be
  • Loading branch information
cwren committed Apr 30, 2018
1 parent be654b3 commit d63dffd
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
23 changes: 23 additions & 0 deletions core/java/android/app/slice/SliceMetrics.java
Expand Up @@ -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.
Expand All @@ -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);
}
}

/**
Expand All @@ -68,5 +84,12 @@ public void logHidden() {
* @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);
}
}
}
18 changes: 18 additions & 0 deletions proto/src/metrics_constants.proto
Expand Up @@ -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
Expand Down

0 comments on commit d63dffd

Please sign in to comment.