Skip to content

Commit

Permalink
fix leak
Browse files Browse the repository at this point in the history
  • Loading branch information
storytellerF committed Mar 30, 2023
1 parent f0cb7b4 commit c1eac68
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/src/main/java/com/storyteller_f/fei/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ class MainActivity : ComponentActivity() {
super.onDestroy(owner)
unregisterReceiver(bluetoothStateReceiver)
unRegister(this@MainActivity, hidDevice)
closeBluetoothProfile(bluetoothManager, hidDevice)
}
})
val connectDevice: (String) -> Boolean = { address ->
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/java/com/storyteller_f/fei/ui/components/Hid.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import android.Manifest
import android.bluetooth.BluetoothDevice
import android.bluetooth.BluetoothHidDevice
import android.bluetooth.BluetoothHidDeviceAppSdpSettings
import android.bluetooth.BluetoothManager
import android.bluetooth.BluetoothProfile
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
Expand Down Expand Up @@ -365,3 +367,11 @@ object Dvorak : KeyboardInterfaceInterceptor {
}.joinToString("")
}
}

fun closeBluetoothProfile(
bluetoothManager: BluetoothManager, bluetoothHidDevice: BluetoothHidDevice?
) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
bluetoothManager.adapter.closeProfileProxy(BluetoothProfile.HID_DEVICE, bluetoothHidDevice)
}
}

0 comments on commit c1eac68

Please sign in to comment.