simplified calls to system services

and fixed some code that assumed BluetoothManager to never be NULL
This commit is contained in:
Ken Van Hoeylandt 2020-09-17 19:49:50 +02:00
parent b98a8ea34b
commit f97bc21719
4 changed files with 22 additions and 15 deletions

View file

@ -0,0 +1,12 @@
package com.geeksville.mesh.android
import android.bluetooth.BluetoothManager
import android.content.Context
import android.hardware.usb.UsbManager
/**
* @return null on platforms without a BlueTooth driver (i.e. the emulator)
*/
val Context.bluetoothManager: BluetoothManager? get() = getSystemService(Context.BLUETOOTH_SERVICE) as? BluetoothManager?
val Context.usbManager: UsbManager get() = requireNotNull(getSystemService(Context.USB_SERVICE) as? UsbManager) { "USB_SERVICE is not available"}