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

Commit d9f4117b authored by Jian-Syuan (Shane) Wong's avatar Jian-Syuan (Shane) Wong Committed by Android (Google) Code Review
Browse files

Merge "Connect FrameRatePowerSavingsBalanced from WindowManager.LayoutParam to...

Merge "Connect FrameRatePowerSavingsBalanced from WindowManager.LayoutParam to ViewRootImpl" into main
parents 9cca7dc1 93d80828
Loading
Loading
Loading
Loading
+5 −17
Original line number Diff line number Diff line
@@ -1066,11 +1066,6 @@ public final class ViewRootImpl implements ViewParent,
    // Used to check if there is a message in the message queue
    // for idleness handling.
    private boolean mHasIdledMessage = false;
    // Used to allow developers to opt out Toolkit dVRR feature.
    // This feature allows device to adjust refresh rate
    // as needed and can be useful for power saving.
    // Should not enable the dVRR feature if the value is false.
    private boolean mIsFrameRatePowerSavingsBalanced = true;
    // Used to check if there is a conflict between different frame rate voting.
    // Take 24 and 30 as an example, 24 is not a divisor of 30.
    // We consider there is a conflict.
@@ -12777,7 +12772,10 @@ public final class ViewRootImpl implements ViewParent,
     */
    @VisibleForTesting
    public boolean isFrameRatePowerSavingsBalanced() {
        return mIsFrameRatePowerSavingsBalanced;
        if (sToolkitSetFrameRateReadOnlyFlagValue) {
            return mWindowAttributes.isFrameRatePowerSavingsBalanced();
        }
        return true;
    }
    /**
@@ -12789,19 +12787,9 @@ public final class ViewRootImpl implements ViewParent,
        return mIsFrameRateConflicted;
    }
    /**
     * Set the value of mIsFrameRatePowerSavingsBalanced
     * Can be used to checked if toolkit dVRR feature is enabled.
     */
    public void setFrameRatePowerSavingsBalanced(boolean enabled) {
        if (sToolkitSetFrameRateReadOnlyFlagValue) {
            mIsFrameRatePowerSavingsBalanced = enabled;
        }
    }
    private boolean shouldEnableDvrr() {
        // uncomment this when we are ready for enabling dVRR
        // return sToolkitSetFrameRateReadOnlyFlagValue && mIsFrameRatePowerSavingsBalanced;
        // return sToolkitSetFrameRateReadOnlyFlagValue && isFrameRatePowerSavingsBalanced();
        return false;
    }
+6 −1
Original line number Diff line number Diff line
@@ -334,7 +334,12 @@ public abstract class Window {
    private boolean mOverlayWithDecorCaptionEnabled = true;
    private boolean mCloseOnSwipeEnabled = false;

    private static boolean sToolkitSetFrameRateReadOnlyFlagValue =
    /**
     * To check if toolkitSetFrameRateReadOnly flag is enabled
     *
     * @hide
     */
    protected static boolean sToolkitSetFrameRateReadOnlyFlagValue =
                android.view.flags.Flags.toolkitSetFrameRateReadOnly();

    // The current window attributes.
+5 −5
Original line number Diff line number Diff line
@@ -365,8 +365,6 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {

    private boolean mUseDecorContext = false;

    private boolean mIsFrameRatePowerSavingsBalanced = true;

    /** @see ViewRootImpl#mActivityConfigCallback */
    private ActivityConfigCallback mActivityConfigCallback;

@@ -2216,7 +2214,6 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
    void onViewRootImplSet(ViewRootImpl viewRoot) {
        viewRoot.setActivityConfigCallback(mActivityConfigCallback);
        viewRoot.getOnBackInvokedDispatcher().updateContext(getContext());
        viewRoot.setFrameRatePowerSavingsBalanced(mIsFrameRatePowerSavingsBalanced);
        mProxyOnBackInvokedDispatcher.setActualDispatcher(viewRoot.getOnBackInvokedDispatcher());
        applyDecorFitsSystemWindows();
    }
@@ -2566,8 +2563,11 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
            requestFeature(FEATURE_ACTIVITY_TRANSITIONS);
        }
        if (a.hasValue(R.styleable.Window_windowIsFrameRatePowerSavingsBalanced)) {
            mIsFrameRatePowerSavingsBalanced =
                    a.getBoolean(R.styleable.Window_windowIsFrameRatePowerSavingsBalanced, true);
            if (sToolkitSetFrameRateReadOnlyFlagValue) {
                setFrameRatePowerSavingsBalanced(
                        a.getBoolean(R.styleable.Window_windowIsFrameRatePowerSavingsBalanced,
                                true));
            }
        }

        mIsTranslucent = a.getBoolean(R.styleable.Window_windowIsTranslucent, false);
+22 −8
Original line number Diff line number Diff line
@@ -1067,18 +1067,32 @@ public class ViewRootImplTest {
    /**
     * Test the IsFrameRatePowerSavingsBalanced values are properly set
     */
    @UiThreadTest
    @Test
    @Ignore("Can be enabled only after b/330596920 is ready")
    @RequiresFlagsEnabled(FLAG_TOOLKIT_SET_FRAME_RATE_READ_ONLY)
    public void votePreferredFrameRate_isFrameRatePowerSavingsBalanced() {
        ViewRootImpl viewRootImpl = new ViewRootImpl(sContext,
                sContext.getDisplayNoVerify());
        assertEquals(viewRootImpl.isFrameRatePowerSavingsBalanced(), true);
        viewRootImpl.setFrameRatePowerSavingsBalanced(false);
        assertEquals(viewRootImpl.isFrameRatePowerSavingsBalanced(), false);
        viewRootImpl.setFrameRatePowerSavingsBalanced(true);
        assertEquals(viewRootImpl.isFrameRatePowerSavingsBalanced(), true);
        View view = new View(sContext);
        attachViewToWindow(view);
        sInstrumentation.waitForIdleSync();

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

        sInstrumentation.runOnMainSync(() -> {
            attrs.setFrameRatePowerSavingsBalanced(false);
            viewRoot.setLayoutParams(attrs, false);
        });
        sInstrumentation.waitForIdleSync();

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

    /**
+4 −2
Original line number Diff line number Diff line
@@ -182,7 +182,8 @@ public final class PhoneWindowTest {

        WindowManager.LayoutParams wmlp = new WindowManager.LayoutParams(TYPE_APPLICATION_OVERLAY);
        wmlp.token = new Binder(); // Set a fake token to bypass 'is your activity running' check

        wmlp.setFrameRatePowerSavingsBalanced(
                    mPhoneWindow.getAttributes().isFrameRatePowerSavingsBalanced());
        sInstrumentation.runOnMainSync(() -> {
            WindowManager wm = mContext.getSystemService(WindowManager.class);
            wm.addView(decorView, wmlp);
@@ -203,7 +204,8 @@ public final class PhoneWindowTest {

        WindowManager.LayoutParams wmlp = new WindowManager.LayoutParams(TYPE_APPLICATION_OVERLAY);
        wmlp.token = new Binder(); // Set a fake token to bypass 'is your activity running' check

        wmlp.setFrameRatePowerSavingsBalanced(
                mPhoneWindow.getAttributes().isFrameRatePowerSavingsBalanced());
        sInstrumentation.runOnMainSync(() -> {
            WindowManager wm = mContext.getSystemService(WindowManager.class);
            wm.addView(decorView, wmlp);