From 9ac2383a2ce776b5ee66c64f113458e505546842 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Wed, 10 Jan 2018 11:14:02 -0500 Subject: [PATCH] Retain changes from session database branch. --- .../Messages/Attachments/TSAttachmentStream.m | 4 +- .../src/Network/API/TSNetworkManager.m | 17 ++- .../src/Network/WebSockets/TSSocketManager.m | 6 +- .../src/Security/OWSRecipientIdentity.m | 60 +++++---- SignalServiceKit/src/Storage/OWSStorage.h | 4 +- SignalServiceKit/src/Storage/OWSStorage.m | 14 +++ SignalServiceKit/src/Util/AppContext.h | 13 +- SignalServiceKit/src/Util/AppContext.m | 7 +- SignalServiceKit/src/Util/AppVersion.m | 3 +- SignalServiceKit/src/Util/Asserts.h | 117 ------------------ .../src/Util/NSUserDefaults+OWS.m | 5 +- SignalServiceKit/src/Util/OWSAnalytics.m | 4 +- SignalServiceKit/src/Util/OWSBackgroundTask.m | 9 +- SignalServiceKit/src/Util/OWSDispatch.h | 8 +- SignalServiceKit/src/Util/OWSFileSystem.h | 6 +- SignalServiceKit/src/Util/OWSFileSystem.m | 11 +- .../SignalShareExtension-Bridging-Header.h | 4 +- .../SignalShareExtension-Prefix.pch | 4 +- .../utils/ShareAppExtensionContext.m | 21 +++- 19 files changed, 142 insertions(+), 175 deletions(-) delete mode 100755 SignalServiceKit/src/Util/Asserts.h diff --git a/SignalServiceKit/src/Messages/Attachments/TSAttachmentStream.m b/SignalServiceKit/src/Messages/Attachments/TSAttachmentStream.m index 60376f737..e07c06613 100644 --- a/SignalServiceKit/src/Messages/Attachments/TSAttachmentStream.m +++ b/SignalServiceKit/src/Messages/Attachments/TSAttachmentStream.m @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // #import "TSAttachmentStream.h" @@ -205,7 +205,7 @@ NS_ASSUME_NONNULL_BEGIN [OWSFileSystem ensureDirectoryExists:attachmentsFolder]; - [OWSFileSystem protectFolderAtPath:attachmentsFolder]; + [OWSFileSystem protectFileOrFolderAtPath:attachmentsFolder]; }); return attachmentsFolder; } diff --git a/SignalServiceKit/src/Network/API/TSNetworkManager.m b/SignalServiceKit/src/Network/API/TSNetworkManager.m index 2722a8ad3..f2bda72f6 100644 --- a/SignalServiceKit/src/Network/API/TSNetworkManager.m +++ b/SignalServiceKit/src/Network/API/TSNetworkManager.m @@ -1,11 +1,15 @@ // -// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // #import "TSNetworkManager.h" +#import "AppContext.h" #import "NSURLSessionDataTask+StatusCode.h" +#import "OWSGetProfileRequest.h" #import "OWSSignalService.h" #import "TSAccountManager.h" +#import "TSRecipientPrekeyRequest.h" +#import "TSSubmitMessageRequest.h" #import "TSVerifyCodeRequest.h" #import @@ -56,6 +60,17 @@ typedef void (^failureBlock)(NSURLSessionDataTask *task, NSError *error); failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failureBlock { DDLogInfo(@"%@ Making request: %@", self.logTag, request); + if (!CurrentAppContext().isMainApp) { + // TODO: Discuss which of these requests to suppress. + if (![request isKindOfClass:[TSRecipientPrekeyRequest class]] + && ![request isKindOfClass:[TSSubmitMessageRequest class]] + && ![request isKindOfClass:[OWSGetProfileRequest class]] + && ![request isKindOfClass:[TSContactsIntersectionRequest class]] + && ![request isKindOfClass:[TSAllocAttachmentRequest class]]) { + // The SAE should only make requests directly related to message sending. + OWSFail(@"%@ Making request: %@", self.logTag, request); + } + } void (^failure)(NSURLSessionDataTask *task, NSError *error) = [TSNetworkManager errorPrettifyingForFailureBlock:failureBlock]; diff --git a/SignalServiceKit/src/Network/WebSockets/TSSocketManager.m b/SignalServiceKit/src/Network/WebSockets/TSSocketManager.m index 0f73a3c68..1e8036ba9 100644 --- a/SignalServiceKit/src/Network/WebSockets/TSSocketManager.m +++ b/SignalServiceKit/src/Network/WebSockets/TSSocketManager.m @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // #import "TSSocketManager.h" @@ -125,11 +125,11 @@ NSString *const kNSNotification_SocketManagerStateDidChange = @"kNSNotification_ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidBecomeActive:) - name:UIApplicationDidBecomeActiveNotification + name:OWSApplicationDidBecomeActiveNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillResignActive:) - name:UIApplicationWillResignActiveNotification + name:OWSApplicationWillResignActiveNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(registrationStateDidChange:) diff --git a/SignalServiceKit/src/Security/OWSRecipientIdentity.m b/SignalServiceKit/src/Security/OWSRecipientIdentity.m index 03ad70d1d..3ae736d62 100644 --- a/SignalServiceKit/src/Security/OWSRecipientIdentity.m +++ b/SignalServiceKit/src/Security/OWSRecipientIdentity.m @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // #import "OWSRecipientIdentity.h" @@ -103,6 +103,37 @@ OWSSignalServiceProtosVerifiedState OWSVerificationStateToProtoState(OWSVerifica }]; } +- (void)saveWithTransaction:(YapDatabaseReadWriteTransaction *)transaction +{ + OWSAssert(transaction.connection == [OWSRecipientIdentity dbReadWriteConnection]); + + [super saveWithTransaction:transaction]; +} + +- (void)removeWithTransaction:(YapDatabaseReadWriteTransaction *)transaction +{ + OWSAssert(transaction.connection == [OWSRecipientIdentity dbReadWriteConnection]); + + [super removeWithTransaction:transaction]; +} + +- (void)touchWithTransaction:(YapDatabaseReadWriteTransaction *)transaction +{ + OWSAssert(transaction.connection == [OWSRecipientIdentity dbReadWriteConnection]); + + [super touchWithTransaction:transaction]; +} + ++ (nullable instancetype)fetchObjectWithUniqueID:(NSString *)uniqueID + transaction:(YapDatabaseReadTransaction *)transaction +{ + OWSAssert(transaction.connection == [OWSRecipientIdentity dbReadConnection]); + + return [super fetchObjectWithUniqueID:uniqueID transaction:transaction]; +} + +#pragma mark - Database Connections + + (YapDatabaseConnection *)dbReadConnection { return self.dbReadWriteConnection; @@ -128,33 +159,14 @@ OWSSignalServiceProtosVerifiedState OWSVerificationStateToProtoState(OWSVerifica return sharedDBConnection; } -- (void)saveWithTransaction:(YapDatabaseReadWriteTransaction *)transaction -{ - OWSAssert(transaction.connection == [OWSRecipientIdentity dbReadWriteConnection]); - - [super saveWithTransaction:transaction]; -} - -- (void)removeWithTransaction:(YapDatabaseReadWriteTransaction *)transaction -{ - OWSAssert(transaction.connection == [OWSRecipientIdentity dbReadWriteConnection]); - - [super removeWithTransaction:transaction]; -} - -- (void)touchWithTransaction:(YapDatabaseReadWriteTransaction *)transaction +- (YapDatabaseConnection *)dbReadConnection { - OWSAssert(transaction.connection == [OWSRecipientIdentity dbReadWriteConnection]); - - [super touchWithTransaction:transaction]; + return OWSRecipientIdentity.dbReadConnection; } -+ (nullable instancetype)fetchObjectWithUniqueID:(NSString *)uniqueID - transaction:(YapDatabaseReadTransaction *)transaction +- (YapDatabaseConnection *)dbReadWriteConnection { - OWSAssert(transaction.connection == [OWSRecipientIdentity dbReadConnection]); - - return [super fetchObjectWithUniqueID:uniqueID transaction:transaction]; + return OWSRecipientIdentity.dbReadWriteConnection; } #pragma mark - debug diff --git a/SignalServiceKit/src/Storage/OWSStorage.h b/SignalServiceKit/src/Storage/OWSStorage.h index 10d83edf8..684bb9dc4 100644 --- a/SignalServiceKit/src/Storage/OWSStorage.h +++ b/SignalServiceKit/src/Storage/OWSStorage.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // #import @@ -40,6 +40,8 @@ extern NSString *const StorageIsReadyNotification; completionBlock:(nullable void (^)(BOOL ready))completionBlock; - (nullable id)registeredExtension:(NSString *)extensionName; +- (unsigned long long)databaseFileSize; + #pragma mark - Password /** diff --git a/SignalServiceKit/src/Storage/OWSStorage.m b/SignalServiceKit/src/Storage/OWSStorage.m index bbd4935cf..56f84d653 100644 --- a/SignalServiceKit/src/Storage/OWSStorage.m +++ b/SignalServiceKit/src/Storage/OWSStorage.m @@ -596,6 +596,20 @@ static NSString *keychainDBPassAccount = @"TSDatabasePass"; [SAMKeychain deletePasswordForService:keychainService account:keychainDBPassAccount]; } +- (unsigned long long)databaseFileSize +{ + NSFileManager *fileManager = [NSFileManager defaultManager]; + NSError *_Nullable error; + unsigned long long fileSize = + [[fileManager attributesOfItemAtPath:self.databaseFilePath error:&error][NSFileSize] unsignedLongLongValue]; + if (error) { + DDLogError(@"%@ Couldn't fetch database file size: %@", self.logTag, error); + } else { + DDLogInfo(@"%@ Database file size: %llu", self.logTag, fileSize); + } + return fileSize; +} + @end NS_ASSUME_NONNULL_END diff --git a/SignalServiceKit/src/Util/AppContext.h b/SignalServiceKit/src/Util/AppContext.h index 8e5c99953..f32bf894e 100755 --- a/SignalServiceKit/src/Util/AppContext.h +++ b/SignalServiceKit/src/Util/AppContext.h @@ -1,9 +1,20 @@ // -// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // NS_ASSUME_NONNULL_BEGIN +// These are fired whenever the corresponding "main app" or "app extension" +// notification is fired. +// +// 1. This saves you the work of observing both. +// 2. This allows us to ensure that any critical work (e.g. re-opening +// databases) has been done before app re-enters foreground, etc. +extern NSString *const OWSApplicationDidEnterBackgroundNotification; +extern NSString *const OWSApplicationWillEnterForegroundNotification; +extern NSString *const OWSApplicationWillResignActiveNotification; +extern NSString *const OWSApplicationDidBecomeActiveNotification; + typedef void (^BackgroundTaskExpirationHandler)(void); @class OWSAES256Key; diff --git a/SignalServiceKit/src/Util/AppContext.m b/SignalServiceKit/src/Util/AppContext.m index f38b586da..724f8df94 100755 --- a/SignalServiceKit/src/Util/AppContext.m +++ b/SignalServiceKit/src/Util/AppContext.m @@ -1,11 +1,16 @@ // -// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // #import "AppContext.h" NS_ASSUME_NONNULL_BEGIN +NSString *const OWSApplicationDidEnterBackgroundNotification = @"OWSApplicationDidEnterBackgroundNotification"; +NSString *const OWSApplicationWillEnterForegroundNotification = @"OWSApplicationWillEnterForegroundNotification"; +NSString *const OWSApplicationWillResignActiveNotification = @"OWSApplicationWillResignActiveNotification"; +NSString *const OWSApplicationDidBecomeActiveNotification = @"OWSApplicationDidBecomeActiveNotification"; + static id currentAppContext = nil; id CurrentAppContext(void) diff --git a/SignalServiceKit/src/Util/AppVersion.m b/SignalServiceKit/src/Util/AppVersion.m index b7277b06c..863bfc79a 100755 --- a/SignalServiceKit/src/Util/AppVersion.m +++ b/SignalServiceKit/src/Util/AppVersion.m @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // #import "AppVersion.h" @@ -32,6 +32,7 @@ NSString *const kNSUserDefaults_LastCompletedLaunchAppVersion = @"kNSUserDefault return instance; } +// TODO: Modify these NSUserDefaults keys for SAE. - (void)configure { self.currentAppVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]; diff --git a/SignalServiceKit/src/Util/Asserts.h b/SignalServiceKit/src/Util/Asserts.h deleted file mode 100755 index 2d9bad1a8..000000000 --- a/SignalServiceKit/src/Util/Asserts.h +++ /dev/null @@ -1,117 +0,0 @@ -// -// Copyright (c) 2017 Open Whisper Systems. All rights reserved. -// - -#ifndef OWSAssert - -#ifdef DEBUG - -#define USE_ASSERTS - -#define CONVERT_TO_STRING(X) #X -#define CONVERT_EXPR_TO_STRING(X) CONVERT_TO_STRING(X) - -// OWSAssert() and OWSFail() should be used in Obj-C methods. -// OWSCAssert() and OWSCFail() should be used in free functions. - -#define OWSAssert(X) \ - if (!(X)) { \ - DDLogError(@"%s Assertion failed: %s", __PRETTY_FUNCTION__, CONVERT_EXPR_TO_STRING(X)); \ - [DDLog flushLog]; \ - NSAssert(0, @"Assertion failed: %s", CONVERT_EXPR_TO_STRING(X)); \ - } - -#define OWSCAssert(X) \ - if (!(X)) { \ - DDLogError(@"%s Assertion failed: %s", __PRETTY_FUNCTION__, CONVERT_EXPR_TO_STRING(X)); \ - [DDLog flushLog]; \ - NSCAssert(0, @"Assertion failed: %s", CONVERT_EXPR_TO_STRING(X)); \ - } - -#define OWSFail(message, ...) \ - { \ - NSString *formattedMessage = [NSString stringWithFormat:message, ##__VA_ARGS__]; \ - DDLogError(@"%s %@", __PRETTY_FUNCTION__, formattedMessage); \ - [DDLog flushLog]; \ - NSAssert(0, formattedMessage); \ - } - -#define OWSCFail(message, ...) \ - { \ - NSString *formattedMessage = [NSString stringWithFormat:message, ##__VA_ARGS__]; \ - DDLogError(@"%s %@", __PRETTY_FUNCTION__, formattedMessage); \ - [DDLog flushLog]; \ - NSCAssert(0, formattedMessage); \ - } - -#define OWSFailNoFormat(message) \ - { \ - DDLogError(@"%s %@", __PRETTY_FUNCTION__, message); \ - [DDLog flushLog]; \ - NSAssert(0, message); \ - } - -#define OWSCFailNoFormat(message) \ - { \ - DDLogError(@"%s %@", __PRETTY_FUNCTION__, message); \ - [DDLog flushLog]; \ - NSCAssert(0, message); \ - } - -#else - -#define OWSAssert(X) -#define OWSCAssert(X) -#define OWSFail(message, ...) -#define OWSCFail(message, ...) -#define OWSFailNoFormat(X) -#define OWSCFailNoFormat(X) - -#endif - -#endif - -#define OWS_ABSTRACT_METHOD() OWSFail(@"Method needs to be implemented by subclasses.") - -#pragma mark - Singleton Asserts - -// The "singleton asserts" can be used to ensure -// that we only create a singleton once. -// -// The simplest way to use them is the OWSSingletonAssert() macro. -// It is intended to be used inside the singleton's initializer. -// -// If, however, a singleton has multiple possible initializers, -// you need to: -// -// 1. Use OWSSingletonAssertFlag() outside the class definition. -// 2. Use OWSSingletonAssertInit() in each initializer. - -#ifndef SSK_BUILDING_FOR_TESTS -#ifdef DEBUG - -#define ENFORCE_SINGLETONS - -#endif -#endif - -#ifdef ENFORCE_SINGLETONS - -#define OWSSingletonAssertFlag() static BOOL _isSingletonCreated = NO; - -#define OWSSingletonAssertInit() \ - @synchronized([self class]) \ - { \ - OWSAssert(!_isSingletonCreated); \ - _isSingletonCreated = YES; \ - } - -#define OWSSingletonAssert() OWSSingletonAssertFlag() OWSSingletonAssertInit() - -#else - -#define OWSSingletonAssertFlag() -#define OWSSingletonAssertInit() -#define OWSSingletonAssert() - -#endif diff --git a/SignalServiceKit/src/Util/NSUserDefaults+OWS.m b/SignalServiceKit/src/Util/NSUserDefaults+OWS.m index 746630d0e..76d9b698f 100644 --- a/SignalServiceKit/src/Util/NSUserDefaults+OWS.m +++ b/SignalServiceKit/src/Util/NSUserDefaults+OWS.m @@ -1,7 +1,8 @@ // -// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // +#import "AppContext.h" #import "NSUserDefaults+OWS.h" #import "TSConstants.h" @@ -34,6 +35,8 @@ NS_ASSUME_NONNULL_BEGIN - (void)removeAll { + OWSAssert(CurrentAppContext().isMainApp); + NSDictionary *dictionary = self.dictionaryRepresentation; for (NSString *key in dictionary) { [self removeObjectForKey:key]; diff --git a/SignalServiceKit/src/Util/OWSAnalytics.m b/SignalServiceKit/src/Util/OWSAnalytics.m index 7a42759f9..403317d53 100755 --- a/SignalServiceKit/src/Util/OWSAnalytics.m +++ b/SignalServiceKit/src/Util/OWSAnalytics.m @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // #import "OWSAnalytics.h" @@ -101,7 +101,7 @@ NSString *NSStringForOWSAnalyticsSeverity(OWSAnalyticsSeverity severity) object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidBecomeActive) - name:UIApplicationDidBecomeActiveNotification + name:OWSApplicationDidBecomeActiveNotification object:nil]; } diff --git a/SignalServiceKit/src/Util/OWSBackgroundTask.m b/SignalServiceKit/src/Util/OWSBackgroundTask.m index b9fee0ec3..bee9fc046 100644 --- a/SignalServiceKit/src/Util/OWSBackgroundTask.m +++ b/SignalServiceKit/src/Util/OWSBackgroundTask.m @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // #import "OWSBackgroundTask.h" @@ -134,8 +134,6 @@ // Make a local copy of this state, since this method is called by `dealloc`. UIBackgroundTaskIdentifier backgroundTaskId; BackgroundTaskCompletionBlock _Nullable completionBlock; - NSString *logTag = self.logTag; - NSString *label = self.label; @synchronized(self) { @@ -151,13 +149,14 @@ // endBackgroundTask must be called on the main thread. DispatchMainThreadSafe(^{ - DDLogVerbose(@"%@ %@ background task completed.", logTag, label); if (completionBlock) { completionBlock(BackgroundTaskState_Success); } - [CurrentAppContext() endBackgroundTask:backgroundTaskId]; + if (backgroundTaskId != UIBackgroundTaskInvalid) { + [CurrentAppContext() endBackgroundTask:backgroundTaskId]; + } }); } diff --git a/SignalServiceKit/src/Util/OWSDispatch.h b/SignalServiceKit/src/Util/OWSDispatch.h index 9996b9940..c9e1f7001 100644 --- a/SignalServiceKit/src/Util/OWSDispatch.h +++ b/SignalServiceKit/src/Util/OWSDispatch.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // NS_ASSUME_NONNULL_BEGIN @@ -24,10 +24,4 @@ NS_ASSUME_NONNULL_BEGIN @end -// This macro is intended for use in Objective-C. -#define OWSAssertIsOnMainThread() OWSCAssert([NSThread isMainThread]) - -// This function is intended for use in Swift. -void AssertIsOnMainThread(void); - NS_ASSUME_NONNULL_END diff --git a/SignalServiceKit/src/Util/OWSFileSystem.h b/SignalServiceKit/src/Util/OWSFileSystem.h index 2d594894e..898266fa2 100644 --- a/SignalServiceKit/src/Util/OWSFileSystem.h +++ b/SignalServiceKit/src/Util/OWSFileSystem.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // NS_ASSUME_NONNULL_BEGIN @@ -8,7 +8,7 @@ NS_ASSUME_NONNULL_BEGIN - (instancetype)init NS_UNAVAILABLE; -+ (void)protectFolderAtPath:(NSString *)path; ++ (void)protectFileOrFolderAtPath:(NSString *)path; + (NSString *)appDocumentDirectoryPath; @@ -25,6 +25,8 @@ NS_ASSUME_NONNULL_BEGIN + (void)deleteFile:(NSString *)filePath; ++ (void)deleteFileIfExists:(NSString *)filePath; + @end NS_ASSUME_NONNULL_END diff --git a/SignalServiceKit/src/Util/OWSFileSystem.m b/SignalServiceKit/src/Util/OWSFileSystem.m index 654aaf18c..11f4b2a1d 100644 --- a/SignalServiceKit/src/Util/OWSFileSystem.m +++ b/SignalServiceKit/src/Util/OWSFileSystem.m @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // #import "OWSFileSystem.h" @@ -9,7 +9,7 @@ NS_ASSUME_NONNULL_BEGIN @implementation OWSFileSystem -+ (void)protectFolderAtPath:(NSString *)path ++ (void)protectFileOrFolderAtPath:(NSString *)path { if (![NSFileManager.defaultManager fileExistsAtPath:path]) { return; @@ -124,6 +124,13 @@ NS_ASSUME_NONNULL_BEGIN } } ++ (void)deleteFileIfExists:(NSString *)filePath +{ + if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) { + [self deleteFile:filePath]; + } +} + @end NS_ASSUME_NONNULL_END diff --git a/SignalShareExtension/SignalShareExtension-Bridging-Header.h b/SignalShareExtension/SignalShareExtension-Bridging-Header.h index cdad2cb66..092490e40 100644 --- a/SignalShareExtension/SignalShareExtension-Bridging-Header.h +++ b/SignalShareExtension/SignalShareExtension-Bridging-Header.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // #import @@ -21,7 +21,7 @@ #import #import #import -#import #import +#import #import #import diff --git a/SignalShareExtension/SignalShareExtension-Prefix.pch b/SignalShareExtension/SignalShareExtension-Prefix.pch index 27fe91e1d..bf34561b0 100644 --- a/SignalShareExtension/SignalShareExtension-Prefix.pch +++ b/SignalShareExtension/SignalShareExtension-Prefix.pch @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // #import @@ -15,7 +15,7 @@ static const NSUInteger ddLogLevel = DDLogLevelInfo; #endif - #import + #import #import #import #import diff --git a/SignalShareExtension/utils/ShareAppExtensionContext.m b/SignalShareExtension/utils/ShareAppExtensionContext.m index 8a383ff68..7de1200a2 100644 --- a/SignalShareExtension/utils/ShareAppExtensionContext.m +++ b/SignalShareExtension/utils/ShareAppExtensionContext.m @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // #import "ShareAppExtensionContext.h" @@ -58,24 +58,43 @@ NS_ASSUME_NONNULL_BEGIN - (void)extensionHostDidBecomeActive:(NSNotification *)notification { + OWSAssertIsOnMainThread(); + DDLogInfo(@"%@ %s", self.logTag, __PRETTY_FUNCTION__); + + [NSNotificationCenter.defaultCenter postNotificationName:OWSApplicationDidBecomeActiveNotification object:nil]; } - (void)extensionHostWillResignActive:(NSNotification *)notification { + OWSAssertIsOnMainThread(); + DDLogInfo(@"%@ %s", self.logTag, __PRETTY_FUNCTION__); [DDLog flushLog]; + + [NSNotificationCenter.defaultCenter postNotificationName:OWSApplicationWillResignActiveNotification object:nil]; } - (void)extensionHostDidEnterBackground:(NSNotification *)notification { + OWSAssertIsOnMainThread(); + DDLogInfo(@"%@ %s", self.logTag, __PRETTY_FUNCTION__); [DDLog flushLog]; + + [NSNotificationCenter.defaultCenter postNotificationName:OWSApplicationDidEnterBackgroundNotification object:nil]; } - (void)extensionHostWillEnterForeground:(NSNotification *)notification { + OWSAssertIsOnMainThread(); + DDLogInfo(@"%@ %s", self.logTag, __PRETTY_FUNCTION__); + + // We want to prod OWSStorage here so that all storage is valid. + [OWSStorage applicationWillEnterForeground]; + + [NSNotificationCenter.defaultCenter postNotificationName:OWSApplicationWillEnterForegroundNotification object:nil]; } #pragma mark -