hold new permissions until targetSdkVersion update

1.2-legacy
andrekir 2022-02-09 22:10:25 -03:00
rodzic d429a94e93
commit 64114ce341
3 zmienionych plików z 17 dodań i 3 usunięć

Wyświetl plik

@ -12,16 +12,20 @@
android:name="android.hardware.location.gps"
android:required="false" />
<!-- Request legacy Bluetooth permissions on older devices -->
<!-- TODO - wait for targetSdkVersion 31
&lt;!&ndash; Request legacy Bluetooth permissions on older devices &ndash;&gt;
<uses-permission android:name="android.permission.BLUETOOTH"
android:maxSdkVersion="30" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"
android:maxSdkVersion="30" />
<!-- API 31+ Bluetooth permissions -->
&lt;!&ndash; API 31+ Bluetooth permissions &ndash;&gt;
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN"
android:usesPermissionFlags="neverForLocation" />
-->
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<!-- Permissions required for providing location (from phone GPS) to mesh -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

Wyświetl plik

@ -268,11 +268,14 @@ class MainActivity : AppCompatActivity(), Logging,
// Manifest.permission.WRITE_EXTERNAL_STORAGE
)
/* TODO - wait for targetSdkVersion 31
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
perms.add(Manifest.permission.BLUETOOTH_CONNECT)
} else {
perms.add(Manifest.permission.BLUETOOTH)
}
*/
perms.add(Manifest.permission.BLUETOOTH)
// Some old phones complain about requesting perms they don't understand
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {

Wyświetl plik

@ -35,12 +35,13 @@ fun Context.getMissingPermissions(perms: List<String>) = perms.filter {
fun Context.getConnectPermissions(): List<String> {
val perms = mutableListOf<String>()
/* TODO - wait for targetSdkVersion 31
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
perms.add(Manifest.permission.BLUETOOTH_CONNECT)
} else {
perms.add(Manifest.permission.BLUETOOTH)
}
*/
return getMissingPermissions(perms)
}
@ -53,12 +54,18 @@ fun Context.hasConnectPermission() = getConnectPermissions().isEmpty()
fun Context.getScanPermissions(): List<String> {
val perms = mutableListOf<String>()
/* TODO - wait for targetSdkVersion 31
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
perms.add(Manifest.permission.BLUETOOTH_SCAN)
} else if (!BluetoothInterface.hasCompanionDeviceApi(this)) {
perms.add(Manifest.permission.ACCESS_FINE_LOCATION)
perms.add(Manifest.permission.BLUETOOTH_ADMIN)
}
*/
if (!BluetoothInterface.hasCompanionDeviceApi(this)) {
perms.add(Manifest.permission.ACCESS_FINE_LOCATION)
perms.add(Manifest.permission.BLUETOOTH_ADMIN)
}
return getMissingPermissions(perms)
}