Merge "Add public intent filters to indexing" into oc-dr1-dev
diff --git a/src/com/android/settings/search/DatabaseIndexingManager.java b/src/com/android/settings/search/DatabaseIndexingManager.java
index 98b06aa..6a6c737 100644
--- a/src/com/android/settings/search/DatabaseIndexingManager.java
+++ b/src/com/android/settings/search/DatabaseIndexingManager.java
@@ -17,6 +17,8 @@
package com.android.settings.search;
+import com.android.settings.R;
+
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.ContentValues;
@@ -858,7 +860,8 @@
List<String> nonIndexableKeys) {
final String className = sir.className;
- final int rank = sir.rank;
+ final String intentAction = sir.intentAction;
+ final String intentTargetPackage = sir.intentTargetPackage;
if (provider == null) {
Log.w(LOG_TAG, "Cannot find provider: " + className);
@@ -886,7 +889,6 @@
.setClassName(className)
.setScreenTitle(raw.screenTitle)
.setIconResId(raw.iconResId)
- .setRank(rank)
.setIntentAction(raw.intentAction)
.setIntentTargetPackage(raw.intentTargetPackage)
.setIntentTargetClass(raw.intentTargetClass)
@@ -911,7 +913,15 @@
continue;
}
- item.className = (TextUtils.isEmpty(item.className)) ? className : item.className;
+ item.className = TextUtils.isEmpty(item.className)
+ ? className
+ : item.className;
+ item.intentAction = TextUtils.isEmpty(item.intentAction)
+ ? intentAction
+ : item.intentAction;
+ item.intentTargetPackage = TextUtils.isEmpty(item.intentTargetPackage)
+ ? intentTargetPackage
+ : item.intentTargetPackage;
indexFromResource(database, localeStr, item, nonIndexableKeys);
}
@@ -1245,7 +1255,11 @@
private Intent buildIntent(Context context) {
final Intent intent;
- if (TextUtils.isEmpty(mIntentAction)) {
+ boolean isEmptyIntentAction = TextUtils.isEmpty(mIntentAction);
+ // No intent action is set, or the intent action is for a subsetting.
+ if (isEmptyIntentAction
+ || (!isEmptyIntentAction && TextUtils.equals(mIntentTargetPackage,
+ SearchIndexableResources.SUBSETTING_TARGET_PACKAGE))) {
// Action is null, we will launch it as a sub-setting
intent = DatabaseIndexingUtils.buildSubsettingIntent(context, mClassName, mKey,
mScreenTitle);
diff --git a/src/com/android/settings/search/SearchIndexableResources.java b/src/com/android/settings/search/SearchIndexableResources.java
index 9dc34de..09080d3 100644
--- a/src/com/android/settings/search/SearchIndexableResources.java
+++ b/src/com/android/settings/search/SearchIndexableResources.java
@@ -21,6 +21,7 @@
import android.support.annotation.VisibleForTesting;
import android.support.annotation.XmlRes;
+import android.text.TextUtils;
import com.android.settings.DateTimeSettings;
import com.android.settings.DeviceInfoSettings;
import com.android.settings.DisplaySettings;
@@ -92,6 +93,12 @@
public final class SearchIndexableResources {
+ /**
+ * Identifies subsettings which have an {@link SearchIndexableResource#intentAction} but
+ * whose intents should still be treated as subsettings inside of Settings.
+ */
+ public static final String SUBSETTING_TARGET_PACKAGE = "subsetting_target_package";
+
@XmlRes
public static final int NO_DATA_RES_ID = 0;
@@ -101,8 +108,22 @@
@VisibleForTesting
static void addIndex(Class<?> indexClass, @XmlRes int xmlResId,
@DrawableRes int iconResId) {
+ addIndex(indexClass, xmlResId, iconResId, null /* targetAction */);
+ }
+
+ @VisibleForTesting
+ static void addIndex(Class<?> indexClass, @XmlRes int xmlResId,
+ @DrawableRes int iconResId, String targetAction) {
String className = indexClass.getName();
- sResMap.put(className, new SearchIndexableResource(0, xmlResId, className, iconResId));
+ SearchIndexableResource resource =
+ new SearchIndexableResource(0, xmlResId, className, iconResId);
+
+ if (!TextUtils.isEmpty(targetAction)) {
+ resource.intentAction = targetAction;
+ resource.intentTargetPackage = SUBSETTING_TARGET_PACKAGE;
+ }
+
+ sResMap.put(className, resource);
}
static {
@@ -117,14 +138,16 @@
addIndex(DataUsageSummary.class, NO_DATA_RES_ID, R.drawable.ic_settings_data_usage);
addIndex(DataUsageMeteredSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_data_usage);
addIndex(ScreenZoomSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_display);
- addIndex(DisplaySettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_display);
+ addIndex(DisplaySettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_display,
+ "android.settings.DISPLAY_SETTINGS");
addIndex(AmbientDisplaySettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_display);
addIndex(WallpaperTypeSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_display);
addIndex(ConfigureNotificationSettings.class,
R.xml.configure_notification_settings, R.drawable.ic_settings_notifications);
addIndex(AppAndNotificationDashboardFragment.class, NO_DATA_RES_ID,
R.drawable.ic_settings_applications);
- addIndex(SoundSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_sound);
+ addIndex(SoundSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_sound,
+ "android.settings.SOUND_SETTINGS");
addIndex(ZenModeSettings.class,
R.xml.zen_mode_settings, R.drawable.ic_settings_notifications);
addIndex(ZenModePrioritySettings.class,
diff --git a/src/com/android/settings/search/SettingsSearchIndexablesProvider.java b/src/com/android/settings/search/SettingsSearchIndexablesProvider.java
index f7c2a16..a13081a 100644
--- a/src/com/android/settings/search/SettingsSearchIndexablesProvider.java
+++ b/src/com/android/settings/search/SettingsSearchIndexablesProvider.java
@@ -58,8 +58,8 @@
ref[COLUMN_INDEX_XML_RES_RESID] = val.xmlResId;
ref[COLUMN_INDEX_XML_RES_CLASS_NAME] = val.className;
ref[COLUMN_INDEX_XML_RES_ICON_RESID] = val.iconResId;
- ref[COLUMN_INDEX_XML_RES_INTENT_ACTION] = null; // intent action
- ref[COLUMN_INDEX_XML_RES_INTENT_TARGET_PACKAGE] = null; // intent target package
+ ref[COLUMN_INDEX_XML_RES_INTENT_ACTION] = val.intentAction;
+ ref[COLUMN_INDEX_XML_RES_INTENT_TARGET_PACKAGE] = val.intentTargetPackage;
ref[COLUMN_INDEX_XML_RES_INTENT_TARGET_CLASS] = null; // intent target class
cursor.addRow(ref);
}
diff --git a/tests/robotests/src/com/android/settings/search/DatabaseIndexingManagerTest.java b/tests/robotests/src/com/android/settings/search/DatabaseIndexingManagerTest.java
index 8d7605b..711b355 100644
--- a/tests/robotests/src/com/android/settings/search/DatabaseIndexingManagerTest.java
+++ b/tests/robotests/src/com/android/settings/search/DatabaseIndexingManagerTest.java
@@ -587,7 +587,7 @@
// Locale
assertThat(cursor.getString(0)).isEqualTo(localeStr);
// Data Rank
- assertThat(cursor.getInt(1)).isEqualTo(rank);
+ assertThat(cursor.getInt(1)).isEqualTo(0);
// Data Title
assertThat(cursor.getString(2)).isEqualTo("Display size");
// Normalized Title
@@ -644,7 +644,7 @@
@Test
public void testResourceProvider_resourceRowMatches() {
- SearchIndexableResource resource = getFakeResource(0);
+ SearchIndexableResource resource = getFakeResource(0 /* xml */);
resource.className = "com.android.settings.display.ScreenZoomSettings";
mManager.indexOneSearchIndexableData(mDb, localeStr, resource, new HashMap<>());
@@ -654,7 +654,7 @@
// Locale
assertThat(cursor.getString(0)).isEqualTo(localeStr);
// Data Rank
- assertThat(cursor.getInt(1)).isEqualTo(rank);
+ assertThat(cursor.getInt(1)).isEqualTo(0);
// Data Title
assertThat(cursor.getString(2)).isEqualTo("Display size");
// Normalized Title
@@ -702,7 +702,7 @@
@Test
public void testResourceProvider_disabledResource_rowsInserted() {
- SearchIndexableResource resource = getFakeResource(0);
+ SearchIndexableResource resource = getFakeResource(0 /* xml */);
resource.className = "com.android.settings.LegalSettings";
mManager.indexOneSearchIndexableData(mDb, localeStr, resource,
@@ -724,6 +724,25 @@
assertThat(cursor.getCount()).isEqualTo(1);
}
+ @Test
+ public void testResourceProvider_nonSubsettingIntent() {
+ SearchIndexableResource resource = getFakeResource(0 /* xml */);
+ String fakeAction = "fake_action";
+ resource.className = "com.android.settings.LegalSettings";
+ resource.intentAction = fakeAction;
+ resource.intentTargetPackage = SearchIndexableResources.SUBSETTING_TARGET_PACKAGE;
+
+ mManager.indexOneSearchIndexableData(mDb, localeStr, resource, new HashMap<>());
+ Cursor cursor = mDb.rawQuery("SELECT * FROM prefs_index", null);
+ cursor.moveToPosition(0);
+
+ // Intent Action
+ assertThat(cursor.getString(13)).isEqualTo(fakeAction);
+ // Target Package
+ assertThat(cursor.getString(14))
+ .isEqualTo(SearchIndexableResources.SUBSETTING_TARGET_PACKAGE);
+ }
+
// Test new public indexing flow
@Test