Created Car Class Implementations am: 5f360d8f60

Change-Id: I2be7a4f47b0e5ddfd9eda13640ce2680a34f5954
diff --git a/src/com/android/settings/intelligence/search/car/CarFeatureFactoryImpl.java b/src/com/android/settings/intelligence/search/car/CarFeatureFactoryImpl.java
new file mode 100644
index 0000000..452ab27
--- /dev/null
+++ b/src/com/android/settings/intelligence/search/car/CarFeatureFactoryImpl.java
@@ -0,0 +1,36 @@
+/*
+ * 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.car;
+
+import androidx.annotation.Keep;
+
+import com.android.settings.intelligence.overlay.FeatureFactoryImpl;
+import com.android.settings.intelligence.search.SearchFeatureProvider;
+
+/**
+ * FeatureFactory implementation for car settings search.
+ */
+@Keep
+public class CarFeatureFactoryImpl extends FeatureFactoryImpl {
+    @Override
+    public SearchFeatureProvider searchFeatureProvider() {
+        if (mSearchFeatureProvider == null) {
+            mSearchFeatureProvider = new CarSearchFeatureProviderImpl();
+        }
+        return mSearchFeatureProvider;
+    }
+}
diff --git a/src/com/android/settings/intelligence/search/car/CarSearchFeatureProviderImpl.java b/src/com/android/settings/intelligence/search/car/CarSearchFeatureProviderImpl.java
new file mode 100644
index 0000000..c141b36
--- /dev/null
+++ b/src/com/android/settings/intelligence/search/car/CarSearchFeatureProviderImpl.java
@@ -0,0 +1,161 @@
+/*
+ * 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.car;
+
+import android.content.Context;
+import android.text.TextUtils;
+import android.util.Log;
+import android.util.Pair;
+import android.view.View;
+
+import com.android.settings.intelligence.search.SearchFeatureProvider;
+import com.android.settings.intelligence.search.SearchFragment;
+import com.android.settings.intelligence.search.SearchResult;
+import com.android.settings.intelligence.search.SearchResultLoader;
+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.query.DatabaseResultTask;
+import com.android.settings.intelligence.search.query.InstalledAppResultTask;
+import com.android.settings.intelligence.search.query.SearchQueryTask;
+import com.android.settings.intelligence.search.savedqueries.SavedQueryLoader;
+import com.android.settings.intelligence.search.sitemap.SiteMapManager;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.FutureTask;
+
+/**
+ * SearchFeatureProvider for car settings search.
+ */
+public class CarSearchFeatureProviderImpl implements SearchFeatureProvider {
+    private static final String TAG = "CarSearchFeatureProvider";
+    private static final long SMART_SEARCH_RANKING_TIMEOUT = 300L;
+
+    private DatabaseIndexingManager mDatabaseIndexingManager;
+    private ExecutorService mExecutorService;
+    private SiteMapManager mSiteMapManager;
+
+    @Override
+    public SearchResultLoader getSearchResultLoader(Context context, String query) {
+        return new SearchResultLoader(context, cleanQuery(query));
+    }
+
+    @Override
+    public List<SearchQueryTask> getSearchQueryTasks(Context context, String query) {
+        List<SearchQueryTask> tasks = new ArrayList<>();
+        String cleanQuery = cleanQuery(query);
+        tasks.add(DatabaseResultTask.newTask(context, getSiteMapManager(), cleanQuery));
+        tasks.add(InstalledAppResultTask.newTask(context, getSiteMapManager(), cleanQuery));
+        return tasks;
+    }
+
+    @Override
+    public SavedQueryLoader getSavedQueryLoader(Context context) {
+        return new SavedQueryLoader(context);
+    }
+
+    @Override
+    public DatabaseIndexingManager getIndexingManager(Context context) {
+        if (mDatabaseIndexingManager == null) {
+            mDatabaseIndexingManager = new DatabaseIndexingManager(context.getApplicationContext());
+        }
+        return mDatabaseIndexingManager;
+    }
+
+    @Override
+    public SiteMapManager getSiteMapManager() {
+        if (mSiteMapManager == null) {
+            mSiteMapManager = new SiteMapManager();
+        }
+        return mSiteMapManager;
+    }
+
+    @Override
+    public boolean isIndexingComplete(Context context) {
+        return getIndexingManager(context).isIndexingComplete();
+    }
+
+    @Override
+    public void initFeedbackButton() {
+    }
+
+    @Override
+    public void showFeedbackButton(SearchFragment fragment, View root) {
+    }
+
+    @Override
+    public void hideFeedbackButton(View root) {
+    }
+
+    @Override
+    public void searchResultClicked(Context context, String query, SearchResult searchResult) {
+    }
+
+    @Override
+    public boolean isSmartSearchRankingEnabled(Context context) {
+        return false;
+    }
+
+    @Override
+    public long smartSearchRankingTimeoutMs(Context context) {
+        return SMART_SEARCH_RANKING_TIMEOUT;
+    }
+
+    @Override
+    public void searchRankingWarmup(Context context) {
+    }
+
+    @Override
+    public FutureTask<List<Pair<String, Float>>> getRankerTask(Context context, String query) {
+        return null;
+    }
+
+    @Override
+    public void updateIndexAsync(Context context, IndexingCallback callback) {
+        if (DEBUG) {
+            Log.d(TAG, "updating index async");
+        }
+        getIndexingManager(context).indexDatabase(callback);
+    }
+
+    @Override
+    public ExecutorService getExecutorService() {
+        if (mExecutorService == null) {
+            mExecutorService = Executors.newCachedThreadPool();
+        }
+        return mExecutorService;
+    }
+
+    /**
+     * A generic method to make the query suitable for searching the database.
+     *
+     * @return the cleaned query string
+     */
+    private String cleanQuery(String query) {
+        if (TextUtils.isEmpty(query)) {
+            return null;
+        }
+        if (Locale.getDefault().equals(Locale.JAPAN)) {
+            query = IndexData.normalizeJapaneseString(query);
+        }
+        return query.trim();
+    }
+}