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

Commit 3acb8907 authored by Shane's avatar Shane
Browse files

Add FrameRateBoostOnTouch API to WindowManager.LayoutParams

Add FrameRateBoostOnTouch API to WindowManager.LayoutParams to allow
developers to enable / disable touch boost

Bug: 315897965
Test: atest ViewRootImplTest / atest WindowTest
Change-Id: I6a1de6ca4ab6f2dbdd9bbbacce47f9a1c2253c66
parent df4a15fb
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -53507,6 +53507,7 @@ package android.view {
    method public android.transition.Transition getExitTransition();
    method protected final int getFeatures();
    method protected final int getForcedWindowFlags();
    method @FlaggedApi("android.view.flags.toolkit_set_frame_rate_read_only") public boolean getFrameRateBoostOnTouchEnabled();
    method @Nullable public android.view.WindowInsetsController getInsetsController();
    method @NonNull public abstract android.view.LayoutInflater getLayoutInflater();
    method protected final int getLocalFeatures();
@@ -53584,6 +53585,7 @@ package android.view {
    method public abstract void setFeatureInt(int, int);
    method public void setFlags(int, int);
    method public void setFormat(int);
    method @FlaggedApi("android.view.flags.toolkit_set_frame_rate_read_only") public void setFrameRateBoostOnTouchEnabled(boolean);
    method public void setGravity(int);
    method @RequiresPermission(android.Manifest.permission.HIDE_OVERLAY_WINDOWS) public final void setHideOverlayWindows(boolean);
    method public void setIcon(@DrawableRes int);
@@ -53927,6 +53929,7 @@ package android.view {
    method @FlaggedApi("com.android.graphics.hwui.flags.limited_hdr") public float getDesiredHdrHeadroom();
    method public int getFitInsetsSides();
    method public int getFitInsetsTypes();
    method @FlaggedApi("android.view.flags.toolkit_set_frame_rate_read_only") public boolean getFrameRateBoostOnTouchEnabled();
    method public final CharSequence getTitle();
    method public boolean isFitInsetsIgnoringVisibility();
    method public boolean isHdrConversionEnabled();
@@ -53938,6 +53941,7 @@ package android.view {
    method public void setFitInsetsIgnoringVisibility(boolean);
    method public void setFitInsetsSides(int);
    method public void setFitInsetsTypes(int);
    method @FlaggedApi("android.view.flags.toolkit_set_frame_rate_read_only") public void setFrameRateBoostOnTouchEnabled(boolean);
    method public void setHdrConversionEnabled(boolean);
    method public final void setTitle(CharSequence);
    method public void setWallpaperTouchEventsEnabled(boolean);
+11 −2
Original line number Diff line number Diff line
@@ -252,7 +252,6 @@ import java.util.Queue;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
import java.util.function.Predicate;

/**
 * The top of a view hierarchy, implementing the needed protocol between View
 * and the WindowManager.  This is for the most part an internal implementation
@@ -12163,7 +12162,8 @@ public final class ViewRootImpl implements ViewParent,
                || motionEventAction == MotionEvent.ACTION_UP;
        boolean undesiredType = windowType == TYPE_INPUT_METHOD;
        // use toolkitSetFrameRate flag to gate the change
        return desiredAction && !undesiredType && sToolkitSetFrameRateReadOnlyFlagValue;
        return desiredAction && !undesiredType && sToolkitSetFrameRateReadOnlyFlagValue
                && getFrameRateBoostOnTouchEnabled();
    }

    /**
@@ -12238,6 +12238,15 @@ public final class ViewRootImpl implements ViewParent,
        return mIsFrameRateBoosting;
    }

    /**
     * Get the value of mFrameRateBoostOnTouchEnabled
     * Can be used to checked if touch boost is enabled. The default value is true.
     */
    @VisibleForTesting
    public boolean getFrameRateBoostOnTouchEnabled() {
        return mWindowAttributes.getFrameRateBoostOnTouchEnabled();
    }

    private void boostFrameRate(int boostTimeOut) {
        mIsFrameRateBoosting = true;
        setPreferredFrameRateCategory(mPreferredFrameRateCategory);
+36 −0
Original line number Diff line number Diff line
@@ -334,6 +334,9 @@ public abstract class Window {
    private boolean mOverlayWithDecorCaptionEnabled = true;
    private boolean mCloseOnSwipeEnabled = false;

    private static boolean sToolkitSetFrameRateReadOnlyFlagValue =
                android.view.flags.Flags.toolkitSetFrameRateReadOnly();

    // The current window attributes.
    @UnsupportedAppUsage
    private final WindowManager.LayoutParams mWindowAttributes =
@@ -1372,6 +1375,39 @@ public abstract class Window {
        return getAttributes().getDesiredHdrHeadroom();
    }

    /**
     * Sets whether the frame rate touch boost is enabled for this Window.
     * When enabled, the frame rate will be boosted when a user touches the Window.
     *
     * @param enabled whether the frame rate touch boost is enabled.
     * @see #getFrameRateBoostOnTouchEnabled()
     * @see WindowManager.LayoutParams#setFrameRateBoostOnTouchEnabled(boolean)
     */
    @FlaggedApi(android.view.flags.Flags.FLAG_TOOLKIT_SET_FRAME_RATE_READ_ONLY)
    public void setFrameRateBoostOnTouchEnabled(boolean enabled) {
        if (sToolkitSetFrameRateReadOnlyFlagValue) {
            final WindowManager.LayoutParams attrs = getAttributes();
            attrs.setFrameRateBoostOnTouchEnabled(enabled);
            dispatchWindowAttributesChanged(attrs);
        }
    }

    /**
     * Get whether frame rate touch boost is enabled
     * {@link #setFrameRateBoostOnTouchEnabled(boolean)}
     *
     * @return whether the frame rate touch boost is enabled.
     * @see #setFrameRateBoostOnTouchEnabled(boolean)
     * @see WindowManager.LayoutParams#getFrameRateBoostOnTouchEnabled()
     */
    @FlaggedApi(android.view.flags.Flags.FLAG_TOOLKIT_SET_FRAME_RATE_READ_ONLY)
    public boolean getFrameRateBoostOnTouchEnabled() {
        if (sToolkitSetFrameRateReadOnlyFlagValue) {
            return getAttributes().getFrameRateBoostOnTouchEnabled();
        }
        return true;
    }

    /**
     * If {@code isPreferred} is true, this method requests that the connected display does minimal
     * post processing when this window is visible on the screen. Otherwise, it requests that the
+50 −1
Original line number Diff line number Diff line
@@ -122,7 +122,6 @@ import android.view.WindowInsets.Side.InsetsSide;
import android.view.WindowInsets.Type;
import android.view.WindowInsets.Type.InsetsType;
import android.view.accessibility.AccessibilityNodeInfo;
import android.window.ITrustedPresentationListener;
import android.window.TaskFpsCallback;
import android.window.TrustedPresentationThresholds;

@@ -4337,6 +4336,13 @@ public interface WindowManager extends ViewManager {
        /** @hide */
        private float mDesiredHdrHeadroom = 0;

        /**
         * For variable refresh rate project.
         */
        private boolean mFrameRateBoostOnTouch = true;
        private static boolean sToolkitSetFrameRateReadOnlyFlagValue =
                android.view.flags.Flags.toolkitSetFrameRateReadOnly();

        /**
         * Carries the requests about {@link WindowInsetsController.Appearance} and
         * {@link WindowInsetsController.Behavior} to the system windows which can produce insets.
@@ -4771,6 +4777,32 @@ public interface WindowManager extends ViewManager {
            return mDesiredHdrHeadroom;
        }

        /**
         * Set the value whether we should enable Touch Boost
         *
         * @param enabled Whether we should enable Touch Boost
         */
        @FlaggedApi(android.view.flags.Flags.FLAG_TOOLKIT_SET_FRAME_RATE_READ_ONLY)
        public void setFrameRateBoostOnTouchEnabled(boolean enabled) {
            if (sToolkitSetFrameRateReadOnlyFlagValue) {
                mFrameRateBoostOnTouch = enabled;
            }
        }

        /**
         * Get the value whether we should enable touch boost as set
         * by {@link #setFrameRateBoostOnTouchEnabled(boolean)}
         *
         * @return A boolean value to indicate whether we should enable touch boost
         */
        @FlaggedApi(android.view.flags.Flags.FLAG_TOOLKIT_SET_FRAME_RATE_READ_ONLY)
        public boolean getFrameRateBoostOnTouchEnabled() {
            if (sToolkitSetFrameRateReadOnlyFlagValue) {
                return mFrameRateBoostOnTouch;
            }
            return true;
        }

        /**
         * <p>
         * Blurs the screen behind the window. The effect is similar to that of {@link #dimAmount},
@@ -4922,6 +4954,9 @@ public interface WindowManager extends ViewManager {
            out.writeTypedArray(paramsForRotation, 0 /* parcelableFlags */);
            out.writeInt(mDisplayFlags);
            out.writeFloat(mDesiredHdrHeadroom);
            if (sToolkitSetFrameRateReadOnlyFlagValue) {
                out.writeBoolean(mFrameRateBoostOnTouch);
            }
        }

        public static final @android.annotation.NonNull Parcelable.Creator<LayoutParams> CREATOR
@@ -4994,6 +5029,9 @@ public interface WindowManager extends ViewManager {
            paramsForRotation = in.createTypedArray(LayoutParams.CREATOR);
            mDisplayFlags = in.readInt();
            mDesiredHdrHeadroom = in.readFloat();
            if (sToolkitSetFrameRateReadOnlyFlagValue) {
                mFrameRateBoostOnTouch = in.readBoolean();
            }
        }

        @SuppressWarnings({"PointlessBitwiseExpression"})
@@ -5330,6 +5368,12 @@ public interface WindowManager extends ViewManager {
                changes |= LAYOUT_CHANGED;
            }

            if (sToolkitSetFrameRateReadOnlyFlagValue
                    && mFrameRateBoostOnTouch != o.mFrameRateBoostOnTouch) {
                mFrameRateBoostOnTouch = o.mFrameRateBoostOnTouch;
                changes |= LAYOUT_CHANGED;
            }

            return changes;
        }

@@ -5552,6 +5596,11 @@ public interface WindowManager extends ViewManager {
                sb.append(prefix).append("  forciblyShownTypes=").append(
                        WindowInsets.Type.toString(forciblyShownTypes));
            }
            if (sToolkitSetFrameRateReadOnlyFlagValue && mFrameRateBoostOnTouch) {
                sb.append(System.lineSeparator());
                sb.append(prefix).append("  frameRateBoostOnTouch=");
                sb.append(mFrameRateBoostOnTouch);
            }
            if (paramsForRotation != null && paramsForRotation.length != 0) {
                sb.append(System.lineSeparator());
                sb.append(prefix).append("  paramsForRotation:");
+31 −2
Original line number Diff line number Diff line
@@ -659,8 +659,6 @@ public class ViewRootImplTest {
        ViewRootImpl viewRootImpl = view.getViewRootImpl();
        sInstrumentation.runOnMainSync(() -> {
            view.invalidate();
            assertEquals(viewRootImpl.getLastPreferredFrameRateCategory(),
                    FRAME_RATE_CATEGORY_NORMAL);
            viewRootImpl.notifyInsetsAnimationRunningStateChanged(true);
            view.invalidate();
        });
@@ -672,6 +670,37 @@ public class ViewRootImplTest {
        });
    }


    /**
     * Test FrameRateBoostOnTouchEnabled API
     */
    @Test
    @RequiresFlagsEnabled(FLAG_TOOLKIT_SET_FRAME_RATE_READ_ONLY)
    public void votePreferredFrameRate_frameRateBoostOnTouch() {
        View view = new View(sContext);
        attachViewToWindow(view);
        sInstrumentation.waitForIdleSync();

        ViewRootImpl viewRootImpl = view.getViewRootImpl();
        final WindowManager.LayoutParams attrs = viewRootImpl.mWindowAttributes;
        assertEquals(attrs.getFrameRateBoostOnTouchEnabled(), true);
        assertEquals(viewRootImpl.getFrameRateBoostOnTouchEnabled(),
                attrs.getFrameRateBoostOnTouchEnabled());

        sInstrumentation.runOnMainSync(() -> {
            attrs.setFrameRateBoostOnTouchEnabled(false);
            viewRootImpl.setLayoutParams(attrs, false);
        });
        sInstrumentation.waitForIdleSync();

        sInstrumentation.runOnMainSync(() -> {
            final WindowManager.LayoutParams newAttrs = viewRootImpl.mWindowAttributes;
            assertEquals(newAttrs.getFrameRateBoostOnTouchEnabled(), false);
            assertEquals(viewRootImpl.getFrameRateBoostOnTouchEnabled(),
                    newAttrs.getFrameRateBoostOnTouchEnabled());
        });
    }

    @Test
    public void forceInvertOffDarkThemeOff_forceDarkModeDisabled() {
        mSetFlagsRule.enableFlags(FLAG_FORCE_INVERT_COLOR);