permissions-dispatcher / PermissionsDispatcher

A declarative API to handle Android runtime permissions.
https://github.com/permissions-dispatcher/PermissionsDispatcher
Apache License 2.0
11.21k stars 1.44k forks source link

ACCESS_BACKGROUND_LOCATION permission has issue when API less than Android Q #646

Open TankJK opened 4 years ago

TankJK commented 4 years ago

FAQs


Overview

ACCESS_BACKGROUND_LOCATION is not handled for Android API less than 29.

Compile and target SDK 29 From Android Q, special permission is required for accessing location in background. This did works well for Android Q but when its less than Android Q, even though user has given Allow permission for location, it consider failure (deny) for ACCESS_BACKGROUND_LOCATION

Expected

Actual

Environment

Reproducible steps

Please guide.

Thanking you in advance, TankJK

hotchemi commented 4 years ago

@TankJK I'm afraid it's not related to our library. Have you tried below?

Allows an app to access location in the background. If you're requesting this permission, you must also request either ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION. Requesting this permission by itself doesn't give you location access.

https://developer.android.com/reference/android/Manifest.permission#ACCESS_BACKGROUND_LOCATION

TankJK commented 4 years ago

@hotchemi Yes all permission is been added.

hotchemi commented 4 years ago

@TankJK really? I wonder because ACCESS_BACKGROUND_LOCATION is from API level 29?

TankJK commented 4 years ago

@hotchemi App all permission: ACCESS_COARSE_LOCATION ACCESS_FINE_LOCATION ACCESS_BACKGROUND_LOCATION

If it's API below 29, simply Allow should give all three permissions. While in 29, users have 2 choices:

  1. While using app (which is ACCESS_FINE_LOCATION)
  2. Allow all the time (which is ACCESS_FINE_LOCATION + ACCESS_BACKGROUND_LOCATION)

But problem occurs when API is less then 29 as described in issue.

hotchemi commented 4 years ago

we'll take a look

hotchemi commented 4 years ago

@TankJK thank you we could replicate the issue.

Actually the root cause is ACCESS_BACKGROUND_LOCATION doesn't exist but you request the permission to Android and it always return -1(DENIED). Kind of obvious but this can be an improvement point for our library, let us think a bit.

A quick workaround is like below on your side.

@NeedsPermission(Manifest.permission.ACCESS_FINE_LOCATION)
fun method1() = TODO

@RequiresApi(api = Build.VERSION_CODES.Q)
@NeedsPermission(Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_BACKGROUND_LOCATION)
fun method2() = TODO

fun test() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
            method2WithPermissionCheck()
        } else {
            method1WithPermissionCheck()
        }
}

Ref:

lumina0o0 commented 4 years ago

I also encountered the same problem {Manifest.permission.ACTIVITY_RECOGNITION} This permission is added after api29 and cannot be run in lower versions Looking forward to your updates

wilder-ness commented 4 years ago

问题。。回调了怎么办。 请求权限分成2个方法。回调的时候

多的这个权限回调在哪执行 OnPermissionDenied 这个会生成2组回调么 我这里 只生成了一组

prash6001 commented 4 years ago

@TankJK thank you we could replicate the issue.

Actually the root cause is ACCESS_BACKGROUND_LOCATION doesn't exist but you request the permission to Android and it always return -1(DENIED). Kind of obvious but this can be an improvement point for our library, let us think a bit.

A quick workaround is like below on your side.

@NeedsPermission(Manifest.permission.ACCESS_FINE_LOCATION)
fun method1() = TODO

@RequiresApi(api = Build.VERSION_CODES.Q)
@NeedsPermission(Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_BACKGROUND_LOCATION)
fun method2() = TODO

fun test() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
            method2WithPermissionCheck()
        } else {
            method1WithPermissionCheck()
        }
}

Ref:

I have used this code for requesting the background location and it works as expected but what if I want to check if user has denied the background location permission by selecting "ALLOW ONLY WHILE USING THE APP"? I am trying to use @OnPermissionDenied(Manifest.permission.ACCESS_BACKGROUND_LOCATION) but library doesn't create the dispatcher method and not getting the callback. Please suggest some solution.

DengFX2010105421 commented 4 years ago

and READ_PHONE_STATE the same. i have allowed READ_PHONE_STATE permission,but it still crashed,with exception: java.lang.RuntimeException: Failure delivering result ResultInfo{who=@android:requestPermissions:, request=0, result=-1, data=Intent { act=android.content.pm.action.REQUEST_PERMISSIONS (has extras) }} to activity {com.centchain.changyo.speeder/com.centchain.changyo.ui.SpeederActivity}: java.lang.SecurityException: getUniqueDeviceId: The user 10452 does not meet the requirements to access device identifiers.

hotchemi commented 3 years ago

JFYI now we're considering to prep a dedicated method in ktx module: https://github.com/permissions-dispatcher/PermissionsDispatcher/pull/679

@DengFX2010105421 do you mean READ_PHONE_NUMBERS from Android 11? https://developer.android.com/preview/privacy/permissions#phone-numbers

look1n commented 2 years ago

Same issue for ACCESS_MEDIA_LOCATION permission introduced in API level 29.

Feature request: ability to specify API level for each requested permission inside "@NeedsPermission" annotation.