Skip to content

Commit

Permalink
Merge branch 'main' into android-14-permission
Browse files Browse the repository at this point in the history
  • Loading branch information
CaiJingLong committed Oct 11, 2023
2 parents 4ebace7 + b3f27d3 commit 78614b6
Show file tree
Hide file tree
Showing 8 changed files with 158 additions and 70 deletions.
36 changes: 18 additions & 18 deletions .github/workflows/check-compatibility.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ on:
push:

jobs:
build-for-android-3-10-6:
name: Build for android with 3.10.6 on ubuntu-latest
build-for-android:
name: Build for Android on ubuntu-latest
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: subosito/flutter-action@v2
with:
flutter-version: 3.10.6
channel: 'stable'
cache: true
cache-key: 'flutter-:os:-:channel:-:version:-:arch:-:hash:'
- uses: actions/setup-java@v3
Expand All @@ -32,14 +32,14 @@ jobs:
- run: flutter build apk --debug
working-directory: ${{ github.workspace }}/new_project
name: Build example
build-for-ios-3-10-6:
name: Build for ios with 3.10.6 on macos-latest
build-for-ios:
name: Build for ios on macos-latest
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- uses: subosito/flutter-action@v2
with:
flutter-version: 3.10.6
channel: 'stable'
cache: true
cache-key: 'flutter-:os:-:channel:-:version:-:arch:-:hash:'
- run: flutter doctor -v
Expand All @@ -60,14 +60,14 @@ jobs:
- run: flutter build ios --release --no-codesign
working-directory: ${{ github.workspace }}/new_project
name: Build example
build-for-web-3-10-6:
name: Build for web with 3.10.6 on ubuntu-latest
build-for-web:
name: Build for Web on ubuntu-latest
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: subosito/flutter-action@v2
with:
flutter-version: 3.10.6
channel: 'stable'
cache: true
cache-key: 'flutter-:os:-:channel:-:version:-:arch:-:hash:'
- run: flutter doctor -v
Expand All @@ -83,14 +83,14 @@ jobs:
- run: flutter build web --release
working-directory: ${{ github.workspace }}/new_project
name: Build example
build-for-linux-3-10-6:
name: Build for linux with 3.10.6 on ubuntu-latest
build-for-linux:
name: Build for Linux on ubuntu-latest
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: subosito/flutter-action@v2
with:
flutter-version: 3.10.6
channel: 'stable'
cache: true
cache-key: 'flutter-:os:-:channel:-:version:-:arch:-:hash:'
- name: Install required packages
Expand All @@ -112,14 +112,14 @@ jobs:
- run: flutter build linux --release
working-directory: ${{ github.workspace }}/new_project
name: Build example
build-for-macos-3-10-6:
name: Build for macos with 3.10.6 on macos-latest
build-for-macos:
name: Build for macOS on macos-latest
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- uses: subosito/flutter-action@v2
with:
flutter-version: 3.10.6
channel: 'stable'
cache: true
cache-key: 'flutter-:os:-:channel:-:version:-:arch:-:hash:'
- run: flutter doctor -v
Expand All @@ -140,14 +140,14 @@ jobs:
- run: flutter build macos --release
working-directory: ${{ github.workspace }}/new_project
name: Build example
build-for-windows-3-10-6:
name: Build for windows with 3.10.6 on windows-latest
build-for-windows:
name: Build for Windows on windows-latest
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- uses: subosito/flutter-action@v2
with:
flutter-version: 3.10.6
channel: 'stable'
cache: true
cache-key: 'flutter-:os:-:channel:-:version:-:arch:-:hash:'
- run: flutter doctor -v
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ User must follow the below methods to ensure permissions were granted:
2. `PhotoManager.setIgnorePermissionCheck(true)`, ignoring permission checks,
handle permission with other mechanisms.

### Fixes

