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

Commit 609e1e9f authored by Winson Chung's avatar Winson Chung
Browse files

Fixing issue with wrong initial multi-window mode.

- When an activity is started into a new task in the adjacent stack, we
  need to initialize the multi-window mode in order to ensure that the
  app gets the required callbacks when it leaves multi-window mode. This
  flow doesn't go through the normal mechanism to schedule changes to the
  app, so we just initialize it manually.

Bug: 38028679
Test: android.server.cts.ActivityManagerDockedStackTests
Test: #testLaunchToSideMultiWindowCallbacks
Change-Id: I783d03bbb3f7e197dca2f8411e23edb7680a9a86
parent 07672353
Loading
Loading
Loading
Loading
+18 −12
Original line number Diff line number Diff line
@@ -128,7 +128,6 @@ import android.content.pm.ApplicationInfo;
import android.content.res.CompatibilityInfo;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.Point;
import android.graphics.Rect;
import android.os.Bundle;
import android.os.Debug;
@@ -248,6 +247,8 @@ final class ActivityRecord extends ConfigurationContainer implements AppWindowCo
    // Last configuration reported to the activity in the client process.
    private MergedConfiguration mLastReportedConfiguration;
    private int mLastReportedDisplayId;
    private boolean mLastReportedMultiWindowMode;
    private boolean mLastReportedPictureInPictureMode;
    CompatibilityInfo compat;// last used compatibility mode
    ActivityRecord resultTo; // who started this entry, so will get our reply
    final String resultWho; // additional identifier for use by resultTo.
@@ -288,10 +289,6 @@ final class ActivityRecord extends ConfigurationContainer implements AppWindowCo
    boolean frozenBeforeDestroy;// has been frozen but not yet destroyed.
    boolean immersive;      // immersive mode (don't interrupt if possible)
    boolean forceNewConfig; // force re-create with new config next time
    private boolean mInMultiWindowMode; // whether or not this activity is currently in multi-window
                                        // mode (default false)
    private boolean mInPictureInPictureMode; // whether or not this activity is currently in
                                             // picture-in-picture mode (default false)
    boolean supportsPictureInPictureWhilePausing;  // This flag is set by the system to indicate
        // that the activity can enter picture in picture while pausing (ie. only when another
        // task is brought to front or started)
@@ -534,6 +531,8 @@ final class ActivityRecord extends ConfigurationContainer implements AppWindowCo
        }
        if (info != null) {
            pw.println(prefix + "resizeMode=" + ActivityInfo.resizeModeToString(info.resizeMode));
            pw.println(prefix + "mLastReportedMultiWindowMode=" + mLastReportedMultiWindowMode
                    + " mLastReportedPictureInPictureMode=" + mLastReportedPictureInPictureMode);
            if (info.supportsPictureInPicture()) {
                pw.println(prefix + "supportsPictureInPicture=" + info.supportsPictureInPicture());
                pw.println(prefix + "supportsPictureInPictureWhilePausing: "
@@ -636,15 +635,15 @@ final class ActivityRecord extends ConfigurationContainer implements AppWindowCo

        // An activity is considered to be in multi-window mode if its task isn't fullscreen.
        final boolean inMultiWindowMode = !task.mFullscreen;
        if (inMultiWindowMode != mInMultiWindowMode) {
            mInMultiWindowMode = inMultiWindowMode;
        if (inMultiWindowMode != mLastReportedMultiWindowMode) {
            mLastReportedMultiWindowMode = inMultiWindowMode;
            scheduleMultiWindowModeChanged(getConfiguration());
        }
    }

    private void scheduleMultiWindowModeChanged(Configuration overrideConfig) {
        try {
            app.thread.scheduleMultiWindowModeChanged(appToken, mInMultiWindowMode,
            app.thread.scheduleMultiWindowModeChanged(appToken, mLastReportedMultiWindowMode,
                    overrideConfig);
        } catch (Exception e) {
            // If process died, I don't care.
@@ -658,11 +657,11 @@ final class ActivityRecord extends ConfigurationContainer implements AppWindowCo

        final boolean inPictureInPictureMode = (task.getStackId() == PINNED_STACK_ID) &&
                (targetStackBounds != null);
        if (inPictureInPictureMode != mInPictureInPictureMode) {
        if (inPictureInPictureMode != mLastReportedPictureInPictureMode) {
            // Picture-in-picture mode changes also trigger a multi-window mode change as well, so
            // update that here in order
            mInPictureInPictureMode = inPictureInPictureMode;
            mInMultiWindowMode = inPictureInPictureMode;
            mLastReportedPictureInPictureMode = inPictureInPictureMode;
            mLastReportedMultiWindowMode = inPictureInPictureMode;
            final Configuration newConfig = task.computeNewOverrideConfigurationForBounds(
                    targetStackBounds, null);
            schedulePictureInPictureModeChanged(newConfig);
@@ -672,7 +671,8 @@ final class ActivityRecord extends ConfigurationContainer implements AppWindowCo

    private void schedulePictureInPictureModeChanged(Configuration overrideConfig) {
        try {
            app.thread.schedulePictureInPictureModeChanged(appToken, mInPictureInPictureMode,
            app.thread.schedulePictureInPictureModeChanged(appToken,
                    mLastReportedPictureInPictureMode,
                    overrideConfig);
        } catch (Exception e) {
            // If process died, no one cares.
@@ -939,6 +939,12 @@ final class ActivityRecord extends ConfigurationContainer implements AppWindowCo

        task.addActivityToTop(this);

        // When an activity is started directly into a split-screen fullscreen stack, we need to
        // update the initial multi-window modes so that the callbacks are scheduled correctly when
        // the user leaves that mode.
        mLastReportedMultiWindowMode = !task.mFullscreen;
        mLastReportedPictureInPictureMode = (task.getStackId() == PINNED_STACK_ID);

        onOverrideConfigurationSent();
    }