Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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 | |
| 17 | package com.android.server.pm; |
| 18 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 19 | import android.annotation.NonNull; |
| 20 | import android.annotation.UserIdInt; |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 21 | import android.app.ActivityManager; |
Makoto Onuki | ea11db1 | 2016-06-24 15:17:44 -0700 | [diff] [blame] | 22 | import android.app.ActivityManagerInternal; |
Ricky Wai | cf134eb | 2018-10-10 09:26:32 +0100 | [diff] [blame] | 23 | import android.app.AppDetailsActivity; |
Kenny Guy | 53fa4ec | 2014-04-29 14:24:18 +0100 | [diff] [blame] | 24 | import android.app.AppGlobals; |
Makoto Onuki | 1a34274 | 2018-04-26 14:56:59 -0700 | [diff] [blame] | 25 | import android.app.IApplicationThread; |
Sunny Goyal | a6be88a | 2017-01-12 16:27:58 -0800 | [diff] [blame] | 26 | import android.app.PendingIntent; |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 27 | import android.content.ComponentName; |
| 28 | import android.content.Context; |
| 29 | import android.content.Intent; |
Sunny Goyal | a6be88a | 2017-01-12 16:27:58 -0800 | [diff] [blame] | 30 | import android.content.IntentSender; |
Kenny Guy | 53fa4ec | 2014-04-29 14:24:18 +0100 | [diff] [blame] | 31 | import android.content.pm.ActivityInfo; |
Kenny Guy | 7724275 | 2016-01-15 13:29:06 +0000 | [diff] [blame] | 32 | import android.content.pm.ApplicationInfo; |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 33 | import android.content.pm.ILauncherApps; |
| 34 | import android.content.pm.IOnAppsChangedListener; |
Makoto Onuki | 4dbe0de | 2016-03-14 17:31:49 -0700 | [diff] [blame] | 35 | import android.content.pm.LauncherApps.ShortcutQuery; |
Kenny Guy | 53fa4ec | 2014-04-29 14:24:18 +0100 | [diff] [blame] | 36 | import android.content.pm.PackageInfo; |
Jeff Sharkey | cd65448 | 2016-01-08 17:42:11 -0700 | [diff] [blame] | 37 | import android.content.pm.PackageManager; |
Todd Kennedy | 18211fd | 2017-06-06 09:15:46 -0700 | [diff] [blame] | 38 | import android.content.pm.PackageManagerInternal; |
Sunny Goyal | 6cbc2fe | 2015-11-24 09:34:20 -0800 | [diff] [blame] | 39 | import android.content.pm.ParceledListSlice; |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 40 | import android.content.pm.ResolveInfo; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 41 | import android.content.pm.ShortcutInfo; |
| 42 | import android.content.pm.ShortcutServiceInternal; |
| 43 | import android.content.pm.ShortcutServiceInternal.ShortcutChangeListener; |
Makoto Onuki | e70b29e | 2018-04-03 16:44:39 -0700 | [diff] [blame] | 44 | import android.content.pm.UserInfo; |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 45 | import android.graphics.Rect; |
Kenny Guy | 466d203 | 2014-07-23 12:23:35 +0100 | [diff] [blame] | 46 | import android.net.Uri; |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 47 | import android.os.Binder; |
| 48 | import android.os.Bundle; |
Makoto Onuki | c5475d4 | 2016-03-25 10:54:07 -0700 | [diff] [blame] | 49 | import android.os.Handler; |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 50 | import android.os.IInterface; |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 51 | import android.os.ParcelFileDescriptor; |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 52 | import android.os.RemoteCallbackList; |
| 53 | import android.os.RemoteException; |
| 54 | import android.os.UserHandle; |
Makoto Onuki | e70b29e | 2018-04-03 16:44:39 -0700 | [diff] [blame] | 55 | import android.os.UserManager; |
Sunny Goyal | 145c8f8 | 2018-02-15 14:27:09 -0800 | [diff] [blame] | 56 | import android.os.UserManagerInternal; |
Kenny Guy | 466d203 | 2014-07-23 12:23:35 +0100 | [diff] [blame] | 57 | import android.provider.Settings; |
Amith Yamasani | 932249d | 2014-05-01 14:39:35 -0700 | [diff] [blame] | 58 | import android.util.Log; |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 59 | import android.util.Slog; |
| 60 | |
Makoto Onuki | 7a6a05f | 2016-03-10 17:01:08 -0800 | [diff] [blame] | 61 | import com.android.internal.annotations.VisibleForTesting; |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 62 | import com.android.internal.content.PackageMonitor; |
Makoto Onuki | c5475d4 | 2016-03-25 10:54:07 -0700 | [diff] [blame] | 63 | import com.android.internal.os.BackgroundThread; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 64 | import com.android.internal.util.Preconditions; |
| 65 | import com.android.server.LocalServices; |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 66 | import com.android.server.SystemService; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 67 | import com.android.server.wm.ActivityTaskManagerInternal; |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 68 | |
Ricky Wai | cf134eb | 2018-10-10 09:26:32 +0100 | [diff] [blame] | 69 | import java.util.ArrayList; |
Makoto Onuki | de3c16c | 2017-01-26 11:39:31 -0800 | [diff] [blame] | 70 | import java.util.Collections; |
Ricky Wai | cf134eb | 2018-10-10 09:26:32 +0100 | [diff] [blame] | 71 | import java.util.HashSet; |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 72 | import java.util.List; |
| 73 | |
| 74 | /** |
| 75 | * Service that manages requests and callbacks for launchers that support |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 76 | * managed profiles. |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 77 | */ |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 78 | public class LauncherAppsService extends SystemService { |
| 79 | |
| 80 | private final LauncherAppsImpl mLauncherAppsImpl; |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 81 | |
| 82 | public LauncherAppsService(Context context) { |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 83 | super(context); |
| 84 | mLauncherAppsImpl = new LauncherAppsImpl(context); |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 85 | } |
| 86 | |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 87 | @Override |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 88 | public void onStart() { |
| 89 | publishBinderService(Context.LAUNCHER_APPS_SERVICE, mLauncherAppsImpl); |
| 90 | } |
| 91 | |
Makoto Onuki | 4dbe0de | 2016-03-14 17:31:49 -0700 | [diff] [blame] | 92 | static class BroadcastCookie { |
| 93 | public final UserHandle user; |
| 94 | public final String packageName; |
Makoto Onuki | 634cecb | 2017-10-13 17:10:48 -0700 | [diff] [blame] | 95 | public final int callingUid; |
| 96 | public final int callingPid; |
Makoto Onuki | 4dbe0de | 2016-03-14 17:31:49 -0700 | [diff] [blame] | 97 | |
Makoto Onuki | 634cecb | 2017-10-13 17:10:48 -0700 | [diff] [blame] | 98 | BroadcastCookie(UserHandle userHandle, String packageName, int callingPid, int callingUid) { |
Makoto Onuki | 4dbe0de | 2016-03-14 17:31:49 -0700 | [diff] [blame] | 99 | this.user = userHandle; |
| 100 | this.packageName = packageName; |
Makoto Onuki | 634cecb | 2017-10-13 17:10:48 -0700 | [diff] [blame] | 101 | this.callingUid = callingUid; |
| 102 | this.callingPid = callingPid; |
Makoto Onuki | 4dbe0de | 2016-03-14 17:31:49 -0700 | [diff] [blame] | 103 | } |
| 104 | } |
| 105 | |
Makoto Onuki | 7a6a05f | 2016-03-10 17:01:08 -0800 | [diff] [blame] | 106 | @VisibleForTesting |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 107 | static class LauncherAppsImpl extends ILauncherApps.Stub { |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 108 | private static final boolean DEBUG = false; |
| 109 | private static final String TAG = "LauncherAppsService"; |
| 110 | private final Context mContext; |
Makoto Onuki | e70b29e | 2018-04-03 16:44:39 -0700 | [diff] [blame] | 111 | private final UserManager mUm; |
Sunny Goyal | 145c8f8 | 2018-02-15 14:27:09 -0800 | [diff] [blame] | 112 | private final UserManagerInternal mUserManagerInternal; |
Makoto Onuki | ea11db1 | 2016-06-24 15:17:44 -0700 | [diff] [blame] | 113 | private final ActivityManagerInternal mActivityManagerInternal; |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 114 | private final ActivityTaskManagerInternal mActivityTaskManagerInternal; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 115 | private final ShortcutServiceInternal mShortcutServiceInternal; |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 116 | private final PackageCallbackList<IOnAppsChangedListener> mListeners |
| 117 | = new PackageCallbackList<IOnAppsChangedListener>(); |
| 118 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 119 | private final MyPackageMonitor mPackageMonitor = new MyPackageMonitor(); |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 120 | |
Makoto Onuki | c5475d4 | 2016-03-25 10:54:07 -0700 | [diff] [blame] | 121 | private final Handler mCallbackHandler; |
| 122 | |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 123 | public LauncherAppsImpl(Context context) { |
| 124 | mContext = context; |
Makoto Onuki | e70b29e | 2018-04-03 16:44:39 -0700 | [diff] [blame] | 125 | mUm = (UserManager) mContext.getSystemService(Context.USER_SERVICE); |
Sunny Goyal | 145c8f8 | 2018-02-15 14:27:09 -0800 | [diff] [blame] | 126 | mUserManagerInternal = Preconditions.checkNotNull( |
| 127 | LocalServices.getService(UserManagerInternal.class)); |
Makoto Onuki | ea11db1 | 2016-06-24 15:17:44 -0700 | [diff] [blame] | 128 | mActivityManagerInternal = Preconditions.checkNotNull( |
| 129 | LocalServices.getService(ActivityManagerInternal.class)); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 130 | mActivityTaskManagerInternal = Preconditions.checkNotNull( |
| 131 | LocalServices.getService(ActivityTaskManagerInternal.class)); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 132 | mShortcutServiceInternal = Preconditions.checkNotNull( |
| 133 | LocalServices.getService(ShortcutServiceInternal.class)); |
| 134 | mShortcutServiceInternal.addListener(mPackageMonitor); |
Makoto Onuki | c5475d4 | 2016-03-25 10:54:07 -0700 | [diff] [blame] | 135 | mCallbackHandler = BackgroundThread.getHandler(); |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 136 | } |
| 137 | |
Makoto Onuki | 2d5b465 | 2016-03-11 16:09:54 -0800 | [diff] [blame] | 138 | @VisibleForTesting |
| 139 | int injectBinderCallingUid() { |
| 140 | return getCallingUid(); |
| 141 | } |
| 142 | |
Makoto Onuki | 634cecb | 2017-10-13 17:10:48 -0700 | [diff] [blame] | 143 | @VisibleForTesting |
| 144 | int injectBinderCallingPid() { |
| 145 | return getCallingPid(); |
| 146 | } |
| 147 | |
Makoto Onuki | ac21497 | 2016-04-04 10:19:45 -0700 | [diff] [blame] | 148 | final int injectCallingUserId() { |
| 149 | return UserHandle.getUserId(injectBinderCallingUid()); |
| 150 | } |
| 151 | |
| 152 | @VisibleForTesting |
| 153 | long injectClearCallingIdentity() { |
| 154 | return Binder.clearCallingIdentity(); |
| 155 | } |
| 156 | |
| 157 | // Injection point. |
| 158 | @VisibleForTesting |
| 159 | void injectRestoreCallingIdentity(long token) { |
| 160 | Binder.restoreCallingIdentity(token); |
| 161 | } |
| 162 | |
Makoto Onuki | 2d5b465 | 2016-03-11 16:09:54 -0800 | [diff] [blame] | 163 | private int getCallingUserId() { |
| 164 | return UserHandle.getUserId(injectBinderCallingUid()); |
| 165 | } |
| 166 | |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 167 | /* |
| 168 | * @see android.content.pm.ILauncherApps#addOnAppsChangedListener( |
| 169 | * android.content.pm.IOnAppsChangedListener) |
| 170 | */ |
| 171 | @Override |
Makoto Onuki | 4dbe0de | 2016-03-14 17:31:49 -0700 | [diff] [blame] | 172 | public void addOnAppsChangedListener(String callingPackage, IOnAppsChangedListener listener) |
| 173 | throws RemoteException { |
Makoto Onuki | 5ba0d3e | 2016-04-11 14:03:46 -0700 | [diff] [blame] | 174 | verifyCallingPackage(callingPackage); |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 175 | synchronized (mListeners) { |
Amith Yamasani | 932249d | 2014-05-01 14:39:35 -0700 | [diff] [blame] | 176 | if (DEBUG) { |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 177 | Log.d(TAG, "Adding listener from " + Binder.getCallingUserHandle()); |
Amith Yamasani | 932249d | 2014-05-01 14:39:35 -0700 | [diff] [blame] | 178 | } |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 179 | if (mListeners.getRegisteredCallbackCount() == 0) { |
| 180 | if (DEBUG) { |
| 181 | Log.d(TAG, "Starting package monitoring"); |
| 182 | } |
| 183 | startWatchingPackageBroadcasts(); |
| 184 | } |
| 185 | mListeners.unregister(listener); |
Makoto Onuki | 4dbe0de | 2016-03-14 17:31:49 -0700 | [diff] [blame] | 186 | mListeners.register(listener, new BroadcastCookie(UserHandle.of(getCallingUserId()), |
Makoto Onuki | 634cecb | 2017-10-13 17:10:48 -0700 | [diff] [blame] | 187 | callingPackage, injectBinderCallingPid(), injectBinderCallingUid())); |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 188 | } |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 189 | } |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 190 | |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 191 | /* |
| 192 | * @see android.content.pm.ILauncherApps#removeOnAppsChangedListener( |
| 193 | * android.content.pm.IOnAppsChangedListener) |
| 194 | */ |
| 195 | @Override |
| 196 | public void removeOnAppsChangedListener(IOnAppsChangedListener listener) |
| 197 | throws RemoteException { |
| 198 | synchronized (mListeners) { |
| 199 | if (DEBUG) { |
| 200 | Log.d(TAG, "Removing listener from " + Binder.getCallingUserHandle()); |
| 201 | } |
| 202 | mListeners.unregister(listener); |
| 203 | if (mListeners.getRegisteredCallbackCount() == 0) { |
| 204 | stopWatchingPackageBroadcasts(); |
| 205 | } |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | /** |
| 210 | * Register a receiver to watch for package broadcasts |
| 211 | */ |
| 212 | private void startWatchingPackageBroadcasts() { |
Makoto Onuki | c5475d4 | 2016-03-25 10:54:07 -0700 | [diff] [blame] | 213 | mPackageMonitor.register(mContext, UserHandle.ALL, true, mCallbackHandler); |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | /** |
| 217 | * Unregister package broadcast receiver |
| 218 | */ |
| 219 | private void stopWatchingPackageBroadcasts() { |
Amith Yamasani | 932249d | 2014-05-01 14:39:35 -0700 | [diff] [blame] | 220 | if (DEBUG) { |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 221 | Log.d(TAG, "Stopped watching for packages"); |
Amith Yamasani | 932249d | 2014-05-01 14:39:35 -0700 | [diff] [blame] | 222 | } |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 223 | mPackageMonitor.unregister(); |
| 224 | } |
| 225 | |
| 226 | void checkCallbackCount() { |
| 227 | synchronized (mListeners) { |
| 228 | if (DEBUG) { |
| 229 | Log.d(TAG, "Callback count = " + mListeners.getRegisteredCallbackCount()); |
| 230 | } |
| 231 | if (mListeners.getRegisteredCallbackCount() == 0) { |
| 232 | stopWatchingPackageBroadcasts(); |
| 233 | } |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 234 | } |
| 235 | } |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 236 | |
Makoto Onuki | de3c16c | 2017-01-26 11:39:31 -0800 | [diff] [blame] | 237 | /** |
| 238 | * Checks if the calling user is in the same group as {@code targetUser}, and allowed |
| 239 | * to access it. |
| 240 | * |
| 241 | * @return TRUE if the calling user can access {@code targetUserId}. FALSE if not *but |
| 242 | * they're still in the same profile group*. |
| 243 | * |
| 244 | * @throws SecurityException if the calling user and {@code targetUser} are not in the same |
| 245 | * group. |
| 246 | */ |
Sunny Goyal | 145c8f8 | 2018-02-15 14:27:09 -0800 | [diff] [blame] | 247 | private boolean canAccessProfile(int targetUserId, String message) { |
Makoto Onuki | e70b29e | 2018-04-03 16:44:39 -0700 | [diff] [blame] | 248 | final int callingUserId = injectCallingUserId(); |
| 249 | |
| 250 | if (targetUserId == callingUserId) return true; |
| 251 | |
| 252 | long ident = injectClearCallingIdentity(); |
| 253 | try { |
| 254 | final UserInfo callingUserInfo = mUm.getUserInfo(callingUserId); |
| 255 | if (callingUserInfo != null && callingUserInfo.isManagedProfile()) { |
| 256 | Slog.w(TAG, message + " for another profile " |
| 257 | + targetUserId + " from " + callingUserId + " not allowed"); |
| 258 | return false; |
| 259 | } |
| 260 | } finally { |
| 261 | injectRestoreCallingIdentity(ident); |
| 262 | } |
| 263 | |
Sunny Goyal | 145c8f8 | 2018-02-15 14:27:09 -0800 | [diff] [blame] | 264 | return mUserManagerInternal.isProfileAccessible(injectCallingUserId(), targetUserId, |
| 265 | message, true); |
Amith Yamasani | 932249d | 2014-05-01 14:39:35 -0700 | [diff] [blame] | 266 | } |
| 267 | |
Makoto Onuki | 7a6a05f | 2016-03-10 17:01:08 -0800 | [diff] [blame] | 268 | @VisibleForTesting // We override it in unit tests |
| 269 | void verifyCallingPackage(String callingPackage) { |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 270 | int packageUid = -1; |
| 271 | try { |
Todd Kennedy | 18211fd | 2017-06-06 09:15:46 -0700 | [diff] [blame] | 272 | packageUid = AppGlobals.getPackageManager().getPackageUid(callingPackage, |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 273 | PackageManager.MATCH_DIRECT_BOOT_AWARE |
| 274 | | PackageManager.MATCH_DIRECT_BOOT_UNAWARE |
Makoto Onuki | 3ee7f71 | 2016-03-10 17:28:55 -0800 | [diff] [blame] | 275 | | PackageManager.MATCH_UNINSTALLED_PACKAGES, |
| 276 | UserHandle.getUserId(getCallingUid())); |
Todd Kennedy | 18211fd | 2017-06-06 09:15:46 -0700 | [diff] [blame] | 277 | } catch (RemoteException ignore) { |
| 278 | } |
| 279 | if (packageUid < 0) { |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 280 | Log.e(TAG, "Package not found: " + callingPackage); |
| 281 | } |
Todd Kennedy | 18211fd | 2017-06-06 09:15:46 -0700 | [diff] [blame] | 282 | if (packageUid != injectBinderCallingUid()) { |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 283 | throw new SecurityException("Calling package name mismatch"); |
| 284 | } |
| 285 | } |
| 286 | |
Ricky Wai | cf134eb | 2018-10-10 09:26:32 +0100 | [diff] [blame] | 287 | private ResolveInfo getHiddenAppActivityInfo(String packageName, int callingUid, |
| 288 | UserHandle user) { |
| 289 | Intent intent = new Intent(); |
| 290 | intent.setComponent(new ComponentName(packageName, AppDetailsActivity.class.getName())); |
| 291 | final PackageManagerInternal pmInt = |
| 292 | LocalServices.getService(PackageManagerInternal.class); |
| 293 | List<ResolveInfo> apps = pmInt.queryIntentActivities(intent, |
| 294 | PackageManager.MATCH_DIRECT_BOOT_AWARE |
| 295 | | PackageManager.MATCH_DIRECT_BOOT_UNAWARE, |
| 296 | callingUid, user.getIdentifier()); |
| 297 | if (apps.size() > 0) { |
| 298 | return apps.get(0); |
| 299 | } |
| 300 | return null; |
| 301 | } |
| 302 | |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 303 | @Override |
Makoto Onuki | 3a2541e | 2017-01-24 09:00:15 -0800 | [diff] [blame] | 304 | public ParceledListSlice<ResolveInfo> getLauncherActivities(String callingPackage, |
Ricky Wai | cf134eb | 2018-10-10 09:26:32 +0100 | [diff] [blame] | 305 | String packageName, UserHandle user) throws RemoteException { |
| 306 | ParceledListSlice<ResolveInfo> launcherActivities = queryActivitiesForUser( |
| 307 | callingPackage, |
Sunny Goyal | a6be88a | 2017-01-12 16:27:58 -0800 | [diff] [blame] | 308 | new Intent(Intent.ACTION_MAIN) |
| 309 | .addCategory(Intent.CATEGORY_LAUNCHER) |
| 310 | .setPackage(packageName), |
| 311 | user); |
Ricky Wai | 13b0abe | 2018-10-23 11:03:02 +0100 | [diff] [blame] | 312 | if (Settings.Global.getInt(mContext.getContentResolver(), |
| 313 | Settings.Global.SHOW_HIDDEN_LAUNCHER_ICON_APPS_ENABLED, 0) == 0) { |
Ricky Wai | cf134eb | 2018-10-10 09:26:32 +0100 | [diff] [blame] | 314 | return launcherActivities; |
| 315 | } |
| 316 | |
| 317 | final int callingUid = injectBinderCallingUid(); |
| 318 | final ArrayList<ResolveInfo> result = new ArrayList<>(launcherActivities.getList()); |
Michal Karpinski | 6d5795f | 2018-11-06 15:18:30 +0000 | [diff] [blame] | 319 | final PackageManagerInternal pmInt = |
| 320 | LocalServices.getService(PackageManagerInternal.class); |
Ricky Wai | cf134eb | 2018-10-10 09:26:32 +0100 | [diff] [blame] | 321 | if (packageName != null) { |
Michal Karpinski | 6d5795f | 2018-11-06 15:18:30 +0000 | [diff] [blame] | 322 | // If this hidden app should not be shown, return the original list. |
| 323 | // Otherwise, inject hidden activity that forwards user to app details page. |
Ricky Wai | cf134eb | 2018-10-10 09:26:32 +0100 | [diff] [blame] | 324 | if (result.size() > 0) { |
| 325 | return launcherActivities; |
| 326 | } |
Michal Karpinski | 6d5795f | 2018-11-06 15:18:30 +0000 | [diff] [blame] | 327 | ApplicationInfo appInfo = pmInt.getApplicationInfo(packageName, /*flags*/ 0, |
| 328 | callingUid, user.getIdentifier()); |
| 329 | if (shouldShowHiddenApp(appInfo)) { |
| 330 | ResolveInfo info = getHiddenAppActivityInfo(packageName, callingUid, user); |
| 331 | if (info != null) { |
| 332 | result.add(info); |
| 333 | } |
Ricky Wai | cf134eb | 2018-10-10 09:26:32 +0100 | [diff] [blame] | 334 | } |
| 335 | return new ParceledListSlice<>(result); |
| 336 | } |
| 337 | |
| 338 | long ident = injectClearCallingIdentity(); |
| 339 | try { |
| 340 | final HashSet<String> visiblePackages = new HashSet<>(); |
| 341 | for (ResolveInfo info : result) { |
| 342 | visiblePackages.add(info.activityInfo.packageName); |
| 343 | } |
Ricky Wai | cf134eb | 2018-10-10 09:26:32 +0100 | [diff] [blame] | 344 | List<ApplicationInfo> installedPackages = pmInt.getInstalledApplications(0, |
| 345 | user.getIdentifier(), callingUid); |
| 346 | for (ApplicationInfo applicationInfo : installedPackages) { |
| 347 | if (!visiblePackages.contains(applicationInfo.packageName)) { |
| 348 | if (!shouldShowHiddenApp(applicationInfo)) { |
| 349 | continue; |
| 350 | } |
| 351 | ResolveInfo info = getHiddenAppActivityInfo(applicationInfo.packageName, |
| 352 | callingUid, user); |
| 353 | if (info != null) { |
| 354 | result.add(info); |
| 355 | } |
| 356 | } |
| 357 | } |
| 358 | return new ParceledListSlice<>(result); |
| 359 | } finally { |
| 360 | injectRestoreCallingIdentity(ident); |
| 361 | } |
| 362 | } |
| 363 | |
| 364 | private static boolean shouldShowHiddenApp(ApplicationInfo appInfo) { |
Michal Karpinski | 08404a95 | 2018-11-15 17:46:00 +0000 | [diff] [blame] | 365 | if (appInfo == null || appInfo.isSystemApp() || appInfo.isUpdatedSystemApp()) { |
Ricky Wai | cf134eb | 2018-10-10 09:26:32 +0100 | [diff] [blame] | 366 | return false; |
| 367 | } |
| 368 | return true; |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | @Override |
Makoto Onuki | 3a2541e | 2017-01-24 09:00:15 -0800 | [diff] [blame] | 372 | public ActivityInfo resolveActivity( |
| 373 | String callingPackage, ComponentName component, UserHandle user) |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 374 | throws RemoteException { |
Sunny Goyal | 145c8f8 | 2018-02-15 14:27:09 -0800 | [diff] [blame] | 375 | if (!canAccessProfile(user.getIdentifier(), "Cannot resolve activity")) { |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 376 | return null; |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 377 | } |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 378 | |
Todd Kennedy | 18211fd | 2017-06-06 09:15:46 -0700 | [diff] [blame] | 379 | final int callingUid = injectBinderCallingUid(); |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 380 | long ident = Binder.clearCallingIdentity(); |
| 381 | try { |
Todd Kennedy | 18211fd | 2017-06-06 09:15:46 -0700 | [diff] [blame] | 382 | final PackageManagerInternal pmInt = |
| 383 | LocalServices.getService(PackageManagerInternal.class); |
| 384 | return pmInt.getActivityInfo(component, |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 385 | PackageManager.MATCH_DIRECT_BOOT_AWARE |
| 386 | | PackageManager.MATCH_DIRECT_BOOT_UNAWARE, |
Todd Kennedy | 18211fd | 2017-06-06 09:15:46 -0700 | [diff] [blame] | 387 | callingUid, user.getIdentifier()); |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 388 | } finally { |
| 389 | Binder.restoreCallingIdentity(ident); |
| 390 | } |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | @Override |
Makoto Onuki | 3a2541e | 2017-01-24 09:00:15 -0800 | [diff] [blame] | 394 | public ParceledListSlice getShortcutConfigActivities( |
| 395 | String callingPackage, String packageName, UserHandle user) |
Sunny Goyal | a6be88a | 2017-01-12 16:27:58 -0800 | [diff] [blame] | 396 | throws RemoteException { |
Makoto Onuki | 3a2541e | 2017-01-24 09:00:15 -0800 | [diff] [blame] | 397 | return queryActivitiesForUser(callingPackage, |
Sunny Goyal | a6be88a | 2017-01-12 16:27:58 -0800 | [diff] [blame] | 398 | new Intent(Intent.ACTION_CREATE_SHORTCUT).setPackage(packageName), user); |
| 399 | } |
| 400 | |
Makoto Onuki | 3a2541e | 2017-01-24 09:00:15 -0800 | [diff] [blame] | 401 | private ParceledListSlice<ResolveInfo> queryActivitiesForUser(String callingPackage, |
| 402 | Intent intent, UserHandle user) { |
Sunny Goyal | 145c8f8 | 2018-02-15 14:27:09 -0800 | [diff] [blame] | 403 | if (!canAccessProfile(user.getIdentifier(), "Cannot retrieve activities")) { |
Sunny Goyal | a6be88a | 2017-01-12 16:27:58 -0800 | [diff] [blame] | 404 | return null; |
| 405 | } |
| 406 | |
Todd Kennedy | 18211fd | 2017-06-06 09:15:46 -0700 | [diff] [blame] | 407 | final int callingUid = injectBinderCallingUid(); |
Sunny Goyal | a6be88a | 2017-01-12 16:27:58 -0800 | [diff] [blame] | 408 | long ident = injectClearCallingIdentity(); |
| 409 | try { |
Todd Kennedy | 18211fd | 2017-06-06 09:15:46 -0700 | [diff] [blame] | 410 | final PackageManagerInternal pmInt = |
| 411 | LocalServices.getService(PackageManagerInternal.class); |
| 412 | List<ResolveInfo> apps = pmInt.queryIntentActivities(intent, |
Sunny Goyal | a6be88a | 2017-01-12 16:27:58 -0800 | [diff] [blame] | 413 | PackageManager.MATCH_DIRECT_BOOT_AWARE |
| 414 | | PackageManager.MATCH_DIRECT_BOOT_UNAWARE, |
Todd Kennedy | 18211fd | 2017-06-06 09:15:46 -0700 | [diff] [blame] | 415 | callingUid, user.getIdentifier()); |
Sunny Goyal | a6be88a | 2017-01-12 16:27:58 -0800 | [diff] [blame] | 416 | return new ParceledListSlice<>(apps); |
| 417 | } finally { |
| 418 | injectRestoreCallingIdentity(ident); |
| 419 | } |
| 420 | } |
| 421 | |
| 422 | @Override |
| 423 | public IntentSender getShortcutConfigActivityIntent(String callingPackage, |
| 424 | ComponentName component, UserHandle user) throws RemoteException { |
Makoto Onuki | de3c16c | 2017-01-26 11:39:31 -0800 | [diff] [blame] | 425 | ensureShortcutPermission(callingPackage); |
Sunny Goyal | 145c8f8 | 2018-02-15 14:27:09 -0800 | [diff] [blame] | 426 | if (!canAccessProfile(user.getIdentifier(), "Cannot check package")) { |
Makoto Onuki | de3c16c | 2017-01-26 11:39:31 -0800 | [diff] [blame] | 427 | return null; |
| 428 | } |
Sunny Goyal | a6be88a | 2017-01-12 16:27:58 -0800 | [diff] [blame] | 429 | Preconditions.checkNotNull(component); |
Sunny Goyal | a6be88a | 2017-01-12 16:27:58 -0800 | [diff] [blame] | 430 | |
| 431 | // All right, create the sender. |
| 432 | Intent intent = new Intent(Intent.ACTION_CREATE_SHORTCUT).setComponent(component); |
| 433 | final long identity = Binder.clearCallingIdentity(); |
| 434 | try { |
Makoto Onuki | de3c16c | 2017-01-26 11:39:31 -0800 | [diff] [blame] | 435 | final PendingIntent pi = PendingIntent.getActivityAsUser( |
Sunny Goyal | a6be88a | 2017-01-12 16:27:58 -0800 | [diff] [blame] | 436 | mContext, 0, intent, PendingIntent.FLAG_ONE_SHOT |
| 437 | | PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_CANCEL_CURRENT, |
Makoto Onuki | de3c16c | 2017-01-26 11:39:31 -0800 | [diff] [blame] | 438 | null, user); |
| 439 | return pi == null ? null : pi.getIntentSender(); |
Sunny Goyal | a6be88a | 2017-01-12 16:27:58 -0800 | [diff] [blame] | 440 | } finally { |
| 441 | Binder.restoreCallingIdentity(identity); |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | @Override |
Makoto Onuki | 3a2541e | 2017-01-24 09:00:15 -0800 | [diff] [blame] | 446 | public boolean isPackageEnabled(String callingPackage, String packageName, UserHandle user) |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 447 | throws RemoteException { |
Sunny Goyal | 145c8f8 | 2018-02-15 14:27:09 -0800 | [diff] [blame] | 448 | if (!canAccessProfile(user.getIdentifier(), "Cannot check package")) { |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 449 | return false; |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 450 | } |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 451 | |
Todd Kennedy | 18211fd | 2017-06-06 09:15:46 -0700 | [diff] [blame] | 452 | final int callingUid = injectBinderCallingUid(); |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 453 | long ident = Binder.clearCallingIdentity(); |
| 454 | try { |
Todd Kennedy | 18211fd | 2017-06-06 09:15:46 -0700 | [diff] [blame] | 455 | final PackageManagerInternal pmInt = |
| 456 | LocalServices.getService(PackageManagerInternal.class); |
| 457 | PackageInfo info = pmInt.getPackageInfo(packageName, |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 458 | PackageManager.MATCH_DIRECT_BOOT_AWARE |
| 459 | | PackageManager.MATCH_DIRECT_BOOT_UNAWARE, |
Todd Kennedy | 18211fd | 2017-06-06 09:15:46 -0700 | [diff] [blame] | 460 | callingUid, user.getIdentifier()); |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 461 | return info != null && info.applicationInfo.enabled; |
| 462 | } finally { |
| 463 | Binder.restoreCallingIdentity(ident); |
| 464 | } |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | @Override |
Suprabh Shukla | 19b41f3 | 2018-03-26 22:35:13 -0700 | [diff] [blame] | 468 | public Bundle getSuspendedPackageLauncherExtras(String packageName, |
| 469 | UserHandle user) { |
| 470 | if (!canAccessProfile(user.getIdentifier(), "Cannot get launcher extras")) { |
| 471 | return null; |
| 472 | } |
| 473 | final PackageManagerInternal pmi = |
| 474 | LocalServices.getService(PackageManagerInternal.class); |
| 475 | return pmi.getSuspendedPackageLauncherExtras(packageName, user.getIdentifier()); |
| 476 | } |
| 477 | |
| 478 | @Override |
Makoto Onuki | 3a2541e | 2017-01-24 09:00:15 -0800 | [diff] [blame] | 479 | public ApplicationInfo getApplicationInfo( |
| 480 | String callingPackage, String packageName, int flags, UserHandle user) |
Kenny Guy | 7724275 | 2016-01-15 13:29:06 +0000 | [diff] [blame] | 481 | throws RemoteException { |
Sunny Goyal | 145c8f8 | 2018-02-15 14:27:09 -0800 | [diff] [blame] | 482 | if (!canAccessProfile(user.getIdentifier(), "Cannot check package")) { |
Kenny Guy | 7724275 | 2016-01-15 13:29:06 +0000 | [diff] [blame] | 483 | return null; |
| 484 | } |
| 485 | |
Todd Kennedy | 18211fd | 2017-06-06 09:15:46 -0700 | [diff] [blame] | 486 | final int callingUid = injectBinderCallingUid(); |
Kenny Guy | 7724275 | 2016-01-15 13:29:06 +0000 | [diff] [blame] | 487 | long ident = Binder.clearCallingIdentity(); |
| 488 | try { |
Todd Kennedy | 18211fd | 2017-06-06 09:15:46 -0700 | [diff] [blame] | 489 | final PackageManagerInternal pmInt = |
| 490 | LocalServices.getService(PackageManagerInternal.class); |
| 491 | ApplicationInfo info = pmInt.getApplicationInfo(packageName, flags, |
| 492 | callingUid, user.getIdentifier()); |
Kenny Guy | 7724275 | 2016-01-15 13:29:06 +0000 | [diff] [blame] | 493 | return info; |
| 494 | } finally { |
| 495 | Binder.restoreCallingIdentity(ident); |
| 496 | } |
| 497 | } |
| 498 | |
Makoto Onuki | de3c16c | 2017-01-26 11:39:31 -0800 | [diff] [blame] | 499 | private void ensureShortcutPermission(@NonNull String callingPackage) { |
Makoto Onuki | 2d5b465 | 2016-03-11 16:09:54 -0800 | [diff] [blame] | 500 | verifyCallingPackage(callingPackage); |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 501 | if (!mShortcutServiceInternal.hasShortcutHostPermission(getCallingUserId(), |
Makoto Onuki | 634cecb | 2017-10-13 17:10:48 -0700 | [diff] [blame] | 502 | callingPackage, injectBinderCallingPid(), injectBinderCallingUid())) { |
Makoto Onuki | 2d5b465 | 2016-03-11 16:09:54 -0800 | [diff] [blame] | 503 | throw new SecurityException("Caller can't access shortcut information"); |
| 504 | } |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 505 | } |
| 506 | |
| 507 | @Override |
| 508 | public ParceledListSlice getShortcuts(String callingPackage, long changedSince, |
Makoto Onuki | 99302b5 | 2017-03-29 12:42:26 -0700 | [diff] [blame] | 509 | String packageName, List shortcutIds, ComponentName componentName, int flags, |
| 510 | UserHandle targetUser) { |
Makoto Onuki | de3c16c | 2017-01-26 11:39:31 -0800 | [diff] [blame] | 511 | ensureShortcutPermission(callingPackage); |
Sunny Goyal | 145c8f8 | 2018-02-15 14:27:09 -0800 | [diff] [blame] | 512 | if (!canAccessProfile(targetUser.getIdentifier(), "Cannot get shortcuts")) { |
Makoto Onuki | de3c16c | 2017-01-26 11:39:31 -0800 | [diff] [blame] | 513 | return new ParceledListSlice<>(Collections.EMPTY_LIST); |
Makoto Onuki | ac21497 | 2016-04-04 10:19:45 -0700 | [diff] [blame] | 514 | } |
Makoto Onuki | abe8442 | 2016-04-07 09:41:19 -0700 | [diff] [blame] | 515 | if (shortcutIds != null && packageName == null) { |
| 516 | throw new IllegalArgumentException( |
| 517 | "To query by shortcut ID, package name must also be set"); |
| 518 | } |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 519 | |
Felipe Leme | f93ce17 | 2016-06-13 14:19:40 -0700 | [diff] [blame] | 520 | // TODO(b/29399275): Eclipse compiler requires explicit List<ShortcutInfo> cast below. |
| 521 | return new ParceledListSlice<>((List<ShortcutInfo>) |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 522 | mShortcutServiceInternal.getShortcuts(getCallingUserId(), |
Makoto Onuki | abe8442 | 2016-04-07 09:41:19 -0700 | [diff] [blame] | 523 | callingPackage, changedSince, packageName, shortcutIds, |
Makoto Onuki | 634cecb | 2017-10-13 17:10:48 -0700 | [diff] [blame] | 524 | componentName, flags, targetUser.getIdentifier(), |
| 525 | injectBinderCallingPid(), injectBinderCallingUid())); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 526 | } |
| 527 | |
| 528 | @Override |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 529 | public void pinShortcuts(String callingPackage, String packageName, List<String> ids, |
Makoto Onuki | de3c16c | 2017-01-26 11:39:31 -0800 | [diff] [blame] | 530 | UserHandle targetUser) { |
| 531 | ensureShortcutPermission(callingPackage); |
Sunny Goyal | 145c8f8 | 2018-02-15 14:27:09 -0800 | [diff] [blame] | 532 | if (!canAccessProfile(targetUser.getIdentifier(), "Cannot pin shortcuts")) { |
Makoto Onuki | de3c16c | 2017-01-26 11:39:31 -0800 | [diff] [blame] | 533 | return; |
| 534 | } |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 535 | |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 536 | mShortcutServiceInternal.pinShortcuts(getCallingUserId(), |
Makoto Onuki | de3c16c | 2017-01-26 11:39:31 -0800 | [diff] [blame] | 537 | callingPackage, packageName, ids, targetUser.getIdentifier()); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | @Override |
Makoto Onuki | abe8442 | 2016-04-07 09:41:19 -0700 | [diff] [blame] | 541 | public int getShortcutIconResId(String callingPackage, String packageName, String id, |
Makoto Onuki | de3c16c | 2017-01-26 11:39:31 -0800 | [diff] [blame] | 542 | int targetUserId) { |
| 543 | ensureShortcutPermission(callingPackage); |
Sunny Goyal | 145c8f8 | 2018-02-15 14:27:09 -0800 | [diff] [blame] | 544 | if (!canAccessProfile(targetUserId, "Cannot access shortcuts")) { |
Makoto Onuki | ac21497 | 2016-04-04 10:19:45 -0700 | [diff] [blame] | 545 | return 0; |
| 546 | } |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 547 | |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 548 | return mShortcutServiceInternal.getShortcutIconResId(getCallingUserId(), |
Makoto Onuki | de3c16c | 2017-01-26 11:39:31 -0800 | [diff] [blame] | 549 | callingPackage, packageName, id, targetUserId); |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 550 | } |
| 551 | |
| 552 | @Override |
Makoto Onuki | abe8442 | 2016-04-07 09:41:19 -0700 | [diff] [blame] | 553 | public ParcelFileDescriptor getShortcutIconFd(String callingPackage, |
Makoto Onuki | de3c16c | 2017-01-26 11:39:31 -0800 | [diff] [blame] | 554 | String packageName, String id, int targetUserId) { |
| 555 | ensureShortcutPermission(callingPackage); |
Sunny Goyal | 145c8f8 | 2018-02-15 14:27:09 -0800 | [diff] [blame] | 556 | if (!canAccessProfile(targetUserId, "Cannot access shortcuts")) { |
Makoto Onuki | ac21497 | 2016-04-04 10:19:45 -0700 | [diff] [blame] | 557 | return null; |
| 558 | } |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 559 | |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 560 | return mShortcutServiceInternal.getShortcutIconFd(getCallingUserId(), |
Makoto Onuki | de3c16c | 2017-01-26 11:39:31 -0800 | [diff] [blame] | 561 | callingPackage, packageName, id, targetUserId); |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | @Override |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 565 | public boolean hasShortcutHostPermission(String callingPackage) { |
Makoto Onuki | 2d5b465 | 2016-03-11 16:09:54 -0800 | [diff] [blame] | 566 | verifyCallingPackage(callingPackage); |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 567 | return mShortcutServiceInternal.hasShortcutHostPermission(getCallingUserId(), |
Makoto Onuki | 634cecb | 2017-10-13 17:10:48 -0700 | [diff] [blame] | 568 | callingPackage, injectBinderCallingPid(), injectBinderCallingUid()); |
Makoto Onuki | 2d5b465 | 2016-03-11 16:09:54 -0800 | [diff] [blame] | 569 | } |
| 570 | |
| 571 | @Override |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 572 | public boolean startShortcut(String callingPackage, String packageName, String shortcutId, |
Makoto Onuki | de3c16c | 2017-01-26 11:39:31 -0800 | [diff] [blame] | 573 | Rect sourceBounds, Bundle startActivityOptions, int targetUserId) { |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 574 | verifyCallingPackage(callingPackage); |
Sunny Goyal | 145c8f8 | 2018-02-15 14:27:09 -0800 | [diff] [blame] | 575 | if (!canAccessProfile(targetUserId, "Cannot start activity")) { |
Makoto Onuki | de3c16c | 2017-01-26 11:39:31 -0800 | [diff] [blame] | 576 | return false; |
| 577 | } |
Makoto Onuki | ac21497 | 2016-04-04 10:19:45 -0700 | [diff] [blame] | 578 | |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 579 | // Even without the permission, pinned shortcuts are always launchable. |
| 580 | if (!mShortcutServiceInternal.isPinnedByCaller(getCallingUserId(), |
Makoto Onuki | de3c16c | 2017-01-26 11:39:31 -0800 | [diff] [blame] | 581 | callingPackage, packageName, shortcutId, targetUserId)) { |
| 582 | ensureShortcutPermission(callingPackage); |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 583 | } |
| 584 | |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 585 | final Intent[] intents = mShortcutServiceInternal.createShortcutIntents( |
Makoto Onuki | 634cecb | 2017-10-13 17:10:48 -0700 | [diff] [blame] | 586 | getCallingUserId(), callingPackage, packageName, shortcutId, targetUserId, |
| 587 | injectBinderCallingPid(), injectBinderCallingUid()); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 588 | if (intents == null || intents.length == 0) { |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 589 | return false; |
Makoto Onuki | 43204b8 | 2016-03-08 16:16:44 -0800 | [diff] [blame] | 590 | } |
| 591 | // Note the target activity doesn't have to be exported. |
| 592 | |
Makoto Onuki | 7e5c3e8 | 2016-07-22 11:57:05 -0700 | [diff] [blame] | 593 | intents[0].addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Makoto Onuki | 0eed441 | 2016-07-21 11:21:59 -0700 | [diff] [blame] | 594 | intents[0].setSourceBounds(sourceBounds); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 595 | |
| 596 | return startShortcutIntentsAsPublisher( |
Makoto Onuki | de3c16c | 2017-01-26 11:39:31 -0800 | [diff] [blame] | 597 | intents, packageName, startActivityOptions, targetUserId); |
Makoto Onuki | ea11db1 | 2016-06-24 15:17:44 -0700 | [diff] [blame] | 598 | } |
| 599 | |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 600 | private boolean startShortcutIntentsAsPublisher(@NonNull Intent[] intents, |
Makoto Onuki | ea11db1 | 2016-06-24 15:17:44 -0700 | [diff] [blame] | 601 | @NonNull String publisherPackage, Bundle startActivityOptions, int userId) { |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 602 | final int code; |
Makoto Onuki | 43204b8 | 2016-03-08 16:16:44 -0800 | [diff] [blame] | 603 | try { |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 604 | code = mActivityTaskManagerInternal.startActivitiesAsPackage(publisherPackage, |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 605 | userId, intents, startActivityOptions); |
Bryce Lee | 7f93686 | 2017-05-09 15:33:18 -0700 | [diff] [blame] | 606 | if (ActivityManager.isStartResultSuccessful(code)) { |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 607 | return true; // Success |
| 608 | } else { |
| 609 | Log.e(TAG, "Couldn't start activity, code=" + code); |
Makoto Onuki | ea11db1 | 2016-06-24 15:17:44 -0700 | [diff] [blame] | 610 | } |
Bryce Lee | 7f93686 | 2017-05-09 15:33:18 -0700 | [diff] [blame] | 611 | return false; |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 612 | } catch (SecurityException e) { |
| 613 | if (DEBUG) { |
| 614 | Slog.d(TAG, "SecurityException while launching intent", e); |
| 615 | } |
| 616 | return false; |
Makoto Onuki | 43204b8 | 2016-03-08 16:16:44 -0800 | [diff] [blame] | 617 | } |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 618 | } |
| 619 | |
Kenny Guy | 7724275 | 2016-01-15 13:29:06 +0000 | [diff] [blame] | 620 | @Override |
Makoto Onuki | 3a2541e | 2017-01-24 09:00:15 -0800 | [diff] [blame] | 621 | public boolean isActivityEnabled( |
| 622 | String callingPackage, ComponentName component, UserHandle user) |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 623 | throws RemoteException { |
Sunny Goyal | 145c8f8 | 2018-02-15 14:27:09 -0800 | [diff] [blame] | 624 | if (!canAccessProfile(user.getIdentifier(), "Cannot check component")) { |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 625 | return false; |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 626 | } |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 627 | |
Todd Kennedy | 18211fd | 2017-06-06 09:15:46 -0700 | [diff] [blame] | 628 | final int callingUid = injectBinderCallingUid(); |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 629 | long ident = Binder.clearCallingIdentity(); |
| 630 | try { |
Todd Kennedy | 18211fd | 2017-06-06 09:15:46 -0700 | [diff] [blame] | 631 | final PackageManagerInternal pmInt = |
| 632 | LocalServices.getService(PackageManagerInternal.class); |
| 633 | ActivityInfo info = pmInt.getActivityInfo(component, |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 634 | PackageManager.MATCH_DIRECT_BOOT_AWARE |
| 635 | | PackageManager.MATCH_DIRECT_BOOT_UNAWARE, |
Todd Kennedy | 18211fd | 2017-06-06 09:15:46 -0700 | [diff] [blame] | 636 | callingUid, user.getIdentifier()); |
Winson Chung | dcf21d15 | 2014-10-01 14:30:05 -0700 | [diff] [blame] | 637 | return info != null; |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 638 | } finally { |
| 639 | Binder.restoreCallingIdentity(ident); |
| 640 | } |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 641 | } |
| 642 | |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 643 | @Override |
Makoto Onuki | 1a34274 | 2018-04-26 14:56:59 -0700 | [diff] [blame] | 644 | public void startActivityAsUser(IApplicationThread caller, String callingPackage, |
Makoto Onuki | 3a2541e | 2017-01-24 09:00:15 -0800 | [diff] [blame] | 645 | ComponentName component, Rect sourceBounds, |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 646 | Bundle opts, UserHandle user) throws RemoteException { |
Sunny Goyal | 145c8f8 | 2018-02-15 14:27:09 -0800 | [diff] [blame] | 647 | if (!canAccessProfile(user.getIdentifier(), "Cannot start activity")) { |
Makoto Onuki | de3c16c | 2017-01-26 11:39:31 -0800 | [diff] [blame] | 648 | return; |
| 649 | } |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 650 | |
| 651 | Intent launchIntent = new Intent(Intent.ACTION_MAIN); |
| 652 | launchIntent.addCategory(Intent.CATEGORY_LAUNCHER); |
Makoto Onuki | 347a6bd | 2016-07-19 11:13:08 -0700 | [diff] [blame] | 653 | launchIntent.setSourceBounds(sourceBounds); |
| 654 | launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 655 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
Kenny Guy | 2df1892 | 2014-07-17 13:01:25 +0100 | [diff] [blame] | 656 | launchIntent.setPackage(component.getPackageName()); |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 657 | |
Makoto Onuki | 1a34274 | 2018-04-26 14:56:59 -0700 | [diff] [blame] | 658 | boolean canLaunch = false; |
| 659 | |
Todd Kennedy | 18211fd | 2017-06-06 09:15:46 -0700 | [diff] [blame] | 660 | final int callingUid = injectBinderCallingUid(); |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 661 | long ident = Binder.clearCallingIdentity(); |
| 662 | try { |
Todd Kennedy | 18211fd | 2017-06-06 09:15:46 -0700 | [diff] [blame] | 663 | final PackageManagerInternal pmInt = |
| 664 | LocalServices.getService(PackageManagerInternal.class); |
Kenny Guy | 2df1892 | 2014-07-17 13:01:25 +0100 | [diff] [blame] | 665 | // Check that the component actually has Intent.CATEGORY_LAUCNCHER |
| 666 | // as calling startActivityAsUser ignores the category and just |
| 667 | // resolves based on the component if present. |
Todd Kennedy | 18211fd | 2017-06-06 09:15:46 -0700 | [diff] [blame] | 668 | List<ResolveInfo> apps = pmInt.queryIntentActivities(launchIntent, |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 669 | PackageManager.MATCH_DIRECT_BOOT_AWARE |
| 670 | | PackageManager.MATCH_DIRECT_BOOT_UNAWARE, |
Todd Kennedy | 18211fd | 2017-06-06 09:15:46 -0700 | [diff] [blame] | 671 | callingUid, user.getIdentifier()); |
Kenny Guy | 2df1892 | 2014-07-17 13:01:25 +0100 | [diff] [blame] | 672 | final int size = apps.size(); |
| 673 | for (int i = 0; i < size; ++i) { |
| 674 | ActivityInfo activityInfo = apps.get(i).activityInfo; |
| 675 | if (activityInfo.packageName.equals(component.getPackageName()) && |
| 676 | activityInfo.name.equals(component.getClassName())) { |
Sunny Goyal | 06ef5af | 2018-10-16 15:32:41 -0700 | [diff] [blame] | 677 | if (!activityInfo.exported) { |
| 678 | throw new SecurityException("Cannot launch non-exported components " |
| 679 | + component); |
| 680 | } |
| 681 | |
Kenny Guy | 2df1892 | 2014-07-17 13:01:25 +0100 | [diff] [blame] | 682 | // Found an activity with category launcher that matches |
| 683 | // this component so ok to launch. |
Tony Mak | 12917c6 | 2018-01-15 15:17:13 +0000 | [diff] [blame] | 684 | launchIntent.setPackage(null); |
Kenny Guy | 2df1892 | 2014-07-17 13:01:25 +0100 | [diff] [blame] | 685 | launchIntent.setComponent(component); |
Makoto Onuki | 1a34274 | 2018-04-26 14:56:59 -0700 | [diff] [blame] | 686 | canLaunch = true; |
| 687 | break; |
Kenny Guy | 2df1892 | 2014-07-17 13:01:25 +0100 | [diff] [blame] | 688 | } |
| 689 | } |
Makoto Onuki | 1a34274 | 2018-04-26 14:56:59 -0700 | [diff] [blame] | 690 | if (!canLaunch) { |
| 691 | throw new SecurityException("Attempt to launch activity without " |
| 692 | + " category Intent.CATEGORY_LAUNCHER " + component); |
| 693 | } |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 694 | } finally { |
| 695 | Binder.restoreCallingIdentity(ident); |
| 696 | } |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 697 | mActivityTaskManagerInternal.startActivityAsUser(caller, callingPackage, |
Makoto Onuki | 1a34274 | 2018-04-26 14:56:59 -0700 | [diff] [blame] | 698 | launchIntent, opts, user.getIdentifier()); |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 699 | } |
| 700 | |
Kenny Guy | 466d203 | 2014-07-23 12:23:35 +0100 | [diff] [blame] | 701 | @Override |
Makoto Onuki | 1a34274 | 2018-04-26 14:56:59 -0700 | [diff] [blame] | 702 | public void showAppDetailsAsUser(IApplicationThread caller, |
| 703 | String callingPackage, ComponentName component, |
Makoto Onuki | 3a2541e | 2017-01-24 09:00:15 -0800 | [diff] [blame] | 704 | Rect sourceBounds, Bundle opts, UserHandle user) throws RemoteException { |
Sunny Goyal | 145c8f8 | 2018-02-15 14:27:09 -0800 | [diff] [blame] | 705 | if (!canAccessProfile(user.getIdentifier(), "Cannot show app details")) { |
Makoto Onuki | de3c16c | 2017-01-26 11:39:31 -0800 | [diff] [blame] | 706 | return; |
| 707 | } |
Kenny Guy | 466d203 | 2014-07-23 12:23:35 +0100 | [diff] [blame] | 708 | |
Makoto Onuki | 1a34274 | 2018-04-26 14:56:59 -0700 | [diff] [blame] | 709 | final Intent intent; |
Kenny Guy | 466d203 | 2014-07-23 12:23:35 +0100 | [diff] [blame] | 710 | long ident = Binder.clearCallingIdentity(); |
| 711 | try { |
| 712 | String packageName = component.getPackageName(); |
Makoto Onuki | 1a34274 | 2018-04-26 14:56:59 -0700 | [diff] [blame] | 713 | intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, |
Kenny Guy | 466d203 | 2014-07-23 12:23:35 +0100 | [diff] [blame] | 714 | Uri.fromParts("package", packageName, null)); |
Winson | 369aad0 | 2016-02-17 10:35:47 -0800 | [diff] [blame] | 715 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); |
Kenny Guy | 466d203 | 2014-07-23 12:23:35 +0100 | [diff] [blame] | 716 | intent.setSourceBounds(sourceBounds); |
Kenny Guy | 466d203 | 2014-07-23 12:23:35 +0100 | [diff] [blame] | 717 | } finally { |
| 718 | Binder.restoreCallingIdentity(ident); |
| 719 | } |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 720 | mActivityTaskManagerInternal.startActivityAsUser(caller, callingPackage, |
Makoto Onuki | 1a34274 | 2018-04-26 14:56:59 -0700 | [diff] [blame] | 721 | intent, opts, user.getIdentifier()); |
Kenny Guy | 466d203 | 2014-07-23 12:23:35 +0100 | [diff] [blame] | 722 | } |
| 723 | |
Makoto Onuki | 4dbe0de | 2016-03-14 17:31:49 -0700 | [diff] [blame] | 724 | /** Checks if user is a profile of or same as listeningUser. |
| 725 | * and the user is enabled. */ |
Sunny Goyal | 145c8f8 | 2018-02-15 14:27:09 -0800 | [diff] [blame] | 726 | private boolean isEnabledProfileOf(UserHandle listeningUser, UserHandle user, |
Makoto Onuki | 4dbe0de | 2016-03-14 17:31:49 -0700 | [diff] [blame] | 727 | String debugMsg) { |
Sunny Goyal | 145c8f8 | 2018-02-15 14:27:09 -0800 | [diff] [blame] | 728 | return mUserManagerInternal.isProfileAccessible(listeningUser.getIdentifier(), |
| 729 | user.getIdentifier(), debugMsg, false); |
Makoto Onuki | 4dbe0de | 2016-03-14 17:31:49 -0700 | [diff] [blame] | 730 | } |
| 731 | |
Makoto Onuki | c5475d4 | 2016-03-25 10:54:07 -0700 | [diff] [blame] | 732 | @VisibleForTesting |
Makoto Onuki | aa8b94a | 2016-03-17 13:14:05 -0700 | [diff] [blame] | 733 | void postToPackageMonitorHandler(Runnable r) { |
Makoto Onuki | c5475d4 | 2016-03-25 10:54:07 -0700 | [diff] [blame] | 734 | mCallbackHandler.post(r); |
Makoto Onuki | 4dbe0de | 2016-03-14 17:31:49 -0700 | [diff] [blame] | 735 | } |
| 736 | |
| 737 | private class MyPackageMonitor extends PackageMonitor implements ShortcutChangeListener { |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 738 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 739 | // TODO Simplify with lambdas. |
| 740 | |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 741 | @Override |
| 742 | public void onPackageAdded(String packageName, int uid) { |
| 743 | UserHandle user = new UserHandle(getChangingUserId()); |
| 744 | final int n = mListeners.beginBroadcast(); |
Makoto Onuki | 7bdb9ce | 2016-09-15 12:52:57 -0700 | [diff] [blame] | 745 | try { |
| 746 | for (int i = 0; i < n; i++) { |
| 747 | IOnAppsChangedListener listener = mListeners.getBroadcastItem(i); |
| 748 | BroadcastCookie cookie = (BroadcastCookie) mListeners.getBroadcastCookie(i); |
Sunny Goyal | 145c8f8 | 2018-02-15 14:27:09 -0800 | [diff] [blame] | 749 | if (!isEnabledProfileOf(cookie.user, user, "onPackageAdded")) continue; |
Makoto Onuki | 7bdb9ce | 2016-09-15 12:52:57 -0700 | [diff] [blame] | 750 | try { |
| 751 | listener.onPackageAdded(user, packageName); |
| 752 | } catch (RemoteException re) { |
| 753 | Slog.d(TAG, "Callback failed ", re); |
| 754 | } |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 755 | } |
Makoto Onuki | 7bdb9ce | 2016-09-15 12:52:57 -0700 | [diff] [blame] | 756 | } finally { |
| 757 | mListeners.finishBroadcast(); |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 758 | } |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 759 | |
| 760 | super.onPackageAdded(packageName, uid); |
| 761 | } |
| 762 | |
| 763 | @Override |
| 764 | public void onPackageRemoved(String packageName, int uid) { |
| 765 | UserHandle user = new UserHandle(getChangingUserId()); |
| 766 | final int n = mListeners.beginBroadcast(); |
Makoto Onuki | 7bdb9ce | 2016-09-15 12:52:57 -0700 | [diff] [blame] | 767 | try { |
| 768 | for (int i = 0; i < n; i++) { |
| 769 | IOnAppsChangedListener listener = mListeners.getBroadcastItem(i); |
| 770 | BroadcastCookie cookie = (BroadcastCookie) mListeners.getBroadcastCookie(i); |
Sunny Goyal | 145c8f8 | 2018-02-15 14:27:09 -0800 | [diff] [blame] | 771 | if (!isEnabledProfileOf(cookie.user, user, "onPackageRemoved")) continue; |
Makoto Onuki | 7bdb9ce | 2016-09-15 12:52:57 -0700 | [diff] [blame] | 772 | try { |
| 773 | listener.onPackageRemoved(user, packageName); |
| 774 | } catch (RemoteException re) { |
| 775 | Slog.d(TAG, "Callback failed ", re); |
| 776 | } |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 777 | } |
Makoto Onuki | 7bdb9ce | 2016-09-15 12:52:57 -0700 | [diff] [blame] | 778 | } finally { |
| 779 | mListeners.finishBroadcast(); |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 780 | } |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 781 | |
| 782 | super.onPackageRemoved(packageName, uid); |
| 783 | } |
| 784 | |
| 785 | @Override |
| 786 | public void onPackageModified(String packageName) { |
| 787 | UserHandle user = new UserHandle(getChangingUserId()); |
| 788 | final int n = mListeners.beginBroadcast(); |
Makoto Onuki | 7bdb9ce | 2016-09-15 12:52:57 -0700 | [diff] [blame] | 789 | try { |
| 790 | for (int i = 0; i < n; i++) { |
| 791 | IOnAppsChangedListener listener = mListeners.getBroadcastItem(i); |
| 792 | BroadcastCookie cookie = (BroadcastCookie) mListeners.getBroadcastCookie(i); |
Sunny Goyal | 145c8f8 | 2018-02-15 14:27:09 -0800 | [diff] [blame] | 793 | if (!isEnabledProfileOf(cookie.user, user, "onPackageModified")) continue; |
Makoto Onuki | 7bdb9ce | 2016-09-15 12:52:57 -0700 | [diff] [blame] | 794 | try { |
| 795 | listener.onPackageChanged(user, packageName); |
| 796 | } catch (RemoteException re) { |
| 797 | Slog.d(TAG, "Callback failed ", re); |
| 798 | } |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 799 | } |
Makoto Onuki | 7bdb9ce | 2016-09-15 12:52:57 -0700 | [diff] [blame] | 800 | } finally { |
| 801 | mListeners.finishBroadcast(); |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 802 | } |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 803 | |
| 804 | super.onPackageModified(packageName); |
| 805 | } |
| 806 | |
| 807 | @Override |
| 808 | public void onPackagesAvailable(String[] packages) { |
| 809 | UserHandle user = new UserHandle(getChangingUserId()); |
| 810 | final int n = mListeners.beginBroadcast(); |
Makoto Onuki | 7bdb9ce | 2016-09-15 12:52:57 -0700 | [diff] [blame] | 811 | try { |
| 812 | for (int i = 0; i < n; i++) { |
| 813 | IOnAppsChangedListener listener = mListeners.getBroadcastItem(i); |
| 814 | BroadcastCookie cookie = (BroadcastCookie) mListeners.getBroadcastCookie(i); |
Sunny Goyal | 145c8f8 | 2018-02-15 14:27:09 -0800 | [diff] [blame] | 815 | if (!isEnabledProfileOf(cookie.user, user, "onPackagesAvailable")) continue; |
Makoto Onuki | 7bdb9ce | 2016-09-15 12:52:57 -0700 | [diff] [blame] | 816 | try { |
| 817 | listener.onPackagesAvailable(user, packages, isReplacing()); |
| 818 | } catch (RemoteException re) { |
| 819 | Slog.d(TAG, "Callback failed ", re); |
| 820 | } |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 821 | } |
Makoto Onuki | 7bdb9ce | 2016-09-15 12:52:57 -0700 | [diff] [blame] | 822 | } finally { |
| 823 | mListeners.finishBroadcast(); |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 824 | } |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 825 | |
| 826 | super.onPackagesAvailable(packages); |
| 827 | } |
| 828 | |
| 829 | @Override |
| 830 | public void onPackagesUnavailable(String[] packages) { |
| 831 | UserHandle user = new UserHandle(getChangingUserId()); |
| 832 | final int n = mListeners.beginBroadcast(); |
Makoto Onuki | 7bdb9ce | 2016-09-15 12:52:57 -0700 | [diff] [blame] | 833 | try { |
| 834 | for (int i = 0; i < n; i++) { |
| 835 | IOnAppsChangedListener listener = mListeners.getBroadcastItem(i); |
| 836 | BroadcastCookie cookie = (BroadcastCookie) mListeners.getBroadcastCookie(i); |
Sunny Goyal | 145c8f8 | 2018-02-15 14:27:09 -0800 | [diff] [blame] | 837 | if (!isEnabledProfileOf(cookie.user, user, "onPackagesUnavailable")) continue; |
Makoto Onuki | 7bdb9ce | 2016-09-15 12:52:57 -0700 | [diff] [blame] | 838 | try { |
| 839 | listener.onPackagesUnavailable(user, packages, isReplacing()); |
| 840 | } catch (RemoteException re) { |
| 841 | Slog.d(TAG, "Callback failed ", re); |
| 842 | } |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 843 | } |
Makoto Onuki | 7bdb9ce | 2016-09-15 12:52:57 -0700 | [diff] [blame] | 844 | } finally { |
| 845 | mListeners.finishBroadcast(); |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 846 | } |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 847 | |
| 848 | super.onPackagesUnavailable(packages); |
| 849 | } |
| 850 | |
Kenny Guy | 7724275 | 2016-01-15 13:29:06 +0000 | [diff] [blame] | 851 | @Override |
Suprabh Shukla | 19b41f3 | 2018-03-26 22:35:13 -0700 | [diff] [blame] | 852 | public void onPackagesSuspended(String[] packages, Bundle launcherExtras) { |
Kenny Guy | 7724275 | 2016-01-15 13:29:06 +0000 | [diff] [blame] | 853 | UserHandle user = new UserHandle(getChangingUserId()); |
| 854 | final int n = mListeners.beginBroadcast(); |
Makoto Onuki | 7bdb9ce | 2016-09-15 12:52:57 -0700 | [diff] [blame] | 855 | try { |
| 856 | for (int i = 0; i < n; i++) { |
| 857 | IOnAppsChangedListener listener = mListeners.getBroadcastItem(i); |
| 858 | BroadcastCookie cookie = (BroadcastCookie) mListeners.getBroadcastCookie(i); |
Sunny Goyal | 145c8f8 | 2018-02-15 14:27:09 -0800 | [diff] [blame] | 859 | if (!isEnabledProfileOf(cookie.user, user, "onPackagesSuspended")) continue; |
Makoto Onuki | 7bdb9ce | 2016-09-15 12:52:57 -0700 | [diff] [blame] | 860 | try { |
Suprabh Shukla | 19b41f3 | 2018-03-26 22:35:13 -0700 | [diff] [blame] | 861 | listener.onPackagesSuspended(user, packages, launcherExtras); |
Makoto Onuki | 7bdb9ce | 2016-09-15 12:52:57 -0700 | [diff] [blame] | 862 | } catch (RemoteException re) { |
| 863 | Slog.d(TAG, "Callback failed ", re); |
| 864 | } |
Kenny Guy | 7724275 | 2016-01-15 13:29:06 +0000 | [diff] [blame] | 865 | } |
Makoto Onuki | 7bdb9ce | 2016-09-15 12:52:57 -0700 | [diff] [blame] | 866 | } finally { |
| 867 | mListeners.finishBroadcast(); |
Kenny Guy | 7724275 | 2016-01-15 13:29:06 +0000 | [diff] [blame] | 868 | } |
Kenny Guy | 7724275 | 2016-01-15 13:29:06 +0000 | [diff] [blame] | 869 | |
Suprabh Shukla | 19b41f3 | 2018-03-26 22:35:13 -0700 | [diff] [blame] | 870 | super.onPackagesSuspended(packages, launcherExtras); |
Kenny Guy | 7724275 | 2016-01-15 13:29:06 +0000 | [diff] [blame] | 871 | } |
| 872 | |
| 873 | @Override |
| 874 | public void onPackagesUnsuspended(String[] packages) { |
| 875 | UserHandle user = new UserHandle(getChangingUserId()); |
| 876 | final int n = mListeners.beginBroadcast(); |
Makoto Onuki | 7bdb9ce | 2016-09-15 12:52:57 -0700 | [diff] [blame] | 877 | try { |
| 878 | for (int i = 0; i < n; i++) { |
| 879 | IOnAppsChangedListener listener = mListeners.getBroadcastItem(i); |
| 880 | BroadcastCookie cookie = (BroadcastCookie) mListeners.getBroadcastCookie(i); |
Sunny Goyal | 145c8f8 | 2018-02-15 14:27:09 -0800 | [diff] [blame] | 881 | if (!isEnabledProfileOf(cookie.user, user, "onPackagesUnsuspended")) continue; |
Makoto Onuki | 7bdb9ce | 2016-09-15 12:52:57 -0700 | [diff] [blame] | 882 | try { |
| 883 | listener.onPackagesUnsuspended(user, packages); |
| 884 | } catch (RemoteException re) { |
| 885 | Slog.d(TAG, "Callback failed ", re); |
| 886 | } |
Kenny Guy | 7724275 | 2016-01-15 13:29:06 +0000 | [diff] [blame] | 887 | } |
Makoto Onuki | 7bdb9ce | 2016-09-15 12:52:57 -0700 | [diff] [blame] | 888 | } finally { |
| 889 | mListeners.finishBroadcast(); |
Kenny Guy | 7724275 | 2016-01-15 13:29:06 +0000 | [diff] [blame] | 890 | } |
Kenny Guy | 7724275 | 2016-01-15 13:29:06 +0000 | [diff] [blame] | 891 | |
| 892 | super.onPackagesUnsuspended(packages); |
| 893 | } |
| 894 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 895 | @Override |
| 896 | public void onShortcutChanged(@NonNull String packageName, |
Makoto Onuki | 4dbe0de | 2016-03-14 17:31:49 -0700 | [diff] [blame] | 897 | @UserIdInt int userId) { |
Makoto Onuki | aa8b94a | 2016-03-17 13:14:05 -0700 | [diff] [blame] | 898 | postToPackageMonitorHandler(() -> onShortcutChangedInner(packageName, userId)); |
Makoto Onuki | 4dbe0de | 2016-03-14 17:31:49 -0700 | [diff] [blame] | 899 | } |
| 900 | |
| 901 | private void onShortcutChangedInner(@NonNull String packageName, |
| 902 | @UserIdInt int userId) { |
Makoto Onuki | 7bdb9ce | 2016-09-15 12:52:57 -0700 | [diff] [blame] | 903 | final int n = mListeners.beginBroadcast(); |
Makoto Onuki | 02f338e | 2016-07-29 09:40:40 -0700 | [diff] [blame] | 904 | try { |
| 905 | final UserHandle user = UserHandle.of(userId); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 906 | |
Makoto Onuki | 02f338e | 2016-07-29 09:40:40 -0700 | [diff] [blame] | 907 | for (int i = 0; i < n; i++) { |
| 908 | IOnAppsChangedListener listener = mListeners.getBroadcastItem(i); |
| 909 | BroadcastCookie cookie = (BroadcastCookie) mListeners.getBroadcastCookie(i); |
Sunny Goyal | 145c8f8 | 2018-02-15 14:27:09 -0800 | [diff] [blame] | 910 | if (!isEnabledProfileOf(cookie.user, user, "onShortcutChanged")) continue; |
Makoto Onuki | 2d5b465 | 2016-03-11 16:09:54 -0800 | [diff] [blame] | 911 | |
Makoto Onuki | 02f338e | 2016-07-29 09:40:40 -0700 | [diff] [blame] | 912 | final int launcherUserId = cookie.user.getIdentifier(); |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 913 | |
Makoto Onuki | 02f338e | 2016-07-29 09:40:40 -0700 | [diff] [blame] | 914 | // Make sure the caller has the permission. |
| 915 | if (!mShortcutServiceInternal.hasShortcutHostPermission( |
Makoto Onuki | 634cecb | 2017-10-13 17:10:48 -0700 | [diff] [blame] | 916 | launcherUserId, cookie.packageName, |
| 917 | cookie.callingPid, cookie.callingUid)) { |
Makoto Onuki | 02f338e | 2016-07-29 09:40:40 -0700 | [diff] [blame] | 918 | continue; |
| 919 | } |
| 920 | // Each launcher has a different set of pinned shortcuts, so we need to do a |
| 921 | // query in here. |
| 922 | // (As of now, only one launcher has the permission at a time, so it's bit |
| 923 | // moot, but we may change the permission model eventually.) |
| 924 | final List<ShortcutInfo> list = |
| 925 | mShortcutServiceInternal.getShortcuts(launcherUserId, |
| 926 | cookie.packageName, |
| 927 | /* changedSince= */ 0, packageName, /* shortcutIds=*/ null, |
| 928 | /* component= */ null, |
| 929 | ShortcutQuery.FLAG_GET_KEY_FIELDS_ONLY |
Makoto Onuki | 634cecb | 2017-10-13 17:10:48 -0700 | [diff] [blame] | 930 | | ShortcutQuery.FLAG_MATCH_ALL_KINDS_WITH_ALL_PINNED |
| 931 | , userId, cookie.callingPid, cookie.callingUid); |
Makoto Onuki | 02f338e | 2016-07-29 09:40:40 -0700 | [diff] [blame] | 932 | try { |
| 933 | listener.onShortcutChanged(user, packageName, |
| 934 | new ParceledListSlice<>(list)); |
| 935 | } catch (RemoteException re) { |
| 936 | Slog.d(TAG, "Callback failed ", re); |
| 937 | } |
Makoto Onuki | 4dbe0de | 2016-03-14 17:31:49 -0700 | [diff] [blame] | 938 | } |
Makoto Onuki | 02f338e | 2016-07-29 09:40:40 -0700 | [diff] [blame] | 939 | } catch (RuntimeException e) { |
| 940 | // When the user is locked we get IllegalState, so just catch all. |
| 941 | Log.w(TAG, e.getMessage(), e); |
Makoto Onuki | 7bdb9ce | 2016-09-15 12:52:57 -0700 | [diff] [blame] | 942 | } finally { |
| 943 | mListeners.finishBroadcast(); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 944 | } |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 945 | } |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 946 | } |
| 947 | |
| 948 | class PackageCallbackList<T extends IInterface> extends RemoteCallbackList<T> { |
| 949 | @Override |
| 950 | public void onCallbackDied(T callback, Object cookie) { |
| 951 | checkCallbackCount(); |
| 952 | } |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 953 | } |
| 954 | } |
Nicolas Prevot | b683019 | 2015-06-26 13:45:12 -0700 | [diff] [blame] | 955 | } |