- Correct the key when fetching video info with MMR on Android. (#997)
- Retrieve original media instead of one with adjustments/filters for subtype files on iOS. (#976)
- Returns original file name instead of `FullSizeRender.*` if this has adjustments on iOS. (#976)

### Improvements

- Add locks to the image provider.

## 2.7.1

### Fixes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ interface IDBUtils {
mmr.setDataSource(path)
width = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH)
?.toInt() ?: 0
height = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH)
height = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT)
?.toInt() ?: 0
orientation =
mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION)
Expand Down
6 changes: 5 additions & 1 deletion example/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,12 @@ def install_plugin_pods(application_path = nil, relative_symlink_dir, platform)
plugin_pods.each do |plugin_hash|
plugin_name = plugin_hash['name']
plugin_path = plugin_hash['path']
# iOS and macOS code can be shared in "darwin" directory, otherwise
# respectively in "ios" or "macos" directories.
shared_darwin_source = plugin_hash.fetch('shared_darwin_source', false)
platform_directory = shared_darwin_source ? 'darwin' : platform
if (plugin_name && plugin_path)
specPath = "#{plugin_path}/#{platform}/#{plugin_name}.podspec"
specPath = "#{plugin_path}/#{platform_directory}/#{plugin_name}.podspec"
pod plugin_name, :path => specPath
end
end
Expand Down
33 changes: 32 additions & 1 deletion example/macos/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,42 @@ require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelpe

flutter_macos_podfile_setup

def install_plugin_pods(application_path = nil, relative_symlink_dir, platform)
# defined_in_file is set by CocoaPods and is a Pathname to the Podfile.
application_path ||= File.dirname(defined_in_file.realpath) if self.respond_to?(:defined_in_file)
raise 'Could not find application path' unless application_path

# Prepare symlinks folder. We use symlinks to avoid having Podfile.lock
# referring to absolute paths on developers' machines.

symlink_dir = File.expand_path(relative_symlink_dir, application_path)
system('rm', '-rf', symlink_dir) # Avoid the complication of dependencies like FileUtils.

symlink_plugins_dir = File.expand_path('plugins', symlink_dir)
system('mkdir', '-p', symlink_plugins_dir)

plugins_file = File.join(application_path, '..', '.flutter-plugins-dependencies')
plugin_pods = flutter_parse_plugins_file(plugins_file, platform)
plugin_pods.each do |plugin_hash|
plugin_name = plugin_hash['name']
plugin_path = plugin_hash['path']
# iOS and macOS code can be shared in "darwin" directory, otherwise
# respectively in "ios" or "macos" directories.
shared_darwin_source = plugin_hash.fetch('shared_darwin_source', false)
platform_directory = shared_darwin_source ? 'darwin' : platform
if (plugin_name && plugin_path)
specPath = "#{plugin_path}/#{platform_directory}/#{plugin_name}.podspec"
pod plugin_name, :path => specPath
end
end
end

target 'Runner' do
use_frameworks!
use_modular_headers!

flutter_install_all_macos_pods File.dirname(File.realpath(__FILE__))
flutter_install_macos_engine_pod(File.dirname(File.realpath(__FILE__)))
install_plugin_pods(File.dirname(File.realpath(__FILE__)), '.symlinks', 'macos')
end

post_install do |installer|
Expand Down
1 change: 1 addition & 0 deletions ios/Classes/core/PHAsset+PM_COMMON.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ NS_ASSUME_NONNULL_BEGIN
- (nullable NSString*)mimeType;
- (BOOL)isAdjust;
- (PHAssetResource *)getAdjustResource;
- (PHAssetResource *)getUntouchedResource;
- (void)requestAdjustedData:(void (^)(NSData *_Nullable result))block;
- (PHAssetResource *)getLivePhotosResource;

Expand Down
27 changes: 26 additions & 1 deletion ios/Classes/core/PHAsset+PM_COMMON.m
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ - (NSString *)originalFilenameWithSubtype:(int)subtype {
return [self getLivePhotosResource].originalFilename;
}
}
PHAssetResource *resource = [self getAdjustResource];
PHAssetResource *resource = [self getUntouchedResource];
if (resource) {
return resource.originalFilename;
}
Expand Down Expand Up @@ -120,6 +120,31 @@ - (BOOL)videoIsAdjust:(NSArray<PHAssetResource *> *)resources {
return NO;
}

- (PHAssetResource *)getUntouchedResource {
NSArray<PHAssetResource *> *resources = [PHAssetResource assetResourcesForAsset:self];
if (resources.count == 0) {
return nil;
}

if (resources.count == 1) {
return resources[0];
}

for (PHAssetResource *res in resources) {
if (self.mediaType == PHAssetMediaTypeImage
&& res.type == PHAssetResourceTypePhoto) {
return res;
}

if (self.mediaType == PHAssetMediaTypeVideo
&& res.type == PHAssetResourceTypeVideo) {
return res;
}
}

return nil;
}

