Merge "Refactor setup wizard-related code"
diff --git a/res/values-sw600dp/dimens.xml b/res/values-sw600dp/dimens.xml
index 0cef851..76ce998 100755
--- a/res/values-sw600dp/dimens.xml
+++ b/res/values-sw600dp/dimens.xml
@@ -44,5 +44,10 @@
 
     <!-- SwitchBar padding start -->
     <dimen name="switchbar_padding_start">80dp</dimen>
+    <!-- SwitchBar padding end -->
+    <dimen name="switchbar_padding_end">80dp</dimen>
+
+    <!-- ActionBar contentInsetStart -->
+    <dimen name="actionbar_contentInsetStart">80dp</dimen>
 
 </resources>
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 460fb44..aa8ab5e 100755
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -94,8 +94,11 @@
     <dimen name="dashboard_category_title_height">48dp</dimen>
 
     <!-- SwitchBar padding start -->
-    <dimen name="switchbar_padding_start">72dp</dimen>
-    <!-- SwitchBar padding emd -->
-    <dimen name="switchbar_padding_end">@*android:dimen/preference_fragment_padding_side</dimen>
+    <dimen name="switchbar_padding_start">84dp</dimen>
+    <!-- SwitchBar padding end. Should be 2 x @*android:dimen/preference_fragment_padding_side -->
+    <dimen name="switchbar_padding_end">32dp</dimen>
+
+    <!-- ActionBar contentInsetStart -->
+    <dimen name="actionbar_contentInsetStart">84dp</dimen>
 
 </resources>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 11adc77..fe487bb 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -610,7 +610,7 @@
     <!-- Wireless controls settings screen, setting check box label -->
     <string name="airplane_mode">Airplane mode</string>
     <!-- Main Settings screen settings title for things like airplane mode, tethering, NFC, VPN.  This will take you to another screen with those settings. -->
-    <string name="radio_controls_title">More\u2026</string>
+    <string name="radio_controls_title">NFC &amp; more</string>
     <!-- Wireless Settings screen title for things like Wi-Fi, bluetooth, airplane mode. -->
     <string name="wireless_networks_settings_title">Wireless &amp; networks</string>
     <!-- Main Settings screen settings summary text for the "Wireless controls" setting -->
diff --git a/res/values/themes.xml b/res/values/themes.xml
index c39910b..366492d 100644
--- a/res/values/themes.xml
+++ b/res/values/themes.xml
@@ -89,6 +89,12 @@
         <!-- Used by the StatusBar and NavBar -->
         <item name="android:colorPrimaryDark">@color/actionbar_background_color</item>
         <item name="android:colorAccent">@color/quantum_orange_A200</item>
+        <!-- Redefine the ActionBar style for contentInsetStart -->
+        <item name="android:actionBarStyle">@style/Theme.ActionBar</item>
+    </style>
+
+    <style name="Theme.ActionBar" parent="@android:style/Widget.Quantum.Light.ActionBar.Solid">
+        <item name="android:contentInsetStart">@dimen/actionbar_contentInsetStart</item>
     </style>
 
 </resources>
diff --git a/res/xml/device_info_settings.xml b/res/xml/device_info_settings.xml
index 0261b67..c9a9a48 100644
--- a/res/xml/device_info_settings.xml
+++ b/res/xml/device_info_settings.xml
@@ -80,15 +80,6 @@
             <intent android:action="android.settings.SAFETY" />
         </PreferenceScreen>
 
-        <!-- Contributors -->
-        <!-- 
-        <PreferenceScreen
-                android:key="contributors"
-                android:title="@string/contributors_title">
-            <intent android:action="android.settings.TEAM" />
-        </PreferenceScreen>
-        -->
-
         <PreferenceScreen
                 android:key="regulatory_info"
                 android:title="@string/regulatory_information">
diff --git a/src/com/android/settings/CryptKeeper.java b/src/com/android/settings/CryptKeeper.java
index 661e304..322bda0 100644
--- a/src/com/android/settings/CryptKeeper.java
+++ b/src/com/android/settings/CryptKeeper.java
@@ -58,7 +58,6 @@
 import android.widget.TextView;
 
 import com.android.internal.statusbar.StatusBarIcon;
-import com.android.internal.telephony.ITelephony;
 import com.android.internal.telephony.Phone;
 import com.android.internal.telephony.PhoneConstants;
 import com.android.internal.widget.LockPatternUtils;
@@ -409,6 +408,7 @@
 
                     final TextView status = (TextView) findViewById(R.id.owner_info);
                     status.setText(owner_info);
+                    status.setSelected(true);
                     passwordEntryInit();
                 }
             }.execute();
@@ -605,8 +605,7 @@
         }
 
         // Disable the Emergency call button if the device has no voice telephone capability
