π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Add legacy backup flow fallback when onlyNewPhotos flag disabled
Prateek Sunald5e6c6468a73
diff --git a/mobile/apps/photos/lib/ui/common/backup_flow_helper.dart b/mobile/apps/photos/lib/ui/common/backup_flow_helper.dartindex 9e6853f5ee..520441d183 100644--- a/mobile/apps/photos/lib/ui/common/backup_flow_helper.dart+++ b/mobile/apps/photos/lib/ui/common/backup_flow_helper.dart@@ -1,8 +1,10 @@+import "dart:async";import "dart:io";import "package:flutter/material.dart";import "package:logging/logging.dart";import "package:photo_manager/photo_manager.dart";+import "package:photos/generated/l10n.dart";import "package:photos/l10n/l10n.dart";import "package:photos/service_locator.dart";import "package:photos/ui/home/loading_photos_widget.dart";@@ -11,13 +13,21 @@ import "package:photos/utils/dialog_util.dart";import "package:photos/utils/navigation_util.dart";/// Helper to centralize navigation when users choose to add photos/backup.-/// [onFirstImportComplete] lets callers override the destination screen once-/// permissions are granted and initial import is done. Defaults to folder-/// selection.+///+/// [isFirstBackup] indicates if this is the first backup flow.+/// [askPermission] (only when onlyNewPhotos flag is disabled) controls whether+/// to request permissions before navigating.Future<void> handleBackupEntryFlow(BuildContext context, {bool isFirstBackup = false,+ bool askPermission = true,}) async {+ // When onlyNewPhotos flag is disabled, use the original simple flow+ if (!flagService.enableOnlyBackupFuturePhotos) {+ await _handleLegacyBackupFlow(context, askPermission: askPermission);+ return;+ }+PermissionState state;try {// Always fetch fresh permission state from the platform instead of relying@@ -33,19 +43,24 @@ Future<void> handleBackupEntryFlow(return;}+ // Permission denied or restricted - offer to open settingsif (state != PermissionState.authorized && state != PermissionState.limited) {- if (!context.mounted) {- return;- }-- if (Platform.isAndroid) {- // On Android, we can only direct users to system settings for upgrades.- await PhotoManager.openSetting();- return;- }+ if (!context.mounted) return;+ await showChoiceDialog(+ context,+ title: context.l10n.allowPermTitle,+ body: context.l10n.allowPermBody,+ firstButtonLabel: context.l10n.openSettings,+ firstButtonOnTap: () async {+ await PhotoManager.openSetting();+ },+ );+ return;+ }- // On iOS, offer a path to either open settings or expand limited access.- final bool hasLimited = state == PermissionState.limited;+ // iOS limited permission - offer to expand access or open settings+ if (state == PermissionState.limited && Platform.isIOS) {+ if (!context.mounted) return;await showChoiceActionSheet(context,title: context.l10n.preserveMore,@@ -54,30 +69,24 @@ Future<void> handleBackupEntryFlow(firstButtonOnTap: () async {await PhotoManager.openSetting();},- secondButtonLabel:- hasLimited ? context.l10n.selectMorePhotos : context.l10n.cancel,+ secondButtonLabel: context.l10n.selectMorePhotos,secondButtonOnTap: () async {- if (hasLimited) {- await PhotoManager.presentLimited();- }+ await PhotoManager.presentLimited();},);- return;+ // Fall through to folder selection after dialog}- if (!context.mounted) {- return;- }+ if (!context.mounted) return;- final bool didSkipPermissionOnboarding =- backupPreferenceService.hasSkippedOnboardingPermission;- // If the user skipped permission onboarding, still show the loading screen- // before navigating to folder selection; otherwise proceed directly.- if (didSkipPermissionOnboarding) {+ // If user skipped permission onboarding, show loading screen first+ // (LoadingPhotosWidget handles navigation to folder selection internally)+ if (backupPreferenceService.hasSkippedOnboardingPermission) {await routeToPage(context,const LoadingPhotosWidget(isOnboardingFlow: false),);+ return;}await routeToPage(@@ -87,3 +96,60 @@ Future<void> handleBackupEntryFlow(),);}++/// Legacy backup flow (pre-onlyNewPhotos feature).+/// Matches the original home_header_widget inline implementation.+Future<void> _handleLegacyBackupFlow(+ BuildContext context, {+ required bool askPermission,+}) async {+ if (askPermission) {+ try {+ final PermissionState state =+ await permissionService.requestPhotoMangerPermissions();+ await permissionService.onUpdatePermission(state);+ } on Exception catch (e) {+ Logger("HomeHeaderWidget").severe(+ "Failed to request permission: ${e.toString()}",+ e,+ );+ }+ }++ if (!permissionService.hasGrantedFullPermission()) {+ if (!context.mounted) return;+ if (Platform.isAndroid) {+ await PhotoManager.openSetting();+ } else {+ final bool hasGrantedLimit =+ permissionService.hasGrantedLimitedPermissions();+ // ignore: unawaited_futures+ showChoiceActionSheet(+ context,+ title: AppLocalizations.of(context).preserveMore,+ body: AppLocalizations.of(context).grantFullAccessPrompt,+ firstButtonLabel: AppLocalizations.of(context).openSettings,+ firstButtonOnTap: () async {+ await PhotoManager.openSetting();+ },+ secondButtonLabel: hasGrantedLimit+ ? AppLocalizations.of(context).selectMorePhotos+ : AppLocalizations.of(context).cancel,+ secondButtonOnTap: () async {+ if (hasGrantedLimit) {+ await PhotoManager.presentLimited();+ }+ },+ );+ }+ } else {+ unawaited(+ routeToPage(+ context,+ const BackupFolderSelectionPage(+ isFirstBackup: false,+ ),+ ),+ );+ }+}