- (PHAssetResource *)getAdjustResource {
NSArray<PHAssetResource *> *resources = [PHAssetResource assetResourcesForAsset:self];
if (resources.count == 0) {
Expand Down
113 changes: 65 additions & 48 deletions lib/src/internal/image_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by an Apache license that can be found
// in the LICENSE file.

import 'dart:async';
import 'dart:io';
import 'dart:typed_data' as typed_data;
import 'dart:ui' as ui;
Expand All @@ -14,6 +15,8 @@ import '../types/thumbnail.dart';
import 'constants.dart';
import 'enums.dart';

final _providerLocks = <AssetEntityImageProvider, Completer<ui.Codec>>{};

/// The [ImageProvider] that handles [AssetEntity].
///
/// Only support [AssetType.image] and [AssetType.video],
Expand Down Expand Up @@ -91,59 +94,73 @@ class AssetEntityImageProvider extends ImageProvider<AssetEntityImageProvider> {
Future<ui.Codec> _loadAsync(
AssetEntityImageProvider key,
DecoderCallback decode, // ignore: deprecated_member_use
) async {
try {
assert(key == this);
if (key.entity.type == AssetType.audio ||
key.entity.type == AssetType.other) {
throw UnsupportedError(
'Image data for the ${key.entity.type} is not supported.',
);
}
) {
if (_providerLocks.containsKey(key)) {
return _providerLocks[key]!.future;
}
final lock = Completer<ui.Codec>();
_providerLocks[key] = lock;
Future(() async {
try {
assert(key == this);
if (key.entity.type == AssetType.audio ||
key.entity.type == AssetType.other) {
throw UnsupportedError(
'Image data for the ${key.entity.type} is not supported.',
);
}

// Define the image type.
final ImageFileType type;
if (key.imageFileType == ImageFileType.other) {
// Assume the title is invalid here, try again with the async getter.
type = _getType(await key.entity.titleAsync);
} else {
type = key.imageFileType;
}
// Define the image type.
final ImageFileType type;
if (key.imageFileType == ImageFileType.other) {
// Assume the title is invalid here, try again with the async getter.
type = _getType(await key.entity.titleAsync);
} else {
type = key.imageFileType;
}

typed_data.Uint8List? data;
if (isOriginal) {
if (key.entity.type == AssetType.video) {
data = await key.entity.thumbnailData;
} else if (type == ImageFileType.heic) {
data = await (await key.entity.file)?.readAsBytes();
typed_data.Uint8List? data;
if (isOriginal) {
if (key.entity.type == AssetType.video) {
data = await key.entity.thumbnailData;
} else if (type == ImageFileType.heic) {
data = await (await key.entity.file)?.readAsBytes();
} else {
data = await key.entity.originBytes;
}
} else {
data = await key.entity.originBytes;
data = await key.entity.thumbnailDataWithOption(
_thumbOption(thumbnailSize!),
);
}
} else {
data = await key.entity.thumbnailDataWithOption(
_thumbOption(thumbnailSize!),
);
}
if (data == null) {
throw StateError('The data of the entity is null: $entity');
}
return decode(data);
} catch (e, s) {
if (kDebugMode) {
FlutterError.presentError(
FlutterErrorDetails(
exception: e,
stack: s,
library: PMConstants.libraryName,
),
);
if (data == null) {
throw StateError('The data of the entity is null: $entity');
}
return decode(data);
} catch (e, s) {
if (kDebugMode) {
FlutterError.presentError(
FlutterErrorDetails(
exception: e,
stack: s,
library: PMConstants.libraryName,
),
);
}
// Depending on where the exception was thrown, the image cache may not
// have had a chance to track the key in the cache at all.
// Schedule a microtask to give the cache a chance to add the key.
Future<void>.microtask(() => _evictCache(key));
rethrow;
}
// Depending on where the exception was thrown, the image cache may not
// have had a chance to track the key in the cache at all.
// Schedule a microtask to give the cache a chance to add the key.
Future<void>.microtask(() => _evictCache(key));
rethrow;
}
}).then((codec) {
lock.complete(codec);
}).catchError((e, s) {
lock.completeError(e, s);
}).whenComplete(() {
_providerLocks.remove(key);
});
return lock.future;
}

ThumbnailOption _thumbOption(ThumbnailSize size) {
Expand Down

0 comments on commit 78614b6

Please sign in to comment.