Merge branch 'charlesmchen/addressSharingExtensionTODOs_'

pull/1/head
Matthew Chen 8 years ago
commit 9aa05733dc

@ -18,12 +18,27 @@ NS_ASSUME_NONNULL_BEGIN
return [UIApplication sharedApplication].applicationState == UIApplicationStateActive;
}
- (UIApplicationState)mainApplicationState
{
return [UIApplication sharedApplication].applicationState;
}
- (UIBackgroundTaskIdentifier)beginBackgroundTaskWithExpirationHandler:
(BackgroundTaskExpirationHandler)expirationHandler
{
return [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:expirationHandler];
}
- (void)endBackgroundTask:(UIBackgroundTaskIdentifier)backgroundTaskIdentifier
{
[UIApplication.sharedApplication endBackgroundTask:backgroundTaskIdentifier];
}
- (void)setMainAppBadgeNumber:(NSInteger)value
{
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:value];
}
@end
NS_ASSUME_NONNULL_END

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

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

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

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

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

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

@ -3,6 +3,7 @@
//
#import "OWSMessageSender.h"
#import "AppContext.h"
#import "ContactsUpdater.h"
#import "NSData+keyVersionByte.h"
#import "NSData+messagePadding.h"
@ -225,17 +226,15 @@ NSUInteger const OWSSendMessageOperationMaxRetries = 4;
AssertIsOnMainThread();
OWSAssert(self.backgroundTaskIdentifier == UIBackgroundTaskInvalid);
// FIXME SHARINGEXTENSION
// self.backgroundTaskIdentifier = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
// DDLogWarn(@"%@ Timed out while in background trying to send message: %@", self.logTag, self.message);
// [self endBackgroundTask];
// }];
self.backgroundTaskIdentifier = [CurrentAppContext() beginBackgroundTaskWithExpirationHandler:^{
DDLogWarn(@"%@ Timed out while in background trying to send message: %@", self.logTag, self.message);
[self endBackgroundTask];
}];
}
- (void)endBackgroundTask
{
// FIXME SHARINGEXTENSION
// [[UIApplication sharedApplication] endBackgroundTask:self.backgroundTaskIdentifier];
[CurrentAppContext() endBackgroundTask:self.backgroundTaskIdentifier];
}
- (void)setBackgroundTaskIdentifier:(UIBackgroundTaskIdentifier)backgroundTaskIdentifier
@ -266,8 +265,7 @@ NSUInteger const OWSSendMessageOperationMaxRetries = 4;
// Should call `startBackgroundTask` before enqueuing the operation
// to ensure we don't get suspended before the operation completes.
// FIXME SHARINGEXTENSION
// OWSAssert(self.backgroundTaskIdentifier != UIBackgroundTaskInvalid);
OWSAssert(!CurrentAppContext().isMainApp || self.backgroundTaskIdentifier != UIBackgroundTaskInvalid);
[self willChangeValueForKey:OWSSendMessageOperationKeyIsExecuting];
self.operationState = OWSSendMessageOperationStateExecuting;
@ -459,8 +457,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
// We call `startBackgroundTask` here to prevent our app from suspending while being backgrounded
// until the operation is completed - at which point the OWSSendMessageOperation ends it's background task.
// FIXME SHARINGEXTENSION
// [sendMessageOperation startBackgroundTask];
[sendMessageOperation startBackgroundTask];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSOperationQueue *sendingQueue = [self sendingQueueForMessage:message];

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

