Log smart settings suggestion enabled/disabled state for A/B experiments
Test: RunSettingsRoboTests
Bug: 64121058
Change-Id: Iadfa575b9a21caecb515b9975d388ee0d0480c11
diff --git a/src/com/android/settings/dashboard/DashboardAdapter.java b/src/com/android/settings/dashboard/DashboardAdapter.java
index fff7002..741067a 100644
--- a/src/com/android/settings/dashboard/DashboardAdapter.java
+++ b/src/com/android/settings/dashboard/DashboardAdapter.java
@@ -30,6 +30,7 @@
import android.text.TextUtils;
import android.util.ArrayMap;
import android.util.Log;
+import android.util.Pair;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -47,6 +48,7 @@
import com.android.settings.dashboard.suggestions.SuggestionAdapter;
import com.android.settings.dashboard.suggestions.SuggestionDismissController;
import com.android.settings.dashboard.suggestions.SuggestionFeatureProvider;
+import com.android.settings.dashboard.suggestions.SuggestionLogHelper;
import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.Utils;
import com.android.settingslib.drawer.DashboardCategory;
@@ -159,7 +161,8 @@
final String identifier = mSuggestionFeatureProvider.getSuggestionIdentifier(
mContext, suggestion);
mMetricsFeatureProvider.action(
- mContext, MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION, identifier);
+ mContext, MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION, identifier,
+ getSuggestionTaggedData());
mSuggestionsShownLogged.add(identifier);
}
}
@@ -289,7 +292,8 @@
mContext, suggestion);
if (mSuggestionsShownLogged.contains(suggestionId)) {
mMetricsFeatureProvider.action(
- mContext, MetricsEvent.ACTION_HIDE_SETTINGS_SUGGESTION, suggestionId);
+ mContext, MetricsEvent.ACTION_HIDE_SETTINGS_SUGGESTION, suggestionId,
+ getSuggestionTaggedData());
}
}
mSuggestionsShownLogged.clear();
@@ -325,8 +329,8 @@
mContext, suggestion);
if (!mSuggestionsShownLogged.contains(suggestionId)) {
mMetricsFeatureProvider.action(
- mContext, MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION,
- suggestionId);
+ mContext, MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION, suggestionId,
+ getSuggestionTaggedData());
mSuggestionsShownLogged.add(suggestionId);
}
}
@@ -507,6 +511,11 @@
parent.setVisibility(View.VISIBLE);
}
+ private Pair<Integer, Object>[] getSuggestionTaggedData() {
+ return SuggestionLogHelper.getSuggestionTaggedData(
+ mSuggestionFeatureProvider.isSmartSuggestionEnabled(mContext));
+ }
+
public static class IconCache {
private final Context mContext;
private final ArrayMap<Icon, Drawable> mMap = new ArrayMap<>();
diff --git a/src/com/android/settings/dashboard/suggestions/SuggestionAdapter.java b/src/com/android/settings/dashboard/suggestions/SuggestionAdapter.java
index 2c9da41..3815211 100644
--- a/src/com/android/settings/dashboard/suggestions/SuggestionAdapter.java
+++ b/src/com/android/settings/dashboard/suggestions/SuggestionAdapter.java
@@ -18,6 +18,7 @@
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
+import android.util.Pair;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -67,11 +68,12 @@
public void onBindViewHolder(DashboardItemHolder holder, int position) {
final Tile suggestion = (Tile) mSuggestions.get(position);
final String suggestionId = mSuggestionFeatureProvider.getSuggestionIdentifier(
- mContext, suggestion);
+ mContext, suggestion);
// This is for cases when a suggestion is dismissed and the next one comes to view
if (!mSuggestionsShownLogged.contains(suggestionId)) {
mMetricsFeatureProvider.action(
- mContext, MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION, suggestionId);
+ mContext, MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION, suggestionId,
+ getSuggestionTaggedData());
mSuggestionsShownLogged.add(suggestionId);
}
if (suggestion.remoteViews != null) {
@@ -102,9 +104,11 @@
// set the item view to disabled to remove any touch effects
holder.itemView.setEnabled(false);
}
+
clickHandler.setOnClickListener(v -> {
mMetricsFeatureProvider.action(mContext,
- MetricsEvent.ACTION_SETTINGS_SUGGESTION, suggestionId);
+ MetricsEvent.ACTION_SETTINGS_SUGGESTION, suggestionId,
+ getSuggestionTaggedData());
((SettingsActivity) mContext).startSuggestion(suggestion.intent);
});
}
@@ -129,7 +133,7 @@
public Tile getSuggestion(int position) {
final long itemId = getItemId(position);
- for (Tile tile: mSuggestions) {
+ for (Tile tile : mSuggestions) {
if (Objects.hash(tile.title) == itemId) {
return tile;
}
@@ -141,4 +145,10 @@
mSuggestions.remove(suggestion);
notifyDataSetChanged();
}
+
+ private Pair<Integer, Object>[] getSuggestionTaggedData() {
+ return SuggestionLogHelper.getSuggestionTaggedData(
+ mSuggestionFeatureProvider.isSmartSuggestionEnabled(mContext));
+ }
+
}
diff --git a/src/com/android/settings/dashboard/suggestions/SuggestionFeatureProviderImpl.java b/src/com/android/settings/dashboard/suggestions/SuggestionFeatureProviderImpl.java
index f8b5a8b..3d40d96 100644
--- a/src/com/android/settings/dashboard/suggestions/SuggestionFeatureProviderImpl.java
+++ b/src/com/android/settings/dashboard/suggestions/SuggestionFeatureProviderImpl.java
@@ -26,8 +26,9 @@
import android.support.annotation.NonNull;
import android.support.annotation.VisibleForTesting;
import android.util.Log;
+import android.util.Pair;
-import com.android.internal.logging.nano.MetricsProto;
+import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.Settings.AmbientDisplayPickupSuggestionActivity;
import com.android.settings.Settings.AmbientDisplaySuggestionActivity;
import com.android.settings.Settings.DoubleTapPowerSuggestionActivity;
@@ -45,6 +46,7 @@
import com.android.settingslib.drawer.Tile;
import com.android.settingslib.suggestions.SuggestionParser;
+import java.util.ArrayList;
import java.util.List;
public class SuggestionFeatureProviderImpl implements SuggestionFeatureProvider {
@@ -130,10 +132,13 @@
if (parser == null || suggestion == null || context == null) {
return;
}
- mMetricsFeatureProvider.action(
- context, MetricsProto.MetricsEvent.ACTION_SETTINGS_DISMISS_SUGGESTION,
- getSuggestionIdentifier(context, suggestion));
+ final Pair<Integer, Object>[] taggedData =
+ SuggestionLogHelper.getSuggestionTaggedData(isSmartSuggestionEnabled(context));
+ mMetricsFeatureProvider.action(
+ context, MetricsEvent.ACTION_SETTINGS_DISMISS_SUGGESTION,
+ getSuggestionIdentifier(context, suggestion),
+ taggedData);
if (!parser.dismissSuggestion(suggestion)) {
return;
}
diff --git a/src/com/android/settings/dashboard/suggestions/SuggestionLogHelper.java b/src/com/android/settings/dashboard/suggestions/SuggestionLogHelper.java
new file mode 100644
index 0000000..339392f
--- /dev/null
+++ b/src/com/android/settings/dashboard/suggestions/SuggestionLogHelper.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.settings.dashboard.suggestions;
+
+import android.util.Pair;
+
+import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
+
+public class SuggestionLogHelper {
+
+ public static Pair<Integer, Object>[] getSuggestionTaggedData(boolean enabled) {
+ return new Pair[]{
+ Pair.create(
+ MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, enabled ? 1 : 0)};
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/dashboard/DashboardAdapterTest.java b/tests/robotests/src/com/android/settings/dashboard/DashboardAdapterTest.java
index e00908e..4b345d0 100644
--- a/tests/robotests/src/com/android/settings/dashboard/DashboardAdapterTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/DashboardAdapterTest.java
@@ -37,6 +37,7 @@
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.util.DisplayMetrics;
+import android.util.Pair;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.RelativeLayout;
@@ -89,6 +90,8 @@
private ArgumentCaptor<Integer> mActionCategoryCaptor = ArgumentCaptor.forClass(Integer.class);
@Captor
private ArgumentCaptor<String> mActionPackageCaptor = ArgumentCaptor.forClass(String.class);
+ @Captor
+ private ArgumentCaptor<Pair> mTaggedDataCaptor = ArgumentCaptor.forClass(Pair.class);
private FakeFeatureFactory mFactory;
private DashboardAdapter mDashboardAdapter;
private DashboardAdapter.SuggestionAndConditionHeaderHolder mSuggestionHolder;
@@ -123,112 +126,143 @@
@Test
public void testSuggestionsLogs_NotExpanded() {
setupSuggestions(makeSuggestions("pkg1", "pkg2", "pkg3"));
+
verify(mFactory.metricsFeatureProvider, times(2)).action(
any(Context.class), mActionCategoryCaptor.capture(),
- mActionPackageCaptor.capture());
- String[] expectedPackages = new String[]{"pkg1", "pkg2"};
- Integer[] expectedActions = new Integer[]{
+ mActionPackageCaptor.capture(),
+ mTaggedDataCaptor.capture());
+ assertThat(mActionCategoryCaptor.getAllValues()).containsExactly(
MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION,
- MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION
- };
- assertThat(mActionCategoryCaptor.getAllValues().toArray()).isEqualTo(expectedActions);
- assertThat(mActionPackageCaptor.getAllValues().toArray()).isEqualTo(expectedPackages);
+ MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION);
+ assertThat(mActionPackageCaptor.getAllValues()).containsExactly("pkg1", "pkg2");
+ assertThat(mTaggedDataCaptor.getAllValues()).containsExactly(
+ Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0),
+ Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0));
}
@Test
public void testSuggestionsLogs_NotExpandedAndPaused() {
setupSuggestions(makeSuggestions("pkg1", "pkg2", "pkg3"));
+
mDashboardAdapter.onPause();
+
verify(mFactory.metricsFeatureProvider, times(4)).action(
any(Context.class), mActionCategoryCaptor.capture(),
- mActionPackageCaptor.capture());
- String[] expectedPackages = new String[]{"pkg1", "pkg2", "pkg1", "pkg2"};
- Integer[] expectedActions = new Integer[]{
+ mActionPackageCaptor.capture(),
+ mTaggedDataCaptor.capture());
+ assertThat(mActionCategoryCaptor.getAllValues()).containsExactly(
MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION,
MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION,
MetricsEvent.ACTION_HIDE_SETTINGS_SUGGESTION,
- MetricsEvent.ACTION_HIDE_SETTINGS_SUGGESTION};
- assertThat(mActionCategoryCaptor.getAllValues().toArray()).isEqualTo(expectedActions);
- assertThat(mActionPackageCaptor.getAllValues().toArray()).isEqualTo(expectedPackages);
+ MetricsEvent.ACTION_HIDE_SETTINGS_SUGGESTION);
+ assertThat(mActionPackageCaptor.getAllValues()).containsExactly(
+ "pkg1", "pkg2", "pkg1", "pkg2");
+ assertThat(mTaggedDataCaptor.getAllValues()).containsExactly(
+ Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0),
+ Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0),
+ Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0),
+ Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0));
}
@Test
public void testSuggestionsLogs_Expanded() {
setupSuggestions(makeSuggestions("pkg1", "pkg2", "pkg3"));
+
mDashboardAdapter.onBindSuggestionConditionHeader(mSuggestionHolder, mSuggestionHeaderData);
mSuggestionHolder.itemView.callOnClick();
+
verify(mFactory.metricsFeatureProvider, times(3)).action(
any(Context.class), mActionCategoryCaptor.capture(),
- mActionPackageCaptor.capture());
- String[] expectedPackages = new String[]{"pkg1", "pkg2", "pkg3"};
- Integer[] expectedActions = new Integer[]{
+ mActionPackageCaptor.capture(),
+ mTaggedDataCaptor.capture());
+ assertThat(mActionCategoryCaptor.getAllValues()).containsExactly(
MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION,
MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION,
- MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION
- };
- assertThat(mActionPackageCaptor.getAllValues().toArray()).isEqualTo(expectedPackages);
- assertThat(mActionCategoryCaptor.getAllValues().toArray()).isEqualTo(expectedActions);
+ MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION);
+ assertThat(mActionPackageCaptor.getAllValues()).containsExactly(
+ "pkg1", "pkg2", "pkg3");
+ assertThat(mTaggedDataCaptor.getAllValues()).containsExactly(
+ Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0),
+ Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0),
+ Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0));
}
@Test
public void testSuggestionsLogs_ExpandedAndPaused() {
setupSuggestions(makeSuggestions("pkg1", "pkg2", "pkg3"));
+
mDashboardAdapter.onBindSuggestionConditionHeader(mSuggestionHolder, mSuggestionHeaderData);
mSuggestionHolder.itemView.callOnClick();
mDashboardAdapter.onPause();
+
verify(mFactory.metricsFeatureProvider, times(6)).action(
any(Context.class), mActionCategoryCaptor.capture(),
- mActionPackageCaptor.capture());
- String[] expectedPackages = new String[]{"pkg1", "pkg2", "pkg3", "pkg1", "pkg2", "pkg3"};
- Integer[] expectedActions = new Integer[]{
+ mActionPackageCaptor.capture(),
+ mTaggedDataCaptor.capture());
+ assertThat(mActionCategoryCaptor.getAllValues()).containsExactly(
MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION,
MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION,
MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION,
MetricsEvent.ACTION_HIDE_SETTINGS_SUGGESTION,
MetricsEvent.ACTION_HIDE_SETTINGS_SUGGESTION,
- MetricsEvent.ACTION_HIDE_SETTINGS_SUGGESTION
- };
- assertThat(mActionPackageCaptor.getAllValues().toArray()).isEqualTo(expectedPackages);
- assertThat(mActionCategoryCaptor.getAllValues().toArray()).isEqualTo(expectedActions);
+ MetricsEvent.ACTION_HIDE_SETTINGS_SUGGESTION);
+ assertThat(mActionPackageCaptor.getAllValues()).containsExactly(
+ "pkg1", "pkg2", "pkg3", "pkg1", "pkg2", "pkg3");
+ assertThat(mTaggedDataCaptor.getAllValues()).containsExactly(
+ Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0),
+ Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0),
+ Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0),
+ Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0),
+ Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0),
+ Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0));
}
@Test
public void testSuggestionsLogs_ExpandedAfterPause() {
setupSuggestions(makeSuggestions("pkg1", "pkg2", "pkg3"));
+
mDashboardAdapter.onPause();
mDashboardAdapter.onBindSuggestionConditionHeader(mSuggestionHolder, mSuggestionHeaderData);
mSuggestionHolder.itemView.callOnClick();
+
verify(mFactory.metricsFeatureProvider, times(7)).action(
any(Context.class), mActionCategoryCaptor.capture(),
- mActionPackageCaptor.capture());
- String[] expectedPackages = new String[]{
- "pkg1", "pkg2", "pkg1", "pkg2", "pkg1", "pkg2", "pkg3"};
- Integer[] expectedActions = new Integer[]{
+ mActionPackageCaptor.capture(),
+ mTaggedDataCaptor.capture());
+ assertThat(mActionCategoryCaptor.getAllValues()).containsExactly(
MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION,
MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION,
MetricsEvent.ACTION_HIDE_SETTINGS_SUGGESTION,
MetricsEvent.ACTION_HIDE_SETTINGS_SUGGESTION,
MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION,
MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION,
- MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION
- };
- assertThat(mActionPackageCaptor.getAllValues().toArray()).isEqualTo(expectedPackages);
- assertThat(mActionCategoryCaptor.getAllValues().toArray()).isEqualTo(expectedActions);
+ MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION);
+ assertThat(mActionPackageCaptor.getAllValues()).containsExactly(
+ "pkg1", "pkg2", "pkg1", "pkg2", "pkg1", "pkg2", "pkg3");
+ assertThat(mTaggedDataCaptor.getAllValues()).containsExactly(
+ Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0),
+ Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0),
+ Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0),
+ Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0),
+ Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0),
+ Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0),
+ Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0));
}
@Test
public void testSuggestionsLogs_ExpandedAfterPauseAndPausedAgain() {
setupSuggestions(makeSuggestions("pkg1", "pkg2", "pkg3"));
+
mDashboardAdapter.onPause();
mDashboardAdapter.onBindSuggestionConditionHeader(mSuggestionHolder, mSuggestionHeaderData);
mSuggestionHolder.itemView.callOnClick();
mDashboardAdapter.onPause();
+
verify(mFactory.metricsFeatureProvider, times(10)).action(
any(Context.class), mActionCategoryCaptor.capture(),
- mActionPackageCaptor.capture());
- String[] expectedPackages = new String[]{
- "pkg1", "pkg2", "pkg1", "pkg2", "pkg1", "pkg2", "pkg3", "pkg1", "pkg2", "pkg3"};
- Integer[] expectedActions = new Integer[]{
+ mActionPackageCaptor.capture(),
+ mTaggedDataCaptor.capture());
+ assertThat(mActionCategoryCaptor.getAllValues()).containsExactly(
MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION,
MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION,
MetricsEvent.ACTION_HIDE_SETTINGS_SUGGESTION,
@@ -238,63 +272,82 @@
MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION,
MetricsEvent.ACTION_HIDE_SETTINGS_SUGGESTION,
MetricsEvent.ACTION_HIDE_SETTINGS_SUGGESTION,
- MetricsEvent.ACTION_HIDE_SETTINGS_SUGGESTION
- };
- assertThat(mActionPackageCaptor.getAllValues().toArray()).isEqualTo(expectedPackages);
- assertThat(mActionCategoryCaptor.getAllValues().toArray()).isEqualTo(expectedActions);
+ MetricsEvent.ACTION_HIDE_SETTINGS_SUGGESTION);
+ assertThat(mActionPackageCaptor.getAllValues()).containsExactly(
+ "pkg1", "pkg2", "pkg1", "pkg2", "pkg1", "pkg2", "pkg3", "pkg1", "pkg2", "pkg3");
+ assertThat(mTaggedDataCaptor.getAllValues()).containsExactly(
+ Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0),
+ Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0),
+ Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0),
+ Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0),
+ Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0),
+ Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0),
+ Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0),
+ Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0),
+ Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0),
+ Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0));
}
@Test
public void testSuggestionsLogs_ExpandedWithLessThanDefaultShown() {
setupSuggestions(makeSuggestions("pkg1"));
+
mDashboardAdapter.onBindSuggestionConditionHeader(mSuggestionHolder, mSuggestionHeaderData);
mSuggestionHolder.itemView.callOnClick();
+
verify(mFactory.metricsFeatureProvider, times(1)).action(
any(Context.class), mActionCategoryCaptor.capture(),
- mActionPackageCaptor.capture());
- String[] expectedPackages = new String[]{"pkg1"};
- Integer[] expectedActions = new Integer[]{
- MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION,
- };
- assertThat(mActionPackageCaptor.getAllValues().toArray()).isEqualTo(expectedPackages);
- assertThat(mActionCategoryCaptor.getAllValues().toArray()).isEqualTo(expectedActions);
+ mActionPackageCaptor.capture(),
+ mTaggedDataCaptor.capture());
+ assertThat(mActionCategoryCaptor.getAllValues()).containsExactly(
+ MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION);
+ assertThat(mActionPackageCaptor.getAllValues()).containsExactly("pkg1");
+ assertThat(mTaggedDataCaptor.getAllValues()).containsExactly(
+ Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0));
}
@Test
public void testSuggestionsLogs_ExpandedWithLessThanDefaultShownAndPaused() {
setupSuggestions(makeSuggestions("pkg1"));
+
mDashboardAdapter.onBindSuggestionConditionHeader(mSuggestionHolder, mSuggestionHeaderData);
mSuggestionHolder.itemView.callOnClick();
mDashboardAdapter.onPause();
+
verify(mFactory.metricsFeatureProvider, times(2)).action(
any(Context.class), mActionCategoryCaptor.capture(),
- mActionPackageCaptor.capture());
- String[] expectedPackages = new String[]{"pkg1", "pkg1"};
- Integer[] expectedActions = new Integer[]{
+ mActionPackageCaptor.capture(),
+ mTaggedDataCaptor.capture());
+ assertThat(mActionCategoryCaptor.getAllValues()).containsExactly(
MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION,
- MetricsEvent.ACTION_HIDE_SETTINGS_SUGGESTION
- };
- assertThat(mActionPackageCaptor.getAllValues().toArray()).isEqualTo(expectedPackages);
- assertThat(mActionCategoryCaptor.getAllValues().toArray()).isEqualTo(expectedActions);
+ MetricsEvent.ACTION_HIDE_SETTINGS_SUGGESTION);
+ assertThat(mActionPackageCaptor.getAllValues()).containsExactly("pkg1", "pkg1");
+ assertThat(mTaggedDataCaptor.getAllValues()).containsExactly(
+ Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0),
+ Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0));
}
@Test
public void testSuggestionsLogs_ExpandedWithLessThanDefaultShownAfterPause() {
setupSuggestions(makeSuggestions("pkg1"));
+
mDashboardAdapter.onPause();
mDashboardAdapter.onBindSuggestionConditionHeader(mSuggestionHolder, mSuggestionHeaderData);
mSuggestionHolder.itemView.callOnClick();
+
verify(mFactory.metricsFeatureProvider, times(3)).action(
any(Context.class), mActionCategoryCaptor.capture(),
- mActionPackageCaptor.capture());
- String[] expectedPackages = new String[]{"pkg1", "pkg1", "pkg1"};
- Integer[] expectedActions = new Integer[]{
+ mActionPackageCaptor.capture(),
+ mTaggedDataCaptor.capture());
+ assertThat(mActionCategoryCaptor.getAllValues()).containsExactly(
MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION,
MetricsEvent.ACTION_HIDE_SETTINGS_SUGGESTION,
- MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION
- };
- assertThat(mActionPackageCaptor.getAllValues().toArray()).isEqualTo(expectedPackages);
- assertThat(mActionCategoryCaptor.getAllValues().toArray()).isEqualTo(expectedActions);
+ MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION);
+ assertThat(mActionPackageCaptor.getAllValues()).containsExactly("pkg1", "pkg1", "pkg1");
+ assertThat(mTaggedDataCaptor.getAllValues()).containsExactly(
+ Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0),
+ Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0),
+ Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0));
}
@Test
@@ -304,18 +357,46 @@
mDashboardAdapter.onBindSuggestionConditionHeader(mSuggestionHolder, mSuggestionHeaderData);
mSuggestionHolder.itemView.callOnClick();
mDashboardAdapter.onPause();
+
verify(mFactory.metricsFeatureProvider, times(4)).action(
any(Context.class), mActionCategoryCaptor.capture(),
- mActionPackageCaptor.capture());
- String[] expectedPackages = new String[]{"pkg1", "pkg1", "pkg1", "pkg1"};
- Integer[] expectedActions = new Integer[]{
+ mActionPackageCaptor.capture(),
+ mTaggedDataCaptor.capture());
+ assertThat(mActionCategoryCaptor.getAllValues()).containsExactly(
MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION,
MetricsEvent.ACTION_HIDE_SETTINGS_SUGGESTION,
MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION,
- MetricsEvent.ACTION_HIDE_SETTINGS_SUGGESTION
- };
- assertThat(mActionPackageCaptor.getAllValues().toArray()).isEqualTo(expectedPackages);
- assertThat(mActionCategoryCaptor.getAllValues().toArray()).isEqualTo(expectedActions);
+ MetricsEvent.ACTION_HIDE_SETTINGS_SUGGESTION);
+ assertThat(mActionPackageCaptor.getAllValues()).containsExactly(
+ "pkg1", "pkg1", "pkg1", "pkg1");
+ assertThat(mTaggedDataCaptor.getAllValues()).containsExactly(
+ Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0),
+ Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0),
+ Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0),
+ Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0));
+ }
+
+ @Test
+ public void testSuggestionsLogs_SmartSuggestionEnabled() {
+ when(mFactory.suggestionsFeatureProvider
+ .isSmartSuggestionEnabled(any(Context.class))).thenReturn(true);
+ setupSuggestions(makeSuggestions("pkg1"));
+
+ mDashboardAdapter.onBindSuggestionConditionHeader(mSuggestionHolder, mSuggestionHeaderData);
+ mSuggestionHolder.itemView.callOnClick();
+ mDashboardAdapter.onPause();
+
+ verify(mFactory.metricsFeatureProvider, times(2)).action(
+ any(Context.class), mActionCategoryCaptor.capture(),
+ mActionPackageCaptor.capture(),
+ mTaggedDataCaptor.capture());
+ assertThat(mActionCategoryCaptor.getAllValues()).containsExactly(
+ MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION,
+ MetricsEvent.ACTION_HIDE_SETTINGS_SUGGESTION);
+ assertThat(mActionPackageCaptor.getAllValues()).containsExactly("pkg1", "pkg1");
+ assertThat(mTaggedDataCaptor.getAllValues()).containsExactly(
+ Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 1),
+ Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 1));
}
@Test
diff --git a/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionFeatureProviderImplTest.java
index 45d04a4..c343f97 100644
--- a/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionFeatureProviderImplTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionFeatureProviderImplTest.java
@@ -35,7 +35,9 @@
import android.content.pm.PackageManager;
import android.hardware.fingerprint.FingerprintManager;
import android.provider.Settings.Secure;
+import android.util.Pair;
+import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
import com.android.settings.Settings.AmbientDisplayPickupSuggestionActivity;
@@ -60,6 +62,8 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
@@ -93,6 +97,8 @@
private FingerprintManager mFingerprintManager;
@Mock
private SharedPreferences mSharedPreferences;
+ @Captor
+ private ArgumentCaptor<Pair> mTaggedDataCaptor = ArgumentCaptor.forClass(Pair.class);
private FakeFeatureFactory mFactory;
private SuggestionFeatureProviderImpl mProvider;
@@ -335,7 +341,10 @@
verify(mFactory.metricsFeatureProvider).action(
eq(mContext),
eq(MetricsProto.MetricsEvent.ACTION_SETTINGS_DISMISS_SUGGESTION),
- anyString());
+ anyString(),
+ mTaggedDataCaptor.capture());
+ assertThat(mTaggedDataCaptor.getAllValues()).containsExactly(
+ Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0));
verify(mContext, never()).getPackageManager();
}
@@ -356,8 +365,10 @@
verify(mFactory.metricsFeatureProvider).action(
eq(mContext),
eq(MetricsProto.MetricsEvent.ACTION_SETTINGS_DISMISS_SUGGESTION),
- anyString());
-
+ anyString(),
+ mTaggedDataCaptor.capture());
+ assertThat(mTaggedDataCaptor.getAllValues()).containsExactly(
+ Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0));
verify(mContext.getPackageManager())
.setComponentEnabledSetting(mSuggestion.intent.getComponent(),
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
diff --git a/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionLogHelperTest.java b/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionLogHelperTest.java
new file mode 100644
index 0000000..8eb4273
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionLogHelperTest.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.dashboard.suggestions;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.util.Pair;
+
+import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
+
+import org.junit.Test;
+
+public class SuggestionLogHelperTest {
+
+ @Test
+ public void testGetSmartSuggestionEnabledTaggedData_disabled() {
+ assertThat(SuggestionLogHelper.getSuggestionTaggedData(false)).asList().containsExactly(
+ Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0));
+ }
+
+ @Test
+ public void testGetSmartSuggestionEnabledTaggedData_enabled() {
+ assertThat(SuggestionLogHelper.getSuggestionTaggedData(true)).asList().containsExactly(
+ Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 1));
+ }
+}
+