[SettingsLib] Add preference click metric log
Add a method to log preference click event.
The log order of priority is:
1. preference key
2. preference intent component name
3. preference intent action
4. preference fragment
Bug: 137559984
Test: robotest
Change-Id: Idecd7ada120a70b523ccd134c878f5753183211b
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 8a0ae91..ed0857c 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
@@ -26,6 +26,8 @@
import android.content.Context;
import android.content.Intent;
+import androidx.preference.Preference;
+
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import org.junit.Before;
@@ -60,19 +62,42 @@
}
@Test
- public void logDashboardStartIntent_intentEmpty_shouldNotLog() {
- mProvider.logDashboardStartIntent(mContext, null /* intent */,
+ public void logClickedPreference_preferenceEmpty_shouldNotLog() {
+ final boolean loggable = mProvider.logClickedPreference(null /* preference */,
MetricsEvent.SETTINGS_GESTURES);
+ assertThat(loggable).isFalse();
verifyNoMoreInteractions(mLogWriter);
}
@Test
- public void logDashboardStartIntent_intentHasNoComponent_shouldLog() {
+ public void logClickedPreference_preferenceHasKey_shouldLog() {
+ final String key = "abc";
+ final Preference preference = new Preference(mContext);
+ preference.setKey(key);
+
+ final boolean loggable = mProvider.logClickedPreference(preference,
+ MetricsEvent.SETTINGS_GESTURES);
+
+ assertThat(loggable).isTrue();
+ verify(mLogWriter).action(
+ MetricsEvent.SETTINGS_GESTURES,
+ MetricsEvent.ACTION_SETTINGS_TILE_CLICK,
+ SettingsEnums.PAGE_UNKNOWN,
+ key,
+ 0);
+ }
+
+ @Test
+ public void logClickedPreference_preferenceHasIntent_shouldLog() {
+ final Preference preference = new Preference(mContext);
final Intent intent = new Intent(Intent.ACTION_ASSIST);
+ preference.setIntent(intent);
- mProvider.logDashboardStartIntent(mContext, intent, MetricsEvent.SETTINGS_GESTURES);
+ final boolean loggable = mProvider.logClickedPreference(preference,
+ MetricsEvent.SETTINGS_GESTURES);
+ assertThat(loggable).isTrue();
verify(mLogWriter).action(
MetricsEvent.SETTINGS_GESTURES,
MetricsEvent.ACTION_SETTINGS_TILE_CLICK,
@@ -82,11 +107,54 @@
}
@Test
- public void logDashboardStartIntent_intentIsExternal_shouldLog() {
+ public void logClickedPreference_preferenceHasFragment_shouldLog() {
+ final Preference preference = new Preference(mContext);
+ final String fragment = "com.android.settings.tts.TextToSpeechSettings";
+ preference.setFragment(fragment);
+
+ final boolean loggable = mProvider.logClickedPreference(preference,
+ MetricsEvent.SETTINGS_GESTURES);
+
+ assertThat(loggable).isTrue();
+ verify(mLogWriter).action(
+ MetricsEvent.SETTINGS_GESTURES,
+ MetricsEvent.ACTION_SETTINGS_TILE_CLICK,
+ SettingsEnums.PAGE_UNKNOWN,
+ fragment,
+ 0);
+ }
+
+ @Test
+ public void logStartedIntent_intentEmpty_shouldNotLog() {
+ final boolean loggable = mProvider.logStartedIntent(null /* intent */,
+ MetricsEvent.SETTINGS_GESTURES);
+
+ assertThat(loggable).isFalse();
+ verifyNoMoreInteractions(mLogWriter);
+ }
+
+ @Test
+ public void logStartedIntent_intentHasNoComponent_shouldLog() {
+ final Intent intent = new Intent(Intent.ACTION_ASSIST);
+
+ final boolean loggable = mProvider.logStartedIntent(intent, MetricsEvent.SETTINGS_GESTURES);
+
+ assertThat(loggable).isTrue();
+ verify(mLogWriter).action(
+ MetricsEvent.SETTINGS_GESTURES,
+ MetricsEvent.ACTION_SETTINGS_TILE_CLICK,
+ SettingsEnums.PAGE_UNKNOWN,
+ Intent.ACTION_ASSIST,
+ 0);
+ }
+
+ @Test
+ public void logStartedIntent_intentIsExternal_shouldLog() {
final Intent intent = new Intent().setComponent(new ComponentName("pkg", "cls"));
- mProvider.logDashboardStartIntent(mContext, intent, MetricsEvent.SETTINGS_GESTURES);
+ final boolean loggable = mProvider.logStartedIntent(intent, MetricsEvent.SETTINGS_GESTURES);
+ assertThat(loggable).isTrue();
verify(mLogWriter).action(
MetricsEvent.SETTINGS_GESTURES,
MetricsEvent.ACTION_SETTINGS_TILE_CLICK,