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