From c7426f9343cf84a518ad46612c5ab3a10846c58c Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Thu, 15 Jun 2017 13:43:18 -0400 Subject: [PATCH] Avoid crashing on startup due to database view creation. * Substitute unread view for unseen view until unseen view is ready. * Register as many views as possible async. * Perform blocking, safe migrations before async registration of views. * Add debug settings view for internal app stats. * Show blocking overlay until async registration of database views is complete. * Convert version migrations to use AppVersions. // FREEBIE --- Podfile | 4 +- Podfile.lock | 9 +- Signal.xcodeproj/project.pbxproj | 6 ++ Signal/src/AppDelegate.m | 83 ++++++++++++++++++- .../ConversationView/MessagesViewController.m | 2 +- .../DebugSettingsTableViewController.h | 9 ++ .../DebugSettingsTableViewController.m | 75 +++++++++++++++++ .../ViewControllers/DebugUI/DebugUIMessages.m | 6 +- .../ViewControllers/OWSTableViewController.h | 2 + .../ViewControllers/OWSTableViewController.m | 16 ++++ .../SettingsTableViewController.m | 14 ++++ .../Migrations/OWSDatabaseMigrationRunner.h | 14 +++- .../Migrations/OWSDatabaseMigrationRunner.m | 16 +++- .../src/environment/PropertyListPreferences.h | 2 - .../src/environment/PropertyListPreferences.m | 15 ---- Signal/src/environment/VersionMigrations.h | 12 +-- Signal/src/environment/VersionMigrations.m | 14 ++-- Signal/src/util/ThreadUtil.m | 6 +- .../translations/en.lproj/Localizable.strings | 3 + 19 files changed, 263 insertions(+), 45 deletions(-) create mode 100644 Signal/src/ViewControllers/DebugSettingsTableViewController.h create mode 100644 Signal/src/ViewControllers/DebugSettingsTableViewController.m diff --git a/Podfile b/Podfile index 64c1915dc..a33208ad2 100644 --- a/Podfile +++ b/Podfile @@ -5,8 +5,8 @@ target 'Signal' do pod 'SocketRocket', :git => 'https://github.com/facebook/SocketRocket.git' pod 'AxolotlKit', git: 'https://github.com/WhisperSystems/SignalProtocolKit.git' #pod 'AxolotlKit', path: '../SignalProtocolKit' - pod 'SignalServiceKit', git: 'https://github.com/WhisperSystems/SignalServiceKit.git' - #pod 'SignalServiceKit', path: '../SignalServiceKit' + #pod 'SignalServiceKit', git: 'https://github.com/WhisperSystems/SignalServiceKit.git' + pod 'SignalServiceKit', path: '../SignalServiceKit' pod 'JSQMessagesViewController', git: 'https://github.com/WhisperSystems/JSQMessagesViewController.git', branch: 'mkirk/position-edit-menu' #pod 'JSQMessagesViewController' path: '../JSQMessagesViewController' pod 'PureLayout' diff --git a/Podfile.lock b/Podfile.lock index 42313d4c2..a26c97191 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -112,7 +112,7 @@ DEPENDENCIES: - JSQMessagesViewController (from `https://github.com/WhisperSystems/JSQMessagesViewController.git`, branch `mkirk/position-edit-menu`) - PureLayout - Reachability - - SignalServiceKit (from `https://github.com/WhisperSystems/SignalServiceKit.git`) + - SignalServiceKit (from `../SignalServiceKit`) - SocketRocket (from `https://github.com/facebook/SocketRocket.git`) EXTERNAL SOURCES: @@ -122,7 +122,7 @@ EXTERNAL SOURCES: :branch: mkirk/position-edit-menu :git: https://github.com/WhisperSystems/JSQMessagesViewController.git SignalServiceKit: - :git: https://github.com/WhisperSystems/SignalServiceKit.git + :path: ../SignalServiceKit SocketRocket: :git: https://github.com/facebook/SocketRocket.git @@ -133,9 +133,6 @@ CHECKOUT OPTIONS: JSQMessagesViewController: :commit: 7054e4b13ee5bcd6d524adb6dc9a726e8c466308 :git: https://github.com/WhisperSystems/JSQMessagesViewController.git - SignalServiceKit: - :commit: 96dc0e4fdb3cf8c99a64230814c849ed0968c087 - :git: https://github.com/WhisperSystems/SignalServiceKit.git SocketRocket: :commit: 877ac7438be3ad0b45ef5ca3969574e4b97112bf :git: https://github.com/facebook/SocketRocket.git @@ -161,6 +158,6 @@ SPEC CHECKSUMS: UnionFind: c33be5adb12983981d6e827ea94fc7f9e370f52d YapDatabase: cd911121580ff16675f65ad742a9eb0ab4d9e266 -PODFILE CHECKSUM: 89fd7aee1e2b0ca592ecc9dba0389e57b70f959b +PODFILE CHECKSUM: 6e5d90a9603eb043b395213fd8a29037d2276a8f COCOAPODS: 1.2.1 diff --git a/Signal.xcodeproj/project.pbxproj b/Signal.xcodeproj/project.pbxproj index a8de933c9..ef4dce017 100644 --- a/Signal.xcodeproj/project.pbxproj +++ b/Signal.xcodeproj/project.pbxproj @@ -72,6 +72,7 @@ 34B3F89C1E8DF3270035BE1A /* BlockListViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34B3F89B1E8DF3270035BE1A /* BlockListViewController.m */; }; 34B3F89F1E8DF5490035BE1A /* OWSTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34B3F89E1E8DF5490035BE1A /* OWSTableViewController.m */; }; 34B3F8A21E8EA6040035BE1A /* ViewControllerUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 34B3F8A11E8EA6040035BE1A /* ViewControllerUtils.m */; }; + 34B7F3691EF2DB2E0083AF1C /* DebugSettingsTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34B7F3681EF2DB2E0083AF1C /* DebugSettingsTableViewController.m */; }; 34D5CC961EA6AFAD005515DB /* OWSContactsSyncing.m in Sources */ = {isa = PBXBuildFile; fileRef = 34D5CC951EA6AFAD005515DB /* OWSContactsSyncing.m */; }; 34D5CCA91EAE3D30005515DB /* GroupViewHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 34D5CCA81EAE3D30005515DB /* GroupViewHelper.m */; }; 34D5CCB11EAE7E7F005515DB /* SelectRecipientViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34D5CCB01EAE7E7F005515DB /* SelectRecipientViewController.m */; }; @@ -475,6 +476,8 @@ 34B3F89E1E8DF5490035BE1A /* OWSTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSTableViewController.m; sourceTree = ""; }; 34B3F8A01E8EA6040035BE1A /* ViewControllerUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ViewControllerUtils.h; sourceTree = ""; }; 34B3F8A11E8EA6040035BE1A /* ViewControllerUtils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ViewControllerUtils.m; sourceTree = ""; }; + 34B7F3671EF2DB2E0083AF1C /* DebugSettingsTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DebugSettingsTableViewController.h; sourceTree = ""; }; + 34B7F3681EF2DB2E0083AF1C /* DebugSettingsTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DebugSettingsTableViewController.m; sourceTree = ""; }; 34D5CC941EA6AFAD005515DB /* OWSContactsSyncing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSContactsSyncing.h; sourceTree = ""; }; 34D5CC951EA6AFAD005515DB /* OWSContactsSyncing.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSContactsSyncing.m; sourceTree = ""; }; 34D5CC981EA6EB79005515DB /* OWSMessageCollectionViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSMessageCollectionViewCell.h; sourceTree = ""; }; @@ -927,6 +930,8 @@ 3448BFC01EDF0EA7005B2D69 /* ConversationView */, 34B3F8401E8DF1700035BE1A /* CountryCodeViewController.h */, 34B3F8411E8DF1700035BE1A /* CountryCodeViewController.m */, + 34B7F3671EF2DB2E0083AF1C /* DebugSettingsTableViewController.h */, + 34B7F3681EF2DB2E0083AF1C /* DebugSettingsTableViewController.m */, 34D8C0221ED3673300188D7C /* DebugUI */, 3497DBED1ECE2E4700DB2605 /* DomainFrontingCountryViewController.h */, 3497DBEE1ECE2E4700DB2605 /* DomainFrontingCountryViewController.m */, @@ -2079,6 +2084,7 @@ 34B3F8791E8DF1700035BE1A /* CountryCodeViewController.m in Sources */, 4CE0E3771B954546007210CF /* TSAnimatedAdapter.m in Sources */, 4531C9C41DD8E6D800F08304 /* JSQMessagesCollectionViewCell+OWS.m in Sources */, + 34B7F3691EF2DB2E0083AF1C /* DebugSettingsTableViewController.m in Sources */, 4542F0961EBB9E9A00C7EE92 /* Promise+retainUntilComplete.swift in Sources */, 4516E3FF1DD2193B00DC4206 /* OWS101ExistingUsersBlockOnIdentityChange.m in Sources */, 4505C2BF1E648EA300CEBF41 /* ExperienceUpgrade.swift in Sources */, diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index 69bec2e1d..b85880b31 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -27,6 +27,7 @@ #import #import #import +#import #import #import #import @@ -44,7 +45,8 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; @interface AppDelegate () -@property (nonatomic, retain) UIWindow *screenProtectionWindow; +@property (nonatomic) UIWindow *screenProtectionWindow; +@property (nonatomic) UIWindow *databaseViewRegistrationOverlay; @property (nonatomic) OWSIncomingMessageReadObserver *incomingMessageReadObserver; @property (nonatomic) OWSStaleNotificationObserver *staleNotificationObserver; @property (nonatomic) OWSContactsSyncing *contactsSyncing; @@ -188,6 +190,11 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; self.contactsSyncing = [[OWSContactsSyncing alloc] initWithContactsManager:[Environment getCurrent].contactsManager messageSender:[Environment getCurrent].messageSender]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(databaseViewRegistrationComplete) + name:kNSNotificationName_DatabaseViewRegistrationComplete + object:nil]; + return YES; } @@ -205,7 +212,9 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; notificationsManager:[Environment getCurrent].notificationsManager]; [TextSecureKitEnv setSharedEnv:sharedEnv]; - [[TSStorageManager sharedManager] setupDatabase]; + [[TSStorageManager sharedManager] setupDatabaseWithSafeBlockingMigrations:^{ + [VersionMigrations runSafeBlockingMigrations]; + }]; self.incomingMessageReadObserver = [[OWSIncomingMessageReadObserver alloc] initWithStorageManager:[TSStorageManager sharedManager] @@ -408,6 +417,8 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; [self removeScreenProtection]; + [self ensureDatabaseViewRegistrationOverlay]; + // Always check prekeys after app launches, and sometimes check on app activation. [TSPreKeyManager checkPreKeysIfNecessary]; } @@ -674,6 +685,74 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; } } +- (void)databaseViewRegistrationComplete +{ + DDLogInfo(@"databaseViewRegistrationComplete"); + + [self ensureDatabaseViewRegistrationOverlay]; +} + +- (void)ensureDatabaseViewRegistrationOverlay +{ + BOOL shouldShowOverlay = [TSDatabaseView hasPendingViewRegistrations]; + + if (!shouldShowOverlay) { + if (self.databaseViewRegistrationOverlay && !self.databaseViewRegistrationOverlay.hidden) { + DDLogWarn(@"Hiding database view registration overlay."); + } + self.databaseViewRegistrationOverlay.hidden = YES; + return; + } + + if (!self.databaseViewRegistrationOverlay || self.databaseViewRegistrationOverlay.hidden) { + DDLogWarn(@"Showing database view registration overlay."); + } + + if (!self.databaseViewRegistrationOverlay) { + // Recycle the "screen lock view", but add a label. + UIWindow *window = [[UIWindow alloc] initWithFrame:self.window.bounds]; + window.hidden = YES; + window.opaque = YES; + window.userInteractionEnabled = NO; + window.windowLevel = CGFLOAT_MAX; + window.backgroundColor = UIColor.ows_materialBlueColor; + window.rootViewController = + [[UIStoryboard storyboardWithName:@"Launch Screen" bundle:nil] instantiateInitialViewController]; + + BOOL shouldShowUpgradeLabel = NO; + NSString *previousVersion = AppVersion.instance.lastAppVersion; + // We added a number of database views in v2.13.0. + if ([VersionMigrations isVersion:previousVersion atLeast:@"2.0.0" andLessThan:@"2.13.0"]) { + shouldShowUpgradeLabel = YES; + } + if (shouldShowUpgradeLabel) { + UIView *rootView = window.rootViewController.view; + UIImageView *iconView = nil; + for (UIView *subview in rootView.subviews) { + if ([subview isKindOfClass:[UIImageView class]]) { + iconView = (UIImageView *)subview; + break; + } + } + if (!iconView) { + OWSFail(@"Database view registration overlay has unexpected contents."); + } else { + UILabel *label = [UILabel new]; + label.text = NSLocalizedString( + @"DATABASE_VIEW_OVERLAY_TITLE", @"Indicates that the app is updating its database."); + label.font = [UIFont ows_mediumFontWithSize:18.f]; + label.textColor = [UIColor whiteColor]; + [rootView addSubview:label]; + [label autoHCenterInSuperview]; + [label autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:iconView withOffset:25.f]; + } + } + + self.databaseViewRegistrationOverlay = window; + } + self.databaseViewRegistrationOverlay.hidden = NO; +} + #pragma mark - Logging + (NSString *)tag diff --git a/Signal/src/ViewControllers/ConversationView/MessagesViewController.m b/Signal/src/ViewControllers/ConversationView/MessagesViewController.m index 7de5a3268..0db01f9f6 100644 --- a/Signal/src/ViewControllers/ConversationView/MessagesViewController.m +++ b/Signal/src/ViewControllers/ConversationView/MessagesViewController.m @@ -3617,7 +3617,7 @@ typedef enum : NSUInteger { uint64_t lastVisibleTimestamp = self.lastVisibleTimestamp; [self.editingDatabaseConnection asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) { NSMutableArray> *interactions = [NSMutableArray new]; - [[transaction ext:TSUnseenDatabaseViewExtensionName] + [[TSDatabaseView unseenDatabaseViewExtension:transaction] enumerateRowsInGroup:thread.uniqueId usingBlock:^( NSString *collection, NSString *key, id object, id metadata, NSUInteger index, BOOL *stop) { diff --git a/Signal/src/ViewControllers/DebugSettingsTableViewController.h b/Signal/src/ViewControllers/DebugSettingsTableViewController.h new file mode 100644 index 000000000..6d8edd916 --- /dev/null +++ b/Signal/src/ViewControllers/DebugSettingsTableViewController.h @@ -0,0 +1,9 @@ +// +// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// + +#import "OWSTableViewController.h" + +@interface DebugSettingsTableViewController : OWSTableViewController + +@end diff --git a/Signal/src/ViewControllers/DebugSettingsTableViewController.m b/Signal/src/ViewControllers/DebugSettingsTableViewController.m new file mode 100644 index 000000000..4d86a4f76 --- /dev/null +++ b/Signal/src/ViewControllers/DebugSettingsTableViewController.m @@ -0,0 +1,75 @@ +// +// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// + +#import "DebugSettingsTableViewController.h" +#import "UIFont+OWS.h" +#import +#import + +@implementation DebugSettingsTableViewController + +- (void)loadView +{ + self.tableViewStyle = UITableViewStylePlain; + [super loadView]; +} + +- (void)viewDidLoad +{ + [super viewDidLoad]; + + [self.navigationController.navigationBar setTranslucent:NO]; + + self.title = @"Debugging"; + + [self updateTableContents]; +} + +- (void)viewWillAppear:(BOOL)animated +{ + [super viewWillAppear:animated]; + + [self updateTableContents]; +} + +- (void)dealloc +{ + [[NSNotificationCenter defaultCenter] removeObserver:self]; +} + +#pragma mark - Table Contents + +- (void)updateTableContents +{ + OWSTableContents *contents = [OWSTableContents new]; + OWSTableSection *section = [OWSTableSection new]; + + __block NSUInteger threadCount; + __block NSUInteger messageCount; + [TSStorageManager.sharedManager.dbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) { + threadCount = [[transaction ext:TSThreadDatabaseViewExtensionName] numberOfItemsInAllGroups]; + messageCount = [[transaction ext:TSMessageDatabaseViewExtensionName] numberOfItemsInAllGroups]; + }]; + + [section addItem:[OWSTableItem labelItemWithText:[NSString stringWithFormat:@"Threads: %zd", threadCount]]]; + [section addItem:[OWSTableItem labelItemWithText:[NSString stringWithFormat:@"Messages: %zd", messageCount]]]; + + [contents addSection:section]; + + self.contents = contents; +} + +#pragma mark - Logging + ++ (NSString *)tag +{ + return [NSString stringWithFormat:@"[%@]", self.class]; +} + +- (NSString *)tag +{ + return self.class.tag; +} + +@end diff --git a/Signal/src/ViewControllers/DebugUI/DebugUIMessages.m b/Signal/src/ViewControllers/DebugUI/DebugUIMessages.m index 3cd339185..ee86986df 100644 --- a/Signal/src/ViewControllers/DebugUI/DebugUIMessages.m +++ b/Signal/src/ViewControllers/DebugUI/DebugUIMessages.m @@ -53,10 +53,14 @@ NS_ASSUME_NONNULL_BEGIN actionBlock:^{ [DebugUIMessages sendTextMessages:1000 thread:thread]; }], - [OWSTableItem itemWithTitle:@"Create 1,000 fake messages" + [OWSTableItem itemWithTitle:@"Create 1k fake messages" actionBlock:^{ [DebugUIMessages sendFakeTextMessage:1000 thread:thread]; }], + [OWSTableItem itemWithTitle:@"Create 10k fake messages" + actionBlock:^{ + [DebugUIMessages sendFakeTextMessage:10 * 1000 thread:thread]; + }], [OWSTableItem itemWithTitle:@"Send text/x-signal-plain" actionBlock:^{ [DebugUIMessages sendOversizeTextMessage:thread]; diff --git a/Signal/src/ViewControllers/OWSTableViewController.h b/Signal/src/ViewControllers/OWSTableViewController.h index 51357dd8a..db2476363 100644 --- a/Signal/src/ViewControllers/OWSTableViewController.h +++ b/Signal/src/ViewControllers/OWSTableViewController.h @@ -68,6 +68,8 @@ typedef UITableViewCell *_Nonnull (^OWSTableCustomCellBlock)(); + (OWSTableItem *)actionItemWithText:(NSString *)text actionBlock:(nullable OWSTableActionBlock)actionBlock; ++ (OWSTableItem *)labelItemWithText:(NSString *)text; + - (nullable UITableViewCell *)customCell; - (NSNumber *)customRowHeight; diff --git a/Signal/src/ViewControllers/OWSTableViewController.m b/Signal/src/ViewControllers/OWSTableViewController.m index 956212f5a..9980e2cb6 100644 --- a/Signal/src/ViewControllers/OWSTableViewController.m +++ b/Signal/src/ViewControllers/OWSTableViewController.m @@ -187,6 +187,22 @@ const CGFloat kOWSTable_DefaultCellHeight = 45.f; return item; } ++ (OWSTableItem *)labelItemWithText:(NSString *)text +{ + OWSAssert(text.length > 0); + + OWSTableItem *item = [OWSTableItem new]; + item.itemType = OWSTableItemTypeAction; + item.customCellBlock = ^{ + UITableViewCell *cell = [UITableViewCell new]; + cell.textLabel.text = text; + cell.textLabel.font = [UIFont ows_regularFontWithSize:18.f]; + cell.textLabel.textColor = [UIColor blackColor]; + return cell; + }; + return item; +} + - (nullable UITableViewCell *)customCell { if (_customCell) { diff --git a/Signal/src/ViewControllers/SettingsTableViewController.m b/Signal/src/ViewControllers/SettingsTableViewController.m index 7a9a7bea8..2ec14b42c 100644 --- a/Signal/src/ViewControllers/SettingsTableViewController.m +++ b/Signal/src/ViewControllers/SettingsTableViewController.m @@ -5,6 +5,7 @@ #import "SettingsTableViewController.h" #import "AboutTableViewController.h" #import "AdvancedSettingsTableViewController.h" +#import "DebugSettingsTableViewController.h" #import "Environment.h" #import "NotificationSettingsViewController.h" #import "OWSContactsManager.h" @@ -196,6 +197,13 @@ [weakSelf showAbout]; }]]; +#ifdef DEBUG + [section addItem:[OWSTableItem disclosureItemWithText:@"Debugging" + actionBlock:^{ + [weakSelf showDebugging]; + }]]; +#endif + [section addItem:[OWSTableItem itemWithCustomCellBlock:^{ UITableViewCell *cell = [UITableViewCell new]; UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; @@ -267,6 +275,12 @@ [self.navigationController pushViewController:vc animated:YES]; } +- (void)showDebugging +{ + DebugSettingsTableViewController *vc = [[DebugSettingsTableViewController alloc] init]; + [self.navigationController pushViewController:vc animated:YES]; +} + - (void)dismissWasPressed:(id)sender { [self dismissViewControllerAnimated:YES completion:nil]; diff --git a/Signal/src/environment/Migrations/OWSDatabaseMigrationRunner.h b/Signal/src/environment/Migrations/OWSDatabaseMigrationRunner.h index 1997a2a73..ee7647083 100644 --- a/Signal/src/environment/Migrations/OWSDatabaseMigrationRunner.h +++ b/Signal/src/environment/Migrations/OWSDatabaseMigrationRunner.h @@ -1,5 +1,6 @@ -// Created by Michael Kirk on 9/28/16. -// Copyright © 2016 Open Whisper Systems. All rights reserved. +// +// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// NS_ASSUME_NONNULL_BEGIN @@ -16,6 +17,15 @@ NS_ASSUME_NONNULL_BEGIN */ - (void)runAllOutstanding; +/** + * Run any outstanding version migrations that are a) blocking and b) safe + * to be run before the environment and storage is completely configured. + * + * Specifically, these migrations should not depend on or affect the data + * of any database view. + */ +- (void)runSafeBlockingMigrations; + /** * On new installations, no need to migrate anything. */ diff --git a/Signal/src/environment/Migrations/OWSDatabaseMigrationRunner.m b/Signal/src/environment/Migrations/OWSDatabaseMigrationRunner.m index d2f59bcb6..d3a0434f4 100644 --- a/Signal/src/environment/Migrations/OWSDatabaseMigrationRunner.m +++ b/Signal/src/environment/Migrations/OWSDatabaseMigrationRunner.m @@ -42,9 +42,23 @@ NS_ASSUME_NONNULL_BEGIN } } +- (void)runSafeBlockingMigrations +{ + [self runMigrations:@[ + [[OWS104CreateRecipientIdentities alloc] initWithStorageManager:self.storageManager], + ]]; +} + - (void)runAllOutstanding { - for (OWSDatabaseMigration *migration in self.allMigrations) { + [self runMigrations:self.allMigrations]; +} + +- (void)runMigrations:(NSArray *)migrations +{ + OWSAssert(migrations); + + for (OWSDatabaseMigration *migration in migrations) { if ([OWSDatabaseMigration fetchObjectWithUniqueID:migration.uniqueId]) { DDLogDebug(@"%@ Skipping previously run migration: %@", self.tag, migration); } else { diff --git a/Signal/src/environment/PropertyListPreferences.h b/Signal/src/environment/PropertyListPreferences.h index b86521e1d..eab323079 100644 --- a/Signal/src/environment/PropertyListPreferences.h +++ b/Signal/src/environment/PropertyListPreferences.h @@ -52,8 +52,6 @@ extern NSString *const PropertyListPreferencesKeyEnableDebugLog; - (BOOL)hasRegisteredVOIPPush; - (void)setHasRegisteredVOIPPush:(BOOL)enabled; -+ (nullable NSString *)lastRanVersion; -+ (NSString *)setAndGetCurrentVersion; - (BOOL)hasDeclinedNoContactsView; - (void)setHasDeclinedNoContactsView:(BOOL)value; diff --git a/Signal/src/environment/PropertyListPreferences.m b/Signal/src/environment/PropertyListPreferences.m index 375350727..fe99284b6 100644 --- a/Signal/src/environment/PropertyListPreferences.m +++ b/Signal/src/environment/PropertyListPreferences.m @@ -16,7 +16,6 @@ NSString *const PropertyListPreferencesKeyEnableDebugLog = @"Debugging Log Enabl NSString *const PropertyListPreferencesKeyNotificationPreviewType = @"Notification Preview Type Key"; NSString *const PropertyListPreferencesKeyHasSentAMessage = @"User has sent a message"; NSString *const PropertyListPreferencesKeyHasArchivedAMessage = @"User archived a message"; -NSString *const PropertyListPreferencesKeyLastRunSignalVersion = @"SignalUpdateVersionKey"; NSString *const PropertyListPreferencesKeyPlaySoundInForeground = @"NotificationSoundInForeground"; NSString *const PropertyListPreferencesKeyHasRegisteredVoipPush = @"VOIPPushEnabled"; NSString *const PropertyListPreferencesKeyLastRecordedPushToken = @"LastRecordedPushToken"; @@ -159,20 +158,6 @@ NSString *const PropertyListPreferencesKeyIOSUpgradeNagVersion = @"iOSUpgradeNag [self setValueForKey:PropertyListPreferencesKeyHasArchivedAMessage toValue:@(enabled)]; } -+ (nullable NSString *)lastRanVersion -{ - return [NSUserDefaults.standardUserDefaults objectForKey:PropertyListPreferencesKeyLastRunSignalVersion]; -} - -+ (NSString *)setAndGetCurrentVersion -{ - NSString *currentVersion = - [NSString stringWithFormat:@"%@", NSBundle.mainBundle.infoDictionary[@"CFBundleVersion"]]; - [NSUserDefaults.standardUserDefaults setObject:currentVersion - forKey:PropertyListPreferencesKeyLastRunSignalVersion]; - [NSUserDefaults.standardUserDefaults synchronize]; - return currentVersion; -} - (BOOL)hasDeclinedNoContactsView { diff --git a/Signal/src/environment/VersionMigrations.h b/Signal/src/environment/VersionMigrations.h index b3b4e68c4..2656ae7f4 100644 --- a/Signal/src/environment/VersionMigrations.h +++ b/Signal/src/environment/VersionMigrations.h @@ -1,9 +1,5 @@ // -// VersionMigrations.h -// Signal -// -// Created by Frederic Jacobs on 29/07/14. -// Copyright (c) 2014 Open Whisper Systems. All rights reserved. +// Copyright (c) 2017 Open Whisper Systems. All rights reserved. // #import @@ -14,4 +10,10 @@ + (void)performUpdateCheck; ++ (void)runSafeBlockingMigrations; + ++ (BOOL)isVersion:(NSString *)thisVersionString + atLeast:(NSString *)openLowerBoundVersionString + andLessThan:(NSString *)closedUpperBoundVersionString; + @end diff --git a/Signal/src/environment/VersionMigrations.m b/Signal/src/environment/VersionMigrations.m index 67555794f..3615acae7 100644 --- a/Signal/src/environment/VersionMigrations.m +++ b/Signal/src/environment/VersionMigrations.m @@ -12,6 +12,7 @@ #import "SignalKeyingStorage.h" #import "TSAccountManager.h" #import "TSNetworkManager.h" +#import #import #define NEEDS_TO_REGISTER_PUSH_KEY @"Register For Push" @@ -34,9 +35,8 @@ // upgrade process may depend on Environment. OWSAssert([Environment getCurrent]); - NSString *previousVersion = PropertyListPreferences.lastRanVersion; - NSString *currentVersion = - [NSString stringWithFormat:@"%@", NSBundle.mainBundle.infoDictionary[@"CFBundleVersion"]]; + NSString *previousVersion = AppVersion.instance.lastAppVersion; + NSString *currentVersion = AppVersion.instance.currentAppVersion; DDLogInfo( @"%@ Checking migrations. currentVersion: %@, lastRanVersion: %@", self.tag, currentVersion, previousVersion); @@ -46,7 +46,6 @@ OWSDatabaseMigrationRunner *runner = [[OWSDatabaseMigrationRunner alloc] initWithStorageManager:[TSStorageManager sharedManager]]; [runner assumeAllExistingMigrationsRun]; - [PropertyListPreferences setAndGetCurrentVersion]; return; } @@ -93,7 +92,12 @@ } [[[OWSDatabaseMigrationRunner alloc] initWithStorageManager:[TSStorageManager sharedManager]] runAllOutstanding]; - [PropertyListPreferences setAndGetCurrentVersion]; +} + ++ (void)runSafeBlockingMigrations +{ + [[[OWSDatabaseMigrationRunner alloc] initWithStorageManager:[TSStorageManager sharedManager]] + runSafeBlockingMigrations]; } + (BOOL)isVersion:(NSString *)thisVersionString diff --git a/Signal/src/util/ThreadUtil.m b/Signal/src/util/ThreadUtil.m index 2f93b079e..4d9714a5d 100644 --- a/Signal/src/util/ThreadUtil.m +++ b/Signal/src/util/ThreadUtil.m @@ -123,7 +123,7 @@ NS_ASSUME_NONNULL_BEGIN NSMutableArray *blockingSafetyNumberChanges = [NSMutableArray new]; NSMutableArray *nonBlockingSafetyNumberChanges = [NSMutableArray new]; // We use different views for performance reasons. - [[transaction ext:TSThreadSpecialMessagesDatabaseViewExtensionName] + [[TSDatabaseView threadSpecialMessagesDatabaseView:transaction] enumerateRowsInGroup:thread.uniqueId usingBlock:^( NSString *collection, NSString *key, id object, id metadata, NSUInteger index, BOOL *stop) { @@ -160,7 +160,7 @@ NS_ASSUME_NONNULL_BEGIN result.firstUnseenInteractionTimestamp = firstUnseenInteractionTimestampParameter; } else { TSInteraction *firstUnseenInteraction = - [[transaction ext:TSUnseenDatabaseViewExtensionName] firstObjectInGroup:thread.uniqueId]; + [[TSDatabaseView unseenDatabaseViewExtension:transaction] firstObjectInGroup:thread.uniqueId]; if (firstUnseenInteraction) { result.firstUnseenInteractionTimestamp = @(firstUnseenInteraction.timestampForSorting); } @@ -182,7 +182,7 @@ NS_ASSUME_NONNULL_BEGIN }]; NSUInteger outgoingMessageCount = - [[transaction ext:TSThreadOutgoingMessageDatabaseViewExtensionName] numberOfItemsInGroup:thread.uniqueId]; + [[TSDatabaseView threadOutgoingMessageDatabaseView:transaction] numberOfItemsInGroup:thread.uniqueId]; NSUInteger threadMessageCount = [[transaction ext:TSMessageDatabaseViewExtensionName] numberOfItemsInGroup:thread.uniqueId]; diff --git a/Signal/translations/en.lproj/Localizable.strings b/Signal/translations/en.lproj/Localizable.strings index c57395072..4ce45d9a7 100644 --- a/Signal/translations/en.lproj/Localizable.strings +++ b/Signal/translations/en.lproj/Localizable.strings @@ -328,6 +328,9 @@ /* Accessibility label for the create group new group button */ "CREATE_NEW_GROUP" = "Create new group"; +/* Indicates that the app is updating its database. */ +"DATABASE_VIEW_OVERLAY_TITLE" = "Updating Database"; + /* {{number of days}} embedded in strings, e.g. 'Alice updated disappearing messages expiration to {{5 days}}'. See other *_TIME_AMOUNT strings */ "DAYS_TIME_AMOUNT" = "%u days";