• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 import android.text.TextUtils;
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.AppAndNotificationDashboardFragment;
37 import com.android.settings.applications.DefaultAppSettings;
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.deletionhelper.AutomaticStorageManagerSettings;
47 import com.android.settings.development.DevelopmentSettings;
48 import com.android.settings.deviceinfo.Status;
49 import com.android.settings.deviceinfo.StorageDashboardFragment;
50 import com.android.settings.deviceinfo.StorageSettings;
51 import com.android.settings.display.AmbientDisplaySettings;
52 import com.android.settings.display.ScreenZoomSettings;
53 import com.android.settings.dream.DreamSettings;
54 import com.android.settings.enterprise.EnterprisePrivacySettings;
55 import com.android.settings.fuelgauge.BatterySaverSettings;
56 import com.android.settings.fuelgauge.PowerUsageAdvanced;
57 import com.android.settings.fuelgauge.PowerUsageSummary;
58 import com.android.settings.gestures.AssistGestureSettings;
59 import com.android.settings.gestures.DoubleTapPowerSettings;
60 import com.android.settings.gestures.DoubleTapScreenSettings;
61 import com.android.settings.gestures.DoubleTwistGestureSettings;
62 import com.android.settings.gestures.GestureSettings;
63 import com.android.settings.gestures.PickupGestureSettings;
64 import com.android.settings.gestures.SwipeToNotificationSettings;
65 import com.android.settings.inputmethod.AvailableVirtualKeyboardFragment;
66 import com.android.settings.inputmethod.PhysicalKeyboardFragment;
67 import com.android.settings.inputmethod.VirtualKeyboardFragment;
68 import com.android.settings.language.LanguageAndInputSettings;
69 import com.android.settings.location.LocationSettings;
70 import com.android.settings.location.ScanningSettings;
71 import com.android.settings.network.NetworkDashboardFragment;
72 import com.android.settings.nfc.PaymentSettings;
73 import com.android.settings.notification.ChannelImportanceSettings;
74 import com.android.settings.notification.ConfigureNotificationSettings;
75 import com.android.settings.notification.SoundSettings;
76 import com.android.settings.notification.ZenModePrioritySettings;
77 import com.android.settings.notification.ZenModeSettings;
78 import com.android.settings.notification.ZenModeVisualInterruptionSettings;
79 import com.android.settings.print.PrintSettingsFragment;
80 import com.android.settings.security.LockscreenDashboardFragment;
81 import com.android.settings.sim.SimSettings;
82 import com.android.settings.support.SupportDashboardActivity;
83 import com.android.settings.system.ResetDashboardFragment;
84 import com.android.settings.system.SystemDashboardFragment;
85 import com.android.settings.tts.TtsEnginePreferenceFragment;
86 import com.android.settings.users.UserSettings;
87 import com.android.settings.wallpaper.WallpaperTypeSettings;
88 import com.android.settings.wifi.ConfigureWifiSettings;
89 import com.android.settings.wifi.SavedAccessPointsWifiSettings;
90 import com.android.settings.wifi.WifiSettings;
91 import java.util.Collection;
92 import java.util.HashMap;
93 
94 public final class SearchIndexableResources {
95 
96     /**
97      * Identifies subsettings which have an {@link SearchIndexableResource#intentAction} but
98      * whose intents should still be treated as subsettings inside of Settings.
99      */
100     public static final String SUBSETTING_TARGET_PACKAGE = "subsetting_target_package";
101 
102     @XmlRes
103     public static final int NO_DATA_RES_ID = 0;
104 
105     @VisibleForTesting
106     static final HashMap<String, SearchIndexableResource> sResMap = new HashMap<>();
107 
108     @VisibleForTesting
addIndex(Class<?> indexClass, @XmlRes int xmlResId, @DrawableRes int iconResId)109     static void addIndex(Class<?> indexClass, @XmlRes int xmlResId,
110             @DrawableRes int iconResId) {
111         addIndex(indexClass, xmlResId, iconResId, null /* targetAction */);
112     }
113 
114     @VisibleForTesting
addIndex(Class<?> indexClass, @XmlRes int xmlResId, @DrawableRes int iconResId, String targetAction)115     static void addIndex(Class<?> indexClass, @XmlRes int xmlResId,
116             @DrawableRes int iconResId, String targetAction) {
117         String className = indexClass.getName();
118         SearchIndexableResource resource =
119                 new SearchIndexableResource(0, xmlResId, className, iconResId);
120 
121         if (!TextUtils.isEmpty(targetAction)) {
122             resource.intentAction = targetAction;
123             resource.intentTargetPackage = SUBSETTING_TARGET_PACKAGE;
124         }
125 
126         sResMap.put(className, resource);
127     }
128 
129     static {
addIndex(WifiSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_wireless)130         addIndex(WifiSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_wireless);
addIndex(NetworkDashboardFragment.class, NO_DATA_RES_ID, R.drawable.ic_settings_wireless)131         addIndex(NetworkDashboardFragment.class, NO_DATA_RES_ID, R.drawable.ic_settings_wireless);
addIndex(ConfigureWifiSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_wireless)132         addIndex(ConfigureWifiSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_wireless);
addIndex(SavedAccessPointsWifiSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_wireless)133         addIndex(SavedAccessPointsWifiSettings.class, NO_DATA_RES_ID,
134                 R.drawable.ic_settings_wireless);
addIndex(BluetoothSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_bluetooth)135         addIndex(BluetoothSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_bluetooth);
addIndex(SimSettings.class, NO_DATA_RES_ID, R.drawable.ic_sim_sd)136         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)137         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)138         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)139         addIndex(ScreenZoomSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_display);
addIndex(DisplaySettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_display, "android.settings.DISPLAY_SETTINGS")140         addIndex(DisplaySettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_display,
141                 "android.settings.DISPLAY_SETTINGS");
addIndex(AmbientDisplaySettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_display)142         addIndex(AmbientDisplaySettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_display);
addIndex(WallpaperTypeSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_display)143         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)144         addIndex(ConfigureNotificationSettings.class,
145                 R.xml.configure_notification_settings, R.drawable.ic_settings_notifications);
addIndex(AppAndNotificationDashboardFragment.class, NO_DATA_RES_ID, R.drawable.ic_settings_applications)146         addIndex(AppAndNotificationDashboardFragment.class, NO_DATA_RES_ID,
147                 R.drawable.ic_settings_applications);
addIndex(SoundSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_sound, "android.settings.SOUND_SETTINGS")148         addIndex(SoundSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_sound,
149                 "android.settings.SOUND_SETTINGS");
addIndex(ZenModeSettings.class, R.xml.zen_mode_settings, R.drawable.ic_settings_notifications)150         addIndex(ZenModeSettings.class,
151                 R.xml.zen_mode_settings, R.drawable.ic_settings_notifications);
addIndex(ZenModePrioritySettings.class, R.xml.zen_mode_priority_settings, R.drawable.ic_settings_notifications)152         addIndex(ZenModePrioritySettings.class,
153                 R.xml.zen_mode_priority_settings, R.drawable.ic_settings_notifications);
addIndex(StorageSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_storage)154         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)155         addIndex(PowerUsageSummary.class,
156                 R.xml.power_usage_summary, R.drawable.ic_settings_battery);
addIndex(PowerUsageAdvanced.class, NO_DATA_RES_ID, R.drawable.ic_settings_battery)157         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)158         addIndex(BatterySaverSettings.class,
159                 R.xml.battery_saver_settings, R.drawable.ic_settings_battery);
addIndex(DefaultAppSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_applications)160         addIndex(DefaultAppSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_applications);
addIndex(ManageAssist.class, NO_DATA_RES_ID, R.drawable.ic_settings_applications)161         addIndex(ManageAssist.class, NO_DATA_RES_ID, R.drawable.ic_settings_applications);
addIndex(SpecialAccessSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_applications)162         addIndex(SpecialAccessSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_applications);
addIndex(UserSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_multiuser)163         addIndex(UserSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_multiuser);
addIndex(AssistGestureSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_gestures)164         addIndex(AssistGestureSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_gestures);
addIndex(PickupGestureSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_gestures)165         addIndex(PickupGestureSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_gestures);
addIndex(DoubleTapScreenSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_gestures)166         addIndex(DoubleTapScreenSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_gestures);
addIndex(DoubleTapPowerSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_gestures)167         addIndex(DoubleTapPowerSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_gestures);
addIndex(DoubleTwistGestureSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_gestures)168         addIndex(DoubleTwistGestureSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_gestures);
addIndex(SwipeToNotificationSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_gestures)169         addIndex(SwipeToNotificationSettings.class, NO_DATA_RES_ID,
170                 R.drawable.ic_settings_gestures);
addIndex(GestureSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_gestures)171         addIndex(GestureSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_gestures);
addIndex(LanguageAndInputSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_language)172         addIndex(LanguageAndInputSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_language);
addIndex(LocationSettings.class, R.xml.location_settings, R.drawable.ic_settings_location)173         addIndex(LocationSettings.class, R.xml.location_settings, R.drawable.ic_settings_location);
addIndex(ScanningSettings.class, R.xml.location_scanning, R.drawable.ic_settings_location)174         addIndex(ScanningSettings.class, R.xml.location_scanning, R.drawable.ic_settings_location);
addIndex(SecuritySettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_security)175         addIndex(SecuritySettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_security);
addIndex(EncryptionAndCredential.class, NO_DATA_RES_ID, R.drawable.ic_settings_security)176         addIndex(EncryptionAndCredential.class, NO_DATA_RES_ID, R.drawable.ic_settings_security);
addIndex(ScreenPinningSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_security)177         addIndex(ScreenPinningSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_security);
addIndex(UserAndAccountDashboardFragment.class, NO_DATA_RES_ID, R.drawable.ic_settings_accounts)178         addIndex(UserAndAccountDashboardFragment.class, NO_DATA_RES_ID,
179                 R.drawable.ic_settings_accounts);
addIndex(VirtualKeyboardFragment.class, NO_DATA_RES_ID, R.drawable.ic_settings_language)180         addIndex(VirtualKeyboardFragment.class, NO_DATA_RES_ID, R.drawable.ic_settings_language);
addIndex(AvailableVirtualKeyboardFragment.class, NO_DATA_RES_ID, R.drawable.ic_settings_language)181         addIndex(AvailableVirtualKeyboardFragment.class,
182                 NO_DATA_RES_ID, R.drawable.ic_settings_language);
addIndex(PhysicalKeyboardFragment.class, NO_DATA_RES_ID, R.drawable.ic_settings_language)183         addIndex(PhysicalKeyboardFragment.class, NO_DATA_RES_ID, R.drawable.ic_settings_language);
addIndex(BackupSettingsActivity.class, NO_DATA_RES_ID, R.drawable.ic_settings_backup)184         addIndex(BackupSettingsActivity.class, NO_DATA_RES_ID, R.drawable.ic_settings_backup);
addIndex(BackupSettingsFragment.class, NO_DATA_RES_ID, R.drawable.ic_settings_backup)185         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)186         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)187         addIndex(AccessibilitySettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_accessibility);
addIndex(PrintSettingsFragment.class, NO_DATA_RES_ID, R.drawable.ic_settings_print)188         addIndex(PrintSettingsFragment.class, NO_DATA_RES_ID, R.drawable.ic_settings_print);
addIndex(DevelopmentSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_development)189         addIndex(DevelopmentSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_development);
addIndex(DeviceInfoSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_about)190         addIndex(DeviceInfoSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_about);
addIndex(Status.class, NO_DATA_RES_ID, 0 )191         addIndex(Status.class, NO_DATA_RES_ID, 0 /* icon */);
addIndex(LegalSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_about)192         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)193         addIndex(ZenModeVisualInterruptionSettings.class,
194                 R.xml.zen_mode_visual_interruptions_settings,
195                 R.drawable.ic_settings_notifications);
addIndex(SystemDashboardFragment.class, NO_DATA_RES_ID, R.drawable.ic_settings_about)196         addIndex(SystemDashboardFragment.class, NO_DATA_RES_ID, R.drawable.ic_settings_about);
addIndex(ResetDashboardFragment.class, NO_DATA_RES_ID, R.drawable.ic_restore)197         addIndex(ResetDashboardFragment.class, NO_DATA_RES_ID, R.drawable.ic_restore);
addIndex(StorageDashboardFragment.class, NO_DATA_RES_ID, R.drawable.ic_settings_storage)198         addIndex(StorageDashboardFragment.class, NO_DATA_RES_ID, R.drawable.ic_settings_storage);
addIndex(ConnectedDeviceDashboardFragment.class, NO_DATA_RES_ID, R.drawable.ic_devices_other)199         addIndex(ConnectedDeviceDashboardFragment.class, NO_DATA_RES_ID,
200                 R.drawable.ic_devices_other);
addIndex(EnterprisePrivacySettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_about)201         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)202         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)203         addIndex(
204                 TtsEnginePreferenceFragment.class, NO_DATA_RES_ID, R.drawable.ic_settings_language);
addIndex(LockscreenDashboardFragment.class, R.xml.security_lockscreen_settings, R.drawable.ic_settings_security)205         addIndex(LockscreenDashboardFragment.class, R.xml.security_lockscreen_settings,
206                 R.drawable.ic_settings_security);
addIndex(MagnificationPreferenceFragment.class, NO_DATA_RES_ID, R.drawable.ic_settings_accessibility)207         addIndex(MagnificationPreferenceFragment.class, NO_DATA_RES_ID,
208                 R.drawable.ic_settings_accessibility);
addIndex(AccessibilityShortcutPreferenceFragment.class, NO_DATA_RES_ID, R.drawable.ic_settings_accessibility)209         addIndex(AccessibilityShortcutPreferenceFragment.class, NO_DATA_RES_ID,
210                 R.drawable.ic_settings_accessibility);
addIndex(ChannelImportanceSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_notifications)211         addIndex(ChannelImportanceSettings.class, NO_DATA_RES_ID,
212                 R.drawable.ic_settings_notifications);
addIndex(DreamSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_display)213         addIndex(DreamSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_display);
addIndex(SupportDashboardActivity.class, NO_DATA_RES_ID, R.drawable.ic_help)214         addIndex(SupportDashboardActivity.class, NO_DATA_RES_ID, R.drawable.ic_help);
addIndex( AutomaticStorageManagerSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_storage)215         addIndex(
216                 AutomaticStorageManagerSettings.class,
217                 NO_DATA_RES_ID,
218                 R.drawable.ic_settings_storage);
219     }
220 
SearchIndexableResources()221     private SearchIndexableResources() {
222     }
223 
size()224     public static int size() {
225         return sResMap.size();
226     }
227 
getResourceByName(String className)228     public static SearchIndexableResource getResourceByName(String className) {
229         return sResMap.get(className);
230     }
231 
values()232     public static Collection<SearchIndexableResource> values() {
233         return sResMap.values();
234     }
235 }
236