Add app version and device info to error report

OmarHatem committed Feb 20, 2023 at 22:17 UTC 7b35604ff586ecd7d040a5a941bdd60aa6f5827f
5 files changed +90 -6
android/build.gradle
+1 -1
@@ -1,5 +1,5 @@
1 buildscript {
2 - ext.kotlin_version = '1.5.10'
2 + ext.kotlin_version = '1.6.21'
3 repositories {
4 google()
5 jcenter()
android/gradle/wrapper/gradle-wrapper.properties
+1 -1
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
3 distributionPath=wrapper/dists
4 zipStoreBase=GRADLE_USER_HOME
5 zipStorePath=wrapper/dists
6 -distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
6 +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip
cw_haven/pubspec.yaml
+1 -1
@@ -12,7 +12,7 @@ environment:
12 dependencies:
13 flutter:
14 sdk: flutter
15 - ffi: ^1.1.2
15 + ffi: ^2.0.1
16 http: ^0.13.4
17 path_provider: ^2.0.11
18 mobx: ^2.0.7+4
cw_monero/pubspec.yaml
+1 -1
@@ -12,7 +12,7 @@ environment:
12 dependencies:
13 flutter:
14 sdk: flutter
15 - ffi: ^1.1.2
15 + ffi: ^2.0.1
16 http: ^0.13.4
17 path_provider: ^2.0.11
18 mobx: ^2.0.7+4
lib/utils/exception_handler.dart
+86 -2
@@ -1,4 +1,3 @@
1 -import 'dart:convert';
1 import 'dart:io';
2
3 import 'package:cake_wallet/entities/preferences_key.dart';
@@ -6,9 +5,11 @@ import 'package:cake_wallet/generated/i18n.dart';
5 import 'package:cake_wallet/main.dart';
6 import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart';
7 import 'package:cake_wallet/utils/show_pop_up.dart';
8 +import 'package:device_info_plus/device_info_plus.dart';
9 import 'package:flutter/foundation.dart';
10 import 'package:flutter/material.dart';
11 import 'package:flutter_mailer/flutter_mailer.dart';
12 +import 'package:package_info/package_info.dart';
13 import 'package:path_provider/path_provider.dart';
14 import 'package:shared_preferences/shared_preferences.dart';
15
@@ -31,7 +32,7 @@ class ExceptionHandler {
32 ==========================================================\n\n''';
33
34 await file.writeAsString(
34 - jsonEncode(exception) + separator,
35 + "$exception $separator",
36 mode: FileMode.append,
37 );
38 }
@@ -42,6 +43,8 @@ class ExceptionHandler {
43
44 final file = File('${appDocDir.path}/error.txt');
45
46 + await _addDeviceInfo(file);
47 +
48 final MailOptions mailOptions = MailOptions(
49 subject: 'Mobile App Issue',
50 recipients: ['support@cakewallet.com'],
@@ -130,4 +133,85 @@ class ExceptionHandler {
133 "errno = 28", // OS Error: No space left on device
134 "PERMISSION_NOT_GRANTED",
135 ];
136 +
137 + static Future<void> _addDeviceInfo(File file) async {
138 + final packageInfo = await PackageInfo.fromPlatform();
139 + final currentVersion = packageInfo.version;
140 +
141 + final deviceInfoPlugin = DeviceInfoPlugin();
142 + Map<String, dynamic> deviceInfo = {};
143 +
144 + if (Platform.isAndroid) {
145 + deviceInfo = _readAndroidBuildData(await deviceInfoPlugin.androidInfo);
146 + deviceInfo["Platform"] = "Android";
147 + } else if (Platform.isIOS) {
148 + deviceInfo = _readIosDeviceInfo(await deviceInfoPlugin.iosInfo);
149 + deviceInfo["Platform"] = "iOS";
150 + } else if (Platform.isLinux) {
151 + deviceInfo = _readLinuxDeviceInfo(await deviceInfoPlugin.linuxInfo);
152 + deviceInfo["Platform"] = "Linux";
153 + } else if (Platform.isMacOS) {
154 + deviceInfo = _readMacOsDeviceInfo(await deviceInfoPlugin.macOsInfo);
155 + deviceInfo["Platform"] = "MacOS";
156 + } else if (Platform.isWindows) {
157 + deviceInfo = _readWindowsDeviceInfo(await deviceInfoPlugin.windowsInfo);
158 + deviceInfo["Platform"] = "Windows";
159 + }
160 +
161 + await file.writeAsString(
162 + "App Version: $currentVersion\n\nDevice Info $deviceInfo",
163 + mode: FileMode.append,
164 + );
165 + }
166 +
167 + static Map<String, dynamic> _readAndroidBuildData(AndroidDeviceInfo build) {
168 + return <String, dynamic>{
169 + 'brand': build.brand,
170 + 'device': build.device,
171 + 'manufacturer': build.manufacturer,
172 + 'model': build.model,
173 + 'product': build.product,
174 + };
175 + }
176 +
177 + static Map<String, dynamic> _readIosDeviceInfo(IosDeviceInfo data) {
178 + return <String, dynamic>{
179 + 'systemName': data.systemName,
180 + 'systemVersion': data.systemVersion,
181 + 'model': data.model,
182 + 'localizedModel': data.localizedModel,
183 + };
184 + }
185 +
186 + static Map<String, dynamic> _readLinuxDeviceInfo(LinuxDeviceInfo data) {
187 + return <String, dynamic>{
188 + 'name': data.name,
189 + 'version': data.version,
190 + 'versionCodename': data.versionCodename,
191 + 'versionId': data.versionId,
192 + 'prettyName': data.prettyName,
193 + 'buildId': data.buildId,
194 + 'variant': data.variant,
195 + 'variantId': data.variantId,
196 + };
197 + }
198 +
199 + static Map<String, dynamic> _readMacOsDeviceInfo(MacOsDeviceInfo data) {
200 + return <String, dynamic>{
201 + 'arch': data.arch,
202 + 'model': data.model,
203 + 'kernelVersion': data.kernelVersion,
204 + 'osRelease': data.osRelease,
205 + };
206 + }
207 +
208 + static Map<String, dynamic> _readWindowsDeviceInfo(WindowsDeviceInfo data) {
209 + return <String, dynamic>{
210 + 'majorVersion': data.majorVersion,
211 + 'minorVersion': data.minorVersion,
212 + 'buildNumber': data.buildNumber,
213 + 'productType': data.productType,
214 + 'productName': data.productName,
215 + };
216 + }
217 }