blob: ee6a3acb6eee2a37cbca64aaa17847b79f39865e [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 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
17package android.app;
18
Bjorn Bringert3c50ef62009-12-09 12:23:12 +000019import android.content.ActivityNotFoundException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080020import android.content.ComponentName;
Karl Rosaen875d50a2009-04-23 19:00:21 -070021import android.content.ContentResolver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080022import android.content.Context;
23import android.content.DialogInterface;
Bjorn Bringert3c50ef62009-12-09 12:23:12 +000024import android.content.Intent;
Narayan Kamathee69ff42011-06-28 12:07:18 +010025import android.content.pm.ResolveInfo;
Tim Kilbourn99e90952014-10-08 17:01:42 -070026import android.content.res.Configuration;
Karl Rosaen875d50a2009-04-23 19:00:21 -070027import android.database.Cursor;
Mathew Inwood050453e2011-10-13 11:00:39 +010028import android.graphics.Rect;
Karl Rosaen875d50a2009-04-23 19:00:21 -070029import android.net.Uri;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030import android.os.Bundle;
31import android.os.Handler;
Karl Rosaen875d50a2009-04-23 19:00:21 -070032import android.os.RemoteException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033import android.os.ServiceManager;
Jeff Sharkey49ca5292016-05-10 12:54:45 -060034import android.os.ServiceManager.ServiceNotFoundException;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070035import android.os.UserHandle;
Bjorn Bringert3fc7c672009-09-28 20:11:52 +010036import android.text.TextUtils;
Bjorn Bringert8d17f3f2009-06-05 13:22:28 +010037import android.util.Log;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080038import android.view.KeyEvent;
39
Bjorn Bringert6d72e022009-04-29 14:56:12 +010040import java.util.List;
41
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042/**
43 * This class provides access to the system search services.
Amith Yamasanie678f462010-09-15 16:13:43 -070044 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080045 * <p>In practice, you won't interact with this class directly, as search
46 * services are provided through methods in {@link android.app.Activity Activity}
Scott Main8ad64652010-03-17 12:06:06 -070047 * and the {@link android.content.Intent#ACTION_SEARCH ACTION_SEARCH}
48 * {@link android.content.Intent Intent}.
49 * If you do require direct access to the SearchManager, do not instantiate
50 * this class directly. Instead, retrieve it through
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051 * {@link android.content.Context#getSystemService
52 * context.getSystemService(Context.SEARCH_SERVICE)}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080053 *
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080054 * <div class="special reference">
55 * <h3>Developer Guides</h3>
56 * <p>For more information about using the search dialog and adding search
57 * suggestions in your application, read the
58 * <a href="{@docRoot}guide/topics/search/index.html">Search</a> developer guide.</p>
Scott Main8ad64652010-03-17 12:06:06 -070059 * </div>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060 */
Amith Yamasanie678f462010-09-15 16:13:43 -070061public class SearchManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080062 implements DialogInterface.OnDismissListener, DialogInterface.OnCancelListener
63{
Bjorn Bringert8d17f3f2009-06-05 13:22:28 +010064
65 private static final boolean DBG = false;
66 private static final String TAG = "SearchManager";
67
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080068 /**
69 * This is a shortcut definition for the default menu key to use for invoking search.
Amith Yamasanie678f462010-09-15 16:13:43 -070070 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080071 * See Menu.Item.setAlphabeticShortcut() for more information.
72 */
73 public final static char MENU_KEY = 's';
74
75 /**
76 * This is a shortcut definition for the default menu key to use for invoking search.
Amith Yamasanie678f462010-09-15 16:13:43 -070077 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080078 * See Menu.Item.setAlphabeticShortcut() for more information.
79 */
80 public final static int MENU_KEYCODE = KeyEvent.KEYCODE_S;
81
82 /**
Amith Yamasanie678f462010-09-15 16:13:43 -070083 * Intent extra data key: Use this key with
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080084 * {@link android.content.Intent#getStringExtra
85 * content.Intent.getStringExtra()}
86 * to obtain the query string from Intent.ACTION_SEARCH.
87 */
88 public final static String QUERY = "query";
89
90 /**
Bjorn Bringert5f806052009-06-24 12:02:26 +010091 * Intent extra data key: Use this key with
92 * {@link android.content.Intent#getStringExtra
93 * content.Intent.getStringExtra()}
94 * to obtain the query string typed in by the user.
95 * This may be different from the value of {@link #QUERY}
96 * if the intent is the result of selecting a suggestion.
97 * In that case, {@link #QUERY} will contain the value of
98 * {@link #SUGGEST_COLUMN_QUERY} for the suggestion, and
99 * {@link #USER_QUERY} will contain the string typed by the
100 * user.
101 */
102 public final static String USER_QUERY = "user_query";
103
104 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800105 * Intent extra data key: Use this key with Intent.ACTION_SEARCH and
106 * {@link android.content.Intent#getBundleExtra
107 * content.Intent.getBundleExtra()}
Amith Yamasanie678f462010-09-15 16:13:43 -0700108 * to obtain any additional app-specific data that was inserted by the
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800109 * activity that launched the search.
110 */
111 public final static String APP_DATA = "app_data";
112
113 /**
Bjorn Bringertbe5b73c2009-09-21 23:05:23 +0100114 * Intent extra data key: Use {@link android.content.Intent#getBundleExtra
115 * content.Intent.getBundleExtra(SEARCH_MODE)} to get the search mode used
116 * to launch the intent.
117 * The only current value for this is {@link #MODE_GLOBAL_SEARCH_SUGGESTION}.
118 *
119 * @hide
120 */
121 public final static String SEARCH_MODE = "search_mode";
122
123 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800124 * Intent extra data key: Use this key with Intent.ACTION_SEARCH and
125 * {@link android.content.Intent#getIntExtra content.Intent.getIntExtra()}
126 * to obtain the keycode that the user used to trigger this query. It will be zero if the
127 * user simply pressed the "GO" button on the search UI. This is primarily used in conjunction
128 * with the keycode attribute in the actionkey element of your searchable.xml configuration
129 * file.
130 */
131 public final static String ACTION_KEY = "action_key";
Amith Yamasanie678f462010-09-15 16:13:43 -0700132
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800133 /**
Karl Rosaen875d50a2009-04-23 19:00:21 -0700134 * Intent extra data key: This key will be used for the extra populated by the
135 * {@link #SUGGEST_COLUMN_INTENT_EXTRA_DATA} column.
Karl Rosaen875d50a2009-04-23 19:00:21 -0700136 */
137 public final static String EXTRA_DATA_KEY = "intent_extra_data_key";
Karl Rosaena058f022009-06-01 23:11:44 +0100138
Karl Rosaena058f022009-06-01 23:11:44 +0100139 /**
Bjorn Bringert55f3ac52010-01-14 11:38:22 +0000140 * Boolean extra data key for {@link #INTENT_ACTION_GLOBAL_SEARCH} intents. If {@code true},
141 * the initial query should be selected when the global search activity is started, so
142 * that the user can easily replace it with another query.
Bjorn Bringert3c50ef62009-12-09 12:23:12 +0000143 */
Bjorn Bringert55f3ac52010-01-14 11:38:22 +0000144 public final static String EXTRA_SELECT_QUERY = "select_query";
Bjorn Bringert32d580c2010-01-06 09:29:11 +0000145
Bjorn Bringert3c50ef62009-12-09 12:23:12 +0000146 /**
Leon Scrogginsaf5b4062011-02-22 16:35:13 -0500147 * Boolean extra data key for {@link Intent#ACTION_WEB_SEARCH} intents. If {@code true},
148 * this search should open a new browser window, rather than using an existing one.
149 */
150 public final static String EXTRA_NEW_SEARCH = "new_search";
151
152 /**
Bjorn Bringert4519ff62011-08-10 15:42:11 -0700153 * Extra data key for {@link Intent#ACTION_WEB_SEARCH}. If set, the value must be a
154 * {@link PendingIntent}. The search activity handling the {@link Intent#ACTION_WEB_SEARCH}
155 * intent will fill in and launch the pending intent. The data URI will be filled in with an
156 * http or https URI, and {@link android.provider.Browser#EXTRA_HEADERS} may be filled in.
157 */
158 public static final String EXTRA_WEB_SEARCH_PENDINGINTENT = "web_search_pendingintent";
159
160 /**
Amith Yamasanic37cb242010-02-24 17:44:46 -0800161 * Boolean extra data key for a suggestion provider to return in {@link Cursor#getExtras} to
162 * indicate that the search is not complete yet. This can be used by the search UI
163 * to indicate that a search is in progress. The suggestion provider can return partial results
164 * this way and send a change notification on the cursor when more results are available.
165 */
166 public final static String CURSOR_EXTRA_KEY_IN_PROGRESS = "in_progress";
167
168 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800169 * Intent extra data key: Use this key with Intent.ACTION_SEARCH and
170 * {@link android.content.Intent#getStringExtra content.Intent.getStringExtra()}
171 * to obtain the action message that was defined for a particular search action key and/or
Amith Yamasanie678f462010-09-15 16:13:43 -0700172 * suggestion. It will be null if the search was launched by typing "enter", touched the the
173 * "GO" button, or other means not involving any action key.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800174 */
175 public final static String ACTION_MSG = "action_msg";
Amith Yamasanie678f462010-09-15 16:13:43 -0700176
177 /**
178 * Flag to specify that the entry can be used for query refinement, i.e., the query text
179 * in the search field can be replaced with the text in this entry, when a query refinement
180 * icon is clicked. The suggestion list should show such a clickable icon beside the entry.
181 * <p>Use this flag as a bit-field for {@link #SUGGEST_COLUMN_FLAGS}.
182 */
183 public final static int FLAG_QUERY_REFINEMENT = 1 << 0;
184
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800185 /**
186 * Uri path for queried suggestions data. This is the path that the search manager
187 * will use when querying your content provider for suggestions data based on user input
188 * (e.g. looking for partial matches).
189 * Typically you'll use this with a URI matcher.
190 */
191 public final static String SUGGEST_URI_PATH_QUERY = "search_suggest_query";
Karl Rosaenb2a50112009-05-05 21:14:01 -0700192
193 /**
Karl Rosaenb619c912009-05-08 14:28:51 -0700194 * MIME type for suggestions data. You'll use this in your suggestions content provider
195 * in the getType() function.
196 */
197 public final static String SUGGEST_MIME_TYPE =
198 "vnd.android.cursor.dir/vnd.android.search.suggest";
199
200 /**
Karl Rosaenb2a50112009-05-05 21:14:01 -0700201 * Uri path for shortcut validation. This is the path that the search manager will use when
202 * querying your content provider to refresh a shortcutted suggestion result and to check if it
203 * is still valid. When asked, a source may return an up to date result, or no result. No
204 * result indicates the shortcut refers to a no longer valid sugggestion.
205 *
206 * @see #SUGGEST_COLUMN_SHORTCUT_ID
Karl Rosaenb2a50112009-05-05 21:14:01 -0700207 */
208 public final static String SUGGEST_URI_PATH_SHORTCUT = "search_suggest_shortcut";
Amith Yamasanie678f462010-09-15 16:13:43 -0700209
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800210 /**
Karl Rosaenb619c912009-05-08 14:28:51 -0700211 * MIME type for shortcut validation. You'll use this in your suggestions content provider
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800212 * in the getType() function.
213 */
Amith Yamasanie678f462010-09-15 16:13:43 -0700214 public final static String SHORTCUT_MIME_TYPE =
Karl Rosaenb619c912009-05-08 14:28:51 -0700215 "vnd.android.cursor.item/vnd.android.search.suggest";
Karl Rosaend4c98c42009-06-09 17:05:54 +0100216
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800217 /**
218 * Column name for suggestions cursor. <i>Unused - can be null or column can be omitted.</i>
219 */
220 public final static String SUGGEST_COLUMN_FORMAT = "suggest_format";
221 /**
Amith Yamasanie678f462010-09-15 16:13:43 -0700222 * Column name for suggestions cursor. <i>Required.</i> This is the primary line of text that
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800223 * will be presented to the user as the suggestion.
224 */
225 public final static String SUGGEST_COLUMN_TEXT_1 = "suggest_text_1";
226 /**
227 * Column name for suggestions cursor. <i>Optional.</i> If your cursor includes this column,
228 * then all suggestions will be provided in a two-line format. The second line of text is in
229 * a much smaller appearance.
230 */
231 public final static String SUGGEST_COLUMN_TEXT_2 = "suggest_text_2";
Bjorn Bringert0b49ab52010-03-02 11:16:17 +0000232
233 /**
234 * Column name for suggestions cursor. <i>Optional.</i> This is a URL that will be shown
235 * as the second line of text instead of {@link #SUGGEST_COLUMN_TEXT_2}. This is a separate
236 * column so that the search UI knows to display the text as a URL, e.g. by using a different
237 * color. If this column is absent, or has the value {@code null},
238 * {@link #SUGGEST_COLUMN_TEXT_2} will be used instead.
239 */
240 public final static String SUGGEST_COLUMN_TEXT_2_URL = "suggest_text_2_url";
241
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800242 /**
243 * Column name for suggestions cursor. <i>Optional.</i> If your cursor includes this column,
Karl Rosaen875d50a2009-04-23 19:00:21 -0700244 * then all suggestions will be provided in a format that includes space for two small icons,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800245 * one at the left and one at the right of each suggestion. The data in the column must
Karl Rosaen875d50a2009-04-23 19:00:21 -0700246 * be a resource ID of a drawable, or a URI in one of the following formats:
247 *
248 * <ul>
249 * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li>
250 * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li>
251 * <li>file ({@link android.content.ContentResolver#SCHEME_FILE})</li>
252 * </ul>
253 *
Amith Yamasanie678f462010-09-15 16:13:43 -0700254 * See {@link android.content.ContentResolver#openAssetFileDescriptor(Uri, String)}
255 * for more information on these schemes.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800256 */
257 public final static String SUGGEST_COLUMN_ICON_1 = "suggest_icon_1";
Xiaolei Wangb2b2ac12014-05-28 15:18:15 -0700258
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800259 /**
260 * Column name for suggestions cursor. <i>Optional.</i> If your cursor includes this column,
Karl Rosaen875d50a2009-04-23 19:00:21 -0700261 * then all suggestions will be provided in a format that includes space for two small icons,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800262 * one at the left and one at the right of each suggestion. The data in the column must
Karl Rosaen875d50a2009-04-23 19:00:21 -0700263 * be a resource ID of a drawable, or a URI in one of the following formats:
264 *
265 * <ul>
266 * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li>
267 * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li>
268 * <li>file ({@link android.content.ContentResolver#SCHEME_FILE})</li>
269 * </ul>
270 *
Amith Yamasanie678f462010-09-15 16:13:43 -0700271 * See {@link android.content.ContentResolver#openAssetFileDescriptor(Uri, String)}
272 * for more information on these schemes.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800273 */
274 public final static String SUGGEST_COLUMN_ICON_2 = "suggest_icon_2";
Xiaolei Wangb2b2ac12014-05-28 15:18:15 -0700275
276 /**
277 * Column name for suggestions cursor. <i>Optional.</i> If your cursor includes this column,
278 * then the image will be displayed when forming the suggestion. The suggested dimension for
279 * the image is 270x400 px for portrait mode and 400x225 px for landscape mode. The data in the
280 * column must be a resource ID of a drawable, or a URI in one of the following formats:
281 *
282 * <ul>
283 * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li>
284 * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li>
285 * <li>file ({@link android.content.ContentResolver#SCHEME_FILE})</li>
286 * </ul>
287 *
288 * See {@link android.content.ContentResolver#openAssetFileDescriptor(Uri, String)}
289 * for more information on these schemes.
290 */
291 public final static String SUGGEST_COLUMN_RESULT_CARD_IMAGE = "suggest_result_card_image";
292
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800293 /**
294 * Column name for suggestions cursor. <i>Optional.</i> If this column exists <i>and</i>
295 * this element exists at the given row, this is the action that will be used when
296 * forming the suggestion's intent. If the element is not provided, the action will be taken
297 * from the android:searchSuggestIntentAction field in your XML metadata. <i>At least one of
298 * these must be present for the suggestion to generate an intent.</i> Note: If your action is
299 * the same for all suggestions, it is more efficient to specify it using XML metadata and omit
300 * it from the cursor.
301 */
302 public final static String SUGGEST_COLUMN_INTENT_ACTION = "suggest_intent_action";
Xiaolei Wangb2b2ac12014-05-28 15:18:15 -0700303
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800304 /**
305 * Column name for suggestions cursor. <i>Optional.</i> If this column exists <i>and</i>
306 * this element exists at the given row, this is the data that will be used when
307 * forming the suggestion's intent. If the element is not provided, the data will be taken
308 * from the android:searchSuggestIntentData field in your XML metadata. If neither source
309 * is provided, the Intent's data field will be null. Note: If your data is
310 * the same for all suggestions, or can be described using a constant part and a specific ID,
311 * it is more efficient to specify it using XML metadata and omit it from the cursor.
312 */
313 public final static String SUGGEST_COLUMN_INTENT_DATA = "suggest_intent_data";
Xiaolei Wangb2b2ac12014-05-28 15:18:15 -0700314
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800315 /**
Satish Sampathbf23fe02009-06-15 23:47:56 +0100316 * Column name for suggestions cursor. <i>Optional.</i> If this column exists <i>and</i>
317 * this element exists at the given row, this is the data that will be used when
318 * forming the suggestion's intent. If not provided, the Intent's extra data field will be null.
319 * This column allows suggestions to provide additional arbitrary data which will be included as
Mike LeBeau131234c2009-07-20 14:09:52 -0700320 * an extra under the key {@link #EXTRA_DATA_KEY}.
Satish Sampathbf23fe02009-06-15 23:47:56 +0100321 */
322 public final static String SUGGEST_COLUMN_INTENT_EXTRA_DATA = "suggest_intent_extra_data";
Xiaolei Wangb2b2ac12014-05-28 15:18:15 -0700323
Satish Sampathbf23fe02009-06-15 23:47:56 +0100324 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800325 * Column name for suggestions cursor. <i>Optional.</i> If this column exists <i>and</i>
326 * this element exists at the given row, then "/" and this value will be appended to the data
327 * field in the Intent. This should only be used if the data field has already been set to an
328 * appropriate base string.
329 */
330 public final static String SUGGEST_COLUMN_INTENT_DATA_ID = "suggest_intent_data_id";
Xiaolei Wangb2b2ac12014-05-28 15:18:15 -0700331
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800332 /**
Amith Yamasanie678f462010-09-15 16:13:43 -0700333 * Column name for suggestions cursor. <i>Required if action is
334 * {@link android.content.Intent#ACTION_SEARCH ACTION_SEARCH}, optional otherwise.</i> If this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800335 * column exists <i>and</i> this element exists at the given row, this is the data that will be
336 * used when forming the suggestion's query.
337 */
338 public final static String SUGGEST_COLUMN_QUERY = "suggest_intent_query";
339
Karl Rosaen875d50a2009-04-23 19:00:21 -0700340 /**
Karl Rosaenb2a50112009-05-05 21:14:01 -0700341 * Column name for suggestions cursor. <i>Optional.</i> This column is used to indicate whether
Karl Rosaenb5041362009-08-11 11:35:07 -0700342 * a search suggestion should be stored as a shortcut, and whether it should be refreshed. If
Karl Rosaenb2a50112009-05-05 21:14:01 -0700343 * missing, the result will be stored as a shortcut and never validated. If set to
344 * {@link #SUGGEST_NEVER_MAKE_SHORTCUT}, the result will not be stored as a shortcut.
Karl Rosaenb5041362009-08-11 11:35:07 -0700345 * Otherwise, the shortcut id will be used to check back for an up to date suggestion using
Karl Rosaenb2a50112009-05-05 21:14:01 -0700346 * {@link #SUGGEST_URI_PATH_SHORTCUT}.
Karl Rosaenb2a50112009-05-05 21:14:01 -0700347 */
348 public final static String SUGGEST_COLUMN_SHORTCUT_ID = "suggest_shortcut_id";
349
350 /**
Mike LeBeauce0959d2009-06-10 23:47:54 +0100351 * Column name for suggestions cursor. <i>Optional.</i> This column is used to specify
352 * that a spinner should be shown in lieu of an icon2 while the shortcut of this suggestion
353 * is being refreshed.
Mike LeBeauce0959d2009-06-10 23:47:54 +0100354 */
355 public final static String SUGGEST_COLUMN_SPINNER_WHILE_REFRESHING =
356 "suggest_spinner_while_refreshing";
Satish Sampath1c5fa0f2009-06-08 23:10:40 +0100357
358 /**
Xiaolei Wangb2b2ac12014-05-28 15:18:15 -0700359 * Column name for suggestions cursor. <i>Optional.</i> If your content is media type, you
360 * should provide this column so search app could understand more about your content. The data
361 * in the column must specify the MIME type of the content.
362 */
363 public final static String SUGGEST_COLUMN_CONTENT_TYPE = "suggest_content_type";
364
365 /**
366 * Column name for suggestions cursor. <i>Optional.</i> If your content is media type, you
367 * should provide this column to specify whether your content is live media such as live video
368 * or live audio. The value in the column is of integer type with value of either 0 indicating
369 * non-live content or 1 indicating live content.
370 */
371 public final static String SUGGEST_COLUMN_IS_LIVE = "suggest_is_live";
372
373 /**
374 * Column name for suggestions cursor. <i>Optional.</i> If your content is video, you should
375 * provide this column to specify the number of vertical lines. The data in the column is of
376 * integer type.
377 */
378 public final static String SUGGEST_COLUMN_VIDEO_WIDTH = "suggest_video_width";
379
380 /**
381 * Column name for suggestions cursor. <i>Optional.</i> If your content is video, you should
382 * provide this column to specify the number of horizontal lines. The data in the column is of
383 * integer type.
384 */
385 public final static String SUGGEST_COLUMN_VIDEO_HEIGHT = "suggest_video_height";
386
387 /**
388 * Column name for suggestions cursor. <i>Optional.</i> If your content contains audio, you
389 * should provide this column to specify the audio channel configuration. The data in the
390 * column is string with format like "channels.subchannels" such as "1.0" or "5.1".
391 */
392 public final static String SUGGEST_COLUMN_AUDIO_CHANNEL_CONFIG = "suggest_audio_channel_config";
393
394 /**
395 * Column name for suggestions cursor. <i>Optional.</i> If your content is purchasable, you
396 * should provide this column to specify the displayable string representation of the purchase
397 * price of your content including the currency and the amount. If it's free, you should
398 * provide localized string to specify that it's free. This column can be omitted if the content
399 * is not applicable to purchase.
400 */
401 public final static String SUGGEST_COLUMN_PURCHASE_PRICE = "suggest_purchase_price";
402
403 /**
404 * Column name for suggestions cursor. <i>Optional.</i> If your content is rentable, you
405 * should provide this column to specify the displayable string representation of the rental
406 * price of your content including the currency and the amount. If it's free, you should
407 * provide localized string to specify that it's free. This column can be ommitted if the
408 * content is not applicable to rent.
409 */
410 public final static String SUGGEST_COLUMN_RENTAL_PRICE = "suggest_rental_price";
411
412 /**
413 * Column name for suggestions cursor. <i>Optional.</i> If your content has a rating, you
414 * should provide this column to specify the rating style of your content. The data in the
415 * column must be one of the constant values specified in {@link android.media.Rating}
416 */
417 public final static String SUGGEST_COLUMN_RATING_STYLE = "suggest_rating_style";
418
419 /**
420 * Column name for suggestions cursor. <i>Optional.</i> If your content has a rating, you
421 * should provide this column to specify the rating score of your content. The data in the
422 * column is of float type. See {@link android.media.Rating} about valid rating scores for each
423 * rating style.
424 */
425 public final static String SUGGEST_COLUMN_RATING_SCORE = "suggest_rating_score";
426
427 /**
428 * Column name for suggestions cursor. <i>Optional.</i> If your content is video or audio and
429 * has a known production year, you should provide this column to specify the production year
430 * of your content. The data in the column is of integer type.
431 */
432 public final static String SUGGEST_COLUMN_PRODUCTION_YEAR = "suggest_production_year";
433
434 /**
435 * Column name for suggestions cursor. <i>Optional.</i> If your content is video or audio, you
436 * should provide this column to specify the duration of your content in milliseconds. The data
437 * in the column is of long type.
438 */
439 public final static String SUGGEST_COLUMN_DURATION = "suggest_duration";
440
441 /**
Amith Yamasanie678f462010-09-15 16:13:43 -0700442 * Column name for suggestions cursor. <i>Optional.</i> This column is used to specify
443 * additional flags per item. Multiple flags can be specified.
444 * <p>
445 * Must be one of {@link #FLAG_QUERY_REFINEMENT} or 0 to indicate no flags.
446 * </p>
447 */
448 public final static String SUGGEST_COLUMN_FLAGS = "suggest_flags";
449
450 /**
Mark Brophya31c7aa2011-06-17 16:36:38 +0100451 * Column name for suggestions cursor. <i>Optional.</i> This column may be
Mark Brophyde2ba4c2011-09-16 12:27:20 +0100452 * used to specify the time in {@link System#currentTimeMillis
Mark Brophya31c7aa2011-06-17 16:36:38 +0100453 * System.currentTImeMillis()} (wall time in UTC) when an item was last
454 * accessed within the results-providing application. If set, this may be
455 * used to show more-recently-used items first.
456 */
457 public final static String SUGGEST_COLUMN_LAST_ACCESS_HINT = "suggest_last_access_hint";
458
459 /**
Karl Rosaenb2a50112009-05-05 21:14:01 -0700460 * Column value for suggestion column {@link #SUGGEST_COLUMN_SHORTCUT_ID} when a suggestion
461 * should not be stored as a shortcut in global search.
Karl Rosaenb2a50112009-05-05 21:14:01 -0700462 */
463 public final static String SUGGEST_NEVER_MAKE_SHORTCUT = "_-1";
464
465 /**
Bjorn Bringert3fc7c672009-09-28 20:11:52 +0100466 * Query parameter added to suggestion queries to limit the number of suggestions returned.
Bjorn Bringert86917db2009-09-28 22:00:50 +0100467 * This limit is only advisory and suggestion providers may chose to ignore it.
Bjorn Bringert3fc7c672009-09-28 20:11:52 +0100468 */
469 public final static String SUGGEST_PARAMETER_LIMIT = "limit";
470
471 /**
Bjorn Bringert55f3ac52010-01-14 11:38:22 +0000472 * Intent action for starting the global search activity.
Bjorn Bringert74708bb2009-04-28 11:26:52 +0100473 * The global search provider should handle this intent.
Bjorn Bringert55f3ac52010-01-14 11:38:22 +0000474 *
475 * Supported extra data keys: {@link #QUERY},
476 * {@link #EXTRA_SELECT_QUERY},
477 * {@link #APP_DATA}.
Bjorn Bringert74708bb2009-04-28 11:26:52 +0100478 */
Amith Yamasanie678f462010-09-15 16:13:43 -0700479 public final static String INTENT_ACTION_GLOBAL_SEARCH
Bjorn Bringert74708bb2009-04-28 11:26:52 +0100480 = "android.search.action.GLOBAL_SEARCH";
Amith Yamasanie678f462010-09-15 16:13:43 -0700481
Bjorn Bringert74708bb2009-04-28 11:26:52 +0100482 /**
Karl Rosaen875d50a2009-04-23 19:00:21 -0700483 * Intent action for starting the global search settings activity.
484 * The global search provider should handle this intent.
Karl Rosaen875d50a2009-04-23 19:00:21 -0700485 */
Amith Yamasanie678f462010-09-15 16:13:43 -0700486 public final static String INTENT_ACTION_SEARCH_SETTINGS
Karl Rosaen875d50a2009-04-23 19:00:21 -0700487 = "android.search.action.SEARCH_SETTINGS";
Amith Yamasanie678f462010-09-15 16:13:43 -0700488
Mike LeBeau3a278032009-06-04 14:09:42 +0100489 /**
490 * Intent action for starting a web search provider's settings activity.
491 * Web search providers should handle this intent if they have provider-specific
492 * settings to implement.
Mike LeBeau3a278032009-06-04 14:09:42 +0100493 */
494 public final static String INTENT_ACTION_WEB_SEARCH_SETTINGS
495 = "android.search.action.WEB_SEARCH_SETTINGS";
Karl Rosaena058f022009-06-01 23:11:44 +0100496
497 /**
Satish Sampathf9acde22009-06-04 11:51:17 +0100498 * Intent action broadcasted to inform that the searchables list or default have changed.
499 * Components should handle this intent if they cache any searchable data and wish to stay
500 * up to date on changes.
Satish Sampathf9acde22009-06-04 11:51:17 +0100501 */
502 public final static String INTENT_ACTION_SEARCHABLES_CHANGED
503 = "android.search.action.SEARCHABLES_CHANGED";
Amith Yamasanie678f462010-09-15 16:13:43 -0700504
Mike LeBeaud4fb7a02009-07-20 17:37:38 -0700505 /**
Narayan Kamathee69ff42011-06-28 12:07:18 +0100506 * Intent action to be broadcast to inform that the global search provider
Michael Jurka3f5cfcf2012-04-27 14:20:59 -0700507 * has changed.
Narayan Kamathee69ff42011-06-28 12:07:18 +0100508 */
509 public final static String INTENT_GLOBAL_SEARCH_ACTIVITY_CHANGED
510 = "android.search.action.GLOBAL_SEARCH_ACTIVITY_CHANGED";
511
512 /**
Mike LeBeaud4fb7a02009-07-20 17:37:38 -0700513 * Intent action broadcasted to inform that the search settings have changed in some way.
Karl Rosaen590f6342009-08-27 17:42:48 -0700514 * Either searchables have been enabled or disabled, or a different web search provider
515 * has been chosen.
Mike LeBeaud4fb7a02009-07-20 17:37:38 -0700516 */
517 public final static String INTENT_ACTION_SEARCH_SETTINGS_CHANGED
518 = "android.search.action.SETTINGS_CHANGED";
Satish Sampathf9acde22009-06-04 11:51:17 +0100519
520 /**
Leon Scroggins4f22a542010-03-09 17:28:13 -0500521 * This means that context is voice, and therefore the SearchDialog should
522 * continue showing the microphone until the user indicates that he/she does
523 * not want to re-speak (e.g. by typing).
524 *
525 * @hide
526 */
527 public final static String CONTEXT_IS_VOICE = "android.search.CONTEXT_IS_VOICE";
528
529 /**
Leon Scroggins III4a028002010-09-14 10:56:25 -0400530 * This means that the voice icon should not be shown at all, because the
531 * current search engine does not support voice search.
532 * @hide
533 */
534 public final static String DISABLE_VOICE_SEARCH
535 = "android.search.DISABLE_VOICE_SEARCH";
536
537 /**
Karl Rosaen875d50a2009-04-23 19:00:21 -0700538 * Reference to the shared system search service.
539 */
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600540 private final ISearchManager mService;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800541
542 private final Context mContext;
Bjorn Bringert8d17f3f2009-06-05 13:22:28 +0100543
544 // package private since they are used by the inner class SearchManagerCallback
Bjorn Bringert8d17f3f2009-06-05 13:22:28 +0100545 /* package */ final Handler mHandler;
546 /* package */ OnDismissListener mDismissListener = null;
547 /* package */ OnCancelListener mCancelListener = null;
548
Amith Yamasanie9ce3f02010-01-25 09:15:50 -0800549 private SearchDialog mSearchDialog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800550
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600551 /*package*/ SearchManager(Context context, Handler handler) throws ServiceNotFoundException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800552 mContext = context;
553 mHandler = handler;
Bjorn Bringert8d153822009-06-22 10:31:44 +0100554 mService = ISearchManager.Stub.asInterface(
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600555 ServiceManager.getServiceOrThrow(Context.SEARCH_SERVICE));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800556 }
Amith Yamasanie678f462010-09-15 16:13:43 -0700557
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800558 /**
559 * Launch search UI.
560 *
561 * <p>The search manager will open a search widget in an overlapping
Amith Yamasanie678f462010-09-15 16:13:43 -0700562 * window, and the underlying activity may be obscured. The search
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800563 * entry state will remain in effect until one of the following events:
564 * <ul>
Amith Yamasanie678f462010-09-15 16:13:43 -0700565 * <li>The user completes the search. In most cases this will launch
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800566 * a search intent.</li>
567 * <li>The user uses the back, home, or other keys to exit the search.</li>
568 * <li>The application calls the {@link #stopSearch}
569 * method, which will hide the search window and return focus to the
570 * activity from which it was launched.</li>
571 *
572 * <p>Most applications will <i>not</i> use this interface to invoke search.
Amith Yamasanie678f462010-09-15 16:13:43 -0700573 * The primary method for invoking search is to call
574 * {@link android.app.Activity#onSearchRequested Activity.onSearchRequested()} or
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800575 * {@link android.app.Activity#startSearch Activity.startSearch()}.
576 *
577 * @param initialQuery A search string can be pre-entered here, but this
578 * is typically null or empty.
579 * @param selectInitialQuery If true, the intial query will be preselected, which means that
580 * any further typing will replace it. This is useful for cases where an entire pre-formed
581 * query is being inserted. If false, the selection point will be placed at the end of the
582 * inserted query. This is useful when the inserted query is text that the user entered,
583 * and the user would expect to be able to keep typing. <i>This parameter is only meaningful
584 * if initialQuery is a non-empty string.</i>
585 * @param launchActivity The ComponentName of the activity that has launched this search.
Amith Yamasanie678f462010-09-15 16:13:43 -0700586 * @param appSearchData An application can insert application-specific
587 * context here, in order to improve quality or specificity of its own
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800588 * searches. This data will be returned with SEARCH intent(s). Null if
589 * no extra data is required.
590 * @param globalSearch If false, this will only launch the search that has been specifically
Amith Yamasanie678f462010-09-15 16:13:43 -0700591 * defined by the application (which is usually defined as a local search). If no default
Mike LeBeaucfa419b2009-08-17 10:56:02 -0700592 * search is defined in the current application or activity, global search will be launched.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800593 * If true, this will always launch a platform-global (e.g. web-based) search instead.
Amith Yamasanie678f462010-09-15 16:13:43 -0700594 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800595 * @see android.app.Activity#onSearchRequested
596 * @see #stopSearch
597 */
Amith Yamasanie678f462010-09-15 16:13:43 -0700598 public void startSearch(String initialQuery,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800599 boolean selectInitialQuery,
600 ComponentName launchActivity,
601 Bundle appSearchData,
602 boolean globalSearch) {
Mathew Inwood050453e2011-10-13 11:00:39 +0100603 startSearch(initialQuery, selectInitialQuery, launchActivity,
604 appSearchData, globalSearch, null);
605 }
606
607 /**
608 * As {@link #startSearch(String, boolean, ComponentName, Bundle, boolean)} but including
609 * source bounds for the global search intent.
610 *
611 * @hide
612 */
613 public void startSearch(String initialQuery,
614 boolean selectInitialQuery,
615 ComponentName launchActivity,
616 Bundle appSearchData,
617 boolean globalSearch,
618 Rect sourceBounds) {
Bjorn Bringert3c50ef62009-12-09 12:23:12 +0000619 if (globalSearch) {
Mathew Inwood050453e2011-10-13 11:00:39 +0100620 startGlobalSearch(initialQuery, selectInitialQuery, appSearchData, sourceBounds);
Bjorn Bringert3c50ef62009-12-09 12:23:12 +0000621 return;
622 }
623
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600624 final UiModeManager uiModeManager = mContext.getSystemService(UiModeManager.class);
Tim Kilbourn99e90952014-10-08 17:01:42 -0700625 // Don't show search dialog on televisions.
626 if (uiModeManager.getCurrentModeType() != Configuration.UI_MODE_TYPE_TELEVISION) {
627 ensureSearchDialog();
Amith Yamasani479ae0a2010-02-04 14:52:32 -0800628
Tim Kilbourn99e90952014-10-08 17:01:42 -0700629 mSearchDialog.show(initialQuery, selectInitialQuery, launchActivity, appSearchData);
630 }
Amith Yamasanie9ce3f02010-01-25 09:15:50 -0800631 }
632
633 private void ensureSearchDialog() {
634 if (mSearchDialog == null) {
635 mSearchDialog = new SearchDialog(mContext, this);
636 mSearchDialog.setOnCancelListener(this);
637 mSearchDialog.setOnDismissListener(this);
krosaend2d60142009-08-17 08:56:48 -0700638 }
639 }
640
641 /**
Bjorn Bringert3c50ef62009-12-09 12:23:12 +0000642 * Starts the global search activity.
643 */
Amith Yamasanie9ce3f02010-01-25 09:15:50 -0800644 /* package */ void startGlobalSearch(String initialQuery, boolean selectInitialQuery,
Mathew Inwood050453e2011-10-13 11:00:39 +0100645 Bundle appSearchData, Rect sourceBounds) {
Bjorn Bringert3c50ef62009-12-09 12:23:12 +0000646 ComponentName globalSearchActivity = getGlobalSearchActivity();
647 if (globalSearchActivity == null) {
648 Log.w(TAG, "No global search activity found.");
649 return;
650 }
Bjorn Bringerta94e7af2010-01-13 21:09:20 +0000651 Intent intent = new Intent(INTENT_ACTION_GLOBAL_SEARCH);
Bjorn Bringertb8144a92010-02-22 20:48:57 +0000652 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Bjorn Bringert3c50ef62009-12-09 12:23:12 +0000653 intent.setComponent(globalSearchActivity);
Bjorn Bringert3c24cb72010-03-16 12:54:41 +0000654 // Make sure that we have a Bundle to put source in
655 if (appSearchData == null) {
656 appSearchData = new Bundle();
657 } else {
658 appSearchData = new Bundle(appSearchData);
Bjorn Bringert3c50ef62009-12-09 12:23:12 +0000659 }
Bjorn Bringert3c24cb72010-03-16 12:54:41 +0000660 // Set source to package name of app that starts global search, if not set already.
661 if (!appSearchData.containsKey("source")) {
662 appSearchData.putString("source", mContext.getPackageName());
663 }
664 intent.putExtra(APP_DATA, appSearchData);
Bjorn Bringert3c50ef62009-12-09 12:23:12 +0000665 if (!TextUtils.isEmpty(initialQuery)) {
Bjorn Bringert55f3ac52010-01-14 11:38:22 +0000666 intent.putExtra(QUERY, initialQuery);
Bjorn Bringert3c50ef62009-12-09 12:23:12 +0000667 }
668 if (selectInitialQuery) {
Bjorn Bringert55f3ac52010-01-14 11:38:22 +0000669 intent.putExtra(EXTRA_SELECT_QUERY, selectInitialQuery);
Bjorn Bringert3c50ef62009-12-09 12:23:12 +0000670 }
Mathew Inwood050453e2011-10-13 11:00:39 +0100671 intent.setSourceBounds(sourceBounds);
Bjorn Bringert3c50ef62009-12-09 12:23:12 +0000672 try {
673 if (DBG) Log.d(TAG, "Starting global search: " + intent.toUri(0));
674 mContext.startActivity(intent);
675 } catch (ActivityNotFoundException ex) {
676 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
677 }
678 }
679
680 /**
Narayan Kamathee69ff42011-06-28 12:07:18 +0100681 * Returns a list of installed apps that handle the global search
682 * intent.
683 *
684 * @hide
685 */
686 public List<ResolveInfo> getGlobalSearchActivities() {
687 try {
688 return mService.getGlobalSearchActivities();
689 } catch (RemoteException ex) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700690 throw ex.rethrowFromSystemServer();
Narayan Kamathee69ff42011-06-28 12:07:18 +0100691 }
692 }
693
694 /**
Bjorn Bringert3c50ef62009-12-09 12:23:12 +0000695 * Gets the name of the global search activity.
Bjorn Bringert3c50ef62009-12-09 12:23:12 +0000696 */
Bjorn Bringert38015f32010-01-14 14:56:18 +0000697 public ComponentName getGlobalSearchActivity() {
Bjorn Bringert6cf7a322010-02-23 13:17:06 +0000698 try {
699 return mService.getGlobalSearchActivity();
700 } catch (RemoteException ex) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700701 throw ex.rethrowFromSystemServer();
Bjorn Bringert3c50ef62009-12-09 12:23:12 +0000702 }
Bjorn Bringert3c50ef62009-12-09 12:23:12 +0000703 }
704
705 /**
Bjorn Bringertea125f42010-02-18 21:57:59 +0000706 * Gets the name of the web search activity.
707 *
708 * @return The name of the default activity for web searches. This activity
709 * can be used to get web search suggestions. Returns {@code null} if
710 * there is no default web search activity.
711 *
712 * @hide
713 */
714 public ComponentName getWebSearchActivity() {
Bjorn Bringert6cf7a322010-02-23 13:17:06 +0000715 try {
716 return mService.getWebSearchActivity();
717 } catch (RemoteException ex) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700718 throw ex.rethrowFromSystemServer();
Bjorn Bringertea125f42010-02-18 21:57:59 +0000719 }
Bjorn Bringertea125f42010-02-18 21:57:59 +0000720 }
721
722 /**
krosaend2d60142009-08-17 08:56:48 -0700723 * Similar to {@link #startSearch} but actually fires off the search query after invoking
724 * the search dialog. Made available for testing purposes.
725 *
726 * @param query The query to trigger. If empty, request will be ignored.
727 * @param launchActivity The ComponentName of the activity that has launched this search.
728 * @param appSearchData An application can insert application-specific
729 * context here, in order to improve quality or specificity of its own
730 * searches. This data will be returned with SEARCH intent(s). Null if
731 * no extra data is required.
krosaend2d60142009-08-17 08:56:48 -0700732 *
733 * @see #startSearch
734 */
735 public void triggerSearch(String query,
736 ComponentName launchActivity,
Bjorn Bringertb782a2f2009-10-01 09:57:33 +0100737 Bundle appSearchData) {
krosaend2d60142009-08-17 08:56:48 -0700738 if (query == null || TextUtils.getTrimmedLength(query) == 0) {
739 Log.w(TAG, "triggerSearch called with empty query, ignoring.");
740 return;
741 }
Amith Yamasanie9ce3f02010-01-25 09:15:50 -0800742 startSearch(query, false, launchActivity, appSearchData, false);
743 mSearchDialog.launchQuerySearch();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800744 }
745
746 /**
747 * Terminate search UI.
748 *
749 * <p>Typically the user will terminate the search UI by launching a
750 * search or by canceling. This function allows the underlying application
751 * or activity to cancel the search prematurely (for any reason).
Amith Yamasanie678f462010-09-15 16:13:43 -0700752 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800753 * <p>This function can be safely called at any time (even if no search is active.)
754 *
755 * @see #startSearch
756 */
Bjorn Bringert8d17f3f2009-06-05 13:22:28 +0100757 public void stopSearch() {
Amith Yamasanie9ce3f02010-01-25 09:15:50 -0800758 if (mSearchDialog != null) {
759 mSearchDialog.cancel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800760 }
761 }
762
763 /**
Amith Yamasanie678f462010-09-15 16:13:43 -0700764 * Determine if the Search UI is currently displayed.
765 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800766 * This is provided primarily for application test purposes.
767 *
768 * @return Returns true if the search UI is currently displayed.
Amith Yamasanie678f462010-09-15 16:13:43 -0700769 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800770 * @hide
771 */
Bjorn Bringert8d17f3f2009-06-05 13:22:28 +0100772 public boolean isVisible() {
Amith Yamasanie9ce3f02010-01-25 09:15:50 -0800773 return mSearchDialog == null? false : mSearchDialog.isShowing();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800774 }
Bjorn Bringert8d17f3f2009-06-05 13:22:28 +0100775
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800776 /**
Karl Rosaena058f022009-06-01 23:11:44 +0100777 * See {@link SearchManager#setOnDismissListener} for configuring your activity to monitor
778 * search UI state.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800779 */
780 public interface OnDismissListener {
781 /**
Karl Rosaena058f022009-06-01 23:11:44 +0100782 * This method will be called when the search UI is dismissed. To make use of it, you must
783 * implement this method in your activity, and call
784 * {@link SearchManager#setOnDismissListener} to register it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800785 */
786 public void onDismiss();
787 }
Amith Yamasanie678f462010-09-15 16:13:43 -0700788
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800789 /**
Karl Rosaena058f022009-06-01 23:11:44 +0100790 * See {@link SearchManager#setOnCancelListener} for configuring your activity to monitor
791 * search UI state.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800792 */
793 public interface OnCancelListener {
794 /**
795 * This method will be called when the search UI is canceled. To make use if it, you must
Karl Rosaena058f022009-06-01 23:11:44 +0100796 * implement this method in your activity, and call
797 * {@link SearchManager#setOnCancelListener} to register it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800798 */
799 public void onCancel();
800 }
801
802 /**
803 * Set or clear the callback that will be invoked whenever the search UI is dismissed.
Amith Yamasanie678f462010-09-15 16:13:43 -0700804 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800805 * @param listener The {@link OnDismissListener} to use, or null.
806 */
807 public void setOnDismissListener(final OnDismissListener listener) {
808 mDismissListener = listener;
809 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800810
811 /**
812 * Set or clear the callback that will be invoked whenever the search UI is canceled.
Amith Yamasanie678f462010-09-15 16:13:43 -0700813 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800814 * @param listener The {@link OnCancelListener} to use, or null.
815 */
Bjorn Bringert8d17f3f2009-06-05 13:22:28 +0100816 public void setOnCancelListener(OnCancelListener listener) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800817 mCancelListener = listener;
818 }
Bjorn Bringert8d17f3f2009-06-05 13:22:28 +0100819
Bjorn Bringert0e01ea42009-07-08 22:01:29 +0100820 /**
821 * @deprecated This method is an obsolete internal implementation detail. Do not use.
822 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -0700823 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800824 public void onCancel(DialogInterface dialog) {
Amith Yamasanie9ce3f02010-01-25 09:15:50 -0800825 if (mCancelListener != null) {
826 mCancelListener.onCancel();
827 }
Bjorn Bringert8d17f3f2009-06-05 13:22:28 +0100828 }
Bjorn Bringert0e01ea42009-07-08 22:01:29 +0100829
830 /**
831 * @deprecated This method is an obsolete internal implementation detail. Do not use.
832 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -0700833 @Deprecated
Bjorn Bringert8d17f3f2009-06-05 13:22:28 +0100834 public void onDismiss(DialogInterface dialog) {
Amith Yamasanie9ce3f02010-01-25 09:15:50 -0800835 if (mDismissListener != null) {
836 mDismissListener.onDismiss();
837 }
Bjorn Bringert8d17f3f2009-06-05 13:22:28 +0100838 }
839
840 /**
Bjorn Bringert04086752010-01-12 15:50:04 +0000841 * Gets information about a searchable activity.
842 *
843 * @param componentName The activity to get searchable information for.
844 * @return Searchable information, or <code>null</code> if the activity does not
845 * exist, or is not searchable.
846 */
847 public SearchableInfo getSearchableInfo(ComponentName componentName) {
848 try {
Bjorn Bringert6cf7a322010-02-23 13:17:06 +0000849 return mService.getSearchableInfo(componentName);
Bjorn Bringert8d17f3f2009-06-05 13:22:28 +0100850 } catch (RemoteException ex) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700851 throw ex.rethrowFromSystemServer();
Karl Rosaen875d50a2009-04-23 19:00:21 -0700852 }
853 }
Bjorn Bringert8d153822009-06-22 10:31:44 +0100854
Karl Rosaen875d50a2009-04-23 19:00:21 -0700855 /**
Bjorn Bringert97325db2009-06-22 11:37:03 +0100856 * Gets a cursor with search suggestions.
857 *
858 * @param searchable Information about how to get the suggestions.
859 * @param query The search text entered (so far).
860 * @return a cursor with suggestions, or <code>null</null> the suggestion query failed.
861 *
862 * @hide because SearchableInfo is not part of the API.
863 */
864 public Cursor getSuggestions(SearchableInfo searchable, String query) {
Bjorn Bringert3fc7c672009-09-28 20:11:52 +0100865 return getSuggestions(searchable, query, -1);
866 }
867
868 /**
869 * Gets a cursor with search suggestions.
870 *
871 * @param searchable Information about how to get the suggestions.
872 * @param query The search text entered (so far).
873 * @param limit The query limit to pass to the suggestion provider. This is advisory,
874 * the returned cursor may contain more rows. Pass {@code -1} for no limit.
875 * @return a cursor with suggestions, or <code>null</null> the suggestion query failed.
876 *
877 * @hide because SearchableInfo is not part of the API.
878 */
879 public Cursor getSuggestions(SearchableInfo searchable, String query, int limit) {
Karl Rosaen875d50a2009-04-23 19:00:21 -0700880 if (searchable == null) {
881 return null;
882 }
883
884 String authority = searchable.getSuggestAuthority();
885 if (authority == null) {
886 return null;
887 }
888
889 Uri.Builder uriBuilder = new Uri.Builder()
890 .scheme(ContentResolver.SCHEME_CONTENT)
Bjorn Bringert3fc7c672009-09-28 20:11:52 +0100891 .authority(authority)
892 .query("") // TODO: Remove, workaround for a bug in Uri.writeToParcel()
893 .fragment(""); // TODO: Remove, workaround for a bug in Uri.writeToParcel()
Karl Rosaen875d50a2009-04-23 19:00:21 -0700894
895 // if content path provided, insert it now
896 final String contentPath = searchable.getSuggestPath();
897 if (contentPath != null) {
898 uriBuilder.appendEncodedPath(contentPath);
899 }
900
Bjorn Bringert3fc7c672009-09-28 20:11:52 +0100901 // append standard suggestion query path
Karl Rosaen875d50a2009-04-23 19:00:21 -0700902 uriBuilder.appendPath(SearchManager.SUGGEST_URI_PATH_QUERY);
903
904 // get the query selection, may be null
905 String selection = searchable.getSuggestSelection();
906 // inject query, either as selection args or inline
907 String[] selArgs = null;
908 if (selection != null) { // use selection if provided
909 selArgs = new String[] { query };
910 } else { // no selection, use REST pattern
911 uriBuilder.appendPath(query);
912 }
913
Bjorn Bringert3fc7c672009-09-28 20:11:52 +0100914 if (limit > 0) {
915 uriBuilder.appendQueryParameter(SUGGEST_PARAMETER_LIMIT, String.valueOf(limit));
916 }
917
918 Uri uri = uriBuilder.build();
Karl Rosaen875d50a2009-04-23 19:00:21 -0700919
920 // finally, make the query
Bjorn Bringert8d153822009-06-22 10:31:44 +0100921 return mContext.getContentResolver().query(uri, null, selection, selArgs, null);
Karl Rosaen875d50a2009-04-23 19:00:21 -0700922 }
Amith Yamasanie678f462010-09-15 16:13:43 -0700923
Bjorn Bringert6d72e022009-04-29 14:56:12 +0100924 /**
925 * Returns a list of the searchable activities that can be included in global search.
Amith Yamasanie678f462010-09-15 16:13:43 -0700926 *
Bjorn Bringert6d72e022009-04-29 14:56:12 +0100927 * @return a list containing searchable information for all searchable activities
Bjorn Bringert13107bb2009-12-07 10:41:24 +0000928 * that have the <code>android:includeInGlobalSearch</code> attribute set
929 * in their searchable meta-data.
Bjorn Bringert6d72e022009-04-29 14:56:12 +0100930 */
Bjorn Bringert8d153822009-06-22 10:31:44 +0100931 public List<SearchableInfo> getSearchablesInGlobalSearch() {
Bjorn Bringert6d72e022009-04-29 14:56:12 +0100932 try {
Bjorn Bringert8d153822009-06-22 10:31:44 +0100933 return mService.getSearchablesInGlobalSearch();
Bjorn Bringert6d72e022009-04-29 14:56:12 +0100934 } catch (RemoteException e) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700935 throw e.rethrowFromSystemServer();
Bjorn Bringert6d72e022009-04-29 14:56:12 +0100936 }
937 }
Satish Sampathf9acde22009-06-04 11:51:17 +0100938
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700939 /**
Jim Miller45308b12012-06-18 19:23:39 -0700940 * Gets an intent for launching installed assistant activity, or null if not available.
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700941 * @return The assist intent.
942 *
943 * @hide
944 */
Jorim Jaggi165ce062015-07-06 16:18:11 -0700945 public Intent getAssistIntent(boolean inclContext) {
Amith Yamasanic1d07a42012-08-14 09:32:02 -0700946 try {
Amith Yamasanic1d07a42012-08-14 09:32:02 -0700947 Intent intent = new Intent(Intent.ACTION_ASSIST);
Dianne Hackbornf9c5e0f2013-01-23 14:39:13 -0800948 if (inclContext) {
949 IActivityManager am = ActivityManagerNative.getDefault();
Dianne Hackborna83ce1d2015-03-11 15:16:13 -0700950 Bundle extras = am.getAssistContextExtras(ActivityManager.ASSIST_CONTEXT_BASIC);
Dianne Hackbornf9c5e0f2013-01-23 14:39:13 -0800951 if (extras != null) {
952 intent.replaceExtras(extras);
953 }
954 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700955 return intent;
Amith Yamasanic1d07a42012-08-14 09:32:02 -0700956 } catch (RemoteException re) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700957 throw re.rethrowFromSystemServer();
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700958 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700959 }
Dianne Hackbornfdf5b352014-10-08 17:43:48 -0700960
961 /**
Jorim Jaggi165ce062015-07-06 16:18:11 -0700962 * Starts the assistant.
963 *
964 * @param args the args to pass to the assistant
965 *
Dianne Hackbornfdf5b352014-10-08 17:43:48 -0700966 * @hide
967 */
Jorim Jaggi165ce062015-07-06 16:18:11 -0700968 public void launchAssist(Bundle args) {
969 try {
970 if (mService == null) {
971 return;
972 }
973 mService.launchAssist(args);
974 } catch (RemoteException re) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700975 throw re.rethrowFromSystemServer();
Jorim Jaggi165ce062015-07-06 16:18:11 -0700976 }
977 }
978
979 /**
980 * Starts the legacy assistant (i.e. the {@link Intent#ACTION_ASSIST}).
981 *
982 * @param args the args to pass to the assistant
983 *
984 * @hide
985 */
986 public boolean launchLegacyAssist(String hint, int userHandle, Bundle args) {
Dianne Hackbornfdf5b352014-10-08 17:43:48 -0700987 try {
988 if (mService == null) {
989 return false;
990 }
Jorim Jaggi165ce062015-07-06 16:18:11 -0700991 return mService.launchLegacyAssist(hint, userHandle, args);
Dianne Hackbornfdf5b352014-10-08 17:43:48 -0700992 } catch (RemoteException re) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700993 throw re.rethrowFromSystemServer();
Dianne Hackbornfdf5b352014-10-08 17:43:48 -0700994 }
995 }
Amith Yamasanie9ce3f02010-01-25 09:15:50 -0800996}