mirror of
https://github.com/permissionlesstech/bitchat-android.git
synced 2026-07-25 05:05:20 +00:00
* try catch the foreground location service if not available * ask for background permissions * background permissions in onboarding * small improvements
42 lines
1.2 KiB
Kotlin
42 lines
1.2 KiB
Kotlin
package com.bitchat.android.mesh
|
|
|
|
import android.Manifest
|
|
import android.content.Context
|
|
import android.content.pm.PackageManager
|
|
import androidx.core.app.ActivityCompat
|
|
|
|
/**
|
|
* Handles all Bluetooth permission checking logic
|
|
*/
|
|
class BluetoothPermissionManager(private val context: Context) {
|
|
|
|
/**
|
|
* Check if all required Bluetooth permissions are granted
|
|
*/
|
|
fun hasBluetoothPermissions(): Boolean {
|
|
val permissions = mutableListOf<String>()
|
|
|
|
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {
|
|
permissions.addAll(listOf(
|
|
Manifest.permission.BLUETOOTH_ADVERTISE,
|
|
Manifest.permission.BLUETOOTH_CONNECT,
|
|
Manifest.permission.BLUETOOTH_SCAN
|
|
))
|
|
} else {
|
|
permissions.addAll(listOf(
|
|
Manifest.permission.BLUETOOTH,
|
|
Manifest.permission.BLUETOOTH_ADMIN
|
|
))
|
|
}
|
|
|
|
permissions.addAll(listOf(
|
|
Manifest.permission.ACCESS_COARSE_LOCATION,
|
|
Manifest.permission.ACCESS_FINE_LOCATION
|
|
))
|
|
|
|
return permissions.all {
|
|
ActivityCompat.checkSelfPermission(context, it) == PackageManager.PERMISSION_GRANTED
|
|
}
|
|
}
|
|
}
|