summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Jason Chiu <chiujason@google.com> 2020-03-26 09:47:18 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2020-03-26 09:47:18 +0000
commitedc7799657e725b73330da7b89f1539ce2ea7a7e (patch)
treece55cbde661f9f1d71b0751dbf35f24c42220904
parentaef65ab07bb4738c03695de173528a94c73a1d1e (diff)
parent39e7d17aeb2132e5e98047cd984b8969dbbb0d7d (diff)
Merge "Support logging intents from Profile select dialog" into rvc-dev
-rw-r--r--packages/SettingsLib/src/com/android/settingslib/core/instrumentation/MetricsFeatureProvider.java16
-rw-r--r--packages/SettingsLib/tests/robotests/src/com/android/settingslib/core/instrumentation/MetricsFeatureProviderTest.java32
2 files changed, 48 insertions, 0 deletions
diff --git a/packages/SettingsLib/src/com/android/settingslib/core/instrumentation/MetricsFeatureProvider.java b/packages/SettingsLib/src/com/android/settingslib/core/instrumentation/MetricsFeatureProvider.java
index c34c365c1bfa..7ef080178a2f 100644
--- a/packages/SettingsLib/src/com/android/settingslib/core/instrumentation/MetricsFeatureProvider.java
+++ b/packages/SettingsLib/src/com/android/settingslib/core/instrumentation/MetricsFeatureProvider.java
@@ -169,6 +169,22 @@ public class MetricsFeatureProvider {
sourceMetricsCategory);
}
+ /**
+ * Logs an event when the intent is started by Profile select dialog.
+ *
+ * @return true if the intent is loggable, otherwise false
+ */
+ public boolean logStartedIntentWithProfile(Intent intent, int sourceMetricsCategory,
+ boolean isWorkProfile) {
+ if (intent == null) {
+ return false;
+ }
+ final ComponentName cn = intent.getComponent();
+ final String key = cn != null ? cn.flattenToString() : intent.getAction();
+ return logSettingsTileClick(key + (isWorkProfile ? "/work" : "/personal"),
+ sourceMetricsCategory);
+ }
+
private boolean logSettingsTileClick(String logKey, int sourceMetricsCategory) {
if (TextUtils.isEmpty(logKey)) {
// Not loggable
diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/core/instrumentation/MetricsFeatureProviderTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/core/instrumentation/MetricsFeatureProviderTest.java
index ed0857ca21dc..204a93333d81 100644
--- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/core/instrumentation/MetricsFeatureProviderTest.java
+++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/core/instrumentation/MetricsFeatureProviderTest.java
@@ -164,6 +164,38 @@ public class MetricsFeatureProviderTest {
}
@Test
+ public void logStartedIntentWithProfile_isPersonalProfile_shouldTagPersonal() {
+ final Intent intent = new Intent().setComponent(new ComponentName("pkg", "cls"));
+
+ final boolean loggable = mProvider.logStartedIntentWithProfile(intent,
+ MetricsEvent.SETTINGS_GESTURES, false);
+
+ assertThat(loggable).isTrue();
+ verify(mLogWriter).action(
+ MetricsEvent.SETTINGS_GESTURES,
+ MetricsEvent.ACTION_SETTINGS_TILE_CLICK,
+ SettingsEnums.PAGE_UNKNOWN,
+ "pkg/cls/personal",
+ 0);
+ }
+
+ @Test
+ public void logStartedIntentWithProfile_isWorkProfile_shouldTagWork() {
+ final Intent intent = new Intent().setComponent(new ComponentName("pkg", "cls"));
+
+ final boolean loggable = mProvider.logStartedIntentWithProfile(intent,
+ MetricsEvent.SETTINGS_GESTURES, true);
+
+ assertThat(loggable).isTrue();
+ verify(mLogWriter).action(
+ MetricsEvent.SETTINGS_GESTURES,
+ MetricsEvent.ACTION_SETTINGS_TILE_CLICK,
+ SettingsEnums.PAGE_UNKNOWN,
+ "pkg/cls/work",
+ 0);
+ }
+
+ @Test
public void getAttribution_noActivity_shouldReturnUnknown() {
assertThat(mProvider.getAttribution(null /* activity */))
.isEqualTo(SettingsEnums.PAGE_UNKNOWN);