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; |
Amith Yamasani | c1d07a4 | 2012-08-14 09:32:02 -0700 | [diff] [blame] | 20 | import android.app.AppGlobals; |
Dianne Hackborn | fdf5b35 | 2014-10-08 17:43:48 -0700 | [diff] [blame] | 21 | import android.app.IActivityManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 | import android.app.ISearchManager; |
Bjorn Bringert | 8d17f3f | 2009-06-05 13:22:28 +0100 | [diff] [blame] | 23 | import android.app.SearchManager; |
Bjorn Bringert | 2126aac | 2009-12-03 15:48:19 +0000 | [diff] [blame] | 24 | import android.app.SearchableInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | import android.content.ComponentName; |
Narayan Kamath | ee69ff4 | 2011-06-28 12:07:18 +0100 | [diff] [blame] | 26 | import android.content.ContentResolver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | import android.content.Context; |
| 28 | import android.content.Intent; |
Amith Yamasani | c1d07a4 | 2012-08-14 09:32:02 -0700 | [diff] [blame] | 29 | import android.content.pm.IPackageManager; |
| 30 | import android.content.pm.PackageManager; |
Narayan Kamath | ee69ff4 | 2011-06-28 12:07:18 +0100 | [diff] [blame] | 31 | import android.content.pm.ResolveInfo; |
| 32 | import android.database.ContentObserver; |
Amith Yamasani | 5bb87cd | 2012-06-14 11:32:13 -0700 | [diff] [blame] | 33 | import android.os.Binder; |
Tim Kilbourn | 0e5f110 | 2015-06-05 16:18:09 -0700 | [diff] [blame] | 34 | import android.os.Bundle; |
Fyodor Kupolov | 7877b8a | 2016-06-29 14:39:19 -0700 | [diff] [blame] | 35 | import android.os.Handler; |
Amith Yamasani | c1d07a4 | 2012-08-14 09:32:02 -0700 | [diff] [blame] | 36 | import android.os.RemoteException; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 37 | import android.os.UserHandle; |
Amith Yamasani | 258848d | 2012-08-10 17:06:33 -0700 | [diff] [blame] | 38 | import android.os.UserManager; |
Narayan Kamath | ee69ff4 | 2011-06-28 12:07:18 +0100 | [diff] [blame] | 39 | import android.provider.Settings; |
Bjorn Bringert | 8d17f3f | 2009-06-05 13:22:28 +0100 | [diff] [blame] | 40 | import android.util.Log; |
Amith Yamasani | 5bb87cd | 2012-06-14 11:32:13 -0700 | [diff] [blame] | 41 | import android.util.SparseArray; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | |
Jeff Sharkey | 4175be2 | 2016-01-09 14:57:45 -0700 | [diff] [blame] | 43 | import com.android.internal.annotations.GuardedBy; |
Jeff Sharkey | 7a96c39 | 2012-11-15 14:01:46 -0800 | [diff] [blame] | 44 | import com.android.internal.content.PackageMonitor; |
Fyodor Kupolov | 7877b8a | 2016-06-29 14:39:19 -0700 | [diff] [blame] | 45 | import com.android.internal.os.BackgroundThread; |
Jeff Sharkey | 7a96c39 | 2012-11-15 14:01:46 -0800 | [diff] [blame] | 46 | import com.android.internal.util.IndentingPrintWriter; |
Jorim Jaggi | 165ce06 | 2015-07-06 16:18:11 -0700 | [diff] [blame] | 47 | import com.android.server.LocalServices; |
Jeff Sharkey | 4175be2 | 2016-01-09 14:57:45 -0700 | [diff] [blame] | 48 | import com.android.server.SystemService; |
Jorim Jaggi | 165ce06 | 2015-07-06 16:18:11 -0700 | [diff] [blame] | 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 | /** |
Jeff Sharkey | 4175be2 | 2016-01-09 14:57:45 -0700 | [diff] [blame] | 56 | * The search manager service handles the search UI, and maintains a registry of |
| 57 | * searchable 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 { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 60 | private static final String TAG = "SearchManagerService"; |
Fyodor Kupolov | 7877b8a | 2016-06-29 14:39:19 -0700 | [diff] [blame] | 61 | final Handler mHandler; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | |
Jeff Sharkey | 4175be2 | 2016-01-09 14:57:45 -0700 | [diff] [blame] | 63 | public static class Lifecycle extends SystemService { |
| 64 | private SearchManagerService mService; |
| 65 | |
| 66 | public Lifecycle(Context context) { |
| 67 | super(context); |
| 68 | } |
| 69 | |
| 70 | @Override |
| 71 | public void onStart() { |
| 72 | mService = new SearchManagerService(getContext()); |
| 73 | publishBinderService(Context.SEARCH_SERVICE, mService); |
| 74 | } |
| 75 | |
| 76 | @Override |
Fyodor Kupolov | 7877b8a | 2016-06-29 14:39:19 -0700 | [diff] [blame] | 77 | public void onUnlockUser(final int userId) { |
| 78 | mService.mHandler.post(new Runnable() { |
| 79 | @Override |
| 80 | public void run() { |
| 81 | mService.onUnlockUser(userId); |
| 82 | } |
| 83 | }); |
Jeff Sharkey | 4175be2 | 2016-01-09 14:57:45 -0700 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | @Override |
| 87 | public void onCleanupUser(int userHandle) { |
| 88 | mService.onCleanupUser(userHandle); |
| 89 | } |
| 90 | } |
| 91 | |
Bjorn Bringert | 444c727 | 2009-07-06 21:32:50 +0100 | [diff] [blame] | 92 | // Context that the service is running in. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 93 | private final Context mContext; |
Bjorn Bringert | 8d17f3f | 2009-06-05 13:22:28 +0100 | [diff] [blame] | 94 | |
Bjorn Bringert | ab5d96c | 2010-02-23 22:48:46 +0000 | [diff] [blame] | 95 | // This field is initialized lazily in getSearchables(), and then never modified. |
Jeff Sharkey | 4175be2 | 2016-01-09 14:57:45 -0700 | [diff] [blame] | 96 | @GuardedBy("mSearchables") |
| 97 | private final SparseArray<Searchables> mSearchables = new SparseArray<>(); |
Narayan Kamath | ee69ff4 | 2011-06-28 12:07:18 +0100 | [diff] [blame] | 98 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 99 | /** |
Karl Rosaen | 875d50a | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 100 | * 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] | 101 | * Only one instance of this object should be created! |
| 102 | * |
| 103 | * @param context to use for accessing DB, window manager, etc. |
| 104 | */ |
Satish Sampath | f9acde2 | 2009-06-04 11:51:17 +0100 | [diff] [blame] | 105 | public SearchManagerService(Context context) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 106 | mContext = context; |
Amith Yamasani | 64442c1 | 2012-10-07 08:17:46 -0700 | [diff] [blame] | 107 | new MyPackageMonitor().register(context, null, UserHandle.ALL, true); |
Jeff Sharkey | 4175be2 | 2016-01-09 14:57:45 -0700 | [diff] [blame] | 108 | new GlobalSearchProviderObserver(context.getContentResolver()); |
Fyodor Kupolov | 7877b8a | 2016-06-29 14:39:19 -0700 | [diff] [blame] | 109 | mHandler = BackgroundThread.getHandler(); |
Bjorn Bringert | 444c727 | 2009-07-06 21:32:50 +0100 | [diff] [blame] | 110 | } |
| 111 | |
Amith Yamasani | 64442c1 | 2012-10-07 08:17:46 -0700 | [diff] [blame] | 112 | private Searchables getSearchables(int userId) { |
Jeff Sharkey | 4175be2 | 2016-01-09 14:57:45 -0700 | [diff] [blame] | 113 | return getSearchables(userId, false); |
| 114 | } |
| 115 | |
| 116 | private Searchables getSearchables(int userId, boolean forceUpdate) { |
| 117 | final long token = Binder.clearCallingIdentity(); |
Amith Yamasani | 64442c1 | 2012-10-07 08:17:46 -0700 | [diff] [blame] | 118 | try { |
Jeff Sharkey | 4175be2 | 2016-01-09 14:57:45 -0700 | [diff] [blame] | 119 | final UserManager um = mContext.getSystemService(UserManager.class); |
| 120 | if (um.getUserInfo(userId) == null) { |
| 121 | throw new IllegalStateException("User " + userId + " doesn't exist"); |
| 122 | } |
Jeff Sharkey | ce18c81 | 2016-04-27 16:00:41 -0600 | [diff] [blame] | 123 | if (!um.isUserUnlockingOrUnlocked(userId)) { |
Jeff Sharkey | 4175be2 | 2016-01-09 14:57:45 -0700 | [diff] [blame] | 124 | throw new IllegalStateException("User " + userId + " isn't unlocked"); |
| 125 | } |
Amith Yamasani | 64442c1 | 2012-10-07 08:17:46 -0700 | [diff] [blame] | 126 | } finally { |
Jeff Sharkey | 4175be2 | 2016-01-09 14:57:45 -0700 | [diff] [blame] | 127 | Binder.restoreCallingIdentity(token); |
Amith Yamasani | 5bb87cd | 2012-06-14 11:32:13 -0700 | [diff] [blame] | 128 | } |
Amith Yamasani | 64442c1 | 2012-10-07 08:17:46 -0700 | [diff] [blame] | 129 | synchronized (mSearchables) { |
| 130 | Searchables searchables = mSearchables.get(userId); |
Amith Yamasani | 64442c1 | 2012-10-07 08:17:46 -0700 | [diff] [blame] | 131 | if (searchables == null) { |
Amith Yamasani | 64442c1 | 2012-10-07 08:17:46 -0700 | [diff] [blame] | 132 | searchables = new Searchables(mContext, userId); |
Jeff Sharkey | 4175be2 | 2016-01-09 14:57:45 -0700 | [diff] [blame] | 133 | searchables.updateSearchableList(); |
Amith Yamasani | 64442c1 | 2012-10-07 08:17:46 -0700 | [diff] [blame] | 134 | mSearchables.append(userId, searchables); |
Jeff Sharkey | 4175be2 | 2016-01-09 14:57:45 -0700 | [diff] [blame] | 135 | } else if (forceUpdate) { |
| 136 | searchables.updateSearchableList(); |
Amith Yamasani | 64442c1 | 2012-10-07 08:17:46 -0700 | [diff] [blame] | 137 | } |
| 138 | return searchables; |
| 139 | } |
| 140 | } |
| 141 | |
Jeff Sharkey | 4175be2 | 2016-01-09 14:57:45 -0700 | [diff] [blame] | 142 | private void onUnlockUser(int userId) { |
Jeff Sharkey | 38e0d0f5 | 2016-07-26 09:47:04 -0600 | [diff] [blame] | 143 | try { |
| 144 | getSearchables(userId, true); |
| 145 | } catch (IllegalStateException ignored) { |
| 146 | // We're just trying to warm a cache, so we don't mind if the user |
| 147 | // was stopped or destroyed before we got here. |
| 148 | } |
Bjorn Bringert | 9bc75cb | 2009-07-13 13:17:27 +0100 | [diff] [blame] | 149 | } |
| 150 | |
Jeff Sharkey | 4175be2 | 2016-01-09 14:57:45 -0700 | [diff] [blame] | 151 | private void onCleanupUser(int userId) { |
| 152 | synchronized (mSearchables) { |
| 153 | mSearchables.remove(userId); |
Amith Yamasani | 64442c1 | 2012-10-07 08:17:46 -0700 | [diff] [blame] | 154 | } |
| 155 | } |
| 156 | |
Bjorn Bringert | 2c7b197 | 2010-05-04 20:44:16 +0100 | [diff] [blame] | 157 | /** |
Bjorn Bringert | 444c727 | 2009-07-06 21:32:50 +0100 | [diff] [blame] | 158 | * Refreshes the "searchables" list when packages are added/removed. |
| 159 | */ |
Bjorn Bringert | ab5d96c | 2010-02-23 22:48:46 +0000 | [diff] [blame] | 160 | class MyPackageMonitor extends PackageMonitor { |
Amith Yamasani | 13bc602 | 2011-08-23 12:11:35 -0700 | [diff] [blame] | 161 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 162 | @Override |
Bjorn Bringert | ab5d96c | 2010-02-23 22:48:46 +0000 | [diff] [blame] | 163 | public void onSomePackagesChanged() { |
Amith Yamasani | 13bc602 | 2011-08-23 12:11:35 -0700 | [diff] [blame] | 164 | updateSearchables(); |
| 165 | } |
| 166 | |
| 167 | @Override |
| 168 | public void onPackageModified(String pkg) { |
| 169 | updateSearchables(); |
| 170 | } |
| 171 | |
| 172 | private void updateSearchables() { |
Amith Yamasani | 64442c1 | 2012-10-07 08:17:46 -0700 | [diff] [blame] | 173 | final int changingUserId = getChangingUserId(); |
| 174 | synchronized (mSearchables) { |
Amith Yamasani | 5bb87cd | 2012-06-14 11:32:13 -0700 | [diff] [blame] | 175 | // Update list of searchable activities |
| 176 | for (int i = 0; i < mSearchables.size(); i++) { |
Amith Yamasani | 64442c1 | 2012-10-07 08:17:46 -0700 | [diff] [blame] | 177 | if (changingUserId == mSearchables.keyAt(i)) { |
Jeff Sharkey | 4175be2 | 2016-01-09 14:57:45 -0700 | [diff] [blame] | 178 | mSearchables.valueAt(i).updateSearchableList(); |
Amith Yamasani | 64442c1 | 2012-10-07 08:17:46 -0700 | [diff] [blame] | 179 | break; |
| 180 | } |
Amith Yamasani | 5bb87cd | 2012-06-14 11:32:13 -0700 | [diff] [blame] | 181 | } |
| 182 | } |
Bjorn Bringert | ab5d96c | 2010-02-23 22:48:46 +0000 | [diff] [blame] | 183 | // Inform all listeners that the list of searchables has been updated. |
| 184 | Intent intent = new Intent(SearchManager.INTENT_ACTION_SEARCHABLES_CHANGED); |
Amith Yamasani | e668794 | 2012-10-29 14:29:05 -0700 | [diff] [blame] | 185 | intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING |
| 186 | | Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); |
Amith Yamasani | 64442c1 | 2012-10-07 08:17:46 -0700 | [diff] [blame] | 187 | mContext.sendBroadcastAsUser(intent, new UserHandle(changingUserId)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 188 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 189 | } |
| 190 | |
Narayan Kamath | ee69ff4 | 2011-06-28 12:07:18 +0100 | [diff] [blame] | 191 | class GlobalSearchProviderObserver extends ContentObserver { |
| 192 | private final ContentResolver mResolver; |
| 193 | |
| 194 | public GlobalSearchProviderObserver(ContentResolver resolver) { |
| 195 | super(null); |
| 196 | mResolver = resolver; |
| 197 | mResolver.registerContentObserver( |
| 198 | Settings.Secure.getUriFor(Settings.Secure.SEARCH_GLOBAL_SEARCH_ACTIVITY), |
| 199 | false /* notifyDescendants */, |
| 200 | this); |
| 201 | } |
| 202 | |
| 203 | @Override |
| 204 | public void onChange(boolean selfChange) { |
Amith Yamasani | 64442c1 | 2012-10-07 08:17:46 -0700 | [diff] [blame] | 205 | synchronized (mSearchables) { |
Amith Yamasani | 5bb87cd | 2012-06-14 11:32:13 -0700 | [diff] [blame] | 206 | for (int i = 0; i < mSearchables.size(); i++) { |
Jeff Sharkey | 4175be2 | 2016-01-09 14:57:45 -0700 | [diff] [blame] | 207 | mSearchables.valueAt(i).updateSearchableList(); |
Amith Yamasani | 5bb87cd | 2012-06-14 11:32:13 -0700 | [diff] [blame] | 208 | } |
| 209 | } |
Narayan Kamath | ee69ff4 | 2011-06-28 12:07:18 +0100 | [diff] [blame] | 210 | Intent intent = new Intent(SearchManager.INTENT_GLOBAL_SEARCH_ACTIVITY_CHANGED); |
| 211 | intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 212 | mContext.sendBroadcastAsUser(intent, UserHandle.ALL); |
Narayan Kamath | ee69ff4 | 2011-06-28 12:07:18 +0100 | [diff] [blame] | 213 | } |
Narayan Kamath | ee69ff4 | 2011-06-28 12:07:18 +0100 | [diff] [blame] | 214 | } |
| 215 | |
Bjorn Bringert | 444c727 | 2009-07-06 21:32:50 +0100 | [diff] [blame] | 216 | // |
| 217 | // Searchable activities API |
| 218 | // |
Bjorn Bringert | a48a5af | 2009-05-20 17:58:39 +0100 | [diff] [blame] | 219 | |
| 220 | /** |
Bjorn Bringert | 444c727 | 2009-07-06 21:32:50 +0100 | [diff] [blame] | 221 | * Returns the SearchableInfo for a given activity. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 222 | * |
| 223 | * @param launchActivity The activity from which we're launching this search. |
Karl Rosaen | 875d50a | 2009-04-23 19:00:21 -0700 | [diff] [blame] | 224 | * @return Returns a SearchableInfo record describing the parameters of the search, |
| 225 | * or null if no searchable metadata was available. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 226 | */ |
Jeff Sharkey | 4175be2 | 2016-01-09 14:57:45 -0700 | [diff] [blame] | 227 | @Override |
Bjorn Bringert | 6cf7a32 | 2010-02-23 13:17:06 +0000 | [diff] [blame] | 228 | public SearchableInfo getSearchableInfo(final ComponentName launchActivity) { |
| 229 | if (launchActivity == null) { |
| 230 | Log.e(TAG, "getSearchableInfo(), activity == null"); |
| 231 | return null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 232 | } |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 233 | return getSearchables(UserHandle.getCallingUserId()).getSearchableInfo(launchActivity); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 234 | } |
Satish Sampath | f9acde2 | 2009-06-04 11:51:17 +0100 | [diff] [blame] | 235 | |
Bjorn Bringert | 6d72e02 | 2009-04-29 14:56:12 +0100 | [diff] [blame] | 236 | /** |
| 237 | * Returns a list of the searchable activities that can be included in global search. |
| 238 | */ |
Jeff Sharkey | 4175be2 | 2016-01-09 14:57:45 -0700 | [diff] [blame] | 239 | @Override |
Bjorn Bringert | 6d72e02 | 2009-04-29 14:56:12 +0100 | [diff] [blame] | 240 | public List<SearchableInfo> getSearchablesInGlobalSearch() { |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 241 | return getSearchables(UserHandle.getCallingUserId()).getSearchablesInGlobalSearchList(); |
Bjorn Bringert | 6d72e02 | 2009-04-29 14:56:12 +0100 | [diff] [blame] | 242 | } |
Bjorn Bringert | 8d17f3f | 2009-06-05 13:22:28 +0100 | [diff] [blame] | 243 | |
Jeff Sharkey | 4175be2 | 2016-01-09 14:57:45 -0700 | [diff] [blame] | 244 | @Override |
Narayan Kamath | ee69ff4 | 2011-06-28 12:07:18 +0100 | [diff] [blame] | 245 | public List<ResolveInfo> getGlobalSearchActivities() { |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 246 | return getSearchables(UserHandle.getCallingUserId()).getGlobalSearchActivities(); |
Narayan Kamath | ee69ff4 | 2011-06-28 12:07:18 +0100 | [diff] [blame] | 247 | } |
| 248 | |
Bjorn Bringert | 8d17f3f | 2009-06-05 13:22:28 +0100 | [diff] [blame] | 249 | /** |
Bjorn Bringert | 6cf7a32 | 2010-02-23 13:17:06 +0000 | [diff] [blame] | 250 | * Gets the name of the global search activity. |
Bjorn Bringert | 8d17f3f | 2009-06-05 13:22:28 +0100 | [diff] [blame] | 251 | */ |
Jeff Sharkey | 4175be2 | 2016-01-09 14:57:45 -0700 | [diff] [blame] | 252 | @Override |
Bjorn Bringert | 6cf7a32 | 2010-02-23 13:17:06 +0000 | [diff] [blame] | 253 | public ComponentName getGlobalSearchActivity() { |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 254 | return getSearchables(UserHandle.getCallingUserId()).getGlobalSearchActivity(); |
Bjorn Bringert | 444c727 | 2009-07-06 21:32:50 +0100 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | /** |
Bjorn Bringert | 6cf7a32 | 2010-02-23 13:17:06 +0000 | [diff] [blame] | 258 | * Gets the name of the web search activity. |
Bjorn Bringert | 444c727 | 2009-07-06 21:32:50 +0100 | [diff] [blame] | 259 | */ |
Jeff Sharkey | 4175be2 | 2016-01-09 14:57:45 -0700 | [diff] [blame] | 260 | @Override |
Bjorn Bringert | 6cf7a32 | 2010-02-23 13:17:06 +0000 | [diff] [blame] | 261 | public ComponentName getWebSearchActivity() { |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 262 | return getSearchables(UserHandle.getCallingUserId()).getWebSearchActivity(); |
Bjorn Bringert | 444c727 | 2009-07-06 21:32:50 +0100 | [diff] [blame] | 263 | } |
| 264 | |
Amith Yamasani | c1d07a4 | 2012-08-14 09:32:02 -0700 | [diff] [blame] | 265 | @Override |
Jorim Jaggi | 165ce06 | 2015-07-06 16:18:11 -0700 | [diff] [blame] | 266 | public void launchAssist(Bundle args) { |
| 267 | StatusBarManagerInternal statusBarManager = |
| 268 | LocalServices.getService(StatusBarManagerInternal.class); |
| 269 | if (statusBarManager != null) { |
| 270 | statusBarManager.startAssist(args); |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | private ComponentName getLegacyAssistComponent(int userHandle) { |
Amith Yamasani | c1d07a4 | 2012-08-14 09:32:02 -0700 | [diff] [blame] | 275 | try { |
Ben Pietrzak | 05cb363 | 2012-12-12 11:31:57 -0800 | [diff] [blame] | 276 | userHandle = ActivityManager.handleIncomingUser(Binder.getCallingPid(), |
Jorim Jaggi | 165ce06 | 2015-07-06 16:18:11 -0700 | [diff] [blame] | 277 | Binder.getCallingUid(), userHandle, true, false, "getLegacyAssistComponent", null); |
Amith Yamasani | c1d07a4 | 2012-08-14 09:32:02 -0700 | [diff] [blame] | 278 | IPackageManager pm = AppGlobals.getPackageManager(); |
| 279 | Intent assistIntent = new Intent(Intent.ACTION_ASSIST); |
| 280 | ResolveInfo info = |
| 281 | pm.resolveIntent(assistIntent, |
Jorim Jaggi | 165ce06 | 2015-07-06 16:18:11 -0700 | [diff] [blame] | 282 | assistIntent.resolveTypeIfNeeded(mContext.getContentResolver()), |
| 283 | PackageManager.MATCH_DEFAULT_ONLY, userHandle); |
Amith Yamasani | c1d07a4 | 2012-08-14 09:32:02 -0700 | [diff] [blame] | 284 | if (info != null) { |
| 285 | return new ComponentName( |
| 286 | info.activityInfo.applicationInfo.packageName, |
| 287 | info.activityInfo.name); |
| 288 | } |
| 289 | } catch (RemoteException re) { |
| 290 | // Local call |
Jorim Jaggi | 165ce06 | 2015-07-06 16:18:11 -0700 | [diff] [blame] | 291 | Log.e(TAG, "RemoteException in getLegacyAssistComponent: " + re); |
Amith Yamasani | c1d07a4 | 2012-08-14 09:32:02 -0700 | [diff] [blame] | 292 | } catch (Exception e) { |
Jorim Jaggi | 165ce06 | 2015-07-06 16:18:11 -0700 | [diff] [blame] | 293 | Log.e(TAG, "Exception in getLegacyAssistComponent: " + e); |
Amith Yamasani | c1d07a4 | 2012-08-14 09:32:02 -0700 | [diff] [blame] | 294 | } |
| 295 | return null; |
| 296 | } |
Amith Yamasani | 64442c1 | 2012-10-07 08:17:46 -0700 | [diff] [blame] | 297 | |
| 298 | @Override |
Jorim Jaggi | 165ce06 | 2015-07-06 16:18:11 -0700 | [diff] [blame] | 299 | public boolean launchLegacyAssist(String hint, int userHandle, Bundle args) { |
| 300 | ComponentName comp = getLegacyAssistComponent(userHandle); |
Dianne Hackborn | fdf5b35 | 2014-10-08 17:43:48 -0700 | [diff] [blame] | 301 | if (comp == null) { |
| 302 | return false; |
| 303 | } |
| 304 | long ident = Binder.clearCallingIdentity(); |
| 305 | try { |
| 306 | Intent intent = new Intent(Intent.ACTION_ASSIST); |
| 307 | intent.setComponent(comp); |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 308 | IActivityManager am = ActivityManager.getService(); |
Dianne Hackborn | a83ce1d | 2015-03-11 15:16:13 -0700 | [diff] [blame] | 309 | return am.launchAssistIntent(intent, ActivityManager.ASSIST_CONTEXT_BASIC, hint, |
Tim Kilbourn | 0e5f110 | 2015-06-05 16:18:09 -0700 | [diff] [blame] | 310 | userHandle, args); |
Dianne Hackborn | fdf5b35 | 2014-10-08 17:43:48 -0700 | [diff] [blame] | 311 | } catch (RemoteException e) { |
| 312 | } finally { |
| 313 | Binder.restoreCallingIdentity(ident); |
| 314 | } |
| 315 | return true; |
| 316 | } |
| 317 | |
| 318 | @Override |
Amith Yamasani | 64442c1 | 2012-10-07 08:17:46 -0700 | [diff] [blame] | 319 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
Jeff Sharkey | 52801aa | 2012-10-12 16:06:16 -0700 | [diff] [blame] | 320 | mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DUMP, TAG); |
| 321 | |
Amith Yamasani | 64442c1 | 2012-10-07 08:17:46 -0700 | [diff] [blame] | 322 | IndentingPrintWriter ipw = new IndentingPrintWriter(pw, " "); |
| 323 | synchronized (mSearchables) { |
| 324 | for (int i = 0; i < mSearchables.size(); i++) { |
| 325 | ipw.print("\nUser: "); ipw.println(mSearchables.keyAt(i)); |
| 326 | ipw.increaseIndent(); |
| 327 | mSearchables.valueAt(i).dump(fd, ipw, args); |
| 328 | ipw.decreaseIndent(); |
| 329 | } |
| 330 | } |
| 331 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 332 | } |