blob: a9529151493613d00afc717d1251c6353394276b [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
Bjorn Bringert2126aac2009-12-03 15:48:19 +000017package android.app;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080018
19import org.xmlpull.v1.XmlPullParser;
20import org.xmlpull.v1.XmlPullParserException;
21
Tor Norbye7b9c9122013-05-30 16:48:33 -070022import android.annotation.StringRes;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import android.content.ComponentName;
24import android.content.Context;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025import android.content.pm.ActivityInfo;
26import android.content.pm.PackageManager;
27import android.content.pm.ProviderInfo;
Amith Yamasani64442c12012-10-07 08:17:46 -070028import android.content.pm.PackageManager.NameNotFoundException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029import android.content.res.TypedArray;
30import android.content.res.XmlResourceParser;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import android.os.Parcel;
32import android.os.Parcelable;
Amith Yamasani64442c12012-10-07 08:17:46 -070033import android.os.UserHandle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034import android.text.InputType;
35import android.util.AttributeSet;
36import android.util.Log;
37import android.util.Xml;
38import android.view.inputmethod.EditorInfo;
39
40import java.io.IOException;
Bjorn Bringerta9204132009-05-05 14:06:35 +010041import java.util.HashMap;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042
Bjorn Bringert2126aac2009-12-03 15:48:19 +000043/**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +010044 * Searchability meta-data for an activity. Only applications that search other applications
45 * should need to use this class.
46 * See <a href="{@docRoot}guide/topics/search/searchable-config.html">Searchable Configuration</a>
47 * for more information about declaring searchability meta-data for your application.
48 *
49 * @see SearchManager#getSearchableInfo(ComponentName)
50 * @see SearchManager#getSearchablesInGlobalSearch()
Bjorn Bringert2126aac2009-12-03 15:48:19 +000051 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080052public final class SearchableInfo implements Parcelable {
53
54 // general debugging support
Mike LeBeau0f7e9142009-06-04 15:07:24 +010055 private static final boolean DBG = false;
Bjorn Bringerta9204132009-05-05 14:06:35 +010056 private static final String LOG_TAG = "SearchableInfo";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057
Karl Rosaen875d50a2009-04-23 19:00:21 -070058 // static strings used for XML lookups.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080059 // TODO how should these be documented for the developer, in a more structured way than
60 // the current long wordy javadoc in SearchManager.java ?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061 private static final String MD_LABEL_SEARCHABLE = "android.app.searchable";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080062 private static final String MD_XML_ELEMENT_SEARCHABLE = "searchable";
63 private static final String MD_XML_ELEMENT_SEARCHABLE_ACTION_KEY = "actionkey";
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +010064
Bjorn Bringerta9204132009-05-05 14:06:35 +010065 // flags in the searchMode attribute
66 private static final int SEARCH_MODE_BADGE_LABEL = 0x04;
67 private static final int SEARCH_MODE_BADGE_ICON = 0x08;
68 private static final int SEARCH_MODE_QUERY_REWRITE_FROM_DATA = 0x10;
69 private static final int SEARCH_MODE_QUERY_REWRITE_FROM_TEXT = 0x20;
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +010070
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080071 // true member variables - what we know about the searchability
Bjorn Bringerta9204132009-05-05 14:06:35 +010072 private final int mLabelId;
73 private final ComponentName mSearchActivity;
74 private final int mHintId;
75 private final int mSearchMode;
76 private final int mIconId;
77 private final int mSearchButtonText;
78 private final int mSearchInputType;
79 private final int mSearchImeOptions;
80 private final boolean mIncludeInGlobalSearch;
Satish Sampath35379ab2009-06-11 14:05:51 +010081 private final boolean mQueryAfterZeroResults;
Satish Sampathd21572c2009-07-08 14:54:11 +010082 private final boolean mAutoUrlDetect;
Bjorn Bringert23897c12010-02-10 16:10:54 +000083 private final int mSettingsDescriptionId;
Bjorn Bringerta9204132009-05-05 14:06:35 +010084 private final String mSuggestAuthority;
85 private final String mSuggestPath;
86 private final String mSuggestSelection;
87 private final String mSuggestIntentAction;
88 private final String mSuggestIntentData;
89 private final int mSuggestThreshold;
90 // Maps key codes to action key information. auto-boxing is not so bad here,
91 // since keycodes for the hard keys are < 127. For such values, Integer.valueOf()
92 // uses shared Integer objects.
93 // This is not final, to allow lazy initialization.
94 private HashMap<Integer,ActionKeyInfo> mActionKeys = null;
95 private final String mSuggestProviderPackage;
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +010096
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080097 // Flag values for Searchable_voiceSearchMode
Bjorn Bringert13107bb2009-12-07 10:41:24 +000098 private static final int VOICE_SEARCH_SHOW_BUTTON = 1;
99 private static final int VOICE_SEARCH_LAUNCH_WEB_SEARCH = 2;
100 private static final int VOICE_SEARCH_LAUNCH_RECOGNIZER = 4;
Bjorn Bringerta9204132009-05-05 14:06:35 +0100101 private final int mVoiceSearchMode;
102 private final int mVoiceLanguageModeId; // voiceLanguageModel
103 private final int mVoicePromptTextId; // voicePromptText
104 private final int mVoiceLanguageId; // voiceLanguage
105 private final int mVoiceMaxResults; // voiceMaxResults
Karl Rosaen875d50a2009-04-23 19:00:21 -0700106
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800107 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100108 * Gets the search suggestion content provider authority.
109 *
110 * @return The search suggestions authority, or {@code null} if not set.
111 * @see android.R.styleable#Searchable_searchSuggestAuthority
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800112 */
113 public String getSuggestAuthority() {
114 return mSuggestAuthority;
115 }
Bjorn Bringerta9204132009-05-05 14:06:35 +0100116
117 /**
Bjorn Bringert83dba192009-07-30 13:58:23 +0100118 * Gets the name of the package where the suggestion provider lives,
119 * or {@code null}.
120 */
121 public String getSuggestPackage() {
122 return mSuggestProviderPackage;
123 }
124
125 /**
Bjorn Bringerta9204132009-05-05 14:06:35 +0100126 * Gets the component name of the searchable activity.
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100127 *
128 * @return A component name, never {@code null}.
Bjorn Bringerta9204132009-05-05 14:06:35 +0100129 */
130 public ComponentName getSearchActivity() {
131 return mSearchActivity;
132 }
133
134 /**
135 * Checks whether the badge should be a text label.
Bjorn Bringert13107bb2009-12-07 10:41:24 +0000136 *
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100137 * @see android.R.styleable#Searchable_searchMode
138 *
Bjorn Bringert13107bb2009-12-07 10:41:24 +0000139 * @hide This feature is deprecated, no need to add it to the API.
Bjorn Bringerta9204132009-05-05 14:06:35 +0100140 */
141 public boolean useBadgeLabel() {
142 return 0 != (mSearchMode & SEARCH_MODE_BADGE_LABEL);
143 }
144
145 /**
146 * Checks whether the badge should be an icon.
Bjorn Bringert13107bb2009-12-07 10:41:24 +0000147 *
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100148 * @see android.R.styleable#Searchable_searchMode
149 *
Bjorn Bringert13107bb2009-12-07 10:41:24 +0000150 * @hide This feature is deprecated, no need to add it to the API.
Bjorn Bringerta9204132009-05-05 14:06:35 +0100151 */
152 public boolean useBadgeIcon() {
153 return (0 != (mSearchMode & SEARCH_MODE_BADGE_ICON)) && (mIconId != 0);
154 }
155
156 /**
157 * Checks whether the text in the query field should come from the suggestion intent data.
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100158 *
159 * @see android.R.styleable#Searchable_searchMode
Bjorn Bringerta9204132009-05-05 14:06:35 +0100160 */
161 public boolean shouldRewriteQueryFromData() {
162 return 0 != (mSearchMode & SEARCH_MODE_QUERY_REWRITE_FROM_DATA);
163 }
164
165 /**
166 * Checks whether the text in the query field should come from the suggestion title.
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100167 *
168 * @see android.R.styleable#Searchable_searchMode
Bjorn Bringerta9204132009-05-05 14:06:35 +0100169 */
170 public boolean shouldRewriteQueryFromText() {
171 return 0 != (mSearchMode & SEARCH_MODE_QUERY_REWRITE_FROM_TEXT);
172 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100173
Mike LeBeau735b3332009-06-30 18:27:40 -0700174 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100175 * Gets the resource id of the description string to use for this source in system search
Bjorn Bringert23897c12010-02-10 16:10:54 +0000176 * settings, or {@code 0} if none has been specified.
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100177 *
178 * @see android.R.styleable#Searchable_searchSettingsDescription
Mike LeBeau735b3332009-06-30 18:27:40 -0700179 */
Bjorn Bringert23897c12010-02-10 16:10:54 +0000180 public int getSettingsDescriptionId() {
181 return mSettingsDescriptionId;
Mike LeBeau735b3332009-06-30 18:27:40 -0700182 }
Bjorn Bringerta9204132009-05-05 14:06:35 +0100183
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800184 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100185 * Gets the content provider path for obtaining search suggestions.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800186 *
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100187 * @return The suggestion path, or {@code null} if not set.
188 * @see android.R.styleable#Searchable_searchSuggestPath
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800189 */
190 public String getSuggestPath() {
191 return mSuggestPath;
192 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100193
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800194 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100195 * Gets the selection for obtaining search suggestions.
196 *
197 * @see android.R.styleable#Searchable_searchSuggestSelection
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800198 */
199 public String getSuggestSelection() {
200 return mSuggestSelection;
201 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100202
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800203 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100204 * Gets the optional intent action for use with these suggestions. This is
205 * useful if all intents will have the same action
206 * (e.g. {@link android.content.Intent#ACTION_VIEW})
207 *
208 * This can be overriden in any given suggestion using the column
209 * {@link SearchManager#SUGGEST_COLUMN_INTENT_ACTION}.
210 *
211 * @return The default intent action, or {@code null} if not set.
212 * @see android.R.styleable#Searchable_searchSuggestIntentAction
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800213 */
214 public String getSuggestIntentAction() {
215 return mSuggestIntentAction;
216 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100217
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800218 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100219 * Gets the optional intent data for use with these suggestions. This is
220 * useful if all intents will have similar data URIs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800221 * but you'll likely need to provide a specific ID as well via the column
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100222 * {@link SearchManager#SUGGEST_COLUMN_INTENT_DATA_ID}, which will be appended to the
223 * intent data URI.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800224 *
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100225 * This can be overriden in any given suggestion using the column
226 * {@link SearchManager#SUGGEST_COLUMN_INTENT_DATA}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800227 *
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100228 * @return The default intent data, or {@code null} if not set.
229 * @see android.R.styleable#Searchable_searchSuggestIntentData
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800230 */
231 public String getSuggestIntentData() {
232 return mSuggestIntentData;
233 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100234
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800235 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100236 * Gets the suggestion threshold.
Bjorn Bringert203464a2009-04-27 17:08:11 +0100237 *
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100238 * @return The suggestion threshold, or {@code 0} if not set.
239 * @see android.R.styleable#Searchable_searchSuggestThreshold
Bjorn Bringert203464a2009-04-27 17:08:11 +0100240 */
241 public int getSuggestThreshold() {
242 return mSuggestThreshold;
243 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100244
Bjorn Bringert203464a2009-04-27 17:08:11 +0100245 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100246 * Get the context for the searchable activity.
247 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800248 * @param context You need to supply a context to start with
249 * @return Returns a context related to the searchable activity
Bjorn Bringert13107bb2009-12-07 10:41:24 +0000250 * @hide
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800251 */
252 public Context getActivityContext(Context context) {
Karl Rosaen875d50a2009-04-23 19:00:21 -0700253 return createActivityContext(context, mSearchActivity);
254 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100255
Karl Rosaen875d50a2009-04-23 19:00:21 -0700256 /**
257 * Creates a context for another activity.
258 */
259 private static Context createActivityContext(Context context, ComponentName activity) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800260 Context theirContext = null;
261 try {
Karl Rosaen875d50a2009-04-23 19:00:21 -0700262 theirContext = context.createPackageContext(activity.getPackageName(), 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800263 } catch (PackageManager.NameNotFoundException e) {
Bjorn Bringert28fe2092010-04-06 14:48:41 +0100264 Log.e(LOG_TAG, "Package not found " + activity.getPackageName());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800265 } catch (java.lang.SecurityException e) {
Bjorn Bringert28fe2092010-04-06 14:48:41 +0100266 Log.e(LOG_TAG, "Can't make context for " + activity.getPackageName(), e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800267 }
268
269 return theirContext;
270 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100271
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800272 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100273 * Get the context for the suggestions provider.
274 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800275 * @param context You need to supply a context to start with
276 * @param activityContext If we can determine that the provider and the activity are the
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100277 * same, we'll just return this one.
278 * @return Returns a context related to the suggestion provider
Bjorn Bringert13107bb2009-12-07 10:41:24 +0000279 * @hide
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800280 */
281 public Context getProviderContext(Context context, Context activityContext) {
282 Context theirContext = null;
283 if (mSearchActivity.getPackageName().equals(mSuggestProviderPackage)) {
284 return activityContext;
285 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100286 if (mSuggestProviderPackage != null) {
287 try {
288 theirContext = context.createPackageContext(mSuggestProviderPackage, 0);
289 } catch (PackageManager.NameNotFoundException e) {
290 // unexpected, but we deal with this by null-checking theirContext
291 } catch (java.lang.SecurityException e) {
292 // unexpected, but we deal with this by null-checking theirContext
293 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800294 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800295 return theirContext;
296 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100297
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800298 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800299 * Constructor
300 *
301 * Given a ComponentName, get the searchability info
302 * and build a local copy of it. Use the factory, not this.
303 *
Karl Rosaen875d50a2009-04-23 19:00:21 -0700304 * @param activityContext runtime context for the activity that the searchable info is about.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800305 * @param attr The attribute set we found in the XML file, contains the values that are used to
306 * construct the object.
307 * @param cName The component name of the searchable activity
Bjorn Bringerta9204132009-05-05 14:06:35 +0100308 * @throws IllegalArgumentException if the searchability info is invalid or insufficient
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800309 */
Karl Rosaen875d50a2009-04-23 19:00:21 -0700310 private SearchableInfo(Context activityContext, AttributeSet attr, final ComponentName cName) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800311 mSearchActivity = cName;
312
Karl Rosaen875d50a2009-04-23 19:00:21 -0700313 TypedArray a = activityContext.obtainStyledAttributes(attr,
314 com.android.internal.R.styleable.Searchable);
315 mSearchMode = a.getInt(com.android.internal.R.styleable.Searchable_searchMode, 0);
316 mLabelId = a.getResourceId(com.android.internal.R.styleable.Searchable_label, 0);
317 mHintId = a.getResourceId(com.android.internal.R.styleable.Searchable_hint, 0);
318 mIconId = a.getResourceId(com.android.internal.R.styleable.Searchable_icon, 0);
319 mSearchButtonText = a.getResourceId(
320 com.android.internal.R.styleable.Searchable_searchButtonText, 0);
321 mSearchInputType = a.getInt(com.android.internal.R.styleable.Searchable_inputType,
322 InputType.TYPE_CLASS_TEXT |
323 InputType.TYPE_TEXT_VARIATION_NORMAL);
324 mSearchImeOptions = a.getInt(com.android.internal.R.styleable.Searchable_imeOptions,
Amith Yamasani747d2d42010-03-12 15:42:45 -0800325 EditorInfo.IME_ACTION_GO);
Bjorn Bringert6d72e022009-04-29 14:56:12 +0100326 mIncludeInGlobalSearch = a.getBoolean(
327 com.android.internal.R.styleable.Searchable_includeInGlobalSearch, false);
Satish Sampath35379ab2009-06-11 14:05:51 +0100328 mQueryAfterZeroResults = a.getBoolean(
329 com.android.internal.R.styleable.Searchable_queryAfterZeroResults, false);
Satish Sampathd21572c2009-07-08 14:54:11 +0100330 mAutoUrlDetect = a.getBoolean(
331 com.android.internal.R.styleable.Searchable_autoUrlDetect, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800332
Bjorn Bringert23897c12010-02-10 16:10:54 +0000333 mSettingsDescriptionId = a.getResourceId(
334 com.android.internal.R.styleable.Searchable_searchSettingsDescription, 0);
Bjorn Bringerta9204132009-05-05 14:06:35 +0100335 mSuggestAuthority = a.getString(
336 com.android.internal.R.styleable.Searchable_searchSuggestAuthority);
337 mSuggestPath = a.getString(
338 com.android.internal.R.styleable.Searchable_searchSuggestPath);
339 mSuggestSelection = a.getString(
340 com.android.internal.R.styleable.Searchable_searchSuggestSelection);
341 mSuggestIntentAction = a.getString(
342 com.android.internal.R.styleable.Searchable_searchSuggestIntentAction);
343 mSuggestIntentData = a.getString(
344 com.android.internal.R.styleable.Searchable_searchSuggestIntentData);
345 mSuggestThreshold = a.getInt(
346 com.android.internal.R.styleable.Searchable_searchSuggestThreshold, 0);
347
Karl Rosaen875d50a2009-04-23 19:00:21 -0700348 mVoiceSearchMode =
349 a.getInt(com.android.internal.R.styleable.Searchable_voiceSearchMode, 0);
350 // TODO this didn't work - came back zero from YouTube
351 mVoiceLanguageModeId =
352 a.getResourceId(com.android.internal.R.styleable.Searchable_voiceLanguageModel, 0);
353 mVoicePromptTextId =
354 a.getResourceId(com.android.internal.R.styleable.Searchable_voicePromptText, 0);
355 mVoiceLanguageId =
356 a.getResourceId(com.android.internal.R.styleable.Searchable_voiceLanguage, 0);
357 mVoiceMaxResults =
358 a.getInt(com.android.internal.R.styleable.Searchable_voiceMaxResults, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800359
Karl Rosaen875d50a2009-04-23 19:00:21 -0700360 a.recycle();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800361
Karl Rosaen875d50a2009-04-23 19:00:21 -0700362 // get package info for suggestions provider (if any)
Bjorn Bringerta9204132009-05-05 14:06:35 +0100363 String suggestProviderPackage = null;
Karl Rosaen875d50a2009-04-23 19:00:21 -0700364 if (mSuggestAuthority != null) {
365 PackageManager pm = activityContext.getPackageManager();
Jeff Sharkeyc7bacab2016-02-09 15:56:11 -0700366 ProviderInfo pi = pm.resolveContentProvider(mSuggestAuthority,
367 PackageManager.MATCH_DEBUG_TRIAGED_MISSING);
Karl Rosaen875d50a2009-04-23 19:00:21 -0700368 if (pi != null) {
Bjorn Bringerta9204132009-05-05 14:06:35 +0100369 suggestProviderPackage = pi.packageName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800370 }
371 }
Bjorn Bringerta9204132009-05-05 14:06:35 +0100372 mSuggestProviderPackage = suggestProviderPackage;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800373
374 // for now, implement some form of rules - minimal data
Bjorn Bringerta9204132009-05-05 14:06:35 +0100375 if (mLabelId == 0) {
Bjorn Bringert8d17f3f2009-06-05 13:22:28 +0100376 throw new IllegalArgumentException("Search label must be a resource reference.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800377 }
378 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100379
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800380 /**
Bjorn Bringert13107bb2009-12-07 10:41:24 +0000381 * Information about an action key in searchability meta-data.
Bjorn Bringert13107bb2009-12-07 10:41:24 +0000382 *
383 * @see SearchableInfo#findActionKey(int)
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100384 *
385 * @hide This feature is used very little, and on many devices there are no reasonable
386 * keys to use for actions.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800387 */
Karl Rosaen875d50a2009-04-23 19:00:21 -0700388 public static class ActionKeyInfo implements Parcelable {
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100389
Bjorn Bringerta9204132009-05-05 14:06:35 +0100390 private final int mKeyCode;
391 private final String mQueryActionMsg;
392 private final String mSuggestActionMsg;
393 private final String mSuggestActionMsgColumn;
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100394
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800395 /**
396 * Create one object using attributeset as input data.
Karl Rosaen875d50a2009-04-23 19:00:21 -0700397 * @param activityContext runtime context of the activity that the action key information
398 * is about.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800399 * @param attr The attribute set we found in the XML file, contains the values that are used to
400 * construct the object.
Bjorn Bringerta9204132009-05-05 14:06:35 +0100401 * @throws IllegalArgumentException if the action key configuration is invalid
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800402 */
Bjorn Bringert13107bb2009-12-07 10:41:24 +0000403 ActionKeyInfo(Context activityContext, AttributeSet attr) {
Karl Rosaen875d50a2009-04-23 19:00:21 -0700404 TypedArray a = activityContext.obtainStyledAttributes(attr,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800405 com.android.internal.R.styleable.SearchableActionKey);
406
407 mKeyCode = a.getInt(
408 com.android.internal.R.styleable.SearchableActionKey_keycode, 0);
409 mQueryActionMsg = a.getString(
410 com.android.internal.R.styleable.SearchableActionKey_queryActionMsg);
Bjorn Bringerta9204132009-05-05 14:06:35 +0100411 mSuggestActionMsg = a.getString(
412 com.android.internal.R.styleable.SearchableActionKey_suggestActionMsg);
413 mSuggestActionMsgColumn = a.getString(
414 com.android.internal.R.styleable.SearchableActionKey_suggestActionMsgColumn);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800415 a.recycle();
416
Bjorn Bringerta9204132009-05-05 14:06:35 +0100417 // sanity check.
418 if (mKeyCode == 0) {
419 throw new IllegalArgumentException("No keycode.");
420 } else if ((mQueryActionMsg == null) &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800421 (mSuggestActionMsg == null) &&
422 (mSuggestActionMsgColumn == null)) {
Bjorn Bringerta9204132009-05-05 14:06:35 +0100423 throw new IllegalArgumentException("No message information.");
424 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800425 }
426
427 /**
428 * Instantiate a new ActionKeyInfo from the data in a Parcel that was
429 * previously written with {@link #writeToParcel(Parcel, int)}.
430 *
431 * @param in The Parcel containing the previously written ActionKeyInfo,
432 * positioned at the location in the buffer where it was written.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800433 */
Bjorn Bringert13107bb2009-12-07 10:41:24 +0000434 private ActionKeyInfo(Parcel in) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800435 mKeyCode = in.readInt();
436 mQueryActionMsg = in.readString();
437 mSuggestActionMsg = in.readString();
438 mSuggestActionMsgColumn = in.readString();
Bjorn Bringerta9204132009-05-05 14:06:35 +0100439 }
440
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100441 /**
442 * Gets the key code that this action key info is for.
443 * @see android.R.styleable#SearchableActionKey_keycode
444 */
Bjorn Bringerta9204132009-05-05 14:06:35 +0100445 public int getKeyCode() {
446 return mKeyCode;
447 }
448
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100449 /**
450 * Gets the action message to use for queries.
451 * @see android.R.styleable#SearchableActionKey_queryActionMsg
452 */
Bjorn Bringerta9204132009-05-05 14:06:35 +0100453 public String getQueryActionMsg() {
454 return mQueryActionMsg;
455 }
456
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100457 /**
458 * Gets the action message to use for suggestions.
459 * @see android.R.styleable#SearchableActionKey_suggestActionMsg
460 */
Bjorn Bringerta9204132009-05-05 14:06:35 +0100461 public String getSuggestActionMsg() {
462 return mSuggestActionMsg;
463 }
464
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100465 /**
466 * Gets the name of the column to get the suggestion action message from.
467 * @see android.R.styleable#SearchableActionKey_suggestActionMsgColumn
468 */
Bjorn Bringerta9204132009-05-05 14:06:35 +0100469 public String getSuggestActionMsgColumn() {
470 return mSuggestActionMsgColumn;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800471 }
472
473 public int describeContents() {
474 return 0;
475 }
476
477 public void writeToParcel(Parcel dest, int flags) {
478 dest.writeInt(mKeyCode);
479 dest.writeString(mQueryActionMsg);
480 dest.writeString(mSuggestActionMsg);
481 dest.writeString(mSuggestActionMsgColumn);
482 }
483 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100484
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800485 /**
486 * If any action keys were defined for this searchable activity, look up and return.
487 *
488 * @param keyCode The key that was pressed
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100489 * @return Returns the action key info, or {@code null} if none defined.
490 *
491 * @hide ActionKeyInfo is hidden
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800492 */
493 public ActionKeyInfo findActionKey(int keyCode) {
Bjorn Bringerta9204132009-05-05 14:06:35 +0100494 if (mActionKeys == null) {
495 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800496 }
Bjorn Bringerta9204132009-05-05 14:06:35 +0100497 return mActionKeys.get(keyCode);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800498 }
Bjorn Bringerta9204132009-05-05 14:06:35 +0100499
500 private void addActionKey(ActionKeyInfo keyInfo) {
501 if (mActionKeys == null) {
502 mActionKeys = new HashMap<Integer,ActionKeyInfo>();
503 }
504 mActionKeys.put(keyInfo.getKeyCode(), keyInfo);
505 }
506
Bjorn Bringert13b24b72009-07-13 15:29:59 +0100507 /**
508 * Gets search information for the given activity.
509 *
510 * @param context Context to use for reading activity resources.
511 * @param activityInfo Activity to get search information from.
512 * @return Search information about the given activity, or {@code null} if
513 * the activity has no or invalid searchability meta-data.
Bjorn Bringert13107bb2009-12-07 10:41:24 +0000514 *
515 * @hide For use by SearchManagerService.
Bjorn Bringert13b24b72009-07-13 15:29:59 +0100516 */
Amith Yamasani64442c12012-10-07 08:17:46 -0700517 public static SearchableInfo getActivityMetaData(Context context, ActivityInfo activityInfo,
518 int userId) {
519 Context userContext = null;
520 try {
521 userContext = context.createPackageContextAsUser("system", 0,
522 new UserHandle(userId));
523 } catch (NameNotFoundException nnfe) {
524 Log.e(LOG_TAG, "Couldn't create package context for user " + userId);
525 return null;
526 }
Karl Rosaen875d50a2009-04-23 19:00:21 -0700527 // for each component, try to find metadata
528 XmlResourceParser xml =
Amith Yamasani64442c12012-10-07 08:17:46 -0700529 activityInfo.loadXmlMetaData(userContext.getPackageManager(), MD_LABEL_SEARCHABLE);
Karl Rosaen875d50a2009-04-23 19:00:21 -0700530 if (xml == null) {
531 return null;
532 }
533 ComponentName cName = new ComponentName(activityInfo.packageName, activityInfo.name);
534
Amith Yamasani64442c12012-10-07 08:17:46 -0700535 SearchableInfo searchable = getActivityMetaData(userContext, xml, cName);
Karl Rosaen875d50a2009-04-23 19:00:21 -0700536 xml.close();
Bjorn Bringerta9204132009-05-05 14:06:35 +0100537
538 if (DBG) {
Bjorn Bringert8d17f3f2009-06-05 13:22:28 +0100539 if (searchable != null) {
540 Log.d(LOG_TAG, "Checked " + activityInfo.name
541 + ",label=" + searchable.getLabelId()
542 + ",icon=" + searchable.getIconId()
543 + ",suggestAuthority=" + searchable.getSuggestAuthority()
544 + ",target=" + searchable.getSearchActivity().getClassName()
545 + ",global=" + searchable.shouldIncludeInGlobalSearch()
Bjorn Bringert23897c12010-02-10 16:10:54 +0000546 + ",settingsDescription=" + searchable.getSettingsDescriptionId()
Bjorn Bringert8d17f3f2009-06-05 13:22:28 +0100547 + ",threshold=" + searchable.getSuggestThreshold());
548 } else {
549 Log.d(LOG_TAG, "Checked " + activityInfo.name + ", no searchable meta-data");
550 }
Bjorn Bringerta9204132009-05-05 14:06:35 +0100551 }
Karl Rosaen875d50a2009-04-23 19:00:21 -0700552 return searchable;
553 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100554
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800555 /**
556 * Get the metadata for a given activity
557 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800558 * @param context runtime context
559 * @param xml XML parser for reading attributes
560 * @param cName The component name of the searchable activity
561 *
562 * @result A completely constructed SearchableInfo, or null if insufficient XML data for it
563 */
564 private static SearchableInfo getActivityMetaData(Context context, XmlPullParser xml,
565 final ComponentName cName) {
566 SearchableInfo result = null;
Karl Rosaen875d50a2009-04-23 19:00:21 -0700567 Context activityContext = createActivityContext(context, cName);
Bjorn Bringert28fe2092010-04-06 14:48:41 +0100568 if (activityContext == null) return null;
569
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800570 // in order to use the attributes mechanism, we have to walk the parser
571 // forward through the file until it's reading the tag of interest.
572 try {
573 int tagType = xml.next();
574 while (tagType != XmlPullParser.END_DOCUMENT) {
575 if (tagType == XmlPullParser.START_TAG) {
576 if (xml.getName().equals(MD_XML_ELEMENT_SEARCHABLE)) {
577 AttributeSet attr = Xml.asAttributeSet(xml);
578 if (attr != null) {
Bjorn Bringerta9204132009-05-05 14:06:35 +0100579 try {
580 result = new SearchableInfo(activityContext, attr, cName);
581 } catch (IllegalArgumentException ex) {
582 Log.w(LOG_TAG, "Invalid searchable metadata for " +
583 cName.flattenToShortString() + ": " + ex.getMessage());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800584 return null;
585 }
586 }
587 } else if (xml.getName().equals(MD_XML_ELEMENT_SEARCHABLE_ACTION_KEY)) {
588 if (result == null) {
589 // Can't process an embedded element if we haven't seen the enclosing
590 return null;
591 }
592 AttributeSet attr = Xml.asAttributeSet(xml);
593 if (attr != null) {
Bjorn Bringerta9204132009-05-05 14:06:35 +0100594 try {
595 result.addActionKey(new ActionKeyInfo(activityContext, attr));
596 } catch (IllegalArgumentException ex) {
597 Log.w(LOG_TAG, "Invalid action key for " +
598 cName.flattenToShortString() + ": " + ex.getMessage());
599 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800600 }
601 }
602 }
603 }
604 tagType = xml.next();
605 }
606 } catch (XmlPullParserException e) {
Bjorn Bringerta9204132009-05-05 14:06:35 +0100607 Log.w(LOG_TAG, "Reading searchable metadata for " + cName.flattenToShortString(), e);
608 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800609 } catch (IOException e) {
Bjorn Bringerta9204132009-05-05 14:06:35 +0100610 Log.w(LOG_TAG, "Reading searchable metadata for " + cName.flattenToShortString(), e);
611 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800612 }
Karl Rosaen875d50a2009-04-23 19:00:21 -0700613
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800614 return result;
615 }
Bjorn Bringerta9204132009-05-05 14:06:35 +0100616
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800617 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100618 * Gets the "label" (user-visible name) of this searchable context. This must be
619 * read using the searchable Activity's resources.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800620 *
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100621 * @return A resource id, or {@code 0} if no label was specified.
622 * @see android.R.styleable#Searchable_label
623 *
624 * @hide deprecated functionality
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800625 */
626 public int getLabelId() {
627 return mLabelId;
628 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100629
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800630 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100631 * Gets the resource id of the hint text. This must be
632 * read using the searchable Activity's resources.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800633 *
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100634 * @return A resource id, or {@code 0} if no hint was specified.
635 * @see android.R.styleable#Searchable_hint
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800636 */
637 public int getHintId() {
638 return mHintId;
639 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100640
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800641 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100642 * Gets the icon id specified by the Searchable_icon meta-data entry. This must be
643 * read using the searchable Activity's resources.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800644 *
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100645 * @return A resource id, or {@code 0} if no icon was specified.
646 * @see android.R.styleable#Searchable_icon
647 *
648 * @hide deprecated functionality
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800649 */
650 public int getIconId() {
651 return mIconId;
652 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100653
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800654 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100655 * Checks if the searchable activity wants the voice search button to be shown.
656 *
657 * @see android.R.styleable#Searchable_voiceSearchMode
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800658 */
659 public boolean getVoiceSearchEnabled() {
660 return 0 != (mVoiceSearchMode & VOICE_SEARCH_SHOW_BUTTON);
661 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100662
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800663 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100664 * Checks if voice search should start web search.
665 *
666 * @see android.R.styleable#Searchable_voiceSearchMode
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800667 */
668 public boolean getVoiceSearchLaunchWebSearch() {
669 return 0 != (mVoiceSearchMode & VOICE_SEARCH_LAUNCH_WEB_SEARCH);
670 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100671
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800672 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100673 * Checks if voice search should start in-app search.
674 *
675 * @see android.R.styleable#Searchable_voiceSearchMode
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800676 */
677 public boolean getVoiceSearchLaunchRecognizer() {
678 return 0 != (mVoiceSearchMode & VOICE_SEARCH_LAUNCH_RECOGNIZER);
679 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100680
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800681 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100682 * Gets the resource id of the voice search language model string.
683 *
684 * @return A resource id, or {@code 0} if no language model was specified.
685 * @see android.R.styleable#Searchable_voiceLanguageModel
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800686 */
Tor Norbye7b9c9122013-05-30 16:48:33 -0700687 @StringRes
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800688 public int getVoiceLanguageModeId() {
689 return mVoiceLanguageModeId;
690 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100691
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800692 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100693 * Gets the resource id of the voice prompt text string.
694 *
695 * @return A resource id, or {@code 0} if no voice prompt text was specified.
696 * @see android.R.styleable#Searchable_voicePromptText
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800697 */
Tor Norbye7b9c9122013-05-30 16:48:33 -0700698 @StringRes
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800699 public int getVoicePromptTextId() {
700 return mVoicePromptTextId;
701 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100702
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800703 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100704 * Gets the resource id of the spoken language to recognize in voice search.
705 *
706 * @return A resource id, or {@code 0} if no language was specified.
707 * @see android.R.styleable#Searchable_voiceLanguage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800708 */
Tor Norbye7b9c9122013-05-30 16:48:33 -0700709 @StringRes
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800710 public int getVoiceLanguageId() {
711 return mVoiceLanguageId;
712 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100713
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800714 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100715 * The maximum number of voice recognition results to return.
716 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800717 * @return the max results count, if specified in the searchable
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100718 * activity's metadata, or {@code 0} if not specified.
719 * @see android.R.styleable#Searchable_voiceMaxResults
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800720 */
721 public int getVoiceMaxResults() {
722 return mVoiceMaxResults;
723 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100724
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800725 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100726 * Gets the resource id of replacement text for the "Search" button.
727 *
728 * @return A resource id, or {@code 0} if no replacement text was specified.
729 * @see android.R.styleable#Searchable_searchButtonText
730 * @hide This feature is deprecated, no need to add it to the API.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800731 */
732 public int getSearchButtonText() {
733 return mSearchButtonText;
734 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100735
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800736 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100737 * Gets the input type as specified in the searchable attributes. This will default to
738 * {@link InputType#TYPE_CLASS_TEXT} if not specified (which is appropriate
739 * for free text input).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800740 *
741 * @return the input type
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100742 * @see android.R.styleable#Searchable_inputType
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800743 */
744 public int getInputType() {
745 return mSearchInputType;
746 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100747
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800748 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100749 * Gets the input method options specified in the searchable attributes.
750 * This will default to {@link EditorInfo#IME_ACTION_GO} if not specified (which is
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800751 * appropriate for a search box).
752 *
753 * @return the input type
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100754 * @see android.R.styleable#Searchable_imeOptions
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800755 */
756 public int getImeOptions() {
757 return mSearchImeOptions;
758 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100759
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800760 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100761 * Checks whether the searchable should be included in global search.
Bjorn Bringert6d72e022009-04-29 14:56:12 +0100762 *
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100763 * @return The value of the {@link android.R.styleable#Searchable_includeInGlobalSearch}
764 * attribute, or {@code false} if the attribute is not set.
765 * @see android.R.styleable#Searchable_includeInGlobalSearch
Bjorn Bringert6d72e022009-04-29 14:56:12 +0100766 */
767 public boolean shouldIncludeInGlobalSearch() {
768 return mIncludeInGlobalSearch;
769 }
770
771 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100772 * Checks whether this searchable activity should be queried for suggestions if a prefix
773 * of the query has returned no results.
Satish Sampath35379ab2009-06-11 14:05:51 +0100774 *
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100775 * @see android.R.styleable#Searchable_queryAfterZeroResults
Satish Sampath35379ab2009-06-11 14:05:51 +0100776 */
777 public boolean queryAfterZeroResults() {
778 return mQueryAfterZeroResults;
779 }
780
781 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100782 * Checks whether this searchable activity has auto URL detection turned on.
Satish Sampathd21572c2009-07-08 14:54:11 +0100783 *
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100784 * @see android.R.styleable#Searchable_autoUrlDetect
Satish Sampathd21572c2009-07-08 14:54:11 +0100785 */
786 public boolean autoUrlDetect() {
787 return mAutoUrlDetect;
788 }
789
790 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800791 * Support for parcelable and aidl operations.
792 */
793 public static final Parcelable.Creator<SearchableInfo> CREATOR
794 = new Parcelable.Creator<SearchableInfo>() {
795 public SearchableInfo createFromParcel(Parcel in) {
796 return new SearchableInfo(in);
797 }
798
799 public SearchableInfo[] newArray(int size) {
800 return new SearchableInfo[size];
801 }
802 };
803
804 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100805 * Instantiates a new SearchableInfo from the data in a Parcel that was
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800806 * previously written with {@link #writeToParcel(Parcel, int)}.
807 *
808 * @param in The Parcel containing the previously written SearchableInfo,
809 * positioned at the location in the buffer where it was written.
810 */
Bjorn Bringert13107bb2009-12-07 10:41:24 +0000811 SearchableInfo(Parcel in) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800812 mLabelId = in.readInt();
813 mSearchActivity = ComponentName.readFromParcel(in);
814 mHintId = in.readInt();
815 mSearchMode = in.readInt();
816 mIconId = in.readInt();
817 mSearchButtonText = in.readInt();
818 mSearchInputType = in.readInt();
819 mSearchImeOptions = in.readInt();
Bjorn Bringert6d72e022009-04-29 14:56:12 +0100820 mIncludeInGlobalSearch = in.readInt() != 0;
Satish Sampath35379ab2009-06-11 14:05:51 +0100821 mQueryAfterZeroResults = in.readInt() != 0;
Satish Sampathd21572c2009-07-08 14:54:11 +0100822 mAutoUrlDetect = in.readInt() != 0;
Mike LeBeau735b3332009-06-30 18:27:40 -0700823
Bjorn Bringert23897c12010-02-10 16:10:54 +0000824 mSettingsDescriptionId = in.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800825 mSuggestAuthority = in.readString();
826 mSuggestPath = in.readString();
827 mSuggestSelection = in.readString();
828 mSuggestIntentAction = in.readString();
829 mSuggestIntentData = in.readString();
Bjorn Bringert203464a2009-04-27 17:08:11 +0100830 mSuggestThreshold = in.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800831
Bjorn Bringerta9204132009-05-05 14:06:35 +0100832 for (int count = in.readInt(); count > 0; count--) {
833 addActionKey(new ActionKeyInfo(in));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800834 }
Bjorn Bringerta9204132009-05-05 14:06:35 +0100835
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800836 mSuggestProviderPackage = in.readString();
837
838 mVoiceSearchMode = in.readInt();
839 mVoiceLanguageModeId = in.readInt();
840 mVoicePromptTextId = in.readInt();
841 mVoiceLanguageId = in.readInt();
842 mVoiceMaxResults = in.readInt();
843 }
844
845 public int describeContents() {
846 return 0;
847 }
848
849 public void writeToParcel(Parcel dest, int flags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800850 dest.writeInt(mLabelId);
851 mSearchActivity.writeToParcel(dest, flags);
852 dest.writeInt(mHintId);
853 dest.writeInt(mSearchMode);
854 dest.writeInt(mIconId);
855 dest.writeInt(mSearchButtonText);
856 dest.writeInt(mSearchInputType);
857 dest.writeInt(mSearchImeOptions);
Bjorn Bringert6d72e022009-04-29 14:56:12 +0100858 dest.writeInt(mIncludeInGlobalSearch ? 1 : 0);
Satish Sampath35379ab2009-06-11 14:05:51 +0100859 dest.writeInt(mQueryAfterZeroResults ? 1 : 0);
Satish Sampathd21572c2009-07-08 14:54:11 +0100860 dest.writeInt(mAutoUrlDetect ? 1 : 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800861
Bjorn Bringert23897c12010-02-10 16:10:54 +0000862 dest.writeInt(mSettingsDescriptionId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800863 dest.writeString(mSuggestAuthority);
864 dest.writeString(mSuggestPath);
865 dest.writeString(mSuggestSelection);
866 dest.writeString(mSuggestIntentAction);
867 dest.writeString(mSuggestIntentData);
Bjorn Bringert203464a2009-04-27 17:08:11 +0100868 dest.writeInt(mSuggestThreshold);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800869
Bjorn Bringerta9204132009-05-05 14:06:35 +0100870 if (mActionKeys == null) {
871 dest.writeInt(0);
872 } else {
873 dest.writeInt(mActionKeys.size());
874 for (ActionKeyInfo actionKey : mActionKeys.values()) {
875 actionKey.writeToParcel(dest, flags);
876 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800877 }
Bjorn Bringerta9204132009-05-05 14:06:35 +0100878
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800879 dest.writeString(mSuggestProviderPackage);
880
881 dest.writeInt(mVoiceSearchMode);
882 dest.writeInt(mVoiceLanguageModeId);
883 dest.writeInt(mVoicePromptTextId);
884 dest.writeInt(mVoiceLanguageId);
885 dest.writeInt(mVoiceMaxResults);
886 }
887}