@ -3,6 +3,7 @@
//
#import "TSStorageManager.h"
#import "AppContext.h"
#import "NSData+Base64.h"
#import "OWSAnalytics.h"
#import "OWSBatchMessageProcessor.h"
@ -491,8 +492,8 @@ void setDatabaseInitialized()
- (void)backgroundedAppDatabasePasswordInaccessibleWithErrorDescription:(NSString *)errorDescription
{
// FIXME SHARINGEXTENSION
// OWSAssert([UIApplication sharedApplication].applicationState == UIApplicationStateBackground);
OWSAssert(
CurrentAppContext().isMainApp && CurrentAppContext().mainApplicationState == UIApplicationStateBackground);
// Sleep to give analytics events time to be delivered.
[NSThread sleepForTimeInterval:5.0f];
@ -513,20 +514,29 @@ void setDatabaseInitialized()
[SAMKeychain passwordForService:keychainService account:keychainDBPassAccount error:&keyFetchError];
if (keyFetchError) {
// FIXME SHARINGEXTENSION
// UIApplicationState applicationState = [UIApplication sharedApplication].applicationState;
// NSString *errorDescription = [NSString stringWithFormat:@"Database password inaccessible. No unlock
// since device restart? Error: %@ ApplicationState: %d", keyFetchError, (int)applicationState];
// DDLogError(@"%@ %@", self.logTag, errorDescription);
// [DDLog flushLog];
// FIXME SHARINGEXTENSION
// if ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground) {
// // TODO: Rather than crash here, we should detect the situation earlier
// // and exit gracefully - (in the app delegate?). See the `
// // This is a last ditch effort to avoid blowing away the user's database.
// [self backgroundedAppDatabasePasswordInaccessibleWithErrorDescription:errorDescription];
// }
NSString *errorDescription =
[NSString stringWithFormat:@"Database password inaccessible. No unlock since device restart? Error: %@",
keyFetchError];
if (CurrentAppContext().isMainApp) {
UIApplicationState applicationState = CurrentAppContext().mainApplicationState;
errorDescription =
[errorDescription stringByAppendingFormat:@", ApplicationState: %d", (int)applicationState];
}
DDLogError(@"%@ %@", self.logTag, errorDescription);
[DDLog flushLog];
if (CurrentAppContext().isMainApp) {
UIApplicationState applicationState = CurrentAppContext().mainApplicationState;
if (applicationState == UIApplicationStateBackground) {
// TODO: Rather than crash here, we should detect the situation earlier
// and exit gracefully - (in the app delegate?). See the `
// This is a last ditch effort to avoid blowing away the user's database.
[self backgroundedAppDatabasePasswordInaccessibleWithErrorDescription:errorDescription];
}
} else {
[self backgroundedAppDatabasePasswordInaccessibleWithErrorDescription:
@"Password inaccessible; not main app."];
}
// At this point, either this is a new install so there's no existing password to retrieve
// or the keychain has become corrupt. Either way, we want to get back to a
@ -538,11 +548,9 @@ void setDatabaseInitialized()
}
// Try to reset app by deleting database.
// FIXME SHARINGEXTENSION
OWSFail(@"disabled while Share extension is WIP");
// [self resetSignalStorage];
[self resetSignalStorage];
// dbPassword = [self createAndSetNewDatabasePassword];
dbPassword = [self createAndSetNewDatabasePassword];
}
return [dbPassword dataUsingEncoding:NSUTF8StringEncoding];

@ -11,12 +11,24 @@ typedef void (^BackgroundTaskExpirationHandler)(void);
- (BOOL)isMainApp;
- (BOOL)isMainAppAndActive;
// Should only be called if isMainApp is YES.
//
// In general, isMainAppAndActive will probably yield more readable code.
- (UIApplicationState)mainApplicationState;
// Should start a background task if isMainApp is YES.
// Should just return UIBackgroundTaskInvalid if isMainApp is NO.
- (UIBackgroundTaskIdentifier)beginBackgroundTaskWithExpirationHandler:
(BackgroundTaskExpirationHandler)expirationHandler;
// Should be a NOOP if isMainApp is NO.
- (void)endBackgroundTask:(UIBackgroundTaskIdentifier)backgroundTaskIdentifier;
// Should only be called if isMainApp is YES.
- (void)setMainAppBadgeNumber:(NSInteger)value;
@end
id<AppContext> CurrentAppContext();
id<AppContext> CurrentAppContext(void);
void SetCurrentAppContext(id<AppContext> appContext);
NS_ASSUME_NONNULL_END

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

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

Loading…
Cancel
Save