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

Commit d6c1d35e authored by Graciela Wissen Putri's avatar Graciela Wissen Putri Committed by Android Build Coastguard Worker
Browse files

Fix letterboxed app input info not added

Launcher remote animation requires permission ACCESS_SURFACE_FLINGER to
set input info. Use pendingTransaction instead of syncTransaction to let
system_server apply input info with permission.

Don't reset parentAppBoundsOverride when configuration is resolved as
double tap can happen after configuration is resolved e.g. unresizable
app in size compat mode which fills either width/height of display.

Flag: EXEMPT bugfix
Fix: 345729003
Test: atest LetterboxTest
      atest SizeCompatTests
      atest LetterboxUiControllerTest
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:4f08ec1ddd88608f09c2c995cfc6e11735d50797)
Merged-In: I66d0b1dbd6aad4639e8e25994577232e388f47bd
Change-Id: I66d0b1dbd6aad4639e8e25994577232e388f47bd
parent 3fb513b1
Loading
Loading
Loading
Loading
+5 −6
Original line number Diff line number Diff line
@@ -158,7 +158,6 @@ import static com.android.internal.util.FrameworkStatsLog.APP_COMPAT_STATE_CHANG
import static com.android.internal.util.FrameworkStatsLog.APP_COMPAT_STATE_CHANGED__STATE__LETTERBOXED_FOR_SIZE_COMPAT_MODE;
import static com.android.internal.util.FrameworkStatsLog.APP_COMPAT_STATE_CHANGED__STATE__NOT_LETTERBOXED;
import static com.android.internal.util.FrameworkStatsLog.APP_COMPAT_STATE_CHANGED__STATE__NOT_VISIBLE;
import static com.android.internal.util.function.pooled.PooledLambda.obtainMessage;
import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
import static com.android.server.wm.ActivityRecord.State.DESTROYED;
@@ -1908,7 +1907,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
    }
    void updateLetterboxSurfaceIfNeeded(WindowState winHint, Transaction t) {
        mLetterboxUiController.updateLetterboxSurfaceIfNeeded(winHint, t);
        mLetterboxUiController.updateLetterboxSurfaceIfNeeded(winHint, t, getPendingTransaction());
    }
    void updateLetterboxSurfaceIfNeeded(WindowState winHint) {
@@ -8675,7 +8674,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
    }
    @Nullable Rect getParentAppBoundsOverride() {
        return Rect.copyOrNull(mResolveConfigHint.mTmpParentAppBoundsOverride);
        return Rect.copyOrNull(mResolveConfigHint.mParentAppBoundsOverride);
    }
    /**
@@ -8860,7 +8859,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        }
        final Rect screenResolvedBounds =
                mSizeCompatBounds != null ? mSizeCompatBounds : resolvedBounds;
        final Rect parentAppBounds = mResolveConfigHint.mTmpParentAppBoundsOverride;
        final Rect parentAppBounds = mResolveConfigHint.mParentAppBoundsOverride;
        final Rect parentBounds = newParentConfiguration.windowConfiguration.getBounds();
        final float screenResolvedBoundsWidth = screenResolvedBounds.width();
        final float parentAppBoundsWidth = parentAppBounds.width();
@@ -9269,7 +9268,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
     */
    private void resolveAspectRatioRestriction(Configuration newParentConfiguration) {
        final Configuration resolvedConfig = getResolvedOverrideConfiguration();
        final Rect parentAppBounds = mResolveConfigHint.mTmpParentAppBoundsOverride;
        final Rect parentAppBounds = mResolveConfigHint.mParentAppBoundsOverride;
        final Rect parentBounds = newParentConfiguration.windowConfiguration.getBounds();
        final Rect resolvedBounds = resolvedConfig.windowConfiguration.getBounds();
        // Use tmp bounds to calculate aspect ratio so we can know whether the activity should use
@@ -9310,7 +9309,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
                : newParentConfiguration.windowConfiguration.getBounds();
        final Rect containerAppBounds = useResolvedBounds
                ? new Rect(resolvedConfig.windowConfiguration.getAppBounds())
                : mResolveConfigHint.mTmpParentAppBoundsOverride;
                : mResolveConfigHint.mParentAppBoundsOverride;
        final int requestedOrientation = getRequestedConfigurationOrientation();
        final boolean orientationRequested = requestedOrientation != ORIENTATION_UNDEFINED;
+9 −5
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import static android.os.InputConstants.DEFAULT_DISPATCHING_TIMEOUT_MILLIS;
import static android.view.SurfaceControl.HIDDEN;
import static android.window.TaskConstants.TASK_CHILD_LAYER_LETTERBOX_BACKGROUND;

import android.annotation.NonNull;
import android.graphics.Color;
import android.graphics.Point;
import android.graphics.Rect;
@@ -209,16 +210,18 @@ public class Letterbox {
        return false;
    }

    public void applySurfaceChanges(SurfaceControl.Transaction t) {
    /** Applies surface changes such as colour, window crop, position and input info. */
    public void applySurfaceChanges(@NonNull SurfaceControl.Transaction t,
            @NonNull SurfaceControl.Transaction inputT) {
        if (useFullWindowSurface()) {
            mFullWindowSurface.applySurfaceChanges(t);
            mFullWindowSurface.applySurfaceChanges(t, inputT);

            for (LetterboxSurface surface : mSurfaces) {
                surface.remove();
            }
        } else {
            for (LetterboxSurface surface : mSurfaces) {
                surface.applySurfaceChanges(t);
                surface.applySurfaceChanges(t, inputT);
            }

            mFullWindowSurface.remove();
@@ -418,7 +421,8 @@ public class Letterbox {
            return Math.max(0, mLayoutFrameGlobal.height());
        }

        public void applySurfaceChanges(SurfaceControl.Transaction t) {
        public void applySurfaceChanges(@NonNull SurfaceControl.Transaction t,
                @NonNull SurfaceControl.Transaction inputT) {
            if (!needsApplySurfaceChanges()) {
                // Nothing changed.
                return;
@@ -446,7 +450,7 @@ public class Letterbox {
            }
            if (mSurface != null && mInputInterceptor != null) {
                mInputInterceptor.updateTouchableRegion(mSurfaceFrameRelative);
                t.setInputWindowInfo(mSurface, mInputInterceptor.mWindowHandle);
                inputT.setInputWindowInfo(mSurface, mInputInterceptor.mWindowHandle);
            }
        }

+5 −3
Original line number Diff line number Diff line
@@ -785,16 +785,18 @@ final class LetterboxUiController {
    }

    void updateLetterboxSurfaceIfNeeded(WindowState winHint) {
        updateLetterboxSurfaceIfNeeded(winHint, mActivityRecord.getSyncTransaction());
        updateLetterboxSurfaceIfNeeded(winHint, mActivityRecord.getSyncTransaction(),
                mActivityRecord.getPendingTransaction());
    }

    void updateLetterboxSurfaceIfNeeded(WindowState winHint, Transaction t) {
    void updateLetterboxSurfaceIfNeeded(WindowState winHint, @NonNull Transaction t,
            @NonNull Transaction inputT) {
        if (shouldNotLayoutLetterbox(winHint)) {
            return;
        }
        layoutLetterboxIfNeeded(winHint);
        if (mLetterbox != null && mLetterbox.needsApplySurfaceChanges()) {
            mLetterbox.applySurfaceChanges(t);
            mLetterbox.applySurfaceChanges(t, inputT);
        }
    }

+4 −5
Original line number Diff line number Diff line
@@ -2241,13 +2241,13 @@ class TaskFragment extends WindowContainer<WindowContainer> {
    static class ConfigOverrideHint {
        @Nullable DisplayInfo mTmpOverrideDisplayInfo;
        @Nullable ActivityRecord.CompatDisplayInsets mTmpCompatInsets;
        @Nullable Rect mTmpParentAppBoundsOverride;
        @Nullable Rect mParentAppBoundsOverride;
        int mTmpOverrideConfigOrientation;
        boolean mUseOverrideInsetsForConfig;

        void resolveTmpOverrides(DisplayContent dc, Configuration parentConfig,
                boolean isFixedRotationTransforming) {
            mTmpParentAppBoundsOverride = new Rect(parentConfig.windowConfiguration.getAppBounds());
            mParentAppBoundsOverride = new Rect(parentConfig.windowConfiguration.getAppBounds());
            final Insets insets;
            if (mUseOverrideInsetsForConfig && dc != null) {
                // Insets are decoupled from configuration by default from V+, use legacy
@@ -2269,13 +2269,12 @@ class TaskFragment extends WindowContainer<WindowContainer> {
            } else {
                insets = Insets.NONE;
            }
            mTmpParentAppBoundsOverride.inset(insets);
            mParentAppBoundsOverride.inset(insets);
        }

        void resetTmpOverrides() {
            mTmpOverrideDisplayInfo = null;
            mTmpCompatInsets = null;
            mTmpParentAppBoundsOverride = null;
            mTmpOverrideConfigOrientation = ORIENTATION_UNDEFINED;
        }
    }
@@ -2364,7 +2363,7 @@ class TaskFragment extends WindowContainer<WindowContainer> {
                final Rect containingAppBounds;
                if (insideParentBounds) {
                    containingAppBounds = useOverrideInsetsForConfig
                            ? overrideHint.mTmpParentAppBoundsOverride
                            ? overrideHint.mParentAppBoundsOverride
                            : parentConfig.windowConfiguration.getAppBounds();
                } else {
                    // Restrict appBounds to display non-decor rather than parent because the
+18 −13
Original line number Diff line number Diff line
@@ -172,14 +172,14 @@ public class LetterboxTest {
    @Test
    public void testSurfaceOrigin_applied() {
        mLetterbox.layout(new Rect(0, 0, 10, 10), new Rect(0, 1, 10, 10), new Point(1000, 2000));
        mLetterbox.applySurfaceChanges(mTransaction);
        applySurfaceChanges();
        verify(mTransaction).setPosition(mSurfaces.top, -1000, -2000);
    }

    @Test
    public void testApplySurfaceChanges_setColor() {
        mLetterbox.layout(new Rect(0, 0, 10, 10), new Rect(0, 1, 10, 10), new Point(1000, 2000));
        mLetterbox.applySurfaceChanges(mTransaction);
        applySurfaceChanges();

        verify(mTransaction).setColor(mSurfaces.top, new float[]{0, 0, 0});

@@ -187,7 +187,7 @@ public class LetterboxTest {

        assertTrue(mLetterbox.needsApplySurfaceChanges());

        mLetterbox.applySurfaceChanges(mTransaction);
        applySurfaceChanges();

        verify(mTransaction).setColor(mSurfaces.top, new float[]{0, 1, 0});
    }
@@ -195,7 +195,7 @@ public class LetterboxTest {
    @Test
    public void testNeedsApplySurfaceChanges_wallpaperBackgroundRequested() {
        mLetterbox.layout(new Rect(0, 0, 10, 10), new Rect(0, 1, 10, 10), new Point(1000, 2000));
        mLetterbox.applySurfaceChanges(mTransaction);
        applySurfaceChanges();

        verify(mTransaction).setAlpha(mSurfaces.top, 1.0f);
        assertFalse(mLetterbox.needsApplySurfaceChanges());
@@ -204,14 +204,14 @@ public class LetterboxTest {

        assertTrue(mLetterbox.needsApplySurfaceChanges());

        mLetterbox.applySurfaceChanges(mTransaction);
        applySurfaceChanges();
        verify(mTransaction).setAlpha(mSurfaces.fullWindowSurface, mDarkScrimAlpha);
    }

    @Test
    public void testNeedsApplySurfaceChanges_setParentSurface() {
        mLetterbox.layout(new Rect(0, 0, 10, 10), new Rect(0, 1, 10, 10), new Point(1000, 2000));
        mLetterbox.applySurfaceChanges(mTransaction);
        applySurfaceChanges();

        verify(mTransaction).reparent(mSurfaces.top, mParentSurface);
        assertFalse(mLetterbox.needsApplySurfaceChanges());
@@ -220,14 +220,14 @@ public class LetterboxTest {

        assertTrue(mLetterbox.needsApplySurfaceChanges());

        mLetterbox.applySurfaceChanges(mTransaction);
        applySurfaceChanges();
        verify(mTransaction).reparent(mSurfaces.top, mParentSurface);
    }

    @Test
    public void testApplySurfaceChanges_cornersNotRounded_surfaceFullWindowSurfaceNotCreated() {
        mLetterbox.layout(new Rect(0, 0, 10, 10), new Rect(0, 1, 10, 10), new Point(1000, 2000));
        mLetterbox.applySurfaceChanges(mTransaction);
        applySurfaceChanges();

        assertNull(mSurfaces.fullWindowSurface);
    }
@@ -236,7 +236,7 @@ public class LetterboxTest {
    public void testApplySurfaceChanges_cornersRounded_surfaceFullWindowSurfaceCreated() {
        mAreCornersRounded = true;
        mLetterbox.layout(new Rect(0, 0, 10, 10), new Rect(0, 1, 10, 10), new Point(1000, 2000));
        mLetterbox.applySurfaceChanges(mTransaction);
        applySurfaceChanges();

        assertNotNull(mSurfaces.fullWindowSurface);
    }
@@ -245,7 +245,7 @@ public class LetterboxTest {
    public void testApplySurfaceChanges_wallpaperBackground_surfaceFullWindowSurfaceCreated() {
        mHasWallpaperBackground = true;
        mLetterbox.layout(new Rect(0, 0, 10, 10), new Rect(0, 1, 10, 10), new Point(1000, 2000));
        mLetterbox.applySurfaceChanges(mTransaction);
        applySurfaceChanges();

        assertNotNull(mSurfaces.fullWindowSurface);
    }
@@ -254,7 +254,7 @@ public class LetterboxTest {
    public void testNotIntersectsOrFullyContains_cornersRounded() {
        mAreCornersRounded = true;
        mLetterbox.layout(new Rect(0, 0, 10, 10), new Rect(0, 1, 10, 10), new Point(0, 0));
        mLetterbox.applySurfaceChanges(mTransaction);
        applySurfaceChanges();

        assertTrue(mLetterbox.notIntersectsOrFullyContains(new Rect(1, 2, 9, 9)));
    }
@@ -262,14 +262,19 @@ public class LetterboxTest {
    @Test
    public void testSurfaceOrigin_changeCausesReapply() {
        mLetterbox.layout(new Rect(0, 0, 10, 10), new Rect(0, 1, 10, 10), new Point(1000, 2000));
        mLetterbox.applySurfaceChanges(mTransaction);
        applySurfaceChanges();
        clearInvocations(mTransaction);
        mLetterbox.layout(new Rect(0, 0, 10, 10), new Rect(0, 1, 10, 10), new Point(0, 0));
        assertTrue(mLetterbox.needsApplySurfaceChanges());
        mLetterbox.applySurfaceChanges(mTransaction);
        applySurfaceChanges();
        verify(mTransaction).setPosition(mSurfaces.top, 0, 0);
    }

    private void applySurfaceChanges() {
        mLetterbox.applySurfaceChanges(/* syncTransaction */ mTransaction,
                /* pendingTransaction */ mTransaction);
    }

    class SurfaceControlMocker implements Supplier<SurfaceControl.Builder> {
        private SurfaceControl.Builder mLeftBuilder;
        public SurfaceControl left;