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

Commit 2c8c33dc authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes Ibe38bfd6,I211f018d,Ie1d76a5e into main

* changes:
  Add logs to track ViewFlipper updateRunning
  Format NotificationViewFlipperBinder
  ViewFlipper: add inhibit state to prevent updates, even when started
parents c4a91c99 7739c8d6
Loading
Loading
Loading
Loading
+28 −3
Original line number Diff line number Diff line
@@ -38,7 +38,9 @@ import android.widget.RemoteViews.RemoteView;
@RemoteView
public class ViewFlipper extends ViewAnimator {
    private static final String TAG = "ViewFlipper";
    private static final boolean LOGD = false;

    //TODO(b/423971232): set LOGD back to false once the log is unneeded
    private static final boolean LOGD = Build.isDebuggable();

    private static final int DEFAULT_INTERVAL = 3000;

@@ -49,6 +51,9 @@ public class ViewFlipper extends ViewAnimator {
    private boolean mStarted = false;
    private boolean mVisible = false;

    // Inhibiting prevents the view from actually animating, even if started or auto-started.
    private boolean mInhibited = false;

    public ViewFlipper(Context context) {
        super(context);
    }
@@ -127,6 +132,22 @@ public class ViewFlipper extends ViewAnimator {
        updateRunning();
    }

    /**
     * Inhibits the view from actually animating, even if it is started or auto-started.
     *
     * <p>NOTE: This state is NOT reflected in the {@link #isFlipping()} method. That method
     * returns true if the view is started or auto-started, even if inhibited. There is no way to
     * inspect the inhibited state, and it is only intended to be a override to prevent the
     * ViewFlipper from updating in cases where the system knows the view is not visible, but the
     * view does not.
     *
     * @hide
     */
    public void setInhibited(boolean inhibited) {
        mInhibited = inhibited;
        updateRunning();
    }

    @Override
    public CharSequence getAccessibilityClassName() {
        return ViewFlipper.class.getName();
@@ -150,7 +171,7 @@ public class ViewFlipper extends ViewAnimator {
     */
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
    private void updateRunning(boolean flipNow) {
        boolean running = mVisible && mStarted;
        boolean running = mVisible && mStarted && !mInhibited;
        if (running != mRunning) {
            if (running) {
                showOnly(mWhichChild, flipNow);
@@ -162,7 +183,11 @@ public class ViewFlipper extends ViewAnimator {
        }
        if (LOGD) {
            Log.d(TAG, "updateRunning() mVisible=" + mVisible + ", mStarted=" + mStarted
                    + ", mRunning=" + mRunning);
                    + ", mInhibited=" + mInhibited + ", mRunning=" + mRunning
                    + ", mInhibited=" + mInhibited + ", flipNow=" + flipNow
                    + ", mFlipInterval=" + mFlipInterval + ", view=" + this
                    + ", parent=" + this.getParent()
            );
        }
    }

+4 −12
Original line number Diff line number Diff line
@@ -18,11 +18,11 @@ package com.android.systemui.statusbar.notification.row.ui.viewbinder

import android.widget.ViewFlipper
import androidx.lifecycle.lifecycleScope
import com.android.app.tracing.coroutines.launchTraced as launch
import com.android.systemui.lifecycle.repeatWhenAttached
import com.android.systemui.statusbar.notification.row.ui.viewmodel.NotificationViewFlipperViewModel
import kotlinx.coroutines.DisposableHandle
import kotlinx.coroutines.coroutineScope
import com.android.app.tracing.coroutines.launchTraced as launch

/** Binds a [NotificationViewFlipper] to its [view model][NotificationViewFlipperViewModel]. */
object NotificationViewFlipperBinder {
@@ -39,16 +39,8 @@ object NotificationViewFlipperBinder {
        }
    }

    suspend fun bind(
        viewFlipper: ViewFlipper,
        viewModel: NotificationViewFlipperViewModel,
    ) = coroutineScope { launch { viewModel.isPaused.collect { viewFlipper.setPaused(it) } } }

    private fun ViewFlipper.setPaused(paused: Boolean) {
        if (paused) {
            stopFlipping()
        } else if (isAutoStart) {
            startFlipping()
        }
    suspend fun bind(viewFlipper: ViewFlipper, viewModel: NotificationViewFlipperViewModel) =
        coroutineScope {
            launch { viewModel.isPaused.collect { viewFlipper.setInhibited(it) } }
        }
}