Merge branch 'master' into bluetooth-state-receiver-readability

This commit is contained in:
Kevin Hester 2020-09-19 07:42:50 -07:00 committed by GitHub
commit c1a62097f4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 205 additions and 29 deletions

View file

@ -278,11 +278,18 @@ class MeshService : Service(), Logging {
warnUserAboutLocation()
}
is ApiException ->
if (exception.statusCode == 17) {
// error: cancelled by user
errormsg("User cancelled location access", exception)
} else {
Exceptions.report(exception)
when (exception.statusCode) {
17 ->
// error: cancelled by user
errormsg("User cancelled location access", exception)
8502 ->
// error: settings change unavailable
errormsg(
"Settings-change-unavailable, user disabled location access (globally?)",
exception
)
else ->
Exceptions.report(exception)
}
else ->
Exceptions.report(exception)

View file

@ -10,6 +10,7 @@ import com.geeksville.android.Logging
import com.geeksville.concurrent.CallbackContinuation
import com.geeksville.concurrent.Continuation
import com.geeksville.concurrent.SyncContinuation
import com.geeksville.mesh.android.bluetoothManager
import com.geeksville.util.exceptionReporter
import kotlinx.coroutines.*
import java.io.Closeable
@ -101,10 +102,7 @@ class SafeBluetooth(private val context: Context, private val device: BluetoothD
fun restartBle() {
GeeksvilleApplication.analytics.track("ble_restart") // record # of times we needed to use this nasty hack
errormsg("Doing emergency BLE restart")
val mgr =
context.getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager
val adp = mgr.adapter
if (null != adp) {
context.bluetoothManager?.adapter?.let { adp ->
if (adp.isEnabled) {
adp.disable()
// TODO: display some kind of UI about restarting BLE

View file

@ -7,6 +7,7 @@ import android.content.IntentFilter
import android.hardware.usb.UsbDevice
import android.hardware.usb.UsbManager
import com.geeksville.android.Logging
import com.geeksville.mesh.android.usbManager
import com.geeksville.util.exceptionReporter
import com.geeksville.util.ignoreException
import com.hoho.android.usbserial.driver.UsbSerialDriver
@ -32,8 +33,7 @@ class SerialInterface(private val service: RadioInterfaceService, val address: S
fun toInterfaceName(deviceName: String) = "s$deviceName"
fun findDrivers(context: Context): List<UsbSerialDriver> {
val manager = context.getSystemService(Context.USB_SERVICE) as UsbManager
val drivers = UsbSerialProber.getDefaultProber().findAllDrivers(manager)
val drivers = UsbSerialProber.getDefaultProber().findAllDrivers(context.usbManager)
val devices = drivers.map { it.device }
devices.forEach { d ->
debug("Found serial port ${d.deviceName}")
@ -43,8 +43,7 @@ class SerialInterface(private val service: RadioInterfaceService, val address: S
fun addressValid(context: Context, rest: String): Boolean {
findSerial(context, rest)?.let { d ->
val manager = context.getSystemService(Context.USB_SERVICE) as UsbManager
return assumePermission || manager.hasPermission(d.device)
return assumePermission || context.usbManager.hasPermission(d.device)
}
return false
}
@ -75,8 +74,7 @@ class SerialInterface(private val service: RadioInterfaceService, val address: S
if (UsbManager.ACTION_USB_DEVICE_ATTACHED == intent.action) {
debug("attaching USB")
val device: UsbDevice = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE)!!
val manager = context.getSystemService(Context.USB_SERVICE) as UsbManager
if (assumePermission || manager.hasPermission(device)) {
if (assumePermission || context.usbManager.hasPermission(device)) {
// reinit the port from scratch and reopen
onDeviceDisconnect(true)
connect()