blob: 100977187239952b1c26f30cf6427cd56e3359b1 [file] [log] [blame]
Kenny Guyb1b30262016-02-09 16:02:35 +00001/*
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 Ogunwale59507092018-10-29 09:00:30 -070017package com.android.server.wm;
Rubin Xu58d25992016-01-21 17:47:13 +000018
19import static android.app.ActivityManager.INTENT_SENDER_ACTIVITY;
Tony Mak83546a82018-01-22 13:56:20 +000020import static android.app.ActivityOptions.ANIM_OPEN_CROSS_PROFILE_APPS;
Rubin Xu58d25992016-01-21 17:47:13 +000021import static android.app.PendingIntent.FLAG_CANCEL_CURRENT;
22import static android.app.PendingIntent.FLAG_IMMUTABLE;
23import static android.app.PendingIntent.FLAG_ONE_SHOT;
Tony Mak706fbe72018-04-03 18:49:05 +010024import static android.app.admin.DevicePolicyManager.EXTRA_RESTRICTION;
25import static android.app.admin.DevicePolicyManager.POLICY_SUSPEND_PACKAGES;
Rubin Xu58d25992016-01-21 17:47:13 +000026import static android.content.Context.KEYGUARD_SERVICE;
27import static android.content.Intent.EXTRA_INTENT;
28import static android.content.Intent.EXTRA_PACKAGE_NAME;
29import static android.content.Intent.EXTRA_TASK_ID;
30import static android.content.Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS;
31import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
Tony Mak4291c762016-03-24 12:23:22 +000032import static android.content.Intent.FLAG_ACTIVITY_TASK_ON_HOME;
Rubin Xu58d25992016-01-21 17:47:13 +000033import static android.content.pm.ApplicationInfo.FLAG_SUSPENDED;
34
Suprabh Shukla3c3af142018-03-30 00:28:37 -070035import static com.android.server.pm.PackageManagerService.PLATFORM_PACKAGE_NAME;
36
Philip P. Moltmann9c5226f2020-01-10 08:53:43 -080037import android.annotation.Nullable;
Tony Mak853304c2016-04-18 15:17:41 +010038import android.app.ActivityOptions;
Rubin Xu58d25992016-01-21 17:47:13 +000039import android.app.KeyguardManager;
Sudheer Shanka7a9c34b2016-03-11 12:25:51 -080040import android.app.admin.DevicePolicyManagerInternal;
Benjamin Franz563707b2017-06-29 15:06:13 +010041import android.content.Context;
Rubin Xu58d25992016-01-21 17:47:13 +000042import android.content.IIntentSender;
43import android.content.Intent;
44import android.content.IntentSender;
45import android.content.pm.ActivityInfo;
Suprabh Shukla3c3af142018-03-30 00:28:37 -070046import android.content.pm.PackageManagerInternal;
Rubin Xu58d25992016-01-21 17:47:13 +000047import android.content.pm.ResolveInfo;
Suprabh Shukla389cb6f2018-10-01 18:20:39 -070048import android.content.pm.SuspendDialogInfo;
Rubin Xu58d25992016-01-21 17:47:13 +000049import android.content.pm.UserInfo;
Tony Mak83546a82018-01-22 13:56:20 +000050import android.os.Bundle;
Ben Gruver1ab3d6e2017-12-07 13:45:08 -080051import android.os.RemoteException;
Rubin Xu58d25992016-01-21 17:47:13 +000052import android.os.UserHandle;
53import android.os.UserManager;
54
Benjamin Franz563707b2017-06-29 15:06:13 +010055import com.android.internal.annotations.VisibleForTesting;
Yuhan Zhaof3b3d412020-01-24 23:37:13 +000056import com.android.internal.app.BlockedAppActivity;
Ben Gruver1ab3d6e2017-12-07 13:45:08 -080057import com.android.internal.app.HarmfulAppWarningActivity;
Suprabh Shukla3c3af142018-03-30 00:28:37 -070058import com.android.internal.app.SuspendedAppActivity;
Rubin Xu58d25992016-01-21 17:47:13 +000059import com.android.internal.app.UnlaunchableAppActivity;
Sudheer Shanka7a9c34b2016-03-11 12:25:51 -080060import com.android.server.LocalServices;
Wale Ogunwale59507092018-10-29 09:00:30 -070061import com.android.server.am.ActivityManagerService;
Rubin Xu58d25992016-01-21 17:47:13 +000062
63/**
64 * A class that contains activity intercepting logic for {@link ActivityStarter#startActivityLocked}
Benjamin Franz563707b2017-06-29 15:06:13 +010065 * 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 Xu58d25992016-01-21 17:47:13 +000069 */
70class ActivityStartInterceptor {
71
Wale Ogunwalec9e57de2018-05-08 14:28:07 -070072 private final ActivityTaskManagerService mService;
Rubin Xu58d25992016-01-21 17:47:13 +000073 private final ActivityStackSupervisor mSupervisor;
Louis Chang149d5c82019-12-30 09:47:39 +080074 private final RootWindowContainer mRootWindowContainer;
Benjamin Franz563707b2017-06-29 15:06:13 +010075 private final Context mServiceContext;
Benjamin Franz563707b2017-06-29 15:06:13 +010076
77 // UserManager cannot be final as it's not ready when this class is instantiated during boot
78 private UserManager mUserManager;
Rubin Xu58d25992016-01-21 17:47:13 +000079
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. Moltmann9c5226f2020-01-10 08:53:43 -080089 private @Nullable String mCallingFeatureId;
Rubin Xu58d25992016-01-21 17:47:13 +000090
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 Franz563707b2017-06-29 15:06:13 +010094 * these values back to {@link ActivityStarter#startActivityLocked}'s local variables if
95 * {@link #intercept} returns true.
Rubin Xu58d25992016-01-21 17:47:13 +000096 */
97 Intent mIntent;
98 int mCallingPid;
99 int mCallingUid;
100 ResolveInfo mRInfo;
101 ActivityInfo mAInfo;
102 String mResolvedType;
Louis Changcdec0802019-11-11 11:45:07 +0800103 Task mInTask;
Tony Mak853304c2016-04-18 15:17:41 +0100104 ActivityOptions mActivityOptions;
Rubin Xu58d25992016-01-21 17:47:13 +0000105
Wale Ogunwalec9e57de2018-05-08 14:28:07 -0700106 ActivityStartInterceptor(
107 ActivityTaskManagerService service, ActivityStackSupervisor supervisor) {
Louis Chang149d5c82019-12-30 09:47:39 +0800108 this(service, supervisor, service.mRootWindowContainer, service.mContext);
Rubin Xu58d25992016-01-21 17:47:13 +0000109 }
110
Benjamin Franz563707b2017-06-29 15:06:13 +0100111 @VisibleForTesting
Wale Ogunwalec9e57de2018-05-08 14:28:07 -0700112 ActivityStartInterceptor(ActivityTaskManagerService service, ActivityStackSupervisor supervisor,
Louis Chang149d5c82019-12-30 09:47:39 +0800113 RootWindowContainer root, Context context) {
Benjamin Franz563707b2017-06-29 15:06:13 +0100114 mService = service;
115 mSupervisor = supervisor;
Louis Chang149d5c82019-12-30 09:47:39 +0800116 mRootWindowContainer = root;
Benjamin Franz563707b2017-06-29 15:06:13 +0100117 mServiceContext = context;
Benjamin Franz563707b2017-06-29 15:06:13 +0100118 }
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 Xu58d25992016-01-21 17:47:13 +0000124 void setStates(int userId, int realCallingPid, int realCallingUid, int startFlags,
Philip P. Moltmann9c5226f2020-01-10 08:53:43 -0800125 String callingPackage, @Nullable String callingFeatureId) {
Rubin Xu58d25992016-01-21 17:47:13 +0000126 mRealCallingPid = realCallingPid;
127 mRealCallingUid = realCallingUid;
128 mUserId = userId;
129 mStartFlags = startFlags;
130 mCallingPackage = callingPackage;
Philip P. Moltmann9c5226f2020-01-10 08:53:43 -0800131 mCallingFeatureId = callingFeatureId;
Rubin Xu58d25992016-01-21 17:47:13 +0000132 }
133
Ben Gruver1ab3d6e2017-12-07 13:45:08 -0800134 private IntentSender createIntentSenderForOriginalIntent(int callingUid, int flags) {
Tony Mak83546a82018-01-22 13:56:20 +0000135 Bundle activityOptions = deferCrossProfileAppsAnimationIfNecessary();
Wale Ogunwaleee6eca12018-09-19 20:37:53 -0700136 final IIntentSender target = mService.getIntentSenderLocked(
Philip P. Moltmann9c5226f2020-01-10 08:53:43 -0800137 INTENT_SENDER_ACTIVITY, mCallingPackage, mCallingFeatureId, callingUid, mUserId,
138 null /*token*/, null /*resultCode*/, 0 /*requestCode*/,
Ben Gruver1ab3d6e2017-12-07 13:45:08 -0800139 new Intent[] { mIntent }, new String[] { mResolvedType },
Tony Mak83546a82018-01-22 13:56:20 +0000140 flags, activityOptions);
Ben Gruver1ab3d6e2017-12-07 13:45:08 -0800141 return new IntentSender(target);
142 }
143
Benjamin Franz563707b2017-06-29 15:06:13 +0100144 /**
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 Changcdec0802019-11-11 11:45:07 +0800151 Task inTask, int callingPid, int callingUid, ActivityOptions activityOptions) {
Benjamin Franz563707b2017-06-29 15:06:13 +0100152 mUserManager = UserManager.get(mServiceContext);
153
Rubin Xu58d25992016-01-21 17:47:13 +0000154 mIntent = intent;
155 mCallingPid = callingPid;
156 mCallingUid = callingUid;
157 mRInfo = rInfo;
158 mAInfo = aInfo;
159 mResolvedType = resolvedType;
160 mInTask = inTask;
Tony Mak853304c2016-04-18 15:17:41 +0100161 mActivityOptions = activityOptions;
Benjamin Franz563707b2017-06-29 15:06:13 +0100162
Rubin Xub93522a2016-02-23 18:21:48 +0000163 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 Franz563707b2017-06-29 15:06:13 +0100166 return true;
Rubin Xub93522a2016-02-23 18:21:48 +0000167 }
Louis Chang97f743f2019-11-26 13:03:10 +0800168 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 Zhaof3b3d412020-01-24 23:37:13 +0000173 if (interceptLockTaskModeViolationPackageIfNeeded()) {
174 return true;
175 }
Ben Gruver1ab3d6e2017-12-07 13:45:08 -0800176 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 Franz563707b2017-06-29 15:06:13 +0100181 return interceptWorkProfileChallengeIfNeeded();
Rubin Xu58d25992016-01-21 17:47:13 +0000182 }
183
Suprabh Shukla0cb57132020-01-18 20:15:08 -0800184 private boolean hasCrossProfileAnimation() {
185 return mActivityOptions != null
186 && mActivityOptions.getAnimationType() == ANIM_OPEN_CROSS_PROFILE_APPS;
187 }
188
Tony Mak83546a82018-01-22 13:56:20 +0000189 /**
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 Shukla0cb57132020-01-18 20:15:08 -0800196 if (hasCrossProfileAnimation()) {
Tony Mak83546a82018-01-22 13:56:20 +0000197 mActivityOptions = null;
198 return ActivityOptions.makeOpenCrossProfileAppsAnimation().toBundle();
199 }
200 return null;
201 }
202
Rubin Xub93522a2016-02-23 18:21:48 +0000203 private boolean interceptQuietProfileIfNeeded() {
Rubin Xu58d25992016-01-21 17:47:13 +0000204 // Do not intercept if the user has not turned off the profile
205 if (!mUserManager.isQuietModeEnabled(UserHandle.of(mUserId))) {
Rubin Xub93522a2016-02-23 18:21:48 +0000206 return false;
Rubin Xu58d25992016-01-21 17:47:13 +0000207 }
Tony Mak83546a82018-01-22 13:56:20 +0000208
Ben Gruver1ab3d6e2017-12-07 13:45:08 -0800209 IntentSender target = createIntentSenderForOriginalIntent(mCallingUid,
210 FLAG_CANCEL_CURRENT | FLAG_ONE_SHOT);
Rubin Xue420c552016-04-06 19:04:30 +0100211
Ben Gruver1ab3d6e2017-12-07 13:45:08 -0800212 mIntent = UnlaunchableAppActivity.createInQuietModeDialogIntent(mUserId, target);
Rubin Xu58d25992016-01-21 17:47:13 +0000213 mCallingPid = mRealCallingPid;
214 mCallingUid = mRealCallingUid;
215 mResolvedType = null;
216
217 final UserInfo parent = mUserManager.getProfileParent(mUserId);
Makoto Onuki1a342742018-04-26 14:56:59 -0700218 mRInfo = mSupervisor.resolveIntent(mIntent, mResolvedType, parent.id, 0, mRealCallingUid);
Rubin Xub93522a2016-02-23 18:21:48 +0000219 mAInfo = mSupervisor.resolveActivity(mIntent, mRInfo, mStartFlags, null /*profilerInfo*/);
220 return true;
Rubin Xu58d25992016-01-21 17:47:13 +0000221 }
222
Suprabh Shukla3c3af142018-03-30 00:28:37 -0700223 private boolean interceptSuspendedByAdminPackage() {
Benjamin Franz563707b2017-06-29 15:06:13 +0100224 DevicePolicyManagerInternal devicePolicyManager = LocalServices
225 .getService(DevicePolicyManagerInternal.class);
Makoto Onuki26704952016-06-13 14:50:11 -0700226 if (devicePolicyManager == null) {
227 return false;
228 }
Nicolas Prevot709a63d2016-06-09 13:14:00 +0100229 mIntent = devicePolicyManager.createShowAdminSupportIntent(mUserId, true);
Tony Mak706fbe72018-04-03 18:49:05 +0100230 mIntent.putExtra(EXTRA_RESTRICTION, POLICY_SUSPEND_PACKAGES);
231
Rubin Xu58d25992016-01-21 17:47:13 +0000232 mCallingPid = mRealCallingPid;
233 mCallingUid = mRealCallingUid;
234 mResolvedType = null;
235
236 final UserInfo parent = mUserManager.getProfileParent(mUserId);
237 if (parent != null) {
Makoto Onuki1a342742018-04-26 14:56:59 -0700238 mRInfo = mSupervisor.resolveIntent(mIntent, mResolvedType, parent.id, 0,
239 mRealCallingUid);
Rubin Xu58d25992016-01-21 17:47:13 +0000240 } else {
Makoto Onuki1a342742018-04-26 14:56:59 -0700241 mRInfo = mSupervisor.resolveIntent(mIntent, mResolvedType, mUserId, 0,
242 mRealCallingUid);
Rubin Xu58d25992016-01-21 17:47:13 +0000243 }
Rubin Xub93522a2016-02-23 18:21:48 +0000244 mAInfo = mSupervisor.resolveActivity(mIntent, mRInfo, mStartFlags, null /*profilerInfo*/);
245 return true;
Rubin Xu58d25992016-01-21 17:47:13 +0000246 }
247
Suprabh Shukla3c3af142018-03-30 00:28:37 -0700248 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 Ogunwale906f9c62018-07-23 11:23:44 -0700254 final PackageManagerInternal pmi = mService.getPackageManagerInternalLocked();
Suprabh Shukla3c3af142018-03-30 00:28:37 -0700255 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 Shuklad3278442019-08-27 15:58:03 -0700263 final SuspendDialogInfo dialogInfo = pmi.getSuspendedDialogInfo(suspendedPackage,
264 suspendingPackage, mUserId);
Suprabh Shukla0cb57132020-01-18 20:15:08 -0800265 final Bundle crossProfileOptions = hasCrossProfileAnimation()
266 ? ActivityOptions.makeOpenCrossProfileAppsAnimation().toBundle()
267 : null;
268 final IntentSender target = createIntentSenderForOriginalIntent(mCallingUid,
269 FLAG_IMMUTABLE);
Suprabh Shukla1ab90a22018-05-10 15:54:08 -0700270 mIntent = SuspendedAppActivity.createSuspendedAppInterceptIntent(suspendedPackage,
Suprabh Shukla0cb57132020-01-18 20:15:08 -0800271 suspendingPackage, dialogInfo, crossProfileOptions, target, mUserId);
Suprabh Shukla3c3af142018-03-30 00:28:37 -0700272 mCallingPid = mRealCallingPid;
273 mCallingUid = mRealCallingUid;
274 mResolvedType = null;
Makoto Onuki1a342742018-04-26 14:56:59 -0700275 mRInfo = mSupervisor.resolveIntent(mIntent, mResolvedType, mUserId, 0, mRealCallingUid);
Suprabh Shukla3c3af142018-03-30 00:28:37 -0700276 mAInfo = mSupervisor.resolveActivity(mIntent, mRInfo, mStartFlags, null /*profilerInfo*/);
277 return true;
278 }
279
Yuhan Zhaof3b3d412020-01-24 23:37:13 +0000280 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 Xub93522a2016-02-23 18:21:48 +0000299 private boolean interceptWorkProfileChallengeIfNeeded() {
Tony Mak83546a82018-01-22 13:56:20 +0000300 final Intent interceptingIntent = interceptWithConfirmCredentialsIfNeeded(mAInfo, mUserId);
Rubin Xu58d25992016-01-21 17:47:13 +0000301 if (interceptingIntent == null) {
Rubin Xub93522a2016-02-23 18:21:48 +0000302 return false;
Rubin Xu58d25992016-01-21 17:47:13 +0000303 }
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 Ogunwale4e79a1c2019-10-05 20:52:40 -0700312 mIntent.putExtra(EXTRA_TASK_ID, mInTask.mTaskId);
Rubin Xu58d25992016-01-21 17:47:13 +0000313 mInTask = null;
314 }
Tony Mak853304c2016-04-18 15:17:41 +0100315 if (mActivityOptions == null) {
316 mActivityOptions = ActivityOptions.makeBasic();
317 }
Victor Chang89d4a9a2016-06-14 13:49:32 +0100318
Rubin Xu58d25992016-01-21 17:47:13 +0000319 final UserInfo parent = mUserManager.getProfileParent(mUserId);
Makoto Onuki1a342742018-04-26 14:56:59 -0700320 mRInfo = mSupervisor.resolveIntent(mIntent, mResolvedType, parent.id, 0, mRealCallingUid);
Rubin Xub93522a2016-02-23 18:21:48 +0000321 mAInfo = mSupervisor.resolveActivity(mIntent, mRInfo, mStartFlags, null /*profilerInfo*/);
322 return true;
Rubin Xu58d25992016-01-21 17:47:13 +0000323 }
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 Mak83546a82018-01-22 13:56:20 +0000330 private Intent interceptWithConfirmCredentialsIfNeeded(ActivityInfo aInfo, int userId) {
Wale Ogunwale86b74462018-07-02 08:42:43 -0700331 if (!mService.mAmInternal.shouldConfirmCredentials(userId)) {
Rubin Xu58d25992016-01-21 17:47:13 +0000332 return null;
333 }
Charles Hee7c5ced2017-04-12 16:22:35 +0100334 // TODO(b/28935539): should allow certain activities to bypass work challenge
Eran Messeri99882e62019-05-08 15:35:53 +0100335 final IntentSender target = createIntentSenderForOriginalIntent(mCallingUid,
Ben Gruver1ab3d6e2017-12-07 13:45:08 -0800336 FLAG_CANCEL_CURRENT | FLAG_ONE_SHOT | FLAG_IMMUTABLE);
Benjamin Franz563707b2017-06-29 15:06:13 +0100337 final KeyguardManager km = (KeyguardManager) mServiceContext
Rubin Xu58d25992016-01-21 17:47:13 +0000338 .getSystemService(KEYGUARD_SERVICE);
joshmccloskey15c0a442019-10-18 16:09:06 -0700339 final Intent newIntent = km.createConfirmDeviceCredentialIntent(null, null, userId,
340 true /* disallowBiometricsIfPolicyExists */);
Rubin Xu58d25992016-01-21 17:47:13 +0000341 if (newIntent == null) {
342 return null;
343 }
Tony Mak4291c762016-03-24 12:23:22 +0000344 newIntent.setFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS |
345 FLAG_ACTIVITY_TASK_ON_HOME);
Rubin Xu58d25992016-01-21 17:47:13 +0000346 newIntent.putExtra(EXTRA_PACKAGE_NAME, aInfo.packageName);
Ben Gruver1ab3d6e2017-12-07 13:45:08 -0800347 newIntent.putExtra(EXTRA_INTENT, target);
Rubin Xu58d25992016-01-21 17:47:13 +0000348 return newIntent;
349 }
350
Ben Gruver1ab3d6e2017-12-07 13:45:08 -0800351 private boolean interceptHarmfulAppIfNeeded() {
352 CharSequence harmfulAppWarning;
353 try {
Wale Ogunwale906f9c62018-07-23 11:23:44 -0700354 harmfulAppWarning = mService.getPackageManager()
Ben Gruver27ffd822018-03-07 13:24:18 -0800355 .getHarmfulAppWarning(mAInfo.packageName, mUserId);
356 } catch (RemoteException ex) {
Ben Gruver1ab3d6e2017-12-07 13:45:08 -0800357 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 Onuki1a342742018-04-26 14:56:59 -0700374 mRInfo = mSupervisor.resolveIntent(mIntent, mResolvedType, mUserId, 0, mRealCallingUid);
Ben Gruver1ab3d6e2017-12-07 13:45:08 -0800375 mAInfo = mSupervisor.resolveActivity(mIntent, mRInfo, mStartFlags, null /*profilerInfo*/);
376 return true;
377 }
Rubin Xu58d25992016-01-21 17:47:13 +0000378}