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