Fix lint warning: ignore impossible SecurityException
This commit is contained in:
parent
27fc09bb8a
commit
cf01890e3a
@ -18,6 +18,10 @@ import androidx.core.content.ContextCompat
|
|||||||
import im.vector.lib.core.utils.compat.getParcelableExtraCompat
|
import im.vector.lib.core.utils.compat.getParcelableExtraCompat
|
||||||
import java.lang.ref.WeakReference
|
import java.lang.ref.WeakReference
|
||||||
|
|
||||||
|
/**
|
||||||
|
* It's only used in API 21 and 22 so we will not have security exception on these OS,
|
||||||
|
* so it's safe to use @Suppress("MissingPermission")
|
||||||
|
*/
|
||||||
class BluetoothHeadsetReceiver : BroadcastReceiver() {
|
class BluetoothHeadsetReceiver : BroadcastReceiver() {
|
||||||
|
|
||||||
interface EventListener {
|
interface EventListener {
|
||||||
@ -53,12 +57,15 @@ class BluetoothHeadsetReceiver : BroadcastReceiver() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val device = intent.getParcelableExtraCompat<BluetoothDevice>(BluetoothDevice.EXTRA_DEVICE)
|
val device = intent.getParcelableExtraCompat<BluetoothDevice>(BluetoothDevice.EXTRA_DEVICE)
|
||||||
|
@Suppress("MissingPermission")
|
||||||
val deviceName = device?.name
|
val deviceName = device?.name
|
||||||
|
@Suppress("MissingPermission")
|
||||||
when (device?.bluetoothClass?.deviceClass) {
|
when (device?.bluetoothClass?.deviceClass) {
|
||||||
BluetoothClass.Device.AUDIO_VIDEO_HANDSFREE,
|
BluetoothClass.Device.AUDIO_VIDEO_HANDSFREE,
|
||||||
BluetoothClass.Device.AUDIO_VIDEO_CAR_AUDIO,
|
BluetoothClass.Device.AUDIO_VIDEO_CAR_AUDIO,
|
||||||
BluetoothClass.Device.AUDIO_VIDEO_WEARABLE_HEADSET -> {
|
BluetoothClass.Device.AUDIO_VIDEO_WEARABLE_HEADSET -> {
|
||||||
// filter only device that we care about for
|
// filter only device that we care about for
|
||||||
|
@Suppress("MissingPermission")
|
||||||
delegate?.get()?.onBTHeadsetEvent(
|
delegate?.get()?.onBTHeadsetEvent(
|
||||||
BTHeadsetPlugEvent(
|
BTHeadsetPlugEvent(
|
||||||
plugged = headsetConnected,
|
plugged = headsetConnected,
|
||||||
|
|||||||
@ -43,6 +43,11 @@ internal class API21AudioDeviceDetector(
|
|||||||
return HashSet<CallAudioManager.Device>().apply {
|
return HashSet<CallAudioManager.Device>().apply {
|
||||||
if (isBluetoothHeadsetOn()) {
|
if (isBluetoothHeadsetOn()) {
|
||||||
connectedBlueToothHeadset?.connectedDevices?.forEach {
|
connectedBlueToothHeadset?.connectedDevices?.forEach {
|
||||||
|
// Call requires permission which may be rejected by user: code should explicitly
|
||||||
|
// check to see if permission is available (with checkPermission) or explicitly
|
||||||
|
// handle a potential SecurityException
|
||||||
|
// But it should not happen on API 21/22.
|
||||||
|
@Suppress("MissingPermission")
|
||||||
add(CallAudioManager.Device.WirelessHeadset(it.name))
|
add(CallAudioManager.Device.WirelessHeadset(it.name))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user