13e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert/* 23e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert * Copyright (C) 2009 The Android Open Source Project 33e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert * 43e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert * Licensed under the Apache License, Version 2.0 (the "License"); 53e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert * you may not use this file except in compliance with the License. 63e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert * You may obtain a copy of the License at 73e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert * 83e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert * http://www.apache.org/licenses/LICENSE-2.0 93e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert * 103e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert * Unless required by applicable law or agreed to in writing, software 113e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert * distributed under the License is distributed on an "AS IS" BASIS, 123e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 133e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert * See the License for the specific language governing permissions and 143e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert * limitations under the License. 153e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert */ 163e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert 173e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringertpackage com.android.quicksearchbox; 183e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert 192353e9c002c45c0adc8a979a49ff317cae5838b8Bjorn Bringertimport com.android.quicksearchbox.util.Util; 202353e9c002c45c0adc8a979a49ff317cae5838b8Bjorn Bringert 21fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringertimport android.app.PendingIntent; 223e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringertimport android.app.SearchManager; 23227180196cf8d92172cbb62f8ddaacf864be28e7Bjorn Bringertimport android.app.SearchableInfo; 243e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringertimport android.content.ComponentName; 253e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringertimport android.content.ContentResolver; 263e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringertimport android.content.Context; 27fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringertimport android.content.Intent; 283e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringertimport android.content.pm.ActivityInfo; 296d5cbd67f7a5f824babb5c892b0f30bfd9f4ff23Bjorn Bringertimport android.content.pm.PackageInfo; 303e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringertimport android.content.pm.PackageManager; 31cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringertimport android.content.pm.PathPermission; 32cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringertimport android.content.pm.ProviderInfo; 333e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringertimport android.content.pm.PackageManager.NameNotFoundException; 343e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringertimport android.database.Cursor; 353e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringertimport android.graphics.drawable.Drawable; 363e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringertimport android.net.Uri; 37fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringertimport android.os.Bundle; 38fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringertimport android.speech.RecognizerIntent; 393e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringertimport android.util.Log; 403e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert 41227180196cf8d92172cbb62f8ddaacf864be28e7Bjorn Bringertimport java.util.Arrays; 42227180196cf8d92172cbb62f8ddaacf864be28e7Bjorn Bringert 433e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert/** 443e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert * Represents a single suggestion source, e.g. Contacts. 453e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert */ 4649fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringertpublic class SearchableSource extends AbstractSource { 473e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert 48b5fc08b7f16a32d3865f44b7f26d8aaa5304a2adBjorn Bringert private static final boolean DBG = false; 490484fb4d652bfa9d5c7fb238a7cec1a6f2244e44Bjorn Bringert private static final String TAG = "QSB.SearchableSource"; 503e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert 51fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert // TODO: This should be exposed or moved to android-common, see http://b/issue?id=2440614 52fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert // The extra key used in an intent to the speech recognizer for in-app voice search. 53fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert private static final String EXTRA_CALLING_PACKAGE = "calling_package"; 54fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert 553e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert private final SearchableInfo mSearchable; 563e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert 5762adab88055fd0ef6779242245cdc8c3ae5f999cBjorn Bringert private final String mName; 5862adab88055fd0ef6779242245cdc8c3ae5f999cBjorn Bringert 593e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert private final ActivityInfo mActivityInfo; 603e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert 616d5cbd67f7a5f824babb5c892b0f30bfd9f4ff23Bjorn Bringert private final int mVersionCode; 626d5cbd67f7a5f824babb5c892b0f30bfd9f4ff23Bjorn Bringert 633e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert // Cached label for the activity 643e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert private CharSequence mLabel = null; 653e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert 663e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert // Cached icon for the activity 673e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert private Drawable.ConstantState mSourceIcon = null; 683e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert 693e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert public SearchableSource(Context context, SearchableInfo searchable) 703e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert throws NameNotFoundException { 7149fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert super(context); 723e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert ComponentName componentName = searchable.getSearchActivity(); 733e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert mSearchable = searchable; 7462adab88055fd0ef6779242245cdc8c3ae5f999cBjorn Bringert mName = componentName.flattenToShortString(); 756d5cbd67f7a5f824babb5c892b0f30bfd9f4ff23Bjorn Bringert PackageManager pm = context.getPackageManager(); 766d5cbd67f7a5f824babb5c892b0f30bfd9f4ff23Bjorn Bringert mActivityInfo = pm.getActivityInfo(componentName, 0); 776d5cbd67f7a5f824babb5c892b0f30bfd9f4ff23Bjorn Bringert PackageInfo pkgInfo = pm.getPackageInfo(componentName.getPackageName(), 0); 786d5cbd67f7a5f824babb5c892b0f30bfd9f4ff23Bjorn Bringert mVersionCode = pkgInfo.versionCode; 79e1fc4581ebab65220a82bcdb3272b4eb85453837Bjorn Bringert } 80e1fc4581ebab65220a82bcdb3272b4eb85453837Bjorn Bringert 81fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert protected SearchableInfo getSearchableInfo() { 82fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert return mSearchable; 83fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert } 84fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert 85cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringert /** 86cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringert * Checks if the current process can read the suggestion provider in this source. 87cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringert */ 88cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringert public boolean canRead() { 89cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringert String authority = mSearchable.getSuggestAuthority(); 90cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringert if (authority == null) { 9181a0897ff9685f3313c58294bf7973700c468b2bBjorn Bringert // TODO: maybe we should have a way to distinguish between having suggestions 9281a0897ff9685f3313c58294bf7973700c468b2bBjorn Bringert // and being readable. 9381a0897ff9685f3313c58294bf7973700c468b2bBjorn Bringert return true; 94cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringert } 95cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringert 96cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringert Uri.Builder uriBuilder = new Uri.Builder() 97cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringert .scheme(ContentResolver.SCHEME_CONTENT) 98cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringert .authority(authority); 99cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringert // if content path provided, insert it now 100cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringert String contentPath = mSearchable.getSuggestPath(); 101cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringert if (contentPath != null) { 102cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringert uriBuilder.appendEncodedPath(contentPath); 103cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringert } 104cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringert // append standard suggestion query path 105cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringert uriBuilder.appendEncodedPath(SearchManager.SUGGEST_URI_PATH_QUERY); 106cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringert Uri uri = uriBuilder.build(); 107cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringert return canRead(uri); 108cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringert } 109cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringert 110cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringert /** 111cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringert * Checks if the current process can read the given content URI. 112cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringert * 113cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringert * TODO: Shouldn't this be a PackageManager / Context / ContentResolver method? 114cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringert */ 115cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringert private boolean canRead(Uri uri) { 11649fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert ProviderInfo provider = getContext().getPackageManager().resolveContentProvider( 117cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringert uri.getAuthority(), 0); 118cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringert if (provider == null) { 119cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringert Log.w(TAG, getName() + " has bad suggestion authority " + uri.getAuthority()); 120cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringert return false; 121cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringert } 122cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringert String readPermission = provider.readPermission; 123cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringert if (readPermission == null) { 124cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringert // No permission required to read anything in the content provider 125cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringert return true; 126cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringert } 127cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringert int pid = android.os.Process.myPid(); 128cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringert int uid = android.os.Process.myUid(); 12949fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert if (getContext().checkPermission(readPermission, pid, uid) 130cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringert == PackageManager.PERMISSION_GRANTED) { 131cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringert // We have permission to read everything in the content provider 132cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringert return true; 133cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringert } 134cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringert PathPermission[] pathPermissions = provider.pathPermissions; 135cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringert if (pathPermissions == null || pathPermissions.length == 0) { 136cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringert // We don't have the readPermission, and there are no pathPermissions 137cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringert if (DBG) Log.d(TAG, "Missing " + readPermission); 138cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringert return false; 139cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringert } 140cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringert String path = uri.getPath(); 141cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringert for (PathPermission perm : pathPermissions) { 142cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringert String pathReadPermission = perm.getReadPermission(); 143cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringert if (pathReadPermission != null 144cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringert && perm.match(path) 14549fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert && getContext().checkPermission(pathReadPermission, pid, uid) 146cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringert == PackageManager.PERMISSION_GRANTED) { 147cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringert // We have the path permission 148cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringert return true; 149cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringert } 150cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringert } 151cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringert if (DBG) Log.d(TAG, "Missing " + readPermission + " and no path permission applies"); 152cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringert return false; 153cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringert } 154cc10dcf07c4e787abd66f4e2cfed31a09580a3b0Bjorn Bringert 15581a0897ff9685f3313c58294bf7973700c468b2bBjorn Bringert public ComponentName getIntentComponent() { 1563e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert return mSearchable.getSearchActivity(); 1573e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert } 1583e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert 1596d5cbd67f7a5f824babb5c892b0f30bfd9f4ff23Bjorn Bringert public int getVersionCode() { 1606d5cbd67f7a5f824babb5c892b0f30bfd9f4ff23Bjorn Bringert return mVersionCode; 1616d5cbd67f7a5f824babb5c892b0f30bfd9f4ff23Bjorn Bringert } 1626d5cbd67f7a5f824babb5c892b0f30bfd9f4ff23Bjorn Bringert 163f252dc7a25ba08b973ecc1cfbbce58eb78d42167Bjorn Bringert public String getName() { 16462adab88055fd0ef6779242245cdc8c3ae5f999cBjorn Bringert return mName; 165d32d6753347e872aa5d9d6e9015ed7f24db3e362Bjorn Bringert } 166d32d6753347e872aa5d9d6e9015ed7f24db3e362Bjorn Bringert 16749fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert @Override 16849fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert protected String getIconPackage() { 16949fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert // Get icons from the package containing the suggestion provider, if any 17049fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert String iconPackage = mSearchable.getSuggestPackage(); 17149fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert if (iconPackage != null) { 17249fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert return iconPackage; 17349fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert } else { 17449fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert // Fall back to the package containing the searchable activity 17549fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert return mSearchable.getSearchActivity().getPackageName(); 17649fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert } 1773e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert } 1783e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert 1793e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert public CharSequence getLabel() { 1803e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert if (mLabel == null) { 1813e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert // Load label lazily 18249fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert mLabel = mActivityInfo.loadLabel(getContext().getPackageManager()); 1833e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert } 1843e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert return mLabel; 1853e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert } 1863e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert 1875691f9062b2a558ba39c700d65bc522d397ebc75Bjorn Bringert public CharSequence getHint() { 1885691f9062b2a558ba39c700d65bc522d397ebc75Bjorn Bringert return getText(mSearchable.getHintId()); 1895691f9062b2a558ba39c700d65bc522d397ebc75Bjorn Bringert } 1905691f9062b2a558ba39c700d65bc522d397ebc75Bjorn Bringert 1913e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert public int getQueryThreshold() { 1923e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert return mSearchable.getSuggestThreshold(); 1933e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert } 1943e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert 1958d9d845323514c34bb07d6eb91146a975324fcedBjorn Bringert public CharSequence getSettingsDescription() { 196fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert return getText(mSearchable.getSettingsDescriptionId()); 1973e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert } 1983e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert 1993e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert public Drawable getSourceIcon() { 2003e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert if (mSourceIcon == null) { 201e46ac8349b012ec2c649d4e20bc835fec9ec681fBjorn Bringert Drawable icon = loadSourceIcon(); 202e46ac8349b012ec2c649d4e20bc835fec9ec681fBjorn Bringert if (icon == null) { 203e46ac8349b012ec2c649d4e20bc835fec9ec681fBjorn Bringert icon = getContext().getResources().getDrawable(R.drawable.corpus_icon_default); 204e46ac8349b012ec2c649d4e20bc835fec9ec681fBjorn Bringert } 2053e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert // Can't share Drawable instances, save constant state instead. 2063e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert mSourceIcon = (icon != null) ? icon.getConstantState() : null; 2073e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert // Optimization, return the Drawable the first time 2083e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert return icon; 2093e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert } 2103e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert return (mSourceIcon != null) ? mSourceIcon.newDrawable() : null; 2113e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert } 2123e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert 213e46ac8349b012ec2c649d4e20bc835fec9ec681fBjorn Bringert private Drawable loadSourceIcon() { 214e46ac8349b012ec2c649d4e20bc835fec9ec681fBjorn Bringert int iconRes = getSourceIconResource(); 215e46ac8349b012ec2c649d4e20bc835fec9ec681fBjorn Bringert if (iconRes == 0) return null; 216e46ac8349b012ec2c649d4e20bc835fec9ec681fBjorn Bringert PackageManager pm = getContext().getPackageManager(); 217e46ac8349b012ec2c649d4e20bc835fec9ec681fBjorn Bringert return pm.getDrawable(mActivityInfo.packageName, iconRes, 218e46ac8349b012ec2c649d4e20bc835fec9ec681fBjorn Bringert mActivityInfo.applicationInfo); 219e46ac8349b012ec2c649d4e20bc835fec9ec681fBjorn Bringert } 220e46ac8349b012ec2c649d4e20bc835fec9ec681fBjorn Bringert 2213e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert public Uri getSourceIconUri() { 222d32d6753347e872aa5d9d6e9015ed7f24db3e362Bjorn Bringert int resourceId = getSourceIconResource(); 223e46ac8349b012ec2c649d4e20bc835fec9ec681fBjorn Bringert if (resourceId == 0) { 224e46ac8349b012ec2c649d4e20bc835fec9ec681fBjorn Bringert return Util.getResourceUri(getContext(), R.drawable.corpus_icon_default); 225e46ac8349b012ec2c649d4e20bc835fec9ec681fBjorn Bringert } else { 226e46ac8349b012ec2c649d4e20bc835fec9ec681fBjorn Bringert return Util.getResourceUri(getContext(), mActivityInfo.applicationInfo, resourceId); 227e46ac8349b012ec2c649d4e20bc835fec9ec681fBjorn Bringert } 2283e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert } 2293e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert 2303e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert private int getSourceIconResource() { 231e46ac8349b012ec2c649d4e20bc835fec9ec681fBjorn Bringert return mActivityInfo.getIconResource(); 2323e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert } 2333e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert 234fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert public boolean voiceSearchEnabled() { 235fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert return mSearchable.getVoiceSearchEnabled(); 236fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert } 237fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert 23849fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert public boolean isLocationAware() { 23949fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert return false; 240fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert } 241fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert 242fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert public Intent createVoiceSearchIntent(Bundle appData) { 243fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert if (mSearchable.getVoiceSearchLaunchWebSearch()) { 24449fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert return createVoiceWebSearchIntent(appData); 245fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert } else if (mSearchable.getVoiceSearchLaunchRecognizer()) { 246fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert return createVoiceAppSearchIntent(appData); 247fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert } 248fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert return null; 249fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert } 250fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert 251fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert /** 252fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert * Create and return an Intent that can launch the voice search activity, perform a specific 253fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert * voice transcription, and forward the results to the searchable activity. 254fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert * 255fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert * This code is copied from SearchDialog 256fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert * 257fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert * @return A completely-configured intent ready to send to the voice search activity 258fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert */ 259fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert private Intent createVoiceAppSearchIntent(Bundle appData) { 260fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert ComponentName searchActivity = mSearchable.getSearchActivity(); 261fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert 262fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert // create the necessary intent to set up a search-and-forward operation 263fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert // in the voice search system. We have to keep the bundle separate, 264fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert // because it becomes immutable once it enters the PendingIntent 265fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert Intent queryIntent = new Intent(Intent.ACTION_SEARCH); 266fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert queryIntent.setComponent(searchActivity); 267fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert PendingIntent pending = PendingIntent.getActivity( 268fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert getContext(), 0, queryIntent, PendingIntent.FLAG_ONE_SHOT); 269fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert 270fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert // Now set up the bundle that will be inserted into the pending intent 271fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert // when it's time to do the search. We always build it here (even if empty) 272fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert // because the voice search activity will always need to insert "QUERY" into 273fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert // it anyway. 274fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert Bundle queryExtras = new Bundle(); 275fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert if (appData != null) { 276fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert queryExtras.putBundle(SearchManager.APP_DATA, appData); 277fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert } 278fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert 279fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert // Now build the intent to launch the voice search. Add all necessary 280fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert // extras to launch the voice recognizer, and then all the necessary extras 281fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert // to forward the results to the searchable activity 282fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); 283fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert voiceIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 284fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert 285fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert // Add all of the configuration options supplied by the searchable's metadata 286fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert String languageModel = getString(mSearchable.getVoiceLanguageModeId()); 287fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert if (languageModel == null) { 288fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert languageModel = RecognizerIntent.LANGUAGE_MODEL_FREE_FORM; 289fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert } 290fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert String prompt = getString(mSearchable.getVoicePromptTextId()); 291fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert String language = getString(mSearchable.getVoiceLanguageId()); 292fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert int maxResults = mSearchable.getVoiceMaxResults(); 293fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert if (maxResults <= 0) { 294fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert maxResults = 1; 295fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert } 296fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert 297fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert voiceIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, languageModel); 298fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert voiceIntent.putExtra(RecognizerIntent.EXTRA_PROMPT, prompt); 299fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert voiceIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, language); 300fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert voiceIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, maxResults); 301fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert voiceIntent.putExtra(EXTRA_CALLING_PACKAGE, 302fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert searchActivity == null ? null : searchActivity.toShortString()); 303fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert 304fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert // Add the values that configure forwarding the results 305fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert voiceIntent.putExtra(RecognizerIntent.EXTRA_RESULTS_PENDINGINTENT, pending); 306fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert voiceIntent.putExtra(RecognizerIntent.EXTRA_RESULTS_PENDINGINTENT_BUNDLE, queryExtras); 307fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert 308fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert return voiceIntent; 309fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert } 310fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert 311cd1e3ba5f7c3f5242345ff6f674281e3d6366e24Mathew Inwood public SourceResult getSuggestions(String query, int queryLimit, boolean onlySource) { 3123e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert try { 31349fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert Cursor cursor = getSuggestions(getContext(), mSearchable, query, queryLimit); 3143e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert if (DBG) Log.d(TAG, toString() + "[" + query + "] returned."); 31549fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert return new CursorBackedSourceResult(this, query, cursor); 3163e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert } catch (RuntimeException ex) { 3173e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert Log.e(TAG, toString() + "[" + query + "] failed", ex); 31849fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert return new CursorBackedSourceResult(this, query); 3193e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert } 3203e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert } 3213e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert 32294e8a2be78530170f50e7895a558bf8011bbf8e8Bryan Mawhinney public SuggestionCursor refreshShortcut(String shortcutId, String extraData) { 32394e8a2be78530170f50e7895a558bf8011bbf8e8Bryan Mawhinney Cursor cursor = null; 32494e8a2be78530170f50e7895a558bf8011bbf8e8Bryan Mawhinney try { 32549fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert cursor = getValidationCursor(getContext(), mSearchable, shortcutId, extraData); 32694e8a2be78530170f50e7895a558bf8011bbf8e8Bryan Mawhinney if (DBG) Log.d(TAG, toString() + "[" + shortcutId + "] returned."); 32794e8a2be78530170f50e7895a558bf8011bbf8e8Bryan Mawhinney if (cursor != null && cursor.getCount() > 0) { 32894e8a2be78530170f50e7895a558bf8011bbf8e8Bryan Mawhinney cursor.moveToFirst(); 32994e8a2be78530170f50e7895a558bf8011bbf8e8Bryan Mawhinney } 33049fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert return new CursorBackedSourceResult(this, null, cursor); 33194e8a2be78530170f50e7895a558bf8011bbf8e8Bryan Mawhinney } catch (RuntimeException ex) { 33294e8a2be78530170f50e7895a558bf8011bbf8e8Bryan Mawhinney Log.e(TAG, toString() + "[" + shortcutId + "] failed", ex); 33394e8a2be78530170f50e7895a558bf8011bbf8e8Bryan Mawhinney if (cursor != null) { 33494e8a2be78530170f50e7895a558bf8011bbf8e8Bryan Mawhinney cursor.close(); 33594e8a2be78530170f50e7895a558bf8011bbf8e8Bryan Mawhinney } 33694e8a2be78530170f50e7895a558bf8011bbf8e8Bryan Mawhinney // TODO: Should we delete the shortcut even if the failure is temporary? 33794e8a2be78530170f50e7895a558bf8011bbf8e8Bryan Mawhinney return null; 33894e8a2be78530170f50e7895a558bf8011bbf8e8Bryan Mawhinney } 33994e8a2be78530170f50e7895a558bf8011bbf8e8Bryan Mawhinney } 34094e8a2be78530170f50e7895a558bf8011bbf8e8Bryan Mawhinney 3413e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert /** 3423e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert * This is a copy of {@link SearchManager#getSuggestions(SearchableInfo, String)}. 3433e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert */ 3443e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert private static Cursor getSuggestions(Context context, SearchableInfo searchable, String query, 3453e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert int queryLimit) { 3463e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert if (searchable == null) { 3473e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert return null; 3483e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert } 3493e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert 3503e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert String authority = searchable.getSuggestAuthority(); 3513e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert if (authority == null) { 3523e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert return null; 3533e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert } 3543e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert 3553e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert Uri.Builder uriBuilder = new Uri.Builder() 3563e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert .scheme(ContentResolver.SCHEME_CONTENT) 3573e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert .authority(authority); 3583e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert 3593e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert // if content path provided, insert it now 3603e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert final String contentPath = searchable.getSuggestPath(); 3613e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert if (contentPath != null) { 3623e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert uriBuilder.appendEncodedPath(contentPath); 3633e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert } 3643e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert 3653e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert // append standard suggestion query path 3663e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert uriBuilder.appendPath(SearchManager.SUGGEST_URI_PATH_QUERY); 3673e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert 3683e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert // get the query selection, may be null 3693e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert String selection = searchable.getSuggestSelection(); 3703e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert // inject query, either as selection args or inline 3713e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert String[] selArgs = null; 3723e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert if (selection != null) { // use selection if provided 3733e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert selArgs = new String[] { query }; 3743e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert } else { // no selection, use REST pattern 3753e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert uriBuilder.appendPath(query); 3763e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert } 3773e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert 3783e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert uriBuilder.appendQueryParameter("limit", String.valueOf(queryLimit)); 3793e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert 3803e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert Uri uri = uriBuilder.build(); 3813e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert 3823e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert // finally, make the query 3833e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert if (DBG) { 3843e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert Log.d(TAG, "query(" + uri + ",null," + selection + "," 3853e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert + Arrays.toString(selArgs) + ",null)"); 3863e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert } 3873e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert return context.getContentResolver().query(uri, null, selection, selArgs, null); 3883e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert } 3893e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert 39094e8a2be78530170f50e7895a558bf8011bbf8e8Bryan Mawhinney private static Cursor getValidationCursor(Context context, SearchableInfo searchable, 39194e8a2be78530170f50e7895a558bf8011bbf8e8Bryan Mawhinney String shortcutId, String extraData) { 39294e8a2be78530170f50e7895a558bf8011bbf8e8Bryan Mawhinney String authority = searchable.getSuggestAuthority(); 39394e8a2be78530170f50e7895a558bf8011bbf8e8Bryan Mawhinney if (authority == null) { 39494e8a2be78530170f50e7895a558bf8011bbf8e8Bryan Mawhinney return null; 39594e8a2be78530170f50e7895a558bf8011bbf8e8Bryan Mawhinney } 39694e8a2be78530170f50e7895a558bf8011bbf8e8Bryan Mawhinney 39794e8a2be78530170f50e7895a558bf8011bbf8e8Bryan Mawhinney Uri.Builder uriBuilder = new Uri.Builder() 39894e8a2be78530170f50e7895a558bf8011bbf8e8Bryan Mawhinney .scheme(ContentResolver.SCHEME_CONTENT) 39994e8a2be78530170f50e7895a558bf8011bbf8e8Bryan Mawhinney .authority(authority); 40094e8a2be78530170f50e7895a558bf8011bbf8e8Bryan Mawhinney 40194e8a2be78530170f50e7895a558bf8011bbf8e8Bryan Mawhinney // if content path provided, insert it now 40294e8a2be78530170f50e7895a558bf8011bbf8e8Bryan Mawhinney final String contentPath = searchable.getSuggestPath(); 40394e8a2be78530170f50e7895a558bf8011bbf8e8Bryan Mawhinney if (contentPath != null) { 40494e8a2be78530170f50e7895a558bf8011bbf8e8Bryan Mawhinney uriBuilder.appendEncodedPath(contentPath); 40594e8a2be78530170f50e7895a558bf8011bbf8e8Bryan Mawhinney } 40694e8a2be78530170f50e7895a558bf8011bbf8e8Bryan Mawhinney 40794e8a2be78530170f50e7895a558bf8011bbf8e8Bryan Mawhinney // append the shortcut path and id 40894e8a2be78530170f50e7895a558bf8011bbf8e8Bryan Mawhinney uriBuilder.appendPath(SearchManager.SUGGEST_URI_PATH_SHORTCUT); 40994e8a2be78530170f50e7895a558bf8011bbf8e8Bryan Mawhinney uriBuilder.appendPath(shortcutId); 41094e8a2be78530170f50e7895a558bf8011bbf8e8Bryan Mawhinney 41194e8a2be78530170f50e7895a558bf8011bbf8e8Bryan Mawhinney Uri uri = uriBuilder 41294e8a2be78530170f50e7895a558bf8011bbf8e8Bryan Mawhinney .appendQueryParameter(SearchManager.SUGGEST_COLUMN_INTENT_EXTRA_DATA, extraData) 41394e8a2be78530170f50e7895a558bf8011bbf8e8Bryan Mawhinney .build(); 41494e8a2be78530170f50e7895a558bf8011bbf8e8Bryan Mawhinney 41594e8a2be78530170f50e7895a558bf8011bbf8e8Bryan Mawhinney if (DBG) Log.d(TAG, "Requesting refresh " + uri); 41694e8a2be78530170f50e7895a558bf8011bbf8e8Bryan Mawhinney // finally, make the query 41794e8a2be78530170f50e7895a558bf8011bbf8e8Bryan Mawhinney return context.getContentResolver().query(uri, null, null, null, null); 41894e8a2be78530170f50e7895a558bf8011bbf8e8Bryan Mawhinney } 41994e8a2be78530170f50e7895a558bf8011bbf8e8Bryan Mawhinney 4203e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert public boolean isWebSuggestionSource() { 421ca78085bb2127559e6f55276a307bfa857018ecaBjorn Bringert return false; 4223e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert } 4233e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert 4243e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert public boolean queryAfterZeroResults() { 4253e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert return mSearchable.queryAfterZeroResults(); 4263e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert } 4273e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert 4283e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert public String getDefaultIntentAction() { 42993bd2e70b8b08da1ec37fd0e990dac05551d2e90Bjorn Bringert String action = mSearchable.getSuggestIntentAction(); 43093bd2e70b8b08da1ec37fd0e990dac05551d2e90Bjorn Bringert if (action != null) return action; 43193bd2e70b8b08da1ec37fd0e990dac05551d2e90Bjorn Bringert return Intent.ACTION_SEARCH; 4323e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert } 4333e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert 4343e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert public String getDefaultIntentData() { 4353e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert return mSearchable.getSuggestIntentData(); 4363e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert } 4373e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert 438fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert private CharSequence getText(int id) { 439fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert if (id == 0) return null; 44049fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert return getContext().getPackageManager().getText(mActivityInfo.packageName, id, 441fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert mActivityInfo.applicationInfo); 442fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert } 443fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert 444fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert private String getString(int id) { 445fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert CharSequence text = getText(id); 446fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert return text == null ? null : text.toString(); 447fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert } 4483e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert} 449