use of android.app.SearchableInfo in project android_frameworks_base by crdroidandroid.
the class Searchables method dump.
void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
pw.println("Searchable authorities:");
synchronized (this) {
if (mSearchablesList != null) {
for (SearchableInfo info : mSearchablesList) {
pw.print(" ");
pw.println(info.getSuggestAuthority());
}
}
}
}
use of android.app.SearchableInfo in project android_frameworks_base by crdroidandroid.
the class SearchablesTest method testSearchablesListEmpty.
/**
* This round of tests confirms good operations with "zero" searchables found
*/
public void testSearchablesListEmpty() {
MyMockPackageManager mockPM = new MyMockPackageManager(mContext.getPackageManager());
MyMockContext mockContext = new MyMockContext(mContext, mockPM);
mockPM.setSearchablesMode(MyMockPackageManager.SEARCHABLES_MOCK_ZERO);
Searchables searchables = new Searchables(mockContext, 0);
searchables.updateSearchableList();
ArrayList<SearchableInfo> searchablesList = searchables.getSearchablesList();
assertNotNull(searchablesList);
MoreAsserts.assertEmpty(searchablesList);
ArrayList<SearchableInfo> global = searchables.getSearchablesInGlobalSearchList();
MoreAsserts.assertEmpty(global);
}
use of android.app.SearchableInfo in project android_frameworks_base by crdroidandroid.
the class SearchablesTest method testSearchablesListReal.
/**
* This is an attempt to run the searchable info list with a mocked context. Here are some
* things I'd like to test.
*
* Confirm OK with "zero" searchables
* Confirm "good" metadata read properly
* Confirm "bad" metadata skipped properly
* Confirm ordering of searchables
* Confirm "good" actionkeys
* confirm "bad" actionkeys are rejected
* confirm XML ordering enforced (will fail today - bug in SearchableInfo)
* findActionKey works
* getIcon works
*/
public void testSearchablesListReal() {
MyMockPackageManager mockPM = new MyMockPackageManager(mContext.getPackageManager());
MyMockContext mockContext = new MyMockContext(mContext, mockPM);
// build item list with real-world source data
mockPM.setSearchablesMode(MyMockPackageManager.SEARCHABLES_PASSTHROUGH);
Searchables searchables = new Searchables(mockContext, 0);
searchables.updateSearchableList();
// tests with "real" searchables (deprecate, this should be a unit test)
ArrayList<SearchableInfo> searchablesList = searchables.getSearchablesList();
int count = searchablesList.size();
// this isn't really a unit test
assertTrue(count >= 1);
checkSearchables(searchablesList);
ArrayList<SearchableInfo> global = searchables.getSearchablesInGlobalSearchList();
checkSearchables(global);
}
use of android.app.SearchableInfo in project SmartAndroidSource by jaychou2012.
the class SearchView method onVoiceClicked.
private void onVoiceClicked() {
// guard against possible race conditions
if (mSearchable == null) {
return;
}
SearchableInfo searchable = mSearchable;
try {
if (searchable.getVoiceSearchLaunchWebSearch()) {
Intent webSearchIntent = createVoiceWebSearchIntent(mVoiceWebSearchIntent, searchable);
getContext().startActivity(webSearchIntent);
} else if (searchable.getVoiceSearchLaunchRecognizer()) {
Intent appSearchIntent = createVoiceAppSearchIntent(mVoiceAppSearchIntent, searchable);
getContext().startActivity(appSearchIntent);
}
} catch (ActivityNotFoundException e) {
// Should not happen, since we check the availability of
// voice search before showing the button. But just in case...
Log.w(LOG_TAG, "Could not find voice search activity");
}
}
use of android.app.SearchableInfo in project platform_frameworks_base by android.
the class Searchables method getSearchableInfo.
/**
* Look up, or construct, based on the activity.
*
* The activities fall into three cases, based on meta-data found in
* the manifest entry:
* <ol>
* <li>The activity itself implements search. This is indicated by the
* presence of a "android.app.searchable" meta-data attribute.
* The value is a reference to an XML file containing search information.</li>
* <li>A related activity implements search. This is indicated by the
* presence of a "android.app.default_searchable" meta-data attribute.
* The value is a string naming the activity implementing search. In this
* case the factory will "redirect" and return the searchable data.</li>
* <li>No searchability data is provided. We return null here and other
* code will insert the "default" (e.g. contacts) search.
*
* TODO: cache the result in the map, and check the map first.
* TODO: it might make sense to implement the searchable reference as
* an application meta-data entry. This way we don't have to pepper each
* and every activity.
* TODO: can we skip the constructor step if it's a non-searchable?
* TODO: does it make sense to plug the default into a slot here for
* automatic return? Probably not, but it's one way to do it.
*
* @param activity The name of the current activity, or null if the
* activity does not define any explicit searchable metadata.
*/
public SearchableInfo getSearchableInfo(ComponentName activity) {
// Step 1. Is the result already hashed? (case 1)
SearchableInfo result;
synchronized (this) {
result = mSearchablesMap.get(activity);
if (result != null)
return result;
}
// Step 2. See if the current activity references a searchable.
// Note: Conceptually, this could be a while(true) loop, but there's
// no point in implementing reference chaining here and risking a loop.
// References must point directly to searchable activities.
ActivityInfo ai = null;
try {
ai = mPm.getActivityInfo(activity, PackageManager.GET_META_DATA, mUserId);
} catch (RemoteException re) {
Log.e(LOG_TAG, "Error getting activity info " + re);
return null;
}
String refActivityName = null;
// First look for activity-specific reference
Bundle md = ai.metaData;
if (md != null) {
refActivityName = md.getString(MD_LABEL_DEFAULT_SEARCHABLE);
}
// If not found, try for app-wide reference
if (refActivityName == null) {
md = ai.applicationInfo.metaData;
if (md != null) {
refActivityName = md.getString(MD_LABEL_DEFAULT_SEARCHABLE);
}
}
// Irrespective of source, if a reference was found, follow it.
if (refActivityName != null) {
// This value is deprecated, return null
if (refActivityName.equals(MD_SEARCHABLE_SYSTEM_SEARCH)) {
return null;
}
String pkg = activity.getPackageName();
ComponentName referredActivity;
if (refActivityName.charAt(0) == '.') {
referredActivity = new ComponentName(pkg, pkg + refActivityName);
} else {
referredActivity = new ComponentName(pkg, refActivityName);
}
// it against the original name so we can skip the check
synchronized (this) {
result = mSearchablesMap.get(referredActivity);
if (result != null) {
mSearchablesMap.put(activity, result);
return result;
}
}
}
// Step 3. None found. Return null.
return null;
}
Aggregations