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

Commit 0a939324 authored by Caitlin Cassidy's avatar Caitlin Cassidy
Browse files

[Media TTT] Add DeviceInfo to the service callback.

Bug: 203800643
Bug: 203800347
Test: manual (verify chip contains right name)
Test: media.taptotransfer tests
Change-Id: Iab3f8a7d793d0c824fad9041c52b5a7fe862d236
parent 38aa601a
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.shared.mediattt;

parcelable DeviceInfo;
+41 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.shared.mediattt

import android.os.Parcel
import android.os.Parcelable

/**
 * Represents a device that can send or receive media. Includes any device information necessary for
 * SysUI to display an informative chip to the user.
 */
class DeviceInfo(val name: String) : Parcelable {
    constructor(parcel: Parcel) : this(parcel.readString())

    override fun writeToParcel(dest: Parcel?, flags: Int) {
        dest?.writeString(name)
    }

    override fun describeContents() = 0

    override fun toString() = "name: $name"

    companion object CREATOR : Parcelable.Creator<DeviceInfo> {
        override fun createFromParcel(parcel: Parcel) = DeviceInfo(parcel)
        override fun newArray(size: Int) = arrayOfNulls<DeviceInfo?>(size)
    }
}
+3 −2
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.systemui.shared.mediattt;

import android.media.MediaRoute2Info;
import com.android.systemui.shared.mediattt.DeviceInfo;

/**
 * A callback interface that can be invoked to trigger media transfer events on System UI.
@@ -40,6 +41,6 @@ interface IDeviceSenderCallback {
     *     playing media locally and the media should be transferred to be played on the receiver
     *     device instead.
     */
     // TODO(b/203800643): Add the otherDeviceInfo parameter.
    oneway void closeToReceiverToStartCast(in MediaRoute2Info mediaInfo);
    oneway void closeToReceiverToStartCast(
        in MediaRoute2Info mediaInfo, in DeviceInfo otherDeviceInfo);
}
+3 −1
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import com.android.systemui.media.taptotransfer.sender.MediaTttSenderService
import com.android.systemui.media.taptotransfer.sender.MoveCloserToStartCast
import com.android.systemui.media.taptotransfer.sender.TransferInitiated
import com.android.systemui.media.taptotransfer.sender.TransferSucceeded
import com.android.systemui.shared.mediattt.DeviceInfo
import com.android.systemui.shared.mediattt.IDeviceSenderCallback
import com.android.systemui.statusbar.commandline.Command
import com.android.systemui.statusbar.commandline.CommandRegistry
@@ -81,11 +82,12 @@ class MediaTttCommandLineHelper @Inject constructor(
            val mediaInfo = MediaRoute2Info.Builder("id", "Test Name")
                .addFeature("feature")
                .build()
            val otherDeviceInfo = DeviceInfo(otherDeviceName)

            when (args[1]) {
                MOVE_CLOSER_TO_START_CAST_COMMAND_NAME -> {
                    runOnService { senderCallback ->
                        senderCallback.closeToReceiverToStartCast(mediaInfo)
                        senderCallback.closeToReceiverToStartCast(mediaInfo, otherDeviceInfo)
                    }
                }

+9 −6
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.graphics.drawable.Icon
import android.media.MediaRoute2Info
import android.os.IBinder
import com.android.systemui.R
import com.android.systemui.shared.mediattt.DeviceInfo
import com.android.systemui.shared.mediattt.IDeviceSenderCallback
import javax.inject.Inject

@@ -37,8 +38,10 @@ class MediaTttSenderService @Inject constructor(

    // TODO(b/203800643): Add logging when callbacks trigger.
    private val binder: IBinder = object : IDeviceSenderCallback.Stub() {
        override fun closeToReceiverToStartCast(mediaInfo: MediaRoute2Info) {
            this@MediaTttSenderService.closeToReceiverToStartCast(mediaInfo)
        override fun closeToReceiverToStartCast(
            mediaInfo: MediaRoute2Info, otherDeviceInfo: DeviceInfo
        ) {
            this@MediaTttSenderService.closeToReceiverToStartCast(mediaInfo, otherDeviceInfo)
        }
    }

@@ -50,14 +53,14 @@ class MediaTttSenderService @Inject constructor(

    override fun onBind(intent: Intent?): IBinder = binder

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

private const val FAKE_DEVICE_NAME = "Fake Other Device Name"
Loading