Merge change 725 into donut
* changes: Add 'includeInGlobalSearch' attribute to searchable meta-data.
This commit is contained in:
@ -22,4 +22,5 @@ import android.server.search.SearchableInfo;
|
||||
/** @hide */
|
||||
interface ISearchManager {
|
||||
SearchableInfo getSearchableInfo(in ComponentName launchActivity, boolean globalSearch);
|
||||
List<SearchableInfo> getSearchablesInGlobalSearch();
|
||||
}
|
||||
|
@ -30,6 +30,8 @@ import android.os.ServiceManager;
|
||||
import android.server.search.SearchableInfo;
|
||||
import android.view.KeyEvent;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class provides access to the system search services.
|
||||
*
|
||||
@ -1655,4 +1657,20 @@ public class SearchManager
|
||||
return context.getContentResolver().query(uri, null, selection, selArgs, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of the searchable activities that can be included in global search.
|
||||
*
|
||||
* @return a list containing searchable information for all searchable activities
|
||||
* that have the <code>exported</code> attribute set in their searchable
|
||||
* meta-data.
|
||||
*
|
||||
* @hide because SearchableInfo is not part of the API.
|
||||
*/
|
||||
public static List<SearchableInfo> getSearchablesInGlobalSearch() {
|
||||
try {
|
||||
return sService.getSearchablesInGlobalSearch();
|
||||
} catch (RemoteException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,8 @@ import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.Handler;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This is a simplified version of the Search Manager service. It no longer handles
|
||||
* presentation (UI). Its function is to maintain the map & list of "searchable"
|
||||
@ -143,5 +145,12 @@ public class SearchManagerService extends ISearchManager.Stub
|
||||
|
||||
return si;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of the searchable activities that can be included in global search.
|
||||
*/
|
||||
public List<SearchableInfo> getSearchablesInGlobalSearch() {
|
||||
return mSearchables.getSearchablesInGlobalSearchList();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -66,6 +66,7 @@ public final class SearchableInfo implements Parcelable {
|
||||
private int mSearchButtonText = 0;
|
||||
private int mSearchInputType = 0;
|
||||
private int mSearchImeOptions = 0;
|
||||
private boolean mIncludeInGlobalSearch = false;
|
||||
private String mSuggestAuthority = null;
|
||||
private String mSuggestPath = null;
|
||||
private String mSuggestSelection = null;
|
||||
@ -236,6 +237,8 @@ public final class SearchableInfo implements Parcelable {
|
||||
InputType.TYPE_TEXT_VARIATION_NORMAL);
|
||||
mSearchImeOptions = a.getInt(com.android.internal.R.styleable.Searchable_imeOptions,
|
||||
EditorInfo.IME_ACTION_SEARCH);
|
||||
mIncludeInGlobalSearch = a.getBoolean(
|
||||
com.android.internal.R.styleable.Searchable_includeInGlobalSearch, false);
|
||||
|
||||
setSearchModeFlags();
|
||||
if (DBG_INHIBIT_SUGGESTIONS == 0) {
|
||||
@ -575,6 +578,16 @@ public final class SearchableInfo implements Parcelable {
|
||||
return mSearchImeOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the searchable is exported.
|
||||
*
|
||||
* @return The value of the <code>exported</code> attribute,
|
||||
* or <code>false</code> if the attribute is not set.
|
||||
*/
|
||||
public boolean shouldIncludeInGlobalSearch() {
|
||||
return mIncludeInGlobalSearch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Support for parcelable and aidl operations.
|
||||
*/
|
||||
@ -606,6 +619,7 @@ public final class SearchableInfo implements Parcelable {
|
||||
mSearchButtonText = in.readInt();
|
||||
mSearchInputType = in.readInt();
|
||||
mSearchImeOptions = in.readInt();
|
||||
mIncludeInGlobalSearch = in.readInt() != 0;
|
||||
setSearchModeFlags();
|
||||
|
||||
mSuggestAuthority = in.readString();
|
||||
@ -644,6 +658,7 @@ public final class SearchableInfo implements Parcelable {
|
||||
dest.writeInt(mSearchButtonText);
|
||||
dest.writeInt(mSearchInputType);
|
||||
dest.writeInt(mSearchImeOptions);
|
||||
dest.writeInt(mIncludeInGlobalSearch ? 1 : 0);
|
||||
|
||||
dest.writeString(mSuggestAuthority);
|
||||
dest.writeString(mSuggestPath);
|
||||
|
@ -44,6 +44,7 @@ public class Searchables {
|
||||
|
||||
private HashMap<ComponentName, SearchableInfo> mSearchablesMap = null;
|
||||
private ArrayList<SearchableInfo> mSearchablesList = null;
|
||||
private ArrayList<SearchableInfo> mSearchablesInGlobalSearchList = null;
|
||||
private SearchableInfo mDefaultSearchable = null;
|
||||
|
||||
/**
|
||||
@ -189,6 +190,8 @@ public class Searchables {
|
||||
= new HashMap<ComponentName, SearchableInfo>();
|
||||
ArrayList<SearchableInfo> newSearchablesList
|
||||
= new ArrayList<SearchableInfo>();
|
||||
ArrayList<SearchableInfo> newSearchablesInGlobalSearchList
|
||||
= new ArrayList<SearchableInfo>();
|
||||
|
||||
final PackageManager pm = mContext.getPackageManager();
|
||||
|
||||
@ -208,6 +211,9 @@ public class Searchables {
|
||||
if (searchable != null) {
|
||||
newSearchablesList.add(searchable);
|
||||
newSearchablesMap.put(searchable.mSearchActivity, searchable);
|
||||
if (searchable.shouldIncludeInGlobalSearch()) {
|
||||
newSearchablesInGlobalSearchList.add(searchable);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -219,8 +225,9 @@ public class Searchables {
|
||||
|
||||
// Store a consistent set of new values
|
||||
synchronized (this) {
|
||||
mSearchablesList = newSearchablesList;
|
||||
mSearchablesMap = newSearchablesMap;
|
||||
mSearchablesList = newSearchablesList;
|
||||
mSearchablesInGlobalSearchList = newSearchablesInGlobalSearchList;
|
||||
mDefaultSearchable = newDefaultSearchable;
|
||||
}
|
||||
}
|
||||
@ -232,4 +239,11 @@ public class Searchables {
|
||||
ArrayList<SearchableInfo> result = new ArrayList<SearchableInfo>(mSearchablesList);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of the searchable activities that can be included in global search.
|
||||
*/
|
||||
public synchronized ArrayList<SearchableInfo> getSearchablesInGlobalSearchList() {
|
||||
return new ArrayList<SearchableInfo>(mSearchablesInGlobalSearchList);
|
||||
}
|
||||
}
|
||||
|
@ -2785,6 +2785,11 @@
|
||||
search suggestions. The default value is 0. <i>Optional attribute.</i> -->
|
||||
<attr name="searchSuggestThreshold" format="integer" />
|
||||
|
||||
<!-- If provided and <code>true</code>, this searchable activity will be
|
||||
included in any global lists of search targets.
|
||||
The default value is <code>false</code>. <i>Optional attribute.</i>. -->
|
||||
<attr name="includeInGlobalSearch" format="boolean" />
|
||||
|
||||
</declare-styleable>
|
||||
|
||||
<!-- In order to process special action keys during search, you must define them using
|
||||
|
@ -153,6 +153,8 @@ public class SearchablesTest extends AndroidTestCase {
|
||||
int count = searchablesList.size();
|
||||
assertTrue(count >= 1); // this isn't really a unit test
|
||||
checkSearchables(searchablesList);
|
||||
ArrayList<SearchableInfo> global = searchables.getSearchablesInGlobalSearchList();
|
||||
checkSearchables(global);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -166,10 +168,10 @@ public class SearchablesTest extends AndroidTestCase {
|
||||
Searchables searchables = new Searchables(mockContext);
|
||||
searchables.buildSearchableList();
|
||||
ArrayList<SearchableInfo> searchablesList = searchables.getSearchablesList();
|
||||
if (searchablesList != null) {
|
||||
int count = searchablesList.size();
|
||||
assertTrue(count == 0);
|
||||
}
|
||||
assertNotNull(searchablesList);
|
||||
MoreAsserts.assertEmpty(searchablesList);
|
||||
ArrayList<SearchableInfo> global = searchables.getSearchablesInGlobalSearchList();
|
||||
MoreAsserts.assertEmpty(global);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user