Merge "Add implementation for SliceMetrics" into pi-dev am: 32491b6f8e
am: e032e2ff4a
Change-Id: I0eb27889a32c02c7a5f74eff1dd7fce05bf7d060
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 ----
|
||||
|
||||
// First Q constant in master goes here:
|
||||
|
||||
Reference in New Issue
Block a user