Skip to content

Commit

Permalink
🐛 [Android] Correct permission checks with requestPermissionExtend
Browse files Browse the repository at this point in the history
…on Android 33 (#843)
  • Loading branch information
AlexV525 authored Oct 7, 2022
1 parent e66aa8f commit 05f74da
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 15 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ that can be found in the LICENSE file. -->

# CHANGELOG

## 2.4.0-dev.3

### Fixes

- Correct permission checks with `requestPermissionExtend` on Android 33. (#843)

## 2.4.0-dev.2

### Fixes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,11 @@ class Methods {
const val getAssetListPaged = "getAssetListPaged"
const val getAssetListRange = "getAssetListRange"

val android13PermissionMethods =
arrayOf(
fetchPathProperties,
getAssetPathList,
getAssetListPaged,
getAssetListRange,
)
val android13PermissionMethods = arrayOf(
fetchPathProperties,
getAssetPathList,
getAssetListPaged,
getAssetListRange,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class PhotoManagerPlugin(
Manifest.permission.WRITE_EXTERNAL_STORAGE
)
val needReadPermission =
Build.VERSION.SDK_INT <= Build.VERSION_CODES.TIRAMISU
Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU
&& permissionsUtils.havePermissionInManifest(
applicationContext,
Manifest.permission.READ_EXTERNAL_STORAGE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import com.fluttercandies.photo_manager.core.utils.RequestTypeUtils
import com.fluttercandies.photo_manager.util.LogUtils
import com.fluttercandies.photo_manager.util.ResultHandler
import io.flutter.plugin.common.MethodCall
import java.lang.IllegalArgumentException
import java.lang.IllegalStateException
import java.lang.NullPointerException
import java.util.ArrayList
Expand Down Expand Up @@ -225,17 +224,27 @@ class PermissionsUtils {
resultHandler: ResultHandler
) {
val method = call.method
if (!Methods.android13PermissionMethods.contains(method)) {
if (method == Methods.requestPermissionExtend) {
// Check all permissions listed in the manifest, regardless the request type.
if (havePermissionInManifest(context, Manifest.permission.READ_MEDIA_IMAGES)) {
permissions.add(Manifest.permission.READ_MEDIA_IMAGES)
}
if (havePermissionInManifest(context, Manifest.permission.READ_MEDIA_VIDEO)) {
permissions.add(Manifest.permission.READ_MEDIA_VIDEO)
}
if (havePermissionInManifest(context, Manifest.permission.READ_MEDIA_AUDIO)) {
permissions.add(Manifest.permission.READ_MEDIA_AUDIO)
}
return
} else if (!Methods.android13PermissionMethods.contains(method)) {
return
}

val type = call.argument<Int>("type")

if (type == null) {
resultHandler.replyError("The $method must pass the 'type' params")
return
}

val haveImage = RequestTypeUtils.containsImage(type)
val haveVideo = RequestTypeUtils.containsVideo(type)
val haveAudio = RequestTypeUtils.containsAudio(type)
Expand All @@ -246,7 +255,7 @@ class PermissionsUtils {
}

if (!havePermissionInManifest(context, manifestPermission)) {
throw IllegalStateException("Request $tag must have $manifestPermission in manifest!")
throw IllegalStateException("Request $tag must have $manifestPermission in manifest.")
}
permissions.add(manifestPermission)
}
Expand All @@ -256,7 +265,7 @@ class PermissionsUtils {
checkAndAddPermission(haveVideo, "video", Manifest.permission.READ_MEDIA_VIDEO)
checkAndAddPermission(haveAudio, "audio", Manifest.permission.READ_MEDIA_AUDIO)
} catch (e: IllegalStateException) {
resultHandler.replyError("The permission have error for android 33 or higher", e.message, e)
resultHandler.replyError("Permissions check error", e.message, e)
}

}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: photo_manager
description: A Flutter plugin that provides assets abstraction management APIs on Android, iOS, and macOS.
repository: https://github.com/fluttercandies/flutter_photo_manager
version: 2.4.0-dev.2
version: 2.4.0-dev.3

environment:
sdk: ">=2.13.0 <3.0.0"
Expand Down

0 comments on commit 05f74da

Please sign in to comment.