|
34 | 34 | import android.text.TextUtils; |
35 | 35 | import android.util.Log; |
36 | 36 |
|
| 37 | +import java.io.FileDescriptor; |
| 38 | +import java.io.PrintWriter; |
37 | 39 | import java.util.ArrayList; |
38 | 40 | import java.util.Collections; |
39 | 41 | import java.util.Comparator; |
@@ -210,59 +212,64 @@ public void buildSearchableList() { |
210 | 212 | // Use intent resolver to generate list of ACTION_SEARCH & ACTION_WEB_SEARCH receivers. |
211 | 213 | List<ResolveInfo> searchList; |
212 | 214 | final Intent intent = new Intent(Intent.ACTION_SEARCH); |
213 | | - |
214 | | - searchList = queryIntentActivities(intent, PackageManager.GET_META_DATA); |
215 | | - |
216 | | - List<ResolveInfo> webSearchInfoList; |
217 | | - final Intent webSearchIntent = new Intent(Intent.ACTION_WEB_SEARCH); |
218 | | - webSearchInfoList = queryIntentActivities(webSearchIntent, PackageManager.GET_META_DATA); |
219 | | - |
220 | | - // analyze each one, generate a Searchables record, and record |
221 | | - if (searchList != null || webSearchInfoList != null) { |
222 | | - int search_count = (searchList == null ? 0 : searchList.size()); |
223 | | - int web_search_count = (webSearchInfoList == null ? 0 : webSearchInfoList.size()); |
224 | | - int count = search_count + web_search_count; |
225 | | - long token = Binder.clearCallingIdentity(); |
226 | | - for (int ii = 0; ii < count; ii++) { |
227 | | - // for each component, try to find metadata |
228 | | - ResolveInfo info = (ii < search_count) |
229 | | - ? searchList.get(ii) |
230 | | - : webSearchInfoList.get(ii - search_count); |
231 | | - ActivityInfo ai = info.activityInfo; |
232 | | - // Check first to avoid duplicate entries. |
233 | | - if (newSearchablesMap.get(new ComponentName(ai.packageName, ai.name)) == null) { |
234 | | - SearchableInfo searchable = SearchableInfo.getActivityMetaData(mContext, ai); |
235 | | - if (searchable != null) { |
236 | | - newSearchablesList.add(searchable); |
237 | | - newSearchablesMap.put(searchable.getSearchActivity(), searchable); |
238 | | - if (searchable.shouldIncludeInGlobalSearch()) { |
239 | | - newSearchablesInGlobalSearchList.add(searchable); |
| 215 | + |
| 216 | + long ident = Binder.clearCallingIdentity(); |
| 217 | + try { |
| 218 | + searchList = queryIntentActivities(intent, PackageManager.GET_META_DATA); |
| 219 | + |
| 220 | + List<ResolveInfo> webSearchInfoList; |
| 221 | + final Intent webSearchIntent = new Intent(Intent.ACTION_WEB_SEARCH); |
| 222 | + webSearchInfoList = queryIntentActivities(webSearchIntent, PackageManager.GET_META_DATA); |
| 223 | + |
| 224 | + // analyze each one, generate a Searchables record, and record |
| 225 | + if (searchList != null || webSearchInfoList != null) { |
| 226 | + int search_count = (searchList == null ? 0 : searchList.size()); |
| 227 | + int web_search_count = (webSearchInfoList == null ? 0 : webSearchInfoList.size()); |
| 228 | + int count = search_count + web_search_count; |
| 229 | + for (int ii = 0; ii < count; ii++) { |
| 230 | + // for each component, try to find metadata |
| 231 | + ResolveInfo info = (ii < search_count) |
| 232 | + ? searchList.get(ii) |
| 233 | + : webSearchInfoList.get(ii - search_count); |
| 234 | + ActivityInfo ai = info.activityInfo; |
| 235 | + // Check first to avoid duplicate entries. |
| 236 | + if (newSearchablesMap.get(new ComponentName(ai.packageName, ai.name)) == null) { |
| 237 | + SearchableInfo searchable = SearchableInfo.getActivityMetaData(mContext, ai, |
| 238 | + mUserId); |
| 239 | + if (searchable != null) { |
| 240 | + newSearchablesList.add(searchable); |
| 241 | + newSearchablesMap.put(searchable.getSearchActivity(), searchable); |
| 242 | + if (searchable.shouldIncludeInGlobalSearch()) { |
| 243 | + newSearchablesInGlobalSearchList.add(searchable); |
| 244 | + } |
240 | 245 | } |
241 | 246 | } |
242 | 247 | } |
243 | 248 | } |
244 | | - Binder.restoreCallingIdentity(token); |
245 | | - } |
246 | 249 |
|
247 | | - List<ResolveInfo> newGlobalSearchActivities = findGlobalSearchActivities(); |
| 250 | + List<ResolveInfo> newGlobalSearchActivities = findGlobalSearchActivities(); |
248 | 251 |
|
249 | | - // Find the global search activity |
250 | | - ComponentName newGlobalSearchActivity = findGlobalSearchActivity( |
251 | | - newGlobalSearchActivities); |
| 252 | + // Find the global search activity |
| 253 | + ComponentName newGlobalSearchActivity = findGlobalSearchActivity( |
| 254 | + newGlobalSearchActivities); |
252 | 255 |
|
253 | | - // Find the web search activity |
254 | | - ComponentName newWebSearchActivity = findWebSearchActivity(newGlobalSearchActivity); |
| 256 | + // Find the web search activity |
| 257 | + ComponentName newWebSearchActivity = findWebSearchActivity(newGlobalSearchActivity); |
255 | 258 |
|
256 | | - // Store a consistent set of new values |
257 | | - synchronized (this) { |
258 | | - mSearchablesMap = newSearchablesMap; |
259 | | - mSearchablesList = newSearchablesList; |
260 | | - mSearchablesInGlobalSearchList = newSearchablesInGlobalSearchList; |
261 | | - mGlobalSearchActivities = newGlobalSearchActivities; |
262 | | - mCurrentGlobalSearchActivity = newGlobalSearchActivity; |
263 | | - mWebSearchActivity = newWebSearchActivity; |
| 259 | + // Store a consistent set of new values |
| 260 | + synchronized (this) { |
| 261 | + mSearchablesMap = newSearchablesMap; |
| 262 | + mSearchablesList = newSearchablesList; |
| 263 | + mSearchablesInGlobalSearchList = newSearchablesInGlobalSearchList; |
| 264 | + mGlobalSearchActivities = newGlobalSearchActivities; |
| 265 | + mCurrentGlobalSearchActivity = newGlobalSearchActivity; |
| 266 | + mWebSearchActivity = newWebSearchActivity; |
| 267 | + } |
| 268 | + } finally { |
| 269 | + Binder.restoreCallingIdentity(ident); |
264 | 270 | } |
265 | 271 | } |
| 272 | + |
266 | 273 | /** |
267 | 274 | * Returns a sorted list of installed search providers as per |
268 | 275 | * the following heuristics: |
@@ -443,4 +450,15 @@ public synchronized ComponentName getGlobalSearchActivity() { |
443 | 450 | public synchronized ComponentName getWebSearchActivity() { |
444 | 451 | return mWebSearchActivity; |
445 | 452 | } |
| 453 | + |
| 454 | + void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 455 | + pw.println("Searchable authorities:"); |
| 456 | + synchronized (this) { |
| 457 | + if (mSearchablesList != null) { |
| 458 | + for (SearchableInfo info: mSearchablesList) { |
| 459 | + pw.print(" "); pw.println(info.getSuggestAuthority()); |
| 460 | + } |
| 461 | + } |
| 462 | + } |
| 463 | + } |
446 | 464 | } |
0 commit comments