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

Commit ff7ca842 authored by Louis Chang's avatar Louis Chang
Browse files

Sets the launch display id for Context associated with a display

Sets the launch display id while starting activity from a Context
that has associated with a display, unless the launch target is
already set by the caller.

Bug: 359387748
Test: atest MultiDisplayImeTests
Test: atest CtsWindowManagerDeviceMultiDisplay
Flag: EXEMPT bugfix
Change-Id: I29a4530b324b7c1f1182a51e58404e27862f1974
parent 2962f79d
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -1587,6 +1587,16 @@ public class ActivityOptions extends ComponentOptions {
        }
    }

    /** @hide */
    public static boolean hasLaunchTargetContainer(ActivityOptions options) {
        return options.getLaunchDisplayId() != INVALID_DISPLAY
                || options.getLaunchTaskDisplayArea() != null
                || options.getLaunchTaskDisplayAreaFeatureId() != FEATURE_UNDEFINED
                || options.getLaunchRootTask() != null
                || options.getLaunchTaskId() != -1
                || options.getLaunchTaskFragmentToken() != null;
    }

    /**
     * Gets whether the activity is to be launched into LockTask mode.
     * @return {@code true} if the activity is to be launched into LockTask mode.
+25 −5
Original line number Diff line number Diff line
@@ -1160,7 +1160,7 @@ class ContextImpl extends Context {
        }
        mMainThread.getInstrumentation().execStartActivity(
                getOuterContext(), mMainThread.getApplicationThread(), null,
                (Activity) null, intent, -1, options);
                (Activity) null, intent, -1, applyLaunchDisplayIfNeeded(options));
    }

    /** @hide */
@@ -1170,8 +1170,8 @@ class ContextImpl extends Context {
            ActivityTaskManager.getService().startActivityAsUser(
                    mMainThread.getApplicationThread(), getOpPackageName(), getAttributionTag(),
                    intent, intent.resolveTypeIfNeeded(getContentResolver()),
                    null, null, 0, Intent.FLAG_ACTIVITY_NEW_TASK, null, options,
                    user.getIdentifier());
                    null, null, 0, Intent.FLAG_ACTIVITY_NEW_TASK, null,
                    applyLaunchDisplayIfNeeded(options), user.getIdentifier());
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -1194,7 +1194,8 @@ class ContextImpl extends Context {
        }
        return mMainThread.getInstrumentation().execStartActivitiesAsUser(
                getOuterContext(), mMainThread.getApplicationThread(), null,
                (Activity) null, intents, options, userHandle.getIdentifier());
                (Activity) null, intents, applyLaunchDisplayIfNeeded(options),
                userHandle.getIdentifier());
    }

    @Override
@@ -1208,7 +1209,26 @@ class ContextImpl extends Context {
        }
        mMainThread.getInstrumentation().execStartActivities(
                getOuterContext(), mMainThread.getApplicationThread(), null,
                (Activity) null, intents, options);
                (Activity) null, intents, applyLaunchDisplayIfNeeded(options));
    }

    private Bundle applyLaunchDisplayIfNeeded(@Nullable Bundle options) {
        if (!isAssociatedWithDisplay()) {
            // return if this Context has no associated display.
            return options;
        }

        final ActivityOptions activityOptions;
        if (options != null) {
            activityOptions = ActivityOptions.fromBundle(options);
            if (ActivityOptions.hasLaunchTargetContainer(activityOptions)) {
                // return if the options already has launching target.
                return options;
            }
        } else {
            activityOptions = ActivityOptions.makeBasic();
        }
        return activityOptions.setLaunchDisplayId(getAssociatedDisplayId()).toBundle();
    }

    @Override