import 'package:aves/model/entry.dart'; import 'package:aves/ref/mime_types.dart'; import 'package:aves/services/common/services.dart'; import 'package:flutter/services.dart'; class AndroidDebugService { static const _platform = MethodChannel('deckers.thibault/aves/debug'); static Future crash() async { try { await _platform.invokeMethod('crash'); } on PlatformException catch (e, stack) { await reportService.recordError(e, stack); } } static Future exception() async { try { await _platform.invokeMethod('exception'); } on PlatformException catch (e, stack) { await reportService.recordError(e, stack); } } static Future safeException() async { try { await _platform.invokeMethod('safeException'); } on PlatformException catch (e, stack) { await reportService.recordError(e, stack); } } static Future exceptionInCoroutine() async { try { await _platform.invokeMethod('exceptionInCoroutine'); } on PlatformException catch (e, stack) { await reportService.recordError(e, stack); } } static Future safeExceptionInCoroutine() async { try { await _platform.invokeMethod('safeExceptionInCoroutine'); } on PlatformException catch (e, stack) { await reportService.recordError(e, stack); } } static Future getContextDirs() async { try { final result = await _platform.invokeMethod('getContextDirs'); if (result != null) return result as Map; } on PlatformException catch (e, stack) { await reportService.recordError(e, stack); } return {}; } static Future> getCodecs() async { try { final result = await _platform.invokeMethod('getCodecs'); if (result != null) return (result as List).cast(); } on PlatformException catch (e, stack) { await reportService.recordError(e, stack); } return []; } static Future getEnv() async { try { final result = await _platform.invokeMethod('getEnv'); if (result != null) return result as Map; } on PlatformException catch (e, stack) { await reportService.recordError(e, stack); } return {}; } static Future getBitmapFactoryInfo(AvesEntry entry) async { try { // returns map with all data available when decoding image bounds with `BitmapFactory` final result = await _platform.invokeMethod('getBitmapFactoryInfo', { 'uri': entry.uri, }); if (result != null) return result as Map; } on PlatformException catch (e, stack) { await reportService.recordError(e, stack); } return {}; } static Future getContentResolverMetadata(AvesEntry entry) async { try { // returns map with all data available from the content resolver final result = await _platform.invokeMethod('getContentResolverMetadata', { 'mimeType': entry.mimeType, 'uri': entry.uri, }); if (result != null) return result as Map; } on PlatformException catch (e, stack) { await reportService.recordError(e, stack); } return {}; } static Future getExifInterfaceMetadata(AvesEntry entry) async { try { // returns map with all data available from the `ExifInterface` library final result = await _platform.invokeMethod('getExifInterfaceMetadata', { 'mimeType': entry.mimeType, 'uri': entry.uri, 'sizeBytes': entry.sizeBytes, }); if (result != null) return result as Map; } on PlatformException catch (e, stack) { await reportService.recordError(e, stack); } return {}; } static Future getMediaMetadataRetrieverMetadata(AvesEntry entry) async { try { // returns map with all data available from `MediaMetadataRetriever` final result = await _platform.invokeMethod('getMediaMetadataRetrieverMetadata', { 'uri': entry.uri, }); if (result != null) return result as Map; } on PlatformException catch (e, stack) { await reportService.recordError(e, stack); } return {}; } static Future getMetadataExtractorSummary(AvesEntry entry) async { try { // returns map with the MIME type and tag count for each directory found by `metadata-extractor` final result = await _platform.invokeMethod('getMetadataExtractorSummary', { 'mimeType': entry.mimeType, 'uri': entry.uri, 'sizeBytes': entry.sizeBytes, }); if (result != null) return result as Map; } on PlatformException catch (e, stack) { await reportService.recordError(e, stack); } return {}; } static Future getPixyMetadata(AvesEntry entry) async { try { // returns map with all data available from the `PixyMeta` library final result = await _platform.invokeMethod('getPixyMetadata', { 'mimeType': entry.mimeType, 'uri': entry.uri, }); if (result != null) return result as Map; } on PlatformException catch (e, stack) { await reportService.recordError(e, stack); } return {}; } static Future getTiffStructure(AvesEntry entry) async { if (entry.mimeType != MimeTypes.tiff) return {}; try { final result = await _platform.invokeMethod('getTiffStructure', { 'uri': entry.uri, }); if (result != null) return result as Map; } on PlatformException catch (e, stack) { await reportService.recordError(e, stack); } return {}; } }