Skip to content

Commit 8f25a9c

Browse files
author
John Qualls
authored
Add default bluetooth device name (#23)
* Add default bluetooth device name if null is returned from the Android BluetoothDevice class * Update changelog * Change constant name with default prefix
1 parent e6c96d5 commit 8f25a9c

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
### 0.1.3
4+
5+
Bug Fixes
6+
7+
- Fixed crash by adding a default bluetooth device name.
8+
39
### 0.1.2
410

511
Enhancements

audioswitch/src/main/java/com/twilio/audioswitch/android/BluetoothDeviceWrapperImpl.kt

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ package com.twilio.audioswitch.android
22

33
import android.bluetooth.BluetoothDevice
44

5+
internal const val DEFAULT_DEVICE_NAME = "Bluetooth"
6+
57
internal class BluetoothDeviceWrapperImpl(
68
private val device: BluetoothDevice,
7-
override val name: String = device.name,
9+
override val name: String = device.name ?: DEFAULT_DEVICE_NAME,
810
override val deviceClass: Int? = device.bluetoothClass?.deviceClass
911
) : BluetoothDeviceWrapper

audioswitch/src/test/java/com/twilio/audioswitch/selection/AudioDeviceSelectorTest.kt

+14
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ import com.nhaarman.mockitokotlin2.verify
1616
import com.nhaarman.mockitokotlin2.verifyZeroInteractions
1717
import com.nhaarman.mockitokotlin2.whenever
1818
import com.twilio.audioswitch.android.BluetoothDeviceWrapper
19+
import com.twilio.audioswitch.android.BluetoothDeviceWrapperImpl
1920
import com.twilio.audioswitch.selection.AudioDeviceSelector.State.ACTIVATED
2021
import com.twilio.audioswitch.selection.AudioDeviceSelector.State.STARTED
2122
import com.twilio.audioswitch.selection.AudioDeviceSelector.State.STOPPED
2223
import com.twilio.audioswitch.android.BuildWrapper
24+
import com.twilio.audioswitch.android.DEFAULT_DEVICE_NAME
2325
import com.twilio.audioswitch.android.LogWrapper
2426
import com.twilio.audioswitch.bluetooth.BluetoothController
2527
import com.twilio.audioswitch.bluetooth.BluetoothControllerAssertions
@@ -76,6 +78,18 @@ class AudioDeviceSelectorTest {
7678
)
7779
private val bluetoothControllerAssertions = BluetoothControllerAssertions()
7880

81+
@Test
82+
fun `availableAudioDevices should return a generic bluetooth device name if none was returned from the BluetoothDevice class`() {
83+
audioDeviceSelector.start(audioDeviceChangeListener)
84+
audioDeviceSelector.bluetoothDeviceConnectionListener.onBluetoothConnected(
85+
BluetoothDeviceWrapperImpl(mock()))
86+
87+
val hasDefaultDeviceName = audioDeviceSelector.availableAudioDevices.any {
88+
it.name == DEFAULT_DEVICE_NAME
89+
}
90+
assertThat(hasDefaultDeviceName, equalTo(true))
91+
}
92+
7993
@Test
8094
fun `start should start the bluetooth and wired headset listeners`() {
8195
audioDeviceSelector.start(audioDeviceChangeListener)

0 commit comments

Comments
 (0)