fluttercandies / flutter_photo_manager

A Flutter plugin that provides images, videos, and audio abstraction management APIs without interface integration, available on Android, iOS, macOS and OpenHarmony.
https://pub.dev/packages/photo_manager
Apache License 2.0
693 stars 314 forks source link

[BUG] Android SDK 33 `requestPermissionExtend` always returns PermissionState.authorized #842

Closed 1N50MN14 closed 2 years ago

1N50MN14 commented 2 years ago

Describe the bug PhotoManager.requestPermissionExtend() always immediately returns PermissionState.authorized without awaiting for the future to resolve, irrelevant the user allowing or disallowing access. It triggers the permission dialog and resolves immediately without awaiting user input. In the case of user denying access, the method still returns PermissionState.authorized as well.

The implications of that, in my case, is wechat_assets_picker (which depends on this package) throwing a PlatformException(Request for permission failed., User denied permission., null, null) which causes the app to crash and there's no way to avoid that by not displaying the picker in case of denied permissions as requestPermissionExtend() always returns PermissionState.authorized.

To Reproduce Steps to reproduce the behavior:

  1. Run the example app
  2. Click on the galley floating icon
  3. Deny access
  4. Tap the gallery floating icon again and pay attention to the PermissionState log, it will print out authorized. Also pay attention to the fact the log prints out even before the permission dialog gets dismissed.

Expected behavior

  1. PhotoManager.requestPermissionExtend() should wait user permission selection
  2. PhotoManager.requestPermissionExtend() should return the correct permission state

Flutter version 3.3.

Smartphone (please complete the following information):

AlexV525 commented 2 years ago

I've checked the example that it does throws, ~but not seeing the immediately return behavior~.

1N50MN14 commented 2 years ago

Yes, in addition to the above ideally it should be possible to handle the exception or at least catch it so it doesn't impact the app in production (in case of user error, i.e. developer forgetting to check for permissions before displaying the picker). Thank you for looking into it.

AlexV525 commented 2 years ago

Some design issues are exposed here. In summary, requestPermissionExtended checks required permissions, but in Android 33, those permissions are not always necessary. Such as I've added images, video, and audio permissions in the manifest, but I can only request images and video in the runtime. That will cause an illusion that the request will be made without RequestType, and returns denied once you have any permissions denied that are declared in the manifest.

AlexV525 commented 2 years ago

That will cause an illusion that the request will be made without RequestType, and returns denied once you have any permissions denied that are declared in the manifest.

But I'll go for this implementation first, and we can make further improvements once we had one.

1N50MN14 commented 2 years ago

@AlexV525 I'm getting a build error with 2.4.0-dev.3, FYI, here's the full log

