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

Commit 983de16b authored by Jeff DeCew's avatar Jeff DeCew
Browse files

Rename ViewRefactorFlag to RefactorFlag; make FeatureFlags exemption clearer.

* I'm removing the word View from the class so that this can be used in other contexts.
* I'm adding an requirement that you call `forView` if you want to omit the FeatureFlags.

Bug: 290365128
Test: atest SystemUITests
Change-Id: I96a273a660f05fc398ee7eb68e19b76aa8db0bc5
parent 721668de
Loading
Loading
Loading
Loading
+24 −15
Original line number Diff line number Diff line
@@ -28,27 +28,23 @@ import com.android.systemui.Dependency
 *   flag-disabled builds, but with a check that should crash eng builds or tests when the
 *   expectation is violated.
 *
 * The constructors prefer that you provide a [FeatureFlags] instance, but does not require it,
 * The constructors require that you provide a [FeatureFlags] instance. If you're using this in a
 * View class, it's acceptable to ue the [forView] constructor methods, which do not require one,
 * falling back to [Dependency.get]. This fallback should ONLY be used to flag-guard code changes
 * inside views where injecting flag values after initialization can be error-prone.
 * inside Views where injecting flag values after initialization can be error-prone.
 */
class ViewRefactorFlag
class RefactorFlag
private constructor(
    private val injectedFlags: FeatureFlags?,
    private val flag: BooleanFlag,
    private val flagName: Any,
    private val readFlagValue: (FeatureFlags) -> Boolean
) {
    @JvmOverloads
    constructor(
        flags: FeatureFlags? = null,
        flags: FeatureFlags,
        flag: UnreleasedFlag
    ) : this(flags, flag, { it.isEnabled(flag) })

    @JvmOverloads
    constructor(
        flags: FeatureFlags? = null,
        flag: ReleasedFlag
    ) : this(flags, flag, { it.isEnabled(flag) })
    constructor(flags: FeatureFlags, flag: ReleasedFlag) : this(flags, flag, { it.isEnabled(flag) })

    /** Whether the flag is enabled. Called to switch between an old behavior and a new behavior. */
    val isEnabled by lazy {
@@ -69,7 +65,8 @@ private constructor(
     * }
     * ````
     */
    fun assertDisabled() = check(!isEnabled) { "Code path not supported when $flag is enabled." }
    fun assertDisabled() =
        check(!isEnabled) { "Code path not supported when $flagName is enabled." }

    /**
     * Called to ensure code is only run when the flag is enabled. This protects users from the
@@ -87,13 +84,25 @@ private constructor(
     */
    fun expectEnabled(): Boolean {
        if (!isEnabled) {
            val message = "Code path not supported when $flag is disabled."
            val message = "Code path not supported when $flagName is disabled."
            Log.wtf(TAG, message, Exception(message))
        }
        return isEnabled
    }

    private companion object {
        private const val TAG = "ViewRefactorFlag"
    companion object {
        private const val TAG = "RefactorFlag"

        /** Construct a [RefactorFlag] within View construction where injection is impossible. */
        @JvmStatic
        @JvmOverloads
        fun forView(flag: UnreleasedFlag, flags: FeatureFlags? = null) =
            RefactorFlag(flags, flag) { it.isEnabled(flag) }

        /** Construct a [RefactorFlag] within View construction where injection is impossible. */
        @JvmStatic
        @JvmOverloads
        fun forView(flag: ReleasedFlag, flags: FeatureFlags? = null) =
            RefactorFlag(flags, flag) { it.isEnabled(flag) }
    }
}
+3 −3
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@ package com.android.systemui.qs
import android.content.Context
import android.util.AttributeSet
import com.android.systemui.flags.Flags
import com.android.systemui.flags.ViewRefactorFlag
import com.android.systemui.flags.RefactorFlag
import com.android.systemui.res.R

open class SideLabelTileLayout(
@@ -27,8 +27,8 @@ open class SideLabelTileLayout(
    attrs: AttributeSet?
) : TileLayout(context, attrs) {

    private final val isSmallLandscapeLockscreenEnabled =
            ViewRefactorFlag(flag = Flags.LOCKSCREEN_ENABLE_LANDSCAPE).isEnabled
    private val isSmallLandscapeLockscreenEnabled =
            RefactorFlag.forView(Flags.LOCKSCREEN_ENABLE_LANDSCAPE).isEnabled

    override fun updateResources(): Boolean {
        return super.updateResources().also {
+3 −3
Original line number Diff line number Diff line
@@ -15,13 +15,13 @@ import androidx.annotation.Nullable;

import com.android.internal.logging.UiEventLogger;
import com.android.systemui.FontSizeUtils;
import com.android.systemui.flags.ViewRefactorFlag;
import com.android.systemui.res.R;
import com.android.systemui.flags.Flags;
import com.android.systemui.flags.RefactorFlag;
import com.android.systemui.qs.QSPanel.QSTileLayout;
import com.android.systemui.qs.QSPanelControllerBase.TileRecord;
import com.android.systemui.qs.tileimpl.HeightOverrideable;
import com.android.systemui.qs.tileimpl.QSTileViewImplKt;
import com.android.systemui.res.R;

import java.util.ArrayList;

@@ -55,7 +55,7 @@ public class TileLayout extends ViewGroup implements QSTileLayout {
    protected int mLastTileBottom;
    protected TextView mTempTextView;
    private final Boolean mIsSmallLandscapeLockscreenEnabled =
            new ViewRefactorFlag(Flags.LOCKSCREEN_ENABLE_LANDSCAPE).isEnabled();
            RefactorFlag.forView(Flags.LOCKSCREEN_ENABLE_LANDSCAPE).isEnabled();

    public TileLayout(Context context) {
        this(context, null);
+6 −6
Original line number Diff line number Diff line
@@ -37,11 +37,11 @@ import androidx.annotation.NonNull;
import com.android.app.animation.Interpolators;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.policy.SystemBarUtils;
import com.android.systemui.res.R;
import com.android.systemui.animation.ShadeInterpolation;
import com.android.systemui.flags.Flags;
import com.android.systemui.flags.ViewRefactorFlag;
import com.android.systemui.flags.RefactorFlag;
import com.android.systemui.plugins.statusbar.StatusBarStateController.StateListener;
import com.android.systemui.res.R;
import com.android.systemui.shade.transition.LargeScreenShadeInterpolator;
import com.android.systemui.statusbar.notification.NotificationUtils;
import com.android.systemui.statusbar.notification.SourceType;
@@ -96,10 +96,10 @@ public class NotificationShelf extends ActivatableNotificationView implements St
    private float mCornerAnimationDistance;
    private NotificationShelfController mController;
    private float mActualWidth = -1;
    private final ViewRefactorFlag mSensitiveRevealAnim =
            new ViewRefactorFlag(Flags.SENSITIVE_REVEAL_ANIM);
    private final ViewRefactorFlag mShelfRefactor =
            new ViewRefactorFlag(Flags.NOTIFICATION_SHELF_REFACTOR);
    private final RefactorFlag mSensitiveRevealAnim =
            RefactorFlag.forView(Flags.SENSITIVE_REVEAL_ANIM);
    private final RefactorFlag mShelfRefactor =
            RefactorFlag.forView(Flags.NOTIFICATION_SHELF_REFACTOR);
    private boolean mCanModifyColorOfNotifications;
    private boolean mCanInteract;
    private NotificationStackScrollLayout mHostLayout;
+3 −3
Original line number Diff line number Diff line
@@ -3,10 +3,10 @@ package com.android.systemui.statusbar.notification
import android.util.FloatProperty
import android.view.View
import androidx.annotation.FloatRange
import com.android.systemui.res.R
import com.android.systemui.flags.FeatureFlags
import com.android.systemui.flags.Flags
import com.android.systemui.flags.ViewRefactorFlag
import com.android.systemui.flags.RefactorFlag
import com.android.systemui.res.R
import com.android.systemui.statusbar.notification.stack.AnimationProperties
import com.android.systemui.statusbar.notification.stack.StackStateAnimator
import kotlin.math.abs
@@ -323,7 +323,7 @@ constructor(
    internal var maxRadius = maxRadius
        private set

    internal val newHeadsUpAnim = ViewRefactorFlag(featureFlags, Flags.IMPROVED_HUN_ANIMATIONS)
    internal val newHeadsUpAnim = RefactorFlag.forView(Flags.IMPROVED_HUN_ANIMATIONS, featureFlags)

    /** Animatable for top roundness */
    private val topAnimatable = topAnimatable(roundable)
Loading