OSDN Git Service

Remove default app duplicates in search
authorMatthew Fritze <mfritze@google.com>
Thu, 11 May 2017 17:39:12 +0000 (10:39 -0700)
committerMatthew Fritze <mfritze@google.com>
Fri, 12 May 2017 01:01:49 +0000 (18:01 -0700)
Default Work Browser and Phone app search results look
identical to the regular defaults. Supress the results
until we differentiate work results.

"Assist and voice input" duplicate is a parent-child
duplication and is removed, as well.

Bug: 36101902
Test: make RunSettingsRoboTests
Change-Id: I3bb75c199cd76e24de42548dd166c4bccd0c7f0a

src/com/android/settings/applications/AdvancedAppSettings.java
src/com/android/settings/search/BaseSearchIndexProvider.java
tests/robotests/src/com/android/settings/applications/AdvancedAppSettingsTest.java

index caa9da1..cce8b7d 100644 (file)
@@ -43,6 +43,8 @@ public class AdvancedAppSettings extends DashboardFragment {
 
     static final String TAG = "AdvancedAppSettings";
 
+    private static final String KEY_ASSIST_VOICE_INPUT = "assist_and_voice_input";
+
     @Override
     protected String getLogTag() {
         return TAG;
@@ -80,6 +82,18 @@ public class AdvancedAppSettings extends DashboardFragment {
                     sir.xmlResId = R.xml.app_default_settings;
                     return Arrays.asList(sir);
                 }
+
+                @Override
+                public List<String> getNonIndexableKeys(Context context) {
+                    List<String> keys = super.getNonIndexableKeys(context);
+                    keys.add(KEY_ASSIST_VOICE_INPUT);
+                    // TODO (b/38230148) Remove these keys when we can differentiate work results
+                    keys.add((new DefaultWorkPhonePreferenceController(context))
+                            .getPreferenceKey());
+                    keys.add((new DefaultWorkBrowserPreferenceController(context))
+                            .getPreferenceKey());
+                    return keys;
+                }
             };
 
     static class SummaryProvider implements SummaryLoader.SummaryProvider {
index 8732227..f5e06ca 100644 (file)
@@ -72,7 +72,7 @@ public class BaseSearchIndexProvider implements Indexable.SearchIndexProvider {
             }
             return nonIndexableKeys;
         } else {
-            return EMPTY_LIST;
+            return new ArrayList<>();
         }
     }
 
index bedb0a5..0c3c160 100644 (file)
@@ -26,6 +26,7 @@ import com.android.settings.applications.defaultapps.DefaultBrowserPreferenceCon
 import com.android.settings.applications.defaultapps.DefaultPhonePreferenceController;
 import com.android.settings.applications.defaultapps.DefaultSmsPreferenceController;
 import com.android.settings.dashboard.SummaryLoader;
+import com.android.settings.testutils.XmlTestUtils;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -34,11 +35,14 @@ import org.robolectric.RuntimeEnvironment;
 import org.robolectric.annotation.Config;
 import org.robolectric.util.ReflectionHelpers;
 
+import java.util.List;
+
 import static com.google.common.truth.Truth.assertThat;
 import static org.mockito.Matchers.anyString;
 import static org.mockito.Matchers.eq;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
@@ -136,4 +140,16 @@ public class AdvancedAppSettingsTest {
 
     }
 
+
+    @Test
+    public void testNonIndexableKeys_existInXmlLayout() {
+        final Context context = spy(RuntimeEnvironment.application);
+        final List<String> niks = AdvancedAppSettings.SEARCH_INDEX_DATA_PROVIDER
+                .getNonIndexableKeys(context);
+        final int xmlId = (new AdvancedAppSettings()).getPreferenceScreenResId();
+
+        final List<String> keys = XmlTestUtils.getKeysFromPreferenceXml(context, xmlId);
+
+        assertThat(keys).containsAllIn(niks);
+    }
 }