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 */
|
/** @hide */
|
||||||
interface ISearchManager {
|
interface ISearchManager {
|
||||||
SearchableInfo getSearchableInfo(in ComponentName launchActivity, boolean globalSearch);
|
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.server.search.SearchableInfo;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class provides access to the system search services.
|
* 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);
|
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.content.IntentFilter;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is a simplified version of the Search Manager service. It no longer handles
|
* 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"
|
* presentation (UI). Its function is to maintain the map & list of "searchable"
|
||||||
@ -143,5 +145,12 @@ public class SearchManagerService extends ISearchManager.Stub
|
|||||||
|
|
||||||
return si;
|
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 mSearchButtonText = 0;
|
||||||
private int mSearchInputType = 0;
|
private int mSearchInputType = 0;
|
||||||
private int mSearchImeOptions = 0;
|
private int mSearchImeOptions = 0;
|
||||||
|
private boolean mIncludeInGlobalSearch = false;
|
||||||
private String mSuggestAuthority = null;
|
private String mSuggestAuthority = null;
|
||||||
private String mSuggestPath = null;
|
private String mSuggestPath = null;
|
||||||
private String mSuggestSelection = null;
|
private String mSuggestSelection = null;
|
||||||
@ -236,6 +237,8 @@ public final class SearchableInfo implements Parcelable {
|
|||||||
InputType.TYPE_TEXT_VARIATION_NORMAL);
|
InputType.TYPE_TEXT_VARIATION_NORMAL);
|
||||||
mSearchImeOptions = a.getInt(com.android.internal.R.styleable.Searchable_imeOptions,
|
mSearchImeOptions = a.getInt(com.android.internal.R.styleable.Searchable_imeOptions,
|
||||||
EditorInfo.IME_ACTION_SEARCH);
|
EditorInfo.IME_ACTION_SEARCH);
|
||||||
|
mIncludeInGlobalSearch = a.getBoolean(
|
||||||
|
com.android.internal.R.styleable.Searchable_includeInGlobalSearch, false);
|
||||||
|
|
||||||
setSearchModeFlags();
|
setSearchModeFlags();
|
||||||
if (DBG_INHIBIT_SUGGESTIONS == 0) {
|
if (DBG_INHIBIT_SUGGESTIONS == 0) {
|
||||||
@ -575,6 +578,16 @@ public final class SearchableInfo implements Parcelable {
|
|||||||
return mSearchImeOptions;
|
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.
|
* Support for parcelable and aidl operations.
|
||||||
*/
|
*/
|
||||||
@ -606,6 +619,7 @@ public final class SearchableInfo implements Parcelable {
|
|||||||
mSearchButtonText = in.readInt();
|
mSearchButtonText = in.readInt();
|
||||||
mSearchInputType = in.readInt();
|
mSearchInputType = in.readInt();
|
||||||
mSearchImeOptions = in.readInt();
|
mSearchImeOptions = in.readInt();
|
||||||
|
mIncludeInGlobalSearch = in.readInt() != 0;
|
||||||
setSearchModeFlags();
|
setSearchModeFlags();
|
||||||
|
|
||||||
mSuggestAuthority = in.readString();
|
mSuggestAuthority = in.readString();
|
||||||
@ -644,6 +658,7 @@ public final class SearchableInfo implements Parcelable {
|
|||||||
dest.writeInt(mSearchButtonText);
|
dest.writeInt(mSearchButtonText);
|
||||||
dest.writeInt(mSearchInputType);
|
dest.writeInt(mSearchInputType);
|
||||||
dest.writeInt(mSearchImeOptions);
|
dest.writeInt(mSearchImeOptions);
|
||||||
|
dest.writeInt(mIncludeInGlobalSearch ? 1 : 0);
|
||||||
|
|
||||||
dest.writeString(mSuggestAuthority);
|
dest.writeString(mSuggestAuthority);
|
||||||
dest.writeString(mSuggestPath);
|
dest.writeString(mSuggestPath);
|
||||||
|
@ -44,6 +44,7 @@ public class Searchables {
|
|||||||
|
|
||||||
private HashMap<ComponentName, SearchableInfo> mSearchablesMap = null;
|
private HashMap<ComponentName, SearchableInfo> mSearchablesMap = null;
|
||||||
private ArrayList<SearchableInfo> mSearchablesList = null;
|
private ArrayList<SearchableInfo> mSearchablesList = null;
|
||||||
|
private ArrayList<SearchableInfo> mSearchablesInGlobalSearchList = null;
|
||||||
private SearchableInfo mDefaultSearchable = null;
|
private SearchableInfo mDefaultSearchable = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -189,6 +190,8 @@ public class Searchables {
|
|||||||
= new HashMap<ComponentName, SearchableInfo>();
|
= new HashMap<ComponentName, SearchableInfo>();
|
||||||
ArrayList<SearchableInfo> newSearchablesList
|
ArrayList<SearchableInfo> newSearchablesList
|
||||||
= new ArrayList<SearchableInfo>();
|
= new ArrayList<SearchableInfo>();
|
||||||
|
ArrayList<SearchableInfo> newSearchablesInGlobalSearchList
|
||||||
|
= new ArrayList<SearchableInfo>();
|
||||||
|
|
||||||
final PackageManager pm = mContext.getPackageManager();
|
final PackageManager pm = mContext.getPackageManager();
|
||||||
|
|
||||||
@ -208,6 +211,9 @@ public class Searchables {
|
|||||||
if (searchable != null) {
|
if (searchable != null) {
|
||||||
newSearchablesList.add(searchable);
|
newSearchablesList.add(searchable);
|
||||||
newSearchablesMap.put(searchable.mSearchActivity, 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
|
// Store a consistent set of new values
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
mSearchablesList = newSearchablesList;
|
|
||||||
mSearchablesMap = newSearchablesMap;
|
mSearchablesMap = newSearchablesMap;
|
||||||
|
mSearchablesList = newSearchablesList;
|
||||||
|
mSearchablesInGlobalSearchList = newSearchablesInGlobalSearchList;
|
||||||
mDefaultSearchable = newDefaultSearchable;
|
mDefaultSearchable = newDefaultSearchable;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -232,4 +239,11 @@ public class Searchables {
|
|||||||
ArrayList<SearchableInfo> result = new ArrayList<SearchableInfo>(mSearchablesList);
|
ArrayList<SearchableInfo> result = new ArrayList<SearchableInfo>(mSearchablesList);
|
||||||
return result;
|
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> -->
|
search suggestions. The default value is 0. <i>Optional attribute.</i> -->
|
||||||
<attr name="searchSuggestThreshold" format="integer" />
|
<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>
|
</declare-styleable>
|
||||||
|
|
||||||
<!-- In order to process special action keys during search, you must define them using
|
<!-- 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();
|
int count = searchablesList.size();
|
||||||
assertTrue(count >= 1); // this isn't really a unit test
|
assertTrue(count >= 1); // this isn't really a unit test
|
||||||
checkSearchables(searchablesList);
|
checkSearchables(searchablesList);
|
||||||
|
ArrayList<SearchableInfo> global = searchables.getSearchablesInGlobalSearchList();
|
||||||
|
checkSearchables(global);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -166,10 +168,10 @@ public class SearchablesTest extends AndroidTestCase {
|
|||||||
Searchables searchables = new Searchables(mockContext);
|
Searchables searchables = new Searchables(mockContext);
|
||||||
searchables.buildSearchableList();
|
searchables.buildSearchableList();
|
||||||
ArrayList<SearchableInfo> searchablesList = searchables.getSearchablesList();
|
ArrayList<SearchableInfo> searchablesList = searchables.getSearchablesList();
|
||||||
if (searchablesList != null) {
|
assertNotNull(searchablesList);
|
||||||
int count = searchablesList.size();
|
MoreAsserts.assertEmpty(searchablesList);
|
||||||
assertTrue(count == 0);
|
ArrayList<SearchableInfo> global = searchables.getSearchablesInGlobalSearchList();
|
||||||
}
|
MoreAsserts.assertEmpty(global);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user