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