Use AppContext to resolve share extension FIXMEs.

pull/1/head
Matthew Chen 7 years ago
parent 94436f7b04
commit e712e8bfc4

@ -24,6 +24,16 @@ NS_ASSUME_NONNULL_BEGIN
return [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:expirationHandler]; return [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:expirationHandler];
} }
- (void)endBackgroundTask:(UIBackgroundTaskIdentifier)backgroundTaskIdentifier
{
[UIApplication.sharedApplication endBackgroundTask:backgroundTaskIdentifier];
}
- (void)setMainAppBadgeNumber:(NSInteger)value
{
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:value];
}
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

@ -3,6 +3,7 @@
// //
#import "TSPreKeyManager.h" #import "TSPreKeyManager.h"
#import "AppContext.h"
#import "NSDate+OWS.h" #import "NSDate+OWS.h"
#import "NSURLSessionDataTask+StatusCode.h" #import "NSURLSessionDataTask+StatusCode.h"
#import "OWSIdentityManager.h" #import "OWSIdentityManager.h"
@ -90,8 +91,9 @@ static const NSTimeInterval kSignedPreKeyUpdateFailureMaxFailureDuration = 10 *
+ (void)checkPreKeysIfNecessary + (void)checkPreKeysIfNecessary
{ {
// FIXME SHARINGEXTENSION if (CurrentAppContext().isMainApp) {
// OWSAssert([UIApplication sharedApplication].applicationState == UIApplicationStateActive); OWSAssert(CurrentAppContext().isMainAppAndActive);
}
// Update the prekey check timestamp. // Update the prekey check timestamp.
dispatch_async(TSPreKeyManager.prekeyQueue, ^{ dispatch_async(TSPreKeyManager.prekeyQueue, ^{

@ -3,6 +3,7 @@
// //
#import "OWSBatchMessageProcessor.h" #import "OWSBatchMessageProcessor.h"
#import "AppContext.h"
#import "NSArray+OWS.h" #import "NSArray+OWS.h"
#import "OWSMessageManager.h" #import "OWSMessageManager.h"
#import "OWSQueues.h" #import "OWSQueues.h"
@ -297,6 +298,11 @@ NSString *const OWSMessageContentJobFinderExtensionGroup = @"OWSMessageContentJo
- (void)drainQueue - (void)drainQueue
{ {
// Don't process incoming messages in app extensions.
if (!CurrentAppContext().isMainApp) {
return;
}
dispatch_async(self.serialQueue, ^{ dispatch_async(self.serialQueue, ^{
if ([TSDatabaseView hasPendingViewRegistrations]) { if ([TSDatabaseView hasPendingViewRegistrations]) {
// We don't want to process incoming messages until database // We don't want to process incoming messages until database

@ -3,6 +3,7 @@
// //
#import "OWSDisappearingMessagesJob.h" #import "OWSDisappearingMessagesJob.h"
#import "AppContext.h"
#import "ContactsManagerProtocol.h" #import "ContactsManagerProtocol.h"
#import "NSDate+OWS.h" #import "NSDate+OWS.h"
#import "NSTimer+OWS.h" #import "NSTimer+OWS.h"
@ -320,12 +321,10 @@ NS_ASSUME_NONNULL_BEGIN
OWSAssert(date); OWSAssert(date);
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
if (!CurrentAppContext().isMainAppAndActive) {
// FIXME SHARINGEXTENSION // Don't schedule run when inactive or not in main app.
// if ([UIApplication sharedApplication].applicationState != UIApplicationStateActive) { return;
// // Don't schedule run when inactive. }
// return;
// }
NSDateFormatter *dateFormatter = [NSDateFormatter new]; NSDateFormatter *dateFormatter = [NSDateFormatter new];
dateFormatter.dateStyle = NSDateFormatterNoStyle; dateFormatter.dateStyle = NSDateFormatterNoStyle;
@ -366,12 +365,10 @@ NS_ASSUME_NONNULL_BEGIN
{ {
OWSAssert([NSThread isMainThread]); OWSAssert([NSThread isMainThread]);
// FIXME SHARINGEXTENSION if (!CurrentAppContext().isMainAppAndActive) {
// if ([UIApplication sharedApplication].applicationState != UIApplicationStateActive) { // Don't schedule run when inactive or not in main app.
// // Don't run when inactive. return;
// OWSFail(@"%@ Disappearing messages job timer fired while app inactive.", self.logTag); }
// return;
// }
[self resetTimer]; [self resetTimer];

@ -3,6 +3,7 @@
// //
#import "OWSIdentityManager.h" #import "OWSIdentityManager.h"
#import "AppContext.h"
#import "NSDate+OWS.h" #import "NSDate+OWS.h"
#import "NSNotificationCenter+OWS.h" #import "NSNotificationCenter+OWS.h"
#import "NotificationsProtocol.h" #import "NotificationsProtocol.h"
@ -19,8 +20,8 @@
#import "TSStorageManager+sessionStore.h" #import "TSStorageManager+sessionStore.h"
#import "TSStorageManager.h" #import "TSStorageManager.h"
#import "TextSecureKitEnv.h" #import "TextSecureKitEnv.h"
#import <Curve25519Kit/Curve25519.h>
#import <AxolotlKit/NSData+keyVersionByte.h> #import <AxolotlKit/NSData+keyVersionByte.h>
#import <Curve25519Kit/Curve25519.h>
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@ -443,13 +444,12 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa
{ {
OWSAssert([NSThread isMainThread]); OWSAssert([NSThread isMainThread]);
// FIXME SHARINGEXTENSION if (!CurrentAppContext().isMainAppAndActive) {
// if ([UIApplication sharedApplication].applicationState != UIApplicationStateActive) { // Only try to sync if the main app is active to avoid interfering with startup.
// // Only try to sync if the app is active to avoid interfering with startup. //
// // // applicationDidBecomeActive: will try to sync again when the main app becomes active.
// // applicationDidBecomeActive: will try to sync again when the app becomes active. return;
// return; }
// }
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
@synchronized(self) @synchronized(self)

@ -3,6 +3,7 @@
// //
#import "OWSMessageManager.h" #import "OWSMessageManager.h"
#import "AppContext.h"
#import "ContactsManagerProtocol.h" #import "ContactsManagerProtocol.h"
#import "Cryptography.h" #import "Cryptography.h"
#import "MimeTypeUtil.h" #import "MimeTypeUtil.h"
@ -149,6 +150,7 @@ NS_ASSUME_NONNULL_BEGIN
OWSAssert(envelope); OWSAssert(envelope);
OWSAssert(transaction); OWSAssert(transaction);
OWSAssert([TSAccountManager isRegistered]); OWSAssert([TSAccountManager isRegistered]);
OWSAssert(CurrentAppContext().isMainApp);
DDLogInfo(@"%@ handling decrypted envelope: %@", self.logTag, [self descriptionForEnvelope:envelope]); DDLogInfo(@"%@ handling decrypted envelope: %@", self.logTag, [self descriptionForEnvelope:envelope]);
@ -1136,9 +1138,12 @@ NS_ASSUME_NONNULL_BEGIN
- (void)updateApplicationBadgeCount - (void)updateApplicationBadgeCount
{ {
if (!CurrentAppContext().isMainApp) {
return;
}
NSUInteger numberOfItems = [self unreadMessagesCount]; NSUInteger numberOfItems = [self unreadMessagesCount];
// FIXME SHARINGEXTENSION can't use UIApplication.sharedAplication [CurrentAppContext() setMainAppBadgeNumber:numberOfItems];
// [[UIApplication sharedApplication] setApplicationIconBadgeNumber:numberOfItems];
} }
- (NSUInteger)unreadMessagesInThread:(TSThread *)thread - (NSUInteger)unreadMessagesInThread:(TSThread *)thread

@ -3,6 +3,7 @@
// //
#import "OWSMessageReceiver.h" #import "OWSMessageReceiver.h"
#import "AppContext.h"
#import "NSArray+OWS.h" #import "NSArray+OWS.h"
#import "OWSBatchMessageProcessor.h" #import "OWSBatchMessageProcessor.h"
#import "OWSMessageDecrypter.h" #import "OWSMessageDecrypter.h"
@ -274,6 +275,11 @@ NSString *const OWSMessageDecryptJobFinderExtensionGroup = @"OWSMessageProcessin
- (void)drainQueue - (void)drainQueue
{ {
// Don't decrypt messages in app extensions.
if (!CurrentAppContext().isMainApp) {
return;
}
dispatch_async(self.serialQueue, ^{ dispatch_async(self.serialQueue, ^{
if ([TSDatabaseView hasPendingViewRegistrations]) { if ([TSDatabaseView hasPendingViewRegistrations]) {
// We don't want to process incoming messages until database // We don't want to process incoming messages until database

@ -3,6 +3,7 @@
// //
#import "OWSMessageSender.h" #import "OWSMessageSender.h"
#import "AppContext.h"
#import "ContactsUpdater.h" #import "ContactsUpdater.h"
#import "NSData+keyVersionByte.h" #import "NSData+keyVersionByte.h"
#import "NSData+messagePadding.h" #import "NSData+messagePadding.h"

@ -3,6 +3,7 @@
// //
#import "TSSocketManager.h" #import "TSSocketManager.h"
#import "AppContext.h"
#import "Cryptography.h" #import "Cryptography.h"
#import "NSNotificationCenter+OWS.h" #import "NSNotificationCenter+OWS.h"
#import "NSTimer+OWS.h" #import "NSTimer+OWS.h"
@ -120,9 +121,7 @@ NSString *const kNSNotification_SocketManagerStateDidChange = @"kNSNotification_
} }
self.hasObservedNotifications = YES; self.hasObservedNotifications = YES;
// // FIXME SHARINGEXTENSION self.appIsActive = CurrentAppContext().isMainAppAndActive;
// self.appIsActive = [UIApplication sharedApplication].applicationState == UIApplicationStateActive;
self.appIsActive = YES;
[[NSNotificationCenter defaultCenter] addObserver:self [[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationDidBecomeActive:) selector:@selector(applicationDidBecomeActive:)
@ -495,6 +494,11 @@ NSString *const kNSNotification_SocketManagerStateDidChange = @"kNSNotification_
{ {
OWSAssert([NSThread isMainThread]); OWSAssert([NSThread isMainThread]);
// Don't open socket in app extensions.
if (!CurrentAppContext().isMainApp) {
return NO;
}
if (![TSAccountManager isRegistered]) { if (![TSAccountManager isRegistered]) {
return NO; return NO;
} }
@ -547,16 +551,14 @@ NSString *const kNSNotification_SocketManagerStateDidChange = @"kNSNotification_
// Additionally, we want the reconnect timer to work in the background too. // Additionally, we want the reconnect timer to work in the background too.
[[NSRunLoop mainRunLoop] addTimer:self.backgroundKeepAliveTimer forMode:NSDefaultRunLoopMode]; [[NSRunLoop mainRunLoop] addTimer:self.backgroundKeepAliveTimer forMode:NSDefaultRunLoopMode];
// FIXME SHARINGEXTENSION self.fetchingTaskIdentifier = [CurrentAppContext() beginBackgroundTaskWithExpirationHandler:^{
// self.fetchingTaskIdentifier = OWSAssert([NSThread isMainThread]);
// [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
// OWSAssert([NSThread isMainThread]); DDLogInfo(@"%s background task expired", __PRETTY_FUNCTION__);
//
// DDLogInfo(@"%s background task expired", __PRETTY_FUNCTION__); [self clearBackgroundState];
// [self applyDesiredSocketState];
// [self clearBackgroundState]; }];
// [self applyDesiredSocketState];
// }];
} else { } else {
OWSAssert(self.backgroundKeepAliveUntilDate); OWSAssert(self.backgroundKeepAliveUntilDate);
OWSAssert(self.backgroundKeepAliveTimer); OWSAssert(self.backgroundKeepAliveTimer);
@ -623,8 +625,7 @@ NSString *const kNSNotification_SocketManagerStateDidChange = @"kNSNotification_
self.backgroundKeepAliveTimer = nil; self.backgroundKeepAliveTimer = nil;
if (self.fetchingTaskIdentifier != UIBackgroundTaskInvalid) { if (self.fetchingTaskIdentifier != UIBackgroundTaskInvalid) {
// FIXME SHARINGEXTENSION [CurrentAppContext() endBackgroundTask:self.fetchingTaskIdentifier];
// [[UIApplication sharedApplication] endBackgroundTask:self.fetchingTaskIdentifier];
self.fetchingTaskIdentifier = UIBackgroundTaskInvalid; self.fetchingTaskIdentifier = UIBackgroundTaskInvalid;
} }
} }

@ -3,6 +3,7 @@
// //
#import "TSStorageManager.h" #import "TSStorageManager.h"
#import "AppContext.h"
#import "NSData+Base64.h" #import "NSData+Base64.h"
#import "OWSAnalytics.h" #import "OWSAnalytics.h"
#import "OWSBatchMessageProcessor.h" #import "OWSBatchMessageProcessor.h"

@ -11,12 +11,17 @@ typedef void (^BackgroundTaskExpirationHandler)(void);
- (BOOL)isMainApp; - (BOOL)isMainApp;
- (BOOL)isMainAppAndActive; - (BOOL)isMainAppAndActive;
// Is a NOOP if isMainApp is NO.
- (UIBackgroundTaskIdentifier)beginBackgroundTaskWithExpirationHandler: - (UIBackgroundTaskIdentifier)beginBackgroundTaskWithExpirationHandler:
(BackgroundTaskExpirationHandler)expirationHandler; (BackgroundTaskExpirationHandler)expirationHandler;
- (void)endBackgroundTask:(UIBackgroundTaskIdentifier)backgroundTaskIdentifier;
// Should only be called if isMainApp is YES.
- (void)setMainAppBadgeNumber:(NSInteger)value;
@end @end
id<AppContext> CurrentAppContext(); id<AppContext> CurrentAppContext(void);
void SetCurrentAppContext(id<AppContext> appContext); void SetCurrentAppContext(id<AppContext> appContext);
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

@ -8,7 +8,7 @@ NS_ASSUME_NONNULL_BEGIN
static id<AppContext> currentAppContext = nil; static id<AppContext> currentAppContext = nil;
id<AppContext> CurrentAppContext() id<AppContext> CurrentAppContext(void)
{ {
OWSCAssert(currentAppContext); OWSCAssert(currentAppContext);

@ -3,6 +3,7 @@
// //
#import "OWSAnalytics.h" #import "OWSAnalytics.h"
#import "AppContext.h"
#import "OWSQueues.h" #import "OWSQueues.h"
#import "TSStorageManager.h" #import "TSStorageManager.h"
#import <CocoaLumberjack/CocoaLumberjack.h> #import <CocoaLumberjack/CocoaLumberjack.h>
@ -231,12 +232,11 @@ NSString *NSStringForOWSAnalyticsSeverity(OWSAnalyticsSeverity severity)
DDLogDebug(@"%@ submitting: %@", self.logTag, eventKey); DDLogDebug(@"%@ submitting: %@", self.logTag, eventKey);
__block UIBackgroundTaskIdentifier task; __block UIBackgroundTaskIdentifier task;
// FIXME SHARINGEXTENSION can't use UIApplication.sharedAplication task = [CurrentAppContext() beginBackgroundTaskWithExpirationHandler:^{
// task = [UIApplication.sharedApplication beginBackgroundTaskWithExpirationHandler:^{ failureBlock();
// failureBlock();
// [CurrentAppContext() endBackgroundTask:task];
// [UIApplication.sharedApplication endBackgroundTask:task]; }];
// }];
// Until we integrate with an analytics platform, behave as though all event delivery succeeds. // Until we integrate with an analytics platform, behave as though all event delivery succeeds.
dispatch_async(self.serialQueue, ^{ dispatch_async(self.serialQueue, ^{
@ -246,8 +246,7 @@ NSString *NSStringForOWSAnalyticsSeverity(OWSAnalyticsSeverity severity)
} else { } else {
failureBlock(); failureBlock();
} }
// FIXME SHARINGEXTENSION can't use UIApplication.sharedAplication [CurrentAppContext() endBackgroundTask:task];
// [UIApplication.sharedApplication endBackgroundTask:task];
}); });
} }

Loading…
Cancel
Save