package com.rtnbleserver import android.Manifest import android.content.Context import android.content.pm.PackageManager import android.os.Build internal object BluetoothPermissions { /** Permissions needed to advertise a GATT server. */ fun serverGranted(context: Context): Boolean { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) { return true } return granted(context, Manifest.permission.BLUETOOTH_CONNECT) && granted(context, Manifest.permission.BLUETOOTH_ADVERTISE) } /** Permissions needed to scan for and connect to a GATT server. */ fun clientGranted(context: Context): Boolean { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { return granted(context, Manifest.permission.BLUETOOTH_SCAN) && granted(context, Manifest.permission.BLUETOOTH_CONNECT) } return granted(context, Manifest.permission.ACCESS_FINE_LOCATION) } private fun granted(context: Context, permission: String): Boolean { return context.checkSelfPermission(permission) == PackageManager.PERMISSION_GRANTED } }