mirror of
https://github.com/TeamVanced/VancedMicroG
synced 2024-12-29 06:05:47 +01:00
EN: Add methods to check if advertising/scanning is supported by device
This commit is contained in:
parent
00a8e83540
commit
f7190091af
@ -232,5 +232,31 @@ class AdvertiserService : LifecycleService() {
|
||||
fun isNeeded(context: Context): Boolean {
|
||||
return ExposurePreferences(context).enabled
|
||||
}
|
||||
|
||||
fun isSupported(context: Context): Boolean? {
|
||||
val adapter = BluetoothAdapter.getDefaultAdapter()
|
||||
return when {
|
||||
adapter == null -> {
|
||||
Log.d(TAG, "LE advertising not supported via adapter")
|
||||
false
|
||||
}
|
||||
Build.VERSION.SDK_INT >= 26 && (adapter.isLeExtendedAdvertisingSupported || adapter.isLePeriodicAdvertisingSupported) -> {
|
||||
Log.d(TAG, "LE advertising supported via feature")
|
||||
true
|
||||
}
|
||||
adapter.state != BluetoothAdapter.STATE_ON -> {
|
||||
Log.d(TAG, "LE advertising unknown via state")
|
||||
null
|
||||
}
|
||||
adapter.bluetoothLeAdvertiser != null -> {
|
||||
Log.d(TAG, "LE advertising supported via advertiser")
|
||||
true
|
||||
}
|
||||
else -> {
|
||||
Log.d(TAG, "LE advertising not supported via advertiser")
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import android.annotation.TargetApi
|
||||
import android.app.AlarmManager
|
||||
import android.app.PendingIntent
|
||||
import android.app.Service
|
||||
import android.bluetooth.BluetoothAdapter
|
||||
import android.bluetooth.BluetoothAdapter.*
|
||||
import android.bluetooth.le.*
|
||||
import android.content.BroadcastReceiver
|
||||
@ -171,5 +172,31 @@ class ScannerService : LifecycleService() {
|
||||
fun isNeeded(context: Context): Boolean {
|
||||
return ExposurePreferences(context).enabled
|
||||
}
|
||||
|
||||
fun isSupported(context: Context): Boolean? {
|
||||
if (AdvertiserService.isSupported(context) == true) {
|
||||
Log.d(TAG, "LE scanning supported via advertiser")
|
||||
return true
|
||||
}
|
||||
val adapter = BluetoothAdapter.getDefaultAdapter()
|
||||
return when {
|
||||
adapter == null -> {
|
||||
Log.d(TAG, "LE scanning not supported via adapter")
|
||||
false
|
||||
}
|
||||
adapter.state != BluetoothAdapter.STATE_ON -> {
|
||||
Log.d(TAG, "LE scanning unknown via state")
|
||||
null
|
||||
}
|
||||
adapter.bluetoothLeScanner != null -> {
|
||||
Log.d(TAG, "LE scanning supported via scanner")
|
||||
true
|
||||
}
|
||||
else -> {
|
||||
Log.d(TAG, "LE scanning not supported via scanner")
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user