diff --git a/src/com/android/settings/search/Index.java b/src/com/android/settings/search/Index.java index 246e8a04ae9..987539b7bc3 100644 --- a/src/com/android/settings/search/Index.java +++ b/src/com/android/settings/search/Index.java @@ -61,14 +61,16 @@ public class Index { public static final int COLUMN_INDEX_SUMMARY_ON = 2; public static final int COLUMN_INDEX_SUMMARY_OFF = 3; public static final int COLUMN_INDEX_ENTRIES = 4; - public static final int COLUMN_INDEX_KEYWORDS = 5; - public static final int COLUMN_INDEX_CLASS_NAME = 6; - public static final int COLUMN_INDEX_SCREEN_TITLE = 7; - public static final int COLUMN_INDEX_ICON = 8; - public static final int COLUMN_INDEX_INTENT_ACTION = 9; - public static final int COLUMN_INDEX_INTENT_ACTION_TARGET_PACKAGE = 10; - public static final int COLUMN_INDEX_INTENT_ACTION_TARGET_CLASS = 11; - public static final int COLUMN_INDEX_ENABLED = 12; + public static final int COLUMN_INDEX_SWITCH_ON = 5; + public static final int COLUMN_INDEX_SWITCH_OFF = 6; + public static final int COLUMN_INDEX_KEYWORDS = 7; + public static final int COLUMN_INDEX_CLASS_NAME = 8; + public static final int COLUMN_INDEX_SCREEN_TITLE = 9; + public static final int COLUMN_INDEX_ICON = 10; + public static final int COLUMN_INDEX_INTENT_ACTION = 11; + public static final int COLUMN_INDEX_INTENT_ACTION_TARGET_PACKAGE = 12; + public static final int COLUMN_INDEX_INTENT_ACTION_TARGET_CLASS = 13; + public static final int COLUMN_INDEX_ENABLED = 14; // If you change the order of columns here, you SHOULD change the COLUMN_INDEX_XXX values private static final String[] SELECT_COLUMNS = new String[] { @@ -77,13 +79,15 @@ public class Index { IndexColumns.DATA_SUMMARY_ON, // 2 IndexColumns.DATA_SUMMARY_OFF, // 3 IndexColumns.DATA_ENTRIES, // 4 - IndexColumns.DATA_KEYWORDS, // 5 - IndexColumns.CLASS_NAME, // 6 - IndexColumns.SCREEN_TITLE, // 7 - IndexColumns.ICON, // 8 - IndexColumns.INTENT_ACTION, // 9 - IndexColumns.INTENT_TARGET_PACKAGE, // 10 - IndexColumns.INTENT_TARGET_CLASS // 11 + IndexColumns.DATA_SWITCH_ON, // 5 + IndexColumns.DATA_SWITCH_OFF, // 6 + IndexColumns.DATA_KEYWORDS, // 7 + IndexColumns.CLASS_NAME, // 8 + IndexColumns.SCREEN_TITLE, // 9 + IndexColumns.ICON, // 10 + IndexColumns.INTENT_ACTION, // 11 + IndexColumns.INTENT_TARGET_PACKAGE, // 12 + IndexColumns.INTENT_TARGET_CLASS // 13 }; private static final String[] MATCH_COLUMNS = { @@ -93,6 +97,10 @@ public class Index { IndexColumns.DATA_SUMMARY_ON_NORMALIZED, IndexColumns.DATA_SUMMARY_OFF, IndexColumns.DATA_SUMMARY_OFF_NORMALIZED, + IndexColumns.DATA_SWITCH_ON, + IndexColumns.DATA_SWITCH_ON_NORMALIZED, + IndexColumns.DATA_SWITCH_OFF, + IndexColumns.DATA_SWITCH_OFF_NORMALIZED, IndexColumns.DATA_ENTRIES, IndexColumns.DATA_KEYWORDS }; @@ -107,6 +115,7 @@ public class Index { private static final String NODE_NAME_PREFERENCE_SCREEN = "PreferenceScreen"; private static final String NODE_NAME_CHECK_BOX_PREFERENCE = "CheckBoxPreference"; private static final String NODE_NAME_LIST_PREFERENCE = "ListPreference"; + private static final String NODE_NAME_SWITCH_PREFERENCE = "SwitchPreference"; private static Index sInstance; private final AtomicBoolean mIsAvailable = new AtomicBoolean(false); @@ -353,16 +362,18 @@ public class Index { final String summaryOn = cursor.getString(2); final String summaryOff = cursor.getString(3); final String entries = cursor.getString(4); - final String keywords = cursor.getString(5); + final String switchOn = cursor.getString(5); + final String switchOff = cursor.getString(6); + final String keywords = cursor.getString(7); - final String screenTitle = cursor.getString(6); + final String screenTitle = cursor.getString(8); - final String className = cursor.getString(7); - final int iconResId = cursor.getInt(8); + final String className = cursor.getString(9); + final int iconResId = cursor.getInt(10); - final String action = cursor.getString(9); - final String targetPackage = cursor.getString(10); - final String targetClass = cursor.getString(11); + final String action = cursor.getString(11); + final String targetPackage = cursor.getString(12); + final String targetClass = cursor.getString(13); SearchIndexableRaw data = new SearchIndexableRaw(packageContext); data.rank = rank; @@ -370,6 +381,8 @@ public class Index { data.summaryOn = summaryOn; data.summaryOff = summaryOff; data.entries = entries; + data.switchOn = switchOn; + data.switchOff = switchOff; data.keywords = keywords; data.screenTitle = screenTitle; data.className = className; @@ -494,7 +507,7 @@ public class Index { // Insert rows for the main PreferenceScreen node. Rewrite the data for removing // hyphens. updateOneRowWithFilteredData(database, localeStr, title, summary, null, null, - fragmentName, screenTitle, iconResId, rank, keywords, + null, null, fragmentName, screenTitle, iconResId, rank, keywords, intentAction, intentTargetPackage, intentTargetClass, true); while ((type = parser.next()) != XmlPullParser.END_DOCUMENT @@ -512,20 +525,26 @@ public class Index { summary = getDataSummary(context, attrs); String entries = null; + String switchOn = null; + String switchOff = null; + if (nodeName.endsWith(NODE_NAME_LIST_PREFERENCE)) { entries = getDataEntries(context, attrs); + } else if (nodeName.endsWith(NODE_NAME_SWITCH_PREFERENCE)) { + switchOn = getDataSwitchOn(context, attrs); + switchOff = getDataSwitchOff(context, attrs); } // Insert rows for the child nodes of PreferenceScreen updateOneRowWithFilteredData(database, localeStr, title, summary, null, entries, - fragmentName, screenTitle, iconResId, rank, keywords, + switchOn, switchOff, fragmentName, screenTitle, iconResId, rank, keywords, intentAction, intentTargetPackage, intentTargetClass, true); } else if (nodeName.equals(NODE_NAME_CHECK_BOX_PREFERENCE)) { final String summaryOn = getDataSummaryOn(context, attrs); final String summaryOff = getDataSummaryOff(context, attrs); updateOneRowWithFilteredData(database, localeStr, title, summaryOn, summaryOff, - null, fragmentName, screenTitle, iconResId, rank, keywords, + null, null, null, fragmentName, screenTitle, iconResId, rank, keywords, intentAction, intentTargetPackage, intentTargetClass, true); } } @@ -551,6 +570,8 @@ public class Index { raw.summaryOn, raw.summaryOff, raw.entries, + raw.switchOn, + raw.switchOff, raw.className, raw.screenTitle, raw.iconResId, @@ -588,6 +609,8 @@ public class Index { raw.summaryOn, raw.summaryOff, raw.entries, + raw.switchOn, + raw.switchOff, sir.className, raw.screenTitle, sir.iconResId, @@ -630,7 +653,8 @@ public class Index { } private void updateOneRowWithFilteredData(SQLiteDatabase database, String locale, - String title, String summaryOn, String summaryOff, String entries, String className, + String title, String summaryOn, String summaryOff, String entries, + String switchOn, String switchOff, String className, String screenTitle, int iconResId, int rank, String keywords, String intentAction, String intentTargetPackage, String intentTargetClass, boolean enabled) { @@ -657,21 +681,41 @@ public class Index { updatedSummaryOff = EMPTY; } + String updatedSwitchOn; + if (switchOn != null) { + updatedSwitchOn = switchOn.replaceAll(NON_BREAKING_HYPHEN, HYPHEN); + } else { + updatedSwitchOn = EMPTY; + } + + String updatedSwitchOff; + if (switchOff != null) { + updatedSwitchOff = switchOff.replaceAll(NON_BREAKING_HYPHEN, HYPHEN); + } else { + updatedSwitchOff = EMPTY; + } + String normalizedTitle = updatedTitle.replaceAll(HYPHEN, EMPTY); String normalizedSummaryOn = updatedSummaryOn.replaceAll(HYPHEN, EMPTY); String normalizedSummaryOff = updatedSummaryOff.replaceAll(HYPHEN, EMPTY); + String normalizedSwitchOn = updatedSwitchOn.replaceAll(HYPHEN, EMPTY); + String normalizedSwitchOff = updatedSwitchOff.replaceAll(HYPHEN, EMPTY); updateOneRow(database, locale, updatedTitle, normalizedTitle, updatedSummaryOn, normalizedSummaryOn, - updatedSummaryOff, normalizedSummaryOff, entries, className, screenTitle, iconResId, + updatedSummaryOff, normalizedSummaryOff, entries, + updatedSwitchOn, normalizedSwitchOn, updatedSwitchOff, normalizedSwitchOff, + className, screenTitle, iconResId, rank, keywords, intentAction, intentTargetPackage, intentTargetClass, enabled); } private void updateOneRow(SQLiteDatabase database, String locale, String updatedTitle, String normalizedTitle, String updatedSummaryOn, String normalizedSummaryOn, - String updatedSummaryOff, String normalizedSummaryOff, String entries, String className, - String screenTitle, int iconResId, int rank, String keywords, + String updatedSummaryOff, String normalizedSummaryOff, String entries, + String updatedSwitchOn, String normalizedSwitchOn, + String updatedSwitchOff, String normalizedSwitchOff, + String className, String screenTitle, int iconResId, int rank, String keywords, String intentAction, String intentTargetPackage, String intentTargetClass, boolean enabled) { @@ -690,6 +734,10 @@ public class Index { values.put(IndexColumns.DATA_SUMMARY_OFF, updatedSummaryOff); values.put(IndexColumns.DATA_SUMMARY_OFF_NORMALIZED, normalizedSummaryOff); values.put(IndexColumns.DATA_ENTRIES, entries); + values.put(IndexColumns.DATA_SWITCH_ON, updatedSwitchOn); + values.put(IndexColumns.DATA_SWITCH_ON_NORMALIZED, normalizedSwitchOn); + values.put(IndexColumns.DATA_SWITCH_OFF, updatedSwitchOff); + values.put(IndexColumns.DATA_SWITCH_OFF_NORMALIZED, normalizedSwitchOff); values.put(IndexColumns.DATA_KEYWORDS, keywords); values.put(IndexColumns.CLASS_NAME, className); values.put(IndexColumns.SCREEN_TITLE, screenTitle); @@ -732,6 +780,18 @@ public class Index { com.android.internal.R.styleable.ListPreference_entries); } + private String getDataSwitchOn(Context context, AttributeSet attrs) { + return getData(context, attrs, + com.android.internal.R.styleable.SwitchPreference, + com.android.internal.R.styleable.SwitchPreference_switchTextOn); + } + + private String getDataSwitchOff(Context context, AttributeSet attrs) { + return getData(context, attrs, + com.android.internal.R.styleable.SwitchPreference, + com.android.internal.R.styleable.SwitchPreference_switchTextOff); + } + private String getDataKeywords(Context context, AttributeSet attrs) { return getData(context, attrs, R.styleable.Preference, R.styleable.Preference_keywords); } diff --git a/src/com/android/settings/search/IndexDatabaseHelper.java b/src/com/android/settings/search/IndexDatabaseHelper.java index 65db6b439e3..bd035c37e18 100644 --- a/src/com/android/settings/search/IndexDatabaseHelper.java +++ b/src/com/android/settings/search/IndexDatabaseHelper.java @@ -28,7 +28,7 @@ public class IndexDatabaseHelper extends SQLiteOpenHelper { private static final String TAG = "IndexDatabaseHelper"; private static final String DATABASE_NAME = "search_index.db"; - private static final int DATABASE_VERSION = 105; + private static final int DATABASE_VERSION = 106; public interface Tables { public static final String TABLE_PREFS_INDEX = "prefs_index"; @@ -46,6 +46,10 @@ public class IndexDatabaseHelper extends SQLiteOpenHelper { public static final String DATA_SUMMARY_OFF = "data_summary_off"; public static final String DATA_SUMMARY_OFF_NORMALIZED = "data_summary_off_normalized"; public static final String DATA_ENTRIES = "data_entries"; + public static final String DATA_SWITCH_ON = "data_switch_on"; + public static final String DATA_SWITCH_ON_NORMALIZED = "data_switch_on_normalized"; + public static final String DATA_SWITCH_OFF = "data_switch_off"; + public static final String DATA_SWITCH_OFF_NORMALIZED = "data_switch_off_normalized"; public static final String DATA_KEYWORDS = "data_keywords"; public static final String CLASS_NAME = "class_name"; public static final String SCREEN_TITLE = "screen_title"; @@ -81,6 +85,14 @@ public class IndexDatabaseHelper extends SQLiteOpenHelper { ", " + IndexColumns.DATA_ENTRIES + ", " + + IndexColumns.DATA_SWITCH_ON + + ", " + + IndexColumns.DATA_SWITCH_ON_NORMALIZED + + ", " + + IndexColumns.DATA_SWITCH_OFF + + ", " + + IndexColumns.DATA_SWITCH_OFF_NORMALIZED + + ", " + IndexColumns.DATA_KEYWORDS + ", " + IndexColumns.SCREEN_TITLE + @@ -153,7 +165,7 @@ public class IndexDatabaseHelper extends SQLiteOpenHelper { @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { - if (oldVersion == 100 || oldVersion == 101 || oldVersion == 102 || oldVersion == 103) { + if (oldVersion < DATABASE_VERSION) { Log.w(TAG, "Detected schema version '" + oldVersion + "'. " + "Index needs to be rebuilt for schema version '" + newVersion + "'."); // We need to drop the tables and recreate them diff --git a/src/com/android/settings/search/SearchIndexableRaw.java b/src/com/android/settings/search/SearchIndexableRaw.java index c4d187e971b..e661c87a538 100644 --- a/src/com/android/settings/search/SearchIndexableRaw.java +++ b/src/com/android/settings/search/SearchIndexableRaw.java @@ -32,6 +32,8 @@ public class SearchIndexableRaw extends SearchIndexableData { public String summaryOn; public String summaryOff; public String entries; + public String switchOn; + public String switchOff; public String keywords; public String screenTitle;