Customize actionless car intents
Change intent handling for CarSettings intents to use package and class
name rather than Search Result Trampoline for intents without an action.
Bug: 155508460
Test: manual
Change-Id: I295ce94b82a0deecb960dc8c749230c0c06c800b
diff --git a/src/com/android/settings/intelligence/search/car/CarSearchFeatureProviderImpl.java b/src/com/android/settings/intelligence/search/car/CarSearchFeatureProviderImpl.java
index c141b36..2491cbd 100644
--- a/src/com/android/settings/intelligence/search/car/CarSearchFeatureProviderImpl.java
+++ b/src/com/android/settings/intelligence/search/car/CarSearchFeatureProviderImpl.java
@@ -29,6 +29,7 @@
import com.android.settings.intelligence.search.indexing.DatabaseIndexingManager;
import com.android.settings.intelligence.search.indexing.IndexData;
import com.android.settings.intelligence.search.indexing.IndexingCallback;
+import com.android.settings.intelligence.search.indexing.car.CarDatabaseIndexingManager;
import com.android.settings.intelligence.search.query.DatabaseResultTask;
import com.android.settings.intelligence.search.query.InstalledAppResultTask;
import com.android.settings.intelligence.search.query.SearchQueryTask;
@@ -49,7 +50,7 @@
private static final String TAG = "CarSearchFeatureProvider";
private static final long SMART_SEARCH_RANKING_TIMEOUT = 300L;
- private DatabaseIndexingManager mDatabaseIndexingManager;
+ private CarDatabaseIndexingManager mDatabaseIndexingManager;
private ExecutorService mExecutorService;
private SiteMapManager mSiteMapManager;
@@ -75,7 +76,8 @@
@Override
public DatabaseIndexingManager getIndexingManager(Context context) {
if (mDatabaseIndexingManager == null) {
- mDatabaseIndexingManager = new DatabaseIndexingManager(context.getApplicationContext());
+ mDatabaseIndexingManager = new CarDatabaseIndexingManager(
+ context.getApplicationContext());
}
return mDatabaseIndexingManager;
}
diff --git a/src/com/android/settings/intelligence/search/indexing/DatabaseIndexingManager.java b/src/com/android/settings/intelligence/search/indexing/DatabaseIndexingManager.java
index 0053f14..32add54 100644
--- a/src/com/android/settings/intelligence/search/indexing/DatabaseIndexingManager.java
+++ b/src/com/android/settings/intelligence/search/indexing/DatabaseIndexingManager.java
@@ -178,7 +178,7 @@
private List<IndexData> getIndexData(PreIndexData data) {
if (mConverter == null) {
- mConverter = new IndexDataConverter(mContext);
+ mConverter = getIndexDataConverter(mContext);
}
return mConverter.convertPreIndexDataToIndexData(data);
}
@@ -186,7 +186,7 @@
private List<SiteMapPair> getSiteMapPairs(List<IndexData> indexData,
List<Pair<String, String>> siteMapClassNames) {
if (mConverter == null) {
- mConverter = new IndexDataConverter(mContext);
+ mConverter = getIndexDataConverter(mContext);
}
return mConverter.convertSiteMapPairs(indexData, siteMapClassNames);
}
@@ -312,6 +312,14 @@
}
}
+ /**
+ * Protected method to get a new IndexDataConverter instance. This method can be overridden
+ * in subclasses to substitute in a custom IndexDataConverter.
+ */
+ protected IndexDataConverter getIndexDataConverter(Context context) {
+ return new IndexDataConverter(context);
+ }
+
public class IndexingTask extends AsyncTask<Void, Void, Void> {
@VisibleForTesting
diff --git a/src/com/android/settings/intelligence/search/indexing/IndexData.java b/src/com/android/settings/intelligence/search/indexing/IndexData.java
index 904deaf..7318eaa 100644
--- a/src/com/android/settings/intelligence/search/indexing/IndexData.java
+++ b/src/com/android/settings/intelligence/search/indexing/IndexData.java
@@ -68,7 +68,7 @@
private static final Pattern REMOVE_DIACRITICALS_PATTERN
= Pattern.compile("\\p{InCombiningDiacriticalMarks}+");
- private IndexData(Builder builder) {
+ protected IndexData(Builder builder) {
locale = Locale.getDefault().toString();
updatedTitle = normalizeHyphen(builder.mTitle);
updatedSummaryOn = normalizeHyphen(builder.mSummaryOn);
@@ -186,6 +186,18 @@
return mKey;
}
+ public String getIntentAction() {
+ return mIntentAction;
+ }
+
+ public String getIntentTargetPackage() {
+ return mIntentTargetPackage;
+ }
+
+ public String getIntentTargetClass() {
+ return mIntentTargetClass;
+ }
+
public Builder setSummaryOn(String summaryOn) {
mSummaryOn = summaryOn;
return this;
@@ -290,9 +302,10 @@
}
/**
- * Adds Intent payload to builder.
+ * Builds Intent payload for the builder.
+ * This protected method that can be overridden in a subclass for custom intents.
*/
- private Intent buildIntent(Context context) {
+ protected Intent buildIntent(Context context) {
final Intent intent;
// TODO REFACTOR (b/62807132) With inline results re-add proper intent support
diff --git a/src/com/android/settings/intelligence/search/indexing/IndexDataConverter.java b/src/com/android/settings/intelligence/search/indexing/IndexDataConverter.java
index bd53596..f57ce6b 100644
--- a/src/com/android/settings/intelligence/search/indexing/IndexDataConverter.java
+++ b/src/com/android/settings/intelligence/search/indexing/IndexDataConverter.java
@@ -165,7 +165,7 @@
// A row is enabled if it does not show up as an nonIndexableKey
boolean enabled = !(nonIndexableKeys != null && nonIndexableKeys.contains(raw.key));
- final IndexData.Builder builder = new IndexData.Builder();
+ final IndexData.Builder builder = getIndexDataBuilder();
builder.setTitle(raw.title)
.setSummaryOn(raw.summaryOn)
.setEntries(raw.entries)
@@ -244,7 +244,7 @@
headerKeywords = XmlParserUtils.getDataKeywords(context, attrs);
enabled = !nonIndexableKeys.contains(headerKey);
// TODO: Set payload type for header results
- IndexData.Builder headerBuilder = new IndexData.Builder();
+ IndexData.Builder headerBuilder = getIndexDataBuilder();
headerBuilder.setTitle(headerTitle)
.setSummaryOn(headerSummary)
.setScreenTitle(screenTitle)
@@ -286,7 +286,7 @@
isHeaderUnique = false;
}
- builder = new IndexData.Builder();
+ builder = getIndexDataBuilder();
builder.setTitle(title)
.setKeywords(keywords)
.setClassName(sir.className)
@@ -365,4 +365,8 @@
final Set<String> result = nonIndexableKeys.get(authority);
return result != null ? result : new ArraySet<>();
}
+
+ protected IndexData.Builder getIndexDataBuilder() {
+ return new IndexData.Builder();
+ }
}
diff --git a/src/com/android/settings/intelligence/search/indexing/car/CarDatabaseIndexingManager.java b/src/com/android/settings/intelligence/search/indexing/car/CarDatabaseIndexingManager.java
new file mode 100644
index 0000000..3026e82
--- /dev/null
+++ b/src/com/android/settings/intelligence/search/indexing/car/CarDatabaseIndexingManager.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2020 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.intelligence.search.indexing.car;
+
+import android.content.Context;
+
+import com.android.settings.intelligence.search.indexing.DatabaseIndexingManager;
+import com.android.settings.intelligence.search.indexing.IndexDataConverter;
+import com.android.settings.intelligence.search.indexing.PreIndexData;
+
+/**
+ * Car extension to {@link DatabaseIndexingManager} to use {@link CarIndexDataConverter} for
+ * converting {@link PreIndexData} into {@link CarIndexData}.
+ */
+public class CarDatabaseIndexingManager extends DatabaseIndexingManager {
+
+ public CarDatabaseIndexingManager(Context context) {
+ super(context);
+ }
+
+ @Override
+ protected IndexDataConverter getIndexDataConverter(Context context) {
+ return new CarIndexDataConverter(context);
+ }
+}
diff --git a/src/com/android/settings/intelligence/search/indexing/car/CarIndexData.java b/src/com/android/settings/intelligence/search/indexing/car/CarIndexData.java
new file mode 100644
index 0000000..a57d003
--- /dev/null
+++ b/src/com/android/settings/intelligence/search/indexing/car/CarIndexData.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2020 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.intelligence.search.indexing.car;
+
+import android.content.Context;
+import android.content.Intent;
+
+import com.android.settings.intelligence.search.indexing.DatabaseIndexingUtils;
+import com.android.settings.intelligence.search.indexing.IndexData;
+
+/**
+ * Car data class representing a single row in the Setting Search results database.
+ */
+public class CarIndexData extends IndexData {
+
+ public CarIndexData(IndexData.Builder builder) {
+ super(builder);
+ }
+
+ /**
+ * Builder class for {@link CarIndexData}, extending {@link IndexData.Builder}, which replaces
+ * all intents with direct search intents, since CarSettings doesn't support
+ * SearchResultTrampolineIntents.
+ */
+ public static class Builder extends IndexData.Builder {
+ @Override
+ protected Intent buildIntent(Context context) {
+ return DatabaseIndexingUtils.buildDirectSearchResultIntent(getIntentAction(),
+ getIntentTargetPackage(), getIntentTargetClass(), getKey());
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/com/android/settings/intelligence/search/indexing/car/CarIndexDataConverter.java b/src/com/android/settings/intelligence/search/indexing/car/CarIndexDataConverter.java
new file mode 100644
index 0000000..11f35cb
--- /dev/null
+++ b/src/com/android/settings/intelligence/search/indexing/car/CarIndexDataConverter.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2020 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.intelligence.search.indexing.car;
+
+import android.content.Context;
+
+import com.android.settings.intelligence.search.indexing.IndexData;
+import com.android.settings.intelligence.search.indexing.IndexDataConverter;
+import com.android.settings.intelligence.search.indexing.PreIndexData;
+
+/**
+ * Car helper class to convert {@link PreIndexData} to {@link CarIndexData}.
+ */
+public class CarIndexDataConverter extends IndexDataConverter {
+
+ public CarIndexDataConverter(Context context) {
+ super(context);
+ }
+
+ @Override
+ protected IndexData.Builder getIndexDataBuilder() {
+ return new CarIndexData.Builder();
+ }
+}