Kenny Guy | b1b3026 | 2016-02-09 16:02:35 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 | |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 17 | package com.android.server.wm; |
Rubin Xu | 58d2599 | 2016-01-21 17:47:13 +0000 | [diff] [blame] | 18 | |
| 19 | import static android.app.ActivityManager.INTENT_SENDER_ACTIVITY; |
Tony Mak | 83546a8 | 2018-01-22 13:56:20 +0000 | [diff] [blame] | 20 | import static android.app.ActivityOptions.ANIM_OPEN_CROSS_PROFILE_APPS; |
Rubin Xu | 58d2599 | 2016-01-21 17:47:13 +0000 | [diff] [blame] | 21 | import static android.app.PendingIntent.FLAG_CANCEL_CURRENT; |
| 22 | import static android.app.PendingIntent.FLAG_IMMUTABLE; |
| 23 | import static android.app.PendingIntent.FLAG_ONE_SHOT; |
Tony Mak | 706fbe7 | 2018-04-03 18:49:05 +0100 | [diff] [blame] | 24 | import static android.app.admin.DevicePolicyManager.EXTRA_RESTRICTION; |
| 25 | import static android.app.admin.DevicePolicyManager.POLICY_SUSPEND_PACKAGES; |
Rubin Xu | 58d2599 | 2016-01-21 17:47:13 +0000 | [diff] [blame] | 26 | import static android.content.Context.KEYGUARD_SERVICE; |
| 27 | import static android.content.Intent.EXTRA_INTENT; |
| 28 | import static android.content.Intent.EXTRA_PACKAGE_NAME; |
| 29 | import static android.content.Intent.EXTRA_TASK_ID; |
| 30 | import static android.content.Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS; |
| 31 | import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; |
Tony Mak | 4291c76 | 2016-03-24 12:23:22 +0000 | [diff] [blame] | 32 | import static android.content.Intent.FLAG_ACTIVITY_TASK_ON_HOME; |
Rubin Xu | 58d2599 | 2016-01-21 17:47:13 +0000 | [diff] [blame] | 33 | import static android.content.pm.ApplicationInfo.FLAG_SUSPENDED; |
| 34 | |
Suprabh Shukla | 3c3af14 | 2018-03-30 00:28:37 -0700 | [diff] [blame] | 35 | import static com.android.server.pm.PackageManagerService.PLATFORM_PACKAGE_NAME; |
| 36 | |
Philip P. Moltmann | 9c5226f | 2020-01-10 08:53:43 -0800 | [diff] [blame^] | 37 | import android.annotation.Nullable; |
Tony Mak | 853304c | 2016-04-18 15:17:41 +0100 | [diff] [blame] | 38 | import android.app.ActivityOptions; |
Rubin Xu | 58d2599 | 2016-01-21 17:47:13 +0000 | [diff] [blame] | 39 | import android.app.KeyguardManager; |
Sudheer Shanka | 7a9c34b | 2016-03-11 12:25:51 -0800 | [diff] [blame] | 40 | import android.app.admin.DevicePolicyManagerInternal; |
Benjamin Franz | 563707b | 2017-06-29 15:06:13 +0100 | [diff] [blame] | 41 | import android.content.Context; |
Rubin Xu | 58d2599 | 2016-01-21 17:47:13 +0000 | [diff] [blame] | 42 | import android.content.IIntentSender; |
| 43 | import android.content.Intent; |
| 44 | import android.content.IntentSender; |
| 45 | import android.content.pm.ActivityInfo; |
Suprabh Shukla | 3c3af14 | 2018-03-30 00:28:37 -0700 | [diff] [blame] | 46 | import android.content.pm.PackageManagerInternal; |
Rubin Xu | 58d2599 | 2016-01-21 17:47:13 +0000 | [diff] [blame] | 47 | import android.content.pm.ResolveInfo; |
Suprabh Shukla | 389cb6f | 2018-10-01 18:20:39 -0700 | [diff] [blame] | 48 | import android.content.pm.SuspendDialogInfo; |
Rubin Xu | 58d2599 | 2016-01-21 17:47:13 +0000 | [diff] [blame] | 49 | import android.content.pm.UserInfo; |
Tony Mak | 83546a8 | 2018-01-22 13:56:20 +0000 | [diff] [blame] | 50 | import android.os.Bundle; |
Ben Gruver | 1ab3d6e | 2017-12-07 13:45:08 -0800 | [diff] [blame] | 51 | import android.os.RemoteException; |
Rubin Xu | 58d2599 | 2016-01-21 17:47:13 +0000 | [diff] [blame] | 52 | import android.os.UserHandle; |
| 53 | import android.os.UserManager; |
| 54 | |
Benjamin Franz | 563707b | 2017-06-29 15:06:13 +0100 | [diff] [blame] | 55 | import com.android.internal.annotations.VisibleForTesting; |
Yuhan Zhao | f3b3d41 | 2020-01-24 23:37:13 +0000 | [diff] [blame] | 56 | import com.android.internal.app.BlockedAppActivity; |
Ben Gruver | 1ab3d6e | 2017-12-07 13:45:08 -0800 | [diff] [blame] | 57 | import com.android.internal.app.HarmfulAppWarningActivity; |
Suprabh Shukla | 3c3af14 | 2018-03-30 00:28:37 -0700 | [diff] [blame] | 58 | import com.android.internal.app.SuspendedAppActivity; |
Rubin Xu | 58d2599 | 2016-01-21 17:47:13 +0000 | [diff] [blame] | 59 | import com.android.internal.app.UnlaunchableAppActivity; |
Sudheer Shanka | 7a9c34b | 2016-03-11 12:25:51 -0800 | [diff] [blame] | 60 | import com.android.server.LocalServices; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 61 | import com.android.server.am.ActivityManagerService; |
Rubin Xu | 58d2599 | 2016-01-21 17:47:13 +0000 | [diff] [blame] | 62 | |
| 63 | /** |
| 64 | * A class that contains activity intercepting logic for {@link ActivityStarter#startActivityLocked} |
Benjamin Franz | 563707b | 2017-06-29 15:06:13 +0100 | [diff] [blame] | 65 | * It's initialized via setStates and interception occurs via the intercept method. |
| 66 | * |
| 67 | * Note that this class is instantiated when {@link ActivityManagerService} gets created so there |
| 68 | * is no guarantee that other system services are already present. |
Rubin Xu | 58d2599 | 2016-01-21 17:47:13 +0000 | [diff] [blame] | 69 | */ |
| 70 | class ActivityStartInterceptor { |
| 71 | |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 72 | private final ActivityTaskManagerService mService; |
Rubin Xu | 58d2599 | 2016-01-21 17:47:13 +0000 | [diff] [blame] | 73 | private final ActivityStackSupervisor mSupervisor; |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 74 | private final RootWindowContainer mRootWindowContainer; |
Benjamin Franz | 563707b | 2017-06-29 15:06:13 +0100 | [diff] [blame] | 75 | private final Context mServiceContext; |
Benjamin Franz | 563707b | 2017-06-29 15:06:13 +0100 | [diff] [blame] | 76 | |
| 77 | // UserManager cannot be final as it's not ready when this class is instantiated during boot |
| 78 | private UserManager mUserManager; |
Rubin Xu | 58d2599 | 2016-01-21 17:47:13 +0000 | [diff] [blame] | 79 | |
| 80 | /* |
| 81 | * Per-intent states loaded from ActivityStarter than shouldn't be changed by any |
| 82 | * interception routines. |
| 83 | */ |
| 84 | private int mRealCallingPid; |
| 85 | private int mRealCallingUid; |
| 86 | private int mUserId; |
| 87 | private int mStartFlags; |
| 88 | private String mCallingPackage; |
Philip P. Moltmann | 9c5226f | 2020-01-10 08:53:43 -0800 | [diff] [blame^] | 89 | private @Nullable String mCallingFeatureId; |
Rubin Xu | 58d2599 | 2016-01-21 17:47:13 +0000 | [diff] [blame] | 90 | |
| 91 | /* |
| 92 | * Per-intent states that were load from ActivityStarter and are subject to modifications |
| 93 | * by the interception routines. After calling {@link #intercept} the caller should assign |
Benjamin Franz | 563707b | 2017-06-29 15:06:13 +0100 | [diff] [blame] | 94 | * these values back to {@link ActivityStarter#startActivityLocked}'s local variables if |
| 95 | * {@link #intercept} returns true. |
Rubin Xu | 58d2599 | 2016-01-21 17:47:13 +0000 | [diff] [blame] | 96 | */ |
| 97 | Intent mIntent; |
| 98 | int mCallingPid; |
| 99 | int mCallingUid; |
| 100 | ResolveInfo mRInfo; |
| 101 | ActivityInfo mAInfo; |
| 102 | String mResolvedType; |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 103 | Task mInTask; |
Tony Mak | 853304c | 2016-04-18 15:17:41 +0100 | [diff] [blame] | 104 | ActivityOptions mActivityOptions; |
Rubin Xu | 58d2599 | 2016-01-21 17:47:13 +0000 | [diff] [blame] | 105 | |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 106 | ActivityStartInterceptor( |
| 107 | ActivityTaskManagerService service, ActivityStackSupervisor supervisor) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 108 | this(service, supervisor, service.mRootWindowContainer, service.mContext); |
Rubin Xu | 58d2599 | 2016-01-21 17:47:13 +0000 | [diff] [blame] | 109 | } |
| 110 | |
Benjamin Franz | 563707b | 2017-06-29 15:06:13 +0100 | [diff] [blame] | 111 | @VisibleForTesting |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 112 | ActivityStartInterceptor(ActivityTaskManagerService service, ActivityStackSupervisor supervisor, |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 113 | RootWindowContainer root, Context context) { |
Benjamin Franz | 563707b | 2017-06-29 15:06:13 +0100 | [diff] [blame] | 114 | mService = service; |
| 115 | mSupervisor = supervisor; |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 116 | mRootWindowContainer = root; |
Benjamin Franz | 563707b | 2017-06-29 15:06:13 +0100 | [diff] [blame] | 117 | mServiceContext = context; |
Benjamin Franz | 563707b | 2017-06-29 15:06:13 +0100 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | /** |
| 121 | * Effectively initialize the class before intercepting the start intent. The values set in this |
| 122 | * method should not be changed during intercept. |
| 123 | */ |
Rubin Xu | 58d2599 | 2016-01-21 17:47:13 +0000 | [diff] [blame] | 124 | void setStates(int userId, int realCallingPid, int realCallingUid, int startFlags, |
Philip P. Moltmann | 9c5226f | 2020-01-10 08:53:43 -0800 | [diff] [blame^] | 125 | String callingPackage, @Nullable String callingFeatureId) { |
Rubin Xu | 58d2599 | 2016-01-21 17:47:13 +0000 | [diff] [blame] | 126 | mRealCallingPid = realCallingPid; |
| 127 | mRealCallingUid = realCallingUid; |
| 128 | mUserId = userId; |
| 129 | mStartFlags = startFlags; |
| 130 | mCallingPackage = callingPackage; |
Philip P. Moltmann | 9c5226f | 2020-01-10 08:53:43 -0800 | [diff] [blame^] | 131 | mCallingFeatureId = callingFeatureId; |
Rubin Xu | 58d2599 | 2016-01-21 17:47:13 +0000 | [diff] [blame] | 132 | } |
| 133 | |
Ben Gruver | 1ab3d6e | 2017-12-07 13:45:08 -0800 | [diff] [blame] | 134 | private IntentSender createIntentSenderForOriginalIntent(int callingUid, int flags) { |
Tony Mak | 83546a8 | 2018-01-22 13:56:20 +0000 | [diff] [blame] | 135 | Bundle activityOptions = deferCrossProfileAppsAnimationIfNecessary(); |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 136 | final IIntentSender target = mService.getIntentSenderLocked( |
Philip P. Moltmann | 9c5226f | 2020-01-10 08:53:43 -0800 | [diff] [blame^] | 137 | INTENT_SENDER_ACTIVITY, mCallingPackage, mCallingFeatureId, callingUid, mUserId, |
| 138 | null /*token*/, null /*resultCode*/, 0 /*requestCode*/, |
Ben Gruver | 1ab3d6e | 2017-12-07 13:45:08 -0800 | [diff] [blame] | 139 | new Intent[] { mIntent }, new String[] { mResolvedType }, |
Tony Mak | 83546a8 | 2018-01-22 13:56:20 +0000 | [diff] [blame] | 140 | flags, activityOptions); |
Ben Gruver | 1ab3d6e | 2017-12-07 13:45:08 -0800 | [diff] [blame] | 141 | return new IntentSender(target); |
| 142 | } |
| 143 | |
Benjamin Franz | 563707b | 2017-06-29 15:06:13 +0100 | [diff] [blame] | 144 | /** |
| 145 | * Intercept the launch intent based on various signals. If an interception happened the |
| 146 | * internal variables get assigned and need to be read explicitly by the caller. |
| 147 | * |
| 148 | * @return true if an interception occurred |
| 149 | */ |
| 150 | boolean intercept(Intent intent, ResolveInfo rInfo, ActivityInfo aInfo, String resolvedType, |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 151 | Task inTask, int callingPid, int callingUid, ActivityOptions activityOptions) { |
Benjamin Franz | 563707b | 2017-06-29 15:06:13 +0100 | [diff] [blame] | 152 | mUserManager = UserManager.get(mServiceContext); |
| 153 | |
Rubin Xu | 58d2599 | 2016-01-21 17:47:13 +0000 | [diff] [blame] | 154 | mIntent = intent; |
| 155 | mCallingPid = callingPid; |
| 156 | mCallingUid = callingUid; |
| 157 | mRInfo = rInfo; |
| 158 | mAInfo = aInfo; |
| 159 | mResolvedType = resolvedType; |
| 160 | mInTask = inTask; |
Tony Mak | 853304c | 2016-04-18 15:17:41 +0100 | [diff] [blame] | 161 | mActivityOptions = activityOptions; |
Benjamin Franz | 563707b | 2017-06-29 15:06:13 +0100 | [diff] [blame] | 162 | |
Rubin Xu | b93522a | 2016-02-23 18:21:48 +0000 | [diff] [blame] | 163 | if (interceptQuietProfileIfNeeded()) { |
| 164 | // If work profile is turned off, skip the work challenge since the profile can only |
| 165 | // be unlocked when profile's user is running. |
Benjamin Franz | 563707b | 2017-06-29 15:06:13 +0100 | [diff] [blame] | 166 | return true; |
Rubin Xu | b93522a | 2016-02-23 18:21:48 +0000 | [diff] [blame] | 167 | } |
Louis Chang | 97f743f | 2019-11-26 13:03:10 +0800 | [diff] [blame] | 168 | if (interceptSuspendedPackageIfNeeded()) { |
| 169 | // Skip the rest of interceptions as the package is suspended by device admin so |
| 170 | // no user action can undo this. |
| 171 | return true; |
| 172 | } |
Yuhan Zhao | f3b3d41 | 2020-01-24 23:37:13 +0000 | [diff] [blame] | 173 | if (interceptLockTaskModeViolationPackageIfNeeded()) { |
| 174 | return true; |
| 175 | } |
Ben Gruver | 1ab3d6e | 2017-12-07 13:45:08 -0800 | [diff] [blame] | 176 | if (interceptHarmfulAppIfNeeded()) { |
| 177 | // If the app has a "harmful app" warning associated with it, we should ask to uninstall |
| 178 | // before issuing the work challenge. |
| 179 | return true; |
| 180 | } |
Benjamin Franz | 563707b | 2017-06-29 15:06:13 +0100 | [diff] [blame] | 181 | return interceptWorkProfileChallengeIfNeeded(); |
Rubin Xu | 58d2599 | 2016-01-21 17:47:13 +0000 | [diff] [blame] | 182 | } |
| 183 | |
Suprabh Shukla | 0cb5713 | 2020-01-18 20:15:08 -0800 | [diff] [blame] | 184 | private boolean hasCrossProfileAnimation() { |
| 185 | return mActivityOptions != null |
| 186 | && mActivityOptions.getAnimationType() == ANIM_OPEN_CROSS_PROFILE_APPS; |
| 187 | } |
| 188 | |
Tony Mak | 83546a8 | 2018-01-22 13:56:20 +0000 | [diff] [blame] | 189 | /** |
| 190 | * If the activity option is the {@link ActivityOptions#ANIM_OPEN_CROSS_PROFILE_APPS} one, |
| 191 | * defer the animation until the original intent is started. |
| 192 | * |
| 193 | * @return the activity option used to start the original intent. |
| 194 | */ |
| 195 | private Bundle deferCrossProfileAppsAnimationIfNecessary() { |
Suprabh Shukla | 0cb5713 | 2020-01-18 20:15:08 -0800 | [diff] [blame] | 196 | if (hasCrossProfileAnimation()) { |
Tony Mak | 83546a8 | 2018-01-22 13:56:20 +0000 | [diff] [blame] | 197 | mActivityOptions = null; |
| 198 | return ActivityOptions.makeOpenCrossProfileAppsAnimation().toBundle(); |
| 199 | } |
| 200 | return null; |
| 201 | } |
| 202 | |
Rubin Xu | b93522a | 2016-02-23 18:21:48 +0000 | [diff] [blame] | 203 | private boolean interceptQuietProfileIfNeeded() { |
Rubin Xu | 58d2599 | 2016-01-21 17:47:13 +0000 | [diff] [blame] | 204 | // Do not intercept if the user has not turned off the profile |
| 205 | if (!mUserManager.isQuietModeEnabled(UserHandle.of(mUserId))) { |
Rubin Xu | b93522a | 2016-02-23 18:21:48 +0000 | [diff] [blame] | 206 | return false; |
Rubin Xu | 58d2599 | 2016-01-21 17:47:13 +0000 | [diff] [blame] | 207 | } |
Tony Mak | 83546a8 | 2018-01-22 13:56:20 +0000 | [diff] [blame] | 208 | |
Ben Gruver | 1ab3d6e | 2017-12-07 13:45:08 -0800 | [diff] [blame] | 209 | IntentSender target = createIntentSenderForOriginalIntent(mCallingUid, |
| 210 | FLAG_CANCEL_CURRENT | FLAG_ONE_SHOT); |
Rubin Xu | e420c55 | 2016-04-06 19:04:30 +0100 | [diff] [blame] | 211 | |
Ben Gruver | 1ab3d6e | 2017-12-07 13:45:08 -0800 | [diff] [blame] | 212 | mIntent = UnlaunchableAppActivity.createInQuietModeDialogIntent(mUserId, target); |
Rubin Xu | 58d2599 | 2016-01-21 17:47:13 +0000 | [diff] [blame] | 213 | mCallingPid = mRealCallingPid; |
| 214 | mCallingUid = mRealCallingUid; |
| 215 | mResolvedType = null; |
| 216 | |
| 217 | final UserInfo parent = mUserManager.getProfileParent(mUserId); |
Makoto Onuki | 1a34274 | 2018-04-26 14:56:59 -0700 | [diff] [blame] | 218 | mRInfo = mSupervisor.resolveIntent(mIntent, mResolvedType, parent.id, 0, mRealCallingUid); |
Rubin Xu | b93522a | 2016-02-23 18:21:48 +0000 | [diff] [blame] | 219 | mAInfo = mSupervisor.resolveActivity(mIntent, mRInfo, mStartFlags, null /*profilerInfo*/); |
| 220 | return true; |
Rubin Xu | 58d2599 | 2016-01-21 17:47:13 +0000 | [diff] [blame] | 221 | } |
| 222 | |
Suprabh Shukla | 3c3af14 | 2018-03-30 00:28:37 -0700 | [diff] [blame] | 223 | private boolean interceptSuspendedByAdminPackage() { |
Benjamin Franz | 563707b | 2017-06-29 15:06:13 +0100 | [diff] [blame] | 224 | DevicePolicyManagerInternal devicePolicyManager = LocalServices |
| 225 | .getService(DevicePolicyManagerInternal.class); |
Makoto Onuki | 2670495 | 2016-06-13 14:50:11 -0700 | [diff] [blame] | 226 | if (devicePolicyManager == null) { |
| 227 | return false; |
| 228 | } |
Nicolas Prevot | 709a63d | 2016-06-09 13:14:00 +0100 | [diff] [blame] | 229 | mIntent = devicePolicyManager.createShowAdminSupportIntent(mUserId, true); |
Tony Mak | 706fbe7 | 2018-04-03 18:49:05 +0100 | [diff] [blame] | 230 | mIntent.putExtra(EXTRA_RESTRICTION, POLICY_SUSPEND_PACKAGES); |
| 231 | |
Rubin Xu | 58d2599 | 2016-01-21 17:47:13 +0000 | [diff] [blame] | 232 | mCallingPid = mRealCallingPid; |
| 233 | mCallingUid = mRealCallingUid; |
| 234 | mResolvedType = null; |
| 235 | |
| 236 | final UserInfo parent = mUserManager.getProfileParent(mUserId); |
| 237 | if (parent != null) { |
Makoto Onuki | 1a34274 | 2018-04-26 14:56:59 -0700 | [diff] [blame] | 238 | mRInfo = mSupervisor.resolveIntent(mIntent, mResolvedType, parent.id, 0, |
| 239 | mRealCallingUid); |
Rubin Xu | 58d2599 | 2016-01-21 17:47:13 +0000 | [diff] [blame] | 240 | } else { |
Makoto Onuki | 1a34274 | 2018-04-26 14:56:59 -0700 | [diff] [blame] | 241 | mRInfo = mSupervisor.resolveIntent(mIntent, mResolvedType, mUserId, 0, |
| 242 | mRealCallingUid); |
Rubin Xu | 58d2599 | 2016-01-21 17:47:13 +0000 | [diff] [blame] | 243 | } |
Rubin Xu | b93522a | 2016-02-23 18:21:48 +0000 | [diff] [blame] | 244 | mAInfo = mSupervisor.resolveActivity(mIntent, mRInfo, mStartFlags, null /*profilerInfo*/); |
| 245 | return true; |
Rubin Xu | 58d2599 | 2016-01-21 17:47:13 +0000 | [diff] [blame] | 246 | } |
| 247 | |
Suprabh Shukla | 3c3af14 | 2018-03-30 00:28:37 -0700 | [diff] [blame] | 248 | private boolean interceptSuspendedPackageIfNeeded() { |
| 249 | // Do not intercept if the package is not suspended |
| 250 | if (mAInfo == null || mAInfo.applicationInfo == null || |
| 251 | (mAInfo.applicationInfo.flags & FLAG_SUSPENDED) == 0) { |
| 252 | return false; |
| 253 | } |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 254 | final PackageManagerInternal pmi = mService.getPackageManagerInternalLocked(); |
Suprabh Shukla | 3c3af14 | 2018-03-30 00:28:37 -0700 | [diff] [blame] | 255 | if (pmi == null) { |
| 256 | return false; |
| 257 | } |
| 258 | final String suspendedPackage = mAInfo.applicationInfo.packageName; |
| 259 | final String suspendingPackage = pmi.getSuspendingPackage(suspendedPackage, mUserId); |
| 260 | if (PLATFORM_PACKAGE_NAME.equals(suspendingPackage)) { |
| 261 | return interceptSuspendedByAdminPackage(); |
| 262 | } |
Suprabh Shukla | d327844 | 2019-08-27 15:58:03 -0700 | [diff] [blame] | 263 | final SuspendDialogInfo dialogInfo = pmi.getSuspendedDialogInfo(suspendedPackage, |
| 264 | suspendingPackage, mUserId); |
Suprabh Shukla | 0cb5713 | 2020-01-18 20:15:08 -0800 | [diff] [blame] | 265 | final Bundle crossProfileOptions = hasCrossProfileAnimation() |
| 266 | ? ActivityOptions.makeOpenCrossProfileAppsAnimation().toBundle() |
| 267 | : null; |
| 268 | final IntentSender target = createIntentSenderForOriginalIntent(mCallingUid, |
| 269 | FLAG_IMMUTABLE); |
Suprabh Shukla | 1ab90a2 | 2018-05-10 15:54:08 -0700 | [diff] [blame] | 270 | mIntent = SuspendedAppActivity.createSuspendedAppInterceptIntent(suspendedPackage, |
Suprabh Shukla | 0cb5713 | 2020-01-18 20:15:08 -0800 | [diff] [blame] | 271 | suspendingPackage, dialogInfo, crossProfileOptions, target, mUserId); |
Suprabh Shukla | 3c3af14 | 2018-03-30 00:28:37 -0700 | [diff] [blame] | 272 | mCallingPid = mRealCallingPid; |
| 273 | mCallingUid = mRealCallingUid; |
| 274 | mResolvedType = null; |
Makoto Onuki | 1a34274 | 2018-04-26 14:56:59 -0700 | [diff] [blame] | 275 | mRInfo = mSupervisor.resolveIntent(mIntent, mResolvedType, mUserId, 0, mRealCallingUid); |
Suprabh Shukla | 3c3af14 | 2018-03-30 00:28:37 -0700 | [diff] [blame] | 276 | mAInfo = mSupervisor.resolveActivity(mIntent, mRInfo, mStartFlags, null /*profilerInfo*/); |
| 277 | return true; |
| 278 | } |
| 279 | |
Yuhan Zhao | f3b3d41 | 2020-01-24 23:37:13 +0000 | [diff] [blame] | 280 | private boolean interceptLockTaskModeViolationPackageIfNeeded() { |
| 281 | if (mAInfo == null || mAInfo.applicationInfo == null) { |
| 282 | return false; |
| 283 | } |
| 284 | LockTaskController controller = mService.getLockTaskController(); |
| 285 | String packageName = mAInfo.applicationInfo.packageName; |
| 286 | int lockTaskLaunchMode = ActivityRecord.getLockTaskLaunchMode(mAInfo, mActivityOptions); |
| 287 | if (controller.isActivityAllowed(mUserId, packageName, lockTaskLaunchMode)) { |
| 288 | return false; |
| 289 | } |
| 290 | mIntent = BlockedAppActivity.createIntent(mUserId, mAInfo.applicationInfo.packageName); |
| 291 | mCallingPid = mRealCallingPid; |
| 292 | mCallingUid = mRealCallingUid; |
| 293 | mResolvedType = null; |
| 294 | mRInfo = mSupervisor.resolveIntent(mIntent, mResolvedType, mUserId, 0, mRealCallingUid); |
| 295 | mAInfo = mSupervisor.resolveActivity(mIntent, mRInfo, mStartFlags, null /*profilerInfo*/); |
| 296 | return true; |
| 297 | } |
| 298 | |
Rubin Xu | b93522a | 2016-02-23 18:21:48 +0000 | [diff] [blame] | 299 | private boolean interceptWorkProfileChallengeIfNeeded() { |
Tony Mak | 83546a8 | 2018-01-22 13:56:20 +0000 | [diff] [blame] | 300 | final Intent interceptingIntent = interceptWithConfirmCredentialsIfNeeded(mAInfo, mUserId); |
Rubin Xu | 58d2599 | 2016-01-21 17:47:13 +0000 | [diff] [blame] | 301 | if (interceptingIntent == null) { |
Rubin Xu | b93522a | 2016-02-23 18:21:48 +0000 | [diff] [blame] | 302 | return false; |
Rubin Xu | 58d2599 | 2016-01-21 17:47:13 +0000 | [diff] [blame] | 303 | } |
| 304 | mIntent = interceptingIntent; |
| 305 | mCallingPid = mRealCallingPid; |
| 306 | mCallingUid = mRealCallingUid; |
| 307 | mResolvedType = null; |
| 308 | // If we are intercepting and there was a task, convert it into an extra for the |
| 309 | // ConfirmCredentials intent and unassign it, as otherwise the task will move to |
| 310 | // front even if ConfirmCredentials is cancelled. |
| 311 | if (mInTask != null) { |
Wale Ogunwale | 4e79a1c | 2019-10-05 20:52:40 -0700 | [diff] [blame] | 312 | mIntent.putExtra(EXTRA_TASK_ID, mInTask.mTaskId); |
Rubin Xu | 58d2599 | 2016-01-21 17:47:13 +0000 | [diff] [blame] | 313 | mInTask = null; |
| 314 | } |
Tony Mak | 853304c | 2016-04-18 15:17:41 +0100 | [diff] [blame] | 315 | if (mActivityOptions == null) { |
| 316 | mActivityOptions = ActivityOptions.makeBasic(); |
| 317 | } |
Victor Chang | 89d4a9a | 2016-06-14 13:49:32 +0100 | [diff] [blame] | 318 | |
Rubin Xu | 58d2599 | 2016-01-21 17:47:13 +0000 | [diff] [blame] | 319 | final UserInfo parent = mUserManager.getProfileParent(mUserId); |
Makoto Onuki | 1a34274 | 2018-04-26 14:56:59 -0700 | [diff] [blame] | 320 | mRInfo = mSupervisor.resolveIntent(mIntent, mResolvedType, parent.id, 0, mRealCallingUid); |
Rubin Xu | b93522a | 2016-02-23 18:21:48 +0000 | [diff] [blame] | 321 | mAInfo = mSupervisor.resolveActivity(mIntent, mRInfo, mStartFlags, null /*profilerInfo*/); |
| 322 | return true; |
Rubin Xu | 58d2599 | 2016-01-21 17:47:13 +0000 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | /** |
| 326 | * Creates an intent to intercept the current activity start with Confirm Credentials if needed. |
| 327 | * |
| 328 | * @return The intercepting intent if needed. |
| 329 | */ |
Tony Mak | 83546a8 | 2018-01-22 13:56:20 +0000 | [diff] [blame] | 330 | private Intent interceptWithConfirmCredentialsIfNeeded(ActivityInfo aInfo, int userId) { |
Wale Ogunwale | 86b7446 | 2018-07-02 08:42:43 -0700 | [diff] [blame] | 331 | if (!mService.mAmInternal.shouldConfirmCredentials(userId)) { |
Rubin Xu | 58d2599 | 2016-01-21 17:47:13 +0000 | [diff] [blame] | 332 | return null; |
| 333 | } |
Charles He | e7c5ced | 2017-04-12 16:22:35 +0100 | [diff] [blame] | 334 | // TODO(b/28935539): should allow certain activities to bypass work challenge |
Eran Messeri | 99882e6 | 2019-05-08 15:35:53 +0100 | [diff] [blame] | 335 | final IntentSender target = createIntentSenderForOriginalIntent(mCallingUid, |
Ben Gruver | 1ab3d6e | 2017-12-07 13:45:08 -0800 | [diff] [blame] | 336 | FLAG_CANCEL_CURRENT | FLAG_ONE_SHOT | FLAG_IMMUTABLE); |
Benjamin Franz | 563707b | 2017-06-29 15:06:13 +0100 | [diff] [blame] | 337 | final KeyguardManager km = (KeyguardManager) mServiceContext |
Rubin Xu | 58d2599 | 2016-01-21 17:47:13 +0000 | [diff] [blame] | 338 | .getSystemService(KEYGUARD_SERVICE); |
joshmccloskey | 15c0a44 | 2019-10-18 16:09:06 -0700 | [diff] [blame] | 339 | final Intent newIntent = km.createConfirmDeviceCredentialIntent(null, null, userId, |
| 340 | true /* disallowBiometricsIfPolicyExists */); |
Rubin Xu | 58d2599 | 2016-01-21 17:47:13 +0000 | [diff] [blame] | 341 | if (newIntent == null) { |
| 342 | return null; |
| 343 | } |
Tony Mak | 4291c76 | 2016-03-24 12:23:22 +0000 | [diff] [blame] | 344 | newIntent.setFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS | |
| 345 | FLAG_ACTIVITY_TASK_ON_HOME); |
Rubin Xu | 58d2599 | 2016-01-21 17:47:13 +0000 | [diff] [blame] | 346 | newIntent.putExtra(EXTRA_PACKAGE_NAME, aInfo.packageName); |
Ben Gruver | 1ab3d6e | 2017-12-07 13:45:08 -0800 | [diff] [blame] | 347 | newIntent.putExtra(EXTRA_INTENT, target); |
Rubin Xu | 58d2599 | 2016-01-21 17:47:13 +0000 | [diff] [blame] | 348 | return newIntent; |
| 349 | } |
| 350 | |
Ben Gruver | 1ab3d6e | 2017-12-07 13:45:08 -0800 | [diff] [blame] | 351 | private boolean interceptHarmfulAppIfNeeded() { |
| 352 | CharSequence harmfulAppWarning; |
| 353 | try { |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 354 | harmfulAppWarning = mService.getPackageManager() |
Ben Gruver | 27ffd82 | 2018-03-07 13:24:18 -0800 | [diff] [blame] | 355 | .getHarmfulAppWarning(mAInfo.packageName, mUserId); |
| 356 | } catch (RemoteException ex) { |
Ben Gruver | 1ab3d6e | 2017-12-07 13:45:08 -0800 | [diff] [blame] | 357 | return false; |
| 358 | } |
| 359 | |
| 360 | if (harmfulAppWarning == null) { |
| 361 | return false; |
| 362 | } |
| 363 | |
| 364 | final IntentSender target = createIntentSenderForOriginalIntent(mCallingUid, |
| 365 | FLAG_CANCEL_CURRENT | FLAG_ONE_SHOT | FLAG_IMMUTABLE); |
| 366 | |
| 367 | mIntent = HarmfulAppWarningActivity.createHarmfulAppWarningIntent(mServiceContext, |
| 368 | mAInfo.packageName, target, harmfulAppWarning); |
| 369 | |
| 370 | mCallingPid = mRealCallingPid; |
| 371 | mCallingUid = mRealCallingUid; |
| 372 | mResolvedType = null; |
| 373 | |
Makoto Onuki | 1a34274 | 2018-04-26 14:56:59 -0700 | [diff] [blame] | 374 | mRInfo = mSupervisor.resolveIntent(mIntent, mResolvedType, mUserId, 0, mRealCallingUid); |
Ben Gruver | 1ab3d6e | 2017-12-07 13:45:08 -0800 | [diff] [blame] | 375 | mAInfo = mSupervisor.resolveActivity(mIntent, mRInfo, mStartFlags, null /*profilerInfo*/); |
| 376 | return true; |
| 377 | } |
Rubin Xu | 58d2599 | 2016-01-21 17:47:13 +0000 | [diff] [blame] | 378 | } |