From d29bd9a04678762310e09aa19c68bffb3936ccc0 Mon Sep 17 00:00:00 2001 From: vishnukvmd Date: Sat, 24 Jul 2021 21:07:57 +0530 Subject: [PATCH] Set anonymized identifier for crashes --- lib/core/configuration.dart | 11 ++++++++++- pubspec.lock | 2 +- pubspec.yaml | 1 + thirdparty/super_logging/lib/super_logging.dart | 5 ++--- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/core/configuration.dart b/lib/core/configuration.dart index dbc1b1e2d..cafaf9ff5 100644 --- a/lib/core/configuration.dart +++ b/lib/core/configuration.dart @@ -24,6 +24,7 @@ import 'package:photos/services/sync_service.dart'; import 'package:photos/utils/crypto_util.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:super_logging/super_logging.dart'; +import 'package:uuid/uuid.dart'; class Configuration { Configuration._privateConstructor(); @@ -51,6 +52,7 @@ class Configuration { "has_migrated_secure_storage_to_first_unlock"; static const hasSelectedAllFoldersForBackupKey = "has_selected_all_folders_for_backup"; + static const anonymousUserIDKey = "anonymous_user_id"; final kTempFolderDeletionTimeBuffer = Duration(days: 1).inMicroseconds; @@ -105,8 +107,8 @@ class Configuration { iOptions: _secureStorageOptionsIOS, ); await _migrateSecurityStorageToFirstUnlock(); - SuperLogging.setUserID(getUserID()); } + SuperLogging.setUserID(await _getOrCreateAnonymousUserID()); } Future logout() async { @@ -514,4 +516,11 @@ class Configuration { hasMigratedSecureStorageToFirstUnlockKey, true); } } + + Future _getOrCreateAnonymousUserID() async { + if (!_preferences.containsKey(anonymousUserIDKey)) { + await _preferences.setString(anonymousUserIDKey, Uuid().v4()); + } + return _preferences.getString(anonymousUserIDKey); + } } diff --git a/pubspec.lock b/pubspec.lock index daeaca5bc..a5ec55a33 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1011,7 +1011,7 @@ packages: source: hosted version: "2.0.0" uuid: - dependency: transitive + dependency: "direct main" description: name: uuid url: "https://pub.dartlang.org" diff --git a/pubspec.yaml b/pubspec.yaml index 0238d616f..589c6122e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -88,6 +88,7 @@ dependencies: syncfusion_flutter_sliders: ^19.1.67-beta uni_links: ^0.5.1 url_launcher: ^6.0.3 + uuid: ^3.0.4 video_player: ^2.0.0 visibility_detector: ^0.2.0 wallpaper_manager_flutter: ^0.0.2 diff --git a/thirdparty/super_logging/lib/super_logging.dart b/thirdparty/super_logging/lib/super_logging.dart index 0c8daa913..6f6e59f94 100644 --- a/thirdparty/super_logging/lib/super_logging.dart +++ b/thirdparty/super_logging/lib/super_logging.dart @@ -182,9 +182,8 @@ class SuperLogging { } } - static void setUserID(int userID) { - Sentry.configureScope( - (scope) => scope.user = SentryUser(id: userID.toString())); + static void setUserID(String userID) { + Sentry.configureScope((scope) => scope.user = SentryUser(id: userID)); } static Future _sendErrorToSentry(Object error, StackTrace stack) async {