Launching lib/main.dart on sdk gphone64 x86 64 in debug mode...
lib/main.dart:1
e: /home/am/Applications/flutter/.pub-cache/hosted/pub.dartlang.org/photo_manager-2.3.0/android/src/main/kotlin/com/fluttercandies/photo_manager/constant/Methods.kt: (3, 7): Redeclaration: Methods
e: /home/am/Applications/flutter/.pub-cache/hosted/pub.dartlang.org/photo_manager-2.3.0/android/src/main/kotlin/com/fluttercandies/photo_manager/core/PhotoManager.kt: (21, 7): Redeclaration: PhotoManager
e: /home/am/Applications/flutter/.pub-cache/hosted/pub.dartlang.org/photo_manager-2.3.0/android/src/main/kotlin/com/fluttercandies/photo_manager/core/PhotoManagerPlugin.kt: (28, 7): Redeclaration: PhotoManagerPlugin
e: /home/am/Applications/flutter/.pub-cache/hosted/pub.dartlang.org/photo_manager-2.3.0/android/src/main/kotlin/com/fluttercandies/photo_manager/core/utils/AndroidQDBUtils.kt: (30, 8): Redeclaration: AndroidQDBUtils
e: /home/am/Applications/flutter/.pub-cache/hosted/pub.dartlang.org/photo_manager-2.3.0/android/src/main/kotlin/com/fluttercandies/photo_manager/core/utils/AndroidQDBUtils.kt: (337, 43): Overload resolution ambiguity:
public fun InputStream.getOrientationDegrees(): Int defined in com.fluttercandies.photo_manager.core.utils in file CommonExt.kt
public fun InputStream.getOrientationDegrees(): Int defined in com.fluttercandies.photo_manager.core.utils in file CommonExt.kt
e: /home/am/Applications/flutter/.pub-cache/hosted/pub.dartlang.org/photo_manager-2.3.0/android/src/main/kotlin/com/fluttercandies/photo_manager/core/utils/AndroidQDBUtils.kt: (359, 13): Overload resolution ambiguity:
public open fun put(p0: String!, p1: Boolean!): Unit defined in android.content.ContentValues
public open fun put(p0: String!, p1: Byte!): Unit defined in android.content.ContentValues
public open fun put(p0: String!, p1: ByteArray!): Unit defined in android.content.ContentValues
public open fun put(p0: String!, p1: Double!): Unit defined in android.content.ContentValues
public open fun put(p0: String!, p1: Float!): Unit defined in android.content.ContentValues
public open fun put(p0: String!, p1: Int!): Unit defined in android.content.ContentValues
public open fun put(p0: String!, p1: Long!): Unit defined in android.content.ContentValues
public open fun put(p0: String!, p1: Short!): Unit defined in android.content.ContentValues
public open fun put(p0: String!, p1: String!): Unit defined in android.content.ContentValues
e: /home/am/Applications/flutter/.pub-cache/hosted/pub.dartlang.org/photo_manager-2.3.0/android/src/main/kotlin/com/fluttercandies/photo_manager/core/utils/AndroidQDBUtils.kt: (383, 14): Overload resolution ambiguity:
2
public fun String.checkDirs(): Unit defined in com.fluttercandies.photo_manager.core.utils in file CommonExt.kt
e: /home/am/Applications/flutter/.pub-cache/hosted/pub.dartlang.org/photo_manager-2.3.0/android/src/main/kotlin/com/fluttercandies/photo_manager/core/utils/AndroidQDBUtils.kt: (397, 43): Overload resolution ambiguity:
2
public fun InputStream.getOrientationDegrees(): Int defined in com.fluttercandies.photo_manager.core.utils in file CommonExt.kt
e: /home/am/Applications/flutter/.pub-cache/hosted/pub.dartlang.org/photo_manager-2.3.0/android/src/main/kotlin/com/fluttercandies/photo_manager/core/utils/AndroidQDBUtils.kt: (412, 13): Overload resolution ambiguity:
public open fun put(p0: String!, p1: Boolean!): Unit defined in android.content.ContentValues
public open fun put(p0: String!, p1: Byte!): Unit defined in android.content.ContentValues
public open fun put(p0: String!, p1: ByteArray!): Unit defined in android.content.ContentValues
public open fun put(p0: String!, p1: Double!): Unit defined in android.content.ContentValues
public open fun put(p0: String!, p1: Float!): Unit defined in android.content.ContentValues
public open fun put(p0: String!, p1: Int!): Unit defined in android.content.ContentValues
public open fun put(p0: String!, p1: Long!): Unit defined in android.content.ContentValues
public open fun put(p0: String!, p1: Short!): Unit defined in android.content.ContentValues
public open fun put(p0: String!, p1: String!): Unit defined in android.content.ContentValues
e: /home/am/Applications/flutter/.pub-cache/hosted/pub.dartlang.org/photo_manager-2.3.0/android/src/main/kotlin/com/fluttercandies/photo_manager/core/utils/AndroidQDBUtils.kt: (620, 14): Overload resolution ambiguity:
2
public fun String.checkDirs(): Unit defined in com.fluttercandies.photo_manager.core.utils in file CommonExt.kt
e: /home/am/Applications/flutter/.pub-cache/hosted/pub.dartlang.org/photo_manager-2.3.0/android/src/main/kotlin/com/fluttercandies/photo_manager/core/utils/AndroidQDBUtils.kt: (628, 43): Overload resolution ambiguity:
2
public fun InputStream.getOrientationDegrees(): Int defined in com.fluttercandies.photo_manager.core.utils in file CommonExt.kt
e: /home/am/Applications/flutter/.pub-cache/hosted/pub.dartlang.org/photo_manager-2.3.0/android/src/main/kotlin/com/fluttercandies/photo_manager/core/utils/AndroidQDBUtils.kt: (650, 13): Overload resolution ambiguity:
public open fun put(p0: String!, p1: Boolean!): Unit defined in android.content.ContentValues
public open fun put(p0: String!, p1: Byte!): Unit defined in android.content.ContentValues
public open fun put(p0: String!, p1: ByteArray!): Unit defined in android.content.ContentValues
public open fun put(p0: String!, p1: Double!): Unit defined in android.content.ContentValues
public open fun put(p0: String!, p1: Float!): Unit defined in android.content.ContentValues
public open fun put(p0: String!, p1: Int!): Unit defined in android.content.ContentValues
public open fun put(p0: String!, p1: Long!): Unit defined in android.content.ContentValues
public open fun put(p0: String!, p1: Short!): Unit defined in android.content.ContentValues
public open fun put(p0: String!, p1: String!): Unit defined in android.content.ContentValues
e: /home/am/Applications/flutter/.pub-cache/hosted/pub.dartlang.org/photo_manager-2.3.0/android/src/main/kotlin/com/fluttercandies/photo_manager/core/utils/CommonExt.kt: (12, 1): Conflicting overloads: public fun String.checkDirs(): Unit defined in com.fluttercandies.photo_manager.core.utils in file CommonExt.kt, public fun String.checkDirs(): Unit defined in com.fluttercandies.photo_manager.core.utils in file CommonExt.kt
e: /home/am/Applications/flutter/.pub-cache/hosted/pub.dartlang.org/photo_manager-2.3.0/android/src/main/kotlin/com/fluttercandies/photo_manager/core/utils/CommonExt.kt: (19, 1): Conflicting overloads: public fun InputStream.getOrientationDegrees(): Int defined in com.fluttercandies.photo_manager.core.utils in file CommonExt.kt, public fun InputStream.getOrientationDegrees(): Int defined in com.fluttercandies.photo_manager.core.utils in file CommonExt.kt
e: /home/am/Applications/flutter/.pub-cache/hosted/pub.dartlang.org/photo_manager-2.3.0/android/src/main/kotlin/com/fluttercandies/photo_manager/core/utils/IDBUtils.kt: (22, 11): Redeclaration: IDBUtils
e: /home/am/Applications/flutter/.pub-cache/hosted/pub.dartlang.org/photo_manager-2.3.0/android/src/main/kotlin/com/fluttercandies/photo_manager/permission/PermissionsUtils.kt: (25, 7): Redeclaration: PermissionsUtils
e: /home/am/Applications/flutter/.pub-cache/hosted/pub.dartlang.org/photo_manager-2.3.0/android/src/main/kotlin/com/fluttercandies/photo_manager/util/LogUtils.kt: (8, 8): Redeclaration: LogUtils
e: /home/am/Applications/flutter/.pub-cache/hosted/pub.dartlang.org/photo_manager-2.4.0-dev.3/android/src/main/kotlin/com/fluttercandies/photo_manager/constant/Methods.kt: (3, 7): Redeclaration: Methods
e: /home/am/Applications/flutter/.pub-cache/hosted/pub.dartlang.org/photo_manager-2.4.0-dev.3/android/src/main/kotlin/com/fluttercandies/photo_manager/core/PhotoManager.kt: (21, 7): Redeclaration: PhotoManager
e: /home/am/Applications/flutter/.pub-cache/hosted/pub.dartlang.org/photo_manager-2.4.0-dev.3/android/src/main/kotlin/com/fluttercandies/photo_manager/core/PhotoManagerPlugin.kt: (27, 7): Redeclaration: PhotoManagerPlugin
e: /home/am/Applications/flutter/.pub-cache/hosted/pub.dartlang.org/photo_manager-2.4.0-dev.3/android/src/main/kotlin/com/fluttercandies/photo_manager/core/utils/AndroidQDBUtils.kt: (31, 8): Redeclaration: AndroidQDBUtils
e: /home/am/Applications/flutter/.pub-cache/hosted/pub.dartlang.org/photo_manager-2.4.0-dev.3/android/src/main/kotlin/com/fluttercandies/photo_manager/core/utils/AndroidQDBUtils.kt: (355, 43): Overload resolution ambiguity:
2
public fun InputStream.getOrientationDegrees(): Int defined in com.fluttercandies.photo_manager.core.utils in file CommonExt.kt
e: /home/am/Applications/flutter/.pub-cache/hosted/pub.dartlang.org/photo_manager-2.4.0-dev.3/android/src/main/kotlin/com/fluttercandies/photo_manager/core/utils/AndroidQDBUtils.kt: (380, 13): Overload resolution ambiguity:
public open fun put(p0: String!, p1: Boolean!): Unit defined in android.content.ContentValues
public open fun put(p0: String!, p1: Byte!): Unit defined in android.content.ContentValues
public open fun put(p0: String!, p1: ByteArray!): Unit defined in android.content.ContentValues
public open fun put(p0: String!, p1: Double!): Unit defined in android.content.ContentValues
public open fun put(p0: String!, p1: Float!): Unit defined in android.content.ContentValues
public open fun put(p0: String!, p1: Int!): Unit defined in android.content.ContentValues
public open fun put(p0: String!, p1: Long!): Unit defined in android.content.ContentValues
public open fun put(p0: String!, p1: Short!): Unit defined in android.content.ContentValues
public open fun put(p0: String!, p1: String!): Unit defined in android.content.ContentValues
e: /home/am/Applications/flutter/.pub-cache/hosted/pub.dartlang.org/photo_manager-2.4.0-dev.3/android/src/main/kotlin/com/fluttercandies/photo_manager/core/utils/AndroidQDBUtils.kt: (404, 14): Overload resolution ambiguity:
2
public fun String.checkDirs(): Unit defined in com.fluttercandies.photo_manager.core.utils in file CommonExt.kt
e: /home/am/Applications/flutter/.pub-cache/hosted/pub.dartlang.org/photo_manager-2.4.0-dev.3/android/src/main/kotlin/com/fluttercandies/photo_manager/core/utils/AndroidQDBUtils.kt: (418, 43): Overload resolution ambiguity:
2
public fun InputStream.getOrientationDegrees(): Int defined in com.fluttercandies.photo_manager.core.utils in file CommonExt.kt
e: /home/am/Applications/flutter/.pub-cache/hosted/pub.dartlang.org/photo_manager-2.4.0-dev.3/android/src/main/kotlin/com/fluttercandies/photo_manager/core/utils/AndroidQDBUtils.kt: (436, 13): Overload resolution ambiguity:
public open fun put(p0: String!, p1: Boolean!): Unit defined in android.content.ContentValues
public open fun put(p0: String!, p1: Byte!): Unit defined in android.content.ContentValues
public open fun put(p0: String!, p1: ByteArray!): Unit defined in android.content.ContentValues
public open fun put(p0: String!, p1: Double!): Unit defined in android.content.ContentValues
public open fun put(p0: String!, p1: Float!): Unit defined in android.content.ContentValues
public open fun put(p0: String!, p1: Int!): Unit defined in android.content.ContentValues
public open fun put(p0: String!, p1: Long!): Unit defined in android.content.ContentValues
public open fun put(p0: String!, p1: Short!): Unit defined in android.content.ContentValues
public open fun put(p0: String!, p1: String!): Unit defined in android.content.ContentValues
e: /home/am/Applications/flutter/.pub-cache/hosted/pub.dartlang.org/photo_manager-2.4.0-dev.3/android/src/main/kotlin/com/fluttercandies/photo_manager/core/utils/AndroidQDBUtils.kt: (648, 14): Overload resolution ambiguity:
2
public fun String.checkDirs(): Unit defined in com.fluttercandies.photo_manager.core.utils in file CommonExt.kt
e: /home/am/Applications/flutter/.pub-cache/hosted/pub.dartlang.org/photo_manager-2.4.0-dev.3/android/src/main/kotlin/com/fluttercandies/photo_manager/core/utils/AndroidQDBUtils.kt: (656, 43): Overload resolution ambiguity:
2
public fun InputStream.getOrientationDegrees(): Int defined in com.fluttercandies.photo_manager.core.utils in file CommonExt.kt
e: /home/am/Applications/flutter/.pub-cache/hosted/pub.dartlang.org/photo_manager-2.4.0-dev.3/android/src/main/kotlin/com/fluttercandies/photo_manager/core/utils/AndroidQDBUtils.kt: (678, 13): Overload resolution ambiguity:
public open fun put(p0: String!, p1: Boolean!): Unit defined in android.content.ContentValues
public open fun put(p0: String!, p1: Byte!): Unit defined in android.content.ContentValues
public open fun put(p0: String!, p1: ByteArray!): Unit defined in android.content.ContentValues
public open fun put(p0: String!, p1: Double!): Unit defined in android.content.ContentValues
public open fun put(p0: String!, p1: Float!): Unit defined in android.content.ContentValues
public open fun put(p0: String!, p1: Int!): Unit defined in android.content.ContentValues
public open fun put(p0: String!, p1: Long!): Unit defined in android.content.ContentValues
public open fun put(p0: String!, p1: Short!): Unit defined in android.content.ContentValues
public open fun put(p0: String!, p1: String!): Unit defined in android.content.ContentValues
e: /home/am/Applications/flutter/.pub-cache/hosted/pub.dartlang.org/photo_manager-2.4.0-dev.3/android/src/main/kotlin/com/fluttercandies/photo_manager/core/utils/CommonExt.kt: (10, 1): Conflicting overloads: public fun String.checkDirs(): Unit defined in com.fluttercandies.photo_manager.core.utils in file CommonExt.kt, public fun String.checkDirs(): Unit defined in com.fluttercandies.photo_manager.core.utils in file CommonExt.kt
e: /home/am/Applications/flutter/.pub-cache/hosted/pub.dartlang.org/photo_manager-2.4.0-dev.3/android/src/main/kotlin/com/fluttercandies/photo_manager/core/utils/CommonExt.kt: (17, 1): Conflicting overloads: public fun InputStream.getOrientationDegrees(): Int defined in com.fluttercandies.photo_manager.core.utils in file CommonExt.kt, public fun InputStream.getOrientationDegrees(): Int defined in com.fluttercandies.photo_manager.core.utils in file CommonExt.kt
e: /home/am/Applications/flutter/.pub-cache/hosted/pub.dartlang.org/photo_manager-2.4.0-dev.3/android/src/main/kotlin/com/fluttercandies/photo_manager/core/utils/IDBUtils.kt: (22, 11): Redeclaration: IDBUtils
e: /home/am/Applications/flutter/.pub-cache/hosted/pub.dartlang.org/photo_manager-2.4.0-dev.3/android/src/main/kotlin/com/fluttercandies/photo_manager/permission/PermissionsUtils.kt: (24, 7): Redeclaration: PermissionsUtils
e: /home/am/Applications/flutter/.pub-cache/hosted/pub.dartlang.org/photo_manager-2.4.0-dev.3/android/src/main/kotlin/com/fluttercandies/photo_manager/util/LogUtils.kt: (8, 8): Redeclaration: LogUtils
AlexV525 commented 2 years ago

https://github.com/fluttercandies/flutter_photo_manager/issues/561

1N50MN14 commented 2 years ago

@AlexV525 I'm using gradle 7.5.1, based on #561 I need to lower it to 6.8.3 but I'm using a package (I believe package_info_plus) which which requires at least 7.3.3... Ok.. I need to figure this out somehow..

AlexV525 commented 2 years ago

No. You just need to run flutter clean.

1N50MN14 commented 2 years ago

I did that, the app wouldn't even build and throws the following error:

A problem occurred evaluating project ':app'.
> Failed to apply plugin 'com.android.internal.version-check'.
   > Minimum supported Gradle version is 7.3.3. Current version is 6.8.3. If using the gradle wrapper, try editing the distributionUrl in /home/am/dev/dfv/clients/rw/android/gradle/wrapper/gradle-wrapper.properties to gradle-7.3.3-all.zip

Also, the app did previously build using photo_manager 2.3.0 and gradle 7.5.1....

1N50MN14 commented 2 years ago

@AlexV525 Ok so I was able to build the app by downgrading gradle to 7.3.3.. I've also tested 2.4.0-dev.3 and it worked as expected.