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 com.android.settings.ChooseLockGeneric;
20 import com.android.settings.DateTimeSettings;
21 import com.android.settings.DevelopmentSettings;
22 import com.android.settings.DeviceInfoSettings;
23 import com.android.settings.DisplaySettings;
24 import com.android.settings.LegalSettings;
25 import com.android.settings.PrivacySettings;
26 import com.android.settings.ScreenPinningSettings;
27 import com.android.settings.SecuritySettings;
28 import com.android.settings.WallpaperTypeSettings;
29 import com.android.settings.WirelessSettings;
30 import com.android.settings.accessibility.AccessibilitySettings;
31 import com.android.settings.accounts.AccountSettings;
32 import com.android.settings.applications.AdvancedAppSettings;
33 import com.android.settings.applications.SpecialAccessSettings;
34 import com.android.settings.bluetooth.BluetoothSettings;
35 import com.android.settings.datausage.DataUsageMeteredSettings;
36 import com.android.settings.datausage.DataUsageSummary;
37 import com.android.settings.deviceinfo.StorageSettings;
38 import com.android.settings.display.ScreenZoomSettings;
39 import com.android.settings.fuelgauge.BatterySaverSettings;
40 import com.android.settings.fuelgauge.PowerUsageSummary;
41 import com.android.settings.inputmethod.InputMethodAndLanguageSettings;
42 import com.android.settings.location.LocationSettings;
43 import com.android.settings.location.ScanningSettings;
44 import com.android.settings.notification.ConfigureNotificationSettings;
45 import com.android.settings.notification.OtherSoundSettings;
46 import com.android.settings.notification.SoundSettings;
47 import com.android.settings.notification.ZenModeAutomationSettings;
48 import com.android.settings.notification.ZenModePrioritySettings;
49 import com.android.settings.notification.ZenModeSettings;
50 import com.android.settings.notification.ZenModeVisualInterruptionSettings;
51 import com.android.settings.print.PrintSettingsFragment;
52 import com.android.settings.sim.SimSettings;
53 import com.android.settings.users.UserSettings;
54 import com.android.settings.wifi.AdvancedWifiSettings;
55 import com.android.settings.wifi.SavedAccessPointsWifiSettings;
56 import com.android.settings.wifi.WifiSettings;
57 
58 import java.util.HashMap;
59 
60 /**
61  * Utility class for dealing with Search Ranking.
62  */
63 public final class Ranking {
64 
65     public static final int RANK_WIFI = 1;
66     public static final int RANK_BT = 2;
67     public static final int RANK_SIM = 3;
68     public static final int RANK_DATA_USAGE = 4;
69     public static final int RANK_WIRELESS = 5;
70     public static final int RANK_DISPLAY = 6;
71     public static final int RANK_WALLPAPER = 7;
72     public static final int RANK_NOTIFICATIONS = 8;
73     public static final int RANK_SOUND = 9;
74     public static final int RANK_APPS = 10;
75     public static final int RANK_STORAGE = 11;
76     public static final int RANK_POWER_USAGE = 12;
77     public static final int RANK_USERS = 13;
78     public static final int RANK_LOCATION = 14;
79     public static final int RANK_SECURITY = 15;
80     public static final int RANK_ACCOUNT = 16;
81     public static final int RANK_IME = 17;
82     public static final int RANK_PRIVACY = 18;
83     public static final int RANK_DATE_TIME = 19;
84     public static final int RANK_ACCESSIBILITY = 20;
85     public static final int RANK_PRINTING = 21;
86     public static final int RANK_DEVELOPEMENT = 22;
87     public static final int RANK_DEVICE_INFO = 23;
88 
89     public static final int RANK_UNDEFINED = -1;
90     public static final int RANK_OTHERS = 1024;
91     public static final int BASE_RANK_DEFAULT = 2048;
92 
93     public static int sCurrentBaseRank = BASE_RANK_DEFAULT;
94 
95     private static HashMap<String, Integer> sRankMap = new HashMap<String, Integer>();
96     private static HashMap<String, Integer> sBaseRankMap = new HashMap<String, Integer>();
97 
98     static {
99         // Wi-Fi
WifiSettings.class.getName()100         sRankMap.put(WifiSettings.class.getName(), RANK_WIFI);
AdvancedWifiSettings.class.getName()101         sRankMap.put(AdvancedWifiSettings.class.getName(), RANK_WIFI);
SavedAccessPointsWifiSettings.class.getName()102         sRankMap.put(SavedAccessPointsWifiSettings.class.getName(), RANK_WIFI);
103 
104         // BT
BluetoothSettings.class.getName()105         sRankMap.put(BluetoothSettings.class.getName(), RANK_BT);
106 
107         // SIM Cards
SimSettings.class.getName()108         sRankMap.put(SimSettings.class.getName(), RANK_SIM);
109 
110         // DataUsage
DataUsageSummary.class.getName()111         sRankMap.put(DataUsageSummary.class.getName(), RANK_DATA_USAGE);
DataUsageMeteredSettings.class.getName()112         sRankMap.put(DataUsageMeteredSettings.class.getName(), RANK_DATA_USAGE);
113 
114         // Other wireless settinfs
WirelessSettings.class.getName()115         sRankMap.put(WirelessSettings.class.getName(), RANK_WIRELESS);
116 
117         // Display
DisplaySettings.class.getName()118         sRankMap.put(DisplaySettings.class.getName(), RANK_DISPLAY);
ScreenZoomSettings.class.getName()119         sRankMap.put(ScreenZoomSettings.class.getName(), RANK_WIFI);
120 
121         // Wallpapers
WallpaperTypeSettings.class.getName()122         sRankMap.put(WallpaperTypeSettings.class.getName(), RANK_WALLPAPER);
123 
124         // Sound
SoundSettings.class.getName()125         sRankMap.put(SoundSettings.class.getName(), RANK_SOUND);
126 
127         // Notifications
ConfigureNotificationSettings.class.getName()128         sRankMap.put(ConfigureNotificationSettings.class.getName(), RANK_NOTIFICATIONS);
OtherSoundSettings.class.getName()129         sRankMap.put(OtherSoundSettings.class.getName(), RANK_NOTIFICATIONS);
ZenModeSettings.class.getName()130         sRankMap.put(ZenModeSettings.class.getName(), RANK_NOTIFICATIONS);
ZenModePrioritySettings.class.getName()131         sRankMap.put(ZenModePrioritySettings.class.getName(), RANK_NOTIFICATIONS);
ZenModeAutomationSettings.class.getName()132         sRankMap.put(ZenModeAutomationSettings.class.getName(), RANK_NOTIFICATIONS);
ZenModeVisualInterruptionSettings.class.getName()133         sRankMap.put(ZenModeVisualInterruptionSettings.class.getName(), RANK_NOTIFICATIONS);
134 
135         // Storage
StorageSettings.class.getName()136         sRankMap.put(StorageSettings.class.getName(), RANK_STORAGE);
137 
138         // Battery
PowerUsageSummary.class.getName()139         sRankMap.put(PowerUsageSummary.class.getName(), RANK_POWER_USAGE);
BatterySaverSettings.class.getName()140         sRankMap.put(BatterySaverSettings.class.getName(), RANK_POWER_USAGE);
141 
142         // Advanced app settings
AdvancedAppSettings.class.getName()143         sRankMap.put(AdvancedAppSettings.class.getName(), RANK_APPS);
SpecialAccessSettings.class.getName()144         sRankMap.put(SpecialAccessSettings.class.getName(), RANK_APPS);
145 
146         // Users
UserSettings.class.getName()147         sRankMap.put(UserSettings.class.getName(), RANK_USERS);
148 
149         // Location
LocationSettings.class.getName()150         sRankMap.put(LocationSettings.class.getName(), RANK_LOCATION);
ScanningSettings.class.getName()151         sRankMap.put(ScanningSettings.class.getName(), RANK_LOCATION);
152 
153         // Security
SecuritySettings.class.getName()154         sRankMap.put(SecuritySettings.class.getName(), RANK_SECURITY);
ChooseLockGeneric.ChooseLockGenericFragment.class.getName()155         sRankMap.put(ChooseLockGeneric.ChooseLockGenericFragment.class.getName(), RANK_SECURITY);
ScreenPinningSettings.class.getName()156         sRankMap.put(ScreenPinningSettings.class.getName(), RANK_SECURITY);
157 
158         // Accounts
AccountSettings.class.getName()159         sRankMap.put(AccountSettings.class.getName(), RANK_ACCOUNT);
160 
161         // IMEs
InputMethodAndLanguageSettings.class.getName()162         sRankMap.put(InputMethodAndLanguageSettings.class.getName(), RANK_IME);
163 
164         // Privacy
PrivacySettings.class.getName()165         sRankMap.put(PrivacySettings.class.getName(), RANK_PRIVACY);
166 
167         // Date / Time
DateTimeSettings.class.getName()168         sRankMap.put(DateTimeSettings.class.getName(), RANK_DATE_TIME);
169 
170         // Accessibility
AccessibilitySettings.class.getName()171         sRankMap.put(AccessibilitySettings.class.getName(), RANK_ACCESSIBILITY);
172 
173         // Print
PrintSettingsFragment.class.getName()174         sRankMap.put(PrintSettingsFragment.class.getName(), RANK_PRINTING);
175 
176         // Development
DevelopmentSettings.class.getName()177         sRankMap.put(DevelopmentSettings.class.getName(), RANK_DEVELOPEMENT);
178 
179         // Device infos
DeviceInfoSettings.class.getName()180         sRankMap.put(DeviceInfoSettings.class.getName(), RANK_DEVICE_INFO);
LegalSettings.class.getName()181         sRankMap.put(LegalSettings.class.getName(), RANK_DEVICE_INFO);
182 
183         sBaseRankMap.put("com.android.settings", 0);
184     }
185 
getRankForClassName(String className)186     public static int getRankForClassName(String className) {
187         Integer rank = sRankMap.get(className);
188         return (rank != null) ? (int) rank: RANK_OTHERS;
189     }
190 
getBaseRankForAuthority(String authority)191     public static int getBaseRankForAuthority(String authority) {
192         synchronized (sBaseRankMap) {
193             Integer base = sBaseRankMap.get(authority);
194             if (base != null) {
195                 return base;
196             }
197             sCurrentBaseRank++;
198             sBaseRankMap.put(authority, sCurrentBaseRank);
199             return sCurrentBaseRank;
200         }
201     }
202 }
203