blob: ac4abf5c36a4563d9ee0721d084bf3ba71e03f0b [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;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070034import android.os.UserHandle;
Bjorn Bringert3fc7c672009-09-28 20:11:52 +010035import android.text.TextUtils;
Bjorn Bringert8d17f3f2009-06-05 13:22:28 +010036import android.util.Log;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037import android.view.KeyEvent;
38
Bjorn Bringert6d72e022009-04-29 14:56:12 +010039import java.util.List;
40
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080041/**
42 * This class provides access to the system search services.
Amith Yamasanie678f462010-09-15 16:13:43 -070043 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044 * <p>In practice, you won't interact with this class directly, as search
45 * services are provided through methods in {@link android.app.Activity Activity}
Scott Main8ad64652010-03-17 12:06:06 -070046 * and the {@link android.content.Intent#ACTION_SEARCH ACTION_SEARCH}
47 * {@link android.content.Intent Intent}.
48 * If you do require direct access to the SearchManager, do not instantiate
49 * this class directly. Instead, retrieve it through
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080050 * {@link android.content.Context#getSystemService
51 * context.getSystemService(Context.SEARCH_SERVICE)}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080052 *
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080053 * <div class="special reference">
54 * <h3>Developer Guides</h3>
55 * <p>For more information about using the search dialog and adding search
56 * suggestions in your application, read the
57 * <a href="{@docRoot}guide/topics/search/index.html">Search</a> developer guide.</p>
Scott Main8ad64652010-03-17 12:06:06 -070058 * </div>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080059 */
Amith Yamasanie678f462010-09-15 16:13:43 -070060public class SearchManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061 implements DialogInterface.OnDismissListener, DialogInterface.OnCancelListener
62{
Bjorn Bringert8d17f3f2009-06-05 13:22:28 +010063
64 private static final boolean DBG = false;
65 private static final String TAG = "SearchManager";
66
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067 /**
68 * This is a shortcut definition for the default menu key to use for invoking search.
Amith Yamasanie678f462010-09-15 16:13:43 -070069 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080070 * See Menu.Item.setAlphabeticShortcut() for more information.
71 */
72 public final static char MENU_KEY = 's';
73
74 /**
75 * This is a shortcut definition for the default menu key to use for invoking search.
Amith Yamasanie678f462010-09-15 16:13:43 -070076 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080077 * See Menu.Item.setAlphabeticShortcut() for more information.
78 */
79 public final static int MENU_KEYCODE = KeyEvent.KEYCODE_S;
80
81 /**
Amith Yamasanie678f462010-09-15 16:13:43 -070082 * Intent extra data key: Use this key with
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080083 * {@link android.content.Intent#getStringExtra
84 * content.Intent.getStringExtra()}
85 * to obtain the query string from Intent.ACTION_SEARCH.
86 */
87 public final static String QUERY = "query";
88
89 /**
Bjorn Bringert5f806052009-06-24 12:02:26 +010090 * Intent extra data key: Use this key with
91 * {@link android.content.Intent#getStringExtra
92 * content.Intent.getStringExtra()}
93 * to obtain the query string typed in by the user.
94 * This may be different from the value of {@link #QUERY}
95 * if the intent is the result of selecting a suggestion.
96 * In that case, {@link #QUERY} will contain the value of
97 * {@link #SUGGEST_COLUMN_QUERY} for the suggestion, and
98 * {@link #USER_QUERY} will contain the string typed by the
99 * user.
100 */
101 public final static String USER_QUERY = "user_query";
102
103 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800104 * Intent extra data key: Use this key with Intent.ACTION_SEARCH and
105 * {@link android.content.Intent#getBundleExtra
106 * content.Intent.getBundleExtra()}
Amith Yamasanie678f462010-09-15 16:13:43 -0700107 * to obtain any additional app-specific data that was inserted by the
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800108 * activity that launched the search.
109 */
110 public final static String APP_DATA = "app_data";
111
112 /**
Bjorn Bringertbe5b73c2009-09-21 23:05:23 +0100113 * Intent extra data key: Use {@link android.content.Intent#getBundleExtra
114 * content.Intent.getBundleExtra(SEARCH_MODE)} to get the search mode used
115 * to launch the intent.
116 * The only current value for this is {@link #MODE_GLOBAL_SEARCH_SUGGESTION}.
117 *
118 * @hide
119 */
120 public final static String SEARCH_MODE = "search_mode";
121
122 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800123 * Intent extra data key: Use this key with Intent.ACTION_SEARCH and
124 * {@link android.content.Intent#getIntExtra content.Intent.getIntExtra()}
125 * to obtain the keycode that the user used to trigger this query. It will be zero if the
126 * user simply pressed the "GO" button on the search UI. This is primarily used in conjunction
127 * with the keycode attribute in the actionkey element of your searchable.xml configuration
128 * file.
129 */
130 public final static String ACTION_KEY = "action_key";
Amith Yamasanie678f462010-09-15 16:13:43 -0700131
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800132 /**
Karl Rosaen875d50a2009-04-23 19:00:21 -0700133 * Intent extra data key: This key will be used for the extra populated by the
134 * {@link #SUGGEST_COLUMN_INTENT_EXTRA_DATA} column.
Karl Rosaen875d50a2009-04-23 19:00:21 -0700135 */
136 public final static String EXTRA_DATA_KEY = "intent_extra_data_key";
Karl Rosaena058f022009-06-01 23:11:44 +0100137
Karl Rosaena058f022009-06-01 23:11:44 +0100138 /**
Bjorn Bringert55f3ac52010-01-14 11:38:22 +0000139 * Boolean extra data key for {@link #INTENT_ACTION_GLOBAL_SEARCH} intents. If {@code true},
140 * the initial query should be selected when the global search activity is started, so
141 * that the user can easily replace it with another query.
Bjorn Bringert3c50ef62009-12-09 12:23:12 +0000142 */
Bjorn Bringert55f3ac52010-01-14 11:38:22 +0000143 public final static String EXTRA_SELECT_QUERY = "select_query";
Bjorn Bringert32d580c2010-01-06 09:29:11 +0000144
Bjorn Bringert3c50ef62009-12-09 12:23:12 +0000145 /**
Leon Scrogginsaf5b4062011-02-22 16:35:13 -0500146 * Boolean extra data key for {@link Intent#ACTION_WEB_SEARCH} intents. If {@code true},
147 * this search should open a new browser window, rather than using an existing one.
148 */
149 public final static String EXTRA_NEW_SEARCH = "new_search";
150
151 /**
Bjorn Bringert4519ff62011-08-10 15:42:11 -0700152 * Extra data key for {@link Intent#ACTION_WEB_SEARCH}. If set, the value must be a
153 * {@link PendingIntent}. The search activity handling the {@link Intent#ACTION_WEB_SEARCH}
154 * intent will fill in and launch the pending intent. The data URI will be filled in with an
155 * http or https URI, and {@link android.provider.Browser#EXTRA_HEADERS} may be filled in.
156 */
157 public static final String EXTRA_WEB_SEARCH_PENDINGINTENT = "web_search_pendingintent";
158
159 /**
Amith Yamasanic37cb242010-02-24 17:44:46 -0800160 * Boolean extra data key for a suggestion provider to return in {@link Cursor#getExtras} to
161 * indicate that the search is not complete yet. This can be used by the search UI
162 * to indicate that a search is in progress. The suggestion provider can return partial results
163 * this way and send a change notification on the cursor when more results are available.
164 */
165 public final static String CURSOR_EXTRA_KEY_IN_PROGRESS = "in_progress";
166
167 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800168 * Intent extra data key: Use this key with Intent.ACTION_SEARCH and
169 * {@link android.content.Intent#getStringExtra content.Intent.getStringExtra()}
170 * to obtain the action message that was defined for a particular search action key and/or
Amith Yamasanie678f462010-09-15 16:13:43 -0700171 * suggestion. It will be null if the search was launched by typing "enter", touched the the
172 * "GO" button, or other means not involving any action key.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800173 */
174 public final static String ACTION_MSG = "action_msg";
Amith Yamasanie678f462010-09-15 16:13:43 -0700175
176 /**
177 * Flag to specify that the entry can be used for query refinement, i.e., the query text
178 * in the search field can be replaced with the text in this entry, when a query refinement
179 * icon is clicked. The suggestion list should show such a clickable icon beside the entry.
180 * <p>Use this flag as a bit-field for {@link #SUGGEST_COLUMN_FLAGS}.
181 */
182 public final static int FLAG_QUERY_REFINEMENT = 1 << 0;
183
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800184 /**
185 * Uri path for queried suggestions data. This is the path that the search manager
186 * will use when querying your content provider for suggestions data based on user input
187 * (e.g. looking for partial matches).
188 * Typically you'll use this with a URI matcher.
189 */
190 public final static String SUGGEST_URI_PATH_QUERY = "search_suggest_query";
Karl Rosaenb2a50112009-05-05 21:14:01 -0700191
192 /**
Karl Rosaenb619c912009-05-08 14:28:51 -0700193 * MIME type for suggestions data. You'll use this in your suggestions content provider
194 * in the getType() function.
195 */
196 public final static String SUGGEST_MIME_TYPE =
197 "vnd.android.cursor.dir/vnd.android.search.suggest";
198
199 /**
Karl Rosaenb2a50112009-05-05 21:14:01 -0700200 * Uri path for shortcut validation. This is the path that the search manager will use when
201 * querying your content provider to refresh a shortcutted suggestion result and to check if it
202 * is still valid. When asked, a source may return an up to date result, or no result. No
203 * result indicates the shortcut refers to a no longer valid sugggestion.
204 *
205 * @see #SUGGEST_COLUMN_SHORTCUT_ID
Karl Rosaenb2a50112009-05-05 21:14:01 -0700206 */
207 public final static String SUGGEST_URI_PATH_SHORTCUT = "search_suggest_shortcut";
Amith Yamasanie678f462010-09-15 16:13:43 -0700208
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800209 /**
Karl Rosaenb619c912009-05-08 14:28:51 -0700210 * MIME type for shortcut validation. You'll use this in your suggestions content provider
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800211 * in the getType() function.
212 */
Amith Yamasanie678f462010-09-15 16:13:43 -0700213 public final static String SHORTCUT_MIME_TYPE =
Karl Rosaenb619c912009-05-08 14:28:51 -0700214 "vnd.android.cursor.item/vnd.android.search.suggest";
Karl Rosaend4c98c42009-06-09 17:05:54 +0100215
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800216 /**
217 * Column name for suggestions cursor. <i>Unused - can be null or column can be omitted.</i>
218 */
219 public final static String SUGGEST_COLUMN_FORMAT = "suggest_format";
220 /**
Amith Yamasanie678f462010-09-15 16:13:43 -0700221 * 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 -0800222 * will be presented to the user as the suggestion.
223 */
224 public final static String SUGGEST_COLUMN_TEXT_1 = "suggest_text_1";
225 /**
226 * Column name for suggestions cursor. <i>Optional.</i> If your cursor includes this column,
227 * then all suggestions will be provided in a two-line format. The second line of text is in
228 * a much smaller appearance.
229 */
230 public final static String SUGGEST_COLUMN_TEXT_2 = "suggest_text_2";
Bjorn Bringert0b49ab52010-03-02 11:16:17 +0000231
232 /**
233 * Column name for suggestions cursor. <i>Optional.</i> This is a URL that will be shown
234 * as the second line of text instead of {@link #SUGGEST_COLUMN_TEXT_2}. This is a separate
235 * column so that the search UI knows to display the text as a URL, e.g. by using a different
236 * color. If this column is absent, or has the value {@code null},
237 * {@link #SUGGEST_COLUMN_TEXT_2} will be used instead.
238 */
239 public final static String SUGGEST_COLUMN_TEXT_2_URL = "suggest_text_2_url";
240
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800241 /**
242 * Column name for suggestions cursor. <i>Optional.</i> If your cursor includes this column,
Karl Rosaen875d50a2009-04-23 19:00:21 -0700243 * 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 -0800244 * 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 -0700245 * be a resource ID of a drawable, or a URI in one of the following formats:
246 *
247 * <ul>
248 * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li>
249 * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li>
250 * <li>file ({@link android.content.ContentResolver#SCHEME_FILE})</li>
251 * </ul>
252 *
Amith Yamasanie678f462010-09-15 16:13:43 -0700253 * See {@link android.content.ContentResolver#openAssetFileDescriptor(Uri, String)}
254 * for more information on these schemes.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800255 */
256 public final static String SUGGEST_COLUMN_ICON_1 = "suggest_icon_1";
Xiaolei Wangb2b2ac12014-05-28 15:18:15 -0700257
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800258 /**
259 * Column name for suggestions cursor. <i>Optional.</i> If your cursor includes this column,
Karl Rosaen875d50a2009-04-23 19:00:21 -0700260 * 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 -0800261 * 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 -0700262 * be a resource ID of a drawable, or a URI in one of the following formats:
263 *
264 * <ul>
265 * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li>
266 * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li>
267 * <li>file ({@link android.content.ContentResolver#SCHEME_FILE})</li>
268 * </ul>
269 *
Amith Yamasanie678f462010-09-15 16:13:43 -0700270 * See {@link android.content.ContentResolver#openAssetFileDescriptor(Uri, String)}
271 * for more information on these schemes.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800272 */
273 public final static String SUGGEST_COLUMN_ICON_2 = "suggest_icon_2";
Xiaolei Wangb2b2ac12014-05-28 15:18:15 -0700274
275 /**
276 * Column name for suggestions cursor. <i>Optional.</i> If your cursor includes this column,
277 * then the image will be displayed when forming the suggestion. The suggested dimension for
278 * the image is 270x400 px for portrait mode and 400x225 px for landscape mode. The data in the
279 * column must be a resource ID of a drawable, or a URI in one of the following formats:
280 *
281 * <ul>
282 * <li>content ({@link android.content.ContentResolver#SCHEME_CONTENT})</li>
283 * <li>android.resource ({@link android.content.ContentResolver#SCHEME_ANDROID_RESOURCE})</li>
284 * <li>file ({@link android.content.ContentResolver#SCHEME_FILE})</li>
285 * </ul>
286 *
287 * See {@link android.content.ContentResolver#openAssetFileDescriptor(Uri, String)}
288 * for more information on these schemes.
289 */
290 public final static String SUGGEST_COLUMN_RESULT_CARD_IMAGE = "suggest_result_card_image";
291
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800292 /**
293 * Column name for suggestions cursor. <i>Optional.</i> If this column exists <i>and</i>
294 * this element exists at the given row, this is the action that will be used when
295 * forming the suggestion's intent. If the element is not provided, the action will be taken
296 * from the android:searchSuggestIntentAction field in your XML metadata. <i>At least one of
297 * these must be present for the suggestion to generate an intent.</i> Note: If your action is
298 * the same for all suggestions, it is more efficient to specify it using XML metadata and omit
299 * it from the cursor.
300 */
301 public final static String SUGGEST_COLUMN_INTENT_ACTION = "suggest_intent_action";
Xiaolei Wangb2b2ac12014-05-28 15:18:15 -0700302
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800303 /**
304 * Column name for suggestions cursor. <i>Optional.</i> If this column exists <i>and</i>
305 * this element exists at the given row, this is the data that will be used when
306 * forming the suggestion's intent. If the element is not provided, the data will be taken
307 * from the android:searchSuggestIntentData field in your XML metadata. If neither source
308 * is provided, the Intent's data field will be null. Note: If your data is
309 * the same for all suggestions, or can be described using a constant part and a specific ID,
310 * it is more efficient to specify it using XML metadata and omit it from the cursor.
311 */
312 public final static String SUGGEST_COLUMN_INTENT_DATA = "suggest_intent_data";
Xiaolei Wangb2b2ac12014-05-28 15:18:15 -0700313
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800314 /**
Satish Sampathbf23fe02009-06-15 23:47:56 +0100315 * Column name for suggestions cursor. <i>Optional.</i> If this column exists <i>and</i>
316 * this element exists at the given row, this is the data that will be used when
317 * forming the suggestion's intent. If not provided, the Intent's extra data field will be null.
318 * This column allows suggestions to provide additional arbitrary data which will be included as
Mike LeBeau131234c2009-07-20 14:09:52 -0700319 * an extra under the key {@link #EXTRA_DATA_KEY}.
Satish Sampathbf23fe02009-06-15 23:47:56 +0100320 */
321 public final static String SUGGEST_COLUMN_INTENT_EXTRA_DATA = "suggest_intent_extra_data";
Xiaolei Wangb2b2ac12014-05-28 15:18:15 -0700322
Satish Sampathbf23fe02009-06-15 23:47:56 +0100323 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800324 * Column name for suggestions cursor. <i>Optional.</i> If this column exists <i>and</i>
325 * this element exists at the given row, then "/" and this value will be appended to the data
326 * field in the Intent. This should only be used if the data field has already been set to an
327 * appropriate base string.
328 */
329 public final static String SUGGEST_COLUMN_INTENT_DATA_ID = "suggest_intent_data_id";
Xiaolei Wangb2b2ac12014-05-28 15:18:15 -0700330
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800331 /**
Amith Yamasanie678f462010-09-15 16:13:43 -0700332 * Column name for suggestions cursor. <i>Required if action is
333 * {@link android.content.Intent#ACTION_SEARCH ACTION_SEARCH}, optional otherwise.</i> If this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800334 * column exists <i>and</i> this element exists at the given row, this is the data that will be
335 * used when forming the suggestion's query.
336 */
337 public final static String SUGGEST_COLUMN_QUERY = "suggest_intent_query";
338
Karl Rosaen875d50a2009-04-23 19:00:21 -0700339 /**
Karl Rosaenb2a50112009-05-05 21:14:01 -0700340 * Column name for suggestions cursor. <i>Optional.</i> This column is used to indicate whether
Karl Rosaenb5041362009-08-11 11:35:07 -0700341 * a search suggestion should be stored as a shortcut, and whether it should be refreshed. If
Karl Rosaenb2a50112009-05-05 21:14:01 -0700342 * missing, the result will be stored as a shortcut and never validated. If set to
343 * {@link #SUGGEST_NEVER_MAKE_SHORTCUT}, the result will not be stored as a shortcut.
Karl Rosaenb5041362009-08-11 11:35:07 -0700344 * Otherwise, the shortcut id will be used to check back for an up to date suggestion using
Karl Rosaenb2a50112009-05-05 21:14:01 -0700345 * {@link #SUGGEST_URI_PATH_SHORTCUT}.
Karl Rosaenb2a50112009-05-05 21:14:01 -0700346 */
347 public final static String SUGGEST_COLUMN_SHORTCUT_ID = "suggest_shortcut_id";
348
349 /**
Mike LeBeauce0959d2009-06-10 23:47:54 +0100350 * Column name for suggestions cursor. <i>Optional.</i> This column is used to specify
351 * that a spinner should be shown in lieu of an icon2 while the shortcut of this suggestion
352 * is being refreshed.
Mike LeBeauce0959d2009-06-10 23:47:54 +0100353 */
354 public final static String SUGGEST_COLUMN_SPINNER_WHILE_REFRESHING =
355 "suggest_spinner_while_refreshing";
Satish Sampath1c5fa0f2009-06-08 23:10:40 +0100356
357 /**
Xiaolei Wangb2b2ac12014-05-28 15:18:15 -0700358 * Column name for suggestions cursor. <i>Optional.</i> If your content is media type, you
359 * should provide this column so search app could understand more about your content. The data
360 * in the column must specify the MIME type of the content.
361 */
362 public final static String SUGGEST_COLUMN_CONTENT_TYPE = "suggest_content_type";
363
364 /**
365 * Column name for suggestions cursor. <i>Optional.</i> If your content is media type, you
366 * should provide this column to specify whether your content is live media such as live video
367 * or live audio. The value in the column is of integer type with value of either 0 indicating
368 * non-live content or 1 indicating live content.
369 */
370 public final static String SUGGEST_COLUMN_IS_LIVE = "suggest_is_live";
371
372 /**
373 * Column name for suggestions cursor. <i>Optional.</i> If your content is video, you should
374 * provide this column to specify the number of vertical lines. The data in the column is of
375 * integer type.
376 */
377 public final static String SUGGEST_COLUMN_VIDEO_WIDTH = "suggest_video_width";
378
379 /**
380 * Column name for suggestions cursor. <i>Optional.</i> If your content is video, you should
381 * provide this column to specify the number of horizontal lines. The data in the column is of
382 * integer type.
383 */
384 public final static String SUGGEST_COLUMN_VIDEO_HEIGHT = "suggest_video_height";
385
386 /**
387 * Column name for suggestions cursor. <i>Optional.</i> If your content contains audio, you
388 * should provide this column to specify the audio channel configuration. The data in the
389 * column is string with format like "channels.subchannels" such as "1.0" or "5.1".
390 */
391 public final static String SUGGEST_COLUMN_AUDIO_CHANNEL_CONFIG = "suggest_audio_channel_config";
392
393 /**
394 * Column name for suggestions cursor. <i>Optional.</i> If your content is purchasable, you
395 * should provide this column to specify the displayable string representation of the purchase
396 * price of your content including the currency and the amount. If it's free, you should
397 * provide localized string to specify that it's free. This column can be omitted if the content
398 * is not applicable to purchase.
399 */
400 public final static String SUGGEST_COLUMN_PURCHASE_PRICE = "suggest_purchase_price";
401
402 /**
403 * Column name for suggestions cursor. <i>Optional.</i> If your content is rentable, you
404 * should provide this column to specify the displayable string representation of the rental
405 * price of your content including the currency and the amount. If it's free, you should
406 * provide localized string to specify that it's free. This column can be ommitted if the
407 * content is not applicable to rent.
408 */
409 public final static String SUGGEST_COLUMN_RENTAL_PRICE = "suggest_rental_price";
410
411 /**
412 * Column name for suggestions cursor. <i>Optional.</i> If your content has a rating, you
413 * should provide this column to specify the rating style of your content. The data in the
414 * column must be one of the constant values specified in {@link android.media.Rating}
415 */
416 public final static String SUGGEST_COLUMN_RATING_STYLE = "suggest_rating_style";
417
418 /**
419 * Column name for suggestions cursor. <i>Optional.</i> If your content has a rating, you
420 * should provide this column to specify the rating score of your content. The data in the
421 * column is of float type. See {@link android.media.Rating} about valid rating scores for each
422 * rating style.
423 */
424 public final static String SUGGEST_COLUMN_RATING_SCORE = "suggest_rating_score";
425
426 /**
427 * Column name for suggestions cursor. <i>Optional.</i> If your content is video or audio and
428 * has a known production year, you should provide this column to specify the production year
429 * of your content. The data in the column is of integer type.
430 */
431 public final static String SUGGEST_COLUMN_PRODUCTION_YEAR = "suggest_production_year";
432
433 /**
434 * Column name for suggestions cursor. <i>Optional.</i> If your content is video or audio, you
435 * should provide this column to specify the duration of your content in milliseconds. The data
436 * in the column is of long type.
437 */
438 public final static String SUGGEST_COLUMN_DURATION = "suggest_duration";
439
440 /**
Amith Yamasanie678f462010-09-15 16:13:43 -0700441 * Column name for suggestions cursor. <i>Optional.</i> This column is used to specify
442 * additional flags per item. Multiple flags can be specified.
443 * <p>
444 * Must be one of {@link #FLAG_QUERY_REFINEMENT} or 0 to indicate no flags.
445 * </p>
446 */
447 public final static String SUGGEST_COLUMN_FLAGS = "suggest_flags";
448
449 /**
Mark Brophya31c7aa2011-06-17 16:36:38 +0100450 * Column name for suggestions cursor. <i>Optional.</i> This column may be
Mark Brophyde2ba4c2011-09-16 12:27:20 +0100451 * used to specify the time in {@link System#currentTimeMillis
Mark Brophya31c7aa2011-06-17 16:36:38 +0100452 * System.currentTImeMillis()} (wall time in UTC) when an item was last
453 * accessed within the results-providing application. If set, this may be
454 * used to show more-recently-used items first.
455 */
456 public final static String SUGGEST_COLUMN_LAST_ACCESS_HINT = "suggest_last_access_hint";
457
458 /**
Karl Rosaenb2a50112009-05-05 21:14:01 -0700459 * Column value for suggestion column {@link #SUGGEST_COLUMN_SHORTCUT_ID} when a suggestion
460 * should not be stored as a shortcut in global search.
Karl Rosaenb2a50112009-05-05 21:14:01 -0700461 */
462 public final static String SUGGEST_NEVER_MAKE_SHORTCUT = "_-1";
463
464 /**
Bjorn Bringert3fc7c672009-09-28 20:11:52 +0100465 * Query parameter added to suggestion queries to limit the number of suggestions returned.
Bjorn Bringert86917db2009-09-28 22:00:50 +0100466 * This limit is only advisory and suggestion providers may chose to ignore it.
Bjorn Bringert3fc7c672009-09-28 20:11:52 +0100467 */
468 public final static String SUGGEST_PARAMETER_LIMIT = "limit";
469
470 /**
Bjorn Bringert55f3ac52010-01-14 11:38:22 +0000471 * Intent action for starting the global search activity.
Bjorn Bringert74708bb2009-04-28 11:26:52 +0100472 * The global search provider should handle this intent.
Bjorn Bringert55f3ac52010-01-14 11:38:22 +0000473 *
474 * Supported extra data keys: {@link #QUERY},
475 * {@link #EXTRA_SELECT_QUERY},
476 * {@link #APP_DATA}.
Bjorn Bringert74708bb2009-04-28 11:26:52 +0100477 */
Amith Yamasanie678f462010-09-15 16:13:43 -0700478 public final static String INTENT_ACTION_GLOBAL_SEARCH
Bjorn Bringert74708bb2009-04-28 11:26:52 +0100479 = "android.search.action.GLOBAL_SEARCH";
Amith Yamasanie678f462010-09-15 16:13:43 -0700480
Bjorn Bringert74708bb2009-04-28 11:26:52 +0100481 /**
Karl Rosaen875d50a2009-04-23 19:00:21 -0700482 * Intent action for starting the global search settings activity.
483 * The global search provider should handle this intent.
Karl Rosaen875d50a2009-04-23 19:00:21 -0700484 */
Amith Yamasanie678f462010-09-15 16:13:43 -0700485 public final static String INTENT_ACTION_SEARCH_SETTINGS
Karl Rosaen875d50a2009-04-23 19:00:21 -0700486 = "android.search.action.SEARCH_SETTINGS";
Amith Yamasanie678f462010-09-15 16:13:43 -0700487
Mike LeBeau3a278032009-06-04 14:09:42 +0100488 /**
489 * Intent action for starting a web search provider's settings activity.
490 * Web search providers should handle this intent if they have provider-specific
491 * settings to implement.
Mike LeBeau3a278032009-06-04 14:09:42 +0100492 */
493 public final static String INTENT_ACTION_WEB_SEARCH_SETTINGS
494 = "android.search.action.WEB_SEARCH_SETTINGS";
Karl Rosaena058f022009-06-01 23:11:44 +0100495
496 /**
Satish Sampathf9acde22009-06-04 11:51:17 +0100497 * Intent action broadcasted to inform that the searchables list or default have changed.
498 * Components should handle this intent if they cache any searchable data and wish to stay
499 * up to date on changes.
Satish Sampathf9acde22009-06-04 11:51:17 +0100500 */
501 public final static String INTENT_ACTION_SEARCHABLES_CHANGED
502 = "android.search.action.SEARCHABLES_CHANGED";
Amith Yamasanie678f462010-09-15 16:13:43 -0700503
Mike LeBeaud4fb7a02009-07-20 17:37:38 -0700504 /**
Narayan Kamathee69ff42011-06-28 12:07:18 +0100505 * Intent action to be broadcast to inform that the global search provider
Michael Jurka3f5cfcf2012-04-27 14:20:59 -0700506 * has changed.
Narayan Kamathee69ff42011-06-28 12:07:18 +0100507 */
508 public final static String INTENT_GLOBAL_SEARCH_ACTIVITY_CHANGED
509 = "android.search.action.GLOBAL_SEARCH_ACTIVITY_CHANGED";
510
511 /**
Mike LeBeaud4fb7a02009-07-20 17:37:38 -0700512 * Intent action broadcasted to inform that the search settings have changed in some way.
Karl Rosaen590f6342009-08-27 17:42:48 -0700513 * Either searchables have been enabled or disabled, or a different web search provider
514 * has been chosen.
Mike LeBeaud4fb7a02009-07-20 17:37:38 -0700515 */
516 public final static String INTENT_ACTION_SEARCH_SETTINGS_CHANGED
517 = "android.search.action.SETTINGS_CHANGED";
Satish Sampathf9acde22009-06-04 11:51:17 +0100518
519 /**
Leon Scroggins4f22a542010-03-09 17:28:13 -0500520 * This means that context is voice, and therefore the SearchDialog should
521 * continue showing the microphone until the user indicates that he/she does
522 * not want to re-speak (e.g. by typing).
523 *
524 * @hide
525 */
526 public final static String CONTEXT_IS_VOICE = "android.search.CONTEXT_IS_VOICE";
527
528 /**
Leon Scroggins III4a028002010-09-14 10:56:25 -0400529 * This means that the voice icon should not be shown at all, because the
530 * current search engine does not support voice search.
531 * @hide
532 */
533 public final static String DISABLE_VOICE_SEARCH
534 = "android.search.DISABLE_VOICE_SEARCH";
535
536 /**
Karl Rosaen875d50a2009-04-23 19:00:21 -0700537 * Reference to the shared system search service.
538 */
Bjorn Bringert8d153822009-06-22 10:31:44 +0100539 private static ISearchManager mService;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800540
541 private final Context mContext;
Bjorn Bringert8d17f3f2009-06-05 13:22:28 +0100542
543 // package private since they are used by the inner class SearchManagerCallback
Bjorn Bringert8d17f3f2009-06-05 13:22:28 +0100544 /* package */ final Handler mHandler;
545 /* package */ OnDismissListener mDismissListener = null;
546 /* package */ OnCancelListener mCancelListener = null;
547
Amith Yamasanie9ce3f02010-01-25 09:15:50 -0800548 private SearchDialog mSearchDialog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800549
550 /*package*/ SearchManager(Context context, Handler handler) {
551 mContext = context;
552 mHandler = handler;
Bjorn Bringert8d153822009-06-22 10:31:44 +0100553 mService = ISearchManager.Stub.asInterface(
554 ServiceManager.getService(Context.SEARCH_SERVICE));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800555 }
Amith Yamasanie678f462010-09-15 16:13:43 -0700556
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800557 /**
558 * Launch search UI.
559 *
560 * <p>The search manager will open a search widget in an overlapping
Amith Yamasanie678f462010-09-15 16:13:43 -0700561 * window, and the underlying activity may be obscured. The search
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800562 * entry state will remain in effect until one of the following events:
563 * <ul>
Amith Yamasanie678f462010-09-15 16:13:43 -0700564 * <li>The user completes the search. In most cases this will launch
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800565 * a search intent.</li>
566 * <li>The user uses the back, home, or other keys to exit the search.</li>
567 * <li>The application calls the {@link #stopSearch}
568 * method, which will hide the search window and return focus to the
569 * activity from which it was launched.</li>
570 *
571 * <p>Most applications will <i>not</i> use this interface to invoke search.
Amith Yamasanie678f462010-09-15 16:13:43 -0700572 * The primary method for invoking search is to call
573 * {@link android.app.Activity#onSearchRequested Activity.onSearchRequested()} or
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800574 * {@link android.app.Activity#startSearch Activity.startSearch()}.
575 *
576 * @param initialQuery A search string can be pre-entered here, but this
577 * is typically null or empty.
578 * @param selectInitialQuery If true, the intial query will be preselected, which means that
579 * any further typing will replace it. This is useful for cases where an entire pre-formed
580 * query is being inserted. If false, the selection point will be placed at the end of the
581 * inserted query. This is useful when the inserted query is text that the user entered,
582 * and the user would expect to be able to keep typing. <i>This parameter is only meaningful
583 * if initialQuery is a non-empty string.</i>
584 * @param launchActivity The ComponentName of the activity that has launched this search.
Amith Yamasanie678f462010-09-15 16:13:43 -0700585 * @param appSearchData An application can insert application-specific
586 * context here, in order to improve quality or specificity of its own
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800587 * searches. This data will be returned with SEARCH intent(s). Null if
588 * no extra data is required.
589 * @param globalSearch If false, this will only launch the search that has been specifically
Amith Yamasanie678f462010-09-15 16:13:43 -0700590 * defined by the application (which is usually defined as a local search). If no default
Mike LeBeaucfa419b2009-08-17 10:56:02 -0700591 * search is defined in the current application or activity, global search will be launched.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800592 * If true, this will always launch a platform-global (e.g. web-based) search instead.
Amith Yamasanie678f462010-09-15 16:13:43 -0700593 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800594 * @see android.app.Activity#onSearchRequested
595 * @see #stopSearch
596 */
Amith Yamasanie678f462010-09-15 16:13:43 -0700597 public void startSearch(String initialQuery,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800598 boolean selectInitialQuery,
599 ComponentName launchActivity,
600 Bundle appSearchData,
601 boolean globalSearch) {
Mathew Inwood050453e2011-10-13 11:00:39 +0100602 startSearch(initialQuery, selectInitialQuery, launchActivity,
603 appSearchData, globalSearch, null);
604 }
605
606 /**
607 * As {@link #startSearch(String, boolean, ComponentName, Bundle, boolean)} but including
608 * source bounds for the global search intent.
609 *
610 * @hide
611 */
612 public void startSearch(String initialQuery,
613 boolean selectInitialQuery,
614 ComponentName launchActivity,
615 Bundle appSearchData,
616 boolean globalSearch,
617 Rect sourceBounds) {
Bjorn Bringert3c50ef62009-12-09 12:23:12 +0000618 if (globalSearch) {
Mathew Inwood050453e2011-10-13 11:00:39 +0100619 startGlobalSearch(initialQuery, selectInitialQuery, appSearchData, sourceBounds);
Bjorn Bringert3c50ef62009-12-09 12:23:12 +0000620 return;
621 }
622
Tim Kilbourn99e90952014-10-08 17:01:42 -0700623 UiModeManager uiModeManager = new UiModeManager();
624 // Don't show search dialog on televisions.
625 if (uiModeManager.getCurrentModeType() != Configuration.UI_MODE_TYPE_TELEVISION) {
626 ensureSearchDialog();
Amith Yamasani479ae0a2010-02-04 14:52:32 -0800627
Tim Kilbourn99e90952014-10-08 17:01:42 -0700628 mSearchDialog.show(initialQuery, selectInitialQuery, launchActivity, appSearchData);
629 }
Amith Yamasanie9ce3f02010-01-25 09:15:50 -0800630 }
631
632 private void ensureSearchDialog() {
633 if (mSearchDialog == null) {
634 mSearchDialog = new SearchDialog(mContext, this);
635 mSearchDialog.setOnCancelListener(this);
636 mSearchDialog.setOnDismissListener(this);
krosaend2d60142009-08-17 08:56:48 -0700637 }
638 }
639
640 /**
Bjorn Bringert3c50ef62009-12-09 12:23:12 +0000641 * Starts the global search activity.
642 */
Amith Yamasanie9ce3f02010-01-25 09:15:50 -0800643 /* package */ void startGlobalSearch(String initialQuery, boolean selectInitialQuery,
Mathew Inwood050453e2011-10-13 11:00:39 +0100644 Bundle appSearchData, Rect sourceBounds) {
Bjorn Bringert3c50ef62009-12-09 12:23:12 +0000645 ComponentName globalSearchActivity = getGlobalSearchActivity();
646 if (globalSearchActivity == null) {
647 Log.w(TAG, "No global search activity found.");
648 return;
649 }
Bjorn Bringerta94e7af2010-01-13 21:09:20 +0000650 Intent intent = new Intent(INTENT_ACTION_GLOBAL_SEARCH);
Bjorn Bringertb8144a92010-02-22 20:48:57 +0000651 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Bjorn Bringert3c50ef62009-12-09 12:23:12 +0000652 intent.setComponent(globalSearchActivity);
Bjorn Bringert3c24cb72010-03-16 12:54:41 +0000653 // Make sure that we have a Bundle to put source in
654 if (appSearchData == null) {
655 appSearchData = new Bundle();
656 } else {
657 appSearchData = new Bundle(appSearchData);
Bjorn Bringert3c50ef62009-12-09 12:23:12 +0000658 }
Bjorn Bringert3c24cb72010-03-16 12:54:41 +0000659 // Set source to package name of app that starts global search, if not set already.
660 if (!appSearchData.containsKey("source")) {
661 appSearchData.putString("source", mContext.getPackageName());
662 }
663 intent.putExtra(APP_DATA, appSearchData);
Bjorn Bringert3c50ef62009-12-09 12:23:12 +0000664 if (!TextUtils.isEmpty(initialQuery)) {
Bjorn Bringert55f3ac52010-01-14 11:38:22 +0000665 intent.putExtra(QUERY, initialQuery);
Bjorn Bringert3c50ef62009-12-09 12:23:12 +0000666 }
667 if (selectInitialQuery) {
Bjorn Bringert55f3ac52010-01-14 11:38:22 +0000668 intent.putExtra(EXTRA_SELECT_QUERY, selectInitialQuery);
Bjorn Bringert3c50ef62009-12-09 12:23:12 +0000669 }
Mathew Inwood050453e2011-10-13 11:00:39 +0100670 intent.setSourceBounds(sourceBounds);
Bjorn Bringert3c50ef62009-12-09 12:23:12 +0000671 try {
672 if (DBG) Log.d(TAG, "Starting global search: " + intent.toUri(0));
673 mContext.startActivity(intent);
674 } catch (ActivityNotFoundException ex) {
675 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
676 }
677 }
678
679 /**
Narayan Kamathee69ff42011-06-28 12:07:18 +0100680 * Returns a list of installed apps that handle the global search
681 * intent.
682 *
683 * @hide
684 */
685 public List<ResolveInfo> getGlobalSearchActivities() {
686 try {
687 return mService.getGlobalSearchActivities();
688 } catch (RemoteException ex) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700689 throw ex.rethrowFromSystemServer();
Narayan Kamathee69ff42011-06-28 12:07:18 +0100690 }
691 }
692
693 /**
Bjorn Bringert3c50ef62009-12-09 12:23:12 +0000694 * Gets the name of the global search activity.
Bjorn Bringert3c50ef62009-12-09 12:23:12 +0000695 */
Bjorn Bringert38015f32010-01-14 14:56:18 +0000696 public ComponentName getGlobalSearchActivity() {
Bjorn Bringert6cf7a322010-02-23 13:17:06 +0000697 try {
698 return mService.getGlobalSearchActivity();
699 } catch (RemoteException ex) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700700 throw ex.rethrowFromSystemServer();
Bjorn Bringert3c50ef62009-12-09 12:23:12 +0000701 }
Bjorn Bringert3c50ef62009-12-09 12:23:12 +0000702 }
703
704 /**
Bjorn Bringertea125f42010-02-18 21:57:59 +0000705 * Gets the name of the web search activity.
706 *
707 * @return The name of the default activity for web searches. This activity
708 * can be used to get web search suggestions. Returns {@code null} if
709 * there is no default web search activity.
710 *
711 * @hide
712 */
713 public ComponentName getWebSearchActivity() {
Bjorn Bringert6cf7a322010-02-23 13:17:06 +0000714 try {
715 return mService.getWebSearchActivity();
716 } catch (RemoteException ex) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700717 throw ex.rethrowFromSystemServer();
Bjorn Bringertea125f42010-02-18 21:57:59 +0000718 }
Bjorn Bringertea125f42010-02-18 21:57:59 +0000719 }
720
721 /**
krosaend2d60142009-08-17 08:56:48 -0700722 * Similar to {@link #startSearch} but actually fires off the search query after invoking
723 * the search dialog. Made available for testing purposes.
724 *
725 * @param query The query to trigger. If empty, request will be ignored.
726 * @param launchActivity The ComponentName of the activity that has launched this search.
727 * @param appSearchData An application can insert application-specific
728 * context here, in order to improve quality or specificity of its own
729 * searches. This data will be returned with SEARCH intent(s). Null if
730 * no extra data is required.
krosaend2d60142009-08-17 08:56:48 -0700731 *
732 * @see #startSearch
733 */
734 public void triggerSearch(String query,
735 ComponentName launchActivity,
Bjorn Bringertb782a2f2009-10-01 09:57:33 +0100736 Bundle appSearchData) {
krosaend2d60142009-08-17 08:56:48 -0700737 if (query == null || TextUtils.getTrimmedLength(query) == 0) {
738 Log.w(TAG, "triggerSearch called with empty query, ignoring.");
739 return;
740 }
Amith Yamasanie9ce3f02010-01-25 09:15:50 -0800741 startSearch(query, false, launchActivity, appSearchData, false);
742 mSearchDialog.launchQuerySearch();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800743 }
744
745 /**
746 * Terminate search UI.
747 *
748 * <p>Typically the user will terminate the search UI by launching a
749 * search or by canceling. This function allows the underlying application
750 * or activity to cancel the search prematurely (for any reason).
Amith Yamasanie678f462010-09-15 16:13:43 -0700751 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800752 * <p>This function can be safely called at any time (even if no search is active.)
753 *
754 * @see #startSearch
755 */
Bjorn Bringert8d17f3f2009-06-05 13:22:28 +0100756 public void stopSearch() {
Amith Yamasanie9ce3f02010-01-25 09:15:50 -0800757 if (mSearchDialog != null) {
758 mSearchDialog.cancel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800759 }
760 }
761
762 /**
Amith Yamasanie678f462010-09-15 16:13:43 -0700763 * Determine if the Search UI is currently displayed.
764 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800765 * This is provided primarily for application test purposes.
766 *
767 * @return Returns true if the search UI is currently displayed.
Amith Yamasanie678f462010-09-15 16:13:43 -0700768 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800769 * @hide
770 */
Bjorn Bringert8d17f3f2009-06-05 13:22:28 +0100771 public boolean isVisible() {
Amith Yamasanie9ce3f02010-01-25 09:15:50 -0800772 return mSearchDialog == null? false : mSearchDialog.isShowing();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800773 }
Bjorn Bringert8d17f3f2009-06-05 13:22:28 +0100774
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800775 /**
Karl Rosaena058f022009-06-01 23:11:44 +0100776 * See {@link SearchManager#setOnDismissListener} for configuring your activity to monitor
777 * search UI state.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800778 */
779 public interface OnDismissListener {
780 /**
Karl Rosaena058f022009-06-01 23:11:44 +0100781 * This method will be called when the search UI is dismissed. To make use of it, you must
782 * implement this method in your activity, and call
783 * {@link SearchManager#setOnDismissListener} to register it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800784 */
785 public void onDismiss();
786 }
Amith Yamasanie678f462010-09-15 16:13:43 -0700787
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800788 /**
Karl Rosaena058f022009-06-01 23:11:44 +0100789 * See {@link SearchManager#setOnCancelListener} for configuring your activity to monitor
790 * search UI state.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800791 */
792 public interface OnCancelListener {
793 /**
794 * 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 +0100795 * implement this method in your activity, and call
796 * {@link SearchManager#setOnCancelListener} to register it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800797 */
798 public void onCancel();
799 }
800
801 /**
802 * Set or clear the callback that will be invoked whenever the search UI is dismissed.
Amith Yamasanie678f462010-09-15 16:13:43 -0700803 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800804 * @param listener The {@link OnDismissListener} to use, or null.
805 */
806 public void setOnDismissListener(final OnDismissListener listener) {
807 mDismissListener = listener;
808 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800809
810 /**
811 * Set or clear the callback that will be invoked whenever the search UI is canceled.
Amith Yamasanie678f462010-09-15 16:13:43 -0700812 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800813 * @param listener The {@link OnCancelListener} to use, or null.
814 */
Bjorn Bringert8d17f3f2009-06-05 13:22:28 +0100815 public void setOnCancelListener(OnCancelListener listener) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800816 mCancelListener = listener;
817 }
Bjorn Bringert8d17f3f2009-06-05 13:22:28 +0100818
Bjorn Bringert0e01ea42009-07-08 22:01:29 +0100819 /**
820 * @deprecated This method is an obsolete internal implementation detail. Do not use.
821 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -0700822 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800823 public void onCancel(DialogInterface dialog) {
Amith Yamasanie9ce3f02010-01-25 09:15:50 -0800824 if (mCancelListener != null) {
825 mCancelListener.onCancel();
826 }
Bjorn Bringert8d17f3f2009-06-05 13:22:28 +0100827 }
Bjorn Bringert0e01ea42009-07-08 22:01:29 +0100828
829 /**
830 * @deprecated This method is an obsolete internal implementation detail. Do not use.
831 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -0700832 @Deprecated
Bjorn Bringert8d17f3f2009-06-05 13:22:28 +0100833 public void onDismiss(DialogInterface dialog) {
Amith Yamasanie9ce3f02010-01-25 09:15:50 -0800834 if (mDismissListener != null) {
835 mDismissListener.onDismiss();
836 }
Bjorn Bringert8d17f3f2009-06-05 13:22:28 +0100837 }
838
839 /**
Bjorn Bringert04086752010-01-12 15:50:04 +0000840 * Gets information about a searchable activity.
841 *
842 * @param componentName The activity to get searchable information for.
843 * @return Searchable information, or <code>null</code> if the activity does not
844 * exist, or is not searchable.
845 */
846 public SearchableInfo getSearchableInfo(ComponentName componentName) {
847 try {
Bjorn Bringert6cf7a322010-02-23 13:17:06 +0000848 return mService.getSearchableInfo(componentName);
Bjorn Bringert8d17f3f2009-06-05 13:22:28 +0100849 } catch (RemoteException ex) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700850 throw ex.rethrowFromSystemServer();
Karl Rosaen875d50a2009-04-23 19:00:21 -0700851 }
852 }
Bjorn Bringert8d153822009-06-22 10:31:44 +0100853
Karl Rosaen875d50a2009-04-23 19:00:21 -0700854 /**
Bjorn Bringert97325db2009-06-22 11:37:03 +0100855 * Gets a cursor with search suggestions.
856 *
857 * @param searchable Information about how to get the suggestions.
858 * @param query The search text entered (so far).
859 * @return a cursor with suggestions, or <code>null</null> the suggestion query failed.
860 *
861 * @hide because SearchableInfo is not part of the API.
862 */
863 public Cursor getSuggestions(SearchableInfo searchable, String query) {
Bjorn Bringert3fc7c672009-09-28 20:11:52 +0100864 return getSuggestions(searchable, query, -1);
865 }
866
867 /**
868 * Gets a cursor with search suggestions.
869 *
870 * @param searchable Information about how to get the suggestions.
871 * @param query The search text entered (so far).
872 * @param limit The query limit to pass to the suggestion provider. This is advisory,
873 * the returned cursor may contain more rows. Pass {@code -1} for no limit.
874 * @return a cursor with suggestions, or <code>null</null> the suggestion query failed.
875 *
876 * @hide because SearchableInfo is not part of the API.
877 */
878 public Cursor getSuggestions(SearchableInfo searchable, String query, int limit) {
Karl Rosaen875d50a2009-04-23 19:00:21 -0700879 if (searchable == null) {
880 return null;
881 }
882
883 String authority = searchable.getSuggestAuthority();
884 if (authority == null) {
885 return null;
886 }
887
888 Uri.Builder uriBuilder = new Uri.Builder()
889 .scheme(ContentResolver.SCHEME_CONTENT)
Bjorn Bringert3fc7c672009-09-28 20:11:52 +0100890 .authority(authority)
891 .query("") // TODO: Remove, workaround for a bug in Uri.writeToParcel()
892 .fragment(""); // TODO: Remove, workaround for a bug in Uri.writeToParcel()
Karl Rosaen875d50a2009-04-23 19:00:21 -0700893
894 // if content path provided, insert it now
895 final String contentPath = searchable.getSuggestPath();
896 if (contentPath != null) {
897 uriBuilder.appendEncodedPath(contentPath);
898 }
899
Bjorn Bringert3fc7c672009-09-28 20:11:52 +0100900 // append standard suggestion query path
Karl Rosaen875d50a2009-04-23 19:00:21 -0700901 uriBuilder.appendPath(SearchManager.SUGGEST_URI_PATH_QUERY);
902
903 // get the query selection, may be null
904 String selection = searchable.getSuggestSelection();
905 // inject query, either as selection args or inline
906 String[] selArgs = null;
907 if (selection != null) { // use selection if provided
908 selArgs = new String[] { query };
909 } else { // no selection, use REST pattern
910 uriBuilder.appendPath(query);
911 }
912
Bjorn Bringert3fc7c672009-09-28 20:11:52 +0100913 if (limit > 0) {
914 uriBuilder.appendQueryParameter(SUGGEST_PARAMETER_LIMIT, String.valueOf(limit));
915 }
916
917 Uri uri = uriBuilder.build();
Karl Rosaen875d50a2009-04-23 19:00:21 -0700918
919 // finally, make the query
Bjorn Bringert8d153822009-06-22 10:31:44 +0100920 return mContext.getContentResolver().query(uri, null, selection, selArgs, null);
Karl Rosaen875d50a2009-04-23 19:00:21 -0700921 }
Amith Yamasanie678f462010-09-15 16:13:43 -0700922
Bjorn Bringert6d72e022009-04-29 14:56:12 +0100923 /**
924 * Returns a list of the searchable activities that can be included in global search.
Amith Yamasanie678f462010-09-15 16:13:43 -0700925 *
Bjorn Bringert6d72e022009-04-29 14:56:12 +0100926 * @return a list containing searchable information for all searchable activities
Bjorn Bringert13107bb2009-12-07 10:41:24 +0000927 * that have the <code>android:includeInGlobalSearch</code> attribute set
928 * in their searchable meta-data.
Bjorn Bringert6d72e022009-04-29 14:56:12 +0100929 */
Bjorn Bringert8d153822009-06-22 10:31:44 +0100930 public List<SearchableInfo> getSearchablesInGlobalSearch() {
Bjorn Bringert6d72e022009-04-29 14:56:12 +0100931 try {
Bjorn Bringert8d153822009-06-22 10:31:44 +0100932 return mService.getSearchablesInGlobalSearch();
Bjorn Bringert6d72e022009-04-29 14:56:12 +0100933 } catch (RemoteException e) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700934 throw e.rethrowFromSystemServer();
Bjorn Bringert6d72e022009-04-29 14:56:12 +0100935 }
936 }
Satish Sampathf9acde22009-06-04 11:51:17 +0100937
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700938 /**
Jim Miller45308b12012-06-18 19:23:39 -0700939 * Gets an intent for launching installed assistant activity, or null if not available.
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700940 * @return The assist intent.
941 *
942 * @hide
943 */
Jorim Jaggi165ce062015-07-06 16:18:11 -0700944 public Intent getAssistIntent(boolean inclContext) {
Amith Yamasanic1d07a42012-08-14 09:32:02 -0700945 try {
Amith Yamasanic1d07a42012-08-14 09:32:02 -0700946 Intent intent = new Intent(Intent.ACTION_ASSIST);
Dianne Hackbornf9c5e0f2013-01-23 14:39:13 -0800947 if (inclContext) {
948 IActivityManager am = ActivityManagerNative.getDefault();
Dianne Hackborna83ce1d2015-03-11 15:16:13 -0700949 Bundle extras = am.getAssistContextExtras(ActivityManager.ASSIST_CONTEXT_BASIC);
Dianne Hackbornf9c5e0f2013-01-23 14:39:13 -0800950 if (extras != null) {
951 intent.replaceExtras(extras);
952 }
953 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700954 return intent;
Amith Yamasanic1d07a42012-08-14 09:32:02 -0700955 } catch (RemoteException re) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700956 throw re.rethrowFromSystemServer();
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700957 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700958 }
Dianne Hackbornfdf5b352014-10-08 17:43:48 -0700959
960 /**
Jorim Jaggi165ce062015-07-06 16:18:11 -0700961 * Starts the assistant.
962 *
963 * @param args the args to pass to the assistant
964 *
Dianne Hackbornfdf5b352014-10-08 17:43:48 -0700965 * @hide
966 */
Jorim Jaggi165ce062015-07-06 16:18:11 -0700967 public void launchAssist(Bundle args) {
968 try {
969 if (mService == null) {
970 return;
971 }
972 mService.launchAssist(args);
973 } catch (RemoteException re) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700974 throw re.rethrowFromSystemServer();
Jorim Jaggi165ce062015-07-06 16:18:11 -0700975 }
976 }
977
978 /**
979 * Starts the legacy assistant (i.e. the {@link Intent#ACTION_ASSIST}).
980 *
981 * @param args the args to pass to the assistant
982 *
983 * @hide
984 */
985 public boolean launchLegacyAssist(String hint, int userHandle, Bundle args) {
Dianne Hackbornfdf5b352014-10-08 17:43:48 -0700986 try {
987 if (mService == null) {
988 return false;
989 }
Jorim Jaggi165ce062015-07-06 16:18:11 -0700990 return mService.launchLegacyAssist(hint, userHandle, args);
Dianne Hackbornfdf5b352014-10-08 17:43:48 -0700991 } catch (RemoteException re) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700992 throw re.rethrowFromSystemServer();
Dianne Hackbornfdf5b352014-10-08 17:43:48 -0700993 }
994 }
Amith Yamasanie9ce3f02010-01-25 09:15:50 -0800995}