From c54002e192d0d57c9f3154151afbe025944f02f4 Mon Sep 17 00:00:00 2001 From: Yanting Yang Date: Thu, 26 Mar 2020 18:22:23 +0800 Subject: [PATCH] Add custom site map pairs into SettingsSearchIndexablesProvider Settings Search need Settings to provide custom site map pairs to build up full breadcrumb for the search results from ScreenLockSettings, WallpaperSuggestionActivity and WifiSettings2. Bug: 147851992 Bug: 151206664 Test: manual test with Settings Search, robotests Change-Id: Ide6e69b3336af255a388737d46147f2fc2ef9790 --- .../search/CustomSiteMapRegistry.java | 48 +++++++++++++++++ .../SettingsSearchIndexablesProvider.java | 8 +++ .../search/CustomSiteMapRegistryTest.java | 53 +++++++++++++++++++ 3 files changed, 109 insertions(+) create mode 100644 src/com/android/settings/search/CustomSiteMapRegistry.java create mode 100644 tests/robotests/src/com/android/settings/search/CustomSiteMapRegistryTest.java diff --git a/src/com/android/settings/search/CustomSiteMapRegistry.java b/src/com/android/settings/search/CustomSiteMapRegistry.java new file mode 100644 index 00000000000..300cf17211d --- /dev/null +++ b/src/com/android/settings/search/CustomSiteMapRegistry.java @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2020 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.search; + +import android.util.ArrayMap; + +import com.android.settings.DisplaySettings; +import com.android.settings.network.NetworkDashboardFragment; +import com.android.settings.security.SecuritySettings; +import com.android.settings.security.screenlock.ScreenLockSettings; +import com.android.settings.wallpaper.WallpaperSuggestionActivity; +import com.android.settings.wifi.WifiSettings2; + +import java.util.Map; + +/** + * A registry of custom site map. + */ +public class CustomSiteMapRegistry { + + /** + * Map from child class to parent class. + */ + public static final Map CUSTOM_SITE_MAP; + + static { + CUSTOM_SITE_MAP = new ArrayMap<>(); + CUSTOM_SITE_MAP.put(ScreenLockSettings.class.getName(), SecuritySettings.class.getName()); + CUSTOM_SITE_MAP.put( + WallpaperSuggestionActivity.class.getName(), DisplaySettings.class.getName()); + CUSTOM_SITE_MAP.put( + WifiSettings2.class.getName(), NetworkDashboardFragment.class.getName()); + } +} diff --git a/src/com/android/settings/search/SettingsSearchIndexablesProvider.java b/src/com/android/settings/search/SettingsSearchIndexablesProvider.java index bb3c76264e9..736a27016fb 100644 --- a/src/com/android/settings/search/SettingsSearchIndexablesProvider.java +++ b/src/com/android/settings/search/SettingsSearchIndexablesProvider.java @@ -211,6 +211,14 @@ public class SettingsSearchIndexablesProvider extends SearchIndexablesProvider { .add(SearchIndexablesContract.SiteMapColumns.CHILD_TITLE, childTitle); } } + + // Loop through custom site map registry to build additional SiteMapPairs + for (String childClass : CustomSiteMapRegistry.CUSTOM_SITE_MAP.keySet()) { + final String parentClass = CustomSiteMapRegistry.CUSTOM_SITE_MAP.get(childClass); + cursor.newRow() + .add(SearchIndexablesContract.SiteMapColumns.PARENT_CLASS, parentClass) + .add(SearchIndexablesContract.SiteMapColumns.CHILD_CLASS, childClass); + } // Done. return cursor; } diff --git a/tests/robotests/src/com/android/settings/search/CustomSiteMapRegistryTest.java b/tests/robotests/src/com/android/settings/search/CustomSiteMapRegistryTest.java new file mode 100644 index 00000000000..5bd4538dfa5 --- /dev/null +++ b/tests/robotests/src/com/android/settings/search/CustomSiteMapRegistryTest.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2020 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.search; + +import static com.google.common.truth.Truth.assertThat; + +import com.android.settings.DisplaySettings; +import com.android.settings.network.NetworkDashboardFragment; +import com.android.settings.security.SecuritySettings; +import com.android.settings.security.screenlock.ScreenLockSettings; +import com.android.settings.wallpaper.WallpaperSuggestionActivity; +import com.android.settings.wifi.WifiSettings2; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.RobolectricTestRunner; + +@RunWith(RobolectricTestRunner.class) +public class CustomSiteMapRegistryTest { + + @Test + public void shouldContainScreenLockSettingsPairs() { + assertThat(CustomSiteMapRegistry.CUSTOM_SITE_MAP.get(ScreenLockSettings.class.getName())) + .isEqualTo(SecuritySettings.class.getName()); + } + + @Test + public void shouldContainWallpaperSuggestionActivityPairs() { + assertThat(CustomSiteMapRegistry.CUSTOM_SITE_MAP.get( + WallpaperSuggestionActivity.class.getName())) + .isEqualTo(DisplaySettings.class.getName()); + } + + @Test + public void shouldContainWifiSettings2Pairs() { + assertThat(CustomSiteMapRegistry.CUSTOM_SITE_MAP.get(WifiSettings2.class.getName())) + .isEqualTo(NetworkDashboardFragment.class.getName()); + } +}