Loading core/java/android/app/slice/SliceMetrics.java +23 −0 Original line number Diff line number Diff line Loading @@ -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. Loading @@ -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); } } /** Loading @@ -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); } } } proto/src/metrics_constants.proto +18 −0 Original line number Diff line number Diff line Loading @@ -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 Loading Loading
core/java/android/app/slice/SliceMetrics.java +23 −0 Original line number Diff line number Diff line Loading @@ -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. Loading @@ -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); } } /** Loading @@ -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); } } }
proto/src/metrics_constants.proto +18 −0 Original line number Diff line number Diff line Loading @@ -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 Loading