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

Commit f465ea0d authored by Bryce Lee's avatar Bryce Lee
Browse files

Disallow starting activities without new task from non-activity context.

A change to the conditions to allow such behavior when a task id was
specified now allows for all non-activity contexts to start activities
as long as no options bundle is specified.

This changelist corrects the condition.

Change-Id: Ifaff4fc6d875ba74ec532b3e3ce91c6aa3ca3362
Fixes: 32625589
Test: atest CtsActivityManagerDeviceTestCases:StartActivityTests
parent f24977b5
Loading
Loading
Loading
Loading
+11 −5
Original line number Diff line number Diff line
@@ -872,9 +872,15 @@ class ContextImpl extends Context {

        // Calling start activity from outside an activity without FLAG_ACTIVITY_NEW_TASK is
        // generally not allowed, except if the caller specifies the task id the activity should
        // be launched in.
        // be launched in. A bug was existed between N and O-MR1 which allowed this to work. We
        // maintain this for backwards compatibility.
        final int targetSdkVersion = getApplicationInfo().targetSdkVersion;

        if ((intent.getFlags() & Intent.FLAG_ACTIVITY_NEW_TASK) == 0
                && options != null && ActivityOptions.fromBundle(options).getLaunchTaskId() == -1) {
                && (targetSdkVersion < Build.VERSION_CODES.N
                        || targetSdkVersion >= Build.VERSION_CODES.P)
                && (options == null
                        || ActivityOptions.fromBundle(options).getLaunchTaskId() == -1)) {
            throw new AndroidRuntimeException(
                    "Calling startActivity() from outside of an Activity "
                            + " context requires the FLAG_ACTIVITY_NEW_TASK flag."