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

Commit 13c529d3 authored by Caitlin Shkuratov's avatar Caitlin Shkuratov
Browse files

[Chipbar] Remove the media-specific wake reason and window title from

the ChipbarCoordinator and instead pass them in each time we display a
temporary view.

Now, TemporaryViewDisplayController needs to handle different
information being displayed with different window titles. That logic has
been added and tested.

Bug: 245610654
Test: manual: Verified that media ttt views still display correctly
Test: manual: Verified that showing a new media ttt view with a new
title will animate out the old view and display the new one
Test: atest TemporaryViewDisplayControllerTest

Change-Id: I5b324867c3e8b0cc040217c21ca94f26ad8c351a
parent c8593005
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -27,10 +27,11 @@ import com.android.systemui.common.shared.model.Icon
/** Utility methods for media tap-to-transfer. */
class MediaTttUtils {
    companion object {
        // Used in CTS tests UpdateMediaTapToTransferSenderDisplayTest and
        // UpdateMediaTapToTransferReceiverDisplayTest
        const val WINDOW_TITLE = "Media Transfer Chip View"
        const val WAKE_REASON = "MEDIA_TRANSFER_ACTIVATED"
        const val WINDOW_TITLE_SENDER = "Media Transfer Chip View (Sender)"
        const val WINDOW_TITLE_RECEIVER = "Media Transfer Chip View (Receiver)"

        const val WAKE_REASON_SENDER = "MEDIA_TRANSFER_ACTIVATED_SENDER"
        const val WAKE_REASON_RECEIVER = "MEDIA_TRANSFER_ACTIVATED_RECEIVER"

        /**
         * Returns the information needed to display the icon in [Icon] form.
+4 −7
Original line number Diff line number Diff line
@@ -40,7 +40,6 @@ import com.android.systemui.media.taptotransfer.common.MediaTttLogger
import com.android.systemui.media.taptotransfer.common.MediaTttUtils
import com.android.systemui.statusbar.CommandQueue
import com.android.systemui.statusbar.policy.ConfigurationController
import com.android.systemui.temporarydisplay.DEFAULT_TIMEOUT_MILLIS
import com.android.systemui.temporarydisplay.TemporaryViewDisplayController
import com.android.systemui.temporarydisplay.TemporaryViewInfo
import com.android.systemui.util.animation.AnimationUtil.Companion.frames
@@ -78,8 +77,6 @@ class MediaTttChipControllerReceiver @Inject constructor(
        configurationController,
        powerManager,
        R.layout.media_ttt_chip_receiver,
        MediaTttUtils.WINDOW_TITLE,
        MediaTttUtils.WAKE_REASON,
) {
    @SuppressLint("WrongConstant") // We're allowed to use LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS
    override val windowLayoutParams = commonWindowLayoutParams.apply {
@@ -231,7 +228,7 @@ class MediaTttChipControllerReceiver @Inject constructor(
data class ChipReceiverInfo(
    val routeInfo: MediaRoute2Info,
    val appIconDrawableOverride: Drawable?,
    val appNameOverride: CharSequence?
) : TemporaryViewInfo {
    override fun getTimeoutMs() = DEFAULT_TIMEOUT_MILLIS
}
    val appNameOverride: CharSequence?,
    override val windowTitle: String = MediaTttUtils.WINDOW_TITLE_RECEIVER,
    override val wakeReason: String = MediaTttUtils.WAKE_REASON_RECEIVER,
) : TemporaryViewInfo()
+2 −2
Original line number Diff line number Diff line
@@ -43,7 +43,7 @@ enum class ChipStateSender(
    @StringRes val stringResId: Int?,
    val transferStatus: TransferStatus,
    val endItem: SenderEndItem?,
    val timeout: Long = DEFAULT_TIMEOUT_MILLIS
    val timeout: Int = DEFAULT_TIMEOUT_MILLIS,
) {
    /**
     * A state representing that the two devices are close but not close enough to *start* a cast to
@@ -223,6 +223,6 @@ sealed class SenderEndItem {
// Give the Transfer*Triggered states a longer timeout since those states represent an active
// process and we should keep the user informed about it as long as possible (but don't allow it to
// continue indefinitely).
private const val TRANSFER_TRIGGERED_TIMEOUT_MILLIS = 30000L
private const val TRANSFER_TRIGGERED_TIMEOUT_MILLIS = 30000

private const val TAG = "ChipStateSender"
+3 −0
Original line number Diff line number Diff line
@@ -159,6 +159,9 @@ constructor(
                    }
                },
            vibrationEffect = chipStateSender.transferStatus.vibrationEffect,
            windowTitle = MediaTttUtils.WINDOW_TITLE_SENDER,
            wakeReason = MediaTttUtils.WAKE_REASON_SENDER,
            timeoutMs = chipStateSender.timeout,
        )
    }

+23 −15
Original line number Diff line number Diff line
@@ -45,11 +45,6 @@ import com.android.systemui.util.concurrency.DelayableExecutor
 *
 * The generic type T is expected to contain all the information necessary for the subclasses to
 * display the view in a certain state, since they receive <T> in [updateView].
 *
 * @property windowTitle the title to use for the window that displays the temporary view. Should be
 *   normally cased, like "Window Title".
 * @property wakeReason a string used for logging if we needed to wake the screen in order to
 *   display the temporary view. Should be screaming snake cased, like WAKE_REASON.
 */
abstract class TemporaryViewDisplayController<T : TemporaryViewInfo, U : TemporaryViewLogger>(
    internal val context: Context,
@@ -60,8 +55,6 @@ abstract class TemporaryViewDisplayController<T : TemporaryViewInfo, U : Tempora
    private val configurationController: ConfigurationController,
    private val powerManager: PowerManager,
    @LayoutRes private val viewLayoutRes: Int,
    private val windowTitle: String,
    private val wakeReason: String,
) : CoreStartable {
    /**
     * Window layout params that will be used as a starting point for the [windowLayoutParams] of
@@ -74,7 +67,6 @@ abstract class TemporaryViewDisplayController<T : TemporaryViewInfo, U : Tempora
        type = WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY
        flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE or
            WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
        title = windowTitle
        format = PixelFormat.TRANSLUCENT
        setTrustedOverlay()
    }
@@ -102,11 +94,22 @@ abstract class TemporaryViewDisplayController<T : TemporaryViewInfo, U : Tempora
    fun displayView(newInfo: T) {
        val currentDisplayInfo = displayInfo

        if (currentDisplayInfo != null) {
        if (currentDisplayInfo != null &&
            currentDisplayInfo.info.windowTitle == newInfo.windowTitle) {
            // We're already displaying information in the correctly-titled window, so we just need
            // to update the view.
            currentDisplayInfo.info = newInfo
            updateView(currentDisplayInfo.info, currentDisplayInfo.view)
        } else {
            // The view is new, so set up all our callbacks and inflate the view
            if (currentDisplayInfo != null) {
                // We're already displaying information but that information is under a different
                // window title. So, we need to remove the old window with the old title and add a
                // new window with the new title.
                removeView(removalReason = "New info has new window title: ${newInfo.windowTitle}")
            }

            // At this point, we're guaranteed to no longer be displaying a view.
            // So, set up all our callbacks and inflate the view.
            configurationController.addCallback(displayScaleListener)
            // Wake the screen if necessary so the user will see the view. (Per b/239426653, we want
            // the view to show over the dream state, so we should only wake up if the screen is
@@ -115,7 +118,7 @@ abstract class TemporaryViewDisplayController<T : TemporaryViewInfo, U : Tempora
                powerManager.wakeUp(
                    SystemClock.uptimeMillis(),
                    PowerManager.WAKE_REASON_APPLICATION,
                        "com.android.systemui:$wakeReason",
                    "com.android.systemui:${newInfo.wakeReason}",
                )
            }
            logger.logChipAddition()
@@ -124,7 +127,7 @@ abstract class TemporaryViewDisplayController<T : TemporaryViewInfo, U : Tempora

        // Cancel and re-set the view timeout each time we get a new state.
        val timeout = accessibilityManager.getRecommendedTimeoutMillis(
            newInfo.getTimeoutMs().toInt(),
            newInfo.timeoutMs,
            // Not all views have controls so FLAG_CONTENT_CONTROLS might be superfluous, but
            // include it just to be safe.
            FLAG_CONTENT_ICONS or FLAG_CONTENT_TEXT or FLAG_CONTENT_CONTROLS
@@ -149,7 +152,12 @@ abstract class TemporaryViewDisplayController<T : TemporaryViewInfo, U : Tempora
        val newDisplayInfo = DisplayInfo(newView, newInfo)
        displayInfo = newDisplayInfo
        updateView(newDisplayInfo.info, newDisplayInfo.view)
        windowManager.addView(newView, windowLayoutParams)

        val paramsWithTitle = WindowManager.LayoutParams().also {
            it.copyFrom(windowLayoutParams)
            it.title = newInfo.windowTitle
        }
        windowManager.addView(newView, paramsWithTitle)
        animateViewIn(newView)
    }

Loading