浏览代码

Set anonymized identifier for crashes

vishnukvmd 4 年之前
父节点
当前提交
d29bd9a046
共有 4 个文件被更改,包括 14 次插入5 次删除
  1. 10 1
      lib/core/configuration.dart
  2. 1 1
      pubspec.lock
  3. 1 0
      pubspec.yaml
  4. 2 3
      thirdparty/super_logging/lib/super_logging.dart

+ 10 - 1
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<void> logout() async {
@@ -514,4 +516,11 @@ class Configuration {
           hasMigratedSecureStorageToFirstUnlockKey, true);
     }
   }
+
+  Future<String> _getOrCreateAnonymousUserID() async {
+    if (!_preferences.containsKey(anonymousUserIDKey)) {
+      await _preferences.setString(anonymousUserIDKey, Uuid().v4());
+    }
+    return _preferences.getString(anonymousUserIDKey);
+  }
 }

+ 1 - 1
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"

+ 1 - 0
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

+ 2 - 3
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<void> _sendErrorToSentry(Object error, StackTrace stack) async {