diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index 993e3185d..163ee2a1e 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -45,13 +45,14 @@ static NSString* const kCallSegue = @"2.0_6.0_Call_Segue"; #pragma mark Detect updates - perform migrations - (void)performUpdateCheck{ - NSString *previousVersion = Environment.preferences.lastRanVersion; - NSString *currentVersion = [Environment.preferences setAndGetCurrentVersion]; + NSString *previousVersion = Environment.preferences.lastRanVersion; + NSString *currentVersion = [Environment.preferences setAndGetCurrentVersion]; + BOOL isCurrentlyMigrating = [VersionMigrations isMigratingTo2Dot0]; if (!previousVersion) { DDLogError(@"No previous version found. Possibly first launch since install."); - } else if(([self isVersion:previousVersion atLeast:@"1.0.2" andLessThan:@"2.0"]) || [Environment.preferences getIsMigratingToVersion2Dot0] ) { - [VersionMigrations migrateFrom1Dot0Dot2ToVersion2Dot0]; + } else if(([self isVersion:previousVersion atLeast:@"1.0.2" andLessThan:@"2.0"]) || isCurrentlyMigrating) { + [VersionMigrations migrateFrom1Dot0Dot2ToVersion2Dot0]; } } diff --git a/Signal/src/environment/PreferencesUtil.h b/Signal/src/environment/PreferencesUtil.h index 689b71569..5eabe7e25 100644 --- a/Signal/src/environment/PreferencesUtil.h +++ b/Signal/src/environment/PreferencesUtil.h @@ -25,9 +25,6 @@ typedef NS_ENUM(NSUInteger, TSImageQuality) { -(NSTimeInterval) getCachedOrDefaultDesiredBufferDepth; -(void) setCachedDesiredBufferDepth:(double)value; -- (BOOL) getIsMigratingToVersion2Dot0; -- (void) setIsMigratingToVersion2Dot0:(BOOL)enabled; - - (BOOL) getHasSentAMessage; - (void) setHasSentAMessage:(BOOL)enabled; diff --git a/Signal/src/environment/PreferencesUtil.m b/Signal/src/environment/PreferencesUtil.m index 9f30498a7..908036285 100644 --- a/Signal/src/environment/PreferencesUtil.m +++ b/Signal/src/environment/PreferencesUtil.m @@ -25,7 +25,6 @@ #define DEBUG_IS_ENABLED_KEY @"Debugging Log Enabled Key" #define NOTIFICATION_PREVIEW_TYPE_KEY @"Notification Preview Type Key" #define IMAGE_UPLOAD_QUALITY_KEY @"Image Upload Quality Key" -#define IS_MIGRATING_FROM_1DOT0_TO_LARGER_KEY @"Migrating from 1.0 to Larger" #define HAS_SENT_A_MESSAGE_KEY @"User has sent a message" #define HAS_ARCHIVED_A_MESSAGE_KEY @"User archived a message" #define kSignalVersionKey @"SignalUpdateVersionKey" @@ -103,16 +102,6 @@ } } - -- (BOOL) getIsMigratingToVersion2Dot0 { - NSNumber *preference = [self tryGetValueForKey:IS_MIGRATING_FROM_1DOT0_TO_LARGER_KEY]; - if (preference) { - return [preference boolValue]; - } else{ - return NO; - } -} - - (BOOL)loggingIsEnabled{ NSNumber *preference = [self tryGetValueForKey:DEBUG_IS_ENABLED_KEY]; if (preference) { @@ -209,10 +198,6 @@ return [NSUserDefaults.standardUserDefaults objectForKey:kSignalVersionKey]; } -- (void) setIsMigratingToVersion2Dot0:(BOOL)enabled { - [self setValueForKey:IS_MIGRATING_FROM_1DOT0_TO_LARGER_KEY toValue:@(enabled)]; -} - - (void) setHasSentAMessage:(BOOL)enabled{ [self setValueForKey:HAS_SENT_A_MESSAGE_KEY toValue:@(enabled)]; } diff --git a/Signal/src/environment/VersionMigrations.h b/Signal/src/environment/VersionMigrations.h index 50757ca11..29699313b 100644 --- a/Signal/src/environment/VersionMigrations.h +++ b/Signal/src/environment/VersionMigrations.h @@ -14,4 +14,6 @@ + (void)migrateFrom1Dot0Dot2ToVersion2Dot0; ++ (BOOL)isMigratingTo2Dot0; + @end diff --git a/Signal/src/environment/VersionMigrations.m b/Signal/src/environment/VersionMigrations.m index 89ae93420..b20ee3b37 100644 --- a/Signal/src/environment/VersionMigrations.m +++ b/Signal/src/environment/VersionMigrations.m @@ -19,6 +19,8 @@ #import "TSStorageManager.h" #import "TSDatabaseView.h" +#define IS_MIGRATING_FROM_1DOT0_TO_LARGER_KEY @"Migrating from 1.0 to Larger" + @interface SignalKeyingStorage(VersionMigrations) +(void)storeString:(NSString*)string forKey:(NSString*)key; @@ -29,13 +31,15 @@ + (void)migrateFrom1Dot0Dot2ToVersion2Dot0 { - if (!([self wasRedPhoneRegistered] || [Environment.preferences getIsMigratingToVersion2Dot0])) { + if (!([self wasRedPhoneRegistered] || [self isMigratingTo2Dot0])) { return; } - [Environment.preferences setIsMigratingToVersion2Dot0:YES]; - [self migrateRecentCallsToVersion2Dot0]; - [self migrateKeyingStorageToVersion2Dot0]; + if ([self wasRedPhoneRegistered]) { + [self migrateRecentCallsToVersion2Dot0]; + [self migrateKeyingStorageToVersion2Dot0]; + [self clearUserDefaults]; + } [UIApplication.sharedApplication setNetworkActivityIndicatorVisible:YES]; @@ -43,14 +47,12 @@ message:nil preferredStyle:UIAlertControllerStyleAlert]; - [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:waitingController - animated:YES - completion:nil]; + [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:waitingController animated:YES completion:nil]; [PushManager.sharedManager registrationAndRedPhoneTokenRequestWithSuccess:^(NSData *pushToken, NSString *signupToken) { [TSAccountManager registerWithRedPhoneToken:signupToken pushToken:pushToken success:^{ [UIApplication.sharedApplication setNetworkActivityIndicatorVisible:NO]; - [Environment.preferences setIsMigratingToVersion2Dot0:NO]; + [self clearMigrationFlag]; Environment *env = [Environment getCurrent]; PhoneNumberDirectoryFilterManager *manager = [env phoneDirectoryManager]; [manager forceUpdate]; @@ -96,15 +98,11 @@ for (RecentCall* recentCall in allRecents) { [Environment.getCurrent.recentCallManager addRecentCall:recentCall]; } - - NSString *appDomain = [[NSBundle mainBundle] bundleIdentifier]; - [[NSUserDefaults standardUserDefaults] removePersistentDomainForName:appDomain]; } } +(BOOL)wasRedPhoneRegistered{ - BOOL hasPassCounter = [UICKeyChainStore stringForKey:PASSWORD_COUNTER_KEY]!=nil; BOOL hasLocalNumber = [UICKeyChainStore stringForKey:LOCAL_NUMBER_KEY]!=nil; BOOL hasPassKey = [UICKeyChainStore stringForKey:SAVED_PASSWORD_KEY]!=nil; BOOL hasSignaling = [UICKeyChainStore dataForKey:SIGNALING_MAC_KEY]!=nil; @@ -114,7 +112,7 @@ BOOL registered = [[NSUserDefaults.standardUserDefaults objectForKey:@"isRegistered"] boolValue]; - return registered &&hasPassCounter && hasLocalNumber && hasPassKey && hasSignaling + return registered && hasLocalNumber && hasPassKey && hasSignaling && hasCipherKey && hasCipherKey && hasZIDKey && hasSignalingExtra; } @@ -151,4 +149,27 @@ [UICKeyChainStore removeItemForKey:SIGNALING_EXTRA_KEY]; } ++ (void)clearUserDefaults{ + NSString *appDomain = [[NSBundle mainBundle] bundleIdentifier]; + [[NSUserDefaults standardUserDefaults] removePersistentDomainForName:appDomain]; + + [Environment.preferences setAndGetCurrentVersion]; + [[NSUserDefaults standardUserDefaults] setObject:@YES forKey:IS_MIGRATING_FROM_1DOT0_TO_LARGER_KEY]; + [[NSUserDefaults standardUserDefaults] synchronize]; +} + ++ (BOOL)isMigratingTo2Dot0{ + NSNumber *num = [[NSUserDefaults standardUserDefaults] objectForKey:IS_MIGRATING_FROM_1DOT0_TO_LARGER_KEY]; + + if (!num) { + return NO; + } else { + return [num boolValue]; + } +} + ++ (void)clearMigrationFlag{ + [[NSUserDefaults standardUserDefaults] setObject:nil forKey:IS_MIGRATING_FROM_1DOT0_TO_LARGER_KEY]; +} + @end diff --git a/Signal/src/view controllers/UITests/SignalsViewController.m b/Signal/src/view controllers/UITests/SignalsViewController.m index 9220cac26..6fdae40bf 100644 --- a/Signal/src/view controllers/UITests/SignalsViewController.m +++ b/Signal/src/view controllers/UITests/SignalsViewController.m @@ -21,6 +21,7 @@ #import "TSContactThread.h" #import "TSMessagesManager+sendMessages.h" #import "UIImage+normalizeImage.h" +#import "VersionMigrations.h" #import "PreferencesUtil.h" #import "NSDate+millisecondTimeStamp.h" @@ -85,7 +86,7 @@ static NSString* const kShowSignupFlowSegue = @"showSignupFlow"; [super viewWillAppear:animated]; [self checkIfEmptyView]; - if (![TSAccountManager isRegistered] && ![Environment.preferences getIsMigratingToVersion2Dot0]){ + if (![TSAccountManager isRegistered] && ![VersionMigrations isMigratingTo2Dot0]){ [self performSegueWithIdentifier:kShowSignupFlowSegue sender:self]; return; }