diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index eb2176fc8..b342ab2ce 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -142,6 +142,11 @@ static NSTimeInterval launchStartedAt; return Environment.shared.windowManager; } +- (OWSBackup *)backup +{ + return AppEnvironment.shared.backup; +} + #pragma mark - - (void)applicationDidEnterBackground:(UIApplication *)application { @@ -547,6 +552,10 @@ static NSTimeInterval launchStartedAt; OWSFailDebug(@"app launch failed"); return NO; } + if (self.backup.hasPendingRestoreDecision) { + OWSLogInfo(@"Ignoring URL; pending restore decision."); + return NO; + } if (!AppReadiness.isAppReady) { OWSLogWarn(@"Ignoring openURL: app not ready."); @@ -744,6 +753,12 @@ static NSTimeInterval launchStartedAt; if (self.didAppLaunchFail) { OWSFailDebug(@"app launch failed"); + completionHandler(NO); + return; + } + if (self.backup.hasPendingRestoreDecision) { + OWSLogInfo(@"Ignoring shortcut action; pending restore decision."); + completionHandler(NO); return; } @@ -795,6 +810,10 @@ static NSTimeInterval launchStartedAt; OWSFailDebug(@"app launch failed"); return NO; } + if (self.backup.hasPendingRestoreDecision) { + OWSLogInfo(@"Ignoring user activity; pending restore decision."); + return NO; + } if ([userActivity.activityType isEqualToString:@"INStartVideoCallIntent"]) { if (!SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(10, 0)) { @@ -950,6 +969,10 @@ static NSTimeInterval launchStartedAt; OWSFailDebug(@"app launch failed"); return; } + if (self.backup.hasPendingRestoreDecision) { + OWSLogInfo(@"Ignoring remote notification; pending restore decision."); + return; + } // It is safe to continue even if the app isn't ready. [[PushManager sharedManager] application:application didReceiveRemoteNotification:userInfo]; @@ -964,6 +987,10 @@ static NSTimeInterval launchStartedAt; OWSFailDebug(@"app launch failed"); return; } + if (self.backup.hasPendingRestoreDecision) { + OWSLogInfo(@"Ignoring remote notification; pending restore decision."); + return; + } // It is safe to continue even if the app isn't ready. [[PushManager sharedManager] application:application @@ -978,6 +1005,10 @@ static NSTimeInterval launchStartedAt; OWSFailDebug(@"app launch failed"); return; } + if (self.backup.hasPendingRestoreDecision) { + OWSLogInfo(@"Ignoring local notification; pending restore decision."); + return; + } OWSLogInfo(@"%@", notification); [AppReadiness runNowOrWhenAppDidBecomeReady:^{ @@ -994,6 +1025,12 @@ static NSTimeInterval launchStartedAt; if (self.didAppLaunchFail) { OWSFailDebug(@"app launch failed"); + completionHandler(); + return; + } + if (self.backup.hasPendingRestoreDecision) { + OWSLogInfo(@"Ignoring action; pending restore decision."); + completionHandler(); return; } @@ -1023,6 +1060,12 @@ static NSTimeInterval launchStartedAt; if (self.didAppLaunchFail) { OWSFailDebug(@"app launch failed"); + completionHandler(); + return; + } + if (self.backup.hasPendingRestoreDecision) { + OWSLogInfo(@"Ignoring action; pending restore decision."); + completionHandler(); return; } @@ -1220,18 +1263,21 @@ static NSTimeInterval launchStartedAt; NSTimeInterval startupDuration = CACurrentMediaTime() - launchStartedAt; OWSLogInfo(@"Presenting app %.2f seconds after launch started.", startupDuration); + UIViewController *rootViewController; if ([self.tsAccountManager isRegistered]) { - HomeViewController *homeView = [HomeViewController new]; - SignalsNavigationController *navigationController = - [[SignalsNavigationController alloc] initWithRootViewController:homeView]; - self.window.rootViewController = navigationController; + if (self.backup.hasPendingRestoreDecision) { + rootViewController = [BackupRestoreViewController new]; + } else { + rootViewController = [HomeViewController new]; + } } else { - RegistrationViewController *viewController = [RegistrationViewController new]; - OWSNavigationController *navigationController = - [[OWSNavigationController alloc] initWithRootViewController:viewController]; - navigationController.navigationBarHidden = YES; - self.window.rootViewController = navigationController; + rootViewController = [RegistrationViewController new]; } + OWSAssertDebug(rootViewController); + OWSNavigationController *navigationController = + [[OWSNavigationController alloc] initWithRootViewController:rootViewController]; + navigationController.navigationBarHidden = YES; + self.window.rootViewController = navigationController; [AppUpdateNag.sharedInstance showAppUpgradeNagIfNecessary]; } diff --git a/Signal/src/ViewControllers/ProfileViewController.m b/Signal/src/ViewControllers/ProfileViewController.m index 3033236d3..6b2a3cf5a 100644 --- a/Signal/src/ViewControllers/ProfileViewController.m +++ b/Signal/src/ViewControllers/ProfileViewController.m @@ -426,9 +426,6 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat { OWSLogVerbose(@""); - [self checkCanImportBackup]; - return; - // Dismiss this view. switch (self.profileViewMode) { case ProfileViewMode_AppSettings: diff --git a/Signal/src/ViewControllers/Registration/BackupRestoreViewController.swift b/Signal/src/ViewControllers/Registration/BackupRestoreViewController.swift index 1c3c90d41..b438027f7 100644 --- a/Signal/src/ViewControllers/Registration/BackupRestoreViewController.swift +++ b/Signal/src/ViewControllers/Registration/BackupRestoreViewController.swift @@ -115,18 +115,27 @@ public class BackupRestoreViewController: OWSTableViewController { backup.setHasPendingRestoreDecision(false) - self.dismiss(animated: true) + dismiss(animated: true) } @objc private func startImport() { Logger.info("") + hasBegunImport = true + backup.tryToImport() } private func showHomeView() { - SignalApp.shared().showHomeView() + let isModal = navigationController?.presentingViewController != nil + if isModal { + dismiss(animated: true, completion: { + SignalApp.shared().showHomeView() + }) + } else { + SignalApp.shared().showHomeView() + } } // MARK: - Notifications @@ -134,7 +143,12 @@ public class BackupRestoreViewController: OWSTableViewController { @objc func backupStateDidChange() { AssertIsOnMainThread() + Logger.verbose("backup.backupImportState: \(NSStringForBackupImportState(backup.backupImportState))") + Logger.flush() + if backup.backupImportState == .succeeded { + backup.setHasPendingRestoreDecision(false) + showHomeView() } else { updateTableContents() diff --git a/Signal/src/util/Backup/OWSBackup.m b/Signal/src/util/Backup/OWSBackup.m index e3bf372dc..4fb283655 100644 --- a/Signal/src/util/Backup/OWSBackup.m +++ b/Signal/src/util/Backup/OWSBackup.m @@ -259,6 +259,11 @@ NSString *NSStringForBackupImportState(OWSBackupState state) if (!self.isBackupEnabled) { return NO; } + if (self.hasPendingRestoreDecision) { + // Don't backup while awaiting user decision about + // whether to import previous backup. + return NO; + } if (UIApplication.sharedApplication.applicationState != UIApplicationStateActive) { // Don't start backups when app is in the background. return NO; diff --git a/Signal/translations/en.lproj/Localizable.strings b/Signal/translations/en.lproj/Localizable.strings index 2e2c9629f..5bae7843b 100644 --- a/Signal/translations/en.lproj/Localizable.strings +++ b/Signal/translations/en.lproj/Localizable.strings @@ -234,13 +234,13 @@ "BACKUP_RESTORE_DECISION_TITLE" = "Backup Available"; /* Label for the backup restore description. */ -"BACKUP_RESTORE_DESCRIPTION" = "BACKUP_RESTORE_DESCRIPTION"; +"BACKUP_RESTORE_DESCRIPTION" = "Restoring Backup"; /* Label for the backup restore progress. */ -"BACKUP_RESTORE_PROGRESS" = "BACKUP_RESTORE_PROGRESS"; +"BACKUP_RESTORE_PROGRESS" = "Progress"; /* Label for the backup restore status. */ -"BACKUP_RESTORE_STATUS" = "BACKUP_RESTORE_STATUS"; +"BACKUP_RESTORE_STATUS" = "Status"; /* An explanation of the consequences of blocking a group. */ "BLOCK_GROUP_BEHAVIOR_EXPLANATION" = "You will no longer receive messages or updates from this group.";