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; |
Kenny Guy | 53fa4ec | 2014-04-29 14:24:18 +0100 | [diff] [blame] | 23 | import android.app.AppGlobals; |
Makoto Onuki | 1a34274 | 2018-04-26 14:56:59 -0700 | [diff] [blame] | 24 | import android.app.IApplicationThread; |
Sunny Goyal | a6be88a | 2017-01-12 16:27:58 -0800 | [diff] [blame] | 25 | import android.app.PendingIntent; |
Ricky Wai | e6a9038 | 2019-01-14 11:34:10 +0000 | [diff] [blame] | 26 | import android.app.admin.DevicePolicyManager; |
Varun Shah | 2546cef | 2019-01-11 15:50:54 -0800 | [diff] [blame] | 27 | import android.app.usage.UsageStatsManagerInternal; |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 28 | import android.content.ComponentName; |
| 29 | import android.content.Context; |
| 30 | import android.content.Intent; |
Sunny Goyal | a6be88a | 2017-01-12 16:27:58 -0800 | [diff] [blame] | 31 | import android.content.IntentSender; |
Kenny Guy | 53fa4ec | 2014-04-29 14:24:18 +0100 | [diff] [blame] | 32 | import android.content.pm.ActivityInfo; |
Kenny Guy | 7724275 | 2016-01-15 13:29:06 +0000 | [diff] [blame] | 33 | import android.content.pm.ApplicationInfo; |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 34 | import android.content.pm.ILauncherApps; |
| 35 | import android.content.pm.IOnAppsChangedListener; |
Jon Miranda | 2b340a2 | 2019-01-25 14:03:49 -0800 | [diff] [blame] | 36 | import android.content.pm.IPackageInstallerCallback; |
Ricky Wai | e346a49 | 2019-01-21 14:54:32 +0000 | [diff] [blame] | 37 | import android.content.pm.LauncherApps; |
Makoto Onuki | 4dbe0de | 2016-03-14 17:31:49 -0700 | [diff] [blame] | 38 | import android.content.pm.LauncherApps.ShortcutQuery; |
Kenny Guy | 53fa4ec | 2014-04-29 14:24:18 +0100 | [diff] [blame] | 39 | import android.content.pm.PackageInfo; |
Jon Miranda | 2b340a2 | 2019-01-25 14:03:49 -0800 | [diff] [blame] | 40 | import android.content.pm.PackageInstaller.SessionInfo; |
Jeff Sharkey | cd65448 | 2016-01-08 17:42:11 -0700 | [diff] [blame] | 41 | import android.content.pm.PackageManager; |
Todd Kennedy | 18211fd | 2017-06-06 09:15:46 -0700 | [diff] [blame] | 42 | import android.content.pm.PackageManagerInternal; |
Sunny Goyal | 6cbc2fe | 2015-11-24 09:34:20 -0800 | [diff] [blame] | 43 | import android.content.pm.ParceledListSlice; |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 44 | import android.content.pm.ResolveInfo; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 45 | import android.content.pm.ShortcutInfo; |
| 46 | import android.content.pm.ShortcutServiceInternal; |
| 47 | import android.content.pm.ShortcutServiceInternal.ShortcutChangeListener; |
Ricky Wai | e346a49 | 2019-01-21 14:54:32 +0000 | [diff] [blame] | 48 | import android.content.pm.Signature; |
| 49 | import android.content.pm.SigningInfo; |
Makoto Onuki | e70b29e | 2018-04-03 16:44:39 -0700 | [diff] [blame] | 50 | import android.content.pm.UserInfo; |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 51 | import android.graphics.Rect; |
Kenny Guy | 466d203 | 2014-07-23 12:23:35 +0100 | [diff] [blame] | 52 | import android.net.Uri; |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 53 | import android.os.Binder; |
| 54 | import android.os.Bundle; |
Makoto Onuki | c5475d4 | 2016-03-25 10:54:07 -0700 | [diff] [blame] | 55 | import android.os.Handler; |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 56 | import android.os.IInterface; |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 57 | import android.os.ParcelFileDescriptor; |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 58 | import android.os.RemoteCallbackList; |
| 59 | import android.os.RemoteException; |
Jon Miranda | 2b340a2 | 2019-01-25 14:03:49 -0800 | [diff] [blame] | 60 | import android.os.ServiceManager; |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 61 | import android.os.UserHandle; |
Makoto Onuki | e70b29e | 2018-04-03 16:44:39 -0700 | [diff] [blame] | 62 | import android.os.UserManager; |
Sunny Goyal | 145c8f8 | 2018-02-15 14:27:09 -0800 | [diff] [blame] | 63 | import android.os.UserManagerInternal; |
Kenny Guy | 466d203 | 2014-07-23 12:23:35 +0100 | [diff] [blame] | 64 | import android.provider.Settings; |
Ricky Wai | e346a49 | 2019-01-21 14:54:32 +0000 | [diff] [blame] | 65 | import android.util.ByteStringUtils; |
Amith Yamasani | 932249d | 2014-05-01 14:39:35 -0700 | [diff] [blame] | 66 | import android.util.Log; |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 67 | import android.util.Slog; |
| 68 | |
Makoto Onuki | 7a6a05f | 2016-03-10 17:01:08 -0800 | [diff] [blame] | 69 | import com.android.internal.annotations.VisibleForTesting; |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 70 | import com.android.internal.content.PackageMonitor; |
Makoto Onuki | c5475d4 | 2016-03-25 10:54:07 -0700 | [diff] [blame] | 71 | import com.android.internal.os.BackgroundThread; |
Ricky Wai | e346a49 | 2019-01-21 14:54:32 +0000 | [diff] [blame] | 72 | import com.android.internal.util.DumpUtils; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 73 | import com.android.internal.util.Preconditions; |
Ricky Wai | e346a49 | 2019-01-21 14:54:32 +0000 | [diff] [blame] | 74 | import com.android.internal.util.StatLogger; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 75 | import com.android.server.LocalServices; |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 76 | import com.android.server.SystemService; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 77 | import com.android.server.wm.ActivityTaskManagerInternal; |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 78 | |
Ricky Wai | e346a49 | 2019-01-21 14:54:32 +0000 | [diff] [blame] | 79 | import java.io.FileDescriptor; |
| 80 | import java.io.PrintWriter; |
| 81 | import java.security.MessageDigest; |
| 82 | import java.security.NoSuchAlgorithmException; |
Ricky Wai | cf134eb | 2018-10-10 09:26:32 +0100 | [diff] [blame] | 83 | import java.util.ArrayList; |
Ricky Wai | e346a49 | 2019-01-21 14:54:32 +0000 | [diff] [blame] | 84 | import java.util.Arrays; |
Makoto Onuki | de3c16c | 2017-01-26 11:39:31 -0800 | [diff] [blame] | 85 | import java.util.Collections; |
Ricky Wai | cf134eb | 2018-10-10 09:26:32 +0100 | [diff] [blame] | 86 | import java.util.HashSet; |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 87 | import java.util.List; |
Ricky Wai | e346a49 | 2019-01-21 14:54:32 +0000 | [diff] [blame] | 88 | import java.util.Set; |
| 89 | import java.util.concurrent.ConcurrentHashMap; |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 90 | |
| 91 | /** |
| 92 | * Service that manages requests and callbacks for launchers that support |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 93 | * managed profiles. |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 94 | */ |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 95 | public class LauncherAppsService extends SystemService { |
| 96 | |
| 97 | private final LauncherAppsImpl mLauncherAppsImpl; |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 98 | |
| 99 | public LauncherAppsService(Context context) { |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 100 | super(context); |
| 101 | mLauncherAppsImpl = new LauncherAppsImpl(context); |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 102 | } |
| 103 | |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 104 | @Override |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 105 | public void onStart() { |
| 106 | publishBinderService(Context.LAUNCHER_APPS_SERVICE, mLauncherAppsImpl); |
| 107 | } |
| 108 | |
Makoto Onuki | 4dbe0de | 2016-03-14 17:31:49 -0700 | [diff] [blame] | 109 | static class BroadcastCookie { |
| 110 | public final UserHandle user; |
| 111 | public final String packageName; |
Makoto Onuki | 634cecb | 2017-10-13 17:10:48 -0700 | [diff] [blame] | 112 | public final int callingUid; |
| 113 | public final int callingPid; |
Makoto Onuki | 4dbe0de | 2016-03-14 17:31:49 -0700 | [diff] [blame] | 114 | |
Makoto Onuki | 634cecb | 2017-10-13 17:10:48 -0700 | [diff] [blame] | 115 | BroadcastCookie(UserHandle userHandle, String packageName, int callingPid, int callingUid) { |
Makoto Onuki | 4dbe0de | 2016-03-14 17:31:49 -0700 | [diff] [blame] | 116 | this.user = userHandle; |
| 117 | this.packageName = packageName; |
Makoto Onuki | 634cecb | 2017-10-13 17:10:48 -0700 | [diff] [blame] | 118 | this.callingUid = callingUid; |
| 119 | this.callingPid = callingPid; |
Makoto Onuki | 4dbe0de | 2016-03-14 17:31:49 -0700 | [diff] [blame] | 120 | } |
| 121 | } |
| 122 | |
Makoto Onuki | 7a6a05f | 2016-03-10 17:01:08 -0800 | [diff] [blame] | 123 | @VisibleForTesting |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 124 | static class LauncherAppsImpl extends ILauncherApps.Stub { |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 125 | private static final boolean DEBUG = false; |
| 126 | private static final String TAG = "LauncherAppsService"; |
Ricky Wai | e346a49 | 2019-01-21 14:54:32 +0000 | [diff] [blame] | 127 | |
| 128 | // Stats |
| 129 | @VisibleForTesting |
| 130 | interface Stats { |
| 131 | int INIT_VOUCHED_SIGNATURES = 0; |
| 132 | int COUNT = INIT_VOUCHED_SIGNATURES + 1; |
| 133 | } |
| 134 | private final StatLogger mStatLogger = new StatLogger(new String[] { |
| 135 | "initVouchedSignatures" |
| 136 | }); |
| 137 | |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 138 | private final Context mContext; |
Makoto Onuki | e70b29e | 2018-04-03 16:44:39 -0700 | [diff] [blame] | 139 | private final UserManager mUm; |
Sunny Goyal | 145c8f8 | 2018-02-15 14:27:09 -0800 | [diff] [blame] | 140 | private final UserManagerInternal mUserManagerInternal; |
Varun Shah | 2546cef | 2019-01-11 15:50:54 -0800 | [diff] [blame] | 141 | private final UsageStatsManagerInternal mUsageStatsManagerInternal; |
Makoto Onuki | ea11db1 | 2016-06-24 15:17:44 -0700 | [diff] [blame] | 142 | private final ActivityManagerInternal mActivityManagerInternal; |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 143 | private final ActivityTaskManagerInternal mActivityTaskManagerInternal; |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 144 | private final ShortcutServiceInternal mShortcutServiceInternal; |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 145 | private final PackageCallbackList<IOnAppsChangedListener> mListeners |
| 146 | = new PackageCallbackList<IOnAppsChangedListener>(); |
Ricky Wai | e6a9038 | 2019-01-14 11:34:10 +0000 | [diff] [blame] | 147 | private final DevicePolicyManager mDpm; |
Ricky Wai | e346a49 | 2019-01-21 14:54:32 +0000 | [diff] [blame] | 148 | private final ConcurrentHashMap<UserHandle, Set<String>> mVouchedSignaturesByUser; |
| 149 | private final Set<String> mVouchProviders; |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 150 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 151 | private final MyPackageMonitor mPackageMonitor = new MyPackageMonitor(); |
Ricky Wai | e346a49 | 2019-01-21 14:54:32 +0000 | [diff] [blame] | 152 | private final VouchesChangedMonitor mVouchesChangedMonitor = new VouchesChangedMonitor(); |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 153 | |
Makoto Onuki | c5475d4 | 2016-03-25 10:54:07 -0700 | [diff] [blame] | 154 | private final Handler mCallbackHandler; |
| 155 | |
Ricky Wai | e346a49 | 2019-01-21 14:54:32 +0000 | [diff] [blame] | 156 | private final Object mVouchedSignaturesLocked = new Object(); |
| 157 | |
Jon Miranda | 2b340a2 | 2019-01-25 14:03:49 -0800 | [diff] [blame] | 158 | private PackageInstallerService mPackageInstallerService; |
| 159 | |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 160 | public LauncherAppsImpl(Context context) { |
| 161 | mContext = context; |
Makoto Onuki | e70b29e | 2018-04-03 16:44:39 -0700 | [diff] [blame] | 162 | mUm = (UserManager) mContext.getSystemService(Context.USER_SERVICE); |
Sunny Goyal | 145c8f8 | 2018-02-15 14:27:09 -0800 | [diff] [blame] | 163 | mUserManagerInternal = Preconditions.checkNotNull( |
| 164 | LocalServices.getService(UserManagerInternal.class)); |
Varun Shah | 2546cef | 2019-01-11 15:50:54 -0800 | [diff] [blame] | 165 | mUsageStatsManagerInternal = Preconditions.checkNotNull( |
| 166 | LocalServices.getService(UsageStatsManagerInternal.class)); |
Makoto Onuki | ea11db1 | 2016-06-24 15:17:44 -0700 | [diff] [blame] | 167 | mActivityManagerInternal = Preconditions.checkNotNull( |
| 168 | LocalServices.getService(ActivityManagerInternal.class)); |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 169 | mActivityTaskManagerInternal = Preconditions.checkNotNull( |
| 170 | LocalServices.getService(ActivityTaskManagerInternal.class)); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 171 | mShortcutServiceInternal = Preconditions.checkNotNull( |
| 172 | LocalServices.getService(ShortcutServiceInternal.class)); |
| 173 | mShortcutServiceInternal.addListener(mPackageMonitor); |
Makoto Onuki | c5475d4 | 2016-03-25 10:54:07 -0700 | [diff] [blame] | 174 | mCallbackHandler = BackgroundThread.getHandler(); |
Ricky Wai | e6a9038 | 2019-01-14 11:34:10 +0000 | [diff] [blame] | 175 | mDpm = (DevicePolicyManager) mContext.getSystemService(Context.DEVICE_POLICY_SERVICE); |
Ricky Wai | e346a49 | 2019-01-21 14:54:32 +0000 | [diff] [blame] | 176 | mVouchedSignaturesByUser = new ConcurrentHashMap<>(); |
| 177 | mVouchProviders = Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>()); |
| 178 | mVouchesChangedMonitor.register(mContext, UserHandle.ALL, true, mCallbackHandler); |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 179 | } |
| 180 | |
Makoto Onuki | 2d5b465 | 2016-03-11 16:09:54 -0800 | [diff] [blame] | 181 | @VisibleForTesting |
| 182 | int injectBinderCallingUid() { |
| 183 | return getCallingUid(); |
| 184 | } |
| 185 | |
Makoto Onuki | 634cecb | 2017-10-13 17:10:48 -0700 | [diff] [blame] | 186 | @VisibleForTesting |
| 187 | int injectBinderCallingPid() { |
| 188 | return getCallingPid(); |
| 189 | } |
| 190 | |
Makoto Onuki | ac21497 | 2016-04-04 10:19:45 -0700 | [diff] [blame] | 191 | final int injectCallingUserId() { |
| 192 | return UserHandle.getUserId(injectBinderCallingUid()); |
| 193 | } |
| 194 | |
| 195 | @VisibleForTesting |
| 196 | long injectClearCallingIdentity() { |
| 197 | return Binder.clearCallingIdentity(); |
| 198 | } |
| 199 | |
| 200 | // Injection point. |
| 201 | @VisibleForTesting |
| 202 | void injectRestoreCallingIdentity(long token) { |
| 203 | Binder.restoreCallingIdentity(token); |
| 204 | } |
| 205 | |
Makoto Onuki | 2d5b465 | 2016-03-11 16:09:54 -0800 | [diff] [blame] | 206 | private int getCallingUserId() { |
| 207 | return UserHandle.getUserId(injectBinderCallingUid()); |
| 208 | } |
| 209 | |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 210 | /* |
Jon Miranda | 2b340a2 | 2019-01-25 14:03:49 -0800 | [diff] [blame] | 211 | * @see android.content.pm.ILauncherApps#addOnAppsChangedListener |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 212 | */ |
| 213 | @Override |
Makoto Onuki | 4dbe0de | 2016-03-14 17:31:49 -0700 | [diff] [blame] | 214 | public void addOnAppsChangedListener(String callingPackage, IOnAppsChangedListener listener) |
| 215 | throws RemoteException { |
Makoto Onuki | 5ba0d3e | 2016-04-11 14:03:46 -0700 | [diff] [blame] | 216 | verifyCallingPackage(callingPackage); |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 217 | synchronized (mListeners) { |
Amith Yamasani | 932249d | 2014-05-01 14:39:35 -0700 | [diff] [blame] | 218 | if (DEBUG) { |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 219 | Log.d(TAG, "Adding listener from " + Binder.getCallingUserHandle()); |
Amith Yamasani | 932249d | 2014-05-01 14:39:35 -0700 | [diff] [blame] | 220 | } |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 221 | if (mListeners.getRegisteredCallbackCount() == 0) { |
| 222 | if (DEBUG) { |
| 223 | Log.d(TAG, "Starting package monitoring"); |
| 224 | } |
| 225 | startWatchingPackageBroadcasts(); |
| 226 | } |
| 227 | mListeners.unregister(listener); |
Makoto Onuki | 4dbe0de | 2016-03-14 17:31:49 -0700 | [diff] [blame] | 228 | mListeners.register(listener, new BroadcastCookie(UserHandle.of(getCallingUserId()), |
Makoto Onuki | 634cecb | 2017-10-13 17:10:48 -0700 | [diff] [blame] | 229 | callingPackage, injectBinderCallingPid(), injectBinderCallingUid())); |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 230 | } |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 231 | } |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 232 | |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 233 | /* |
Jon Miranda | 2b340a2 | 2019-01-25 14:03:49 -0800 | [diff] [blame] | 234 | * @see android.content.pm.ILauncherApps#removeOnAppsChangedListener |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 235 | */ |
| 236 | @Override |
| 237 | public void removeOnAppsChangedListener(IOnAppsChangedListener listener) |
| 238 | throws RemoteException { |
| 239 | synchronized (mListeners) { |
| 240 | if (DEBUG) { |
| 241 | Log.d(TAG, "Removing listener from " + Binder.getCallingUserHandle()); |
| 242 | } |
| 243 | mListeners.unregister(listener); |
| 244 | if (mListeners.getRegisteredCallbackCount() == 0) { |
| 245 | stopWatchingPackageBroadcasts(); |
| 246 | } |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | /** |
Jon Miranda | 2b340a2 | 2019-01-25 14:03:49 -0800 | [diff] [blame] | 251 | * @see android.content.pm.ILauncherApps#registerPackageInstallerCallback |
| 252 | */ |
| 253 | @Override |
| 254 | public void registerPackageInstallerCallback(String callingPackage, |
| 255 | IPackageInstallerCallback callback) { |
| 256 | verifyCallingPackage(callingPackage); |
| 257 | UserHandle callingIdUserHandle = new UserHandle(getCallingUserId()); |
| 258 | getPackageInstallerService().registerCallback(callback, eventUserId -> |
| 259 | isEnabledProfileOf(callingIdUserHandle, |
| 260 | new UserHandle(eventUserId), "shouldReceiveEvent")); |
| 261 | } |
| 262 | |
| 263 | @Override |
| 264 | public ParceledListSlice<SessionInfo> getAllSessions(String callingPackage) { |
| 265 | verifyCallingPackage(callingPackage); |
| 266 | List<SessionInfo> sessionInfos = new ArrayList<>(); |
| 267 | int[] userIds = mUm.getEnabledProfileIds(getCallingUserId()); |
| 268 | long token = Binder.clearCallingIdentity(); |
| 269 | try { |
| 270 | for (int userId : userIds) { |
| 271 | sessionInfos.addAll(getPackageInstallerService().getAllSessions(userId) |
| 272 | .getList()); |
| 273 | } |
| 274 | } finally { |
| 275 | Binder.restoreCallingIdentity(token); |
| 276 | } |
| 277 | return new ParceledListSlice<>(sessionInfos); |
| 278 | } |
| 279 | |
| 280 | private PackageInstallerService getPackageInstallerService() { |
| 281 | if (mPackageInstallerService == null) { |
| 282 | mPackageInstallerService = ((PackageInstallerService) ((PackageManagerService) |
| 283 | ServiceManager.getService("package")).getPackageInstaller()); |
| 284 | } |
| 285 | return mPackageInstallerService; |
| 286 | } |
| 287 | |
| 288 | /** |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 289 | * Register a receiver to watch for package broadcasts |
| 290 | */ |
| 291 | private void startWatchingPackageBroadcasts() { |
Makoto Onuki | c5475d4 | 2016-03-25 10:54:07 -0700 | [diff] [blame] | 292 | mPackageMonitor.register(mContext, UserHandle.ALL, true, mCallbackHandler); |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | /** |
| 296 | * Unregister package broadcast receiver |
| 297 | */ |
| 298 | private void stopWatchingPackageBroadcasts() { |
Amith Yamasani | 932249d | 2014-05-01 14:39:35 -0700 | [diff] [blame] | 299 | if (DEBUG) { |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 300 | Log.d(TAG, "Stopped watching for packages"); |
Amith Yamasani | 932249d | 2014-05-01 14:39:35 -0700 | [diff] [blame] | 301 | } |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 302 | mPackageMonitor.unregister(); |
| 303 | } |
| 304 | |
| 305 | void checkCallbackCount() { |
| 306 | synchronized (mListeners) { |
| 307 | if (DEBUG) { |
| 308 | Log.d(TAG, "Callback count = " + mListeners.getRegisteredCallbackCount()); |
| 309 | } |
| 310 | if (mListeners.getRegisteredCallbackCount() == 0) { |
| 311 | stopWatchingPackageBroadcasts(); |
| 312 | } |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 313 | } |
| 314 | } |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 315 | |
Makoto Onuki | de3c16c | 2017-01-26 11:39:31 -0800 | [diff] [blame] | 316 | /** |
| 317 | * Checks if the calling user is in the same group as {@code targetUser}, and allowed |
| 318 | * to access it. |
| 319 | * |
| 320 | * @return TRUE if the calling user can access {@code targetUserId}. FALSE if not *but |
| 321 | * they're still in the same profile group*. |
| 322 | * |
| 323 | * @throws SecurityException if the calling user and {@code targetUser} are not in the same |
| 324 | * group. |
| 325 | */ |
Sunny Goyal | 145c8f8 | 2018-02-15 14:27:09 -0800 | [diff] [blame] | 326 | private boolean canAccessProfile(int targetUserId, String message) { |
Makoto Onuki | e70b29e | 2018-04-03 16:44:39 -0700 | [diff] [blame] | 327 | final int callingUserId = injectCallingUserId(); |
| 328 | |
| 329 | if (targetUserId == callingUserId) return true; |
| 330 | |
| 331 | long ident = injectClearCallingIdentity(); |
| 332 | try { |
| 333 | final UserInfo callingUserInfo = mUm.getUserInfo(callingUserId); |
| 334 | if (callingUserInfo != null && callingUserInfo.isManagedProfile()) { |
| 335 | Slog.w(TAG, message + " for another profile " |
| 336 | + targetUserId + " from " + callingUserId + " not allowed"); |
| 337 | return false; |
| 338 | } |
| 339 | } finally { |
| 340 | injectRestoreCallingIdentity(ident); |
| 341 | } |
| 342 | |
Sunny Goyal | 145c8f8 | 2018-02-15 14:27:09 -0800 | [diff] [blame] | 343 | return mUserManagerInternal.isProfileAccessible(injectCallingUserId(), targetUserId, |
| 344 | message, true); |
Amith Yamasani | 932249d | 2014-05-01 14:39:35 -0700 | [diff] [blame] | 345 | } |
| 346 | |
Makoto Onuki | 7a6a05f | 2016-03-10 17:01:08 -0800 | [diff] [blame] | 347 | @VisibleForTesting // We override it in unit tests |
| 348 | void verifyCallingPackage(String callingPackage) { |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 349 | int packageUid = -1; |
| 350 | try { |
Todd Kennedy | 18211fd | 2017-06-06 09:15:46 -0700 | [diff] [blame] | 351 | packageUid = AppGlobals.getPackageManager().getPackageUid(callingPackage, |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 352 | PackageManager.MATCH_DIRECT_BOOT_AWARE |
| 353 | | PackageManager.MATCH_DIRECT_BOOT_UNAWARE |
Makoto Onuki | 3ee7f71 | 2016-03-10 17:28:55 -0800 | [diff] [blame] | 354 | | PackageManager.MATCH_UNINSTALLED_PACKAGES, |
| 355 | UserHandle.getUserId(getCallingUid())); |
Todd Kennedy | 18211fd | 2017-06-06 09:15:46 -0700 | [diff] [blame] | 356 | } catch (RemoteException ignore) { |
| 357 | } |
| 358 | if (packageUid < 0) { |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 359 | Log.e(TAG, "Package not found: " + callingPackage); |
| 360 | } |
Todd Kennedy | 18211fd | 2017-06-06 09:15:46 -0700 | [diff] [blame] | 361 | if (packageUid != injectBinderCallingUid()) { |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 362 | throw new SecurityException("Calling package name mismatch"); |
| 363 | } |
| 364 | } |
| 365 | |
Ricky Wai | cf134eb | 2018-10-10 09:26:32 +0100 | [diff] [blame] | 366 | private ResolveInfo getHiddenAppActivityInfo(String packageName, int callingUid, |
| 367 | UserHandle user) { |
| 368 | Intent intent = new Intent(); |
Ricky Wai | 92cd006 | 2019-02-14 20:23:22 +0000 | [diff] [blame] | 369 | intent.setComponent(new ComponentName(packageName, |
| 370 | PackageManager.APP_DETAILS_ACTIVITY_CLASS_NAME)); |
Ricky Wai | cf134eb | 2018-10-10 09:26:32 +0100 | [diff] [blame] | 371 | final PackageManagerInternal pmInt = |
| 372 | LocalServices.getService(PackageManagerInternal.class); |
| 373 | List<ResolveInfo> apps = pmInt.queryIntentActivities(intent, |
| 374 | PackageManager.MATCH_DIRECT_BOOT_AWARE |
| 375 | | PackageManager.MATCH_DIRECT_BOOT_UNAWARE, |
| 376 | callingUid, user.getIdentifier()); |
| 377 | if (apps.size() > 0) { |
| 378 | return apps.get(0); |
| 379 | } |
| 380 | return null; |
| 381 | } |
| 382 | |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 383 | @Override |
Suprabh Shukla | 7900049 | 2018-12-24 17:03:02 -0800 | [diff] [blame] | 384 | public boolean shouldHideFromSuggestions(String packageName, UserHandle user) { |
| 385 | if (!canAccessProfile(user.getIdentifier(), "cannot get shouldHideFromSuggestions")) { |
| 386 | return false; |
| 387 | } |
| 388 | final PackageManagerInternal pmi = LocalServices.getService( |
| 389 | PackageManagerInternal.class); |
| 390 | int flags = pmi.getDistractingPackageRestrictions(packageName, user.getIdentifier()); |
| 391 | return (flags & PackageManager.RESTRICTION_HIDE_FROM_SUGGESTIONS) != 0; |
| 392 | } |
| 393 | |
| 394 | @Override |
Makoto Onuki | 3a2541e | 2017-01-24 09:00:15 -0800 | [diff] [blame] | 395 | public ParceledListSlice<ResolveInfo> getLauncherActivities(String callingPackage, |
Ricky Wai | cf134eb | 2018-10-10 09:26:32 +0100 | [diff] [blame] | 396 | String packageName, UserHandle user) throws RemoteException { |
| 397 | ParceledListSlice<ResolveInfo> launcherActivities = queryActivitiesForUser( |
| 398 | callingPackage, |
Sunny Goyal | a6be88a | 2017-01-12 16:27:58 -0800 | [diff] [blame] | 399 | new Intent(Intent.ACTION_MAIN) |
| 400 | .addCategory(Intent.CATEGORY_LAUNCHER) |
| 401 | .setPackage(packageName), |
| 402 | user); |
Ricky Wai | 13b0abe | 2018-10-23 11:03:02 +0100 | [diff] [blame] | 403 | if (Settings.Global.getInt(mContext.getContentResolver(), |
Michal Karpinski | 217d597 | 2018-11-07 15:18:21 +0000 | [diff] [blame] | 404 | Settings.Global.SHOW_HIDDEN_LAUNCHER_ICON_APPS_ENABLED, 1) == 0) { |
Ricky Wai | cf134eb | 2018-10-10 09:26:32 +0100 | [diff] [blame] | 405 | return launcherActivities; |
| 406 | } |
Ricky Wai | 10ceaf9 | 2019-01-14 10:39:40 +0000 | [diff] [blame] | 407 | if (launcherActivities == null) { |
| 408 | // Cannot access profile, so we don't even return any hidden apps. |
| 409 | return null; |
| 410 | } |
Ricky Wai | cf134eb | 2018-10-10 09:26:32 +0100 | [diff] [blame] | 411 | |
| 412 | final int callingUid = injectBinderCallingUid(); |
Ricky Wai | e6a9038 | 2019-01-14 11:34:10 +0000 | [diff] [blame] | 413 | final long ident = injectClearCallingIdentity(); |
| 414 | try { |
| 415 | if (mUm.getUserInfo(user.getIdentifier()).isManagedProfile()) { |
| 416 | // Managed profile should not show hidden apps |
Ricky Wai | cf134eb | 2018-10-10 09:26:32 +0100 | [diff] [blame] | 417 | return launcherActivities; |
| 418 | } |
Ricky Wai | e6a9038 | 2019-01-14 11:34:10 +0000 | [diff] [blame] | 419 | if (mDpm.getDeviceOwnerComponentOnAnyUser() != null) { |
| 420 | // Device owner devices should not show hidden apps |
| 421 | return launcherActivities; |
Ricky Wai | cf134eb | 2018-10-10 09:26:32 +0100 | [diff] [blame] | 422 | } |
Ricky Wai | cf134eb | 2018-10-10 09:26:32 +0100 | [diff] [blame] | 423 | |
Ricky Wai | e6a9038 | 2019-01-14 11:34:10 +0000 | [diff] [blame] | 424 | final ArrayList<ResolveInfo> result = new ArrayList<>(launcherActivities.getList()); |
| 425 | final PackageManagerInternal pmInt = |
| 426 | LocalServices.getService(PackageManagerInternal.class); |
| 427 | if (packageName != null) { |
| 428 | // If this hidden app should not be shown, return the original list. |
| 429 | // Otherwise, inject hidden activity that forwards user to app details page. |
| 430 | if (result.size() > 0) { |
| 431 | return launcherActivities; |
| 432 | } |
| 433 | ApplicationInfo appInfo = pmInt.getApplicationInfo(packageName, /*flags*/ 0, |
| 434 | callingUid, user.getIdentifier()); |
Ricky Wai | e346a49 | 2019-01-21 14:54:32 +0000 | [diff] [blame] | 435 | if (shouldShowHiddenApp(user, appInfo)) { |
Ricky Wai | e6a9038 | 2019-01-14 11:34:10 +0000 | [diff] [blame] | 436 | ResolveInfo info = getHiddenAppActivityInfo(packageName, callingUid, user); |
| 437 | if (info != null) { |
| 438 | result.add(info); |
| 439 | } |
| 440 | } |
| 441 | return new ParceledListSlice<>(result); |
| 442 | } |
Ricky Wai | cf134eb | 2018-10-10 09:26:32 +0100 | [diff] [blame] | 443 | final HashSet<String> visiblePackages = new HashSet<>(); |
| 444 | for (ResolveInfo info : result) { |
| 445 | visiblePackages.add(info.activityInfo.packageName); |
| 446 | } |
Ricky Wai | cf134eb | 2018-10-10 09:26:32 +0100 | [diff] [blame] | 447 | List<ApplicationInfo> installedPackages = pmInt.getInstalledApplications(0, |
| 448 | user.getIdentifier(), callingUid); |
| 449 | for (ApplicationInfo applicationInfo : installedPackages) { |
| 450 | if (!visiblePackages.contains(applicationInfo.packageName)) { |
Ricky Wai | e346a49 | 2019-01-21 14:54:32 +0000 | [diff] [blame] | 451 | if (!shouldShowHiddenApp(user, applicationInfo)) { |
Ricky Wai | cf134eb | 2018-10-10 09:26:32 +0100 | [diff] [blame] | 452 | continue; |
| 453 | } |
| 454 | ResolveInfo info = getHiddenAppActivityInfo(applicationInfo.packageName, |
| 455 | callingUid, user); |
| 456 | if (info != null) { |
| 457 | result.add(info); |
| 458 | } |
| 459 | } |
| 460 | } |
| 461 | return new ParceledListSlice<>(result); |
| 462 | } finally { |
| 463 | injectRestoreCallingIdentity(ident); |
| 464 | } |
| 465 | } |
| 466 | |
Ricky Wai | e346a49 | 2019-01-21 14:54:32 +0000 | [diff] [blame] | 467 | private boolean shouldShowHiddenApp(UserHandle user, ApplicationInfo appInfo) { |
Michal Karpinski | 08404a95 | 2018-11-15 17:46:00 +0000 | [diff] [blame] | 468 | if (appInfo == null || appInfo.isSystemApp() || appInfo.isUpdatedSystemApp()) { |
Ricky Wai | cf134eb | 2018-10-10 09:26:32 +0100 | [diff] [blame] | 469 | return false; |
| 470 | } |
Ricky Wai | e346a49 | 2019-01-21 14:54:32 +0000 | [diff] [blame] | 471 | if (!mVouchedSignaturesByUser.containsKey(user)) { |
| 472 | initVouchedSignatures(user); |
| 473 | } |
Ricky Wai | 8757727 | 2019-01-24 19:18:25 +0000 | [diff] [blame] | 474 | if (isManagedProfileAdmin(user, appInfo.packageName)) { |
| 475 | return false; |
| 476 | } |
Ricky Wai | e346a49 | 2019-01-21 14:54:32 +0000 | [diff] [blame] | 477 | if (mVouchProviders.contains(appInfo.packageName)) { |
| 478 | // If it's a vouching packages then we must show hidden app |
| 479 | return true; |
| 480 | } |
| 481 | // If app's signature is in vouch list, do not show hidden app |
| 482 | final Set<String> vouches = mVouchedSignaturesByUser.get(user); |
| 483 | try { |
| 484 | final PackageInfo pkgInfo = mContext.getPackageManager().getPackageInfo( |
| 485 | appInfo.packageName, PackageManager.GET_SIGNING_CERTIFICATES); |
| 486 | final Signature[] signatures = getLatestSignatures(pkgInfo.signingInfo); |
| 487 | // If any of the signatures appears in vouches, then we don't show hidden app |
| 488 | for (Signature signature : signatures) { |
| 489 | final String certDigest = computePackageCertDigest(signature); |
| 490 | if (vouches.contains(certDigest)) { |
| 491 | return false; |
| 492 | } |
| 493 | } |
| 494 | } catch (PackageManager.NameNotFoundException e) { |
| 495 | // Should not happen |
| 496 | } |
Ricky Wai | cf134eb | 2018-10-10 09:26:32 +0100 | [diff] [blame] | 497 | return true; |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 498 | } |
| 499 | |
Ricky Wai | 8757727 | 2019-01-24 19:18:25 +0000 | [diff] [blame] | 500 | private boolean isManagedProfileAdmin(UserHandle user, String packageName) { |
| 501 | final List<UserInfo> userInfoList = mUm.getProfiles(user.getIdentifier()); |
| 502 | for (int i = 0; i < userInfoList.size(); i++) { |
| 503 | UserInfo userInfo = userInfoList.get(i); |
| 504 | if (!userInfo.isManagedProfile()) { |
| 505 | continue; |
| 506 | } |
| 507 | ComponentName componentName = mDpm.getProfileOwnerAsUser(userInfo.getUserHandle()); |
| 508 | if (componentName == null) { |
| 509 | continue; |
| 510 | } |
| 511 | if (componentName.getPackageName().equals(packageName)) { |
| 512 | return true; |
| 513 | } |
| 514 | } |
| 515 | return false; |
| 516 | } |
| 517 | |
Ricky Wai | e346a49 | 2019-01-21 14:54:32 +0000 | [diff] [blame] | 518 | @VisibleForTesting |
| 519 | static String computePackageCertDigest(Signature signature) { |
| 520 | MessageDigest messageDigest; |
| 521 | try { |
| 522 | messageDigest = MessageDigest.getInstance("SHA1"); |
| 523 | } catch (NoSuchAlgorithmException e) { |
| 524 | // Should not happen |
| 525 | return null; |
| 526 | } |
| 527 | messageDigest.update(signature.toByteArray()); |
| 528 | final byte[] digest = messageDigest.digest(); |
| 529 | return ByteStringUtils.toHexString(digest); |
| 530 | } |
| 531 | |
| 532 | @VisibleForTesting |
| 533 | static Signature[] getLatestSignatures(SigningInfo signingInfo) { |
| 534 | if (signingInfo.hasMultipleSigners()) { |
| 535 | return signingInfo.getApkContentsSigners(); |
| 536 | } else { |
| 537 | final Signature[] signatures = signingInfo.getSigningCertificateHistory(); |
| 538 | return new Signature[]{signatures[0]}; |
| 539 | } |
| 540 | } |
| 541 | |
| 542 | private void updateVouches(String packageName, UserHandle user) { |
| 543 | final PackageManagerInternal pmInt = |
| 544 | LocalServices.getService(PackageManagerInternal.class); |
| 545 | ApplicationInfo appInfo = pmInt.getApplicationInfo(packageName, |
| 546 | PackageManager.GET_META_DATA, Binder.getCallingUid(), user.getIdentifier()); |
| 547 | if (appInfo == null) { |
| 548 | Log.w(TAG, "appInfo " + packageName + " is null"); |
| 549 | return; |
| 550 | } |
| 551 | updateVouches(appInfo, user); |
| 552 | } |
| 553 | |
| 554 | private void updateVouches(ApplicationInfo appInfo, UserHandle user) { |
| 555 | if (appInfo == null || appInfo.metaData == null) { |
| 556 | // No meta-data |
| 557 | return; |
| 558 | } |
| 559 | int tokenResourceId = appInfo.metaData.getInt(LauncherApps.VOUCHED_CERTS_KEY); |
| 560 | if (tokenResourceId == 0) { |
| 561 | // No xml file |
| 562 | return; |
| 563 | } |
| 564 | mVouchProviders.add(appInfo.packageName); |
| 565 | Set<String> vouches = mVouchedSignaturesByUser.get(user); |
| 566 | try { |
| 567 | List<String> signatures = Arrays.asList( |
| 568 | mContext.getPackageManager().getResourcesForApplication( |
| 569 | appInfo.packageName).getStringArray(tokenResourceId)); |
| 570 | for (String signature : signatures) { |
| 571 | vouches.add(signature.toUpperCase()); |
| 572 | } |
| 573 | } catch (PackageManager.NameNotFoundException e) { |
| 574 | // Should not happen |
| 575 | } |
| 576 | } |
| 577 | |
| 578 | private void initVouchedSignatures(UserHandle user) { |
| 579 | synchronized (mVouchedSignaturesLocked) { |
| 580 | if (mVouchedSignaturesByUser.contains(user)) { |
| 581 | return; |
| 582 | } |
| 583 | final long startTime = mStatLogger.getTime(); |
| 584 | |
| 585 | Set<String> vouches = Collections.newSetFromMap( |
| 586 | new ConcurrentHashMap<String, Boolean>()); |
| 587 | |
| 588 | final int callingUid = injectBinderCallingUid(); |
| 589 | long ident = Binder.clearCallingIdentity(); |
| 590 | try { |
| 591 | final PackageManagerInternal pmInt = |
| 592 | LocalServices.getService(PackageManagerInternal.class); |
| 593 | List<ApplicationInfo> installedPackages = pmInt.getInstalledApplications( |
| 594 | PackageManager.GET_META_DATA, user.getIdentifier(), callingUid); |
| 595 | for (ApplicationInfo appInfo : installedPackages) { |
| 596 | updateVouches(appInfo, user); |
| 597 | } |
| 598 | } finally { |
| 599 | Binder.restoreCallingIdentity(ident); |
| 600 | } |
| 601 | mVouchedSignaturesByUser.putIfAbsent(user, vouches); |
| 602 | mStatLogger.logDurationStat(Stats.INIT_VOUCHED_SIGNATURES, startTime); |
| 603 | } |
| 604 | } |
| 605 | |
| 606 | @Override |
| 607 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 608 | if (!DumpUtils.checkDumpAndUsageStatsPermission(mContext, TAG, pw)) return; |
| 609 | mStatLogger.dump(pw, " "); |
| 610 | } |
| 611 | |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 612 | @Override |
Makoto Onuki | 3a2541e | 2017-01-24 09:00:15 -0800 | [diff] [blame] | 613 | public ActivityInfo resolveActivity( |
| 614 | String callingPackage, ComponentName component, UserHandle user) |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 615 | throws RemoteException { |
Sunny Goyal | 145c8f8 | 2018-02-15 14:27:09 -0800 | [diff] [blame] | 616 | if (!canAccessProfile(user.getIdentifier(), "Cannot resolve activity")) { |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 617 | return null; |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 618 | } |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 619 | |
Todd Kennedy | 18211fd | 2017-06-06 09:15:46 -0700 | [diff] [blame] | 620 | final int callingUid = injectBinderCallingUid(); |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 621 | long ident = Binder.clearCallingIdentity(); |
| 622 | try { |
Todd Kennedy | 18211fd | 2017-06-06 09:15:46 -0700 | [diff] [blame] | 623 | final PackageManagerInternal pmInt = |
| 624 | LocalServices.getService(PackageManagerInternal.class); |
| 625 | return pmInt.getActivityInfo(component, |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 626 | PackageManager.MATCH_DIRECT_BOOT_AWARE |
| 627 | | PackageManager.MATCH_DIRECT_BOOT_UNAWARE, |
Todd Kennedy | 18211fd | 2017-06-06 09:15:46 -0700 | [diff] [blame] | 628 | callingUid, user.getIdentifier()); |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 629 | } finally { |
| 630 | Binder.restoreCallingIdentity(ident); |
| 631 | } |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | @Override |
Makoto Onuki | 3a2541e | 2017-01-24 09:00:15 -0800 | [diff] [blame] | 635 | public ParceledListSlice getShortcutConfigActivities( |
| 636 | String callingPackage, String packageName, UserHandle user) |
Sunny Goyal | a6be88a | 2017-01-12 16:27:58 -0800 | [diff] [blame] | 637 | throws RemoteException { |
Makoto Onuki | 3a2541e | 2017-01-24 09:00:15 -0800 | [diff] [blame] | 638 | return queryActivitiesForUser(callingPackage, |
Sunny Goyal | a6be88a | 2017-01-12 16:27:58 -0800 | [diff] [blame] | 639 | new Intent(Intent.ACTION_CREATE_SHORTCUT).setPackage(packageName), user); |
| 640 | } |
| 641 | |
Makoto Onuki | 3a2541e | 2017-01-24 09:00:15 -0800 | [diff] [blame] | 642 | private ParceledListSlice<ResolveInfo> queryActivitiesForUser(String callingPackage, |
| 643 | Intent intent, UserHandle user) { |
Sunny Goyal | 145c8f8 | 2018-02-15 14:27:09 -0800 | [diff] [blame] | 644 | if (!canAccessProfile(user.getIdentifier(), "Cannot retrieve activities")) { |
Sunny Goyal | a6be88a | 2017-01-12 16:27:58 -0800 | [diff] [blame] | 645 | return null; |
| 646 | } |
| 647 | |
Todd Kennedy | 18211fd | 2017-06-06 09:15:46 -0700 | [diff] [blame] | 648 | final int callingUid = injectBinderCallingUid(); |
Sunny Goyal | a6be88a | 2017-01-12 16:27:58 -0800 | [diff] [blame] | 649 | long ident = injectClearCallingIdentity(); |
| 650 | try { |
Todd Kennedy | 18211fd | 2017-06-06 09:15:46 -0700 | [diff] [blame] | 651 | final PackageManagerInternal pmInt = |
| 652 | LocalServices.getService(PackageManagerInternal.class); |
| 653 | List<ResolveInfo> apps = pmInt.queryIntentActivities(intent, |
Sunny Goyal | a6be88a | 2017-01-12 16:27:58 -0800 | [diff] [blame] | 654 | PackageManager.MATCH_DIRECT_BOOT_AWARE |
| 655 | | PackageManager.MATCH_DIRECT_BOOT_UNAWARE, |
Todd Kennedy | 18211fd | 2017-06-06 09:15:46 -0700 | [diff] [blame] | 656 | callingUid, user.getIdentifier()); |
Sunny Goyal | a6be88a | 2017-01-12 16:27:58 -0800 | [diff] [blame] | 657 | return new ParceledListSlice<>(apps); |
| 658 | } finally { |
| 659 | injectRestoreCallingIdentity(ident); |
| 660 | } |
| 661 | } |
| 662 | |
| 663 | @Override |
| 664 | public IntentSender getShortcutConfigActivityIntent(String callingPackage, |
| 665 | ComponentName component, UserHandle user) throws RemoteException { |
Makoto Onuki | de3c16c | 2017-01-26 11:39:31 -0800 | [diff] [blame] | 666 | ensureShortcutPermission(callingPackage); |
Sunny Goyal | 145c8f8 | 2018-02-15 14:27:09 -0800 | [diff] [blame] | 667 | if (!canAccessProfile(user.getIdentifier(), "Cannot check package")) { |
Makoto Onuki | de3c16c | 2017-01-26 11:39:31 -0800 | [diff] [blame] | 668 | return null; |
| 669 | } |
Sunny Goyal | a6be88a | 2017-01-12 16:27:58 -0800 | [diff] [blame] | 670 | Preconditions.checkNotNull(component); |
Sunny Goyal | a6be88a | 2017-01-12 16:27:58 -0800 | [diff] [blame] | 671 | |
| 672 | // All right, create the sender. |
| 673 | Intent intent = new Intent(Intent.ACTION_CREATE_SHORTCUT).setComponent(component); |
| 674 | final long identity = Binder.clearCallingIdentity(); |
| 675 | try { |
Makoto Onuki | de3c16c | 2017-01-26 11:39:31 -0800 | [diff] [blame] | 676 | final PendingIntent pi = PendingIntent.getActivityAsUser( |
Sunny Goyal | a6be88a | 2017-01-12 16:27:58 -0800 | [diff] [blame] | 677 | mContext, 0, intent, PendingIntent.FLAG_ONE_SHOT |
| 678 | | PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_CANCEL_CURRENT, |
Makoto Onuki | de3c16c | 2017-01-26 11:39:31 -0800 | [diff] [blame] | 679 | null, user); |
| 680 | return pi == null ? null : pi.getIntentSender(); |
Sunny Goyal | a6be88a | 2017-01-12 16:27:58 -0800 | [diff] [blame] | 681 | } finally { |
| 682 | Binder.restoreCallingIdentity(identity); |
| 683 | } |
| 684 | } |
| 685 | |
| 686 | @Override |
Makoto Onuki | 3a2541e | 2017-01-24 09:00:15 -0800 | [diff] [blame] | 687 | public boolean isPackageEnabled(String callingPackage, String packageName, UserHandle user) |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 688 | throws RemoteException { |
Sunny Goyal | 145c8f8 | 2018-02-15 14:27:09 -0800 | [diff] [blame] | 689 | if (!canAccessProfile(user.getIdentifier(), "Cannot check package")) { |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 690 | return false; |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 691 | } |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 692 | |
Todd Kennedy | 18211fd | 2017-06-06 09:15:46 -0700 | [diff] [blame] | 693 | final int callingUid = injectBinderCallingUid(); |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 694 | long ident = Binder.clearCallingIdentity(); |
| 695 | try { |
Todd Kennedy | 18211fd | 2017-06-06 09:15:46 -0700 | [diff] [blame] | 696 | final PackageManagerInternal pmInt = |
| 697 | LocalServices.getService(PackageManagerInternal.class); |
| 698 | PackageInfo info = pmInt.getPackageInfo(packageName, |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 699 | PackageManager.MATCH_DIRECT_BOOT_AWARE |
| 700 | | PackageManager.MATCH_DIRECT_BOOT_UNAWARE, |
Todd Kennedy | 18211fd | 2017-06-06 09:15:46 -0700 | [diff] [blame] | 701 | callingUid, user.getIdentifier()); |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 702 | return info != null && info.applicationInfo.enabled; |
| 703 | } finally { |
| 704 | Binder.restoreCallingIdentity(ident); |
| 705 | } |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 706 | } |
| 707 | |
| 708 | @Override |
Suprabh Shukla | 19b41f3 | 2018-03-26 22:35:13 -0700 | [diff] [blame] | 709 | public Bundle getSuspendedPackageLauncherExtras(String packageName, |
| 710 | UserHandle user) { |
| 711 | if (!canAccessProfile(user.getIdentifier(), "Cannot get launcher extras")) { |
| 712 | return null; |
| 713 | } |
| 714 | final PackageManagerInternal pmi = |
| 715 | LocalServices.getService(PackageManagerInternal.class); |
| 716 | return pmi.getSuspendedPackageLauncherExtras(packageName, user.getIdentifier()); |
| 717 | } |
| 718 | |
| 719 | @Override |
Makoto Onuki | 3a2541e | 2017-01-24 09:00:15 -0800 | [diff] [blame] | 720 | public ApplicationInfo getApplicationInfo( |
| 721 | String callingPackage, String packageName, int flags, UserHandle user) |
Kenny Guy | 7724275 | 2016-01-15 13:29:06 +0000 | [diff] [blame] | 722 | throws RemoteException { |
Sunny Goyal | 145c8f8 | 2018-02-15 14:27:09 -0800 | [diff] [blame] | 723 | if (!canAccessProfile(user.getIdentifier(), "Cannot check package")) { |
Kenny Guy | 7724275 | 2016-01-15 13:29:06 +0000 | [diff] [blame] | 724 | return null; |
| 725 | } |
| 726 | |
Todd Kennedy | 18211fd | 2017-06-06 09:15:46 -0700 | [diff] [blame] | 727 | final int callingUid = injectBinderCallingUid(); |
Kenny Guy | 7724275 | 2016-01-15 13:29:06 +0000 | [diff] [blame] | 728 | long ident = Binder.clearCallingIdentity(); |
| 729 | try { |
Todd Kennedy | 18211fd | 2017-06-06 09:15:46 -0700 | [diff] [blame] | 730 | final PackageManagerInternal pmInt = |
| 731 | LocalServices.getService(PackageManagerInternal.class); |
| 732 | ApplicationInfo info = pmInt.getApplicationInfo(packageName, flags, |
| 733 | callingUid, user.getIdentifier()); |
Kenny Guy | 7724275 | 2016-01-15 13:29:06 +0000 | [diff] [blame] | 734 | return info; |
| 735 | } finally { |
| 736 | Binder.restoreCallingIdentity(ident); |
| 737 | } |
| 738 | } |
| 739 | |
Varun Shah | 2546cef | 2019-01-11 15:50:54 -0800 | [diff] [blame] | 740 | @Override |
| 741 | public LauncherApps.AppUsageLimit getAppUsageLimit(String callingPackage, |
| 742 | String packageName, UserHandle user) { |
| 743 | verifyCallingPackage(callingPackage); |
| 744 | if (!canAccessProfile(user.getIdentifier(), "Cannot access usage limit")) { |
| 745 | return null; |
| 746 | } |
Varun Shah | e9abb75 | 2019-02-11 11:25:06 -0800 | [diff] [blame] | 747 | if (!mActivityTaskManagerInternal.isCallerRecents(Binder.getCallingUid())) { |
| 748 | throw new SecurityException("Caller is not the recents app"); |
Varun Shah | 2546cef | 2019-01-11 15:50:54 -0800 | [diff] [blame] | 749 | } |
| 750 | |
| 751 | final UsageStatsManagerInternal.AppUsageLimitData data = |
| 752 | mUsageStatsManagerInternal.getAppUsageLimit(packageName, user); |
| 753 | if (data == null) { |
| 754 | return null; |
| 755 | } |
| 756 | return new LauncherApps.AppUsageLimit( |
Varun Shah | 9c6f72b | 2019-01-25 21:13:56 -0800 | [diff] [blame] | 757 | data.getTotalUsageLimit(), data.getUsageRemaining()); |
Varun Shah | 2546cef | 2019-01-11 15:50:54 -0800 | [diff] [blame] | 758 | } |
| 759 | |
Makoto Onuki | de3c16c | 2017-01-26 11:39:31 -0800 | [diff] [blame] | 760 | private void ensureShortcutPermission(@NonNull String callingPackage) { |
Makoto Onuki | 2d5b465 | 2016-03-11 16:09:54 -0800 | [diff] [blame] | 761 | verifyCallingPackage(callingPackage); |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 762 | if (!mShortcutServiceInternal.hasShortcutHostPermission(getCallingUserId(), |
Makoto Onuki | 634cecb | 2017-10-13 17:10:48 -0700 | [diff] [blame] | 763 | callingPackage, injectBinderCallingPid(), injectBinderCallingUid())) { |
Makoto Onuki | 2d5b465 | 2016-03-11 16:09:54 -0800 | [diff] [blame] | 764 | throw new SecurityException("Caller can't access shortcut information"); |
| 765 | } |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 766 | } |
| 767 | |
| 768 | @Override |
| 769 | public ParceledListSlice getShortcuts(String callingPackage, long changedSince, |
Makoto Onuki | 99302b5 | 2017-03-29 12:42:26 -0700 | [diff] [blame] | 770 | String packageName, List shortcutIds, ComponentName componentName, int flags, |
| 771 | UserHandle targetUser) { |
Makoto Onuki | de3c16c | 2017-01-26 11:39:31 -0800 | [diff] [blame] | 772 | ensureShortcutPermission(callingPackage); |
Sunny Goyal | 145c8f8 | 2018-02-15 14:27:09 -0800 | [diff] [blame] | 773 | if (!canAccessProfile(targetUser.getIdentifier(), "Cannot get shortcuts")) { |
Makoto Onuki | de3c16c | 2017-01-26 11:39:31 -0800 | [diff] [blame] | 774 | return new ParceledListSlice<>(Collections.EMPTY_LIST); |
Makoto Onuki | ac21497 | 2016-04-04 10:19:45 -0700 | [diff] [blame] | 775 | } |
Makoto Onuki | abe8442 | 2016-04-07 09:41:19 -0700 | [diff] [blame] | 776 | if (shortcutIds != null && packageName == null) { |
| 777 | throw new IllegalArgumentException( |
| 778 | "To query by shortcut ID, package name must also be set"); |
| 779 | } |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 780 | |
Felipe Leme | f93ce17 | 2016-06-13 14:19:40 -0700 | [diff] [blame] | 781 | // TODO(b/29399275): Eclipse compiler requires explicit List<ShortcutInfo> cast below. |
| 782 | return new ParceledListSlice<>((List<ShortcutInfo>) |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 783 | mShortcutServiceInternal.getShortcuts(getCallingUserId(), |
Makoto Onuki | abe8442 | 2016-04-07 09:41:19 -0700 | [diff] [blame] | 784 | callingPackage, changedSince, packageName, shortcutIds, |
Makoto Onuki | 634cecb | 2017-10-13 17:10:48 -0700 | [diff] [blame] | 785 | componentName, flags, targetUser.getIdentifier(), |
| 786 | injectBinderCallingPid(), injectBinderCallingUid())); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 787 | } |
| 788 | |
| 789 | @Override |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 790 | public void pinShortcuts(String callingPackage, String packageName, List<String> ids, |
Makoto Onuki | de3c16c | 2017-01-26 11:39:31 -0800 | [diff] [blame] | 791 | UserHandle targetUser) { |
| 792 | ensureShortcutPermission(callingPackage); |
Sunny Goyal | 145c8f8 | 2018-02-15 14:27:09 -0800 | [diff] [blame] | 793 | if (!canAccessProfile(targetUser.getIdentifier(), "Cannot pin shortcuts")) { |
Makoto Onuki | de3c16c | 2017-01-26 11:39:31 -0800 | [diff] [blame] | 794 | return; |
| 795 | } |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 796 | |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 797 | mShortcutServiceInternal.pinShortcuts(getCallingUserId(), |
Makoto Onuki | de3c16c | 2017-01-26 11:39:31 -0800 | [diff] [blame] | 798 | callingPackage, packageName, ids, targetUser.getIdentifier()); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 799 | } |
| 800 | |
| 801 | @Override |
Makoto Onuki | abe8442 | 2016-04-07 09:41:19 -0700 | [diff] [blame] | 802 | public int getShortcutIconResId(String callingPackage, String packageName, String id, |
Makoto Onuki | de3c16c | 2017-01-26 11:39:31 -0800 | [diff] [blame] | 803 | int targetUserId) { |
| 804 | ensureShortcutPermission(callingPackage); |
Sunny Goyal | 145c8f8 | 2018-02-15 14:27:09 -0800 | [diff] [blame] | 805 | if (!canAccessProfile(targetUserId, "Cannot access shortcuts")) { |
Makoto Onuki | ac21497 | 2016-04-04 10:19:45 -0700 | [diff] [blame] | 806 | return 0; |
| 807 | } |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 808 | |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 809 | return mShortcutServiceInternal.getShortcutIconResId(getCallingUserId(), |
Makoto Onuki | de3c16c | 2017-01-26 11:39:31 -0800 | [diff] [blame] | 810 | callingPackage, packageName, id, targetUserId); |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 811 | } |
| 812 | |
| 813 | @Override |
Makoto Onuki | abe8442 | 2016-04-07 09:41:19 -0700 | [diff] [blame] | 814 | public ParcelFileDescriptor getShortcutIconFd(String callingPackage, |
Makoto Onuki | de3c16c | 2017-01-26 11:39:31 -0800 | [diff] [blame] | 815 | String packageName, String id, int targetUserId) { |
| 816 | ensureShortcutPermission(callingPackage); |
Sunny Goyal | 145c8f8 | 2018-02-15 14:27:09 -0800 | [diff] [blame] | 817 | if (!canAccessProfile(targetUserId, "Cannot access shortcuts")) { |
Makoto Onuki | ac21497 | 2016-04-04 10:19:45 -0700 | [diff] [blame] | 818 | return null; |
| 819 | } |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 820 | |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 821 | return mShortcutServiceInternal.getShortcutIconFd(getCallingUserId(), |
Makoto Onuki | de3c16c | 2017-01-26 11:39:31 -0800 | [diff] [blame] | 822 | callingPackage, packageName, id, targetUserId); |
Makoto Onuki | 5504622 | 2016-03-08 10:49:47 -0800 | [diff] [blame] | 823 | } |
| 824 | |
| 825 | @Override |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 826 | public boolean hasShortcutHostPermission(String callingPackage) { |
Makoto Onuki | 2d5b465 | 2016-03-11 16:09:54 -0800 | [diff] [blame] | 827 | verifyCallingPackage(callingPackage); |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 828 | return mShortcutServiceInternal.hasShortcutHostPermission(getCallingUserId(), |
Makoto Onuki | 634cecb | 2017-10-13 17:10:48 -0700 | [diff] [blame] | 829 | callingPackage, injectBinderCallingPid(), injectBinderCallingUid()); |
Makoto Onuki | 2d5b465 | 2016-03-11 16:09:54 -0800 | [diff] [blame] | 830 | } |
| 831 | |
| 832 | @Override |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 833 | public boolean startShortcut(String callingPackage, String packageName, String shortcutId, |
Makoto Onuki | de3c16c | 2017-01-26 11:39:31 -0800 | [diff] [blame] | 834 | Rect sourceBounds, Bundle startActivityOptions, int targetUserId) { |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 835 | verifyCallingPackage(callingPackage); |
Sunny Goyal | 145c8f8 | 2018-02-15 14:27:09 -0800 | [diff] [blame] | 836 | if (!canAccessProfile(targetUserId, "Cannot start activity")) { |
Makoto Onuki | de3c16c | 2017-01-26 11:39:31 -0800 | [diff] [blame] | 837 | return false; |
| 838 | } |
Makoto Onuki | ac21497 | 2016-04-04 10:19:45 -0700 | [diff] [blame] | 839 | |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 840 | // Even without the permission, pinned shortcuts are always launchable. |
| 841 | if (!mShortcutServiceInternal.isPinnedByCaller(getCallingUserId(), |
Makoto Onuki | de3c16c | 2017-01-26 11:39:31 -0800 | [diff] [blame] | 842 | callingPackage, packageName, shortcutId, targetUserId)) { |
| 843 | ensureShortcutPermission(callingPackage); |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 844 | } |
| 845 | |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 846 | final Intent[] intents = mShortcutServiceInternal.createShortcutIntents( |
Makoto Onuki | 634cecb | 2017-10-13 17:10:48 -0700 | [diff] [blame] | 847 | getCallingUserId(), callingPackage, packageName, shortcutId, targetUserId, |
| 848 | injectBinderCallingPid(), injectBinderCallingUid()); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 849 | if (intents == null || intents.length == 0) { |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 850 | return false; |
Makoto Onuki | 43204b8 | 2016-03-08 16:16:44 -0800 | [diff] [blame] | 851 | } |
| 852 | // Note the target activity doesn't have to be exported. |
| 853 | |
Makoto Onuki | 7e5c3e8 | 2016-07-22 11:57:05 -0700 | [diff] [blame] | 854 | intents[0].addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Makoto Onuki | 0eed441 | 2016-07-21 11:21:59 -0700 | [diff] [blame] | 855 | intents[0].setSourceBounds(sourceBounds); |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 856 | |
| 857 | return startShortcutIntentsAsPublisher( |
Makoto Onuki | de3c16c | 2017-01-26 11:39:31 -0800 | [diff] [blame] | 858 | intents, packageName, startActivityOptions, targetUserId); |
Makoto Onuki | ea11db1 | 2016-06-24 15:17:44 -0700 | [diff] [blame] | 859 | } |
| 860 | |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 861 | private boolean startShortcutIntentsAsPublisher(@NonNull Intent[] intents, |
Makoto Onuki | ea11db1 | 2016-06-24 15:17:44 -0700 | [diff] [blame] | 862 | @NonNull String publisherPackage, Bundle startActivityOptions, int userId) { |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 863 | final int code; |
Makoto Onuki | 43204b8 | 2016-03-08 16:16:44 -0800 | [diff] [blame] | 864 | try { |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 865 | code = mActivityTaskManagerInternal.startActivitiesAsPackage(publisherPackage, |
Makoto Onuki | 440a1ea | 2016-07-20 14:21:18 -0700 | [diff] [blame] | 866 | userId, intents, startActivityOptions); |
Bryce Lee | 7f93686 | 2017-05-09 15:33:18 -0700 | [diff] [blame] | 867 | if (ActivityManager.isStartResultSuccessful(code)) { |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 868 | return true; // Success |
| 869 | } else { |
| 870 | Log.e(TAG, "Couldn't start activity, code=" + code); |
Makoto Onuki | ea11db1 | 2016-06-24 15:17:44 -0700 | [diff] [blame] | 871 | } |
Bryce Lee | 7f93686 | 2017-05-09 15:33:18 -0700 | [diff] [blame] | 872 | return false; |
Makoto Onuki | 83f6d2d | 2016-07-11 14:30:19 -0700 | [diff] [blame] | 873 | } catch (SecurityException e) { |
| 874 | if (DEBUG) { |
| 875 | Slog.d(TAG, "SecurityException while launching intent", e); |
| 876 | } |
| 877 | return false; |
Makoto Onuki | 43204b8 | 2016-03-08 16:16:44 -0800 | [diff] [blame] | 878 | } |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 879 | } |
| 880 | |
Kenny Guy | 7724275 | 2016-01-15 13:29:06 +0000 | [diff] [blame] | 881 | @Override |
Makoto Onuki | 3a2541e | 2017-01-24 09:00:15 -0800 | [diff] [blame] | 882 | public boolean isActivityEnabled( |
| 883 | String callingPackage, ComponentName component, UserHandle user) |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 884 | throws RemoteException { |
Sunny Goyal | 145c8f8 | 2018-02-15 14:27:09 -0800 | [diff] [blame] | 885 | if (!canAccessProfile(user.getIdentifier(), "Cannot check component")) { |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 886 | return false; |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 887 | } |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 888 | |
Todd Kennedy | 18211fd | 2017-06-06 09:15:46 -0700 | [diff] [blame] | 889 | final int callingUid = injectBinderCallingUid(); |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 890 | long ident = Binder.clearCallingIdentity(); |
| 891 | try { |
Todd Kennedy | 18211fd | 2017-06-06 09:15:46 -0700 | [diff] [blame] | 892 | final PackageManagerInternal pmInt = |
| 893 | LocalServices.getService(PackageManagerInternal.class); |
| 894 | ActivityInfo info = pmInt.getActivityInfo(component, |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 895 | PackageManager.MATCH_DIRECT_BOOT_AWARE |
| 896 | | PackageManager.MATCH_DIRECT_BOOT_UNAWARE, |
Todd Kennedy | 18211fd | 2017-06-06 09:15:46 -0700 | [diff] [blame] | 897 | callingUid, user.getIdentifier()); |
Makoto Onuki | 516020a | 2019-01-28 14:16:42 -0800 | [diff] [blame] | 898 | // Note we don't check "exported" because if the caller has the same UID as the |
| 899 | // callee's UID, it can still be launched. |
| 900 | // (If an app doesn't export a front door activity and causes issues with the |
| 901 | // launcher, that's just the app's bug.) |
| 902 | return info != null && info.isEnabled(); |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 903 | } finally { |
| 904 | Binder.restoreCallingIdentity(ident); |
| 905 | } |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 906 | } |
| 907 | |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 908 | @Override |
Jon Miranda | 2b340a2 | 2019-01-25 14:03:49 -0800 | [diff] [blame] | 909 | public void startSessionDetailsActivityAsUser(IApplicationThread caller, |
| 910 | String callingPackage, SessionInfo sessionInfo, Rect sourceBounds, |
| 911 | Bundle opts, UserHandle userHandle) throws RemoteException { |
| 912 | int userId = userHandle.getIdentifier(); |
| 913 | if (!canAccessProfile(userId, "Cannot start details activity")) { |
| 914 | return; |
| 915 | } |
| 916 | |
| 917 | Intent i = new Intent(Intent.ACTION_VIEW) |
| 918 | .setData(new Uri.Builder() |
| 919 | .scheme("market") |
| 920 | .authority("details") |
| 921 | .appendQueryParameter("id", sessionInfo.appPackageName) |
| 922 | .build()) |
| 923 | .putExtra(Intent.EXTRA_REFERRER, new Uri.Builder().scheme("android-app") |
| 924 | .authority(callingPackage).build()); |
| 925 | i.setSourceBounds(sourceBounds); |
| 926 | |
| 927 | mActivityTaskManagerInternal.startActivityAsUser(caller, callingPackage, i, opts, |
| 928 | userId); |
| 929 | } |
| 930 | |
| 931 | @Override |
Makoto Onuki | 1a34274 | 2018-04-26 14:56:59 -0700 | [diff] [blame] | 932 | public void startActivityAsUser(IApplicationThread caller, String callingPackage, |
Makoto Onuki | 3a2541e | 2017-01-24 09:00:15 -0800 | [diff] [blame] | 933 | ComponentName component, Rect sourceBounds, |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 934 | Bundle opts, UserHandle user) throws RemoteException { |
Sunny Goyal | 145c8f8 | 2018-02-15 14:27:09 -0800 | [diff] [blame] | 935 | if (!canAccessProfile(user.getIdentifier(), "Cannot start activity")) { |
Makoto Onuki | de3c16c | 2017-01-26 11:39:31 -0800 | [diff] [blame] | 936 | return; |
| 937 | } |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 938 | |
| 939 | Intent launchIntent = new Intent(Intent.ACTION_MAIN); |
| 940 | launchIntent.addCategory(Intent.CATEGORY_LAUNCHER); |
Makoto Onuki | 347a6bd | 2016-07-19 11:13:08 -0700 | [diff] [blame] | 941 | launchIntent.setSourceBounds(sourceBounds); |
| 942 | launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 943 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
Kenny Guy | 2df1892 | 2014-07-17 13:01:25 +0100 | [diff] [blame] | 944 | launchIntent.setPackage(component.getPackageName()); |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 945 | |
Makoto Onuki | 1a34274 | 2018-04-26 14:56:59 -0700 | [diff] [blame] | 946 | boolean canLaunch = false; |
| 947 | |
Todd Kennedy | 18211fd | 2017-06-06 09:15:46 -0700 | [diff] [blame] | 948 | final int callingUid = injectBinderCallingUid(); |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 949 | long ident = Binder.clearCallingIdentity(); |
| 950 | try { |
Todd Kennedy | 18211fd | 2017-06-06 09:15:46 -0700 | [diff] [blame] | 951 | final PackageManagerInternal pmInt = |
| 952 | LocalServices.getService(PackageManagerInternal.class); |
Kenny Guy | 2df1892 | 2014-07-17 13:01:25 +0100 | [diff] [blame] | 953 | // Check that the component actually has Intent.CATEGORY_LAUCNCHER |
| 954 | // as calling startActivityAsUser ignores the category and just |
| 955 | // resolves based on the component if present. |
Todd Kennedy | 18211fd | 2017-06-06 09:15:46 -0700 | [diff] [blame] | 956 | List<ResolveInfo> apps = pmInt.queryIntentActivities(launchIntent, |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 957 | PackageManager.MATCH_DIRECT_BOOT_AWARE |
| 958 | | PackageManager.MATCH_DIRECT_BOOT_UNAWARE, |
Todd Kennedy | 18211fd | 2017-06-06 09:15:46 -0700 | [diff] [blame] | 959 | callingUid, user.getIdentifier()); |
Kenny Guy | 2df1892 | 2014-07-17 13:01:25 +0100 | [diff] [blame] | 960 | final int size = apps.size(); |
| 961 | for (int i = 0; i < size; ++i) { |
| 962 | ActivityInfo activityInfo = apps.get(i).activityInfo; |
| 963 | if (activityInfo.packageName.equals(component.getPackageName()) && |
| 964 | activityInfo.name.equals(component.getClassName())) { |
Sunny Goyal | 06ef5af | 2018-10-16 15:32:41 -0700 | [diff] [blame] | 965 | if (!activityInfo.exported) { |
| 966 | throw new SecurityException("Cannot launch non-exported components " |
| 967 | + component); |
| 968 | } |
| 969 | |
Kenny Guy | 2df1892 | 2014-07-17 13:01:25 +0100 | [diff] [blame] | 970 | // Found an activity with category launcher that matches |
| 971 | // this component so ok to launch. |
Tony Mak | 12917c6 | 2018-01-15 15:17:13 +0000 | [diff] [blame] | 972 | launchIntent.setPackage(null); |
Kenny Guy | 2df1892 | 2014-07-17 13:01:25 +0100 | [diff] [blame] | 973 | launchIntent.setComponent(component); |
Makoto Onuki | 1a34274 | 2018-04-26 14:56:59 -0700 | [diff] [blame] | 974 | canLaunch = true; |
| 975 | break; |
Kenny Guy | 2df1892 | 2014-07-17 13:01:25 +0100 | [diff] [blame] | 976 | } |
| 977 | } |
Makoto Onuki | 1a34274 | 2018-04-26 14:56:59 -0700 | [diff] [blame] | 978 | if (!canLaunch) { |
| 979 | throw new SecurityException("Attempt to launch activity without " |
| 980 | + " category Intent.CATEGORY_LAUNCHER " + component); |
| 981 | } |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 982 | } finally { |
| 983 | Binder.restoreCallingIdentity(ident); |
| 984 | } |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 985 | mActivityTaskManagerInternal.startActivityAsUser(caller, callingPackage, |
Makoto Onuki | 1a34274 | 2018-04-26 14:56:59 -0700 | [diff] [blame] | 986 | launchIntent, opts, user.getIdentifier()); |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 987 | } |
| 988 | |
Kenny Guy | 466d203 | 2014-07-23 12:23:35 +0100 | [diff] [blame] | 989 | @Override |
Makoto Onuki | 1a34274 | 2018-04-26 14:56:59 -0700 | [diff] [blame] | 990 | public void showAppDetailsAsUser(IApplicationThread caller, |
| 991 | String callingPackage, ComponentName component, |
Makoto Onuki | 3a2541e | 2017-01-24 09:00:15 -0800 | [diff] [blame] | 992 | Rect sourceBounds, Bundle opts, UserHandle user) throws RemoteException { |
Sunny Goyal | 145c8f8 | 2018-02-15 14:27:09 -0800 | [diff] [blame] | 993 | if (!canAccessProfile(user.getIdentifier(), "Cannot show app details")) { |
Makoto Onuki | de3c16c | 2017-01-26 11:39:31 -0800 | [diff] [blame] | 994 | return; |
| 995 | } |
Kenny Guy | 466d203 | 2014-07-23 12:23:35 +0100 | [diff] [blame] | 996 | |
Makoto Onuki | 1a34274 | 2018-04-26 14:56:59 -0700 | [diff] [blame] | 997 | final Intent intent; |
Kenny Guy | 466d203 | 2014-07-23 12:23:35 +0100 | [diff] [blame] | 998 | long ident = Binder.clearCallingIdentity(); |
| 999 | try { |
| 1000 | String packageName = component.getPackageName(); |
Makoto Onuki | 1a34274 | 2018-04-26 14:56:59 -0700 | [diff] [blame] | 1001 | intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, |
Kenny Guy | 466d203 | 2014-07-23 12:23:35 +0100 | [diff] [blame] | 1002 | Uri.fromParts("package", packageName, null)); |
Winson | 369aad0 | 2016-02-17 10:35:47 -0800 | [diff] [blame] | 1003 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); |
Kenny Guy | 466d203 | 2014-07-23 12:23:35 +0100 | [diff] [blame] | 1004 | intent.setSourceBounds(sourceBounds); |
Kenny Guy | 466d203 | 2014-07-23 12:23:35 +0100 | [diff] [blame] | 1005 | } finally { |
| 1006 | Binder.restoreCallingIdentity(ident); |
| 1007 | } |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 1008 | mActivityTaskManagerInternal.startActivityAsUser(caller, callingPackage, |
Makoto Onuki | 1a34274 | 2018-04-26 14:56:59 -0700 | [diff] [blame] | 1009 | intent, opts, user.getIdentifier()); |
Kenny Guy | 466d203 | 2014-07-23 12:23:35 +0100 | [diff] [blame] | 1010 | } |
| 1011 | |
Makoto Onuki | 4dbe0de | 2016-03-14 17:31:49 -0700 | [diff] [blame] | 1012 | /** Checks if user is a profile of or same as listeningUser. |
| 1013 | * and the user is enabled. */ |
Sunny Goyal | 145c8f8 | 2018-02-15 14:27:09 -0800 | [diff] [blame] | 1014 | private boolean isEnabledProfileOf(UserHandle listeningUser, UserHandle user, |
Makoto Onuki | 4dbe0de | 2016-03-14 17:31:49 -0700 | [diff] [blame] | 1015 | String debugMsg) { |
Sunny Goyal | 145c8f8 | 2018-02-15 14:27:09 -0800 | [diff] [blame] | 1016 | return mUserManagerInternal.isProfileAccessible(listeningUser.getIdentifier(), |
| 1017 | user.getIdentifier(), debugMsg, false); |
Makoto Onuki | 4dbe0de | 2016-03-14 17:31:49 -0700 | [diff] [blame] | 1018 | } |
| 1019 | |
Makoto Onuki | c5475d4 | 2016-03-25 10:54:07 -0700 | [diff] [blame] | 1020 | @VisibleForTesting |
Makoto Onuki | aa8b94a | 2016-03-17 13:14:05 -0700 | [diff] [blame] | 1021 | void postToPackageMonitorHandler(Runnable r) { |
Makoto Onuki | c5475d4 | 2016-03-25 10:54:07 -0700 | [diff] [blame] | 1022 | mCallbackHandler.post(r); |
Makoto Onuki | 4dbe0de | 2016-03-14 17:31:49 -0700 | [diff] [blame] | 1023 | } |
| 1024 | |
Ricky Wai | e346a49 | 2019-01-21 14:54:32 +0000 | [diff] [blame] | 1025 | private class VouchesChangedMonitor extends PackageMonitor { |
| 1026 | @Override |
| 1027 | public void onPackageAdded(String packageName, int uid) { |
| 1028 | updateVouches(packageName, new UserHandle(getChangingUserId())); |
| 1029 | } |
| 1030 | |
| 1031 | @Override |
| 1032 | public void onPackageModified(String packageName) { |
| 1033 | updateVouches(packageName, new UserHandle(getChangingUserId())); |
| 1034 | } |
| 1035 | } |
| 1036 | |
Makoto Onuki | 4dbe0de | 2016-03-14 17:31:49 -0700 | [diff] [blame] | 1037 | private class MyPackageMonitor extends PackageMonitor implements ShortcutChangeListener { |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 1038 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1039 | // TODO Simplify with lambdas. |
| 1040 | |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 1041 | @Override |
| 1042 | public void onPackageAdded(String packageName, int uid) { |
| 1043 | UserHandle user = new UserHandle(getChangingUserId()); |
| 1044 | final int n = mListeners.beginBroadcast(); |
Makoto Onuki | 7bdb9ce | 2016-09-15 12:52:57 -0700 | [diff] [blame] | 1045 | try { |
| 1046 | for (int i = 0; i < n; i++) { |
| 1047 | IOnAppsChangedListener listener = mListeners.getBroadcastItem(i); |
| 1048 | BroadcastCookie cookie = (BroadcastCookie) mListeners.getBroadcastCookie(i); |
Sunny Goyal | 145c8f8 | 2018-02-15 14:27:09 -0800 | [diff] [blame] | 1049 | if (!isEnabledProfileOf(cookie.user, user, "onPackageAdded")) continue; |
Makoto Onuki | 7bdb9ce | 2016-09-15 12:52:57 -0700 | [diff] [blame] | 1050 | try { |
| 1051 | listener.onPackageAdded(user, packageName); |
| 1052 | } catch (RemoteException re) { |
| 1053 | Slog.d(TAG, "Callback failed ", re); |
| 1054 | } |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 1055 | } |
Makoto Onuki | 7bdb9ce | 2016-09-15 12:52:57 -0700 | [diff] [blame] | 1056 | } finally { |
| 1057 | mListeners.finishBroadcast(); |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 1058 | } |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 1059 | |
| 1060 | super.onPackageAdded(packageName, uid); |
| 1061 | } |
| 1062 | |
| 1063 | @Override |
| 1064 | public void onPackageRemoved(String packageName, int uid) { |
| 1065 | UserHandle user = new UserHandle(getChangingUserId()); |
| 1066 | final int n = mListeners.beginBroadcast(); |
Makoto Onuki | 7bdb9ce | 2016-09-15 12:52:57 -0700 | [diff] [blame] | 1067 | try { |
| 1068 | for (int i = 0; i < n; i++) { |
| 1069 | IOnAppsChangedListener listener = mListeners.getBroadcastItem(i); |
| 1070 | BroadcastCookie cookie = (BroadcastCookie) mListeners.getBroadcastCookie(i); |
Sunny Goyal | 145c8f8 | 2018-02-15 14:27:09 -0800 | [diff] [blame] | 1071 | if (!isEnabledProfileOf(cookie.user, user, "onPackageRemoved")) continue; |
Makoto Onuki | 7bdb9ce | 2016-09-15 12:52:57 -0700 | [diff] [blame] | 1072 | try { |
| 1073 | listener.onPackageRemoved(user, packageName); |
| 1074 | } catch (RemoteException re) { |
| 1075 | Slog.d(TAG, "Callback failed ", re); |
| 1076 | } |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 1077 | } |
Makoto Onuki | 7bdb9ce | 2016-09-15 12:52:57 -0700 | [diff] [blame] | 1078 | } finally { |
| 1079 | mListeners.finishBroadcast(); |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 1080 | } |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 1081 | |
| 1082 | super.onPackageRemoved(packageName, uid); |
| 1083 | } |
| 1084 | |
| 1085 | @Override |
| 1086 | public void onPackageModified(String packageName) { |
| 1087 | UserHandle user = new UserHandle(getChangingUserId()); |
| 1088 | final int n = mListeners.beginBroadcast(); |
Makoto Onuki | 7bdb9ce | 2016-09-15 12:52:57 -0700 | [diff] [blame] | 1089 | try { |
| 1090 | for (int i = 0; i < n; i++) { |
| 1091 | IOnAppsChangedListener listener = mListeners.getBroadcastItem(i); |
| 1092 | BroadcastCookie cookie = (BroadcastCookie) mListeners.getBroadcastCookie(i); |
Sunny Goyal | 145c8f8 | 2018-02-15 14:27:09 -0800 | [diff] [blame] | 1093 | if (!isEnabledProfileOf(cookie.user, user, "onPackageModified")) continue; |
Makoto Onuki | 7bdb9ce | 2016-09-15 12:52:57 -0700 | [diff] [blame] | 1094 | try { |
| 1095 | listener.onPackageChanged(user, packageName); |
| 1096 | } catch (RemoteException re) { |
| 1097 | Slog.d(TAG, "Callback failed ", re); |
| 1098 | } |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 1099 | } |
Makoto Onuki | 7bdb9ce | 2016-09-15 12:52:57 -0700 | [diff] [blame] | 1100 | } finally { |
| 1101 | mListeners.finishBroadcast(); |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 1102 | } |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 1103 | |
| 1104 | super.onPackageModified(packageName); |
| 1105 | } |
| 1106 | |
| 1107 | @Override |
| 1108 | public void onPackagesAvailable(String[] packages) { |
| 1109 | UserHandle user = new UserHandle(getChangingUserId()); |
| 1110 | final int n = mListeners.beginBroadcast(); |
Makoto Onuki | 7bdb9ce | 2016-09-15 12:52:57 -0700 | [diff] [blame] | 1111 | try { |
| 1112 | for (int i = 0; i < n; i++) { |
| 1113 | IOnAppsChangedListener listener = mListeners.getBroadcastItem(i); |
| 1114 | BroadcastCookie cookie = (BroadcastCookie) mListeners.getBroadcastCookie(i); |
Sunny Goyal | 145c8f8 | 2018-02-15 14:27:09 -0800 | [diff] [blame] | 1115 | if (!isEnabledProfileOf(cookie.user, user, "onPackagesAvailable")) continue; |
Makoto Onuki | 7bdb9ce | 2016-09-15 12:52:57 -0700 | [diff] [blame] | 1116 | try { |
| 1117 | listener.onPackagesAvailable(user, packages, isReplacing()); |
| 1118 | } catch (RemoteException re) { |
| 1119 | Slog.d(TAG, "Callback failed ", re); |
| 1120 | } |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 1121 | } |
Makoto Onuki | 7bdb9ce | 2016-09-15 12:52:57 -0700 | [diff] [blame] | 1122 | } finally { |
| 1123 | mListeners.finishBroadcast(); |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 1124 | } |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 1125 | |
| 1126 | super.onPackagesAvailable(packages); |
| 1127 | } |
| 1128 | |
| 1129 | @Override |
| 1130 | public void onPackagesUnavailable(String[] packages) { |
| 1131 | UserHandle user = new UserHandle(getChangingUserId()); |
| 1132 | final int n = mListeners.beginBroadcast(); |
Makoto Onuki | 7bdb9ce | 2016-09-15 12:52:57 -0700 | [diff] [blame] | 1133 | try { |
| 1134 | for (int i = 0; i < n; i++) { |
| 1135 | IOnAppsChangedListener listener = mListeners.getBroadcastItem(i); |
| 1136 | BroadcastCookie cookie = (BroadcastCookie) mListeners.getBroadcastCookie(i); |
Sunny Goyal | 145c8f8 | 2018-02-15 14:27:09 -0800 | [diff] [blame] | 1137 | if (!isEnabledProfileOf(cookie.user, user, "onPackagesUnavailable")) continue; |
Makoto Onuki | 7bdb9ce | 2016-09-15 12:52:57 -0700 | [diff] [blame] | 1138 | try { |
| 1139 | listener.onPackagesUnavailable(user, packages, isReplacing()); |
| 1140 | } catch (RemoteException re) { |
| 1141 | Slog.d(TAG, "Callback failed ", re); |
| 1142 | } |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 1143 | } |
Makoto Onuki | 7bdb9ce | 2016-09-15 12:52:57 -0700 | [diff] [blame] | 1144 | } finally { |
| 1145 | mListeners.finishBroadcast(); |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 1146 | } |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 1147 | |
| 1148 | super.onPackagesUnavailable(packages); |
| 1149 | } |
| 1150 | |
Kenny Guy | 7724275 | 2016-01-15 13:29:06 +0000 | [diff] [blame] | 1151 | @Override |
Suprabh Shukla | 19b41f3 | 2018-03-26 22:35:13 -0700 | [diff] [blame] | 1152 | public void onPackagesSuspended(String[] packages, Bundle launcherExtras) { |
Kenny Guy | 7724275 | 2016-01-15 13:29:06 +0000 | [diff] [blame] | 1153 | UserHandle user = new UserHandle(getChangingUserId()); |
| 1154 | final int n = mListeners.beginBroadcast(); |
Makoto Onuki | 7bdb9ce | 2016-09-15 12:52:57 -0700 | [diff] [blame] | 1155 | try { |
| 1156 | for (int i = 0; i < n; i++) { |
| 1157 | IOnAppsChangedListener listener = mListeners.getBroadcastItem(i); |
| 1158 | BroadcastCookie cookie = (BroadcastCookie) mListeners.getBroadcastCookie(i); |
Sunny Goyal | 145c8f8 | 2018-02-15 14:27:09 -0800 | [diff] [blame] | 1159 | if (!isEnabledProfileOf(cookie.user, user, "onPackagesSuspended")) continue; |
Makoto Onuki | 7bdb9ce | 2016-09-15 12:52:57 -0700 | [diff] [blame] | 1160 | try { |
Suprabh Shukla | 19b41f3 | 2018-03-26 22:35:13 -0700 | [diff] [blame] | 1161 | listener.onPackagesSuspended(user, packages, launcherExtras); |
Makoto Onuki | 7bdb9ce | 2016-09-15 12:52:57 -0700 | [diff] [blame] | 1162 | } catch (RemoteException re) { |
| 1163 | Slog.d(TAG, "Callback failed ", re); |
| 1164 | } |
Kenny Guy | 7724275 | 2016-01-15 13:29:06 +0000 | [diff] [blame] | 1165 | } |
Makoto Onuki | 7bdb9ce | 2016-09-15 12:52:57 -0700 | [diff] [blame] | 1166 | } finally { |
| 1167 | mListeners.finishBroadcast(); |
Kenny Guy | 7724275 | 2016-01-15 13:29:06 +0000 | [diff] [blame] | 1168 | } |
Kenny Guy | 7724275 | 2016-01-15 13:29:06 +0000 | [diff] [blame] | 1169 | |
Suprabh Shukla | 19b41f3 | 2018-03-26 22:35:13 -0700 | [diff] [blame] | 1170 | super.onPackagesSuspended(packages, launcherExtras); |
Kenny Guy | 7724275 | 2016-01-15 13:29:06 +0000 | [diff] [blame] | 1171 | } |
| 1172 | |
| 1173 | @Override |
| 1174 | public void onPackagesUnsuspended(String[] packages) { |
| 1175 | UserHandle user = new UserHandle(getChangingUserId()); |
| 1176 | final int n = mListeners.beginBroadcast(); |
Makoto Onuki | 7bdb9ce | 2016-09-15 12:52:57 -0700 | [diff] [blame] | 1177 | try { |
| 1178 | for (int i = 0; i < n; i++) { |
| 1179 | IOnAppsChangedListener listener = mListeners.getBroadcastItem(i); |
| 1180 | BroadcastCookie cookie = (BroadcastCookie) mListeners.getBroadcastCookie(i); |
Sunny Goyal | 145c8f8 | 2018-02-15 14:27:09 -0800 | [diff] [blame] | 1181 | if (!isEnabledProfileOf(cookie.user, user, "onPackagesUnsuspended")) continue; |
Makoto Onuki | 7bdb9ce | 2016-09-15 12:52:57 -0700 | [diff] [blame] | 1182 | try { |
| 1183 | listener.onPackagesUnsuspended(user, packages); |
| 1184 | } catch (RemoteException re) { |
| 1185 | Slog.d(TAG, "Callback failed ", re); |
| 1186 | } |
Kenny Guy | 7724275 | 2016-01-15 13:29:06 +0000 | [diff] [blame] | 1187 | } |
Makoto Onuki | 7bdb9ce | 2016-09-15 12:52:57 -0700 | [diff] [blame] | 1188 | } finally { |
| 1189 | mListeners.finishBroadcast(); |
Kenny Guy | 7724275 | 2016-01-15 13:29:06 +0000 | [diff] [blame] | 1190 | } |
Kenny Guy | 7724275 | 2016-01-15 13:29:06 +0000 | [diff] [blame] | 1191 | |
| 1192 | super.onPackagesUnsuspended(packages); |
| 1193 | } |
| 1194 | |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1195 | @Override |
| 1196 | public void onShortcutChanged(@NonNull String packageName, |
Makoto Onuki | 4dbe0de | 2016-03-14 17:31:49 -0700 | [diff] [blame] | 1197 | @UserIdInt int userId) { |
Makoto Onuki | aa8b94a | 2016-03-17 13:14:05 -0700 | [diff] [blame] | 1198 | postToPackageMonitorHandler(() -> onShortcutChangedInner(packageName, userId)); |
Makoto Onuki | 4dbe0de | 2016-03-14 17:31:49 -0700 | [diff] [blame] | 1199 | } |
| 1200 | |
| 1201 | private void onShortcutChangedInner(@NonNull String packageName, |
| 1202 | @UserIdInt int userId) { |
Makoto Onuki | 7bdb9ce | 2016-09-15 12:52:57 -0700 | [diff] [blame] | 1203 | final int n = mListeners.beginBroadcast(); |
Makoto Onuki | 02f338e | 2016-07-29 09:40:40 -0700 | [diff] [blame] | 1204 | try { |
| 1205 | final UserHandle user = UserHandle.of(userId); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1206 | |
Makoto Onuki | 02f338e | 2016-07-29 09:40:40 -0700 | [diff] [blame] | 1207 | for (int i = 0; i < n; i++) { |
| 1208 | IOnAppsChangedListener listener = mListeners.getBroadcastItem(i); |
| 1209 | BroadcastCookie cookie = (BroadcastCookie) mListeners.getBroadcastCookie(i); |
Sunny Goyal | 145c8f8 | 2018-02-15 14:27:09 -0800 | [diff] [blame] | 1210 | if (!isEnabledProfileOf(cookie.user, user, "onShortcutChanged")) continue; |
Makoto Onuki | 2d5b465 | 2016-03-11 16:09:54 -0800 | [diff] [blame] | 1211 | |
Makoto Onuki | 02f338e | 2016-07-29 09:40:40 -0700 | [diff] [blame] | 1212 | final int launcherUserId = cookie.user.getIdentifier(); |
Makoto Onuki | d99c6f0 | 2016-03-28 11:02:54 -0700 | [diff] [blame] | 1213 | |
Makoto Onuki | 02f338e | 2016-07-29 09:40:40 -0700 | [diff] [blame] | 1214 | // Make sure the caller has the permission. |
| 1215 | if (!mShortcutServiceInternal.hasShortcutHostPermission( |
Makoto Onuki | 634cecb | 2017-10-13 17:10:48 -0700 | [diff] [blame] | 1216 | launcherUserId, cookie.packageName, |
| 1217 | cookie.callingPid, cookie.callingUid)) { |
Makoto Onuki | 02f338e | 2016-07-29 09:40:40 -0700 | [diff] [blame] | 1218 | continue; |
| 1219 | } |
| 1220 | // Each launcher has a different set of pinned shortcuts, so we need to do a |
| 1221 | // query in here. |
| 1222 | // (As of now, only one launcher has the permission at a time, so it's bit |
| 1223 | // moot, but we may change the permission model eventually.) |
| 1224 | final List<ShortcutInfo> list = |
| 1225 | mShortcutServiceInternal.getShortcuts(launcherUserId, |
| 1226 | cookie.packageName, |
| 1227 | /* changedSince= */ 0, packageName, /* shortcutIds=*/ null, |
| 1228 | /* component= */ null, |
| 1229 | ShortcutQuery.FLAG_GET_KEY_FIELDS_ONLY |
Makoto Onuki | 634cecb | 2017-10-13 17:10:48 -0700 | [diff] [blame] | 1230 | | ShortcutQuery.FLAG_MATCH_ALL_KINDS_WITH_ALL_PINNED |
| 1231 | , userId, cookie.callingPid, cookie.callingUid); |
Makoto Onuki | 02f338e | 2016-07-29 09:40:40 -0700 | [diff] [blame] | 1232 | try { |
| 1233 | listener.onShortcutChanged(user, packageName, |
| 1234 | new ParceledListSlice<>(list)); |
| 1235 | } catch (RemoteException re) { |
| 1236 | Slog.d(TAG, "Callback failed ", re); |
| 1237 | } |
Makoto Onuki | 4dbe0de | 2016-03-14 17:31:49 -0700 | [diff] [blame] | 1238 | } |
Makoto Onuki | 02f338e | 2016-07-29 09:40:40 -0700 | [diff] [blame] | 1239 | } catch (RuntimeException e) { |
| 1240 | // When the user is locked we get IllegalState, so just catch all. |
| 1241 | Log.w(TAG, e.getMessage(), e); |
Makoto Onuki | 7bdb9ce | 2016-09-15 12:52:57 -0700 | [diff] [blame] | 1242 | } finally { |
| 1243 | mListeners.finishBroadcast(); |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1244 | } |
Makoto Onuki | 6f7362d9 | 2016-03-04 13:39:41 -0800 | [diff] [blame] | 1245 | } |
Amith Yamasani | df7db07 | 2014-06-01 10:41:13 -0700 | [diff] [blame] | 1246 | } |
| 1247 | |
| 1248 | class PackageCallbackList<T extends IInterface> extends RemoteCallbackList<T> { |
| 1249 | @Override |
| 1250 | public void onCallbackDied(T callback, Object cookie) { |
| 1251 | checkCallbackCount(); |
| 1252 | } |
Amith Yamasani | 4f58263 | 2014-02-19 14:31:52 -0800 | [diff] [blame] | 1253 | } |
| 1254 | } |
Nicolas Prevot | b683019 | 2015-06-26 13:45:12 -0700 | [diff] [blame] | 1255 | } |