info: check prop exists before querying owner package
This commit is contained in:
parent
beef2ed654
commit
f8337f6e3d
4 changed files with 47 additions and 4 deletions
|
@ -5,6 +5,7 @@ import android.content.Context
|
|||
import android.database.Cursor
|
||||
import android.media.MediaMetadataRetriever
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.provider.MediaStore
|
||||
import android.util.Log
|
||||
import androidx.exifinterface.media.ExifInterface
|
||||
|
@ -77,6 +78,7 @@ class MetadataHandler(private val context: Context) : MethodCallHandler {
|
|||
"getOverlayMetadata" -> GlobalScope.launch(Dispatchers.IO) { safe(call, result, ::getOverlayMetadata) }
|
||||
"getMultiPageInfo" -> GlobalScope.launch(Dispatchers.IO) { safe(call, result, ::getMultiPageInfo) }
|
||||
"getPanoramaInfo" -> GlobalScope.launch(Dispatchers.IO) { safe(call, result, ::getPanoramaInfo) }
|
||||
"hasContentResolverProp" -> GlobalScope.launch(Dispatchers.IO) { safe(call, result, ::hasContentResolverProp) }
|
||||
"getContentResolverProp" -> GlobalScope.launch(Dispatchers.IO) { safe(call, result, ::getContentResolverProp) }
|
||||
else -> result.notImplemented()
|
||||
}
|
||||
|
@ -681,6 +683,24 @@ class MetadataHandler(private val context: Context) : MethodCallHandler {
|
|||
result.error("getPanoramaInfo-empty", "failed to read XMP from uri=$uri", null)
|
||||
}
|
||||
|
||||
private fun hasContentResolverProp(call: MethodCall, result: MethodChannel.Result) {
|
||||
val prop = call.argument<String>("prop")
|
||||
if (prop == null) {
|
||||
result.error("hasContentResolverProp-args", "failed because of missing arguments", null)
|
||||
return
|
||||
}
|
||||
|
||||
result.success(
|
||||
when (prop) {
|
||||
"owner_package_name" -> Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q
|
||||
else -> {
|
||||
result.error("hasContentResolverProp-unknown", "unknown property=$prop", null)
|
||||
return
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
private fun getContentResolverProp(call: MethodCall, result: MethodChannel.Result) {
|
||||
val mimeType = call.argument<String>("mimeType")
|
||||
val uri = call.argument<String>("uri")?.let { Uri.parse(it) }
|
||||
|
|
|
@ -13,9 +13,7 @@ class AppShortcutService {
|
|||
static bool? _canPin;
|
||||
|
||||
static Future<bool> canPin() async {
|
||||
if (_canPin != null) {
|
||||
return SynchronousFuture(_canPin!);
|
||||
}
|
||||
if (_canPin != null) return SynchronousFuture(_canPin!);
|
||||
|
||||
try {
|
||||
final result = await platform.invokeMethod('canPin');
|
||||
|
|
|
@ -4,6 +4,7 @@ import 'package:aves/model/multipage.dart';
|
|||
import 'package:aves/model/panorama.dart';
|
||||
import 'package:aves/services/service_policy.dart';
|
||||
import 'package:aves/services/services.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
abstract class MetadataService {
|
||||
|
@ -18,6 +19,8 @@ abstract class MetadataService {
|
|||
|
||||
Future<PanoramaInfo?> getPanoramaInfo(AvesEntry entry);
|
||||
|
||||
Future<bool> hasContentResolverProp(String prop);
|
||||
|
||||
Future<String?> getContentResolverProp(AvesEntry entry, String prop);
|
||||
}
|
||||
|
||||
|
@ -137,6 +140,25 @@ class PlatformMetadataService implements MetadataService {
|
|||
return null;
|
||||
}
|
||||
|
||||
final Map<String, bool> _contentResolverProps = {};
|
||||
|
||||
@override
|
||||
Future<bool> hasContentResolverProp(String prop) async {
|
||||
var exists = _contentResolverProps[prop];
|
||||
if (exists != null) return SynchronousFuture(exists);
|
||||
|
||||
try {
|
||||
exists = await platform.invokeMethod('hasContentResolverProp', <String, dynamic>{
|
||||
'prop': prop,
|
||||
});
|
||||
} on PlatformException catch (e, stack) {
|
||||
await reportService.recordError(e, stack);
|
||||
}
|
||||
exists ??= false;
|
||||
_contentResolverProps[prop] = exists;
|
||||
return exists;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<String?> getContentResolverProp(AvesEntry entry, String prop) async {
|
||||
try {
|
||||
|
|
|
@ -135,6 +135,7 @@ class _OwnerPropState extends State<OwnerProp> {
|
|||
|
||||
AvesEntry get entry => widget.entry;
|
||||
|
||||
static const ownerPackageNamePropKey = 'owner_package_name';
|
||||
static const iconSize = 20.0;
|
||||
|
||||
@override
|
||||
|
@ -142,7 +143,9 @@ class _OwnerPropState extends State<OwnerProp> {
|
|||
super.initState();
|
||||
final isMediaContent = entry.uri.startsWith('content://media/external/');
|
||||
if (isMediaContent) {
|
||||
_ownerPackageFuture = metadataService.getContentResolverProp(entry, 'owner_package_name');
|
||||
_ownerPackageFuture = metadataService.hasContentResolverProp(ownerPackageNamePropKey).then((exists) {
|
||||
return exists ? metadataService.getContentResolverProp(entry, ownerPackageNamePropKey) : SynchronousFuture(null);
|
||||
});
|
||||
} else {
|
||||
_ownerPackageFuture = SynchronousFuture(null);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue