mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
WIP - work with background location being optional
This commit is contained in:
parent
e0bbbb3c14
commit
9c1316ea09
5 changed files with 105 additions and 66 deletions
|
|
@ -1,9 +1,13 @@
|
|||
package com.geeksville.mesh.android
|
||||
|
||||
import android.Manifest
|
||||
import android.app.NotificationManager
|
||||
import android.bluetooth.BluetoothManager
|
||||
import android.content.Context
|
||||
import android.content.pm.PackageManager
|
||||
import android.hardware.usb.UsbManager
|
||||
import android.os.Build
|
||||
import androidx.core.content.ContextCompat
|
||||
|
||||
/**
|
||||
* @return null on platforms without a BlueTooth driver (i.e. the emulator)
|
||||
|
|
@ -13,3 +17,28 @@ val Context.bluetoothManager: BluetoothManager? get() = getSystemService(Context
|
|||
val Context.usbManager: UsbManager get() = requireNotNull(getSystemService(Context.USB_SERVICE) as? UsbManager?) { "USB_SERVICE is not available"}
|
||||
|
||||
val Context.notificationManager: NotificationManager get() = requireNotNull(getSystemService(Context.NOTIFICATION_SERVICE) as? NotificationManager?)
|
||||
|
||||
/**
|
||||
* return a list of the permissions we don't have
|
||||
*/
|
||||
fun Context.getMissingPermissions(perms: List<String>) = perms.filter {
|
||||
ContextCompat.checkSelfPermission(
|
||||
this,
|
||||
it
|
||||
) != PackageManager.PERMISSION_GRANTED
|
||||
}
|
||||
|
||||
/**
|
||||
* A list of missing background location permissions (or empty if we already have what we need)
|
||||
*/
|
||||
fun Context.getBackgroundPermissions(): List<String> {
|
||||
val perms = mutableListOf<String>()
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 29) // only added later
|
||||
perms.add(Manifest.permission.ACCESS_BACKGROUND_LOCATION)
|
||||
|
||||
return getMissingPermissions(perms)
|
||||
}
|
||||
|
||||
/** @return true if the user already has background location permission */
|
||||
fun Context.hasBackgroundPermission() = getBackgroundPermissions().isEmpty()
|
||||
Loading…
Add table
Add a link
Reference in a new issue