diff --git a/Podfile.lock b/Podfile.lock index bebd66947..d38989028 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -188,6 +188,6 @@ SPEC CHECKSUMS: YapDatabase: cd911121580ff16675f65ad742a9eb0ab4d9e266 YYImage: 1e1b62a9997399593e4b9c4ecfbbabbf1d3f3b54 -PODFILE CHECKSUM: 8e42a06de2d254e448580cfd6212545739de62d6 +PODFILE CHECKSUM: 558b99b22f87c7fb6e4a9c3084b14a384203d431 COCOAPODS: 1.3.1 diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index f537ff8aa..fff346c7c 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -24,6 +24,7 @@ #import "VersionMigrations.h" #import "ViewControllerUtils.h" #import +#import #import #import #import @@ -39,7 +40,6 @@ #import #import #import -#import @import WebRTC; @import Intents; @@ -104,13 +104,14 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; DDLogWarn(@"%@ application: didFinishLaunchingWithOptions.", self.logTag); - // We need to this _after_ we set up logging but _before_ we do + // We need to do this _after_ we set up logging but _before_ we do // anything else. [self ensureIsReadyForAppExtensions]; #if RELEASE // ensureIsReadyForAppExtensions may have changed the state of the logging - // preference, so honor that change if necessary. + // preference (due to [NSUserDefaults migrateToSharedUserDefaults]), so honor + // that change if necessary. if (loggingIsEnabled && !OWSPreferences.loggingIsEnabled) { [DebugLogger.sharedLogger disableFileLogging]; } diff --git a/Signal/src/Profiles/OWSProfileManager.m b/Signal/src/Profiles/OWSProfileManager.m index 2cef339a7..8c05020f7 100644 --- a/Signal/src/Profiles/OWSProfileManager.m +++ b/Signal/src/Profiles/OWSProfileManager.m @@ -1384,20 +1384,20 @@ const NSUInteger kOWSProfileManager_MaxAvatarDiameter = 640; return image; } -+ (NSString *)oldProfileAvatarsDirPath ++ (NSString *)legacyProfileAvatarsDirPath { return [[OWSFileSystem appDocumentDirectoryPath] stringByAppendingPathComponent:@"ProfileAvatars"]; } -+ (NSString *)newProfileAvatarsDirPath ++ (NSString *)sharedDataProfileAvatarsDirPath { return [[OWSFileSystem appSharedDataDirectoryPath] stringByAppendingPathComponent:@"ProfileAvatars"]; } + (void)migrateToSharedData { - [OWSFileSystem moveAppFilePath:self.oldProfileAvatarsDirPath - sharedDataFilePath:self.newProfileAvatarsDirPath + [OWSFileSystem moveAppFilePath:self.legacyProfileAvatarsDirPath + sharedDataFilePath:self.sharedDataProfileAvatarsDirPath exceptionName:@"ProfileManagerCouldNotMigrateProfileDirectory"]; } @@ -1406,7 +1406,7 @@ const NSUInteger kOWSProfileManager_MaxAvatarDiameter = 640; static NSString *profileAvatarsDirPath = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ - profileAvatarsDirPath = OWSProfileManager.newProfileAvatarsDirPath; + profileAvatarsDirPath = OWSProfileManager.sharedDataProfileAvatarsDirPath; BOOL isDirectory; BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:profileAvatarsDirPath isDirectory:&isDirectory]; diff --git a/SignalServiceKit/src/Messages/Attachments/TSAttachmentStream.m b/SignalServiceKit/src/Messages/Attachments/TSAttachmentStream.m index 187ad5498..390f6b9d0 100644 --- a/SignalServiceKit/src/Messages/Attachments/TSAttachmentStream.m +++ b/SignalServiceKit/src/Messages/Attachments/TSAttachmentStream.m @@ -180,20 +180,20 @@ NS_ASSUME_NONNULL_BEGIN return [dataSource writeToPath:filePath]; } -+ (NSString *)oldAttachmentsDirPath ++ (NSString *)legacyAttachmentsDirPath { return [[OWSFileSystem appDocumentDirectoryPath] stringByAppendingPathComponent:@"Attachments"]; } -+ (NSString *)newAttachmentsDirPath ++ (NSString *)sharedDataAttachmentsDirPath { return [[OWSFileSystem appSharedDataDirectoryPath] stringByAppendingPathComponent:@"Attachments"]; } + (void)migrateToSharedData { - [OWSFileSystem moveAppFilePath:self.oldAttachmentsDirPath - sharedDataFilePath:self.newAttachmentsDirPath + [OWSFileSystem moveAppFilePath:self.legacyAttachmentsDirPath + sharedDataFilePath:self.sharedDataAttachmentsDirPath exceptionName:@"CouldNotMigrateAttachmentsDirectory"]; } @@ -202,7 +202,7 @@ NS_ASSUME_NONNULL_BEGIN static NSString *attachmentsFolder = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ - attachmentsFolder = TSAttachmentStream.newAttachmentsDirPath; + attachmentsFolder = TSAttachmentStream.sharedDataAttachmentsDirPath; BOOL isDirectory; BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:attachmentsFolder isDirectory:&isDirectory]; diff --git a/SignalServiceKit/src/Storage/TSStorageManager.m b/SignalServiceKit/src/Storage/TSStorageManager.m index a4b18c3ae..5a2dd722c 100644 --- a/SignalServiceKit/src/Storage/TSStorageManager.m +++ b/SignalServiceKit/src/Storage/TSStorageManager.m @@ -360,12 +360,12 @@ void setDatabaseInitialized() { // The old database location was in the Document directory, // so protect the database files individually. - [OWSFileSystem protectFolderAtPath:[self oldDatabaseFilePath]]; - [OWSFileSystem protectFolderAtPath:[self oldDatabaseFilePath_SHM]]; - [OWSFileSystem protectFolderAtPath:[self oldDatabaseFilePath_WAL]]; + [OWSFileSystem protectFolderAtPath:self.legacyDatabaseFilePath]; + [OWSFileSystem protectFolderAtPath:self.legacyDatabaseFilePath_SHM]; + [OWSFileSystem protectFolderAtPath:self.legacyDatabaseFilePath_WAL]; // Protect the entire new database directory. - [OWSFileSystem protectFolderAtPath:[self newDatabaseDirPath]]; + [OWSFileSystem protectFolderAtPath:self.sharedDataDatabaseDirPath]; } - (nullable YapDatabaseConnection *)newDatabaseConnection @@ -377,12 +377,12 @@ void setDatabaseInitialized() return FALSE; } -+ (NSString *)oldDatabaseDirPath ++ (NSString *)legacyDatabaseDirPath { return [OWSFileSystem appDocumentDirectoryPath]; } -+ (NSString *)newDatabaseDirPath ++ (NSString *)sharedDataDatabaseDirPath { NSString *databaseDirPath = [[OWSFileSystem appSharedDataDirectoryPath] stringByAppendingPathComponent:@"database"]; @@ -422,54 +422,54 @@ void setDatabaseInitialized() return [self.databaseFilename stringByAppendingString:@"-wal"]; } -+ (NSString *)oldDatabaseFilePath ++ (NSString *)legacyDatabaseFilePath { - return [self.oldDatabaseDirPath stringByAppendingPathComponent:self.databaseFilename]; + return [self.legacyDatabaseDirPath stringByAppendingPathComponent:self.databaseFilename]; } -+ (NSString *)oldDatabaseFilePath_SHM ++ (NSString *)legacyDatabaseFilePath_SHM { - return [self.oldDatabaseDirPath stringByAppendingPathComponent:self.databaseFilename_SHM]; + return [self.legacyDatabaseDirPath stringByAppendingPathComponent:self.databaseFilename_SHM]; } -+ (NSString *)oldDatabaseFilePath_WAL ++ (NSString *)legacyDatabaseFilePath_WAL { - return [self.oldDatabaseDirPath stringByAppendingPathComponent:self.databaseFilename_WAL]; + return [self.legacyDatabaseDirPath stringByAppendingPathComponent:self.databaseFilename_WAL]; } -+ (NSString *)newDatabaseFilePath ++ (NSString *)sharedDataDatabaseFilePath { - return [self.newDatabaseDirPath stringByAppendingPathComponent:self.databaseFilename]; + return [self.sharedDataDatabaseDirPath stringByAppendingPathComponent:self.databaseFilename]; } -+ (NSString *)newDatabaseFilePath_SHM ++ (NSString *)sharedDataDatabaseFilePath_SHM { - return [self.newDatabaseDirPath stringByAppendingPathComponent:self.databaseFilename_SHM]; + return [self.sharedDataDatabaseDirPath stringByAppendingPathComponent:self.databaseFilename_SHM]; } -+ (NSString *)newDatabaseFilePath_WAL ++ (NSString *)sharedDataDatabaseFilePath_WAL { - return [self.newDatabaseDirPath stringByAppendingPathComponent:self.databaseFilename_WAL]; + return [self.sharedDataDatabaseDirPath stringByAppendingPathComponent:self.databaseFilename_WAL]; } + (void)migrateToSharedData { - [OWSFileSystem moveAppFilePath:self.oldDatabaseFilePath - sharedDataFilePath:self.newDatabaseFilePath + [OWSFileSystem moveAppFilePath:self.legacyDatabaseFilePath + sharedDataFilePath:self.sharedDataDatabaseFilePath exceptionName:TSStorageManagerExceptionName_CouldNotMoveDatabaseFile]; - [OWSFileSystem moveAppFilePath:self.oldDatabaseFilePath_SHM - sharedDataFilePath:self.newDatabaseFilePath_SHM + [OWSFileSystem moveAppFilePath:self.legacyDatabaseFilePath_SHM + sharedDataFilePath:self.sharedDataDatabaseFilePath_SHM exceptionName:TSStorageManagerExceptionName_CouldNotMoveDatabaseFile]; - [OWSFileSystem moveAppFilePath:self.oldDatabaseFilePath_WAL - sharedDataFilePath:self.newDatabaseFilePath_WAL + [OWSFileSystem moveAppFilePath:self.legacyDatabaseFilePath_WAL + sharedDataFilePath:self.sharedDataDatabaseFilePath_WAL exceptionName:TSStorageManagerExceptionName_CouldNotMoveDatabaseFile]; } - (NSString *)dbPath { - DDLogVerbose(@"databasePath: %@", TSStorageManager.newDatabaseFilePath); + DDLogVerbose(@"databasePath: %@", TSStorageManager.sharedDataDatabaseFilePath); - return TSStorageManager.newDatabaseFilePath; + return TSStorageManager.sharedDataDatabaseFilePath; } + (BOOL)isDatabasePasswordAccessible diff --git a/SignalServiceKit/src/Util/NSUserDefaults+OWS.m b/SignalServiceKit/src/Util/NSUserDefaults+OWS.m index 923ada8e1..746630d0e 100644 --- a/SignalServiceKit/src/Util/NSUserDefaults+OWS.m +++ b/SignalServiceKit/src/Util/NSUserDefaults+OWS.m @@ -28,9 +28,17 @@ NS_ASSUME_NONNULL_BEGIN + (void)removeAll { - NSString *appDomain = NSBundle.mainBundle.bundleIdentifier; - [NSUserDefaults.standardUserDefaults removePersistentDomainForName:appDomain]; - // TODO: How to clear the shared user defaults? + [NSUserDefaults.standardUserDefaults removeAll]; + [self.appUserDefaults removeAll]; +} + +- (void)removeAll +{ + NSDictionary *dictionary = self.dictionaryRepresentation; + for (NSString *key in dictionary) { + [self removeObjectForKey:key]; + } + [self synchronize]; } @end