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

Commit 0d7ae60c authored by Jeff DeCew's avatar Jeff DeCew
Browse files

Rename RefactorFlag methods

Test: atest SystemUITests
Bug: 290365128
Change-Id: I979bd50cb1aec2e6f4ffd75177fb2cad4f9b33ef
parent c00a4c0a
Loading
Loading
Loading
Loading
+12 −13
Original line number Diff line number Diff line
@@ -22,11 +22,11 @@ import com.android.systemui.Dependency
/**
 * This class promotes best practices for flag guarding System UI view refactors.
 * * [isEnabled] allows changing an implementation.
 * * [assertDisabled] allows authors to flag code as being "dead" when the flag gets enabled and
 * * [assertInLegacyMode] allows authors to flag code as being "dead" when the flag gets enabled and
 *   ensure that it is not being invoked accidentally in the post-flag refactor.
 * * [expectEnabled] allows authors to guard new code with a "safe" alternative when invoked on
 *   flag-disabled builds, but with a check that should crash eng builds or tests when the
 *   expectation is violated.
 * * [isUnexpectedlyInLegacyMode] allows authors to guard new code with a "safe" alternative when
 *   invoked on flag-disabled builds, but with a check that should crash eng builds or tests when
 *   the expectation is violated.
 *
 * 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,
@@ -60,13 +60,13 @@ private constructor(
     * Example usage:
     * ```
     * public void setController(NotificationShelfController notificationShelfController) {
     *     mShelfRefactor.assertDisabled();
     *     mShelfRefactor.assertInLegacyMode();
     *     mController = notificationShelfController;
     * }
     * ````
     */
    fun assertDisabled() =
        check(!isEnabled) { "Code path not supported when $flagName is enabled." }
    fun assertInLegacyMode() =
        check(!isEnabled) { "Legacy 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
@@ -76,18 +76,17 @@ private constructor(
     * Example usage:
     * ```
     * public void setShelfIcons(NotificationIconContainer icons) {
     *     if (mShelfRefactor.expectEnabled()) {
     *     if (mShelfRefactor.isUnexpectedlyInLegacyMode()) return;
     *     mShelfIcons = icons;
     * }
     * }
     * ```
     */
    fun expectEnabled(): Boolean {
    fun isUnexpectedlyInLegacyMode(): Boolean {
        if (!isEnabled) {
            val message = "Code path not supported when $flagName is disabled."
            val message = "New code path expects $flagName to be enabled."
            Log.wtf(TAG, message, Exception(message))
        }
        return isEnabled
        return !isEnabled
    }

    companion object {
+7 −7
Original line number Diff line number Diff line
@@ -133,7 +133,7 @@ public class NotificationShelf extends ActivatableNotificationView implements St

    public void bind(AmbientState ambientState,
                     NotificationStackScrollLayoutController hostLayoutController) {
        mShelfRefactor.assertDisabled();
        mShelfRefactor.assertInLegacyMode();
        mAmbientState = ambientState;
        mHostLayoutController = hostLayoutController;
        hostLayoutController.setOnNotificationRemovedListener((child, isTransferInProgress) -> {
@@ -143,7 +143,7 @@ public class NotificationShelf extends ActivatableNotificationView implements St

    public void bind(AmbientState ambientState, NotificationStackScrollLayout hostLayout,
            NotificationRoundnessManager roundnessManager) {
        if (!mShelfRefactor.expectEnabled()) return;
        if (mShelfRefactor.isUnexpectedlyInLegacyMode()) return;
        mAmbientState = ambientState;
        mHostLayout = hostLayout;
        mRoundnessManager = roundnessManager;
@@ -964,7 +964,7 @@ public class NotificationShelf extends ActivatableNotificationView implements St

    @Override
    public void onStateChanged(int newState) {
        mShelfRefactor.assertDisabled();
        mShelfRefactor.assertInLegacyMode();
        mStatusBarState = newState;
        updateInteractiveness();
    }
@@ -1022,17 +1022,17 @@ public class NotificationShelf extends ActivatableNotificationView implements St
    }

    public void setController(NotificationShelfController notificationShelfController) {
        mShelfRefactor.assertDisabled();
        mShelfRefactor.assertInLegacyMode();
        mController = notificationShelfController;
    }

    public void setCanModifyColorOfNotifications(boolean canModifyColorOfNotifications) {
        if (!mShelfRefactor.expectEnabled()) return;
        if (mShelfRefactor.isUnexpectedlyInLegacyMode()) return;
        mCanModifyColorOfNotifications = canModifyColorOfNotifications;
    }

    public void setCanInteract(boolean canInteract) {
        if (!mShelfRefactor.expectEnabled()) return;
        if (mShelfRefactor.isUnexpectedlyInLegacyMode()) return;
        mCanInteract = canInteract;
        updateInteractiveness();
    }
@@ -1050,7 +1050,7 @@ public class NotificationShelf extends ActivatableNotificationView implements St
    }

    public void requestRoundnessResetFor(ExpandableView child) {
        if (!mShelfRefactor.expectEnabled()) return;
        if (mShelfRefactor.isUnexpectedlyInLegacyMode()) return;
        child.requestRoundnessReset(SHELF_SCROLL);
    }

+10 −11
Original line number Diff line number Diff line
@@ -167,7 +167,7 @@ constructor(
        NotificationShelfViewBinderWrapperControllerImpl.unsupported

    override fun setShelfIcons(icons: NotificationIconContainer) {
        if (shelfRefactor.expectEnabled()) {
        if (shelfRefactor.isUnexpectedlyInLegacyMode()) return
        NotificationIconContainerViewBinder.bind(
            icons,
            shelfIconsViewModel,
@@ -178,7 +178,6 @@ constructor(
        )
        shelfIcons = icons
    }
    }

    override fun onDensityOrFontScaleChanged(context: Context) {
        updateIconLayoutParams(context)
+4 −4
Original line number Diff line number Diff line
@@ -2733,7 +2733,7 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
     * @param listener callback for notification removed
     */
    public void setOnNotificationRemovedListener(OnNotificationRemovedListener listener) {
        mShelfRefactor.assertDisabled();
        mShelfRefactor.assertInLegacyMode();
        mOnNotificationRemovedListener = listener;
    }

@@ -4967,12 +4967,12 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable

    @Nullable
    public ExpandableView getShelf() {
        if (!mShelfRefactor.expectEnabled()) return null;
        if (mShelfRefactor.isUnexpectedlyInLegacyMode()) return null;
        return mShelf;
    }

    public void setShelf(NotificationShelf shelf) {
        if (!mShelfRefactor.expectEnabled()) return;
        if (mShelfRefactor.isUnexpectedlyInLegacyMode()) return;
        int index = -1;
        if (mShelf != null) {
            index = indexOfChild(mShelf);
@@ -4986,7 +4986,7 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
    }

    public void setShelfController(NotificationShelfController notificationShelfController) {
        mShelfRefactor.assertDisabled();
        mShelfRefactor.assertInLegacyMode();
        int index = -1;
        if (mShelf != null) {
            index = indexOfChild(mShelf);
+3 −3
Original line number Diff line number Diff line
@@ -1431,7 +1431,7 @@ public class NotificationStackScrollLayoutController {
    }

    public void setShelfController(NotificationShelfController notificationShelfController) {
        mShelfRefactor.assertDisabled();
        mShelfRefactor.assertInLegacyMode();
        mView.setShelfController(notificationShelfController);
    }

@@ -1644,12 +1644,12 @@ public class NotificationStackScrollLayoutController {
    }

    public void setShelf(NotificationShelf shelf) {
        if (!mShelfRefactor.expectEnabled()) return;
        if (mShelfRefactor.isUnexpectedlyInLegacyMode()) return;
        mView.setShelf(shelf);
    }

    public int getShelfHeight() {
        if (!mShelfRefactor.expectEnabled()) {
        if (mShelfRefactor.isUnexpectedlyInLegacyMode()) {
            return 0;
        }
        ExpandableView shelf = mView.getShelf();
Loading