| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.app; |
| 18 |
|
| 19 |
import android.annotation.StringRes; |
| 20 |
import android.compat.annotation.UnsupportedAppUsage; |
| 21 |
import android.content.ComponentName; |
| 22 |
import android.content.Context; |
| 23 |
import android.content.pm.ActivityInfo; |
| 24 |
import android.content.pm.PackageManager; |
| 25 |
import android.content.pm.PackageManager.NameNotFoundException; |
| 26 |
import android.content.pm.ProviderInfo; |
| 27 |
import android.content.res.TypedArray; |
| 28 |
import android.content.res.XmlResourceParser; |
| 29 |
import android.os.Parcel; |
| 30 |
import android.os.Parcelable; |
| 31 |
import android.os.UserHandle; |
| 32 |
import android.text.InputType; |
| 33 |
import android.util.AttributeSet; |
| 34 |
import android.util.Log; |
| 35 |
import android.util.Xml; |
| 36 |
import android.view.inputmethod.EditorInfo; |
| 37 |
|
| 38 |
import org.xmlpull.v1.XmlPullParser; |
| 39 |
import org.xmlpull.v1.XmlPullParserException; |
| 40 |
|
| 41 |
import java.io.IOException; |
| 42 |
import java.util.HashMap; |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
public final class SearchableInfo implements Parcelable { |
| 54 |
|
| 55 |
|
| 56 |
private static final boolean DBG = false; |
| 57 |
private static final String LOG_TAG = "SearchableInfo"; |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
private static final String MD_LABEL_SEARCHABLE = "android.app.searchable"; |
| 63 |
private static final String MD_XML_ELEMENT_SEARCHABLE = "searchable"; |
| 64 |
private static final String MD_XML_ELEMENT_SEARCHABLE_ACTION_KEY = "actionkey"; |
| 65 |
|
| 66 |
|
| 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; |
| 71 |
|
| 72 |
|
| 73 |
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; |
| 82 |
private final boolean mQueryAfterZeroResults; |
| 83 |
private final boolean mAutoUrlDetect; |
| 84 |
private final int mSettingsDescriptionId; |
| 85 |
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 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
private HashMap<Integer,ActionKeyInfo> mActionKeys = null; |
| 96 |
private final String mSuggestProviderPackage; |
| 97 |
|
| 98 |
|
| 99 |
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; |
| 102 |
private final int mVoiceSearchMode; |
| 103 |
private final int mVoiceLanguageModeId; |
| 104 |
private final int mVoicePromptTextId; |
| 105 |
private final int mVoiceLanguageId; |
| 106 |
private final int mVoiceMaxResults; |
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
public String getSuggestAuthority() { |
| 115 |
return mSuggestAuthority; |
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
public String getSuggestPackage() { |
| 123 |
return mSuggestProviderPackage; |
| 124 |
} |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
public ComponentName getSearchActivity() { |
| 132 |
return mSearchActivity; |
| 133 |
} |
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
public boolean useBadgeLabel() { |
| 143 |
return 0 != (mSearchMode & SEARCH_MODE_BADGE_LABEL); |
| 144 |
} |
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
public boolean useBadgeIcon() { |
| 154 |
return (0 != (mSearchMode & SEARCH_MODE_BADGE_ICON)) && (mIconId != 0); |
| 155 |
} |
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
public boolean shouldRewriteQueryFromData() { |
| 163 |
return 0 != (mSearchMode & SEARCH_MODE_QUERY_REWRITE_FROM_DATA); |
| 164 |
} |
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
public boolean shouldRewriteQueryFromText() { |
| 172 |
return 0 != (mSearchMode & SEARCH_MODE_QUERY_REWRITE_FROM_TEXT); |
| 173 |
} |
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
public int getSettingsDescriptionId() { |
| 182 |
return mSettingsDescriptionId; |
| 183 |
} |
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
public String getSuggestPath() { |
| 192 |
return mSuggestPath; |
| 193 |
} |
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
public String getSuggestSelection() { |
| 201 |
return mSuggestSelection; |
| 202 |
} |
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
public String getSuggestIntentAction() { |
| 216 |
return mSuggestIntentAction; |
| 217 |
} |
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
public String getSuggestIntentData() { |
| 233 |
return mSuggestIntentData; |
| 234 |
} |
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
public int getSuggestThreshold() { |
| 243 |
return mSuggestThreshold; |
| 244 |
} |
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
@UnsupportedAppUsage |
| 254 |
public Context getActivityContext(Context context) { |
| 255 |
return createActivityContext(context, mSearchActivity); |
| 256 |
} |
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
private static Context createActivityContext(Context context, ComponentName activity) { |
| 262 |
Context theirContext = null; |
| 263 |
try { |
| 264 |
theirContext = context.createPackageContext(activity.getPackageName(), 0); |
| 265 |
} catch (PackageManager.NameNotFoundException e) { |
| 266 |
Log.e(LOG_TAG, "Package not found " + activity.getPackageName()); |
| 267 |
} catch (java.lang.SecurityException e) { |
| 268 |
Log.e(LOG_TAG, "Can't make context for " + activity.getPackageName(), e); |
| 269 |
} |
| 270 |
|
| 271 |
return theirContext; |
| 272 |
} |
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
@UnsupportedAppUsage |
| 284 |
public Context getProviderContext(Context context, Context activityContext) { |
| 285 |
Context theirContext = null; |
| 286 |
if (mSearchActivity.getPackageName().equals(mSuggestProviderPackage)) { |
| 287 |
return activityContext; |
| 288 |
} |
| 289 |
if (mSuggestProviderPackage != null) { |
| 290 |
try { |
| 291 |
theirContext = context.createPackageContext(mSuggestProviderPackage, 0); |
| 292 |
} catch (PackageManager.NameNotFoundException e) { |
| 293 |
|
| 294 |
} catch (java.lang.SecurityException e) { |
| 295 |
|
| 296 |
} |
| 297 |
} |
| 298 |
return theirContext; |
| 299 |
} |
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
@UnsupportedAppUsage |
| 314 |
private SearchableInfo(Context activityContext, AttributeSet attr, final ComponentName cName) { |
| 315 |
mSearchActivity = cName; |
| 316 |
|
| 317 |
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, |
| 329 |
EditorInfo.IME_ACTION_GO); |
| 330 |
mIncludeInGlobalSearch = a.getBoolean( |
| 331 |
com.android.internal.R.styleable.Searchable_includeInGlobalSearch, false); |
| 332 |
mQueryAfterZeroResults = a.getBoolean( |
| 333 |
com.android.internal.R.styleable.Searchable_queryAfterZeroResults, false); |
| 334 |
mAutoUrlDetect = a.getBoolean( |
| 335 |
com.android.internal.R.styleable.Searchable_autoUrlDetect, false); |
| 336 |
|
| 337 |
mSettingsDescriptionId = a.getResourceId( |
| 338 |
com.android.internal.R.styleable.Searchable_searchSettingsDescription, 0); |
| 339 |
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 |
|
| 352 |
mVoiceSearchMode = |
| 353 |
a.getInt(com.android.internal.R.styleable.Searchable_voiceSearchMode, 0); |
| 354 |
|
| 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); |
| 363 |
|
| 364 |
a.recycle(); |
| 365 |
|
| 366 |
|
| 367 |
String suggestProviderPackage = null; |
| 368 |
if (mSuggestAuthority != null) { |
| 369 |
PackageManager pm = activityContext.getPackageManager(); |
| 370 |
ProviderInfo pi = pm.resolveContentProvider(mSuggestAuthority, |
| 371 |
PackageManager.MATCH_DEBUG_TRIAGED_MISSING); |
| 372 |
if (pi != null) { |
| 373 |
suggestProviderPackage = pi.packageName; |
| 374 |
} |
| 375 |
} |
| 376 |
mSuggestProviderPackage = suggestProviderPackage; |
| 377 |
|
| 378 |
|
| 379 |
if (mLabelId == 0) { |
| 380 |
throw new IllegalArgumentException("Search label must be a resource reference."); |
| 381 |
} |
| 382 |
} |
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
public static class ActionKeyInfo implements Parcelable { |
| 393 |
|
| 394 |
private final int mKeyCode; |
| 395 |
private final String mQueryActionMsg; |
| 396 |
private final String mSuggestActionMsg; |
| 397 |
private final String mSuggestActionMsgColumn; |
| 398 |
|
| 399 |
public static final Parcelable.Creator<ActionKeyInfo> CREATOR = |
| 400 |
new Parcelable.Creator<ActionKeyInfo>() { |
| 401 |
public ActionKeyInfo createFromParcel(Parcel in) { |
| 402 |
return new ActionKeyInfo(in); |
| 403 |
} |
| 404 |
|
| 405 |
public ActionKeyInfo[] newArray(int size) { |
| 406 |
return new ActionKeyInfo[size]; |
| 407 |
} |
| 408 |
}; |
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
ActionKeyInfo(Context activityContext, AttributeSet attr) { |
| 419 |
TypedArray a = activityContext.obtainStyledAttributes(attr, |
| 420 |
com.android.internal.R.styleable.SearchableActionKey); |
| 421 |
|
| 422 |
mKeyCode = a.getInt( |
| 423 |
com.android.internal.R.styleable.SearchableActionKey_keycode, 0); |
| 424 |
mQueryActionMsg = a.getString( |
| 425 |
com.android.internal.R.styleable.SearchableActionKey_queryActionMsg); |
| 426 |
mSuggestActionMsg = a.getString( |
| 427 |
com.android.internal.R.styleable.SearchableActionKey_suggestActionMsg); |
| 428 |
mSuggestActionMsgColumn = a.getString( |
| 429 |
com.android.internal.R.styleable.SearchableActionKey_suggestActionMsgColumn); |
| 430 |
a.recycle(); |
| 431 |
|
| 432 |
|
| 433 |
if (mKeyCode == 0) { |
| 434 |
throw new IllegalArgumentException("No keycode."); |
| 435 |
} else if ((mQueryActionMsg == null) && |
| 436 |
(mSuggestActionMsg == null) && |
| 437 |
(mSuggestActionMsgColumn == null)) { |
| 438 |
throw new IllegalArgumentException("No message information."); |
| 439 |
} |
| 440 |
} |
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
private ActionKeyInfo(Parcel in) { |
| 450 |
mKeyCode = in.readInt(); |
| 451 |
mQueryActionMsg = in.readString(); |
| 452 |
mSuggestActionMsg = in.readString(); |
| 453 |
mSuggestActionMsgColumn = in.readString(); |
| 454 |
} |
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
public int getKeyCode() { |
| 461 |
return mKeyCode; |
| 462 |
} |
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
@UnsupportedAppUsage |
| 469 |
public String getQueryActionMsg() { |
| 470 |
return mQueryActionMsg; |
| 471 |
} |
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
@UnsupportedAppUsage |
| 478 |
public String getSuggestActionMsg() { |
| 479 |
return mSuggestActionMsg; |
| 480 |
} |
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
@UnsupportedAppUsage |
| 487 |
public String getSuggestActionMsgColumn() { |
| 488 |
return mSuggestActionMsgColumn; |
| 489 |
} |
| 490 |
|
| 491 |
public int describeContents() { |
| 492 |
return 0; |
| 493 |
} |
| 494 |
|
| 495 |
public void writeToParcel(Parcel dest, int flags) { |
| 496 |
dest.writeInt(mKeyCode); |
| 497 |
dest.writeString(mQueryActionMsg); |
| 498 |
dest.writeString(mSuggestActionMsg); |
| 499 |
dest.writeString(mSuggestActionMsgColumn); |
| 500 |
} |
| 501 |
} |
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
@UnsupportedAppUsage |
| 512 |
public ActionKeyInfo findActionKey(int keyCode) { |
| 513 |
if (mActionKeys == null) { |
| 514 |
return null; |
| 515 |
} |
| 516 |
return mActionKeys.get(keyCode); |
| 517 |
} |
| 518 |
|
| 519 |
private void addActionKey(ActionKeyInfo keyInfo) { |
| 520 |
if (mActionKeys == null) { |
| 521 |
mActionKeys = new HashMap<Integer,ActionKeyInfo>(); |
| 522 |
} |
| 523 |
mActionKeys.put(keyInfo.getKeyCode(), keyInfo); |
| 524 |
} |
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
public static SearchableInfo getActivityMetaData(Context context, ActivityInfo activityInfo, |
| 537 |
int userId) { |
| 538 |
Context userContext = null; |
| 539 |
try { |
| 540 |
userContext = context.createPackageContextAsUser("system", 0, |
| 541 |
new UserHandle(userId)); |
| 542 |
} catch (NameNotFoundException nnfe) { |
| 543 |
Log.e(LOG_TAG, "Couldn't create package context for user " + userId); |
| 544 |
return null; |
| 545 |
} |
| 546 |
|
| 547 |
XmlResourceParser xml = |
| 548 |
activityInfo.loadXmlMetaData(userContext.getPackageManager(), MD_LABEL_SEARCHABLE); |
| 549 |
if (xml == null) { |
| 550 |
return null; |
| 551 |
} |
| 552 |
ComponentName cName = new ComponentName(activityInfo.packageName, activityInfo.name); |
| 553 |
|
| 554 |
SearchableInfo searchable = getActivityMetaData(userContext, xml, cName); |
| 555 |
xml.close(); |
| 556 |
|
| 557 |
if (DBG) { |
| 558 |
if (searchable != null) { |
| 559 |
Log.d(LOG_TAG, "Checked " + activityInfo.name |
| 560 |
+ ",label=" + searchable.getLabelId() |
| 561 |
+ ",icon=" + searchable.getIconId() |
| 562 |
+ ",suggestAuthority=" + searchable.getSuggestAuthority() |
| 563 |
+ ",target=" + searchable.getSearchActivity().getClassName() |
| 564 |
+ ",global=" + searchable.shouldIncludeInGlobalSearch() |
| 565 |
+ ",settingsDescription=" + searchable.getSettingsDescriptionId() |
| 566 |
+ ",threshold=" + searchable.getSuggestThreshold()); |
| 567 |
} else { |
| 568 |
Log.d(LOG_TAG, "Checked " + activityInfo.name + ", no searchable meta-data"); |
| 569 |
} |
| 570 |
} |
| 571 |
return searchable; |
| 572 |
} |
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
private static SearchableInfo getActivityMetaData(Context context, XmlPullParser xml, |
| 584 |
final ComponentName cName) { |
| 585 |
SearchableInfo result = null; |
| 586 |
Context activityContext = createActivityContext(context, cName); |
| 587 |
if (activityContext == null) return null; |
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
try { |
| 592 |
int tagType = xml.next(); |
| 593 |
while (tagType != XmlPullParser.END_DOCUMENT) { |
| 594 |
if (tagType == XmlPullParser.START_TAG) { |
| 595 |
if (xml.getName().equals(MD_XML_ELEMENT_SEARCHABLE)) { |
| 596 |
AttributeSet attr = Xml.asAttributeSet(xml); |
| 597 |
if (attr != null) { |
| 598 |
try { |
| 599 |
result = new SearchableInfo(activityContext, attr, cName); |
| 600 |
} catch (IllegalArgumentException ex) { |
| 601 |
Log.w(LOG_TAG, "Invalid searchable metadata for " + |
| 602 |
cName.flattenToShortString() + ": " + ex.getMessage()); |
| 603 |
return null; |
| 604 |
} |
| 605 |
} |
| 606 |
} else if (xml.getName().equals(MD_XML_ELEMENT_SEARCHABLE_ACTION_KEY)) { |
| 607 |
if (result == null) { |
| 608 |
|
| 609 |
return null; |
| 610 |
} |
| 611 |
AttributeSet attr = Xml.asAttributeSet(xml); |
| 612 |
if (attr != null) { |
| 613 |
try { |
| 614 |
result.addActionKey(new ActionKeyInfo(activityContext, attr)); |
| 615 |
} catch (IllegalArgumentException ex) { |
| 616 |
Log.w(LOG_TAG, "Invalid action key for " + |
| 617 |
cName.flattenToShortString() + ": " + ex.getMessage()); |
| 618 |
return null; |
| 619 |
} |
| 620 |
} |
| 621 |
} |
| 622 |
} |
| 623 |
tagType = xml.next(); |
| 624 |
} |
| 625 |
} catch (XmlPullParserException e) { |
| 626 |
Log.w(LOG_TAG, "Reading searchable metadata for " + cName.flattenToShortString(), e); |
| 627 |
return null; |
| 628 |
} catch (IOException e) { |
| 629 |
Log.w(LOG_TAG, "Reading searchable metadata for " + cName.flattenToShortString(), e); |
| 630 |
return null; |
| 631 |
} |
| 632 |
|
| 633 |
return result; |
| 634 |
} |
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
@UnsupportedAppUsage |
| 646 |
public int getLabelId() { |
| 647 |
return mLabelId; |
| 648 |
} |
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
public int getHintId() { |
| 658 |
return mHintId; |
| 659 |
} |
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
@UnsupportedAppUsage |
| 671 |
public int getIconId() { |
| 672 |
return mIconId; |
| 673 |
} |
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
public boolean getVoiceSearchEnabled() { |
| 681 |
return 0 != (mVoiceSearchMode & VOICE_SEARCH_SHOW_BUTTON); |
| 682 |
} |
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
public boolean getVoiceSearchLaunchWebSearch() { |
| 690 |
return 0 != (mVoiceSearchMode & VOICE_SEARCH_LAUNCH_WEB_SEARCH); |
| 691 |
} |
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
public boolean getVoiceSearchLaunchRecognizer() { |
| 699 |
return 0 != (mVoiceSearchMode & VOICE_SEARCH_LAUNCH_RECOGNIZER); |
| 700 |
} |
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
@StringRes |
| 709 |
public int getVoiceLanguageModeId() { |
| 710 |
return mVoiceLanguageModeId; |
| 711 |
} |
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
@StringRes |
| 720 |
public int getVoicePromptTextId() { |
| 721 |
return mVoicePromptTextId; |
| 722 |
} |
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
@StringRes |
| 731 |
public int getVoiceLanguageId() { |
| 732 |
return mVoiceLanguageId; |
| 733 |
} |
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
public int getVoiceMaxResults() { |
| 743 |
return mVoiceMaxResults; |
| 744 |
} |
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
public int getSearchButtonText() { |
| 754 |
return mSearchButtonText; |
| 755 |
} |
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
|
| 763 |
|
| 764 |
|
| 765 |
public int getInputType() { |
| 766 |
return mSearchInputType; |
| 767 |
} |
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
public int getImeOptions() { |
| 778 |
return mSearchImeOptions; |
| 779 |
} |
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
public boolean shouldIncludeInGlobalSearch() { |
| 789 |
return mIncludeInGlobalSearch; |
| 790 |
} |
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
public boolean queryAfterZeroResults() { |
| 799 |
return mQueryAfterZeroResults; |
| 800 |
} |
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
|
| 805 |
|
| 806 |
|
| 807 |
public boolean autoUrlDetect() { |
| 808 |
return mAutoUrlDetect; |
| 809 |
} |
| 810 |
|
| 811 |
|
| 812 |
|
| 813 |
|
| 814 |
public static final @android.annotation.NonNull Parcelable.Creator<SearchableInfo> CREATOR |
| 815 |
= new Parcelable.Creator<SearchableInfo>() { |
| 816 |
public SearchableInfo createFromParcel(Parcel in) { |
| 817 |
return new SearchableInfo(in); |
| 818 |
} |
| 819 |
|
| 820 |
public SearchableInfo[] newArray(int size) { |
| 821 |
return new SearchableInfo[size]; |
| 822 |
} |
| 823 |
}; |
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
SearchableInfo(Parcel in) { |
| 833 |
mLabelId = in.readInt(); |
| 834 |
mSearchActivity = ComponentName.readFromParcel(in); |
| 835 |
mHintId = in.readInt(); |
| 836 |
mSearchMode = in.readInt(); |
| 837 |
mIconId = in.readInt(); |
| 838 |
mSearchButtonText = in.readInt(); |
| 839 |
mSearchInputType = in.readInt(); |
| 840 |
mSearchImeOptions = in.readInt(); |
| 841 |
mIncludeInGlobalSearch = in.readInt() != 0; |
| 842 |
mQueryAfterZeroResults = in.readInt() != 0; |
| 843 |
mAutoUrlDetect = in.readInt() != 0; |
| 844 |
|
| 845 |
mSettingsDescriptionId = in.readInt(); |
| 846 |
mSuggestAuthority = in.readString(); |
| 847 |
mSuggestPath = in.readString(); |
| 848 |
mSuggestSelection = in.readString(); |
| 849 |
mSuggestIntentAction = in.readString(); |
| 850 |
mSuggestIntentData = in.readString(); |
| 851 |
mSuggestThreshold = in.readInt(); |
| 852 |
|
| 853 |
for (int count = in.readInt(); count > 0; count--) { |
| 854 |
addActionKey(new ActionKeyInfo(in)); |
| 855 |
} |
| 856 |
|
| 857 |
mSuggestProviderPackage = in.readString(); |
| 858 |
|
| 859 |
mVoiceSearchMode = in.readInt(); |
| 860 |
mVoiceLanguageModeId = in.readInt(); |
| 861 |
mVoicePromptTextId = in.readInt(); |
| 862 |
mVoiceLanguageId = in.readInt(); |
| 863 |
mVoiceMaxResults = in.readInt(); |
| 864 |
} |
| 865 |
|
| 866 |
public int describeContents() { |
| 867 |
return 0; |
| 868 |
} |
| 869 |
|
| 870 |
public void writeToParcel(Parcel dest, int flags) { |
| 871 |
dest.writeInt(mLabelId); |
| 872 |
mSearchActivity.writeToParcel(dest, flags); |
| 873 |
dest.writeInt(mHintId); |
| 874 |
dest.writeInt(mSearchMode); |
| 875 |
dest.writeInt(mIconId); |
| 876 |
dest.writeInt(mSearchButtonText); |
| 877 |
dest.writeInt(mSearchInputType); |
| 878 |
dest.writeInt(mSearchImeOptions); |
| 879 |
dest.writeInt(mIncludeInGlobalSearch ? 1 : 0); |
| 880 |
dest.writeInt(mQueryAfterZeroResults ? 1 : 0); |
| 881 |
dest.writeInt(mAutoUrlDetect ? 1 : 0); |
| 882 |
|
| 883 |
dest.writeInt(mSettingsDescriptionId); |
| 884 |
dest.writeString(mSuggestAuthority); |
| 885 |
dest.writeString(mSuggestPath); |
| 886 |
dest.writeString(mSuggestSelection); |
| 887 |
dest.writeString(mSuggestIntentAction); |
| 888 |
dest.writeString(mSuggestIntentData); |
| 889 |
dest.writeInt(mSuggestThreshold); |
| 890 |
|
| 891 |
if (mActionKeys == null) { |
| 892 |
dest.writeInt(0); |
| 893 |
} else { |
| 894 |
dest.writeInt(mActionKeys.size()); |
| 895 |
for (ActionKeyInfo actionKey : mActionKeys.values()) { |
| 896 |
actionKey.writeToParcel(dest, flags); |
| 897 |
} |
| 898 |
} |
| 899 |
|
| 900 |
dest.writeString(mSuggestProviderPackage); |
| 901 |
|
| 902 |
dest.writeInt(mVoiceSearchMode); |
| 903 |
dest.writeInt(mVoiceLanguageModeId); |
| 904 |
dest.writeInt(mVoicePromptTextId); |
| 905 |
dest.writeInt(mVoiceLanguageId); |
| 906 |
dest.writeInt(mVoiceMaxResults); |
| 907 |
} |
| 908 |
} |