blob: a01cec7aa944f115cbb3a8cf9297c192979fb798 [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;
Mathew Inwood61e8ae62018-08-14 14:17:44 +010023import android.annotation.UnsupportedAppUsage;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024import android.content.ComponentName;
25import android.content.Context;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026import android.content.pm.ActivityInfo;
27import android.content.pm.PackageManager;
28import android.content.pm.ProviderInfo;
Amith Yamasani64442c12012-10-07 08:17:46 -070029import android.content.pm.PackageManager.NameNotFoundException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030import android.content.res.TypedArray;
31import android.content.res.XmlResourceParser;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032import android.os.Parcel;
33import android.os.Parcelable;
Amith Yamasani64442c12012-10-07 08:17:46 -070034import android.os.UserHandle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035import android.text.InputType;
36import android.util.AttributeSet;
37import android.util.Log;
38import android.util.Xml;
39import android.view.inputmethod.EditorInfo;
40
41import java.io.IOException;
Bjorn Bringerta9204132009-05-05 14:06:35 +010042import java.util.HashMap;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043
Bjorn Bringert2126aac2009-12-03 15:48:19 +000044/**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +010045 * Searchability meta-data for an activity. Only applications that search other applications
46 * should need to use this class.
47 * See <a href="{@docRoot}guide/topics/search/searchable-config.html">Searchable Configuration</a>
48 * for more information about declaring searchability meta-data for your application.
49 *
50 * @see SearchManager#getSearchableInfo(ComponentName)
51 * @see SearchManager#getSearchablesInGlobalSearch()
Bjorn Bringert2126aac2009-12-03 15:48:19 +000052 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080053public final class SearchableInfo implements Parcelable {
54
55 // general debugging support
Mike LeBeau0f7e9142009-06-04 15:07:24 +010056 private static final boolean DBG = false;
Bjorn Bringerta9204132009-05-05 14:06:35 +010057 private static final String LOG_TAG = "SearchableInfo";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080058
Karl Rosaen875d50a2009-04-23 19:00:21 -070059 // static strings used for XML lookups.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060 // TODO how should these be documented for the developer, in a more structured way than
61 // the current long wordy javadoc in SearchManager.java ?
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080062 private static final String MD_LABEL_SEARCHABLE = "android.app.searchable";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063 private static final String MD_XML_ELEMENT_SEARCHABLE = "searchable";
64 private static final String MD_XML_ELEMENT_SEARCHABLE_ACTION_KEY = "actionkey";
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +010065
Bjorn Bringerta9204132009-05-05 14:06:35 +010066 // flags in the searchMode attribute
67 private static final int SEARCH_MODE_BADGE_LABEL = 0x04;
68 private static final int SEARCH_MODE_BADGE_ICON = 0x08;
69 private static final int SEARCH_MODE_QUERY_REWRITE_FROM_DATA = 0x10;
70 private static final int SEARCH_MODE_QUERY_REWRITE_FROM_TEXT = 0x20;
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +010071
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080072 // true member variables - what we know about the searchability
Bjorn Bringerta9204132009-05-05 14:06:35 +010073 private final int mLabelId;
74 private final ComponentName mSearchActivity;
75 private final int mHintId;
76 private final int mSearchMode;
77 private final int mIconId;
78 private final int mSearchButtonText;
79 private final int mSearchInputType;
80 private final int mSearchImeOptions;
81 private final boolean mIncludeInGlobalSearch;
Satish Sampath35379ab2009-06-11 14:05:51 +010082 private final boolean mQueryAfterZeroResults;
Satish Sampathd21572c2009-07-08 14:54:11 +010083 private final boolean mAutoUrlDetect;
Bjorn Bringert23897c12010-02-10 16:10:54 +000084 private final int mSettingsDescriptionId;
Bjorn Bringerta9204132009-05-05 14:06:35 +010085 private final String mSuggestAuthority;
86 private final String mSuggestPath;
87 private final String mSuggestSelection;
88 private final String mSuggestIntentAction;
89 private final String mSuggestIntentData;
90 private final int mSuggestThreshold;
91 // Maps key codes to action key information. auto-boxing is not so bad here,
92 // since keycodes for the hard keys are < 127. For such values, Integer.valueOf()
93 // uses shared Integer objects.
94 // This is not final, to allow lazy initialization.
95 private HashMap<Integer,ActionKeyInfo> mActionKeys = null;
96 private final String mSuggestProviderPackage;
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +010097
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098 // Flag values for Searchable_voiceSearchMode
Bjorn Bringert13107bb2009-12-07 10:41:24 +000099 private static final int VOICE_SEARCH_SHOW_BUTTON = 1;
100 private static final int VOICE_SEARCH_LAUNCH_WEB_SEARCH = 2;
101 private static final int VOICE_SEARCH_LAUNCH_RECOGNIZER = 4;
Bjorn Bringerta9204132009-05-05 14:06:35 +0100102 private final int mVoiceSearchMode;
103 private final int mVoiceLanguageModeId; // voiceLanguageModel
104 private final int mVoicePromptTextId; // voicePromptText
105 private final int mVoiceLanguageId; // voiceLanguage
106 private final int mVoiceMaxResults; // voiceMaxResults
Karl Rosaen875d50a2009-04-23 19:00:21 -0700107
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800108 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100109 * Gets the search suggestion content provider authority.
110 *
111 * @return The search suggestions authority, or {@code null} if not set.
112 * @see android.R.styleable#Searchable_searchSuggestAuthority
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800113 */
114 public String getSuggestAuthority() {
115 return mSuggestAuthority;
116 }
Bjorn Bringerta9204132009-05-05 14:06:35 +0100117
118 /**
Bjorn Bringert83dba192009-07-30 13:58:23 +0100119 * Gets the name of the package where the suggestion provider lives,
120 * or {@code null}.
121 */
122 public String getSuggestPackage() {
123 return mSuggestProviderPackage;
124 }
125
126 /**
Bjorn Bringerta9204132009-05-05 14:06:35 +0100127 * Gets the component name of the searchable activity.
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100128 *
129 * @return A component name, never {@code null}.
Bjorn Bringerta9204132009-05-05 14:06:35 +0100130 */
131 public ComponentName getSearchActivity() {
132 return mSearchActivity;
133 }
134
135 /**
136 * Checks whether the badge should be a text label.
Bjorn Bringert13107bb2009-12-07 10:41:24 +0000137 *
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100138 * @see android.R.styleable#Searchable_searchMode
139 *
Bjorn Bringert13107bb2009-12-07 10:41:24 +0000140 * @hide This feature is deprecated, no need to add it to the API.
Bjorn Bringerta9204132009-05-05 14:06:35 +0100141 */
142 public boolean useBadgeLabel() {
143 return 0 != (mSearchMode & SEARCH_MODE_BADGE_LABEL);
144 }
145
146 /**
147 * Checks whether the badge should be an icon.
Bjorn Bringert13107bb2009-12-07 10:41:24 +0000148 *
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100149 * @see android.R.styleable#Searchable_searchMode
150 *
Bjorn Bringert13107bb2009-12-07 10:41:24 +0000151 * @hide This feature is deprecated, no need to add it to the API.
Bjorn Bringerta9204132009-05-05 14:06:35 +0100152 */
153 public boolean useBadgeIcon() {
154 return (0 != (mSearchMode & SEARCH_MODE_BADGE_ICON)) && (mIconId != 0);
155 }
156
157 /**
158 * Checks whether the text in the query field should come from the suggestion intent data.
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100159 *
160 * @see android.R.styleable#Searchable_searchMode
Bjorn Bringerta9204132009-05-05 14:06:35 +0100161 */
162 public boolean shouldRewriteQueryFromData() {
163 return 0 != (mSearchMode & SEARCH_MODE_QUERY_REWRITE_FROM_DATA);
164 }
165
166 /**
167 * Checks whether the text in the query field should come from the suggestion title.
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100168 *
169 * @see android.R.styleable#Searchable_searchMode
Bjorn Bringerta9204132009-05-05 14:06:35 +0100170 */
171 public boolean shouldRewriteQueryFromText() {
172 return 0 != (mSearchMode & SEARCH_MODE_QUERY_REWRITE_FROM_TEXT);
173 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100174
Mike LeBeau735b3332009-06-30 18:27:40 -0700175 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100176 * Gets the resource id of the description string to use for this source in system search
Bjorn Bringert23897c12010-02-10 16:10:54 +0000177 * settings, or {@code 0} if none has been specified.
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100178 *
179 * @see android.R.styleable#Searchable_searchSettingsDescription
Mike LeBeau735b3332009-06-30 18:27:40 -0700180 */
Bjorn Bringert23897c12010-02-10 16:10:54 +0000181 public int getSettingsDescriptionId() {
182 return mSettingsDescriptionId;
Mike LeBeau735b3332009-06-30 18:27:40 -0700183 }
Bjorn Bringerta9204132009-05-05 14:06:35 +0100184
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800185 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100186 * Gets the content provider path for obtaining search suggestions.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800187 *
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100188 * @return The suggestion path, or {@code null} if not set.
189 * @see android.R.styleable#Searchable_searchSuggestPath
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800190 */
191 public String getSuggestPath() {
192 return mSuggestPath;
193 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100194
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800195 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100196 * Gets the selection for obtaining search suggestions.
197 *
198 * @see android.R.styleable#Searchable_searchSuggestSelection
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800199 */
200 public String getSuggestSelection() {
201 return mSuggestSelection;
202 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100203
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800204 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100205 * Gets the optional intent action for use with these suggestions. This is
206 * useful if all intents will have the same action
207 * (e.g. {@link android.content.Intent#ACTION_VIEW})
208 *
209 * This can be overriden in any given suggestion using the column
210 * {@link SearchManager#SUGGEST_COLUMN_INTENT_ACTION}.
211 *
212 * @return The default intent action, or {@code null} if not set.
213 * @see android.R.styleable#Searchable_searchSuggestIntentAction
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800214 */
215 public String getSuggestIntentAction() {
216 return mSuggestIntentAction;
217 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100218
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800219 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100220 * Gets the optional intent data for use with these suggestions. This is
221 * useful if all intents will have similar data URIs,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800222 * but you'll likely need to provide a specific ID as well via the column
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100223 * {@link SearchManager#SUGGEST_COLUMN_INTENT_DATA_ID}, which will be appended to the
224 * intent data URI.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800225 *
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100226 * This can be overriden in any given suggestion using the column
227 * {@link SearchManager#SUGGEST_COLUMN_INTENT_DATA}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800228 *
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100229 * @return The default intent data, or {@code null} if not set.
230 * @see android.R.styleable#Searchable_searchSuggestIntentData
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800231 */
232 public String getSuggestIntentData() {
233 return mSuggestIntentData;
234 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100235
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800236 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100237 * Gets the suggestion threshold.
Bjorn Bringert203464a2009-04-27 17:08:11 +0100238 *
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100239 * @return The suggestion threshold, or {@code 0} if not set.
240 * @see android.R.styleable#Searchable_searchSuggestThreshold
Bjorn Bringert203464a2009-04-27 17:08:11 +0100241 */
242 public int getSuggestThreshold() {
243 return mSuggestThreshold;
244 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100245
Bjorn Bringert203464a2009-04-27 17:08:11 +0100246 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100247 * Get the context for the searchable activity.
248 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800249 * @param context You need to supply a context to start with
250 * @return Returns a context related to the searchable activity
Bjorn Bringert13107bb2009-12-07 10:41:24 +0000251 * @hide
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800252 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100253 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800254 public Context getActivityContext(Context context) {
Karl Rosaen875d50a2009-04-23 19:00:21 -0700255 return createActivityContext(context, mSearchActivity);
256 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100257
Karl Rosaen875d50a2009-04-23 19:00:21 -0700258 /**
259 * Creates a context for another activity.
260 */
261 private static Context createActivityContext(Context context, ComponentName activity) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800262 Context theirContext = null;
263 try {
Karl Rosaen875d50a2009-04-23 19:00:21 -0700264 theirContext = context.createPackageContext(activity.getPackageName(), 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800265 } catch (PackageManager.NameNotFoundException e) {
Bjorn Bringert28fe2092010-04-06 14:48:41 +0100266 Log.e(LOG_TAG, "Package not found " + activity.getPackageName());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800267 } catch (java.lang.SecurityException e) {
Bjorn Bringert28fe2092010-04-06 14:48:41 +0100268 Log.e(LOG_TAG, "Can't make context for " + activity.getPackageName(), e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800269 }
270
271 return theirContext;
272 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100273
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800274 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100275 * Get the context for the suggestions provider.
276 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800277 * @param context You need to supply a context to start with
278 * @param activityContext If we can determine that the provider and the activity are the
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100279 * same, we'll just return this one.
280 * @return Returns a context related to the suggestion provider
Bjorn Bringert13107bb2009-12-07 10:41:24 +0000281 * @hide
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800282 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100283 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800284 public Context getProviderContext(Context context, Context activityContext) {
285 Context theirContext = null;
286 if (mSearchActivity.getPackageName().equals(mSuggestProviderPackage)) {
287 return activityContext;
288 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100289 if (mSuggestProviderPackage != null) {
290 try {
291 theirContext = context.createPackageContext(mSuggestProviderPackage, 0);
292 } catch (PackageManager.NameNotFoundException e) {
293 // unexpected, but we deal with this by null-checking theirContext
294 } catch (java.lang.SecurityException e) {
295 // unexpected, but we deal with this by null-checking theirContext
296 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800297 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800298 return theirContext;
299 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100300
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800301 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800302 * Constructor
303 *
304 * Given a ComponentName, get the searchability info
305 * and build a local copy of it. Use the factory, not this.
306 *
Karl Rosaen875d50a2009-04-23 19:00:21 -0700307 * @param activityContext runtime context for the activity that the searchable info is about.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800308 * @param attr The attribute set we found in the XML file, contains the values that are used to
309 * construct the object.
310 * @param cName The component name of the searchable activity
Bjorn Bringerta9204132009-05-05 14:06:35 +0100311 * @throws IllegalArgumentException if the searchability info is invalid or insufficient
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800312 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100313 @UnsupportedAppUsage
Karl Rosaen875d50a2009-04-23 19:00:21 -0700314 private SearchableInfo(Context activityContext, AttributeSet attr, final ComponentName cName) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800315 mSearchActivity = cName;
316
Karl Rosaen875d50a2009-04-23 19:00:21 -0700317 TypedArray a = activityContext.obtainStyledAttributes(attr,
318 com.android.internal.R.styleable.Searchable);
319 mSearchMode = a.getInt(com.android.internal.R.styleable.Searchable_searchMode, 0);
320 mLabelId = a.getResourceId(com.android.internal.R.styleable.Searchable_label, 0);
321 mHintId = a.getResourceId(com.android.internal.R.styleable.Searchable_hint, 0);
322 mIconId = a.getResourceId(com.android.internal.R.styleable.Searchable_icon, 0);
323 mSearchButtonText = a.getResourceId(
324 com.android.internal.R.styleable.Searchable_searchButtonText, 0);
325 mSearchInputType = a.getInt(com.android.internal.R.styleable.Searchable_inputType,
326 InputType.TYPE_CLASS_TEXT |
327 InputType.TYPE_TEXT_VARIATION_NORMAL);
328 mSearchImeOptions = a.getInt(com.android.internal.R.styleable.Searchable_imeOptions,
Amith Yamasani747d2d42010-03-12 15:42:45 -0800329 EditorInfo.IME_ACTION_GO);
Bjorn Bringert6d72e022009-04-29 14:56:12 +0100330 mIncludeInGlobalSearch = a.getBoolean(
331 com.android.internal.R.styleable.Searchable_includeInGlobalSearch, false);
Satish Sampath35379ab2009-06-11 14:05:51 +0100332 mQueryAfterZeroResults = a.getBoolean(
333 com.android.internal.R.styleable.Searchable_queryAfterZeroResults, false);
Satish Sampathd21572c2009-07-08 14:54:11 +0100334 mAutoUrlDetect = a.getBoolean(
335 com.android.internal.R.styleable.Searchable_autoUrlDetect, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800336
Bjorn Bringert23897c12010-02-10 16:10:54 +0000337 mSettingsDescriptionId = a.getResourceId(
338 com.android.internal.R.styleable.Searchable_searchSettingsDescription, 0);
Bjorn Bringerta9204132009-05-05 14:06:35 +0100339 mSuggestAuthority = a.getString(
340 com.android.internal.R.styleable.Searchable_searchSuggestAuthority);
341 mSuggestPath = a.getString(
342 com.android.internal.R.styleable.Searchable_searchSuggestPath);
343 mSuggestSelection = a.getString(
344 com.android.internal.R.styleable.Searchable_searchSuggestSelection);
345 mSuggestIntentAction = a.getString(
346 com.android.internal.R.styleable.Searchable_searchSuggestIntentAction);
347 mSuggestIntentData = a.getString(
348 com.android.internal.R.styleable.Searchable_searchSuggestIntentData);
349 mSuggestThreshold = a.getInt(
350 com.android.internal.R.styleable.Searchable_searchSuggestThreshold, 0);
351
Karl Rosaen875d50a2009-04-23 19:00:21 -0700352 mVoiceSearchMode =
353 a.getInt(com.android.internal.R.styleable.Searchable_voiceSearchMode, 0);
354 // TODO this didn't work - came back zero from YouTube
355 mVoiceLanguageModeId =
356 a.getResourceId(com.android.internal.R.styleable.Searchable_voiceLanguageModel, 0);
357 mVoicePromptTextId =
358 a.getResourceId(com.android.internal.R.styleable.Searchable_voicePromptText, 0);
359 mVoiceLanguageId =
360 a.getResourceId(com.android.internal.R.styleable.Searchable_voiceLanguage, 0);
361 mVoiceMaxResults =
362 a.getInt(com.android.internal.R.styleable.Searchable_voiceMaxResults, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800363
Karl Rosaen875d50a2009-04-23 19:00:21 -0700364 a.recycle();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800365
Karl Rosaen875d50a2009-04-23 19:00:21 -0700366 // get package info for suggestions provider (if any)
Bjorn Bringerta9204132009-05-05 14:06:35 +0100367 String suggestProviderPackage = null;
Karl Rosaen875d50a2009-04-23 19:00:21 -0700368 if (mSuggestAuthority != null) {
369 PackageManager pm = activityContext.getPackageManager();
Jeff Sharkeyc7bacab2016-02-09 15:56:11 -0700370 ProviderInfo pi = pm.resolveContentProvider(mSuggestAuthority,
371 PackageManager.MATCH_DEBUG_TRIAGED_MISSING);
Karl Rosaen875d50a2009-04-23 19:00:21 -0700372 if (pi != null) {
Bjorn Bringerta9204132009-05-05 14:06:35 +0100373 suggestProviderPackage = pi.packageName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800374 }
375 }
Bjorn Bringerta9204132009-05-05 14:06:35 +0100376 mSuggestProviderPackage = suggestProviderPackage;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800377
378 // for now, implement some form of rules - minimal data
Bjorn Bringerta9204132009-05-05 14:06:35 +0100379 if (mLabelId == 0) {
Bjorn Bringert8d17f3f2009-06-05 13:22:28 +0100380 throw new IllegalArgumentException("Search label must be a resource reference.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800381 }
382 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100383
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800384 /**
Bjorn Bringert13107bb2009-12-07 10:41:24 +0000385 * Information about an action key in searchability meta-data.
Bjorn Bringert13107bb2009-12-07 10:41:24 +0000386 *
387 * @see SearchableInfo#findActionKey(int)
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100388 *
389 * @hide This feature is used very little, and on many devices there are no reasonable
390 * keys to use for actions.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800391 */
Karl Rosaen875d50a2009-04-23 19:00:21 -0700392 public static class ActionKeyInfo implements Parcelable {
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100393
Bjorn Bringerta9204132009-05-05 14:06:35 +0100394 private final int mKeyCode;
395 private final String mQueryActionMsg;
396 private final String mSuggestActionMsg;
397 private final String mSuggestActionMsgColumn;
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100398
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800399 /**
400 * Create one object using attributeset as input data.
Karl Rosaen875d50a2009-04-23 19:00:21 -0700401 * @param activityContext runtime context of the activity that the action key information
402 * is about.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800403 * @param attr The attribute set we found in the XML file, contains the values that are used to
404 * construct the object.
Bjorn Bringerta9204132009-05-05 14:06:35 +0100405 * @throws IllegalArgumentException if the action key configuration is invalid
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800406 */
Bjorn Bringert13107bb2009-12-07 10:41:24 +0000407 ActionKeyInfo(Context activityContext, AttributeSet attr) {
Karl Rosaen875d50a2009-04-23 19:00:21 -0700408 TypedArray a = activityContext.obtainStyledAttributes(attr,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800409 com.android.internal.R.styleable.SearchableActionKey);
410
411 mKeyCode = a.getInt(
412 com.android.internal.R.styleable.SearchableActionKey_keycode, 0);
413 mQueryActionMsg = a.getString(
414 com.android.internal.R.styleable.SearchableActionKey_queryActionMsg);
Bjorn Bringerta9204132009-05-05 14:06:35 +0100415 mSuggestActionMsg = a.getString(
416 com.android.internal.R.styleable.SearchableActionKey_suggestActionMsg);
417 mSuggestActionMsgColumn = a.getString(
418 com.android.internal.R.styleable.SearchableActionKey_suggestActionMsgColumn);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800419 a.recycle();
420
Bjorn Bringerta9204132009-05-05 14:06:35 +0100421 // sanity check.
422 if (mKeyCode == 0) {
423 throw new IllegalArgumentException("No keycode.");
424 } else if ((mQueryActionMsg == null) &&
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800425 (mSuggestActionMsg == null) &&
426 (mSuggestActionMsgColumn == null)) {
Bjorn Bringerta9204132009-05-05 14:06:35 +0100427 throw new IllegalArgumentException("No message information.");
428 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800429 }
430
431 /**
432 * Instantiate a new ActionKeyInfo from the data in a Parcel that was
433 * previously written with {@link #writeToParcel(Parcel, int)}.
434 *
435 * @param in The Parcel containing the previously written ActionKeyInfo,
436 * positioned at the location in the buffer where it was written.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800437 */
Bjorn Bringert13107bb2009-12-07 10:41:24 +0000438 private ActionKeyInfo(Parcel in) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800439 mKeyCode = in.readInt();
440 mQueryActionMsg = in.readString();
441 mSuggestActionMsg = in.readString();
442 mSuggestActionMsgColumn = in.readString();
Bjorn Bringerta9204132009-05-05 14:06:35 +0100443 }
444
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100445 /**
446 * Gets the key code that this action key info is for.
447 * @see android.R.styleable#SearchableActionKey_keycode
448 */
Bjorn Bringerta9204132009-05-05 14:06:35 +0100449 public int getKeyCode() {
450 return mKeyCode;
451 }
452
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100453 /**
454 * Gets the action message to use for queries.
455 * @see android.R.styleable#SearchableActionKey_queryActionMsg
456 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100457 @UnsupportedAppUsage
Bjorn Bringerta9204132009-05-05 14:06:35 +0100458 public String getQueryActionMsg() {
459 return mQueryActionMsg;
460 }
461
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100462 /**
463 * Gets the action message to use for suggestions.
464 * @see android.R.styleable#SearchableActionKey_suggestActionMsg
465 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100466 @UnsupportedAppUsage
Bjorn Bringerta9204132009-05-05 14:06:35 +0100467 public String getSuggestActionMsg() {
468 return mSuggestActionMsg;
469 }
470
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100471 /**
472 * Gets the name of the column to get the suggestion action message from.
473 * @see android.R.styleable#SearchableActionKey_suggestActionMsgColumn
474 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100475 @UnsupportedAppUsage
Bjorn Bringerta9204132009-05-05 14:06:35 +0100476 public String getSuggestActionMsgColumn() {
477 return mSuggestActionMsgColumn;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800478 }
479
480 public int describeContents() {
481 return 0;
482 }
483
484 public void writeToParcel(Parcel dest, int flags) {
485 dest.writeInt(mKeyCode);
486 dest.writeString(mQueryActionMsg);
487 dest.writeString(mSuggestActionMsg);
488 dest.writeString(mSuggestActionMsgColumn);
489 }
490 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100491
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800492 /**
493 * If any action keys were defined for this searchable activity, look up and return.
494 *
495 * @param keyCode The key that was pressed
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100496 * @return Returns the action key info, or {@code null} if none defined.
497 *
498 * @hide ActionKeyInfo is hidden
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800499 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100500 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800501 public ActionKeyInfo findActionKey(int keyCode) {
Bjorn Bringerta9204132009-05-05 14:06:35 +0100502 if (mActionKeys == null) {
503 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800504 }
Bjorn Bringerta9204132009-05-05 14:06:35 +0100505 return mActionKeys.get(keyCode);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800506 }
Bjorn Bringerta9204132009-05-05 14:06:35 +0100507
508 private void addActionKey(ActionKeyInfo keyInfo) {
509 if (mActionKeys == null) {
510 mActionKeys = new HashMap<Integer,ActionKeyInfo>();
511 }
512 mActionKeys.put(keyInfo.getKeyCode(), keyInfo);
513 }
514
Bjorn Bringert13b24b72009-07-13 15:29:59 +0100515 /**
516 * Gets search information for the given activity.
517 *
518 * @param context Context to use for reading activity resources.
519 * @param activityInfo Activity to get search information from.
520 * @return Search information about the given activity, or {@code null} if
521 * the activity has no or invalid searchability meta-data.
Bjorn Bringert13107bb2009-12-07 10:41:24 +0000522 *
523 * @hide For use by SearchManagerService.
Bjorn Bringert13b24b72009-07-13 15:29:59 +0100524 */
Amith Yamasani64442c12012-10-07 08:17:46 -0700525 public static SearchableInfo getActivityMetaData(Context context, ActivityInfo activityInfo,
526 int userId) {
527 Context userContext = null;
528 try {
529 userContext = context.createPackageContextAsUser("system", 0,
530 new UserHandle(userId));
531 } catch (NameNotFoundException nnfe) {
532 Log.e(LOG_TAG, "Couldn't create package context for user " + userId);
533 return null;
534 }
Karl Rosaen875d50a2009-04-23 19:00:21 -0700535 // for each component, try to find metadata
536 XmlResourceParser xml =
Amith Yamasani64442c12012-10-07 08:17:46 -0700537 activityInfo.loadXmlMetaData(userContext.getPackageManager(), MD_LABEL_SEARCHABLE);
Karl Rosaen875d50a2009-04-23 19:00:21 -0700538 if (xml == null) {
539 return null;
540 }
541 ComponentName cName = new ComponentName(activityInfo.packageName, activityInfo.name);
542
Amith Yamasani64442c12012-10-07 08:17:46 -0700543 SearchableInfo searchable = getActivityMetaData(userContext, xml, cName);
Karl Rosaen875d50a2009-04-23 19:00:21 -0700544 xml.close();
Bjorn Bringerta9204132009-05-05 14:06:35 +0100545
546 if (DBG) {
Bjorn Bringert8d17f3f2009-06-05 13:22:28 +0100547 if (searchable != null) {
548 Log.d(LOG_TAG, "Checked " + activityInfo.name
549 + ",label=" + searchable.getLabelId()
550 + ",icon=" + searchable.getIconId()
551 + ",suggestAuthority=" + searchable.getSuggestAuthority()
552 + ",target=" + searchable.getSearchActivity().getClassName()
553 + ",global=" + searchable.shouldIncludeInGlobalSearch()
Bjorn Bringert23897c12010-02-10 16:10:54 +0000554 + ",settingsDescription=" + searchable.getSettingsDescriptionId()
Bjorn Bringert8d17f3f2009-06-05 13:22:28 +0100555 + ",threshold=" + searchable.getSuggestThreshold());
556 } else {
557 Log.d(LOG_TAG, "Checked " + activityInfo.name + ", no searchable meta-data");
558 }
Bjorn Bringerta9204132009-05-05 14:06:35 +0100559 }
Karl Rosaen875d50a2009-04-23 19:00:21 -0700560 return searchable;
561 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100562
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800563 /**
564 * Get the metadata for a given activity
565 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800566 * @param context runtime context
567 * @param xml XML parser for reading attributes
568 * @param cName The component name of the searchable activity
569 *
570 * @result A completely constructed SearchableInfo, or null if insufficient XML data for it
571 */
572 private static SearchableInfo getActivityMetaData(Context context, XmlPullParser xml,
573 final ComponentName cName) {
574 SearchableInfo result = null;
Karl Rosaen875d50a2009-04-23 19:00:21 -0700575 Context activityContext = createActivityContext(context, cName);
Bjorn Bringert28fe2092010-04-06 14:48:41 +0100576 if (activityContext == null) return null;
577
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800578 // in order to use the attributes mechanism, we have to walk the parser
579 // forward through the file until it's reading the tag of interest.
580 try {
581 int tagType = xml.next();
582 while (tagType != XmlPullParser.END_DOCUMENT) {
583 if (tagType == XmlPullParser.START_TAG) {
584 if (xml.getName().equals(MD_XML_ELEMENT_SEARCHABLE)) {
585 AttributeSet attr = Xml.asAttributeSet(xml);
586 if (attr != null) {
Bjorn Bringerta9204132009-05-05 14:06:35 +0100587 try {
588 result = new SearchableInfo(activityContext, attr, cName);
589 } catch (IllegalArgumentException ex) {
590 Log.w(LOG_TAG, "Invalid searchable metadata for " +
591 cName.flattenToShortString() + ": " + ex.getMessage());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800592 return null;
593 }
594 }
595 } else if (xml.getName().equals(MD_XML_ELEMENT_SEARCHABLE_ACTION_KEY)) {
596 if (result == null) {
597 // Can't process an embedded element if we haven't seen the enclosing
598 return null;
599 }
600 AttributeSet attr = Xml.asAttributeSet(xml);
601 if (attr != null) {
Bjorn Bringerta9204132009-05-05 14:06:35 +0100602 try {
603 result.addActionKey(new ActionKeyInfo(activityContext, attr));
604 } catch (IllegalArgumentException ex) {
605 Log.w(LOG_TAG, "Invalid action key for " +
606 cName.flattenToShortString() + ": " + ex.getMessage());
607 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800608 }
609 }
610 }
611 }
612 tagType = xml.next();
613 }
614 } catch (XmlPullParserException e) {
Bjorn Bringerta9204132009-05-05 14:06:35 +0100615 Log.w(LOG_TAG, "Reading searchable metadata for " + cName.flattenToShortString(), e);
616 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800617 } catch (IOException e) {
Bjorn Bringerta9204132009-05-05 14:06:35 +0100618 Log.w(LOG_TAG, "Reading searchable metadata for " + cName.flattenToShortString(), e);
619 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800620 }
Karl Rosaen875d50a2009-04-23 19:00:21 -0700621
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800622 return result;
623 }
Bjorn Bringerta9204132009-05-05 14:06:35 +0100624
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800625 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100626 * Gets the "label" (user-visible name) of this searchable context. This must be
627 * read using the searchable Activity's resources.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800628 *
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100629 * @return A resource id, or {@code 0} if no label was specified.
630 * @see android.R.styleable#Searchable_label
631 *
632 * @hide deprecated functionality
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800633 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100634 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800635 public int getLabelId() {
636 return mLabelId;
637 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100638
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800639 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100640 * Gets the resource id of the hint text. This must be
641 * read using the searchable Activity's resources.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800642 *
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100643 * @return A resource id, or {@code 0} if no hint was specified.
644 * @see android.R.styleable#Searchable_hint
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800645 */
646 public int getHintId() {
647 return mHintId;
648 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100649
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800650 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100651 * Gets the icon id specified by the Searchable_icon meta-data entry. This must be
652 * read using the searchable Activity's resources.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800653 *
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100654 * @return A resource id, or {@code 0} if no icon was specified.
655 * @see android.R.styleable#Searchable_icon
656 *
657 * @hide deprecated functionality
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800658 */
Mathew Inwood61e8ae62018-08-14 14:17:44 +0100659 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800660 public int getIconId() {
661 return mIconId;
662 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100663
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800664 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100665 * Checks if the searchable activity wants the voice search button to be shown.
666 *
667 * @see android.R.styleable#Searchable_voiceSearchMode
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800668 */
669 public boolean getVoiceSearchEnabled() {
670 return 0 != (mVoiceSearchMode & VOICE_SEARCH_SHOW_BUTTON);
671 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100672
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800673 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100674 * Checks if voice search should start web search.
675 *
676 * @see android.R.styleable#Searchable_voiceSearchMode
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800677 */
678 public boolean getVoiceSearchLaunchWebSearch() {
679 return 0 != (mVoiceSearchMode & VOICE_SEARCH_LAUNCH_WEB_SEARCH);
680 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100681
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800682 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100683 * Checks if voice search should start in-app search.
684 *
685 * @see android.R.styleable#Searchable_voiceSearchMode
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800686 */
687 public boolean getVoiceSearchLaunchRecognizer() {
688 return 0 != (mVoiceSearchMode & VOICE_SEARCH_LAUNCH_RECOGNIZER);
689 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100690
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800691 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100692 * Gets the resource id of the voice search language model string.
693 *
694 * @return A resource id, or {@code 0} if no language model was specified.
695 * @see android.R.styleable#Searchable_voiceLanguageModel
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800696 */
Tor Norbye7b9c9122013-05-30 16:48:33 -0700697 @StringRes
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800698 public int getVoiceLanguageModeId() {
699 return mVoiceLanguageModeId;
700 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100701
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800702 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100703 * Gets the resource id of the voice prompt text string.
704 *
705 * @return A resource id, or {@code 0} if no voice prompt text was specified.
706 * @see android.R.styleable#Searchable_voicePromptText
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800707 */
Tor Norbye7b9c9122013-05-30 16:48:33 -0700708 @StringRes
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800709 public int getVoicePromptTextId() {
710 return mVoicePromptTextId;
711 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100712
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800713 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100714 * Gets the resource id of the spoken language to recognize in voice search.
715 *
716 * @return A resource id, or {@code 0} if no language was specified.
717 * @see android.R.styleable#Searchable_voiceLanguage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800718 */
Tor Norbye7b9c9122013-05-30 16:48:33 -0700719 @StringRes
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800720 public int getVoiceLanguageId() {
721 return mVoiceLanguageId;
722 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100723
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800724 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100725 * The maximum number of voice recognition results to return.
726 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800727 * @return the max results count, if specified in the searchable
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100728 * activity's metadata, or {@code 0} if not specified.
729 * @see android.R.styleable#Searchable_voiceMaxResults
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800730 */
731 public int getVoiceMaxResults() {
732 return mVoiceMaxResults;
733 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100734
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800735 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100736 * Gets the resource id of replacement text for the "Search" button.
737 *
738 * @return A resource id, or {@code 0} if no replacement text was specified.
739 * @see android.R.styleable#Searchable_searchButtonText
740 * @hide This feature is deprecated, no need to add it to the API.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800741 */
742 public int getSearchButtonText() {
743 return mSearchButtonText;
744 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100745
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800746 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100747 * Gets the input type as specified in the searchable attributes. This will default to
748 * {@link InputType#TYPE_CLASS_TEXT} if not specified (which is appropriate
749 * for free text input).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800750 *
751 * @return the input type
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100752 * @see android.R.styleable#Searchable_inputType
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800753 */
754 public int getInputType() {
755 return mSearchInputType;
756 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100757
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800758 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100759 * Gets the input method options specified in the searchable attributes.
760 * This will default to {@link EditorInfo#IME_ACTION_GO} if not specified (which is
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800761 * appropriate for a search box).
762 *
763 * @return the input type
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100764 * @see android.R.styleable#Searchable_imeOptions
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800765 */
766 public int getImeOptions() {
767 return mSearchImeOptions;
768 }
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100769
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800770 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100771 * Checks whether the searchable should be included in global search.
Bjorn Bringert6d72e022009-04-29 14:56:12 +0100772 *
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100773 * @return The value of the {@link android.R.styleable#Searchable_includeInGlobalSearch}
774 * attribute, or {@code false} if the attribute is not set.
775 * @see android.R.styleable#Searchable_includeInGlobalSearch
Bjorn Bringert6d72e022009-04-29 14:56:12 +0100776 */
777 public boolean shouldIncludeInGlobalSearch() {
778 return mIncludeInGlobalSearch;
779 }
780
781 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100782 * Checks whether this searchable activity should be queried for suggestions if a prefix
783 * of the query has returned no results.
Satish Sampath35379ab2009-06-11 14:05:51 +0100784 *
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100785 * @see android.R.styleable#Searchable_queryAfterZeroResults
Satish Sampath35379ab2009-06-11 14:05:51 +0100786 */
787 public boolean queryAfterZeroResults() {
788 return mQueryAfterZeroResults;
789 }
790
791 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100792 * Checks whether this searchable activity has auto URL detection turned on.
Satish Sampathd21572c2009-07-08 14:54:11 +0100793 *
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100794 * @see android.R.styleable#Searchable_autoUrlDetect
Satish Sampathd21572c2009-07-08 14:54:11 +0100795 */
796 public boolean autoUrlDetect() {
797 return mAutoUrlDetect;
798 }
799
800 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800801 * Support for parcelable and aidl operations.
802 */
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -0700803 public static final @android.annotation.NonNull Parcelable.Creator<SearchableInfo> CREATOR
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800804 = new Parcelable.Creator<SearchableInfo>() {
805 public SearchableInfo createFromParcel(Parcel in) {
806 return new SearchableInfo(in);
807 }
808
809 public SearchableInfo[] newArray(int size) {
810 return new SearchableInfo[size];
811 }
812 };
813
814 /**
Bjorn Bringertfef8ceb2010-03-29 22:21:43 +0100815 * Instantiates a new SearchableInfo from the data in a Parcel that was
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800816 * previously written with {@link #writeToParcel(Parcel, int)}.
817 *
818 * @param in The Parcel containing the previously written SearchableInfo,
819 * positioned at the location in the buffer where it was written.
820 */
Bjorn Bringert13107bb2009-12-07 10:41:24 +0000821 SearchableInfo(Parcel in) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800822 mLabelId = in.readInt();
823 mSearchActivity = ComponentName.readFromParcel(in);
824 mHintId = in.readInt();
825 mSearchMode = in.readInt();
826 mIconId = in.readInt();
827 mSearchButtonText = in.readInt();
828 mSearchInputType = in.readInt();
829 mSearchImeOptions = in.readInt();
Bjorn Bringert6d72e022009-04-29 14:56:12 +0100830 mIncludeInGlobalSearch = in.readInt() != 0;
Satish Sampath35379ab2009-06-11 14:05:51 +0100831 mQueryAfterZeroResults = in.readInt() != 0;
Satish Sampathd21572c2009-07-08 14:54:11 +0100832 mAutoUrlDetect = in.readInt() != 0;
Mike LeBeau735b3332009-06-30 18:27:40 -0700833
Bjorn Bringert23897c12010-02-10 16:10:54 +0000834 mSettingsDescriptionId = in.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800835 mSuggestAuthority = in.readString();
836 mSuggestPath = in.readString();
837 mSuggestSelection = in.readString();
838 mSuggestIntentAction = in.readString();
839 mSuggestIntentData = in.readString();
Bjorn Bringert203464a2009-04-27 17:08:11 +0100840 mSuggestThreshold = in.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800841
Bjorn Bringerta9204132009-05-05 14:06:35 +0100842 for (int count = in.readInt(); count > 0; count--) {
843 addActionKey(new ActionKeyInfo(in));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800844 }
Bjorn Bringerta9204132009-05-05 14:06:35 +0100845
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800846 mSuggestProviderPackage = in.readString();
847
848 mVoiceSearchMode = in.readInt();
849 mVoiceLanguageModeId = in.readInt();
850 mVoicePromptTextId = in.readInt();
851 mVoiceLanguageId = in.readInt();
852 mVoiceMaxResults = in.readInt();
853 }
854
855 public int describeContents() {
856 return 0;
857 }
858
859 public void writeToParcel(Parcel dest, int flags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800860 dest.writeInt(mLabelId);
861 mSearchActivity.writeToParcel(dest, flags);
862 dest.writeInt(mHintId);
863 dest.writeInt(mSearchMode);
864 dest.writeInt(mIconId);
865 dest.writeInt(mSearchButtonText);
866 dest.writeInt(mSearchInputType);
867 dest.writeInt(mSearchImeOptions);
Bjorn Bringert6d72e022009-04-29 14:56:12 +0100868 dest.writeInt(mIncludeInGlobalSearch ? 1 : 0);
Satish Sampath35379ab2009-06-11 14:05:51 +0100869 dest.writeInt(mQueryAfterZeroResults ? 1 : 0);
Satish Sampathd21572c2009-07-08 14:54:11 +0100870 dest.writeInt(mAutoUrlDetect ? 1 : 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800871
Bjorn Bringert23897c12010-02-10 16:10:54 +0000872 dest.writeInt(mSettingsDescriptionId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800873 dest.writeString(mSuggestAuthority);
874 dest.writeString(mSuggestPath);
875 dest.writeString(mSuggestSelection);
876 dest.writeString(mSuggestIntentAction);
877 dest.writeString(mSuggestIntentData);
Bjorn Bringert203464a2009-04-27 17:08:11 +0100878 dest.writeInt(mSuggestThreshold);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800879
Bjorn Bringerta9204132009-05-05 14:06:35 +0100880 if (mActionKeys == null) {
881 dest.writeInt(0);
882 } else {
883 dest.writeInt(mActionKeys.size());
884 for (ActionKeyInfo actionKey : mActionKeys.values()) {
885 actionKey.writeToParcel(dest, flags);
886 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800887 }
Bjorn Bringerta9204132009-05-05 14:06:35 +0100888
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800889 dest.writeString(mSuggestProviderPackage);
890
891 dest.writeInt(mVoiceSearchMode);
892 dest.writeInt(mVoiceLanguageModeId);
893 dest.writeInt(mVoicePromptTextId);
894 dest.writeInt(mVoiceLanguageId);
895 dest.writeInt(mVoiceMaxResults);
896 }
897}