The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Jeff Sharkey | 7a96c39 | 2012-11-15 14:01:46 -0800 | [diff] [blame] | 17 | package com.android.server.search; |
Bjorn Bringert | ab5d96c | 2010-02-23 22:48:46 +0000 | [diff] [blame] | 18 | |
Amith Yamasani | c1d07a4 | 2012-08-14 09:32:02 -0700 | [diff] [blame] | 19 | import android.app.ActivityManager; |
Dianne Hackborn | fdf5b35 | 2014-10-08 17:43:48 -0700 | [diff] [blame] | 20 | import android.app.ActivityManagerNative; |
Amith Yamasani | c1d07a4 | 2012-08-14 09:32:02 -0700 | [diff] [blame] | 21 | import android.app.AppGlobals; |
Dianne Hackborn | fdf5b35 | 2014-10-08 17:43:48 -0700 | [diff] [blame] | 22 | import android.app.IActivityManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 23 | import android.app.ISearchManager; |
Bjorn Bringert | 8d17f3f | 2009-06-05 13:22:28 +0100 | [diff] [blame] | 24 | import android.app.SearchManager; |
Bjorn Bringert | 2126aac | 2009-12-03 15:48:19 +0000 | [diff] [blame] | 25 | import android.app.SearchableInfo; |
Bjorn Bringert | 2c7b197 | 2010-05-04 20:44:16 +0100 | [diff] [blame] | 26 | import android.content.BroadcastReceiver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | import android.content.ComponentName; |
Narayan Kamath | ee69ff4 | 2011-06-28 12:07:18 +0100 | [diff] [blame] | 28 | import android.content.ContentResolver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | import android.content.Context; |
| 30 | import android.content.Intent; |
Bjorn Bringert | 2c7b197 | 2010-05-04 20:44:16 +0100 | [diff] [blame] | 31 | import android.content.IntentFilter; |
Amith Yamasani | c1d07a4 | 2012-08-14 09:32:02 -0700 | [diff] [blame] | 32 | import android.content.pm.IPackageManager; |
| 33 | import android.content.pm.PackageManager; |
Narayan Kamath | ee69ff4 | 2011-06-28 12:07:18 +0100 | [diff] [blame] | 34 | import android.content.pm.ResolveInfo; |
| 35 | import android.database.ContentObserver; |
Amith Yamasani | 5bb87cd | 2012-06-14 11:32:13 -0700 | [diff] [blame] | 36 | import android.os.Binder; |
Tim Kilbourn | 0e5f110 | 2015-06-05 16:18:09 -0700 | [diff] [blame] | 37 | import android.os.Bundle; |
Bjorn Bringert | 2c7b197 | 2010-05-04 20:44:16 +0100 | [diff] [blame] | 38 | import android.os.Process; |
Amith Yamasani | c1d07a4 | 2012-08-14 09:32:02 -0700 | [diff] [blame] | 39 | import android.os.RemoteException; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 40 | import android.os.UserHandle; |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 41 | import android.os.UserManager; |
Narayan Kamath | ee69ff4 | 2011-06-28 12:07:18 +0100 | [diff] [blame] | 42 | import android.provider.Settings; |
Bjorn Bringert | 8d17f3f | 2009-06-05 13:22:28 +0100 | [diff] [blame] | 43 | import android.util.Log; |
Amith Yamasani | 5bb87cd | 2012-06-14 11:32:13 -0700 | [diff] [blame] | 44 | import android.util.SparseArray; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | |
Jeff Sharkey | 7a96c39 | 2012-11-15 14:01:46 -0800 | [diff] [blame] | 46 | import com.android.internal.content.PackageMonitor; |
| 47 | import com.android.internal.util.IndentingPrintWriter; |
Jorim Jaggi | 165ce06 | 2015-07-06 16:18:11 -0700 | [diff] [blame] | 48 | import com.android.server.LocalServices; |
| 49 | import com.android.server.statusbar.StatusBarManagerInternal; |
Jeff Sharkey | 7a96c39 | 2012-11-15 14:01:46 -0800 | [diff] [blame] | 50 | |
Amith Yamasani | 64442c1 | 2012-10-07 08:17:46 -0700 | [diff] [blame] | 51 | import java.io.FileDescriptor; |
| 52 | import java.io.PrintWriter; |
Bjorn Bringert | 6d72e02 | 2009-04-29 14:56:12 +0100 | [diff] [blame] | 53 | import java.util.List; |
| 54 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | /** |
Bjorn Bringert | 444c727 | 2009-07-06 21:32:50 +0100 | [diff] [blame] | 56 | * The search manager service handles the search UI, and maintains a registry of searchable |
| 57 | * activities. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 58 | */ |
Bjorn Bringert | 444c727 | 2009-07-06 21:32:50 +0100 | [diff] [blame] | 59 | public class SearchManagerService extends ISearchManager.Stub { |
| 60 | |
| 61 | // general debugging support |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | private static final String TAG = "SearchManagerService"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 63 | |
Bjorn Bringert | 444c727 | 2009-07-06 21:32:50 +0100 | [diff] [blame] | 64 | // Context that the service is running in. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | private final Context mContext; |
Bjorn Bringert | 8d17f3f | 2009-06-05 13:22:28 +0100 | [diff] [blame] | 66 | |
Bjorn Bringert | ab5d96c | 2010-02-23 22:48:46 +0000 | [diff] [blame] | 67 | // This field is initialized lazily in getSearchables(), and then never modified. |
Amith Yamasani | 64442c1 | 2012-10-07 08:17:46 -0700 | [diff] [blame] | 68 | private final SparseArray<Searchables> mSearchables = new SparseArray<Searchables>(); |
Narayan Kamath | ee69ff4 | 2011-06-28 12:07:18 +0100 | [diff] [blame] | 69 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 70 | /** |
Karl Rosaen | 875d50a | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 71 | * Initializes the Search Manager service in the provided system context. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 72 | * Only one instance of this object should be created! |
| 73 | * |
| 74 | * @param context to use for accessing DB, window manager, etc. |
| 75 | */ |
Satish Sampath | f9acde2 | 2009-06-04 11:51:17 +0100 | [diff] [blame] | 76 | public SearchManagerService(Context context) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 77 | mContext = context; |
Dianne Hackborn | d83a096 | 2014-05-02 16:28:33 -0700 | [diff] [blame] | 78 | IntentFilter filter = new IntentFilter(Intent.ACTION_BOOT_COMPLETED); |
| 79 | filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY); |
| 80 | mContext.registerReceiver(new BootCompletedReceiver(), filter); |
Amith Yamasani | e668794 | 2012-10-29 14:29:05 -0700 | [diff] [blame] | 81 | mContext.registerReceiver(new UserReceiver(), |
Amith Yamasani | 64442c1 | 2012-10-07 08:17:46 -0700 | [diff] [blame] | 82 | new IntentFilter(Intent.ACTION_USER_REMOVED)); |
| 83 | new MyPackageMonitor().register(context, null, UserHandle.ALL, true); |
Bjorn Bringert | 444c727 | 2009-07-06 21:32:50 +0100 | [diff] [blame] | 84 | } |
| 85 | |
Amith Yamasani | 64442c1 | 2012-10-07 08:17:46 -0700 | [diff] [blame] | 86 | private Searchables getSearchables(int userId) { |
Amith Yamasani | 5bb87cd | 2012-06-14 11:32:13 -0700 | [diff] [blame] | 87 | long origId = Binder.clearCallingIdentity(); |
Amith Yamasani | 64442c1 | 2012-10-07 08:17:46 -0700 | [diff] [blame] | 88 | try { |
| 89 | boolean userExists = ((UserManager) mContext.getSystemService(Context.USER_SERVICE)) |
| 90 | .getUserInfo(userId) != null; |
| 91 | if (!userExists) return null; |
| 92 | } finally { |
| 93 | Binder.restoreCallingIdentity(origId); |
Amith Yamasani | 5bb87cd | 2012-06-14 11:32:13 -0700 | [diff] [blame] | 94 | } |
Amith Yamasani | 64442c1 | 2012-10-07 08:17:46 -0700 | [diff] [blame] | 95 | synchronized (mSearchables) { |
| 96 | Searchables searchables = mSearchables.get(userId); |
| 97 | |
| 98 | if (searchables == null) { |
Dianne Hackborn | 40e9f29 | 2012-11-27 19:12:23 -0800 | [diff] [blame] | 99 | //Log.i(TAG, "Building list of searchable activities for userId=" + userId); |
Amith Yamasani | 64442c1 | 2012-10-07 08:17:46 -0700 | [diff] [blame] | 100 | searchables = new Searchables(mContext, userId); |
| 101 | searchables.buildSearchableList(); |
| 102 | mSearchables.append(userId, searchables); |
| 103 | } |
| 104 | return searchables; |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | private void onUserRemoved(int userId) { |
| 109 | if (userId != UserHandle.USER_OWNER) { |
| 110 | synchronized (mSearchables) { |
| 111 | mSearchables.remove(userId); |
| 112 | } |
| 113 | } |
Bjorn Bringert | 9bc75cb | 2009-07-13 13:17:27 +0100 | [diff] [blame] | 114 | } |
| 115 | |
Bjorn Bringert | 444c727 | 2009-07-06 21:32:50 +0100 | [diff] [blame] | 116 | /** |
Bjorn Bringert | 2c7b197 | 2010-05-04 20:44:16 +0100 | [diff] [blame] | 117 | * Creates the initial searchables list after boot. |
| 118 | */ |
| 119 | private final class BootCompletedReceiver extends BroadcastReceiver { |
| 120 | @Override |
| 121 | public void onReceive(Context context, Intent intent) { |
| 122 | new Thread() { |
| 123 | @Override |
| 124 | public void run() { |
| 125 | Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); |
| 126 | mContext.unregisterReceiver(BootCompletedReceiver.this); |
Amith Yamasani | 5bb87cd | 2012-06-14 11:32:13 -0700 | [diff] [blame] | 127 | getSearchables(0); |
Bjorn Bringert | 2c7b197 | 2010-05-04 20:44:16 +0100 | [diff] [blame] | 128 | } |
| 129 | }.start(); |
| 130 | } |
| 131 | } |
| 132 | |
Amith Yamasani | 64442c1 | 2012-10-07 08:17:46 -0700 | [diff] [blame] | 133 | private final class UserReceiver extends BroadcastReceiver { |
| 134 | @Override |
| 135 | public void onReceive(Context context, Intent intent) { |
| 136 | onUserRemoved(intent.getIntExtra(Intent.EXTRA_USER_HANDLE, UserHandle.USER_OWNER)); |
| 137 | } |
| 138 | } |
| 139 | |
Bjorn Bringert | 2c7b197 | 2010-05-04 20:44:16 +0100 | [diff] [blame] | 140 | /** |
Bjorn Bringert | 444c727 | 2009-07-06 21:32:50 +0100 | [diff] [blame] | 141 | * Refreshes the "searchables" list when packages are added/removed. |
| 142 | */ |
Bjorn Bringert | ab5d96c | 2010-02-23 22:48:46 +0000 | [diff] [blame] | 143 | class MyPackageMonitor extends PackageMonitor { |
Amith Yamasani | 13bc602 | 2011-08-23 12:11:35 -0700 | [diff] [blame] | 144 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 145 | @Override |
Bjorn Bringert | ab5d96c | 2010-02-23 22:48:46 +0000 | [diff] [blame] | 146 | public void onSomePackagesChanged() { |
Amith Yamasani | 13bc602 | 2011-08-23 12:11:35 -0700 | [diff] [blame] | 147 | updateSearchables(); |
| 148 | } |
| 149 | |
| 150 | @Override |
| 151 | public void onPackageModified(String pkg) { |
| 152 | updateSearchables(); |
| 153 | } |
| 154 | |
| 155 | private void updateSearchables() { |
Amith Yamasani | 64442c1 | 2012-10-07 08:17:46 -0700 | [diff] [blame] | 156 | final int changingUserId = getChangingUserId(); |
| 157 | synchronized (mSearchables) { |
Amith Yamasani | 5bb87cd | 2012-06-14 11:32:13 -0700 | [diff] [blame] | 158 | // Update list of searchable activities |
| 159 | for (int i = 0; i < mSearchables.size(); i++) { |
Amith Yamasani | 64442c1 | 2012-10-07 08:17:46 -0700 | [diff] [blame] | 160 | if (changingUserId == mSearchables.keyAt(i)) { |
| 161 | getSearchables(mSearchables.keyAt(i)).buildSearchableList(); |
| 162 | break; |
| 163 | } |
Amith Yamasani | 5bb87cd | 2012-06-14 11:32:13 -0700 | [diff] [blame] | 164 | } |
| 165 | } |
Bjorn Bringert | ab5d96c | 2010-02-23 22:48:46 +0000 | [diff] [blame] | 166 | // Inform all listeners that the list of searchables has been updated. |
| 167 | Intent intent = new Intent(SearchManager.INTENT_ACTION_SEARCHABLES_CHANGED); |
Amith Yamasani | e668794 | 2012-10-29 14:29:05 -0700 | [diff] [blame] | 168 | intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING |
| 169 | | Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); |
Amith Yamasani | 64442c1 | 2012-10-07 08:17:46 -0700 | [diff] [blame] | 170 | mContext.sendBroadcastAsUser(intent, new UserHandle(changingUserId)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 171 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 172 | } |
| 173 | |
Narayan Kamath | ee69ff4 | 2011-06-28 12:07:18 +0100 | [diff] [blame] | 174 | class GlobalSearchProviderObserver extends ContentObserver { |
| 175 | private final ContentResolver mResolver; |
| 176 | |
| 177 | public GlobalSearchProviderObserver(ContentResolver resolver) { |
| 178 | super(null); |
| 179 | mResolver = resolver; |
| 180 | mResolver.registerContentObserver( |
| 181 | Settings.Secure.getUriFor(Settings.Secure.SEARCH_GLOBAL_SEARCH_ACTIVITY), |
| 182 | false /* notifyDescendants */, |
| 183 | this); |
| 184 | } |
| 185 | |
| 186 | @Override |
| 187 | public void onChange(boolean selfChange) { |
Amith Yamasani | 64442c1 | 2012-10-07 08:17:46 -0700 | [diff] [blame] | 188 | synchronized (mSearchables) { |
Amith Yamasani | 5bb87cd | 2012-06-14 11:32:13 -0700 | [diff] [blame] | 189 | for (int i = 0; i < mSearchables.size(); i++) { |
| 190 | getSearchables(mSearchables.keyAt(i)).buildSearchableList(); |
| 191 | } |
| 192 | } |
Narayan Kamath | ee69ff4 | 2011-06-28 12:07:18 +0100 | [diff] [blame] | 193 | Intent intent = new Intent(SearchManager.INTENT_GLOBAL_SEARCH_ACTIVITY_CHANGED); |
| 194 | intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 195 | mContext.sendBroadcastAsUser(intent, UserHandle.ALL); |
Narayan Kamath | ee69ff4 | 2011-06-28 12:07:18 +0100 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | } |
| 199 | |
Bjorn Bringert | 444c727 | 2009-07-06 21:32:50 +0100 | [diff] [blame] | 200 | // |
| 201 | // Searchable activities API |
| 202 | // |
Bjorn Bringert | a48a5af | 2009-05-20 17:58:39 +0100 | [diff] [blame] | 203 | |
| 204 | /** |
Bjorn Bringert | 444c727 | 2009-07-06 21:32:50 +0100 | [diff] [blame] | 205 | * Returns the SearchableInfo for a given activity. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 206 | * |
| 207 | * @param launchActivity The activity from which we're launching this search. |
Karl Rosaen | 875d50a | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 208 | * @return Returns a SearchableInfo record describing the parameters of the search, |
| 209 | * or null if no searchable metadata was available. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 210 | */ |
Bjorn Bringert | 6cf7a32 | 2010-02-23 13:17:06 +0000 | [diff] [blame] | 211 | public SearchableInfo getSearchableInfo(final ComponentName launchActivity) { |
| 212 | if (launchActivity == null) { |
| 213 | Log.e(TAG, "getSearchableInfo(), activity == null"); |
| 214 | return null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 215 | } |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 216 | return getSearchables(UserHandle.getCallingUserId()).getSearchableInfo(launchActivity); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 217 | } |
Satish Sampath | f9acde2 | 2009-06-04 11:51:17 +0100 | [diff] [blame] | 218 | |
Bjorn Bringert | 6d72e02 | 2009-04-29 14:56:12 +0100 | [diff] [blame] | 219 | /** |
| 220 | * Returns a list of the searchable activities that can be included in global search. |
| 221 | */ |
| 222 | public List<SearchableInfo> getSearchablesInGlobalSearch() { |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 223 | return getSearchables(UserHandle.getCallingUserId()).getSearchablesInGlobalSearchList(); |
Bjorn Bringert | 6d72e02 | 2009-04-29 14:56:12 +0100 | [diff] [blame] | 224 | } |
Bjorn Bringert | 8d17f3f | 2009-06-05 13:22:28 +0100 | [diff] [blame] | 225 | |
Narayan Kamath | ee69ff4 | 2011-06-28 12:07:18 +0100 | [diff] [blame] | 226 | public List<ResolveInfo> getGlobalSearchActivities() { |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 227 | return getSearchables(UserHandle.getCallingUserId()).getGlobalSearchActivities(); |
Narayan Kamath | ee69ff4 | 2011-06-28 12:07:18 +0100 | [diff] [blame] | 228 | } |
| 229 | |
Bjorn Bringert | 8d17f3f | 2009-06-05 13:22:28 +0100 | [diff] [blame] | 230 | /** |
Bjorn Bringert | 6cf7a32 | 2010-02-23 13:17:06 +0000 | [diff] [blame] | 231 | * Gets the name of the global search activity. |
Bjorn Bringert | 8d17f3f | 2009-06-05 13:22:28 +0100 | [diff] [blame] | 232 | */ |
Bjorn Bringert | 6cf7a32 | 2010-02-23 13:17:06 +0000 | [diff] [blame] | 233 | public ComponentName getGlobalSearchActivity() { |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 234 | return getSearchables(UserHandle.getCallingUserId()).getGlobalSearchActivity(); |
Bjorn Bringert | 444c727 | 2009-07-06 21:32:50 +0100 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | /** |
Bjorn Bringert | 6cf7a32 | 2010-02-23 13:17:06 +0000 | [diff] [blame] | 238 | * Gets the name of the web search activity. |
Bjorn Bringert | 444c727 | 2009-07-06 21:32:50 +0100 | [diff] [blame] | 239 | */ |
Bjorn Bringert | 6cf7a32 | 2010-02-23 13:17:06 +0000 | [diff] [blame] | 240 | public ComponentName getWebSearchActivity() { |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 241 | return getSearchables(UserHandle.getCallingUserId()).getWebSearchActivity(); |
Bjorn Bringert | 444c727 | 2009-07-06 21:32:50 +0100 | [diff] [blame] | 242 | } |
| 243 | |
Amith Yamasani | c1d07a4 | 2012-08-14 09:32:02 -0700 | [diff] [blame] | 244 | @Override |
Jorim Jaggi | 165ce06 | 2015-07-06 16:18:11 -0700 | [diff] [blame] | 245 | public void launchAssist(Bundle args) { |
| 246 | StatusBarManagerInternal statusBarManager = |
| 247 | LocalServices.getService(StatusBarManagerInternal.class); |
| 248 | if (statusBarManager != null) { |
| 249 | statusBarManager.startAssist(args); |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | private ComponentName getLegacyAssistComponent(int userHandle) { |
Amith Yamasani | c1d07a4 | 2012-08-14 09:32:02 -0700 | [diff] [blame] | 254 | try { |
Ben Pietrzak | 05cb363 | 2012-12-12 11:31:57 -0800 | [diff] [blame] | 255 | userHandle = ActivityManager.handleIncomingUser(Binder.getCallingPid(), |
Jorim Jaggi | 165ce06 | 2015-07-06 16:18:11 -0700 | [diff] [blame] | 256 | Binder.getCallingUid(), userHandle, true, false, "getLegacyAssistComponent", null); |
Amith Yamasani | c1d07a4 | 2012-08-14 09:32:02 -0700 | [diff] [blame] | 257 | IPackageManager pm = AppGlobals.getPackageManager(); |
| 258 | Intent assistIntent = new Intent(Intent.ACTION_ASSIST); |
| 259 | ResolveInfo info = |
| 260 | pm.resolveIntent(assistIntent, |
Jorim Jaggi | 165ce06 | 2015-07-06 16:18:11 -0700 | [diff] [blame] | 261 | assistIntent.resolveTypeIfNeeded(mContext.getContentResolver()), |
| 262 | PackageManager.MATCH_DEFAULT_ONLY, userHandle); |
Amith Yamasani | c1d07a4 | 2012-08-14 09:32:02 -0700 | [diff] [blame] | 263 | if (info != null) { |
| 264 | return new ComponentName( |
| 265 | info.activityInfo.applicationInfo.packageName, |
| 266 | info.activityInfo.name); |
| 267 | } |
| 268 | } catch (RemoteException re) { |
| 269 | // Local call |
Jorim Jaggi | 165ce06 | 2015-07-06 16:18:11 -0700 | [diff] [blame] | 270 | Log.e(TAG, "RemoteException in getLegacyAssistComponent: " + re); |
Amith Yamasani | c1d07a4 | 2012-08-14 09:32:02 -0700 | [diff] [blame] | 271 | } catch (Exception e) { |
Jorim Jaggi | 165ce06 | 2015-07-06 16:18:11 -0700 | [diff] [blame] | 272 | Log.e(TAG, "Exception in getLegacyAssistComponent: " + e); |
Amith Yamasani | c1d07a4 | 2012-08-14 09:32:02 -0700 | [diff] [blame] | 273 | } |
| 274 | return null; |
| 275 | } |
Amith Yamasani | 64442c1 | 2012-10-07 08:17:46 -0700 | [diff] [blame] | 276 | |
| 277 | @Override |
Jorim Jaggi | 165ce06 | 2015-07-06 16:18:11 -0700 | [diff] [blame] | 278 | public boolean launchLegacyAssist(String hint, int userHandle, Bundle args) { |
| 279 | ComponentName comp = getLegacyAssistComponent(userHandle); |
Dianne Hackborn | fdf5b35 | 2014-10-08 17:43:48 -0700 | [diff] [blame] | 280 | if (comp == null) { |
| 281 | return false; |
| 282 | } |
| 283 | long ident = Binder.clearCallingIdentity(); |
| 284 | try { |
| 285 | Intent intent = new Intent(Intent.ACTION_ASSIST); |
| 286 | intent.setComponent(comp); |
| 287 | IActivityManager am = ActivityManagerNative.getDefault(); |
Dianne Hackborn | a83ce1d | 2015-03-11 15:16:13 -0700 | [diff] [blame] | 288 | return am.launchAssistIntent(intent, ActivityManager.ASSIST_CONTEXT_BASIC, hint, |
Tim Kilbourn | 0e5f110 | 2015-06-05 16:18:09 -0700 | [diff] [blame] | 289 | userHandle, args); |
Dianne Hackborn | fdf5b35 | 2014-10-08 17:43:48 -0700 | [diff] [blame] | 290 | } catch (RemoteException e) { |
| 291 | } finally { |
| 292 | Binder.restoreCallingIdentity(ident); |
| 293 | } |
| 294 | return true; |
| 295 | } |
| 296 | |
| 297 | @Override |
Amith Yamasani | 64442c1 | 2012-10-07 08:17:46 -0700 | [diff] [blame] | 298 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
Jeff Sharkey | 52801aa | 2012-10-12 16:06:16 -0700 | [diff] [blame] | 299 | mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DUMP, TAG); |
| 300 | |
Amith Yamasani | 64442c1 | 2012-10-07 08:17:46 -0700 | [diff] [blame] | 301 | IndentingPrintWriter ipw = new IndentingPrintWriter(pw, " "); |
| 302 | synchronized (mSearchables) { |
| 303 | for (int i = 0; i < mSearchables.size(); i++) { |
| 304 | ipw.print("\nUser: "); ipw.println(mSearchables.keyAt(i)); |
| 305 | ipw.increaseIndent(); |
| 306 | mSearchables.valueAt(i).dump(fd, ipw, args); |
| 307 | ipw.decreaseIndent(); |
| 308 | } |
| 309 | } |
| 310 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 311 | } |