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

Commit cb1b8480 authored by Jorim Jaggi's avatar Jorim Jaggi Committed by Tiger Huang
Browse files

Window Manager Flag Migration (4/n)

Wire up the appearance and the transient state of system bars between
WMS and System UI. The derived classes of CommandQueue.Callbacks no
longer listen to setSystemUiVisibility, but listen to showTransient,
abortTransient, and onSystemBarAppearanceChanged instead.

Bug: 118118435
Test: atest InsetsSourceProviderTest InsetsStateControllerTest
            InsetsPolicyTest WindowStateTests CommandQueueTest
            RegisterStatusBarResultTest InsetsFlagsTest
            LightBarControllerTest
Change-Id: I1dcaff47ae57ccee91146fdc042cde5e26fc0b3f
parent 2ff65cd6
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -305,6 +305,11 @@ interface IWindowManager
     */
    oneway void statusBarVisibilityChanged(int displayId, int visibility);

    /**
     * Called by System UI to notify Window Manager to hide transient bars.
     */
    oneway void hideTransientBars(int displayId);

    /**
    * When set to {@code true} the system bars will always be shown. This is true even if an app
    * requests to be fullscreen by setting the system ui visibility flags. The
+17 −17
Original line number Diff line number Diff line
@@ -146,20 +146,11 @@ public class InsetsAnimationControlImpl implements WindowInsetsAnimationControll
        }
        final Insets offset = Insets.subtract(mShownInsets, mPendingInsets);
        ArrayList<SurfaceParams> params = new ArrayList<>();
        if (offset.left != 0) {
        updateLeashesForSide(INSET_SIDE_LEFT, offset.left, mPendingInsets.left, params, state);
        }
        if (offset.top != 0) {
        updateLeashesForSide(INSET_SIDE_TOP, offset.top, mPendingInsets.top, params, state);
        }
        if (offset.right != 0) {
            updateLeashesForSide(INSET_SIDE_RIGHT, offset.right, mPendingInsets.right, params,
                    state);
        }
        if (offset.bottom != 0) {
        updateLeashesForSide(INSET_SIDE_RIGHT, offset.right, mPendingInsets.right, params, state);
        updateLeashesForSide(INSET_SIDE_BOTTOM, offset.bottom, mPendingInsets.bottom, params,
                state);
        }
        SyncRtSurfaceTransactionApplier applier = mTransactionApplierSupplier.get();
        applier.scheduleApply(params.toArray(new SurfaceParams[params.size()]));
        mCurrentInsets = mPendingInsets;
@@ -224,6 +215,9 @@ public class InsetsAnimationControlImpl implements WindowInsetsAnimationControll
    private void updateLeashesForSide(@InsetSide int side, int offset, int inset,
            ArrayList<SurfaceParams> surfaceParams, InsetsState state) {
        ArraySet<InsetsSourceConsumer> items = mSideSourceMap.get(side);
        if (items == null) {
            return;
        }
        // TODO: Implement behavior when inset spans over multiple types
        for (int i = items.size() - 1; i >= 0; i--) {
            final InsetsSourceConsumer consumer = items.valueAt(i);
@@ -274,9 +268,15 @@ public class InsetsAnimationControlImpl implements WindowInsetsAnimationControll
            SparseSetArray<InsetsSourceConsumer> sideSourcesMap,
            SparseArray<InsetsSourceConsumer> consumers) {
        for (int i = typeSideMap.size() - 1; i >= 0; i--) {
            int type = typeSideMap.keyAt(i);
            int side = typeSideMap.valueAt(i);
            sideSourcesMap.add(side, consumers.get(type));
            final int type = typeSideMap.keyAt(i);
            final int side = typeSideMap.valueAt(i);
            final InsetsSourceConsumer consumer = consumers.get(type);
            if (consumer == null) {
                // If the types that we are controlling are less than the types that the system has,
                // there can be some null consumers.
                continue;
            }
            sideSourcesMap.add(side, consumer);
        }
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -67,9 +67,9 @@ public class InsetsController implements WindowInsetsController {
     * Translation animation evaluator.
     */
    private static TypeEvaluator<Insets> sEvaluator = (fraction, startValue, endValue) -> Insets.of(
            0,
            (int) (startValue.left + fraction * (endValue.left - startValue.left)),
            (int) (startValue.top + fraction * (endValue.top - startValue.top)),
            0,
            (int) (startValue.right + fraction * (endValue.right - startValue.right)),
            (int) (startValue.bottom + fraction * (endValue.bottom - startValue.bottom)));

    /**
+56 −4
Original line number Diff line number Diff line
@@ -16,10 +16,18 @@

package android.view;

import static android.view.View.NAVIGATION_BAR_TRANSLUCENT;
import static android.view.View.NAVIGATION_BAR_TRANSPARENT;
import static android.view.View.STATUS_BAR_TRANSLUCENT;
import static android.view.View.STATUS_BAR_TRANSPARENT;
import static android.view.View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
import static android.view.View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
import static android.view.View.SYSTEM_UI_FLAG_LOW_PROFILE;
import static android.view.WindowInsetsController.APPEARANCE_LIGHT_SIDE_BARS;
import static android.view.WindowInsetsController.APPEARANCE_LIGHT_TOP_BAR;
import static android.view.WindowInsetsController.APPEARANCE_LOW_PROFILE_BARS;
import static android.view.WindowInsetsController.APPEARANCE_OPAQUE_BARS;
import static android.view.WindowInsetsController.APPEARANCE_OPAQUE_SIDE_BARS;
import static android.view.WindowInsetsController.APPEARANCE_OPAQUE_TOP_BAR;
import static android.view.WindowInsetsController.BEHAVIOR_SHOW_BARS_BY_SWIPE;
import static android.view.WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE;

@@ -35,9 +43,13 @@ public class InsetsFlags {

    @ViewDebug.ExportedProperty(flagMapping = {
            @ViewDebug.FlagToString(
                    mask = APPEARANCE_OPAQUE_BARS,
                    equals = APPEARANCE_OPAQUE_BARS,
                    name = "OPAQUE_BARS"),
                    mask = APPEARANCE_OPAQUE_TOP_BAR,
                    equals = APPEARANCE_OPAQUE_TOP_BAR,
                    name = "OPAQUE_TOP_BAR"),
            @ViewDebug.FlagToString(
                    mask = APPEARANCE_OPAQUE_SIDE_BARS,
                    equals = APPEARANCE_OPAQUE_SIDE_BARS,
                    name = "OPAQUE_SIDE_BARS"),
            @ViewDebug.FlagToString(
                    mask = APPEARANCE_LOW_PROFILE_BARS,
                    equals = APPEARANCE_LOW_PROFILE_BARS,
@@ -64,4 +76,44 @@ public class InsetsFlags {
                    name = "SHOW_TRANSIENT_BARS_BY_SWIPE")
    })
    public @Behavior int behavior;

    /**
     * Converts system UI visibility to appearance.
     *
     * @param systemUiVisibility the system UI visibility to be converted.
     * @return the outcome {@link Appearance}
     */
    public static @Appearance int getAppearance(int systemUiVisibility) {
        int appearance = 0;
        appearance |= convertFlag(systemUiVisibility, SYSTEM_UI_FLAG_LOW_PROFILE,
                APPEARANCE_LOW_PROFILE_BARS);
        appearance |= convertFlag(systemUiVisibility, SYSTEM_UI_FLAG_LIGHT_STATUS_BAR,
                APPEARANCE_LIGHT_TOP_BAR);
        appearance |= convertFlag(systemUiVisibility, SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR,
                APPEARANCE_LIGHT_SIDE_BARS);
        appearance |= convertNoFlag(systemUiVisibility,
                STATUS_BAR_TRANSLUCENT | STATUS_BAR_TRANSPARENT, APPEARANCE_OPAQUE_TOP_BAR);
        appearance |= convertNoFlag(systemUiVisibility,
                NAVIGATION_BAR_TRANSLUCENT | NAVIGATION_BAR_TRANSPARENT,
                APPEARANCE_OPAQUE_SIDE_BARS);
        return appearance;
    }

    /**
     * Converts the system UI visibility into an appearance flag if the given visibility contains
     * the given system UI flag.
     */
    private static @Appearance int convertFlag(int systemUiVisibility, int systemUiFlag,
            @Appearance int appearance) {
        return (systemUiVisibility & systemUiFlag) != 0 ? appearance : 0;
    }

    /**
     * Converts the system UI visibility into an appearance flag if the given visibility doesn't
     * contains the given system UI flag.
     */
    private static @Appearance int convertNoFlag(int systemUiVisibility, int systemUiFlag,
            @Appearance int appearance) {
        return (systemUiVisibility & systemUiFlag) == 0 ? appearance : 0;
    }
}
+28 −2
Original line number Diff line number Diff line
@@ -270,10 +270,23 @@ public class InsetsState implements Parcelable {
     *
     * @param type The {@link InternalInsetType} of the source to remove
     */
    public void removeSource(int type) {
    public void removeSource(@InternalInsetType int type) {
        mSources.remove(type);
    }

    /**
     * A shortcut for setting the visibility of the source.
     *
     * @param type The {@link InternalInsetType} of the source to set the visibility
     * @param visible {@code true} for visible
     */
    public void setSourceVisible(@InternalInsetType int type, boolean visible) {
        InsetsSource source = mSources.get(type);
        if (source != null) {
            source.setVisible(visible);
        }
    }

    public void set(InsetsState other) {
        set(other, false /* copySources */);
    }
@@ -357,6 +370,19 @@ public class InsetsState implements Parcelable {
        }
    }

    public static boolean containsType(@InternalInsetType int[] types,
            @InternalInsetType int type) {
        if (types == null) {
            return false;
        }
        for (int t : types) {
            if (t == type) {
                return true;
            }
        }
        return false;
    }

    public void dump(String prefix, PrintWriter pw) {
        pw.println(prefix + "InsetsState");
        for (int i = mSources.size() - 1; i >= 0; i--) {
@@ -364,7 +390,7 @@ public class InsetsState implements Parcelable {
        }
    }

    public static String typeToString(int type) {
    public static String typeToString(@InternalInsetType int type) {
        switch (type) {
            case TYPE_TOP_BAR:
                return "TYPE_TOP_BAR";
Loading