From 97169f521afaeee6472d9dfa70a0be1fb1087e4b Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Wed, 5 Jul 2017 17:54:22 -0400 Subject: [PATCH 1/3] =?UTF-8?q?Move=20more=20initialization=20until=20afte?= =?UTF-8?q?r=20didBecomeActive=20is=20complete=20to=20avoid=20the=20?= =?UTF-8?q?=E2=80=9Cbad=20food=E2=80=9D=20crash.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit // FREEBIE --- Signal/src/AppDelegate.m | 94 +++++++++++++++++++++------------------- 1 file changed, 50 insertions(+), 44 deletions(-) diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index 0c45b54df..e3d2c3c87 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -136,50 +136,6 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; [self prepareScreenProtection]; - // At this point, potentially lengthy DB locking migrations could be running. - // Avoid blocking app launch by putting all further possible DB access in async thread. - [[TSAccountManager sharedInstance] - ifRegistered:YES - runAsync:^{ - DDLogInfo( - @"%@ running post launch block for registered user: %@", self.tag, [TSAccountManager localNumber]); - - [TSSocketManager requestSocketOpen]; - - RTCInitializeSSL(); - - [OWSSyncPushTokensJob runWithPushManager:[PushManager sharedManager] - accountManager:[Environment getCurrent].accountManager - preferences:[Environment preferences] - showAlerts:NO]; - - // Clean up any messages that expired since last launch immediately - // and continue cleaning in the background. - [[OWSDisappearingMessagesJob sharedJob] startIfNecessary]; - - // Mark all "attempting out" messages as "unsent", i.e. any messages that were not successfully - // sent before the app exited should be marked as failures. - [[[OWSFailedMessagesJob alloc] initWithStorageManager:[TSStorageManager sharedManager]] run]; - [[[OWSFailedAttachmentDownloadsJob alloc] initWithStorageManager:[TSStorageManager sharedManager]] run]; - - [AppStoreRating setupRatingLibrary]; - }]; - - [[TSAccountManager sharedInstance] - ifRegistered:NO - runAsync:^{ - dispatch_async(dispatch_get_main_queue(), ^{ - DDLogInfo(@"%@ running post launch block for unregistered user.", self.tag); - [TSSocketManager requestSocketOpen]; - - UITapGestureRecognizer *gesture = - [[UITapGestureRecognizer alloc] initWithTarget:[Pastelog class] action:@selector(submitLogs)]; - gesture.numberOfTapsRequired = 8; - [self.window addGestureRecognizer:gesture]; - }); - RTCInitializeSSL(); - }]; - self.contactsSyncing = [[OWSContactsSyncing alloc] initWithContactsManager:[Environment getCurrent].contactsManager identityManager:[OWSIdentityManager sharedManager] messageSender:[Environment getCurrent].messageSender]; @@ -505,6 +461,56 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; // Always check prekeys after app launches, and sometimes check on app activation. [TSPreKeyManager checkPreKeysIfNecessary]; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + // At this point, potentially lengthy DB locking migrations could be running. + // Avoid blocking app launch by putting all further possible DB access in async thread. + [[TSAccountManager sharedInstance] + ifRegistered:YES + runAsync:^{ + DDLogInfo(@"%@ running post launch block for registered user: %@", + self.tag, + [TSAccountManager localNumber]); + + [TSSocketManager requestSocketOpen]; + + RTCInitializeSSL(); + + [OWSSyncPushTokensJob runWithPushManager:[PushManager sharedManager] + accountManager:[Environment getCurrent].accountManager + preferences:[Environment preferences] + showAlerts:NO]; + + // Clean up any messages that expired since last launch immediately + // and continue cleaning in the background. + [[OWSDisappearingMessagesJob sharedJob] startIfNecessary]; + + // Mark all "attempting out" messages as "unsent", i.e. any messages that were not successfully + // sent before the app exited should be marked as failures. + [[[OWSFailedMessagesJob alloc] initWithStorageManager:[TSStorageManager sharedManager]] run]; + [[[OWSFailedAttachmentDownloadsJob alloc] initWithStorageManager:[TSStorageManager sharedManager]] + run]; + + [AppStoreRating setupRatingLibrary]; + }]; + + [[TSAccountManager sharedInstance] + ifRegistered:NO + runAsync:^{ + dispatch_async(dispatch_get_main_queue(), ^{ + DDLogInfo(@"%@ running post launch block for unregistered user.", self.tag); + [TSSocketManager requestSocketOpen]; + + UITapGestureRecognizer *gesture = + [[UITapGestureRecognizer alloc] initWithTarget:[Pastelog class] + action:@selector(submitLogs)]; + gesture.numberOfTapsRequired = 8; + [self.window addGestureRecognizer:gesture]; + }); + RTCInitializeSSL(); + }]; + }); + DDLogInfo(@"%@ applicationDidBecomeActive completed.", self.tag); } From ab3aa9d0ce966ab10f0c0a0d02b3e3b4bba8a722 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Wed, 5 Jul 2017 18:12:06 -0400 Subject: [PATCH 2/3] Respond to CR. // FREEBIE --- Signal/src/AppDelegate.m | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index e3d2c3c87..1d00b4710 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -436,23 +436,6 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; if (getenv("runningTests_dontStartApp")) { return; } - - [[TSAccountManager sharedInstance] ifRegistered:YES - runAsync:^{ - // We're double checking that the app is active, to be sure since we - // can't verify in production env due to code - // signing. - [TSSocketManager requestSocketOpen]; - - dispatch_async(dispatch_get_main_queue(), ^{ - [[Environment getCurrent] - .contactsManager fetchSystemContactsIfAlreadyAuthorized]; - }); - - // This will fetch new messages, if we're using domain - // fronting. - [[PushManager sharedManager] applicationDidBecomeActive]; - }]; [self removeScreenProtection]; @@ -499,6 +482,7 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; runAsync:^{ dispatch_async(dispatch_get_main_queue(), ^{ DDLogInfo(@"%@ running post launch block for unregistered user.", self.tag); + [TSSocketManager requestSocketOpen]; UITapGestureRecognizer *gesture = @@ -511,6 +495,18 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; }]; }); + [[TSAccountManager sharedInstance] + ifRegistered:YES + runAsync:^{ + dispatch_async(dispatch_get_main_queue(), ^{ + [[Environment getCurrent].contactsManager fetchSystemContactsIfAlreadyAuthorized]; + }); + + // This will fetch new messages, if we're using domain + // fronting. + [[PushManager sharedManager] applicationDidBecomeActive]; + }]; + DDLogInfo(@"%@ applicationDidBecomeActive completed.", self.tag); } From c5bf85d0b30d651d22744b6302bd2c8b36c412bc Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Wed, 5 Jul 2017 18:49:02 -0400 Subject: [PATCH 3/3] Respond to CR. // FREEBIE --- Signal/src/AppDelegate.m | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index 1d00b4710..b9d9026a9 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -455,8 +455,6 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; self.tag, [TSAccountManager localNumber]); - [TSSocketManager requestSocketOpen]; - RTCInitializeSSL(); [OWSSyncPushTokensJob runWithPushManager:[PushManager sharedManager] @@ -484,7 +482,7 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; DDLogInfo(@"%@ running post launch block for unregistered user.", self.tag); [TSSocketManager requestSocketOpen]; - + UITapGestureRecognizer *gesture = [[UITapGestureRecognizer alloc] initWithTarget:[Pastelog class] action:@selector(submitLogs)]; @@ -498,6 +496,8 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; [[TSAccountManager sharedInstance] ifRegistered:YES runAsync:^{ + [TSSocketManager requestSocketOpen]; + dispatch_async(dispatch_get_main_queue(), ^{ [[Environment getCurrent].contactsManager fetchSystemContactsIfAlreadyAuthorized]; });