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

Commit 60bb228f authored by Caitlin Cassidy's avatar Caitlin Cassidy
Browse files

[Media TTT] Add the #transferToReceiverTriggered callback.

Also renames TransferInitiated -> TransferToReceiverTriggered, because
we also need a TransferToThisDeviceTriggered callback.

Bug: 203800643
Bug: 203800347
Test: verify `adb shell cmd statusbar media-ttt-chip-add-sender Tablet
TransferToReceiverTriggered` works
Test: media.taptotransfer tests

Change-Id: Ibb968d5c35391cf84e28fc2460148ea6bf396d14
parent 4d4b6c47
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -60,6 +60,18 @@ interface IDeviceSenderCallback {
    oneway void closeToReceiverToEndCast(
        in MediaRoute2Info mediaInfo, in DeviceInfo otherDeviceInfo);

    /**
     * Invoke to notify System UI that a media transfer from this device (the sender) to a receiver
     * device has been started.
     *
     * Important notes:
     *   - This callback is for *starting* a cast. It should be used when this device is currently
     *     playing media locally and the media has started being transferred to the receiver device
     *     instead.
     */
    oneway void transferToReceiverTriggered(
        in MediaRoute2Info mediaInfo, in DeviceInfo otherDeviceInfo);

    /**
     * Invoke to notify System UI that the attempted transfer has failed.
     *
+9 −14
Original line number Diff line number Diff line
@@ -35,7 +35,7 @@ import com.android.systemui.media.taptotransfer.sender.MediaTttSenderService
import com.android.systemui.media.taptotransfer.sender.MoveCloserToEndCast
import com.android.systemui.media.taptotransfer.sender.MoveCloserToStartCast
import com.android.systemui.media.taptotransfer.sender.TransferFailed
import com.android.systemui.media.taptotransfer.sender.TransferInitiated
import com.android.systemui.media.taptotransfer.sender.TransferToReceiverTriggered
import com.android.systemui.media.taptotransfer.sender.TransferSucceeded
import com.android.systemui.shared.mediattt.DeviceInfo
import com.android.systemui.shared.mediattt.IDeviceSenderCallback
@@ -93,18 +93,13 @@ class MediaTttCommandLineHelper @Inject constructor(
                        senderCallback.closeToReceiverToEndCast(mediaInfo, otherDeviceInfo)
                    }
                }

                // TODO(b/203800643): Migrate other commands to invoke the service instead of the
                //   controller.
                TRANSFER_INITIATED_COMMAND_NAME -> {
                    mediaTttChipControllerSender.displayChip(
                        TransferInitiated(
                            appIconDrawable,
                            APP_ICON_CONTENT_DESCRIPTION,
                            otherDeviceName
                        )
                    )
                TRANSFER_TO_RECEIVER_TRIGGERED_COMMAND_NAME -> {
                    runOnService { senderCallback ->
                        senderCallback.transferToReceiverTriggered(mediaInfo, otherDeviceInfo)
                    }
                }
                // TODO(b/203800643): Migrate this command to invoke the service instead of the
                //   controller.
                TRANSFER_SUCCEEDED_COMMAND_NAME -> {
                    mediaTttChipControllerSender.displayChip(
                        TransferSucceeded(
@@ -124,7 +119,7 @@ class MediaTttCommandLineHelper @Inject constructor(
                    pw.println("Chip type must be one of " +
                            "$MOVE_CLOSER_TO_START_CAST_COMMAND_NAME, " +
                            "$MOVE_CLOSER_TO_END_CAST_COMMAND_NAME, " +
                            "$TRANSFER_INITIATED_COMMAND_NAME, " +
                            "$TRANSFER_TO_RECEIVER_TRIGGERED_COMMAND_NAME, " +
                            "$TRANSFER_SUCCEEDED_COMMAND_NAME, " +
                            TRANSFER_FAILED_COMMAND_NAME
                    )
@@ -234,7 +229,7 @@ val MOVE_CLOSER_TO_START_CAST_COMMAND_NAME = MoveCloserToStartCast::class.simple
@VisibleForTesting
val MOVE_CLOSER_TO_END_CAST_COMMAND_NAME = MoveCloserToEndCast::class.simpleName!!
@VisibleForTesting
val TRANSFER_INITIATED_COMMAND_NAME = TransferInitiated::class.simpleName!!
val TRANSFER_TO_RECEIVER_TRIGGERED_COMMAND_NAME = TransferToReceiverTriggered::class.simpleName!!
@VisibleForTesting
val TRANSFER_SUCCEEDED_COMMAND_NAME = TransferSucceeded::class.simpleName!!
@VisibleForTesting
+5 −2
Original line number Diff line number Diff line
@@ -70,8 +70,11 @@ class MoveCloserToEndCast(
    otherDeviceName
)

/** A state representing that a transfer has been initiated (but not completed). */
class TransferInitiated(
/**
 * A state representing that a transfer to the receiver device has been initiated (but not
 * completed).
 */
class TransferToReceiverTriggered(
    appIconDrawable: Drawable,
    appIconContentDescription: String,
    otherDeviceName: String
+1 −1
Original line number Diff line number Diff line
@@ -49,7 +49,7 @@ class MediaTttChipControllerSender @Inject constructor(
        }

        // Loading
        val showLoading = chipState is TransferInitiated
        val showLoading = chipState is TransferToReceiverTriggered
        currentChipView.requireViewById<View>(R.id.loading).visibility =
            if (showLoading) { View.VISIBLE } else { View.GONE }

+17 −0
Original line number Diff line number Diff line
@@ -55,6 +55,12 @@ class MediaTttSenderService @Inject constructor(
        ) {
            this@MediaTttSenderService.transferFailed(mediaInfo, otherDeviceInfo)
        }

        override fun transferToReceiverTriggered(
            mediaInfo: MediaRoute2Info, otherDeviceInfo: DeviceInfo
        ) {
            this@MediaTttSenderService.transferToReceiverTriggered(mediaInfo, otherDeviceInfo)
        }
    }

    // TODO(b/203800643): Use the app icon from the media info instead of a fake one.
@@ -93,4 +99,15 @@ class MediaTttSenderService @Inject constructor(
        )
        controller.displayChip(chipState)
    }

    private fun transferToReceiverTriggered(
        mediaInfo: MediaRoute2Info, otherDeviceInfo: DeviceInfo
    ) {
        val chipState = TransferToReceiverTriggered(
            appIconDrawable = fakeAppIconDrawable,
            appIconContentDescription = mediaInfo.name.toString(),
            otherDeviceName = otherDeviceInfo.name
        )
        controller.displayChip(chipState)
    }
}
Loading