Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 52a0e799 authored by Chilun's avatar Chilun
Browse files

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
parent 498493cd
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -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;
    }