π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mob] Show verification banner after 3 days
Neeraj Gupta976634f8c725
diff --git a/mobile/lib/service_locator.dart b/mobile/lib/service_locator.dartindex d33bef747e..f056258598 100644--- a/mobile/lib/service_locator.dart+++ b/mobile/lib/service_locator.dart@@ -13,7 +13,6 @@ import "package:photos/services/magic_cache_service.dart";import "package:photos/services/storage_bonus_service.dart";import "package:photos/services/trash_sync_service.dart";import "package:photos/services/update_service.dart";-import "package:photos/services/user_remote_flag_service.dart";import "package:photos/utils/local_settings.dart";import "package:shared_preferences/shared_preferences.dart";@@ -101,15 +100,6 @@ LocationService get locationService {return _locationService!;}-UserRemoteFlagService? _userRemoteFlagService;-UserRemoteFlagService get userRemoteFlagService {- _userRemoteFlagService ??= UserRemoteFlagService(- ServiceLocator.instance.enteDio,- ServiceLocator.instance.prefs,- );- return _userRemoteFlagService!;-}-MagicCacheService? _magicCacheService;MagicCacheService get magicCacheService {_magicCacheService ??= MagicCacheService(diff --git a/mobile/lib/services/user_remote_flag_service.dart b/mobile/lib/services/user_remote_flag_service.dartdeleted file mode 100644index 0c8961fbd1..0000000000--- a/mobile/lib/services/user_remote_flag_service.dart+++ /dev/null@@ -1,122 +0,0 @@-import 'dart:async';-import 'dart:io';--import 'package:collection/collection.dart';-import "package:dio/dio.dart";-import "package:flutter/foundation.dart";-import 'package:logging/logging.dart';-import 'package:photos/core/event_bus.dart';-import 'package:photos/events/notification_event.dart';-import 'package:photos/services/user_service.dart';-import 'package:shared_preferences/shared_preferences.dart';--class UserRemoteFlagService {- final Dio _enteDio;- late final _logger = Logger((UserRemoteFlagService).toString());- final SharedPreferences _prefs;-- static const String recoveryVerificationFlag = "recoveryKeyVerified";- static const String needRecoveryKeyVerification =- "needRecoveryKeyVerification";-- UserRemoteFlagService(this._enteDio, this._prefs) {- debugPrint("UserRemoteFlagService constructor");- }-- bool shouldShowRecoveryVerification() {- if (!_prefs.containsKey(needRecoveryKeyVerification)) {- // fetch the status from remote- _refreshRecoveryVerificationFlag().ignore();- return false;- } else {- final bool shouldShow = _prefs.getBool(needRecoveryKeyVerification)!;- if (shouldShow) {- // refresh the status to check if user marked it as done on another device- _refreshRecoveryVerificationFlag().ignore();- }- return shouldShow;- }- }-- // markRecoveryVerificationAsDone is used to track if user has verified their- // recovery key in the past or not. This helps in avoid showing the same- // prompt to the user on re-install or signing into a different device- Future<void> markRecoveryVerificationAsDone() async {- await _updateKeyValue(recoveryVerificationFlag, true.toString());- await _prefs.setBool(needRecoveryKeyVerification, false);- }-- Future<void> _refreshRecoveryVerificationFlag() async {- _logger.finest('refresh recovery key verification flag');- final remoteStatusValue =- await _getValue(recoveryVerificationFlag, "false");- final bool isNeedVerificationFlagSet =- _prefs.containsKey(needRecoveryKeyVerification);- if (remoteStatusValue.toLowerCase() == "true") {- await _prefs.setBool(needRecoveryKeyVerification, false);- // If the user verified on different device, then we should refresh- // the UI to dismiss the Notification.- if (isNeedVerificationFlagSet) {- Bus.instance.fire(NotificationEvent());- }- } else if (!isNeedVerificationFlagSet) {- // Verification is not done yet as remoteStatus is false and local flag to- // show notification isn't set. Set the flag to true if any active- // session is older than 1 day.- final activeSessions = await UserService.instance.getActiveSessions();- final int microSecondsInADay = const Duration(days: 1).inMicroseconds;- final bool anyActiveSessionOlderThanADay =- activeSessions.sessions.firstWhereOrNull(- (e) =>- (e.creationTime + microSecondsInADay) <- DateTime.now().microsecondsSinceEpoch,- ) !=- null;- if (anyActiveSessionOlderThanADay) {- await _prefs.setBool(needRecoveryKeyVerification, true);- Bus.instance.fire(NotificationEvent());- } else {- // continue defaulting to no verification prompt- _logger.finest('No active session older than 1 day');- }- }- }-- Future<String> _getValue(String key, String? defaultValue) async {- try {- final Map<String, dynamic> queryParams = {"key": key};- if (defaultValue != null) {- queryParams["defaultValue"] = defaultValue;- }- final response =- await _enteDio.get("/remote-store", queryParameters: queryParams);- if (response.statusCode != HttpStatus.ok) {- throw Exception("Unexpected status code ${response.statusCode}");- }- return response.data["value"];- } catch (e) {- _logger.info("Error while fetching bool status for $key", e);- rethrow;- }- }-- // _setBooleanFlag sets the corresponding flag on remote- // to mark recovery as completed- Future<void> _updateKeyValue(String key, String value) async {- try {- final response = await _enteDio.post(- "/remote-store/update",- data: {- "key": key,- "value": value,- },- );- if (response.statusCode != HttpStatus.ok) {- throw Exception("Unexpected state");- }- } catch (e) {- _logger.warning("Failed to set flag for $key", e);- rethrow;- }- }-}diff --git a/mobile/lib/ui/account/verify_recovery_page.dart b/mobile/lib/ui/account/verify_recovery_page.dartindex 573f351828..94a289089b 100644--- a/mobile/lib/ui/account/verify_recovery_page.dart+++ b/mobile/lib/ui/account/verify_recovery_page.dart@@ -40,7 +40,7 @@ class _VerifyRecoveryPageState extends State<VerifyRecoveryPage> {final String recoveryKeyWords = bip39.entropyToMnemonic(recoveryKey);if (inputKey == recoveryKey || inputKey == recoveryKeyWords) {try {- await userRemoteFlagService.markRecoveryVerificationAsDone();+ await flagService.setRecoveryKeyVerified(true);} catch (e) {await dialog.hide();if (e is DioException && e.type == DioExceptionType.connectionError) {diff --git a/mobile/lib/ui/home/status_bar_widget.dart b/mobile/lib/ui/home/status_bar_widget.dartindex a36f2f75a5..56f46cbb53 100644--- a/mobile/lib/ui/home/status_bar_widget.dart+++ b/mobile/lib/ui/home/status_bar_widget.dart@@ -112,7 +112,6 @@ class _StatusBarWidgetState extends State<StatusBarWidget> {_subscription.cancel();_notificationSubscription.cancel();_previewSubscription.cancel();-super.dispose();}@@ -176,9 +175,7 @@ class _StatusBarWidgetState extends State<StatusBarWidget> {),): const SizedBox.shrink(),- userRemoteFlagService.shouldShowRecoveryVerification() &&- !_showErrorBanner &&- !_showMlBanner+ _showVerificationBanner()? Padding(padding:const EdgeInsets.symmetric(horizontal: 16.0, vertical: 12),@@ -200,6 +197,17 @@ class _StatusBarWidgetState extends State<StatusBarWidget> {],);}++ // _showVerificationBanner after 3 days of installation+ bool _showVerificationBanner() {+ if (_showErrorBanner ||+ _showErrorBanner ||+ flagService.recoveryKeyVerified) {+ return false;+ }+ final DateTime installTime = localSettings.getInstallDateTime();+ return DateTime.now().difference(installTime).inDays >= 3;+ }}class SyncStatusWidget extends StatefulWidget {diff --git a/mobile/lib/utils/local_settings.dart b/mobile/lib/utils/local_settings.dartindex 204db7d3ca..8ca37cd29b 100644--- a/mobile/lib/utils/local_settings.dart+++ b/mobile/lib/utils/local_settings.dart@@ -22,6 +22,7 @@ class LocalSettings {"has_configured_links_in_app_permission";static const _hideSharedItemsFromHomeGalleryTag ="hide_shared_items_from_home_gallery";+ static const _installTimeKey = "install_time";final SharedPreferences _prefs;@@ -55,6 +56,20 @@ class LocalSettings {}}+ // getEstimatedInstallTimeInMs returns the time when the app was installed+ // The time is stored in shared preferences and will be reset on logout+ DateTime getInstallDateTime() {+ if (_prefs.containsKey('install_time')) {+ return DateTime.fromMillisecondsSinceEpoch(+ _prefs.getInt('install_time')!,+ );+ } else {+ final installTime = DateTime.now();+ _prefs.setInt('install_time', installTime.millisecondsSinceEpoch);+ return installTime;+ }+ }+Future<void> setRateUsShownCount(int value) async {await _prefs.setInt(kRateUsShownCount, value);}diff --git a/mobile/plugins/ente_feature_flag/lib/src/service.dart b/mobile/plugins/ente_feature_flag/lib/src/service.dartindex b6e99eb0b5..c89dea719b 100644--- a/mobile/plugins/ente_feature_flag/lib/src/service.dart+++ b/mobile/plugins/ente_feature_flag/lib/src/service.dart@@ -70,6 +70,11 @@ class FlagService {_updateFlags(flags.copyWith(faceSearchEnabled: isEnabled));}+ Future<void> setRecoveryKeyVerified(bool isVerified) async {+ await _updateKeyValue("recoveryKeyVerified", isVerified.toString());+ _updateFlags(flags.copyWith(recoveryKeyVerified: isVerified));+ }+Completer<void>? _fetchCompleter;Future<void> _fetch() async {if (_fetchCompleter != null) {