1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 * 16 */ 17 package com.android.settings.intelligence.search; 18 19 import android.content.Context; 20 import android.util.Pair; 21 import android.view.View; 22 23 import com.android.settings.intelligence.search.indexing.DatabaseIndexingManager; 24 import com.android.settings.intelligence.search.indexing.IndexingCallback; 25 import com.android.settings.intelligence.search.query.SearchQueryTask; 26 import com.android.settings.intelligence.search.savedqueries.SavedQueryLoader; 27 import com.android.settings.intelligence.search.sitemap.SiteMapManager; 28 29 import java.util.List; 30 import java.util.concurrent.ExecutorService; 31 import java.util.concurrent.FutureTask; 32 33 /** 34 * FeatureProvider for Settings Search 35 */ 36 public interface SearchFeatureProvider { 37 38 boolean DEBUG = false; 39 40 /** 41 * Returns a new loader to get settings search results. 42 */ getSearchResultLoader(Context context, String query)43 SearchResultLoader getSearchResultLoader(Context context, String query); 44 45 /** 46 * Returns a list of {@link SearchQueryTask}, each responsible for searching a subsystem for 47 * user query. 48 */ getSearchQueryTasks(Context context, String query)49 List<SearchQueryTask> getSearchQueryTasks(Context context, String query); 50 51 /** 52 * Returns a new loader to get all recently saved queries search terms. 53 */ getSavedQueryLoader(Context context)54 SavedQueryLoader getSavedQueryLoader(Context context); 55 56 /** 57 * Returns the manager for indexing Settings data. 58 */ getIndexingManager(Context context)59 DatabaseIndexingManager getIndexingManager(Context context); 60 61 /** 62 * Returns the manager for looking up breadcrumbs. 63 */ getSiteMapManager()64 SiteMapManager getSiteMapManager(); 65 66 /** 67 * Updates the Settings indexes and calls {@link IndexingCallback#onIndexingFinished()} on 68 * {@param callback} when indexing is complete. 69 */ updateIndexAsync(Context context, IndexingCallback callback)70 void updateIndexAsync(Context context, IndexingCallback callback); 71 72 /** 73 * @returns true when indexing is complete. 74 */ isIndexingComplete(Context context)75 boolean isIndexingComplete(Context context); 76 77 /** 78 * @return a {@link ExecutorService} to be shared between search tasks. 79 */ getExecutorService()80 ExecutorService getExecutorService(); 81 82 /** 83 * Initializes the feedback button in case it was dismissed. 84 */ initFeedbackButton()85 void initFeedbackButton(); 86 87 /** 88 * Show a button users can click to submit feedback on the quality of the search results. 89 */ showFeedbackButton(SearchFragment fragment, View root)90 void showFeedbackButton(SearchFragment fragment, View root); 91 92 /** 93 * Hide the feedback button shown by 94 * {@link #showFeedbackButton(SearchFragment fragment, View view) showFeedbackButton} 95 */ hideFeedbackButton(View root)96 void hideFeedbackButton(View root); 97 98 /** 99 * Notify that a search result is clicked. 100 * 101 * @param context application context 102 * @param query input user query 103 * @param searchResult clicked result 104 */ searchResultClicked(Context context, String query, SearchResult searchResult)105 void searchResultClicked(Context context, String query, SearchResult searchResult); 106 107 /** 108 * @return true to enable search ranking. 109 */ isSmartSearchRankingEnabled(Context context)110 boolean isSmartSearchRankingEnabled(Context context); 111 112 /** 113 * @return smart ranking timeout in milliseconds. 114 */ smartSearchRankingTimeoutMs(Context context)115 long smartSearchRankingTimeoutMs(Context context); 116 117 /** 118 * Prepare for search ranking predictions to avoid latency on the first prediction call. 119 */ searchRankingWarmup(Context context)120 void searchRankingWarmup(Context context); 121 122 /** 123 * Return a FutureTask to get a list of scores for search results. 124 */ getRankerTask(Context context, String query)125 FutureTask<List<Pair<String, Float>>> getRankerTask(Context context, String query); 126 } 127