Create whitelist for the most popular settings
As a temporary solution to getting the most popular settings to be the top rank, we have created a white list. If a prioritized setting shows up somewhere in the results then it will be given an elevated rank to be at the top. Bug: 35048659 Test: make RunSettingsRoboTests Change-Id: I92b563a17b42d8f91d980dd1d8e5f8f29ca5aa9c
This commit is contained in:
@@ -99,6 +99,8 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem
|
||||
|
||||
private final IntentFilter mIntentFilter;
|
||||
|
||||
// For Search
|
||||
private static final String DATA_KEY_REFERENCE = "main_toggle_bluetooth";
|
||||
|
||||
// accessed from inner class (not private to avoid thunks)
|
||||
FooterPreference mMyDevicePreference;
|
||||
@@ -567,6 +569,7 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem
|
||||
SearchIndexableRaw data = new SearchIndexableRaw(context);
|
||||
data.title = res.getString(R.string.bluetooth_settings);
|
||||
data.screenTitle = res.getString(R.string.bluetooth_settings);
|
||||
data.key = DATA_KEY_REFERENCE;
|
||||
result.add(data);
|
||||
|
||||
// Add cached paired BT devices
|
||||
|
@@ -35,6 +35,7 @@ import com.android.settings.Utils;
|
||||
import com.android.settings.dashboard.SiteMapManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
@@ -77,6 +78,22 @@ class CursorToSearchResultConverter {
|
||||
|
||||
private final Set<String> mKeys;
|
||||
|
||||
private final int LONG_TITLE_LENGTH = 20;
|
||||
|
||||
private static final String[] whiteList = {
|
||||
"main_toggle_wifi",
|
||||
"main_toggle_bluetooth",
|
||||
"toggle_airplane",
|
||||
"tether_settings",
|
||||
"battery_saver",
|
||||
"toggle_nfc",
|
||||
"restrict_background",
|
||||
"data_usage_enable",
|
||||
"button_roaming_key",
|
||||
};
|
||||
private static final Set<String> prioritySettings = new HashSet(Arrays.asList(whiteList));
|
||||
|
||||
|
||||
public CursorToSearchResultConverter(Context context, String queryText) {
|
||||
mContext = context;
|
||||
mKeys = new HashSet<>();
|
||||
@@ -135,7 +152,7 @@ class CursorToSearchResultConverter {
|
||||
}
|
||||
|
||||
final List<String> breadcrumbs = getBreadcrumbs(sitemapManager, cursor);
|
||||
final int rank = getRank(breadcrumbs, baseRank);
|
||||
final int rank = getRank(title, breadcrumbs, baseRank, key);
|
||||
|
||||
final SearchResult.Builder builder = new SearchResult.Builder();
|
||||
builder.addTitle(title)
|
||||
@@ -225,18 +242,32 @@ class CursorToSearchResultConverter {
|
||||
}
|
||||
|
||||
/** Uses the breadcrumbs to determine the offset to the base rank.
|
||||
* There are two checks
|
||||
* A) If the query matches the highest level menu title
|
||||
* B) If the query matches a subsequent menu title
|
||||
* There are three checks
|
||||
* A) If the result is prioritized and the highest base level
|
||||
* B) If the query matches the highest level menu title
|
||||
* C) If the query matches a subsequent menu title
|
||||
* D) Is the title longer than 20
|
||||
*
|
||||
* If the query matches A and B, the offset is 0.
|
||||
* If the query matches A only, the offset is 1.
|
||||
* If the query matches neither A nor B, the offset is 2.
|
||||
* If the query matches A, set it to TOP_RANK
|
||||
* If the query matches B and C, the offset is 0.
|
||||
* If the query matches C only, the offset is 1.
|
||||
* If the query matches neither B nor C, the offset is 2.
|
||||
* If the query matches D, the offset is 2
|
||||
|
||||
* @param title of the result.
|
||||
* @param crumbs from the Information Architecture
|
||||
* @param baseRank of the result. Lower if it's a better result.
|
||||
* @return
|
||||
*/
|
||||
private int getRank(List<String> crumbs, int baseRank) {
|
||||
private int getRank(String title, List<String> crumbs, int baseRank, String key) {
|
||||
// The result can only be prioritized if it is a top ranked result.
|
||||
if (prioritySettings.contains(key) && baseRank < DatabaseResultLoader.BASE_RANKS[1]) {
|
||||
return SearchResult.TOP_RANK;
|
||||
}
|
||||
if (title.length() > LONG_TITLE_LENGTH) {
|
||||
return baseRank + 2;
|
||||
}
|
||||
return baseRank;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -97,7 +97,7 @@ public class DatabaseResultLoader extends AsyncLoader<List<? extends SearchResul
|
||||
* If the query only matches keywords or entries, the best rank it can be is 9
|
||||
*
|
||||
*/
|
||||
private static final int[] BASE_RANKS = {1, 3, 7, 9};
|
||||
public static final int[] BASE_RANKS = {1, 3, 7, 9};
|
||||
|
||||
private final String mQueryText;
|
||||
private final Context mContext;
|
||||
|
@@ -27,10 +27,15 @@ import java.util.Objects;
|
||||
public class SearchResult implements Comparable<SearchResult> {
|
||||
|
||||
/**
|
||||
* Defines the max rank for a search result to be considered as ranked. Results with ranks
|
||||
* Defines the lowest rank for a search result to be considered as ranked. Results with ranks
|
||||
* higher than this have no guarantee for sorting order.
|
||||
*/
|
||||
public static final int MAX_RANK = 10;
|
||||
public static final int BOTTOM_RANK = 10;
|
||||
|
||||
/**
|
||||
* Defines the highest rank for a search result. Used for special search results only.
|
||||
*/
|
||||
public static final int TOP_RANK = 0;
|
||||
|
||||
/**
|
||||
* The title of the result and main text displayed.
|
||||
|
@@ -32,7 +32,8 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.android.settings.search2.SearchResult.MAX_RANK;
|
||||
import static com.android.settings.search2.SearchResult.TOP_RANK;
|
||||
import static com.android.settings.search2.SearchResult.BOTTOM_RANK;
|
||||
|
||||
public class SearchResultsAdapter extends Adapter<SearchViewHolder> {
|
||||
|
||||
@@ -117,9 +118,9 @@ public class SearchResultsAdapter extends Adapter<SearchViewHolder> {
|
||||
|
||||
int dbIndex = 0;
|
||||
int appIndex = 0;
|
||||
int rank = 1;
|
||||
int rank = TOP_RANK;
|
||||
|
||||
while (rank <= MAX_RANK) {
|
||||
while (rank <= BOTTOM_RANK) {
|
||||
while ((dbIndex < dbSize) && (databaseResults.get(dbIndex).rank == rank)) {
|
||||
results.add(databaseResults.get(dbIndex++));
|
||||
}
|
||||
|
@@ -168,6 +168,9 @@ public class WifiSettings extends RestrictedSettingsFragment
|
||||
|
||||
private MenuItem mScanMenuItem;
|
||||
|
||||
// For Search
|
||||
private static final String DATA_KEY_REFERENCE = "main_toggle_wifi";
|
||||
|
||||
/* End of "used in Wifi Setup context" */
|
||||
|
||||
public WifiSettings() {
|
||||
@@ -1028,6 +1031,7 @@ public class WifiSettings extends RestrictedSettingsFragment
|
||||
data.title = res.getString(R.string.wifi_settings);
|
||||
data.screenTitle = res.getString(R.string.wifi_settings);
|
||||
data.keywords = res.getString(R.string.keywords_wifi);
|
||||
data.key = DATA_KEY_REFERENCE;
|
||||
result.add(data);
|
||||
|
||||
// Add saved Wi-Fi access points
|
||||
|
Reference in New Issue
Block a user