1 /*
2  * Copyright (C) 2014 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.settings.search;
18 
19 import android.provider.SearchIndexableResource;
20 import android.support.annotation.DrawableRes;
21 import android.support.annotation.VisibleForTesting;
22 import android.support.annotation.XmlRes;
23 
24 import com.android.settings.DateTimeSettings;
25 import com.android.settings.DeviceInfoSettings;
26 import com.android.settings.DisplaySettings;
27 import com.android.settings.EncryptionAndCredential;
28 import com.android.settings.LegalSettings;
29 import com.android.settings.R;
30 import com.android.settings.ScreenPinningSettings;
31 import com.android.settings.SecuritySettings;
32 import com.android.settings.accessibility.AccessibilitySettings;
33 import com.android.settings.accessibility.AccessibilityShortcutPreferenceFragment;
34 import com.android.settings.accessibility.MagnificationPreferenceFragment;
35 import com.android.settings.accounts.UserAndAccountDashboardFragment;
36 import com.android.settings.applications.AdvancedAppSettings;
37 import com.android.settings.applications.AppAndNotificationDashboardFragment;
38 import com.android.settings.applications.SpecialAccessSettings;
39 import com.android.settings.applications.assist.ManageAssist;
40 import com.android.settings.backup.BackupSettingsActivity;
41 import com.android.settings.backup.BackupSettingsFragment;
42 import com.android.settings.bluetooth.BluetoothSettings;
43 import com.android.settings.connecteddevice.ConnectedDeviceDashboardFragment;
44 import com.android.settings.datausage.DataUsageMeteredSettings;
45 import com.android.settings.datausage.DataUsageSummary;
46 import com.android.settings.development.DevelopmentSettings;
47 import com.android.settings.deviceinfo.StorageDashboardFragment;
48 import com.android.settings.deviceinfo.StorageSettings;
49 import com.android.settings.display.ScreenZoomSettings;
50 import com.android.settings.enterprise.EnterprisePrivacySettings;
51 import com.android.settings.fuelgauge.BatterySaverSettings;
52 import com.android.settings.fuelgauge.PowerUsageAdvanced;
53 import com.android.settings.fuelgauge.PowerUsageSummary;
54 import com.android.settings.gestures.AssistGestureSettings;
55 import com.android.settings.gestures.DoubleTapPowerSettings;
56 import com.android.settings.gestures.DoubleTapScreenSettings;
57 import com.android.settings.gestures.DoubleTwistGestureSettings;
58 import com.android.settings.gestures.PickupGestureSettings;
59 import com.android.settings.gestures.SwipeToNotificationSettings;
60 import com.android.settings.inputmethod.AvailableVirtualKeyboardFragment;
61 import com.android.settings.inputmethod.PhysicalKeyboardFragment;
62 import com.android.settings.inputmethod.VirtualKeyboardFragment;
63 import com.android.settings.language.LanguageAndInputSettings;
64 import com.android.settings.location.LocationSettings;
65 import com.android.settings.location.ScanningSettings;
66 import com.android.settings.network.NetworkDashboardFragment;
67 import com.android.settings.nfc.PaymentSettings;
68 import com.android.settings.notification.ChannelImportanceSettings;
69 import com.android.settings.notification.ConfigureNotificationSettings;
70 import com.android.settings.notification.SoundSettings;
71 import com.android.settings.notification.ZenModePrioritySettings;
72 import com.android.settings.notification.ZenModeSettings;
73 import com.android.settings.notification.ZenModeVisualInterruptionSettings;
74 import com.android.settings.print.PrintSettingsFragment;
75 import com.android.settings.security.LockscreenDashboardFragment;
76 import com.android.settings.sim.SimSettings;
77 import com.android.settings.system.ResetDashboardFragment;
78 import com.android.settings.system.SystemDashboardFragment;
79 import com.android.settings.tts.TtsEnginePreferenceFragment;
80 import com.android.settings.users.UserSettings;
81 import com.android.settings.wallpaper.WallpaperTypeSettings;
82 import com.android.settings.wifi.ConfigureWifiSettings;
83 import com.android.settings.wifi.SavedAccessPointsWifiSettings;
84 import com.android.settings.wifi.WifiSettings;
85 
86 import java.util.Collection;
87 import java.util.HashMap;
88 
89 public final class SearchIndexableResources {
90 
91     @XmlRes
92     public static final int NO_DATA_RES_ID = 0;
93 
94     @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
95     static final HashMap<String, SearchIndexableResource> sResMap = new HashMap<>();
96 
97     @VisibleForTesting
addIndex(Class<?> indexClass, @XmlRes int xmlResId, @DrawableRes int iconResId)98     static void addIndex(Class<?> indexClass, @XmlRes int xmlResId,
99             @DrawableRes int iconResId) {
100         String className = indexClass.getName();
101         sResMap.put(className, new SearchIndexableResource(0, xmlResId, className, iconResId));
102     }
103 
104     static {
addIndex(WifiSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_wireless)105         addIndex(WifiSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_wireless);
addIndex(NetworkDashboardFragment.class, NO_DATA_RES_ID, R.drawable.ic_settings_wireless)106         addIndex(NetworkDashboardFragment.class, NO_DATA_RES_ID, R.drawable.ic_settings_wireless);
addIndex(ConfigureWifiSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_wireless)107         addIndex(ConfigureWifiSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_wireless);
addIndex(SavedAccessPointsWifiSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_wireless)108         addIndex(SavedAccessPointsWifiSettings.class, NO_DATA_RES_ID,
109                 R.drawable.ic_settings_wireless);
addIndex(BluetoothSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_bluetooth)110         addIndex(BluetoothSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_bluetooth);
addIndex(SimSettings.class, NO_DATA_RES_ID, R.drawable.ic_sim_sd)111         addIndex(SimSettings.class, NO_DATA_RES_ID, R.drawable.ic_sim_sd);
addIndex(DataUsageSummary.class, NO_DATA_RES_ID, R.drawable.ic_settings_data_usage)112         addIndex(DataUsageSummary.class, NO_DATA_RES_ID, R.drawable.ic_settings_data_usage);
addIndex(DataUsageMeteredSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_data_usage)113         addIndex(DataUsageMeteredSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_data_usage);
addIndex(ScreenZoomSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_display)114         addIndex(ScreenZoomSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_display);
addIndex(DisplaySettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_display)115         addIndex(DisplaySettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_display);
addIndex(WallpaperTypeSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_display)116         addIndex(WallpaperTypeSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_display);
addIndex(ConfigureNotificationSettings.class, R.xml.configure_notification_settings, R.drawable.ic_settings_notifications)117         addIndex(ConfigureNotificationSettings.class,
118                 R.xml.configure_notification_settings, R.drawable.ic_settings_notifications);
addIndex(AppAndNotificationDashboardFragment.class, NO_DATA_RES_ID, R.drawable.ic_settings_applications)119         addIndex(AppAndNotificationDashboardFragment.class, NO_DATA_RES_ID,
120                 R.drawable.ic_settings_applications);
addIndex(SoundSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_sound)121         addIndex(SoundSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_sound);
addIndex(ZenModeSettings.class, R.xml.zen_mode_settings, R.drawable.ic_settings_notifications)122         addIndex(ZenModeSettings.class,
123                 R.xml.zen_mode_settings, R.drawable.ic_settings_notifications);
addIndex(ZenModePrioritySettings.class, R.xml.zen_mode_priority_settings, R.drawable.ic_settings_notifications)124         addIndex(ZenModePrioritySettings.class,
125                 R.xml.zen_mode_priority_settings, R.drawable.ic_settings_notifications);
addIndex(StorageSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_storage)126         addIndex(StorageSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_storage);
addIndex(PowerUsageSummary.class, R.xml.power_usage_summary, R.drawable.ic_settings_battery)127         addIndex(PowerUsageSummary.class,
128                 R.xml.power_usage_summary, R.drawable.ic_settings_battery);
addIndex(PowerUsageAdvanced.class, NO_DATA_RES_ID, R.drawable.ic_settings_battery)129         addIndex(PowerUsageAdvanced.class, NO_DATA_RES_ID, R.drawable.ic_settings_battery);
addIndex(BatterySaverSettings.class, R.xml.battery_saver_settings, R.drawable.ic_settings_battery)130         addIndex(BatterySaverSettings.class,
131                 R.xml.battery_saver_settings, R.drawable.ic_settings_battery);
addIndex(AdvancedAppSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_applications)132         addIndex(AdvancedAppSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_applications);
addIndex(ManageAssist.class, NO_DATA_RES_ID, R.drawable.ic_settings_applications)133         addIndex(ManageAssist.class, NO_DATA_RES_ID, R.drawable.ic_settings_applications);
addIndex(SpecialAccessSettings.class, R.xml.special_access, R.drawable.ic_settings_applications)134         addIndex(SpecialAccessSettings.class,
135                 R.xml.special_access, R.drawable.ic_settings_applications);
addIndex(UserSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_multiuser)136         addIndex(UserSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_multiuser);
addIndex(AssistGestureSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_gestures)137         addIndex(AssistGestureSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_gestures);
addIndex(PickupGestureSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_gestures)138         addIndex(PickupGestureSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_gestures);
addIndex(DoubleTapScreenSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_gestures)139         addIndex(DoubleTapScreenSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_gestures);
addIndex(DoubleTapPowerSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_gestures)140         addIndex(DoubleTapPowerSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_gestures);
addIndex(DoubleTwistGestureSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_gestures)141         addIndex(DoubleTwistGestureSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_gestures);
addIndex(SwipeToNotificationSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_gestures)142         addIndex(SwipeToNotificationSettings.class, NO_DATA_RES_ID,
143                 R.drawable.ic_settings_gestures);
addIndex(LanguageAndInputSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_language)144         addIndex(LanguageAndInputSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_language);
addIndex(LocationSettings.class, R.xml.location_settings, R.drawable.ic_settings_location)145         addIndex(LocationSettings.class, R.xml.location_settings, R.drawable.ic_settings_location);
addIndex(ScanningSettings.class, R.xml.location_scanning, R.drawable.ic_settings_location)146         addIndex(ScanningSettings.class, R.xml.location_scanning, R.drawable.ic_settings_location);
addIndex(SecuritySettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_security)147         addIndex(SecuritySettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_security);
addIndex(EncryptionAndCredential.class, R.xml.encryption_and_credential, R.drawable.ic_settings_security)148         addIndex(EncryptionAndCredential.class, R.xml.encryption_and_credential,
149                 R.drawable.ic_settings_security);
addIndex(ScreenPinningSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_security)150         addIndex(ScreenPinningSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_security);
addIndex(UserAndAccountDashboardFragment.class, NO_DATA_RES_ID, R.drawable.ic_settings_accounts)151         addIndex(UserAndAccountDashboardFragment.class, NO_DATA_RES_ID,
152                 R.drawable.ic_settings_accounts);
addIndex(VirtualKeyboardFragment.class, NO_DATA_RES_ID, R.drawable.ic_settings_language)153         addIndex(VirtualKeyboardFragment.class, NO_DATA_RES_ID, R.drawable.ic_settings_language);
addIndex(AvailableVirtualKeyboardFragment.class, NO_DATA_RES_ID, R.drawable.ic_settings_language)154         addIndex(AvailableVirtualKeyboardFragment.class,
155                 NO_DATA_RES_ID, R.drawable.ic_settings_language);
addIndex(PhysicalKeyboardFragment.class, NO_DATA_RES_ID, R.drawable.ic_settings_language)156         addIndex(PhysicalKeyboardFragment.class, NO_DATA_RES_ID, R.drawable.ic_settings_language);
addIndex(BackupSettingsActivity.class, NO_DATA_RES_ID, R.drawable.ic_settings_backup)157         addIndex(BackupSettingsActivity.class, NO_DATA_RES_ID, R.drawable.ic_settings_backup);
addIndex(BackupSettingsFragment.class, NO_DATA_RES_ID, R.drawable.ic_settings_backup)158         addIndex(BackupSettingsFragment.class, NO_DATA_RES_ID, R.drawable.ic_settings_backup);
addIndex(DateTimeSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_date_time)159         addIndex(DateTimeSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_date_time);
addIndex(AccessibilitySettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_accessibility)160         addIndex(AccessibilitySettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_accessibility);
addIndex(PrintSettingsFragment.class, NO_DATA_RES_ID, R.drawable.ic_settings_print)161         addIndex(PrintSettingsFragment.class, NO_DATA_RES_ID, R.drawable.ic_settings_print);
addIndex(DevelopmentSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_development)162         addIndex(DevelopmentSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_development);
addIndex(DeviceInfoSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_about)163         addIndex(DeviceInfoSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_about);
addIndex(LegalSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_about)164         addIndex(LegalSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_about);
addIndex(ZenModeVisualInterruptionSettings.class, R.xml.zen_mode_visual_interruptions_settings, R.drawable.ic_settings_notifications)165         addIndex(ZenModeVisualInterruptionSettings.class,
166                 R.xml.zen_mode_visual_interruptions_settings,
167                 R.drawable.ic_settings_notifications);
addIndex(SystemDashboardFragment.class, NO_DATA_RES_ID, R.drawable.ic_settings_about)168         addIndex(SystemDashboardFragment.class, NO_DATA_RES_ID, R.drawable.ic_settings_about);
addIndex(ResetDashboardFragment.class, NO_DATA_RES_ID, R.drawable.ic_restore)169         addIndex(ResetDashboardFragment.class, NO_DATA_RES_ID, R.drawable.ic_restore);
addIndex(StorageDashboardFragment.class, NO_DATA_RES_ID, R.drawable.ic_settings_storage)170         addIndex(StorageDashboardFragment.class, NO_DATA_RES_ID, R.drawable.ic_settings_storage);
addIndex(ConnectedDeviceDashboardFragment.class, NO_DATA_RES_ID, R.drawable.ic_devices_other)171         addIndex(ConnectedDeviceDashboardFragment.class, NO_DATA_RES_ID,
172                 R.drawable.ic_devices_other);
addIndex(EnterprisePrivacySettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_about)173         addIndex(EnterprisePrivacySettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_about);
addIndex(PaymentSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_nfc_payment)174         addIndex(PaymentSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_nfc_payment);
addIndex( TtsEnginePreferenceFragment.class, NO_DATA_RES_ID, R.drawable.ic_settings_language)175         addIndex(
176                 TtsEnginePreferenceFragment.class, NO_DATA_RES_ID, R.drawable.ic_settings_language);
addIndex(LockscreenDashboardFragment.class, R.xml.security_lockscreen_settings, R.drawable.ic_settings_security)177         addIndex(LockscreenDashboardFragment.class, R.xml.security_lockscreen_settings,
178             R.drawable.ic_settings_security);
addIndex(MagnificationPreferenceFragment.class, NO_DATA_RES_ID, R.drawable.ic_settings_accessibility)179         addIndex(MagnificationPreferenceFragment.class, NO_DATA_RES_ID,
180                 R.drawable.ic_settings_accessibility);
addIndex(AccessibilityShortcutPreferenceFragment.class, NO_DATA_RES_ID, R.drawable.ic_settings_accessibility)181         addIndex(AccessibilityShortcutPreferenceFragment.class, NO_DATA_RES_ID,
182                 R.drawable.ic_settings_accessibility);
addIndex(ChannelImportanceSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_notifications)183         addIndex(ChannelImportanceSettings.class, NO_DATA_RES_ID,
184                 R.drawable.ic_settings_notifications);
185     }
186 
SearchIndexableResources()187     private SearchIndexableResources() {
188     }
189 
size()190     public static int size() {
191         return sResMap.size();
192     }
193 
getResourceByName(String className)194     public static SearchIndexableResource getResourceByName(String className) {
195         return sResMap.get(className);
196     }
197 
values()198     public static Collection<SearchIndexableResource> values() {
199         return sResMap.values();
200     }
201 }
202