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

Commit b8bcb11d authored by Caitlin Cassidy's avatar Caitlin Cassidy
Browse files

[Media TTT] Add the #closeToReceiverToEndCast callback.

Bug: 203800643
Bug: 203800347
Test: verify `adb shell cmd statusbar media-ttt-chip-add-sender
Tablet MoveCloserToStartCast` triggers start cast chip
Test: verify `adb shell cmd statusbar media-ttt-chip-add-sender
Tablet MoveCloserToEndCast` triggers end cast chip
Test: media.taptotransfer tests

Change-Id: I1be9f1ab9785b47c4b2321e48a61e0985613e112
parent 0a939324
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -2189,6 +2189,8 @@
    <string name="media_transfer_undo">Undo</string>
    <!-- Text to ask the user to move their device closer to a different device (deviceName) in order to play media on the different device. [CHAR LIMIT=75] -->
    <string name="media_move_closer_to_start_cast">Move closer to play on <xliff:g id="deviceName" example="My Tablet">%1$s</xliff:g></string>
    <!-- Text to ask the user to move their device closer to a different device (deviceName) in order to transfer media from the different device and back onto the current device. [CHAR LIMIT=75] -->
    <string name="media_move_closer_to_end_cast">Move closer to <xliff:g id="deviceName" example="My Tablet">%1$s</xliff:g> to play here</string>
    <!-- Text informing the user that their media is now playing on a different device (deviceName). [CHAR LIMIT=50] -->
    <string name="media_transfer_playing">Playing on <xliff:g id="deviceName" example="My Tablet">%1$s</xliff:g></string>

+16 −0
Original line number Diff line number Diff line
@@ -43,4 +43,20 @@ interface IDeviceSenderCallback {
     */
    oneway void closeToReceiverToStartCast(
        in MediaRoute2Info mediaInfo, in DeviceInfo otherDeviceInfo);

    /**
     * Invoke to notify System UI that this device (the sender) is close to a receiver device, so
     * the user can potentially *end* a cast on the receiver device if the user moves this device a
     * bit closer.
     *
     * Important notes:
     *   - When this callback triggers, the device is close enough to inform the user that
     *     transferring is an option, but the device is *not* close enough to actually initiate a
     *     transfer yet.
     *   - This callback is for *ending* a cast. It should be used when media is currently being
     *     played on the receiver device and the media should be transferred to play locally
     *     instead.
     */
    oneway void closeToReceiverToEndCast(
        in MediaRoute2Info mediaInfo, in DeviceInfo otherDeviceInfo);
}
+9 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import com.android.systemui.media.taptotransfer.receiver.MediaTttChipControllerR
import com.android.systemui.media.taptotransfer.receiver.ChipStateReceiver
import com.android.systemui.media.taptotransfer.sender.MediaTttChipControllerSender
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.TransferInitiated
import com.android.systemui.media.taptotransfer.sender.TransferSucceeded
@@ -90,6 +91,11 @@ class MediaTttCommandLineHelper @Inject constructor(
                        senderCallback.closeToReceiverToStartCast(mediaInfo, otherDeviceInfo)
                    }
                }
                MOVE_CLOSER_TO_END_CAST_COMMAND_NAME -> {
                    runOnService { senderCallback ->
                        senderCallback.closeToReceiverToEndCast(mediaInfo, otherDeviceInfo)
                    }
                }

                // TODO(b/203800643): Migrate other commands to invoke the service instead of the
                //   controller.
@@ -119,6 +125,7 @@ class MediaTttCommandLineHelper @Inject constructor(
                else -> {
                    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_SUCCEEDED_COMMAND_NAME
                    )
@@ -226,6 +233,8 @@ const val REMOVE_CHIP_COMMAND_RECEIVER_TAG = "media-ttt-chip-remove-receiver"
@VisibleForTesting
val MOVE_CLOSER_TO_START_CAST_COMMAND_NAME = MoveCloserToStartCast::class.simpleName!!
@VisibleForTesting
val MOVE_CLOSER_TO_END_CAST_COMMAND_NAME = MoveCloserToEndCast::class.simpleName!!
@VisibleForTesting
val TRANSFER_INITIATED_COMMAND_NAME = TransferInitiated::class.simpleName!!
@VisibleForTesting
val TRANSFER_SUCCEEDED_COMMAND_NAME = TransferSucceeded::class.simpleName!!
+16 −0
Original line number Diff line number Diff line
@@ -55,6 +55,22 @@ class MoveCloserToStartCast(
    otherDeviceName
)

/**
 * A state representing that the two devices are close but not close enough to *end* a cast that's
 * currently occurring the receiver device. The chip will instruct the user to move closer in order
 * to initiate the transfer from the receiver and back onto this device (the original sender).
 */
class MoveCloserToEndCast(
    appIconDrawable: Drawable,
    appIconContentDescription: String,
    otherDeviceName: String,
) : ChipStateSender(
    appIconDrawable,
    appIconContentDescription,
    R.string.media_move_closer_to_end_cast,
    otherDeviceName
)

/**
 * A state representing that a transfer has been initiated (but not completed).
 *
+15 −0
Original line number Diff line number Diff line
@@ -43,6 +43,12 @@ class MediaTttSenderService @Inject constructor(
        ) {
            this@MediaTttSenderService.closeToReceiverToStartCast(mediaInfo, otherDeviceInfo)
        }

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

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

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