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

Commit c89dafe5 authored by chelseahao's avatar chelseahao
Browse files

Add selected channel index to `PrivateBroadcastReceiveData`.

Flag: com.android.settingslib.flags.audio_stream_play_pause_by_modify_source
Test: atest
Bug: 384976631
Change-Id: I94714dc55ba1eee56e42cd6a0fc28708532ed146
parent fc1985f4
Loading
Loading
Loading
Loading
+12 −3
Original line number Diff line number Diff line
@@ -20,9 +20,11 @@ import android.bluetooth.BluetoothDevice
import android.os.Parcel
import android.os.Parcelable
import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcastAssistant.LocalBluetoothLeBroadcastSourceState
import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcastAssistant.LocalBluetoothLeBroadcastSourceState.DECRYPTION_FAILED
import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcastAssistant.LocalBluetoothLeBroadcastSourceState.PAUSED
import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcastAssistant.LocalBluetoothLeBroadcastSourceState.PAUSED_BY_RECEIVER
import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcastAssistant.LocalBluetoothLeBroadcastSourceState.STREAMING
import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcastAssistant.LocalBluetoothLeBroadcastSourceState.DECRYPTION_FAILED
import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcastAssistant.UNKNOWN_CHANNEL

/**
 * Data class representing information received in a private broadcast.
@@ -41,6 +43,7 @@ data class PrivateBroadcastReceiveData(
    val broadcastId: Int = -1,
    val programInfo: String = "",
    val state: LocalBluetoothLeBroadcastSourceState?,
    val selectedChannelIndex: Set<Int> = UNKNOWN_CHANNEL
) : Parcelable {

    override fun describeContents(): Int = 0
@@ -51,6 +54,7 @@ data class PrivateBroadcastReceiveData(
        parcel.writeInt(broadcastId)
        parcel.writeString(programInfo)
        parcel.writeSerializable(state)
        parcel.writeSerializable(java.util.HashSet(selectedChannelIndex))
    }

    companion object {
@@ -70,7 +74,11 @@ data class PrivateBroadcastReceiveData(
                            state = readSerializable(
                                LocalBluetoothLeBroadcastSourceState::class.java.classLoader,
                                LocalBluetoothLeBroadcastSourceState::class.java
                            )
                            ),
                            selectedChannelIndex = readSerializable(
                                HashSet::class.java.classLoader,
                                HashSet::class.java
                            )?.filterIsInstance<Int>()?.toHashSet() ?: UNKNOWN_CHANNEL
                        )
                    }
                override fun newArray(size: Int): Array<PrivateBroadcastReceiveData?> {
@@ -84,7 +92,8 @@ data class PrivateBroadcastReceiveData(
                    && broadcastId != -1
                    && (state == STREAMING
                    || state == PAUSED
                    || state == DECRYPTION_FAILED)
                    || state == DECRYPTION_FAILED
                    || state == PAUSED_BY_RECEIVER)
        }
    }
}
+15 −6
Original line number Diff line number Diff line
@@ -20,7 +20,9 @@ import android.bluetooth.BluetoothAdapter
import android.bluetooth.BluetoothDevice
import android.os.Parcel
import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcastAssistant.LocalBluetoothLeBroadcastSourceState
import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcastAssistant.UNKNOWN_CHANNEL
import com.android.settingslib.bluetooth.PrivateBroadcastReceiveData.Companion.isValid
import java.util.HashSet
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
@@ -38,7 +40,8 @@ class PrivateBroadcastReceiveDataTest {
            sourceId = 1,
            broadcastId = 2,
            programInfo = "Test Program",
            state = LocalBluetoothLeBroadcastSourceState.STREAMING
            state = LocalBluetoothLeBroadcastSourceState.STREAMING,
            selectedChannelIndex = UNKNOWN_CHANNEL
        )

        val parcel = Parcel.obtain()
@@ -56,7 +59,8 @@ class PrivateBroadcastReceiveDataTest {
            sink = sink,
            sourceId = 1,
            broadcastId = 2,
            state = LocalBluetoothLeBroadcastSourceState.STREAMING
            state = LocalBluetoothLeBroadcastSourceState.STREAMING,
            selectedChannelIndex = HashSet.newHashSet(1)
        )
        assertTrue(data.isValid())
    }
@@ -67,7 +71,8 @@ class PrivateBroadcastReceiveDataTest {
            sink = null,
            sourceId = 1,
            broadcastId = 2,
            state = LocalBluetoothLeBroadcastSourceState.STREAMING
            state = LocalBluetoothLeBroadcastSourceState.STREAMING,
            selectedChannelIndex = HashSet.newHashSet(1)
        )
        assertFalse(data.isValid())
    }
@@ -78,7 +83,8 @@ class PrivateBroadcastReceiveDataTest {
            sink = sink,
            sourceId = -1,
            broadcastId = 2,
            state = LocalBluetoothLeBroadcastSourceState.STREAMING
            state = LocalBluetoothLeBroadcastSourceState.STREAMING,
            selectedChannelIndex = HashSet.newHashSet(1)
        )
        assertFalse(data.isValid())
    }
@@ -89,7 +95,8 @@ class PrivateBroadcastReceiveDataTest {
            sink = sink,
            sourceId = 1,
            broadcastId = -1,
            state = LocalBluetoothLeBroadcastSourceState.STREAMING
            state = LocalBluetoothLeBroadcastSourceState.STREAMING,
            selectedChannelIndex = HashSet.newHashSet(1)
        )
        assertFalse(data.isValid())
    }
@@ -100,7 +107,8 @@ class PrivateBroadcastReceiveDataTest {
            sink = sink,
            sourceId = 1,
            broadcastId = 2,
            state = null
            state = null,
            selectedChannelIndex = HashSet.newHashSet(1)
        )
        assertFalse(data.isValid())
    }
@@ -110,6 +118,7 @@ class PrivateBroadcastReceiveDataTest {
        assertTrue(PrivateBroadcastReceiveData(sink, 1, 1, state = LocalBluetoothLeBroadcastSourceState.STREAMING).isValid())
        assertTrue(PrivateBroadcastReceiveData(sink, 1, 1, state = LocalBluetoothLeBroadcastSourceState.PAUSED).isValid())
        assertTrue(PrivateBroadcastReceiveData(sink, 1, 1, state = LocalBluetoothLeBroadcastSourceState.DECRYPTION_FAILED).isValid())
        assertTrue(PrivateBroadcastReceiveData(sink, 1, 1, state = LocalBluetoothLeBroadcastSourceState.PAUSED_BY_RECEIVER).isValid())
    }

    private companion object {