-        final TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
-        if (!tm.isVoiceCapable()) {
+        if (!getTelephonyManager().isVoiceCapable()) {
             final View emergencyCall = findViewById(R.id.emergencyCallButton);
             if (emergencyCall != null) {
                 Log.d(TAG, "Removing the emergency Call button");
@@ -760,7 +759,7 @@
      */
     private final void setAirplaneModeIfNecessary() {
         final boolean isLteDevice =
-                TelephonyManager.getDefault().getLteOnCdmaMode() == PhoneConstants.LTE_ON_CDMA_TRUE;
+                getTelephonyManager().getLteOnCdmaMode() == PhoneConstants.LTE_ON_CDMA_TRUE;
         if (!isLteDevice) {
             Log.d(TAG, "Going into airplane mode.");
             Settings.Global.putInt(getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 1);
@@ -796,7 +795,7 @@
             return;
         }
 
-        final int newState = TelephonyManager.getDefault().getCallState();
+        final int newState = getTelephonyManager().getCallState();
         int textId;
         if (newState == TelephonyManager.CALL_STATE_OFFHOOK) {
             // Show "return to call" text and show phone icon
@@ -816,23 +815,14 @@
     }
 
     private void takeEmergencyCallAction() {
-        if (TelephonyManager.getDefault().getCallState() == TelephonyManager.CALL_STATE_OFFHOOK) {
-            resumeCall();
+        TelephonyManager telephonyManager = getTelephonyManager();
+        if (telephonyManager.getCallState() == TelephonyManager.CALL_STATE_OFFHOOK) {
+            telephonyManager.showCallScreen();
         } else {
             launchEmergencyDialer();
         }
     }
 
-    private void resumeCall() {
-        final ITelephony phone = ITelephony.Stub.asInterface(ServiceManager.checkService("phone"));
-        if (phone != null) {
-            try {
-                phone.showCallScreen();
-            } catch (RemoteException e) {
-                Log.e(TAG, "Error calling ITelephony service: " + e);
-            }
-        }
-    }
 
     private void launchEmergencyDialer() {
         final Intent intent = new Intent(ACTION_EMERGENCY_DIAL);
@@ -841,6 +831,10 @@
         startActivity(intent);
     }
 
+    private TelephonyManager getTelephonyManager() {
+        return (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
+    }
+
     /**
      * Listen to key events so we can disable sounds when we get a keyinput in EditText.
      */
diff --git a/src/com/android/settings/DeviceInfoSettings.java b/src/com/android/settings/DeviceInfoSettings.java
index 9d10ecb..c26e4ab 100644
--- a/src/com/android/settings/DeviceInfoSettings.java
+++ b/src/com/android/settings/DeviceInfoSettings.java
@@ -35,27 +35,30 @@
 import android.preference.Preference;
 import android.preference.PreferenceGroup;
 import android.preference.PreferenceScreen;
+import android.provider.SearchIndexableResource;
 import android.provider.Settings;
 import android.text.TextUtils;
 import android.util.Log;
 import android.widget.Toast;
+import com.android.settings.search.BaseSearchIndexProvider;
+import com.android.settings.search.Indexable;
 
 import java.io.BufferedReader;
 import java.io.FileReader;
 import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-public class DeviceInfoSettings extends SettingsPreferenceFragment {
+public class DeviceInfoSettings extends SettingsPreferenceFragment implements Indexable {
 
     private static final String LOG_TAG = "DeviceInfoSettings";
     private static final String FILENAME_PROC_VERSION = "/proc/version";
     private static final String FILENAME_MSV = "/sys/board_properties/soc/msv";
 
     private static final String KEY_CONTAINER = "container";
-    private static final String KEY_TEAM = "team";
-    private static final String KEY_CONTRIBUTORS = "contributors";
     private static final String KEY_REGULATORY_INFO = "regulatory_info";
     private static final String KEY_TERMS = "terms";
     private static final String KEY_LICENSE = "license";
@@ -73,6 +76,7 @@
     private static final String KEY_EQUIPMENT_ID = "fcc_equipment_id";
     private static final String PROPERTY_EQUIPMENT_ID = "ro.ril.fccid";
     private static final String KEY_DEVICE_FEEDBACK = "device_feedback";
+    private static final String KEY_SAFETY_LEGAL = "safetylegal";
 
     static final int TAPS_TO_BE_A_DEVELOPER = 7;
 
@@ -109,7 +113,7 @@
                 PROPERTY_SELINUX_STATUS);
 
         // Remove Safety information preference if PROPERTY_URL_SAFETYLEGAL is not set
-        removePreferenceIfPropertyMissing(getPreferenceScreen(), "safetylegal",
+        removePreferenceIfPropertyMissing(getPreferenceScreen(), KEY_SAFETY_LEGAL,
                 PROPERTY_URL_SAFETYLEGAL);
 
         // Remove Equipment id preference if FCC ID is not set by RIL
@@ -139,8 +143,6 @@
                 Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
         Utils.updatePreferenceToSpecificActivityOrRemove(act, parentPreference, KEY_COPYRIGHT,
                 Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
-        Utils.updatePreferenceToSpecificActivityOrRemove(act, parentPreference, KEY_TEAM,
-                Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
 
         // These are contained by the root preference screen
         parentPreference = getPreferenceScreen();
@@ -152,8 +154,6 @@
             // Remove for secondary users
             removePreference(KEY_SYSTEM_UPDATE_SETTINGS);
         }
-        Utils.updatePreferenceToSpecificActivityOrRemove(act, parentPreference, KEY_CONTRIBUTORS,
-                Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
 
         // Read platform settings for additional system update setting
         removePreferenceIfBoolFalse(KEY_UPDATE_SETTING,
@@ -365,7 +365,7 @@
     }
 
     private static String getFeedbackReporterPackage(Context context) {
-        String feedbackReporter =
+        final String feedbackReporter =
                 context.getResources().getString(R.string.oem_preferred_feedback_reporter);
         if (TextUtils.isEmpty(feedbackReporter)) {
             // Reporter not configured. Return.
@@ -373,7 +373,7 @@
         }
         // Additional checks to ensure the reporter is on system image, and reporter is
         // configured to listen to the intent. Otherwise, dont show the "send feedback" option.
-        Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
+        final Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
 
         PackageManager pm = context.getPackageManager();
         List<ResolveInfo> resolvedPackages =
@@ -398,5 +398,83 @@
         }
         return null;
     }
+
+    /**
+     * For Search.
+     */
+    public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
+        new BaseSearchIndexProvider() {
+
+            @Override
+            public List<SearchIndexableResource> getXmlResourcesToIndex(
+                    Context context, boolean enabled) {
+                final SearchIndexableResource sir = new SearchIndexableResource(context);
+                sir.xmlResId = R.xml.device_info_settings;
+                return Arrays.asList(sir);
+            }
+
+            @Override
+            public List<String> getNonIndexableKeys(Context context) {
+                final List<String> keys = new ArrayList<String>();
+                if (isPropertyMissing(PROPERTY_SELINUX_STATUS)) {
+                    keys.add(KEY_SELINUX_STATUS);
+                }
+                if (isPropertyMissing(PROPERTY_URL_SAFETYLEGAL)) {
+                    keys.add(KEY_SAFETY_LEGAL);
+                }
+                if (isPropertyMissing(PROPERTY_EQUIPMENT_ID)) {
+                    keys.add(KEY_EQUIPMENT_ID);
+                }
+                // Remove Baseband version if wifi-only device
+                if (Utils.isWifiOnly(context)) {
+                    keys.add((KEY_BASEBAND_VERSION));
+                }
+                // Dont show feedback option if there is no reporter.
+                if (TextUtils.isEmpty(getFeedbackReporterPackage(context))) {
+                    keys.add(KEY_DEVICE_FEEDBACK);
+                }
+                if (!checkIntentAction(context, "android.settings.TERMS")) {
+                    keys.add(KEY_TERMS);
+                }
+                if (!checkIntentAction(context, "android.settings.LICENSE")) {
+                    keys.add(KEY_LICENSE);
+                }
+                if (!checkIntentAction(context, "android.settings.COPYRIGHT")) {
+                    keys.add(KEY_COPYRIGHT);
+                }
+                if (UserHandle.myUserId() != UserHandle.USER_OWNER) {
+                    keys.add(KEY_SYSTEM_UPDATE_SETTINGS);
+                }
+                if (!context.getResources().getBoolean(
+                        R.bool.config_additional_system_update_setting_enable)) {
+                    keys.add(KEY_UPDATE_SETTING);
+                }
+                return keys;
+            }
+
+            private boolean isPropertyMissing(String property) {
+                return SystemProperties.get(property).equals("");
+            }
+
+            private boolean checkIntentAction(Context context, String action) {
+                final Intent intent = new Intent(action);
+
+                // Find the activity that is in the system image
+                final PackageManager pm = context.getPackageManager();
+                final List<ResolveInfo> list = pm.queryIntentActivities(intent, 0);
+                final int listSize = list.size();
+
+                for (int i = 0; i < listSize; i++) {
+                    ResolveInfo resolveInfo = list.get(i);
+                    if ((resolveInfo.activityInfo.applicationInfo.flags &
+                            ApplicationInfo.FLAG_SYSTEM) != 0) {
+                        return true;
+                    }
+                }
+
+                return false;
+            }
+        };
+
 }
 
diff --git a/src/com/android/settings/notification/ZenModeSettings.java b/src/com/android/settings/notification/ZenModeSettings.java
index 8a66d1b..379b4c7 100644
--- a/src/com/android/settings/notification/ZenModeSettings.java
+++ b/src/com/android/settings/notification/ZenModeSettings.java
@@ -74,6 +74,7 @@
     private static final String KEY_GENERAL = "general";
     private static final String KEY_CALLS = "phone_calls";
     private static final String KEY_MESSAGES = "messages";
+    private static final String KEY_STARRED = "starred";
 
     private static final String KEY_AUTOMATIC = "automatic";
     private static final String KEY_WHEN = "when";
@@ -91,6 +92,7 @@
             rt.put(R.string.zen_mode_phone_calls, KEY_CALLS);
         }
         rt.put(R.string.zen_mode_messages, KEY_MESSAGES);
+        rt.put(R.string.zen_mode_from_starred, KEY_STARRED);
         rt.put(R.string.zen_mode_automatic_category, KEY_AUTOMATIC);
         rt.put(R.string.zen_mode_when, KEY_WHEN);
         rt.put(R.string.zen_mode_start_time, KEY_START_TIME);
@@ -194,12 +196,25 @@
         });
 
         mStarred = new DropDownPreference(mContext);
-        mStarred.setEnabled(false);
+        mStarred.setKey(KEY_STARRED);
         mStarred.setTitle(R.string.zen_mode_from);
         mStarred.setDropDownWidth(R.dimen.zen_mode_dropdown_width);
-        mStarred.addItem(R.string.zen_mode_from_anyone, null);
-        mStarred.addItem(R.string.zen_mode_from_starred, null);
-        mStarred.addItem(R.string.zen_mode_from_contacts, null);
+        mStarred.addItem(R.string.zen_mode_from_anyone, ZenModeConfig.SOURCE_ANYONE);
+        mStarred.addItem(R.string.zen_mode_from_starred, ZenModeConfig.SOURCE_STAR);
+        mStarred.addItem(R.string.zen_mode_from_contacts, ZenModeConfig.SOURCE_CONTACT);
+        mStarred.setCallback(new DropDownPreference.Callback() {
+            @Override
+            public boolean onItemSelected(int pos, Object newValue) {
+                if (mDisableListeners) return true;
+                final int val = (Integer) newValue;
+                if (val == mConfig.allowFrom) return true;
+                if (DEBUG) Log.d(TAG, "onPrefChange allowFrom=" +
+                        ZenModeConfig.sourceToString(val));
+                final ZenModeConfig newConfig = mConfig.copy();
+                newConfig.allowFrom = val;
+                return setZenModeConfig(newConfig);
+            }
+        });
         general.addPreference(mStarred);
 
         final Preference alarmInfo = new Preference(mContext) {
@@ -266,7 +281,6 @@
         mEnd = new TimePickerPreference(mContext, mgr);
         mEnd.setKey(KEY_END_TIME);
         mEnd.setTitle(R.string.zen_mode_end_time);
-        mEnd.setSummaryFormat(R.string.zen_mode_end_time_summary_format);
         mEnd.setCallback(new TimePickerPreference.Callback() {
             @Override
             public boolean onSetTime(int hour, int minute) {
@@ -311,18 +325,26 @@
         updateControls();
     }
 
+    private void updateEndSummary() {
+        final int startMin = 60 * mConfig.sleepStartHour + mConfig.sleepStartMinute;
+        final int endMin = 60 * mConfig.sleepEndHour + mConfig.sleepEndMinute;
+        final boolean nextDay = startMin >= endMin;
+        mEnd.setSummaryFormat(nextDay ? R.string.zen_mode_end_time_summary_format : 0);
+    }
+
     private void updateControls() {
         mDisableListeners = true;
         if (mCalls != null) {
             mCalls.setChecked(mConfig.allowCalls);
         }
         mMessages.setChecked(mConfig.allowMessages);
-        mStarred.setSelectedItem(0);
+        mStarred.setSelectedValue(mConfig.allowFrom);
         mWhen.setSelectedValue(mConfig.sleepMode);
         mStart.setTime(mConfig.sleepStartHour, mConfig.sleepStartMinute);
         mEnd.setTime(mConfig.sleepEndHour, mConfig.sleepEndMinute);
         mDisableListeners = false;
         refreshAutomationSection();
+        updateEndSummary();
     }
 
     private void refreshAutomationSection() {
@@ -425,6 +447,7 @@
             if (success) {
                 mConfig = config;
                 if (DEBUG) Log.d(TAG, "Saved mConfig=" + mConfig);
+                updateEndSummary();
             }
             return success;
         } catch (Exception e) {
diff --git a/src/com/android/settings/search/Index.java b/src/com/android/settings/search/Index.java
index b1d21af..1b1825c 100644
--- a/src/com/android/settings/search/Index.java
+++ b/src/com/android/settings/search/Index.java
@@ -284,15 +284,17 @@
 
     private boolean addIndexablesFromRemoteProvider(String packageName, String authority) {
         try {
+            final int baseRank = Ranking.getBaseRankForAuthority(authority);
+
             final Context packageContext = mContext.createPackageContext(packageName, 0);
 
             final Uri uriForResources = buildUriForXmlResources(authority);
             addIndexablesForXmlResourceUri(packageContext, packageName, uriForResources,
-                    SearchIndexablesContract.INDEXABLES_XML_RES_COLUMNS);
+                    SearchIndexablesContract.INDEXABLES_XML_RES_COLUMNS, baseRank);
 
             final Uri uriForRawData = buildUriForRawData(authority);
             addIndexablesForRawDataUri(packageContext, packageName, uriForRawData,
-                    SearchIndexablesContract.INDEXABLES_RAW_COLUMNS);
+                    SearchIndexablesContract.INDEXABLES_RAW_COLUMNS, baseRank);
             return true;
         } catch (PackageManager.NameNotFoundException e) {
             Log.w(LOG_TAG, "Could not create context for " + packageName + ": "
@@ -501,7 +503,7 @@
     }
 
     private void addIndexablesForXmlResourceUri(Context packageContext, String packageName,
-            Uri uri, String[] projection) {
+            Uri uri, String[] projection, int baseRank) {
 
         final ContentResolver resolver = packageContext.getContentResolver();
         final Cursor cursor = resolver.query(uri, projection, null, null, null);
@@ -515,7 +517,9 @@
             final int count = cursor.getCount();
             if (count > 0) {
                 while (cursor.moveToNext()) {
-                    final int rank = cursor.getInt(COLUMN_INDEX_XML_RES_RANK);
+                    final int providerRank = cursor.getInt(COLUMN_INDEX_XML_RES_RANK);
+                    final int rank = (providerRank > 0) ? baseRank + providerRank : baseRank;
+
                     final int xmlResId = cursor.getInt(COLUMN_INDEX_XML_RES_RESID);
 
                     final String className = cursor.getString(COLUMN_INDEX_XML_RES_CLASS_NAME);
@@ -546,7 +550,7 @@
     }
 
     private void addIndexablesForRawDataUri(Context packageContext, String packageName,
-            Uri uri, String[] projection) {
+            Uri uri, String[] projection, int baseRank) {
 
         final ContentResolver resolver = packageContext.getContentResolver();
         final Cursor cursor = resolver.query(uri, projection, null, null, null);
@@ -560,7 +564,9 @@
             final int count = cursor.getCount();
             if (count > 0) {
                 while (cursor.moveToNext()) {
-                    final int rank = cursor.getInt(COLUMN_INDEX_RAW_RANK);
+                    final int providerRank = cursor.getInt(COLUMN_INDEX_RAW_RANK);
+                    final int rank = (providerRank > 0) ? baseRank + providerRank : baseRank;
+
                     final String title = cursor.getString(COLUMN_INDEX_RAW_TITLE);
                     final String summaryOn = cursor.getString(COLUMN_INDEX_RAW_SUMMARY_ON);
                     final String summaryOff = cursor.getString(COLUMN_INDEX_RAW_SUMMARY_OFF);
diff --git a/src/com/android/settings/search/Ranking.java b/src/com/android/settings/search/Ranking.java
new file mode 100644
index 0000000..074a8d7
--- /dev/null
+++ b/src/com/android/settings/search/Ranking.java
@@ -0,0 +1,147 @@
+/*
+ * Copyright (C) 2014 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 com.android.settings.ChooseLockGeneric;
+import com.android.settings.DataUsageSummary;
+import com.android.settings.DateTimeSettings;
+import com.android.settings.DevelopmentSettings;
+import com.android.settings.DeviceInfoSettings;
+import com.android.settings.DisplaySettings;
+import com.android.settings.HomeSettings;
+import com.android.settings.PrivacySettings;
+import com.android.settings.SecuritySettings;
+import com.android.settings.WallpaperTypeSettings;
+import com.android.settings.WirelessSettings;
+import com.android.settings.accessibility.AccessibilitySettings;
+import com.android.settings.bluetooth.BluetoothSettings;
+import com.android.settings.deviceinfo.Memory;
+import com.android.settings.fuelgauge.PowerUsageSummary;
+import com.android.settings.inputmethod.InputMethodAndLanguageSettings;
+import com.android.settings.location.LocationSettings;
+import com.android.settings.notification.NotificationDisplaySettings;
+import com.android.settings.notification.NotificationSettings;
+import com.android.settings.notification.OtherSoundSettings;
+import com.android.settings.notification.ZenModeSettings;
+import com.android.settings.print.PrintSettingsFragment;
+import com.android.settings.users.UserSettings;
+import com.android.settings.wifi.AdvancedWifiSettings;
+import com.android.settings.wifi.WifiSettings;
+
+import java.util.HashMap;
+
+/**
+ * Utility class for dealing with Search Ranking.
+ */
+public final class Ranking {
+
+    public static final int RANK_WIFI = 1;
+    public static final int RANK_BT = 2;
+    public static final int RANK_DATA_USAGE = 3;
+    public static final int RANK_WIRELESS = 4;
+    public static final int RANK_HOME = 5;
+    public static final int RANK_DISPLAY = 6;
+    public static final int RANK_WALLPAPER = 7;
+    public static final int RANK_NOTIFICATIONS = 8;
+    public static final int RANK_MEMORY = 9;
+    public static final int RANK_POWER_USAGE = 10;
+    public static final int RANK_USERS = 11;
+    public static final int RANK_LOCATION = 12;
+    public static final int RANK_SECURITY = 13;
+    public static final int RANK_IME = 14;
+    public static final int RANK_PRIVACY = 15;
+    public static final int RANK_DATE_TIME = 16;
+    public static final int RANK_ACCESSIBILITY = 17;
+    public static final int RANK_PRINTING = 18;
+    public static final int RANK_DEVELOPEMENT = 19;
+    public static final int RANK_DEVICE_INFO = 20;
+
+    public static final int RANK_UNDEFINED = -1;
+    public static final int RANK_OTHERS = 1024;
+    public static final int BASE_RANK_DEFAULT = 2048;
+
+    public static int sCurrentBaseRank = BASE_RANK_DEFAULT;
+
+    private static HashMap<String, Integer> sRankMap = new HashMap<String, Integer>();
+    private static HashMap<String, Integer> sBaseRankMap = new HashMap<String, Integer>();
+
+    static {
+        sRankMap.put(WifiSettings.class.getName(), RANK_WIFI);
+        sRankMap.put(AdvancedWifiSettings.class.getName(), RANK_WIFI);
+
+        sRankMap.put(BluetoothSettings.class.getName(), RANK_BT);
+
+        sRankMap.put(DataUsageSummary.class.getName(), RANK_DATA_USAGE);
+
+        sRankMap.put(WirelessSettings.class.getName(), RANK_WIRELESS);
+
+        sRankMap.put(HomeSettings.class.getName(), RANK_HOME);
+
+        sRankMap.put(DisplaySettings.class.getName(), RANK_DISPLAY);
+
+        sRankMap.put(WallpaperTypeSettings.class.getName(), RANK_WALLPAPER);
+
+        sRankMap.put(NotificationSettings.class.getName(), RANK_NOTIFICATIONS);
+        sRankMap.put(NotificationDisplaySettings.class.getName(), RANK_NOTIFICATIONS);
+        sRankMap.put(OtherSoundSettings.class.getName(), RANK_NOTIFICATIONS);
+        sRankMap.put(ZenModeSettings.class.getName(), RANK_NOTIFICATIONS);
+
+        sRankMap.put(Memory.class.getName(), RANK_MEMORY);
+
+        sRankMap.put(PowerUsageSummary.class.getName(), RANK_POWER_USAGE);
+
+        sRankMap.put(UserSettings.class.getName(), RANK_USERS);
+
+        sRankMap.put(LocationSettings.class.getName(), RANK_LOCATION);
+
+        sRankMap.put(SecuritySettings.class.getName(), RANK_SECURITY);
+        sRankMap.put(ChooseLockGeneric.ChooseLockGenericFragment.class.getName(), RANK_SECURITY);
+
+        sRankMap.put(InputMethodAndLanguageSettings.class.getName(), RANK_IME);
+
+        sRankMap.put(PrivacySettings.class.getName(), RANK_PRIVACY);
+
+        sRankMap.put(DateTimeSettings.class.getName(), RANK_DATE_TIME);
+
+        sRankMap.put(AccessibilitySettings.class.getName(), RANK_ACCESSIBILITY);
+
+        sRankMap.put(PrintSettingsFragment.class.getName(), RANK_PRINTING);
+
+        sRankMap.put(DevelopmentSettings.class.getName(), RANK_DEVELOPEMENT);
+
+        sRankMap.put(DeviceInfoSettings.class.getName(), RANK_DEVICE_INFO);
+
+        sBaseRankMap.put("com.android.settings", 0);
+    }
+
+    public static int getRankForClassName(String className) {
+        Integer rank = sRankMap.get(className);
+        return (rank != null) ? (int) rank: RANK_OTHERS;
+    }
+
+    public static int getBaseRankForAuthority(String authority) {
+        synchronized (sBaseRankMap) {
+            Integer base = sBaseRankMap.get(authority);
+            if (base != null) {
+                return base;
+            }
+            sCurrentBaseRank++;
+            sBaseRankMap.put(authority, sCurrentBaseRank);
+            return sCurrentBaseRank;
+        }
+    }
+}
diff --git a/src/com/android/settings/search/SearchIndexableResources.java b/src/com/android/settings/search/SearchIndexableResources.java
index 2d6388f..5156648 100644
--- a/src/com/android/settings/search/SearchIndexableResources.java
+++ b/src/com/android/settings/search/SearchIndexableResources.java
@@ -52,179 +52,183 @@
 
     public static int NO_DATA_RES_ID = 0;
 
-    public static final int RANK_WIFI = 1;
-    public static final int RANK_BT = 2;
-    public static final int RANK_DATA_USAGE = 3;
-    public static final int RANK_WIRELESS = 4;
-    public static final int RANK_HOME = 5;
-    public static final int RANK_DISPLAY = 7;
-    public static final int RANK_WALLPAPER = 7;
-    public static final int RANK_NOTIFICATIONS = 8;
-    public static final int RANK_MEMORY = 9;
-    public static final int RANK_POWER_USAGE = 10;
-    public static final int RANK_USERS = 11;
-    public static final int RANK_LOCATION = 12;
-    public static final int RANK_SECURITY = 13;
-    public static final int RANK_IME = 14;
-    public static final int RANK_PRIVACY = 15;
-    public static final int RANK_DATE_TIME = 16;
-    public static final int RANK_ACCESSIBILITY = 17;
-    public static final int RANK_PRINTING = 18;
-    public static final int RANK_DEVELOPEMENT = 19;
-    public static final int RANK_DEVICE_INFO = 20;
-
     private static HashMap<String, SearchIndexableResource> sResMap =
             new HashMap<String, SearchIndexableResource>();
 
-
     static {
         sResMap.put(WifiSettings.class.getName(),
-                new SearchIndexableResource(RANK_WIFI,
+                new SearchIndexableResource(
+                        Ranking.getRankForClassName(WifiSettings.class.getName()),
                         NO_DATA_RES_ID,
                         WifiSettings.class.getName(),
                         R.drawable.ic_settings_wireless));
 
         sResMap.put(WifiSettings.class.getName(),
-                new SearchIndexableResource(RANK_WIFI,
+                new SearchIndexableResource(
+                        Ranking.getRankForClassName(AdvancedWifiSettings.class.getName()),
                         R.xml.wifi_advanced_settings,
                         AdvancedWifiSettings.class.getName(),
                         R.drawable.ic_settings_wireless));
 
         sResMap.put(BluetoothSettings.class.getName(),
-                new SearchIndexableResource(RANK_BT,
+                new SearchIndexableResource(
+                        Ranking.getRankForClassName(BluetoothSettings.class.getName()),
                         NO_DATA_RES_ID,
                         BluetoothSettings.class.getName(),
                         R.drawable.ic_settings_bluetooth2));
 
         sResMap.put(DataUsageSummary.class.getName(),
-                new SearchIndexableResource(RANK_DATA_USAGE,
+                new SearchIndexableResource(
+                        Ranking.getRankForClassName(DataUsageSummary.class.getName()),
                         NO_DATA_RES_ID,
                         DataUsageSummary.class.getName(),
                         R.drawable.ic_settings_data_usage));
 
         sResMap.put(WirelessSettings.class.getName(),
-                new SearchIndexableResource(RANK_WIRELESS,
+                new SearchIndexableResource(
+                        Ranking.getRankForClassName(WirelessSettings.class.getName()),
                         R.xml.wireless_settings,
                         WirelessSettings.class.getName(),
                         R.drawable.empty_icon));
 
         sResMap.put(HomeSettings.class.getName(),
-                new SearchIndexableResource(RANK_HOME,
+                new SearchIndexableResource(
+                        Ranking.getRankForClassName(HomeSettings.class.getName()),
                         R.xml.home_selection,
                         HomeSettings.class.getName(),
                         R.drawable.ic_settings_home));
 
         sResMap.put(DisplaySettings.class.getName(),
-                new SearchIndexableResource(RANK_DISPLAY,
+                new SearchIndexableResource(
+                        Ranking.getRankForClassName(DisplaySettings.class.getName()),
                         R.xml.display_settings,
                         DisplaySettings.class.getName(),
                         R.drawable.ic_settings_display));
 
         sResMap.put(WallpaperTypeSettings.class.getName(),
-                new SearchIndexableResource(RANK_WALLPAPER,
+                new SearchIndexableResource(
+                        Ranking.getRankForClassName(WallpaperTypeSettings.class.getName()),
                         NO_DATA_RES_ID,
                         WallpaperTypeSettings.class.getName(),
                         R.drawable.ic_settings_display));
 
         sResMap.put(NotificationSettings.class.getName(),
-                new SearchIndexableResource(RANK_NOTIFICATIONS,
+                new SearchIndexableResource(
+                        Ranking.getRankForClassName(NotificationSettings.class.getName()),
                         NO_DATA_RES_ID,
                         NotificationSettings.class.getName(),
                         R.drawable.ic_settings_notifications));
 
         sResMap.put(NotificationDisplaySettings.class.getName(),
-                new SearchIndexableResource(RANK_NOTIFICATIONS,
+                new SearchIndexableResource(
+                        Ranking.getRankForClassName(NotificationDisplaySettings.class.getName()),
                         R.xml.notification_display_settings,
                         NotificationDisplaySettings.class.getName(),
                         R.drawable.ic_settings_notifications));
 
         sResMap.put(OtherSoundSettings.class.getName(),
-                new SearchIndexableResource(RANK_NOTIFICATIONS,
+                new SearchIndexableResource(
+                        Ranking.getRankForClassName(OtherSoundSettings.class.getName()),
                         NO_DATA_RES_ID,
                         OtherSoundSettings.class.getName(),
                         R.drawable.ic_settings_notifications));
 
         sResMap.put(ZenModeSettings.class.getName(),
-                new SearchIndexableResource(RANK_NOTIFICATIONS,
+                new SearchIndexableResource(
+                        Ranking.getRankForClassName(ZenModeSettings.class.getName()),
                         NO_DATA_RES_ID,
                         ZenModeSettings.class.getName(),
                         R.drawable.ic_settings_notifications));
 
         sResMap.put(Memory.class.getName(),
-                new SearchIndexableResource(RANK_MEMORY,
+                new SearchIndexableResource(
+                        Ranking.getRankForClassName(Memory.class.getName()),
                         NO_DATA_RES_ID,
                         Memory.class.getName(),
                         R.drawable.ic_settings_storage));
 
         sResMap.put(PowerUsageSummary.class.getName(),
-                new SearchIndexableResource(RANK_POWER_USAGE,
+                new SearchIndexableResource(
+                        Ranking.getRankForClassName(PowerUsageSummary.class.getName()),
                         R.xml.power_usage_summary,
                         PowerUsageSummary.class.getName(),
                         R.drawable.ic_settings_battery));
 
         sResMap.put(UserSettings.class.getName(),
-                new SearchIndexableResource(RANK_USERS,
+                new SearchIndexableResource(
+                        Ranking.getRankForClassName(UserSettings.class.getName()),
                         R.xml.user_settings,
                         UserSettings.class.getName(),
                         R.drawable.ic_settings_multiuser));
 
         sResMap.put(LocationSettings.class.getName(),
-                new SearchIndexableResource(RANK_LOCATION,
+                new SearchIndexableResource(
+                        Ranking.getRankForClassName(LocationSettings.class.getName()),
                         R.xml.location_settings,
                         LocationSettings.class.getName(),
                         R.drawable.ic_settings_location));
 
         sResMap.put(SecuritySettings.class.getName(),
-                new SearchIndexableResource(RANK_SECURITY,
+                new SearchIndexableResource(
+                        Ranking.getRankForClassName(SecuritySettings.class.getName()),
                         NO_DATA_RES_ID,
                         SecuritySettings.class.getName(),
                         R.drawable.ic_settings_security));
 
         sResMap.put(ChooseLockGeneric.ChooseLockGenericFragment.class.getName(),
-                new SearchIndexableResource(RANK_SECURITY,
+                new SearchIndexableResource(
+                        Ranking.getRankForClassName(
+                                ChooseLockGeneric.ChooseLockGenericFragment.class.getName()),
                         R.xml.security_settings_picker,
                         ChooseLockGeneric.ChooseLockGenericFragment.class.getName(),
                         R.drawable.ic_settings_security));
 
         sResMap.put(InputMethodAndLanguageSettings.class.getName(),
-                new SearchIndexableResource(RANK_IME,
+                new SearchIndexableResource(
+                        Ranking.getRankForClassName(InputMethodAndLanguageSettings.class.getName()),
                         NO_DATA_RES_ID,
                         InputMethodAndLanguageSettings.class.getName(),
                         R.drawable.ic_settings_language));
 
         sResMap.put(PrivacySettings.class.getName(),
-                new SearchIndexableResource(RANK_PRIVACY,
+                new SearchIndexableResource(
+                        Ranking.getRankForClassName(PrivacySettings.class.getName()),
                         R.xml.privacy_settings,
                         PrivacySettings.class.getName(),
                         R.drawable.ic_settings_backup));
 
         sResMap.put(DateTimeSettings.class.getName(),
-                new SearchIndexableResource(RANK_DATE_TIME,
+                new SearchIndexableResource(
+                        Ranking.getRankForClassName(DateTimeSettings.class.getName()),
                         R.xml.date_time_prefs,
                         DateTimeSettings.class.getName(),
                         R.drawable.ic_settings_date_time));
 
         sResMap.put(AccessibilitySettings.class.getName(),
-                new SearchIndexableResource(RANK_ACCESSIBILITY,
+                new SearchIndexableResource(
+                        Ranking.getRankForClassName(AccessibilitySettings.class.getName()),
                         NO_DATA_RES_ID,
                         AccessibilitySettings.class.getName(),
                         R.drawable.ic_settings_accessibility));
 
         sResMap.put(PrintSettingsFragment.class.getName(),
-                new SearchIndexableResource(RANK_PRINTING,
+                new SearchIndexableResource(
+                        Ranking.getRankForClassName(PrintSettingsFragment.class.getName()),
                         NO_DATA_RES_ID,
                         PrintSettingsFragment.class.getName(),
                         R.drawable.ic_settings_print));
 
         sResMap.put(DevelopmentSettings.class.getName(),
-                new SearchIndexableResource(RANK_DEVELOPEMENT,
+                new SearchIndexableResource(
+                        Ranking.getRankForClassName(DevelopmentSettings.class.getName()),
                         R.xml.development_prefs,
                         DevelopmentSettings.class.getName(),
                         R.drawable.ic_settings_development));
 
         sResMap.put(DeviceInfoSettings.class.getName(),
-                new SearchIndexableResource(RANK_DEVICE_INFO,
-                        R.xml.device_info_settings,
+                new SearchIndexableResource(
+                        Ranking.getRankForClassName(DeviceInfoSettings.class.getName()),
+                        NO_DATA_RES_ID,
                         DeviceInfoSettings.class.getName(),
                         R.drawable.ic_settings_about));
     }