From 7b35604ff586ecd7d040a5a941bdd60aa6f5827f Mon Sep 17 00:00:00 2001 From: OmarHatem Date: Mon, 20 Feb 2023 22:17:41 +0200 Subject: [PATCH] Add app version and device info to error report --- android/build.gradle | 2 +- .../gradle/wrapper/gradle-wrapper.properties | 2 +- cw_haven/pubspec.yaml | 2 +- cw_monero/pubspec.yaml | 2 +- lib/utils/exception_handler.dart | 88 ++++++++++++++++++- 5 files changed, 90 insertions(+), 6 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index 04c2af566..692e8dfb1 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,5 +1,5 @@ buildscript { - ext.kotlin_version = '1.5.10' + ext.kotlin_version = '1.6.21' repositories { google() jcenter() diff --git a/android/gradle/wrapper/gradle-wrapper.properties b/android/gradle/wrapper/gradle-wrapper.properties index b7ca2e6de..733c691d3 100644 --- a/android/gradle/wrapper/gradle-wrapper.properties +++ b/android/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip diff --git a/cw_haven/pubspec.yaml b/cw_haven/pubspec.yaml index 28f2c315e..7a5ac6aa4 100644 --- a/cw_haven/pubspec.yaml +++ b/cw_haven/pubspec.yaml @@ -12,7 +12,7 @@ environment: dependencies: flutter: sdk: flutter - ffi: ^1.1.2 + ffi: ^2.0.1 http: ^0.13.4 path_provider: ^2.0.11 mobx: ^2.0.7+4 diff --git a/cw_monero/pubspec.yaml b/cw_monero/pubspec.yaml index 23e8782cb..6d5041dfa 100644 --- a/cw_monero/pubspec.yaml +++ b/cw_monero/pubspec.yaml @@ -12,7 +12,7 @@ environment: dependencies: flutter: sdk: flutter - ffi: ^1.1.2 + ffi: ^2.0.1 http: ^0.13.4 path_provider: ^2.0.11 mobx: ^2.0.7+4 diff --git a/lib/utils/exception_handler.dart b/lib/utils/exception_handler.dart index 4cbebdb5d..8aefe7bc6 100644 --- a/lib/utils/exception_handler.dart +++ b/lib/utils/exception_handler.dart @@ -1,4 +1,3 @@ -import 'dart:convert'; import 'dart:io'; import 'package:cake_wallet/entities/preferences_key.dart'; @@ -6,9 +5,11 @@ import 'package:cake_wallet/generated/i18n.dart'; import 'package:cake_wallet/main.dart'; import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart'; import 'package:cake_wallet/utils/show_pop_up.dart'; +import 'package:device_info_plus/device_info_plus.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_mailer/flutter_mailer.dart'; +import 'package:package_info/package_info.dart'; import 'package:path_provider/path_provider.dart'; import 'package:shared_preferences/shared_preferences.dart'; @@ -31,7 +32,7 @@ class ExceptionHandler { ==========================================================\n\n'''; await file.writeAsString( - jsonEncode(exception) + separator, + "$exception $separator", mode: FileMode.append, ); } @@ -42,6 +43,8 @@ class ExceptionHandler { final file = File('${appDocDir.path}/error.txt'); + await _addDeviceInfo(file); + final MailOptions mailOptions = MailOptions( subject: 'Mobile App Issue', recipients: ['support@cakewallet.com'], @@ -130,4 +133,85 @@ class ExceptionHandler { "errno = 28", // OS Error: No space left on device "PERMISSION_NOT_GRANTED", ]; + + static Future _addDeviceInfo(File file) async { + final packageInfo = await PackageInfo.fromPlatform(); + final currentVersion = packageInfo.version; + + final deviceInfoPlugin = DeviceInfoPlugin(); + Map deviceInfo = {}; + + if (Platform.isAndroid) { + deviceInfo = _readAndroidBuildData(await deviceInfoPlugin.androidInfo); + deviceInfo["Platform"] = "Android"; + } else if (Platform.isIOS) { + deviceInfo = _readIosDeviceInfo(await deviceInfoPlugin.iosInfo); + deviceInfo["Platform"] = "iOS"; + } else if (Platform.isLinux) { + deviceInfo = _readLinuxDeviceInfo(await deviceInfoPlugin.linuxInfo); + deviceInfo["Platform"] = "Linux"; + } else if (Platform.isMacOS) { + deviceInfo = _readMacOsDeviceInfo(await deviceInfoPlugin.macOsInfo); + deviceInfo["Platform"] = "MacOS"; + } else if (Platform.isWindows) { + deviceInfo = _readWindowsDeviceInfo(await deviceInfoPlugin.windowsInfo); + deviceInfo["Platform"] = "Windows"; + } + + await file.writeAsString( + "App Version: $currentVersion\n\nDevice Info $deviceInfo", + mode: FileMode.append, + ); + } + + static Map _readAndroidBuildData(AndroidDeviceInfo build) { + return { + 'brand': build.brand, + 'device': build.device, + 'manufacturer': build.manufacturer, + 'model': build.model, + 'product': build.product, + }; + } + + static Map _readIosDeviceInfo(IosDeviceInfo data) { + return { + 'systemName': data.systemName, + 'systemVersion': data.systemVersion, + 'model': data.model, + 'localizedModel': data.localizedModel, + }; + } + + static Map _readLinuxDeviceInfo(LinuxDeviceInfo data) { + return { + 'name': data.name, + 'version': data.version, + 'versionCodename': data.versionCodename, + 'versionId': data.versionId, + 'prettyName': data.prettyName, + 'buildId': data.buildId, + 'variant': data.variant, + 'variantId': data.variantId, + }; + } + + static Map _readMacOsDeviceInfo(MacOsDeviceInfo data) { + return { + 'arch': data.arch, + 'model': data.model, + 'kernelVersion': data.kernelVersion, + 'osRelease': data.osRelease, + }; + } + + static Map _readWindowsDeviceInfo(WindowsDeviceInfo data) { + return { + 'majorVersion': data.majorVersion, + 'minorVersion': data.minorVersion, + 'buildNumber': data.buildNumber, + 'productType': data.productType, + 'productName': data.productName, + }; + } }