Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android-14-permission #982

Merged
merged 21 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 29 additions & 13 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@ that can be found in the LICENSE file. -->

# CHANGELOG

## 2.8.0

### Feature

- Support android API 34(Android 14) limit access to photos and videos.
- Because limit permission, we refactor the permission request API.

***Breaking changes for permission behavior***
CaiJingLong marked this conversation as resolved.
Show resolved Hide resolved

Now, users need to ensure they have the access permissions through the
following means before using the API to access resources.
Two ways:

1. `PhotoManager.requestPermissionExtend()` and the result is `PermissionState.authorized` or `PermissionState.limited`.
2. `PhotoManager.setIgnorePermissionCheck(true)` to ignore permission check and use other permission plugin.

## 2.7.1

### Fixes
Expand Down Expand Up @@ -38,9 +54,9 @@ that can be found in the LICENSE file. -->

- Support `CustomFilter` for more filter options. (#901)
- Add two new static methods for `PhotoManager`:
- `getAssetCount` for getting assets count.
- `getAssetListRange` for getting assets between start and end.
- `getAssetCount` for getting assets count.
- `getAssetListRange` for getting assets between start and end.

## 2.5.2

### Improvements
Expand Down Expand Up @@ -120,8 +136,8 @@ that can be found in the LICENSE file. -->

- Introduce `AssetPathEntity.assetCountAsync` getter,
which improves the speed when loading paths mainly on iOS, also:
- Deprecate `AssetPathEntity.assetCount`.
- Remove `FilterOptionGroup.containsEmptyAlbum`.
- Deprecate `AssetPathEntity.assetCount`.
- Remove `FilterOptionGroup.containsEmptyAlbum`.

### Improvements

Expand Down Expand Up @@ -545,7 +561,7 @@ and applied multiple ### Fixes which make this plugin as the most solid ever.
but at the same time user have to bear the risks corresponding to the permission).
- Support clean file cache.
- Experimental
- Preload image (Use `PhotoCachingManager` api.)
- Preload image (Use `PhotoCachingManager` api.)
- Add `OrderOption` as sort condition. The option default value is order by create date desc;
- Support icloud asset progress.

Expand Down Expand Up @@ -608,14 +624,14 @@ and applied multiple ### Fixes which make this plugin as the most solid ever.
- Create AssetEntity with id.
- Create AssetPathEntity from id.
- Only iOS
- Create folder or album.
- Remove assets in album.
- Delete folder or album.
- Favorite asset.
- Create folder or album.
- Remove assets in album.
- Delete folder or album.
- Favorite asset.
- Only android
- move asset to another path.
- Remove all non-existing rows.
- add `relativePath` for android.
- move asset to another path.
- Remove all non-existing rows.
- add `relativePath` for android.

### Improvements

