From 213b9b23a6a4a6f1b647251ceaa13750b72e0f78 Mon Sep 17 00:00:00 2001 From: Sunny Shao Date: Wed, 27 Nov 2019 18:53:54 +0800 Subject: [PATCH] Update the VisibilityLoggerMixin and add a new enum - Add a new action enum. - Add a writeElapsedTimeMetric api. Bug: 137558156 Test: compilation Change-Id: I82e15a5b2b3b30e7ef9300e53c2afe4f57655f5c --- core/proto/android/app/settings_enums.proto | 6 ++++++ .../core/instrumentation/VisibilityLoggerMixin.java | 13 +++++++++++++ 2 files changed, 19 insertions(+) diff --git a/core/proto/android/app/settings_enums.proto b/core/proto/android/app/settings_enums.proto index d181436d18f3a..ab97fdd74b469 100644 --- a/core/proto/android/app/settings_enums.proto +++ b/core/proto/android/app/settings_enums.proto @@ -693,6 +693,12 @@ enum Action { // CATEGORY: SETTINGS // OS: R ACTION_CONTROLLER_UPDATE_STATE = 1728; + + // Custom tag to evaluate the consuming time from onAttach to + // DashboardFragment.updatePreferenceStates. + // CATEGORY: SETTINGS + // OS: R + ACTION_DASHBOARD_VISIBLE_TIME = 1729; } /** diff --git a/packages/SettingsLib/src/com/android/settingslib/core/instrumentation/VisibilityLoggerMixin.java b/packages/SettingsLib/src/com/android/settingslib/core/instrumentation/VisibilityLoggerMixin.java index 1c6287907fbd2..0a1a1226d0a3a 100644 --- a/packages/SettingsLib/src/com/android/settingslib/core/instrumentation/VisibilityLoggerMixin.java +++ b/packages/SettingsLib/src/com/android/settingslib/core/instrumentation/VisibilityLoggerMixin.java @@ -75,6 +75,19 @@ public class VisibilityLoggerMixin implements LifecycleObserver, OnAttach { } } + /** + * Logs the elapsed time from onAttach to calling {@link #writeElapsedTimeMetric(int, String)}. + * @param action : The value of the Action Enums. + * @param key : The value of special key string. + */ + public void writeElapsedTimeMetric(int action, String key) { + if (mMetricsFeature == null || mMetricsCategory == METRICS_CATEGORY_UNKNOWN) { + return; + } + final int elapse = (int) (SystemClock.elapsedRealtime() - mTimestamp); + mMetricsFeature.action(METRICS_CATEGORY_UNKNOWN, action, mMetricsCategory, key, elapse); + } + /** * Sets source metrics category for this logger. Source is the caller that opened this UI. */