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