Skip to content

Commit adb1ae8

Browse files
committed
Provide default Android permissions via kable-default-permissions artifact
1 parent f1f95a4 commit adb1ae8

File tree

5 files changed

+68
-117
lines changed

5 files changed

+68
-117
lines changed

README.md

+8-79
Original file line numberDiff line numberDiff line change
@@ -584,86 +584,13 @@ after initialization will result in an `IllegalStateException` being thrown.
584584

585585
### Android Permissions
586586

587-
Kable [declares permissions for common use cases](kable-core/src/androidMain/AndroidManifest.xml), but your app's
588-
configuration may need to be adjusted under the following conditions:
589-
590-
<table>
591-
<tr>
592-
<td align="center">Your app...</td>
593-
<td align="center"><code>AndroidManifest.xml</code> additions</td>
594-
</tr>
595-
596-
<tr>
597-
<td>
598-
599-
[Obtains the user's location (e.g. maps)](https://developer.android.com/training/location/permissions#foreground)
600-
601-
</td>
602-
<td>
603-
604-
```xml
605-
<uses-permission
606-
android:name="android.permission.ACCESS_COARSE_LOCATION"
607-
tools:node="replace"/>
608-
<uses-permission
609-
android:name="android.permission.ACCESS_FINE_LOCATION"
610-
tools:node="replace"/>
611-
```
612-
613-
</td>
614-
</tr>
615-
616-
<tr>
617-
<td>
618-
619-
[Derives the user's location from Bluetooth Low Energy scans](https://developer.android.com/guide/topics/connectivity/bluetooth/permissions#declare-android12-or-higher)
620-
621-
</td>
622-
<td>
623-
624-
```xml
625-
<uses-permission
626-
android:name="android.permission.BLUETOOTH_SCAN"
627-
tools:node="replace"/>
628-
```
629-
630-
</td>
631-
</tr>
632-
633-
<tr>
634-
<td>
635-
636-
[Performs background Bluetooth Low Energy scans](https://developer.android.com/training/location/permissions#background)
587+
Kable does not declare any permissions; it is expected that the consuming app declares any necessary
588+
permissions. For detailed information on Android Bluetooth permissions, refer to the official
589+
Android Developers guide: [Bluetooth permissions]
637590

638-
</td>
639-
<td>
640-
641-
```xml
642-
<uses-permission
643-
android:name="android.permission.ACCESS_BACKGROUND_LOCATION"
644-
android:maxSdkVersion="30"/>
645-
```
646-
647-
</td>
648-
</tr>
649-
650-
<tr>
651-
<td>
652-
653-
[Requires Bluetooth Low Energy (and won't function without it)](https://developer.android.com/guide/topics/connectivity/bluetooth/permissions#features)
654-
655-
</td>
656-
<td>
657-
658-
```xml
659-
<uses-feature
660-
android:name="android.hardware.bluetooth_le"
661-
android:required="true"/>
662-
```
663-
664-
</td>
665-
</tr>
666-
</table>
591+
> [!TIP]
592+
> For convenience, the `com.juul.kable:kable-default-permissions` Maven artifact may be used to
593+
> provide permissions for common use cases.
667594
668595
### Gradle
669596

@@ -696,6 +623,7 @@ kotlin {
696623

697624
androidMain.dependencies {
698625
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:${coroutinesVersion}")
626+
implementation("com.juul.kable:kable-default-permissions:${kableVersion}") // Optional
699627
}
700628
}
701629
}
@@ -724,6 +652,7 @@ limitations under the License.
724652
```
725653

726654

655+
[Bluetooth permissions]: https://developer.android.com/develop/connectivity/bluetooth/bt-permissions
727656
[Coroutine scope]: https://kotlinlang.org/docs/reference/coroutines/coroutine-context-and-dispatchers.html#coroutine-scope
728657
[Coroutines with multithread support for Kotlin/Native]: https://github.com/Kotlin/kotlinx.coroutines/issues/462
729658
[SensorTag sample app]: https://github.com/JuulLabs/sensortag

kable-core/src/androidMain/AndroidManifest.xml

-38
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,6 @@
44
xmlns:tools="http://schemas.android.com/tools"
55
>
66

7-
<!-- Necessary to perform any Bluetooth classic or BLE communication, such as requesting a
8-
connection, accepting a connection, and transferring data. -->
9-
<uses-permission
10-
android:name="android.permission.BLUETOOTH"
11-
android:maxSdkVersion="30"
12-
/>
13-
<uses-permission
14-
android:name="android.permission.BLUETOOTH_ADMIN"
15-
android:maxSdkVersion="30"
16-
/>
17-
18-
<!-- Not needed for apps targeting Android 9 (API 28) or lower, but there is no `minSdkVersion` attribute. -->
19-
<uses-permission
20-
android:name="android.permission.ACCESS_COARSE_LOCATION"
21-
android:maxSdkVersion="30"
22-
/>
23-
<uses-permission
24-
android:name="android.permission.ACCESS_FINE_LOCATION"
25-
android:maxSdkVersion="30"
26-
/>
27-
28-
<uses-permission
29-
android:name="android.permission.BLUETOOTH_SCAN"
30-
android:usesPermissionFlags="neverForLocation"
31-
tools:targetApi="s"
32-
/>
33-
34-
<!-- Required to call `BluetoothDevice.getName()`, `BluetoothDevice.getBondState()`, `BluetoothGatt.disconnect()`, etc. -->
35-
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
36-
37-
<!-- "If you say the feature is required for your app, then the Google Play store will hide your
38-
app from users on devices lacking those features. For this reason, you should only set the
39-
required attribute to `true` if your app can't work without the feature."
40-
— https://developer.android.com/guide/topics/connectivity/bluetooth/permissions#features
41-
42-
Marked as `false` as Kable shouldn't make this decision for the consuming app. -->
43-
<uses-feature android:name="android.hardware.bluetooth_le" android:required="false"/>
44-
457
<application>
468
<provider
479
android:name="androidx.startup.InitializationProvider"
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
plugins {
2+
id("com.android.library")
3+
kotlin("android")
4+
id("com.vanniktech.maven.publish")
5+
}
6+
7+
kotlin {
8+
jvmToolchain(libs.versions.jvm.toolchain.get().toInt())
9+
}
10+
11+
android {
12+
compileSdk = libs.versions.android.compile.get().toInt()
13+
defaultConfig.minSdk = libs.versions.android.min.get().toInt()
14+
namespace = "com.juul.kable"
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
xmlns:tools="http://schemas.android.com/tools"
5+
>
6+
7+
<!-- Necessary to perform any Bluetooth classic or BLE communication, such as requesting a
8+
connection, accepting a connection, and transferring data. -->
9+
<uses-permission
10+
android:name="android.permission.BLUETOOTH"
11+
android:maxSdkVersion="30"
12+
/>
13+
<uses-permission
14+
android:name="android.permission.BLUETOOTH_ADMIN"
15+
android:maxSdkVersion="30"
16+
/>
17+
18+
<!-- Not needed for apps targeting Android 9 (API 28) or lower, but there is no `minSdkVersion` attribute. -->
19+
<uses-permission
20+
android:name="android.permission.ACCESS_COARSE_LOCATION"
21+
android:maxSdkVersion="30"
22+
/>
23+
<uses-permission
24+
android:name="android.permission.ACCESS_FINE_LOCATION"
25+
android:maxSdkVersion="30"
26+
/>
27+
28+
<uses-permission
29+
android:name="android.permission.BLUETOOTH_SCAN"
30+
android:usesPermissionFlags="neverForLocation"
31+
tools:targetApi="s"
32+
/>
33+
34+
<!-- Required to call `BluetoothDevice.getName()`, `BluetoothDevice.getBondState()`, `BluetoothGatt.disconnect()`, etc. -->
35+
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
36+
37+
<!-- "If you say the feature is required for your app, then the Google Play store will hide your
38+
app from users on devices lacking those features. For this reason, you should only set the
39+
required attribute to `true` if your app can't work without the feature."
40+
— https://developer.android.com/guide/topics/connectivity/bluetooth/permissions#features
41+
42+
Marked as `false` as Kable shouldn't make this decision for the consuming app. -->
43+
<uses-feature android:name="android.hardware.bluetooth_le" android:required="false"/>
44+
</manifest>

settings.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ pluginManagement {
1010

1111
include(
1212
"kable-core",
13+
"kable-default-permissions",
1314
"kable-log-engine-khronicle",
1415
)

0 commit comments

Comments
 (0)