Loading packages/SystemUI/src/com/android/systemui/flags/ViewRefactorFlag.kt→packages/SystemUI/src/com/android/systemui/flags/RefactorFlag.kt +24 −15 Original line number Diff line number Diff line Loading @@ -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 { Loading @@ -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 Loading @@ -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) } } } packages/SystemUI/src/com/android/systemui/qs/SideLabelTileLayout.kt +3 −3 Original line number Diff line number Diff line Loading @@ -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( Loading @@ -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 { Loading packages/SystemUI/src/com/android/systemui/qs/TileLayout.java +3 −3 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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); Loading packages/SystemUI/src/com/android/systemui/statusbar/NotificationShelf.java +6 −6 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading packages/SystemUI/src/com/android/systemui/statusbar/notification/Roundable.kt +3 −3 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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 Loading
packages/SystemUI/src/com/android/systemui/flags/ViewRefactorFlag.kt→packages/SystemUI/src/com/android/systemui/flags/RefactorFlag.kt +24 −15 Original line number Diff line number Diff line Loading @@ -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 { Loading @@ -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 Loading @@ -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) } } }
packages/SystemUI/src/com/android/systemui/qs/SideLabelTileLayout.kt +3 −3 Original line number Diff line number Diff line Loading @@ -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( Loading @@ -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 { Loading
packages/SystemUI/src/com/android/systemui/qs/TileLayout.java +3 −3 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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); Loading
packages/SystemUI/src/com/android/systemui/statusbar/NotificationShelf.java +6 −6 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading
packages/SystemUI/src/com/android/systemui/statusbar/notification/Roundable.kt +3 −3 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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