From 9c8178653d3c4fbe82bf303943956b7c175dad6b Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Mon, 12 Feb 2018 10:00:20 -0500 Subject: [PATCH 1/2] Revisit TODOs in the SAE work. --- Signal/src/AppDelegate.m | 13 +++----- SignalServiceKit/src/Util/AppVersion.h | 7 +++-- SignalServiceKit/src/Util/AppVersion.m | 30 +++++++++++++++++++ .../ShareViewController.swift | 17 ++++------- .../utils/ShareAppExtensionContext.m | 2 +- 5 files changed, 46 insertions(+), 23 deletions(-) diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index f911c0cda..726ecf30b 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -554,12 +554,6 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; // and continue cleaning in the background. [[OWSDisappearingMessagesJob sharedJob] startIfNecessary]; - // TODO remove this once we're sure our app boot process is coherent. - // Currently this happens *before* db registration is complete when - // launching the app directly, but *after* db registration is complete when - // the app is launched in the background, e.g. from a voip notification. - [[OWSProfileManager sharedManager] ensureLocalProfileCached]; - // Mark all "attempting out" messages as "unsent", i.e. any messages that were not successfully // sent before the app exited should be marked as failures. [[[OWSFailedMessagesJob alloc] initWithStorageManager:[TSStorageManager sharedManager]] run]; @@ -993,6 +987,9 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; [OWSPreferences setIsRegistered:[TSAccountManager isRegistered]]; + // TODO: Once "app ready" logic is moved into AppSetup, move this line there. + [[OWSProfileManager sharedManager] ensureLocalProfileCached]; + // Note that this does much more than set a flag; // it will also run all deferred blocks. [AppReadiness setAppIsReady]; @@ -1013,7 +1010,7 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; [DeviceSleepManager.sharedInstance removeBlockWithBlockObject:self]; - [AppVersion.instance appLaunchDidComplete]; + [AppVersion.instance mainAppLaunchDidComplete]; [Environment.current.contactsManager loadSignalAccountsFromCache]; @@ -1021,8 +1018,6 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; [[OWSMessageReceiver sharedInstance] handleAnyUnprocessedEnvelopesAsync]; [[OWSBatchMessageProcessor sharedInstance] handleAnyUnprocessedEnvelopesAsync]; - [[OWSProfileManager sharedManager] ensureLocalProfileCached]; - #ifdef DEBUG // A bug in orphan cleanup could be disastrous so let's only diff --git a/SignalServiceKit/src/Util/AppVersion.h b/SignalServiceKit/src/Util/AppVersion.h index d5455f41a..df84b8b35 100755 --- a/SignalServiceKit/src/Util/AppVersion.h +++ b/SignalServiceKit/src/Util/AppVersion.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // @interface AppVersion : NSObject @@ -11,10 +11,13 @@ // Unlike lastAppVersion, this property isn't updated until // appLaunchDidComplete is called. @property (nonatomic, readonly) NSString *lastCompletedLaunchAppVersion; +@property (nonatomic, readonly) NSString *lastCompletedLaunchMainAppVersion; +@property (nonatomic, readonly) NSString *lastCompletedLaunchSAEAppVersion; + (instancetype)instance; -- (void)appLaunchDidComplete; +- (void)mainAppLaunchDidComplete; +- (void)saeLaunchDidComplete; - (BOOL)isFirstLaunch; diff --git a/SignalServiceKit/src/Util/AppVersion.m b/SignalServiceKit/src/Util/AppVersion.m index 863bfc79a..19f0b15ef 100755 --- a/SignalServiceKit/src/Util/AppVersion.m +++ b/SignalServiceKit/src/Util/AppVersion.m @@ -8,6 +8,10 @@ NSString *const kNSUserDefaults_FirstAppVersion = @"kNSUserDefaults_FirstAppVersion"; NSString *const kNSUserDefaults_LastAppVersion = @"kNSUserDefaults_LastVersion"; NSString *const kNSUserDefaults_LastCompletedLaunchAppVersion = @"kNSUserDefaults_LastCompletedLaunchAppVersion"; +NSString *const kNSUserDefaults_LastCompletedLaunchAppVersion_MainApp + = @"kNSUserDefaults_LastCompletedLaunchAppVersion_MainApp"; +NSString *const kNSUserDefaults_LastCompletedLaunchAppVersion_SAE + = @"kNSUserDefaults_LastCompletedLaunchAppVersion_SAE"; @interface AppVersion () @@ -15,6 +19,8 @@ NSString *const kNSUserDefaults_LastCompletedLaunchAppVersion = @"kNSUserDefault @property (nonatomic) NSString *lastAppVersion; @property (nonatomic) NSString *currentAppVersion; @property (nonatomic) NSString *lastCompletedLaunchAppVersion; +@property (nonatomic) NSString *lastCompletedLaunchMainAppVersion; +@property (nonatomic) NSString *lastCompletedLaunchSAEAppVersion; @end @@ -44,6 +50,10 @@ NSString *const kNSUserDefaults_LastCompletedLaunchAppVersion = @"kNSUserDefault self.lastAppVersion = [[NSUserDefaults appUserDefaults] objectForKey:kNSUserDefaults_LastAppVersion]; self.lastCompletedLaunchAppVersion = [[NSUserDefaults appUserDefaults] objectForKey:kNSUserDefaults_LastCompletedLaunchAppVersion]; + self.lastCompletedLaunchMainAppVersion = + [[NSUserDefaults appUserDefaults] objectForKey:kNSUserDefaults_LastCompletedLaunchAppVersion_MainApp]; + self.lastCompletedLaunchSAEAppVersion = + [[NSUserDefaults appUserDefaults] objectForKey:kNSUserDefaults_LastCompletedLaunchAppVersion_SAE]; // Ensure the value for the "first launched version". if (!self.firstAppVersion) { @@ -63,6 +73,8 @@ NSString *const kNSUserDefaults_LastCompletedLaunchAppVersion = @"kNSUserDefault [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]); DDLogInfo(@"%@ lastCompletedLaunchAppVersion: %@", self.logTag, self.lastCompletedLaunchAppVersion); + DDLogInfo(@"%@ lastCompletedLaunchMainAppVersion: %@", self.logTag, self.lastCompletedLaunchMainAppVersion); + DDLogInfo(@"%@ lastCompletedLaunchSAEAppVersion: %@", self.logTag, self.lastCompletedLaunchSAEAppVersion); } - (void)appLaunchDidComplete @@ -77,6 +89,24 @@ NSString *const kNSUserDefaults_LastCompletedLaunchAppVersion = @"kNSUserDefault [[NSUserDefaults appUserDefaults] synchronize]; } +- (void)mainAppLaunchDidComplete +{ + self.lastCompletedLaunchMainAppVersion = self.currentAppVersion; + [[NSUserDefaults appUserDefaults] setObject:self.currentAppVersion + forKey:kNSUserDefaults_LastCompletedLaunchAppVersion_MainApp]; + + [self appLaunchDidComplete]; +} + +- (void)saeLaunchDidComplete +{ + self.lastCompletedLaunchSAEAppVersion = self.currentAppVersion; + [[NSUserDefaults appUserDefaults] setObject:self.currentAppVersion + forKey:kNSUserDefaults_LastCompletedLaunchAppVersion_SAE]; + + [self appLaunchDidComplete]; +} + - (BOOL)isFirstLaunch { return self.firstAppVersion != nil; diff --git a/SignalShareExtension/ShareViewController.swift b/SignalShareExtension/ShareViewController.swift index d80c7ba19..595c6434d 100644 --- a/SignalShareExtension/ShareViewController.swift +++ b/SignalShareExtension/ShareViewController.swift @@ -50,8 +50,8 @@ public class ShareViewController: UIViewController, ShareViewDelegate, SAEFailed // We don't need to use DeviceSleepManager in the SAE. - // TODO: - // [UIUtil applySignalAppearence]; + // TODO: Do we need to applySignalAppearence in the SAE? + UIUtil.applySignalAppearence() if CurrentAppContext().isRunningTests { // TODO: Do we need to implement isRunningTests in the SAE context? @@ -154,12 +154,6 @@ public class ShareViewController: UIViewController, ShareViewDelegate, SAEFailed // We don't need to use OWSDisappearingMessagesJob in the SAE. - // TODO remove this once we're sure our app boot process is coherent. - // Currently this happens *before* db registration is complete when - // launching the app directly, but *after* db registration is complete when - // the app is launched in the background, e.g. from a voip notification. - OWSProfileManager.shared().ensureLocalProfileCached() - // We don't need to use OWSFailedMessagesJob in the SAE. // We don't need to use OWSFailedAttachmentDownloadsJob in the SAE. @@ -172,7 +166,6 @@ public class ShareViewController: UIViewController, ShareViewDelegate, SAEFailed // We don't need to prod the TSSocketManager in the SAE. } - // TODO: Do we want to move this logic into the notification handler for "SAE will appear". if TSAccountManager.isRegistered() { DispatchQueue.main.async { [weak self] in guard let strongSelf = self else { return } @@ -227,6 +220,9 @@ public class ShareViewController: UIViewController, ShareViewDelegate, SAEFailed Logger.debug("\(self.logTag) \(#function)") + // TODO: Once "app ready" logic is moved into AppSetup, move this line there. + OWSProfileManager.shared().ensureLocalProfileCached() + // Note that this does much more than set a flag; // it will also run all deferred blocks. AppReadiness.setAppIsReady() @@ -241,8 +237,7 @@ public class ShareViewController: UIViewController, ShareViewDelegate, SAEFailed // We don't need to use DeviceSleepManager in the SAE. - // TODO: Should we distinguish main app and SAE "completion"? - AppVersion.instance().appLaunchDidComplete() + AppVersion.instance().saeLaunchDidComplete() Environment.current().contactsManager.loadSignalAccountsFromCache() diff --git a/SignalShareExtension/utils/ShareAppExtensionContext.m b/SignalShareExtension/utils/ShareAppExtensionContext.m index 60dc26ae7..c73db5fc4 100644 --- a/SignalShareExtension/utils/ShareAppExtensionContext.m +++ b/SignalShareExtension/utils/ShareAppExtensionContext.m @@ -189,7 +189,7 @@ NS_ASSUME_NONNULL_BEGIN - (BOOL)isRunningTests { - // TODO: I don't think we'll need to distinguish this in the SAE. + // We don't need to distinguish this in the SAE. return NO; } From ba42ac73d8a3c8d590dc75fde625ad0de0d5c153 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Mon, 12 Feb 2018 10:28:38 -0500 Subject: [PATCH 2/2] Revisit TODOs in the SAE work. --- .../ViewControllers/ConversationView/Cells/OWSMessageCell.m | 2 +- SignalMessaging/profiles/ProfileFetcherJob.swift | 1 - SignalServiceKit/src/Storage/OWSStorage.h | 1 - SignalServiceKit/src/Storage/OWSStorage.m | 6 +++--- SignalServiceKit/src/Util/AppVersion.m | 1 - 5 files changed, 4 insertions(+), 7 deletions(-) diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageCell.m b/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageCell.m index f4da0f6c3..64c42b6bf 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageCell.m +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageCell.m @@ -1370,7 +1370,7 @@ const CGFloat OWSMessageCellCornerRadius = 17; OWSAssert(backupZipPath.length > 0); OWSBackupImportViewController *backupViewController = [OWSBackupImportViewController new]; - // TODO: Add support for restoring password-protected backups. + // There currently isn't any support for restoring password-protected backups. [backupViewController importBackup:backupZipPath password:nil]; UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:backupViewController]; diff --git a/SignalMessaging/profiles/ProfileFetcherJob.swift b/SignalMessaging/profiles/ProfileFetcherJob.swift index 8ccf253b3..93c88a52a 100644 --- a/SignalMessaging/profiles/ProfileFetcherJob.swift +++ b/SignalMessaging/profiles/ProfileFetcherJob.swift @@ -141,7 +141,6 @@ public class ProfileFetcherJob: NSObject { } } -// TODO: This was a struct. @objc public class SignalServiceProfile: NSObject { let TAG = "[SignalServiceProfile]" diff --git a/SignalServiceKit/src/Storage/OWSStorage.h b/SignalServiceKit/src/Storage/OWSStorage.h index 93a969340..39abc6472 100644 --- a/SignalServiceKit/src/Storage/OWSStorage.h +++ b/SignalServiceKit/src/Storage/OWSStorage.h @@ -50,7 +50,6 @@ extern NSString *const StorageIsReadyNotification; + (void)resetAllStorage; -// TODO: Deprecate? - (YapDatabaseConnection *)newDatabaseConnection; #ifdef DEBUG diff --git a/SignalServiceKit/src/Storage/OWSStorage.m b/SignalServiceKit/src/Storage/OWSStorage.m index 5b9b534e0..967588424 100644 --- a/SignalServiceKit/src/Storage/OWSStorage.m +++ b/SignalServiceKit/src/Storage/OWSStorage.m @@ -263,7 +263,7 @@ typedef NSData *_Nullable (^CreateDatabaseMetadataBlock)(void); // Try to reset app by deleting all databases. // // TODO: Possibly clean up all app files. - // [OWSStorage deleteDatabaseFiles]; + // [OWSStorage deleteDatabaseFiles]; if (![self tryToLoadDatabase]) { OWSFail(@"%@ Could not load database (second try)", self.logTag); @@ -599,8 +599,8 @@ typedef NSData *_Nullable (^CreateDatabaseMetadataBlock)(void); if (CurrentAppContext().isMainApp) { if (CurrentAppContext().isInBackground) { - // TODO: Rather than crash here, we should detect the situation earlier - // and exit gracefully - (in the app delegate?). See the ` + // Rather than crash here, we should have already detected the situation earlier + // and exited gracefully (in the app delegate) using isDatabasePasswordAccessible. // This is a last ditch effort to avoid blowing away the user's database. [self raiseKeySpecInaccessibleExceptionWithErrorDescription:errorDescription]; } diff --git a/SignalServiceKit/src/Util/AppVersion.m b/SignalServiceKit/src/Util/AppVersion.m index 19f0b15ef..a9bcd64a7 100755 --- a/SignalServiceKit/src/Util/AppVersion.m +++ b/SignalServiceKit/src/Util/AppVersion.m @@ -38,7 +38,6 @@ NSString *const kNSUserDefaults_LastCompletedLaunchAppVersion_SAE return instance; } -// TODO: Modify these NSUserDefaults keys for SAE. - (void)configure { self.currentAppVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];