From c2d78bba1252ba1d57013c005c7438a0e711d02a Mon Sep 17 00:00:00 2001 From: Frederic Jacobs Date: Fri, 1 Aug 2014 19:24:26 -0400 Subject: [PATCH] Migration scheme --- Signal/Signal-Prefix.pch | 3 +-- Signal/src/AppDelegate.m | 27 +++++++++++----------- Signal/src/contact/ContactsManager.m | 3 --- Signal/src/environment/LocalizableText.h | 1 - Signal/src/environment/Release.m | 1 - Signal/src/environment/VersionMigrations.m | 21 +++++++++++++---- Signal/src/network/PushManager.h | 1 - Signal/src/phone/PhoneNumber.m | 1 - 8 files changed, 31 insertions(+), 27 deletions(-) diff --git a/Signal/Signal-Prefix.pch b/Signal/Signal-Prefix.pch index f6a7cf97d..9af74af72 100644 --- a/Signal/Signal-Prefix.pch +++ b/Signal/Signal-Prefix.pch @@ -12,8 +12,7 @@ #ifdef DEBUG static const int ddLogLevel = LOG_LEVEL_VERBOSE; #else -// As long as we have call initialization issues we'll log a bit more aggressively - static const int ddLogLevel = LOG_LEVEL_VERBOSE; + static const int ddLogLevel = LOG_LEVEL_ERROR; #endif #endif diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index 7b4729957..c4b9c74a4 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -4,6 +4,7 @@ #import "CategorizingLogger.h" #import "DialerViewController.h" #import "DiscardingLog.h" +#import "Environment.h" #import "InCallViewController.h" #import "LeftSideMenuViewController.h" #import "MMDrawerController.h" @@ -15,9 +16,7 @@ #import "SettingsViewController.h" #import "TabBarParentViewController.h" #import "Util.h" -#import -#import "Environment.h" -#import "CallServerRequestsManager.h" +#import "VersionMigrations.h" #define kSignalVersionKey @"SignalUpdateVersionKey" @@ -49,6 +48,7 @@ // Application was updated, let's see if we have a migration scheme for it. if ([previousVersion isEqualToString:@"1.0.2"]) { // Migrate from custom preferences to NSUserDefaults + [VersionMigrations migrationFrom1Dot0Dot2toLarger]; } } @@ -63,13 +63,12 @@ */ - (void)protectPreferenceFiles{ - NSMutableArray *pathsToExclude = [NSMutableArray array]; [pathsToExclude addObject:[[[NSHomeDirectory() stringByAppendingString:@"/Library/Preferences/"] stringByAppendingString:[[NSBundle mainBundle] bundleIdentifier]] stringByAppendingString:@".plist"]]; NSError *error; - + NSString *logPath = [NSHomeDirectory() stringByAppendingString:@"/Library/Caches/Logs/"]; NSArray *logsFiles = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:logPath error:&error]; @@ -79,17 +78,17 @@ for (NSUInteger i = 0; i < [pathsToExclude count]; i++) { [[NSURL fileURLWithPath:[pathsToExclude objectAtIndex:i]] setResourceValue: [NSNumber numberWithBool: YES] - forKey: NSURLIsExcludedFromBackupKey error: &error]; + forKey: NSURLIsExcludedFromBackupKey error: &error]; } if (error) { - NSLog(@"Error: %@", error.description); + DDLogError(@"Error while removing log files from backup: %@", error.description); UIAlertView *alert = [[UIAlertView alloc]initWithTitle:NSLocalizedString(@"WARNING", @"") message:NSLocalizedString(@"DISABLING_BACKUP_FAILED", @"") delegate:nil cancelButtonTitle:NSLocalizedString(@"OK", @"") otherButtonTitles:nil, nil]; [alert show]; return; } - + } - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { @@ -112,27 +111,27 @@ [[Environment getCurrent].phoneDirectoryManager startUntilCancelled:nil]; [[Environment getCurrent].contactsManager doAfterEnvironmentInitSetup]; [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault]; - + LeftSideMenuViewController *leftSideMenuViewController = [LeftSideMenuViewController new]; - + self.drawerController = [[MMDrawerController alloc] initWithCenterViewController:leftSideMenuViewController.centerTabBarViewController leftDrawerViewController:leftSideMenuViewController]; self.window.rootViewController = _drawerController; [self.window makeKeyAndVisible]; - + //Accept push notification when app is not open NSDictionary *remoteNotif = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]; if (remoteNotif) { DDLogInfo(@"Application was launched by tapping a push notification."); [self application:application didReceiveRemoteNotification:remoteNotif]; } - + [[[Environment phoneManager] currentCallObservable] watchLatestValue:^(CallState* latestCall) { if (latestCall == nil){ return; } InCallViewController *callViewController = [InCallViewController inCallViewControllerWithCallState:latestCall - andOptionallyKnownContact:[latestCall potentiallySpecifiedContact]]; + andOptionallyKnownContact:[latestCall potentiallySpecifiedContact]]; [_drawerController.centerViewController presentViewController:callViewController animated:YES completion:nil]; } onThread:[NSThread mainThread] untilCancelled:nil]; @@ -158,7 +157,7 @@ DDLogError(@"Error parsing remote notification. Error: %@.", ex); return; } - + [[Environment phoneManager] incomingCallWithSession:call]; } diff --git a/Signal/src/contact/ContactsManager.m b/Signal/src/contact/ContactsManager.m index fff3fc61d..6f1048afd 100644 --- a/Signal/src/contact/ContactsManager.m +++ b/Signal/src/contact/ContactsManager.m @@ -10,9 +10,6 @@ #import "PreferencesUtil.h" #import "Util.h" - -//@TODO: Split Up into Seperate components. - #define ADDRESSBOOK_QUEUE dispatch_get_main_queue() static NSString *const FAVOURITES_DEFAULT_KEY = @"FAVOURITES_DEFAULT_KEY"; diff --git a/Signal/src/environment/LocalizableText.h b/Signal/src/environment/LocalizableText.h index a5a9b9df0..db7019f6e 100644 --- a/Signal/src/environment/LocalizableText.h +++ b/Signal/src/environment/LocalizableText.h @@ -21,7 +21,6 @@ #define TXT_END_CALL_HANGUP_REMOTE NSLocalizedString(@"END_CALL_HANGUP_REMOTE", @"") #define TXT_END_CALL_HANGUP_LOCAL NSLocalizedString(@"END_CALL_HANGUP_LOCAL", @"") #define TXT_END_CALL_REPLACED_BY_NEXT NSLocalizedString(@"END_CALL_REPLACED_BY_NEXT", @"") -// @todo: some languages probably don't prefix this sort of thing #define TXT_END_CALL_MESSAGE_FROM_SERVER_PREFIX NSLocalizedString(@"END_CALL_MESSAGE_FROM_SERVER_PREFIX", @"") #pragma mark - Menu Table Cell Titles diff --git a/Signal/src/environment/Release.m b/Signal/src/environment/Release.m index 68ef5b92a..f8e0a3f51 100644 --- a/Signal/src/environment/Release.m +++ b/Signal/src/environment/Release.m @@ -45,7 +45,6 @@ static unsigned char DH3K_PRIME[]={ @implementation Release +(Environment*) releaseEnvironmentWithLogging:(id)logging { - // @todo: turn off error notification //ErrorHandlerBlock errorDiscarder = ^(id error, id relatedInfo, bool causedTermination) {}; ErrorHandlerBlock errorNoter = ^(id error, id relatedInfo, bool causedTermination) { DDLogError(@"%@: %@, %d", error, relatedInfo, causedTermination); }; diff --git a/Signal/src/environment/VersionMigrations.m b/Signal/src/environment/VersionMigrations.m index 474643418..3bd7f33c2 100644 --- a/Signal/src/environment/VersionMigrations.m +++ b/Signal/src/environment/VersionMigrations.m @@ -6,23 +6,26 @@ // Copyright (c) 2014 Open Whisper Systems. All rights reserved. // +#import "PushManager.h" #import "VersionMigrations.h" @implementation VersionMigrations + (void)migrationFrom1Dot0Dot2toLarger{ - // Read everything in preference file, drop into NSUserDefaults + + // Preferences were stored in both a preference file and a plist in the documents folder, as a temporary measure, we are going to move all the preferences to the NSUserDefaults preference store, those will be migrated to a SQLCipher-backed database NSString* documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"/Documents/"]; NSString *path = [NSString stringWithFormat:@"%@/%@.plist", documentsDirectory, @"RedPhone-Data"]; NSData *plistData = [NSData dataWithContentsOfFile:path]; - NSString *error; + NSError *error; NSPropertyListFormat format; - NSDictionary *dict = [NSPropertyListSerialization propertyListFromData:plistData mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&error]; + NSDictionary *dict = [NSPropertyListSerialization propertyListWithData:plistData options:NSPropertyListImmutable format:&format error:&error]; NSLog(@"%@", dict); + NSArray *entries = [dict allKeys]; NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; @@ -33,7 +36,17 @@ [defaults synchronize]; - // delete + [[NSFileManager defaultManager]removeItemAtPath:path error:&error]; + + if (error) { + DDLogError(@"Error while migrating data: %@", error.description); + } + + // Some users push IDs were not correctly registered, by precaution, we are going to re-register all of them + + [[PushManager sharedManager] askForPushRegistration]; + + return; } @end diff --git a/Signal/src/network/PushManager.h b/Signal/src/network/PushManager.h index 363197415..5f9878f95 100644 --- a/Signal/src/network/PushManager.h +++ b/Signal/src/network/PushManager.h @@ -12,7 +12,6 @@ + (instancetype)sharedManager; - - (void)verifyPushActivated; - (void)askForPushRegistration; diff --git a/Signal/src/phone/PhoneNumber.m b/Signal/src/phone/PhoneNumber.m index fa3bba88c..497ade0e2 100644 --- a/Signal/src/phone/PhoneNumber.m +++ b/Signal/src/phone/PhoneNumber.m @@ -124,7 +124,6 @@ static NSString *const RPDefaultsKeyPhoneNumberCanonical = @"RPDefaultsKeyPhoneN } -(NSURL*) toUrl { - // @todo: can we return a more user-friendly link (using original text) in some limited cases? NSString* link = [NSString stringWithFormat:@"telprompt://%@", e164]; return [NSURL URLWithString:link]; }