import 'package:aves/model/entry.dart'; import 'package:aves/ref/mime_types.dart'; import 'package:aves/services/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) { await reportService.recordChannelError('crash', e); } } static Future exception() async { try { await platform.invokeMethod('exception'); } on PlatformException catch (e) { await reportService.recordChannelError('exception', e); } } static Future safeException() async { try { await platform.invokeMethod('safeException'); } on PlatformException catch (e) { await reportService.recordChannelError('safeException', e); } } static Future exceptionInCoroutine() async { try { await platform.invokeMethod('exceptionInCoroutine'); } on PlatformException catch (e) { await reportService.recordChannelError('exceptionInCoroutine', e); } } static Future safeExceptionInCoroutine() async { try { await platform.invokeMethod('safeExceptionInCoroutine'); } on PlatformException catch (e) { await reportService.recordChannelError('safeExceptionInCoroutine', e); } } static Future getContextDirs() async { try { final result = await platform.invokeMethod('getContextDirs'); if (result != null) return result as Map; } on PlatformException catch (e) { await reportService.recordChannelError('getContextDirs', e); } return {}; } static Future getEnv() async { try { final result = await platform.invokeMethod('getEnv'); if (result != null) return result as Map; } on PlatformException catch (e) { await reportService.recordChannelError('getEnv', e); } 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) { await reportService.recordChannelError('getBitmapFactoryInfo', e); } 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) { await reportService.recordChannelError('getContentResolverMetadata', e); } 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) { await reportService.recordChannelError('getExifInterfaceMetadata', e); } 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) { await reportService.recordChannelError('getMediaMetadataRetrieverMetadata', e); } 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) { await reportService.recordChannelError('getMetadataExtractorSummary', e); } 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) { await reportService.recordChannelError('getTiffStructure', e); } return {}; } }