Block activity launching if DWPC does not allow

Prvent an activity from launching and return START_CANCELED if target
display's DWPC does not allow it.

Bug: 205811272
Test: atest ActivityBlockingTest ActivityStarterTests
Change-Id: I8b6bbc5713da035bd7320c507ba4f3f49bda8423
This commit is contained in:
Chilun
2022-03-10 23:11:41 +08:00
parent 498493cdd3
commit 52a0e799f2

View File

@@ -135,6 +135,7 @@ import com.android.server.wm.LaunchParamsController.LaunchParams;
import java.io.PrintWriter;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Date;
/**
@@ -2009,6 +2010,27 @@ class ActivityStarter {
return START_PERMISSION_DENIED;
}
// Do not start the activity if target display's DWPC does not allow it.
// We can't return fatal error code here because it will crash the caller of
// startActivity() if they don't catch the exception. We don't expect 3P apps to make
// changes.
if (mPreferredTaskDisplayArea != null) {
final DisplayContent displayContent = mRootWindowContainer.getDisplayContentOrCreate(
mPreferredTaskDisplayArea.getDisplayId());
if (displayContent != null && displayContent.mDwpcHelper.hasController()) {
final ArrayList<ActivityInfo> activities = new ArrayList<>();
activities.add(r.info);
final int targetWindowingMode = (targetTask != null)
? targetTask.getWindowingMode() : displayContent.getWindowingMode();
if (!displayContent.mDwpcHelper
.canContainActivities(activities, targetWindowingMode)) {
Slog.w(TAG, "Abort to launch " + r.info.getComponentName()
+ " on display area " + mPreferredTaskDisplayArea);
return START_ABORTED;
}
}
}
return START_SUCCESS;
}