Expand Down
17 changes: 14 additions & 3 deletions README-ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,10 @@ Android 10 引入了 **Scoped Storage**,导致原始资源文件不能通过
```dart
final PermissionState ps = await PhotoManager.requestPermissionExtend();
if (ps.isAuth) {
// 已获取到权限。
// 已获取到权限
} else if (ps.hasAccess) {
// 已获取到权限(哪怕只是有限的访问权限)。
// iOS Android 目前都已经有了部分权限的概念。
} else {
// 权限受限制(iOS)或者被拒绝,使用 `==` 能够更准确的判断是受限还是拒绝。
// 你可以使用 `PhotoManager.openSetting()` 打开系统设置页面进行进一步的逻辑定制。
Expand All @@ -228,14 +231,22 @@ PhotoManager.setIgnorePermissionCheck(true);

对于一些后台操作(应用未启动等)而言,忽略检查是比较合适的做法。

#### iOS 受限的资源权限
#### 受限的资源权限

##### iOS 受限的资源权限

iOS14 引入了部分资源限制的权限 (`PermissionState.limited`)。
`PhotoManager.requestPermissionExtend()` 会返回当前的权限状态 `PermissionState`。
详情请参阅 [PHAuthorizationStatus][]。

如果你想要重新选择在应用里能够读取到的资源,你可以使用 `PhotoManager.presentLimited()` 重新选择资源,
这个方法仅在 iOS 14 以上的版本生效,其他平台或版本无法调用这个方法。
这个方法对于 iOS 14 以上的版本生效。

##### Android 受限的资源权限

和 iOS 类似,安卓 14(API 34) 中也加入了这个概念,dart 端的使用方法也完全一致。

但行为上略有不同(基于模拟器),安卓中一旦授予某个资源的访问权限,就无法撤销,即使再次使用 `presentLimited` 时不选中也一样。
CaiJingLong marked this conversation as resolved.
Show resolved Hide resolved

### 获取相簿或图集 (`AssetPathEntity`)

Expand Down
23 changes: 18 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,12 @@ It's pretty much the same as the `NSPhotoLibraryUsageDescription`.
Most of the APIs can only use with granted permission.

```dart
final PermissionState ps = await PhotoManager.requestPermissionExtend();
final PermissionState ps = await PhotoManager.requestPermissionExtend(); // the method can use optional param `permission`.
if (ps.isAuth) {
// Granted.
// Granted
// You can to get assets here.
} else if (ps.hasAccess) {
// Access will continue, but the amount visible depends on the user's selection.
} else {
// Limited(iOS) or Rejected, use `==` for more precise judgements.
// You can call `PhotoManager.openSetting()` to open settings for further steps.
Expand All @@ -240,7 +243,9 @@ PhotoManager.setIgnorePermissionCheck(true);
For background processing (such as when the app is not in the foreground),
ignore permissions check would be proper solution.

#### Limited entities access on iOS
#### Limited entities access
CaiJingLong marked this conversation as resolved.
Show resolved Hide resolved

##### Limited entities access on iOS

With iOS 14 released, Apple brought a "Limited Photos Library" permission
(`PermissionState.limited`) to iOS.
Expand All @@ -251,8 +256,16 @@ To reselect accessible entities for the app,
use `PhotoManager.presentLimited()` to call the modal of
accessible entities' management.
This method only available for iOS 14+ and when the permission state
is limited (`PermissionState.limited`),
other platform won't make a valid call.
is limited (`PermissionState.limited`).

##### Limited entities access on android

Similar to iOS, Android 14 (API 34) has also introduced this concept, and the usage on the Dart side is completely identical.

However, there is a slight difference in behavior (based on the emulator).

In Android, once access permission to a certain resource is granted, it cannot be revoked,
even if you do not select it again when using `presentLimited`.
CaiJingLong marked this conversation as resolved.
Show resolved Hide resolved

### Get albums/folders (`AssetPathEntity`)

Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ android {
namespace 'com.flutterandies.photo_manager'
}

compileSdkVersion 33
compileSdkVersion 34

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,61 @@ package com.fluttercandies.photo_manager.constant

class Methods {
companion object {
// Not need permission methods
const val log = "log"
const val openSetting = "openSetting"
const val forceOldAPI = "forceOldApi"
const val systemVersion = "systemVersion"
const val clearFileCache = "clearFileCache"
const val releaseMemoryCache = "releaseMemoryCache"
const val ignorePermissionCheck = "ignorePermissionCheck"

fun isNotNeedPermissionMethod(method: String): Boolean {
return method in arrayOf(
log,
openSetting,
forceOldAPI,
systemVersion,
clearFileCache,
releaseMemoryCache,
ignorePermissionCheck,
)
}
// Not need permission methods end

// About permission start
const val requestPermissionExtend = "requestPermissionExtend"
const val presentLimited = "presentLimited"

fun isPermissionMethod(method: String): Boolean {
return method in arrayOf(
requestPermissionExtend,
presentLimited,
)
}
// About permission end

/// Have [requestType] start
const val fetchPathProperties = "fetchPathProperties"
const val getAssetPathList = "getAssetPathList"
const val getAssetListPaged = "getAssetListPaged"
const val getAssetListRange = "getAssetListRange"
const val getAssetCount = "getAssetCount"
const val getAssetsByRange = "getAssetsByRange"

val haveRequestTypeMethods = arrayOf(
fetchPathProperties,
getAssetPathList,
getAssetListPaged,
getAssetListRange,
getAssetCount,
getAssetsByRange,
)

fun isHaveRequestTypeMethod(method: String): Boolean {
return method in haveRequestTypeMethods
}
/// Have [requestType] end

const val getThumbnail = "getThumb"
const val requestCacheAssetsThumbnail = "requestCacheAssetsThumb"
Expand All @@ -31,20 +78,22 @@ class Methods {
const val removeNoExistsAssets = "removeNoExistsAssets"
const val getColumnNames = "getColumnNames"

const val getAssetCount = "getAssetCount"
const val getAssetsByRange = "getAssetsByRange"
val needMediaLocationMethods = arrayOf(
getLatLng,
getFullFile,
getOriginBytes,
)

/// Below methods have [RequestType] params, thus permissions are required for Android 13.
const val fetchPathProperties = "fetchPathProperties"
const val getAssetPathList = "getAssetPathList"
const val getAssetListPaged = "getAssetListPaged"
const val getAssetListRange = "getAssetListRange"
fun isNeedMediaLocationMethod(method: String): Boolean {
return method in needMediaLocationMethods
}

val android13PermissionMethods = arrayOf(
fetchPathProperties,
getAssetPathList,
getAssetListPaged,
getAssetListRange,
)
fun otherMethods(method: String): Boolean {
return (isNotNeedPermissionMethod(method) ||
isPermissionMethod(method) ||
isHaveRequestTypeMethod(method) ||
isNeedMediaLocationMethod(method))
.not()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class PhotoManager(private val context: Context) {
format,
quality,
frame,
resultHandler.result
resultHandler,
)
} catch (e: Exception) {
Log.e(LogUtils.TAG, "get $id thumbnail error, width : $width, height: $height", e)
Expand Down
Loading
Loading