Skip to content

Commit cf01890

Browse files
committed
Fix lint warning: ignore impossible SecurityException
1 parent 27fc09b commit cf01890

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

vector/src/main/java/im/vector/app/core/services/BluetoothHeadsetReceiver.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ import androidx.core.content.ContextCompat
1818
import im.vector.lib.core.utils.compat.getParcelableExtraCompat
1919
import java.lang.ref.WeakReference
2020

21+
/**
22+
* It's only used in API 21 and 22 so we will not have security exception on these OS,
23+
* so it's safe to use @Suppress("MissingPermission")
24+
*/
2125
class BluetoothHeadsetReceiver : BroadcastReceiver() {
2226

2327
interface EventListener {
@@ -53,12 +57,15 @@ class BluetoothHeadsetReceiver : BroadcastReceiver() {
5357
}
5458

5559
val device = intent.getParcelableExtraCompat<BluetoothDevice>(BluetoothDevice.EXTRA_DEVICE)
60+
@Suppress("MissingPermission")
5661
val deviceName = device?.name
62+
@Suppress("MissingPermission")
5763
when (device?.bluetoothClass?.deviceClass) {
5864
BluetoothClass.Device.AUDIO_VIDEO_HANDSFREE,
5965
BluetoothClass.Device.AUDIO_VIDEO_CAR_AUDIO,
6066
BluetoothClass.Device.AUDIO_VIDEO_WEARABLE_HEADSET -> {
6167
// filter only device that we care about for
68+
@Suppress("MissingPermission")
6269
delegate?.get()?.onBTHeadsetEvent(
6370
BTHeadsetPlugEvent(
6471
plugged = headsetConnected,

vector/src/main/java/im/vector/app/features/call/audio/API21AudioDeviceDetector.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ internal class API21AudioDeviceDetector(
4343
return HashSet<CallAudioManager.Device>().apply {
4444
if (isBluetoothHeadsetOn()) {
4545
connectedBlueToothHeadset?.connectedDevices?.forEach {
46+
// Call requires permission which may be rejected by user: code should explicitly
47+
// check to see if permission is available (with checkPermission) or explicitly
48+
// handle a potential SecurityException
49+
// But it should not happen on API 21/22.
50+
@Suppress("MissingPermission")
4651
add(CallAudioManager.Device.WirelessHeadset(it.name))
4752
}
4853
}

0 commit comments

Comments
 (0)