Skip to content

Commit ec4c235

Browse files
authored
Merge pull request #112 from ZiXOps/task/add-background-location-permission
Add BACKGROUND_LOCATION Permission
2 parents 42ade68 + 24664f6 commit ec4c235

File tree

6 files changed

+22
-1
lines changed

6 files changed

+22
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ The full list can be found in `dev.icerock.moko.permissions.Permission` enum.
5858
* Storage write: **Permission.WRITE_STORAGE**
5959
* Fine location: **Permission.LOCATION**
6060
* Coarse location: **Permission.COARSE_LOCATION**
61+
* Background location: **Permission.BACKGROUND_LOCATION**
6162
* Remote notifications: **Permission.REMOTE_NOTIFICATION**
6263
* Audio recording: **Permission.RECORD_AUDIO**
6364
* Bluetooth LE: **Permission.BLUETOOTH_LE**

permissions/src/androidMain/kotlin/dev/icerock/moko/permissions/PermissionsControllerImpl.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ class PermissionsControllerImpl(
144144
Permission.WRITE_STORAGE -> listOf(Manifest.permission.WRITE_EXTERNAL_STORAGE)
145145
Permission.LOCATION -> fineLocationCompat()
146146
Permission.COARSE_LOCATION -> listOf(Manifest.permission.ACCESS_COARSE_LOCATION)
147+
Permission.BACKGROUND_LOCATION -> backgroundLocationCompat()
147148
Permission.REMOTE_NOTIFICATION -> remoteNotificationsPermissions()
148149
Permission.RECORD_AUDIO -> listOf(Manifest.permission.RECORD_AUDIO)
149150
Permission.BLUETOOTH_LE -> allBluetoothPermissions()
@@ -192,6 +193,22 @@ class PermissionsControllerImpl(
192193
listOf(Manifest.permission.ACCESS_FINE_LOCATION)
193194
}
194195

196+
private fun backgroundLocationCompat() =
197+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
198+
listOf(
199+
Manifest.permission.ACCESS_FINE_LOCATION,
200+
Manifest.permission.ACCESS_COARSE_LOCATION,
201+
Manifest.permission.ACCESS_BACKGROUND_LOCATION,
202+
)
203+
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
204+
listOf(
205+
Manifest.permission.ACCESS_FINE_LOCATION,
206+
Manifest.permission.ACCESS_BACKGROUND_LOCATION,
207+
)
208+
} else {
209+
listOf(Manifest.permission.ACCESS_FINE_LOCATION)
210+
}
211+
195212
/**
196213
* Bluetooth permissions
197214
*

permissions/src/commonMain/kotlin/dev/icerock/moko/permissions/Permission.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ enum class Permission {
1111
WRITE_STORAGE,
1212
LOCATION,
1313
COARSE_LOCATION,
14+
BACKGROUND_LOCATION,
1415
BLUETOOTH_LE,
1516
REMOTE_NOTIFICATION,
1617
RECORD_AUDIO,

permissions/src/iosMain/kotlin/dev/icerock/moko/permissions/ios/PermissionsController.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class PermissionsController : PermissionsControllerProtocol {
4141
Permission.CAMERA -> AVCapturePermissionDelegate(AVMediaTypeVideo, permission)
4242
Permission.GALLERY -> GalleryPermissionDelegate()
4343
Permission.STORAGE, Permission.WRITE_STORAGE -> AlwaysGrantedPermissionDelegate()
44-
Permission.LOCATION, Permission.COARSE_LOCATION ->
44+
Permission.LOCATION, Permission.COARSE_LOCATION, Permission.BACKGROUND_LOCATION ->
4545
LocationPermissionDelegate(locationManagerDelegate, permission)
4646

4747
Permission.RECORD_AUDIO -> AVCapturePermissionDelegate(AVMediaTypeAudio, permission)

sample/android-app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
1414
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
1515
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
16+
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
1617
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
1718
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
1819
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO"/>

sample/compose-android-app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
1414
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
1515
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
16+
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
1617
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
1718

1819
<application

0 commit comments

Comments
 (0)