Merge branch 'charlesmchen/sessionDatabaseRevert_'

This commit is contained in:
Matthew Chen 2018-01-10 17:56:07 -05:00
commit 49fc302294
49 changed files with 269 additions and 133 deletions

View file

@ -1,5 +1,5 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import <Availability.h>
@ -15,7 +15,7 @@
static const NSUInteger ddLogLevel = DDLogLevelInfo;
#endif
#import <SignalServiceKit/Asserts.h>
#import <SignalServiceKit/OWSAsserts.h>
#import <SignalServiceKit/Constraints.h>
#import <SignalServiceKit/OWSAnalytics.h>
#import <SignalServiceKit/OWSDispatch.h>

View file

@ -1,5 +1,5 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import <Foundation/Foundation.h>
@ -58,7 +58,6 @@
#import <SignalMessaging/UIView+OWS.h>
#import <SignalMessaging/UIViewController+OWS.h>
#import <SignalServiceKit/AppVersion.h>
#import <SignalServiceKit/Asserts.h>
#import <SignalServiceKit/Contact.h>
#import <SignalServiceKit/ContactsUpdater.h>
#import <SignalServiceKit/Cryptography.h>
@ -72,6 +71,7 @@
#import <SignalServiceKit/OWSAcknowledgeMessageDeliveryRequest.h>
#import <SignalServiceKit/OWSAnalytics.h>
#import <SignalServiceKit/OWSAnalyticsEvents.h>
#import <SignalServiceKit/OWSAsserts.h>
#import <SignalServiceKit/OWSAttachmentsProcessor.h>
#import <SignalServiceKit/OWSBackgroundTask.h>
#import <SignalServiceKit/OWSCallAnswerMessage.h>

View file

@ -1,5 +1,5 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "AboutTableViewController.h"
@ -75,11 +75,14 @@
threadCount = [[transaction ext:TSThreadDatabaseViewExtensionName] numberOfItemsInAllGroups];
messageCount = [[transaction ext:TSMessageDatabaseViewExtensionName] numberOfItemsInAllGroups];
}];
unsigned long long databaseFileSize = [TSStorageManager.sharedManager databaseFileSize];
OWSTableSection *debugSection = [OWSTableSection new];
debugSection.headerTitle = @"Debug";
[debugSection addItem:[OWSTableItem labelItemWithText:[NSString stringWithFormat:@"Threads: %zd", threadCount]]];
[debugSection addItem:[OWSTableItem labelItemWithText:[NSString stringWithFormat:@"Messages: %zd", messageCount]]];
[debugSection
addItem:[OWSTableItem labelItemWithText:[NSString stringWithFormat:@"Database size: %llu", databaseFileSize]]];
[contents addSection:debugSection];
OWSPreferences *preferences = [Environment preferences];

View file

@ -1,5 +1,5 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
import Foundation
@ -146,7 +146,7 @@ class CallViewController: OWSViewController, CallObserver, CallServiceObserver {
func observeNotifications() {
NotificationCenter.default.addObserver(self,
selector:#selector(didBecomeActive),
name:NSNotification.Name.UIApplicationDidBecomeActive,
name:NSNotification.Name.OWSApplicationDidBecomeActive,
object:nil)
NotificationCenter.default.addObserver(forName: CallAudioServiceSessionChanged, object: nil, queue: nil) { [weak self] _ in

View file

@ -1,5 +1,5 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "ConversationViewController.h"
@ -302,19 +302,19 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationWillEnterForeground:)
name:UIApplicationWillEnterForegroundNotification
name:OWSApplicationWillEnterForegroundNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationDidEnterBackground:)
name:UIApplicationDidEnterBackgroundNotification
name:OWSApplicationDidEnterBackgroundNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationWillResignActive:)
name:UIApplicationWillResignActiveNotification
name:OWSApplicationWillResignActiveNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(cancelReadTimer)
name:UIApplicationDidEnterBackgroundNotification
name:OWSApplicationDidEnterBackgroundNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(otherUsersProfileDidChange:)

View file

@ -1,5 +1,5 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
import Foundation
@ -127,7 +127,7 @@ class GifPickerViewController: OWSViewController, UISearchBarDelegate, UICollect
object: nil)
NotificationCenter.default.addObserver(self,
selector: #selector(didBecomeActive),
name: NSNotification.Name.UIApplicationDidBecomeActive,
name: NSNotification.Name.OWSApplicationDidBecomeActive,
object: nil)
}

View file

@ -1,5 +1,5 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "HomeViewController.h"
@ -124,15 +124,15 @@ typedef NS_ENUM(NSInteger, CellState) { kArchiveState, kInboxState };
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationWillEnterForeground:)
name:UIApplicationWillEnterForegroundNotification
name:OWSApplicationWillEnterForegroundNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationDidEnterBackground:)
name:UIApplicationDidEnterBackgroundNotification
name:OWSApplicationDidEnterBackgroundNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationDidBecomeActive:)
name:UIApplicationDidBecomeActiveNotification
name:OWSApplicationDidBecomeActiveNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(yapDatabaseModified:)

View file

@ -1,5 +1,5 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
import Foundation
@ -230,11 +230,11 @@ protocol CallServiceObserver: class {
NotificationCenter.default.addObserver(self,
selector: #selector(didEnterBackground),
name: NSNotification.Name.UIApplicationDidEnterBackground,
name: NSNotification.Name.OWSApplicationDidEnterBackground,
object: nil)
NotificationCenter.default.addObserver(self,
selector: #selector(didBecomeActive),
name: NSNotification.Name.UIApplicationDidBecomeActive,
name: NSNotification.Name.OWSApplicationDidBecomeActive,
object: nil)
}

View file

@ -1,5 +1,5 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
import Foundation
@ -848,7 +848,7 @@ extension URLSessionTask {
}
// Don't back up Giphy downloads.
OWSFileSystem.protectFolder(atPath:dirPath)
OWSFileSystem.protectFileOrFolder(atPath:dirPath)
} catch let error as NSError {
owsFail("\(GiphyAsset.TAG) ensureTempFolder failed: \(dirPath), \(error)")
gifFolderPath = tempDirPath

View file

@ -1,5 +1,5 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "MainAppContext.h"
@ -53,28 +53,46 @@ NS_ASSUME_NONNULL_BEGIN
- (void)applicationWillEnterForeground:(NSNotification *)notification
{
AssertIsOnMainThread();
DDLogInfo(@"%@ %s", self.logTag, __PRETTY_FUNCTION__);
[NSNotificationCenter.defaultCenter postNotificationName:OWSApplicationWillEnterForegroundNotification object:nil];
}
- (void)applicationDidEnterBackground:(NSNotification *)notification
{
AssertIsOnMainThread();
DDLogInfo(@"%@ %s", self.logTag, __PRETTY_FUNCTION__);
[DDLog flushLog];
[NSNotificationCenter.defaultCenter postNotificationName:OWSApplicationDidEnterBackgroundNotification object:nil];
}
- (void)applicationWillResignActive:(NSNotification *)notification
{
AssertIsOnMainThread();
DDLogInfo(@"%@ %s", self.logTag, __PRETTY_FUNCTION__);
[DDLog flushLog];
[NSNotificationCenter.defaultCenter postNotificationName:OWSApplicationWillResignActiveNotification object:nil];
}
- (void)applicationDidBecomeActive:(NSNotification *)notification
{
AssertIsOnMainThread();
DDLogInfo(@"%@ %s", self.logTag, __PRETTY_FUNCTION__);
[NSNotificationCenter.defaultCenter postNotificationName:OWSApplicationDidBecomeActiveNotification object:nil];
}
- (void)applicationWillTerminate:(NSNotification *)notification
{
AssertIsOnMainThread();
DDLogInfo(@"%@ %s", self.logTag, __PRETTY_FUNCTION__);
[DDLog flushLog];
}

View file

@ -492,8 +492,8 @@ open class MarqueeLabel: UILabel, CAAnimationDelegate {
NotificationCenter.default.addObserver(self, selector: #selector(MarqueeLabel.labelizeForController(_:)), name: NSNotification.Name(rawValue: MarqueeKeys.Labelize.rawValue), object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(MarqueeLabel.animateForController(_:)), name: NSNotification.Name(rawValue: MarqueeKeys.Animate.rawValue), object: nil)
// UIApplication state notifications
NotificationCenter.default.addObserver(self, selector: #selector(MarqueeLabel.restartLabel), name: NSNotification.Name.UIApplicationDidBecomeActive, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(MarqueeLabel.shutdownLabel), name: NSNotification.Name.UIApplicationDidEnterBackground, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(MarqueeLabel.restartLabel), name: NSNotification.Name.OWSApplicationDidBecomeActive, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(MarqueeLabel.shutdownLabel), name: NSNotification.Name.OWSApplicationDidEnterBackground, object: nil)
}
override open func awakeFromNib() {

View file

@ -656,7 +656,7 @@
"FINGERPRINT_SCAN_VERIFY_BUTTON" = "Mark as Verified";
/* No comment provided by engineer. */
"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON" = "Reset this session.";
"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON" = "Reset this session";
/* Accessibilty label for finishing new group */
"FINISH_GROUP_CREATION_LABEL" = "Finish creating group";

View file

@ -1,5 +1,5 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import <Availability.h>
@ -15,7 +15,7 @@
static const NSUInteger ddLogLevel = DDLogLevelInfo;
#endif
#import <SignalServiceKit/Asserts.h>
#import <SignalServiceKit/OWSAsserts.h>
#import <SignalServiceKit/Constraints.h>
#import <SignalServiceKit/OWSAnalytics.h>
#import <SignalServiceKit/OWSDispatch.h>

View file

@ -1,5 +1,5 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "ThreadViewHelper.h"
@ -57,11 +57,11 @@ NS_ASSUME_NONNULL_BEGIN
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationWillEnterForeground:)
name:UIApplicationWillEnterForegroundNotification
name:OWSApplicationWillEnterForegroundNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationDidEnterBackground:)
name:UIApplicationDidEnterBackgroundNotification
name:OWSApplicationDidEnterBackgroundNotification
object:nil];
self.shouldObserveDBModifications

View file

@ -1,5 +1,5 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSAudioAttachmentPlayer.h"
@ -48,7 +48,7 @@ NS_ASSUME_NONNULL_BEGIN
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationDidEnterBackground:)
name:UIApplicationDidEnterBackgroundNotification
name:OWSApplicationDidEnterBackgroundNotification
object:nil];
return self;

View file

@ -1,5 +1,5 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
import Foundation
@ -57,7 +57,7 @@ class ContactsFrameworkContactStoreAdaptee: ContactStoreAdaptee {
self.changeHandler = changeHandler
self.lastSortOrder = CNContactsUserDefaults.shared().sortOrder
NotificationCenter.default.addObserver(self, selector: #selector(runChangeHandler), name: .CNContactStoreDidChange, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(didBecomeActive), name: .UIApplicationDidBecomeActive, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(didBecomeActive), name: .OWSApplicationDidBecomeActive, object: nil)
}
@objc

View file

@ -1,5 +1,5 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "AppSetup.h"
@ -7,6 +7,7 @@
#import "Release.h"
#import "VersionMigrations.h"
#import <AxolotlKit/SessionCipher.h>
#import <SignalMessaging/OWSDatabaseMigration.h>
#import <SignalMessaging/OWSProfileManager.h>
#import <SignalMessaging/SignalMessaging-Swift.h>
#import <SignalServiceKit/OWSStorage.h>
@ -40,6 +41,10 @@ NS_ASSUME_NONNULL_BEGIN
profileManager:OWSProfileManager.sharedManager];
[TextSecureKitEnv setSharedEnv:sharedEnv];
// Register renamed classes.
[NSKeyedUnarchiver setClass:[OWSUserProfile class] forClassName:[OWSUserProfile collection]];
[NSKeyedUnarchiver setClass:[OWSDatabaseMigration class] forClassName:[OWSDatabaseMigration collection]];
[OWSStorage setupWithSafeBlockingMigrations:^{
[VersionMigrations runSafeBlockingMigrations];
}];

View file

@ -1,5 +1,5 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSProfileManager.h"
@ -124,7 +124,7 @@ const NSUInteger kOWSProfileManager_MaxAvatarDiameter = 640;
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationDidBecomeActive:)
name:UIApplicationDidBecomeActiveNotification
name:OWSApplicationDidBecomeActiveNotification
object:nil];
}
@ -1128,8 +1128,8 @@ const NSUInteger kOWSProfileManager_MaxAvatarDiameter = 640;
profileAvatarsDirPath = OWSProfileManager.sharedDataProfileAvatarsDirPath;
[OWSFileSystem ensureDirectoryExists:profileAvatarsDirPath];
[OWSFileSystem protectFolderAtPath:profileAvatarsDirPath];
[OWSFileSystem protectFileOrFolderAtPath:profileAvatarsDirPath];
});
return profileAvatarsDirPath;
}

View file

@ -1,5 +1,5 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSUserProfile.h"
@ -112,7 +112,7 @@ NSString *const kLocalProfileUniqueId = @"kLocalProfileUniqueId";
__block BOOL didChange = YES;
[dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
NSString *collection = [[self class] collection];
OWSUserProfile *latestInstance = [transaction objectForKey:self.uniqueId inCollection:collection];
OWSUserProfile *_Nullable latestInstance = [transaction objectForKey:self.uniqueId inCollection:collection];
if (latestInstance) {
changeBlock(latestInstance);

View file

@ -1,5 +1,5 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "DebugLogger.h"
@ -35,7 +35,7 @@
{
NSString *dirPath = [[OWSFileSystem cachesDirectoryPath] stringByAppendingPathComponent:@"Logs"];
[OWSFileSystem ensureDirectoryExists:dirPath];
[OWSFileSystem protectFolderAtPath:dirPath];
[OWSFileSystem protectFileOrFolderAtPath:dirPath];
return dirPath;
}
@ -44,7 +44,7 @@
NSString *dirPath =
[[OWSFileSystem appSharedDataDirectoryPath] stringByAppendingPathComponent:@"ShareExtensionLogs"];
[OWSFileSystem ensureDirectoryExists:dirPath];
[OWSFileSystem protectFolderAtPath:dirPath];
[OWSFileSystem protectFileOrFolderAtPath:dirPath];
return dirPath;
}

View file

@ -1,5 +1,5 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
import Foundation
@ -42,7 +42,7 @@ public class DeviceSleepManager: NSObject {
NotificationCenter.default.addObserver(self,
selector:#selector(didEnterBackground),
name:NSNotification.Name.UIApplicationDidEnterBackground,
name:NSNotification.Name.OWSApplicationDidEnterBackground,
object:nil)
}

View file

@ -1,8 +1,9 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSPreferences.h"
#import <SignalServiceKit/AppContext.h>
#import <SignalServiceKit/NSUserDefaults+OWS.h>
#import <SignalServiceKit/TSStorageHeaders.h>
#import <SignalServiceKit/YapDatabaseConnection+OWS.h>
@ -24,7 +25,7 @@ NSString *const OWSPreferencesKeyCallKitPrivacyEnabled = @"CallKitPrivacyEnabled
NSString *const OWSPreferencesKeyCallsHideIPAddress = @"CallsHideIPAddress";
NSString *const OWSPreferencesKeyHasDeclinedNoContactsView = @"hasDeclinedNoContactsView";
NSString *const OWSPreferencesKeyIOSUpgradeNagVersion = @"iOSUpgradeNagVersion";
NSString *const OWSPreferencesKey_IsReadyForAppExtensions = @"isReadyForAppExtensions2";
NSString *const OWSPreferencesKey_IsReadyForAppExtensions = @"isReadyForAppExtensions_5";
NSString *const OWSPreferencesKey_IsRegistered = @"OWSPreferencesKey_IsRegistered";
@implementation OWSPreferences
@ -78,6 +79,8 @@ NSString *const OWSPreferencesKey_IsRegistered = @"OWSPreferencesKey_IsRegistere
+ (void)setIsReadyForAppExtensions
{
OWSAssert(CurrentAppContext().isMainApp);
[NSUserDefaults.appUserDefaults setObject:@(YES) forKey:OWSPreferencesKey_IsReadyForAppExtensions];
[NSUserDefaults.appUserDefaults synchronize];
}
@ -95,6 +98,8 @@ NSString *const OWSPreferencesKey_IsRegistered = @"OWSPreferencesKey_IsRegistere
+ (void)setIsRegistered:(BOOL)value
{
OWSAssert(CurrentAppContext().isMainApp);
[NSUserDefaults.appUserDefaults setObject:@(value) forKey:OWSPreferencesKey_IsRegistered];
[NSUserDefaults.appUserDefaults synchronize];
}
@ -143,6 +148,8 @@ NSString *const OWSPreferencesKey_IsRegistered = @"OWSPreferencesKey_IsRegistere
+ (void)setIsLoggingEnabled:(BOOL)flag
{
OWSAssert(CurrentAppContext().isMainApp);
// Logging preferences are stored in UserDefaults instead of the database, so that we can (optionally) start
// logging before the database is initialized. This is important because sometimes there are problems *with* the
// database initialization, and without logging it would be hard to track down.

View file

@ -1,5 +1,5 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "TSPreKeyManager.h"
@ -91,9 +91,10 @@ static const NSTimeInterval kSignedPreKeyUpdateFailureMaxFailureDuration = 10 *
+ (void)checkPreKeysIfNecessary
{
if (CurrentAppContext().isMainApp) {
OWSAssert(CurrentAppContext().isMainAppAndActive);
if (!CurrentAppContext().isMainApp) {
return;
}
OWSAssert(CurrentAppContext().isMainAppAndActive);
// Update the prekey check timestamp.
dispatch_async(TSPreKeyManager.prekeyQueue, ^{
@ -214,6 +215,10 @@ static const NSTimeInterval kSignedPreKeyUpdateFailureMaxFailureDuration = 10 *
+ (void)checkPreKeys
{
if (!CurrentAppContext().isMainApp) {
return;
}
// Optimistically mark the prekeys as checked. This
// de-bounces prekey checks.
//

View file

@ -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;
}

View file

@ -1,8 +1,9 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSBlockingManager.h"
#import "AppContext.h"
#import "NSNotificationCenter+OWS.h"
#import "OWSBlockedPhoneNumbersMessage.h"
#import "OWSMessageSender.h"
@ -86,7 +87,7 @@ NSString *const kOWSBlockingManager_SyncedBlockedPhoneNumbersKey = @"kOWSBlockin
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationDidBecomeActive:)
name:UIApplicationDidBecomeActiveNotification
name:OWSApplicationDidBecomeActiveNotification
object:nil];
}

View file

@ -1,5 +1,5 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSDisappearingMessagesJob.h"
@ -57,11 +57,11 @@ NS_ASSUME_NONNULL_BEGIN
[[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];
return self;

View file

@ -1,5 +1,5 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSFailedAttachmentDownloadsJob.h"
@ -82,7 +82,6 @@ static NSString *const OWSFailedAttachmentDownloadsJobAttachmentStateIndex = @"i
[self enumerateAttemptingOutAttachmentsWithBlock:^(TSAttachmentPointer *attachment) {
// sanity check
if (attachment.state != TSAttachmentPointerStateFailed) {
DDLogDebug(@"%@ marking attachment as failed", self.logTag);
attachment.state = TSAttachmentPointerStateFailed;
[attachment saveWithTransaction:transaction];
count++;

View file

@ -1,11 +1,14 @@
//
// 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 "OWSSignalService.h"
#import "TSAccountManager.h"
#import "TSRecipientPrekeyRequest.h"
#import "TSSubmitMessageRequest.h"
#import "TSVerifyCodeRequest.h"
#import <AFNetworking/AFNetworking.h>
@ -56,6 +59,15 @@ typedef void (^failureBlock)(NSURLSessionDataTask *task, NSError *error);
failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failureBlock
{
DDLogInfo(@"%@ Making request: %@", self.logTag, request);
if (!CurrentAppContext().isMainApp) {
if (![request isKindOfClass:[TSRecipientPrekeyRequest class]]
&& ![request isKindOfClass:[TSSubmitMessageRequest 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];

View file

@ -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:)

View file

@ -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,31 +103,6 @@ OWSSignalServiceProtosVerifiedState OWSVerificationStateToProtoState(OWSVerifica
}];
}
+ (YapDatabaseConnection *)dbReadConnection
{
return self.dbReadWriteConnection;
}
/**
* Override to disable the object cache to better enforce transaction semantics on the store.
* Note that it's still technically possible to access this collection from a different collection,
* but that should be considered a bug.
*/
+ (YapDatabaseConnection *)dbReadWriteConnection
{
static dispatch_once_t onceToken;
static YapDatabaseConnection *sharedDBConnection;
dispatch_once(&onceToken, ^{
sharedDBConnection = [TSStorageManager sharedManager].newDatabaseConnection;
sharedDBConnection.objectCacheEnabled = NO;
#if DEBUG
sharedDBConnection.permittedTransactions = YDB_AnySyncTransaction;
#endif
});
return sharedDBConnection;
}
- (void)saveWithTransaction:(YapDatabaseReadWriteTransaction *)transaction
{
OWSAssert(transaction.connection == [OWSRecipientIdentity dbReadWriteConnection]);
@ -157,6 +132,43 @@ OWSSignalServiceProtosVerifiedState OWSVerificationStateToProtoState(OWSVerifica
return [super fetchObjectWithUniqueID:uniqueID transaction:transaction];
}
#pragma mark - Database Connections
+ (YapDatabaseConnection *)dbReadConnection
{
return self.dbReadWriteConnection;
}
/**
* Override to disable the object cache to better enforce transaction semantics on the store.
* Note that it's still technically possible to access this collection from a different collection,
* but that should be considered a bug.
*/
+ (YapDatabaseConnection *)dbReadWriteConnection
{
static dispatch_once_t onceToken;
static YapDatabaseConnection *sharedDBConnection;
dispatch_once(&onceToken, ^{
sharedDBConnection = [TSStorageManager sharedManager].newDatabaseConnection;
sharedDBConnection.objectCacheEnabled = NO;
#if DEBUG
sharedDBConnection.permittedTransactions = YDB_AnySyncTransaction;
#endif
});
return sharedDBConnection;
}
- (YapDatabaseConnection *)dbReadConnection
{
return OWSRecipientIdentity.dbReadConnection;
}
- (YapDatabaseConnection *)dbReadWriteConnection
{
return OWSRecipientIdentity.dbReadWriteConnection;
}
#pragma mark - debug
+ (void)printAllIdentities

View file

@ -1,5 +1,5 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import <YapDatabase/YapDatabaseConnection.h>
@ -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
/**

View file

@ -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

View file

@ -1,5 +1,5 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "TSStorageManager.h"
@ -127,12 +127,12 @@ NSString *const TSStorageManagerExceptionName_CouldNotCreateDatabaseDirectory
{
// The old database location was in the Document directory,
// so protect the database files individually.
[OWSFileSystem protectFolderAtPath:self.legacyDatabaseFilePath];
[OWSFileSystem protectFolderAtPath:self.legacyDatabaseFilePath_SHM];
[OWSFileSystem protectFolderAtPath:self.legacyDatabaseFilePath_WAL];
[OWSFileSystem protectFileOrFolderAtPath:self.legacyDatabaseFilePath];
[OWSFileSystem protectFileOrFolderAtPath:self.legacyDatabaseFilePath_SHM];
[OWSFileSystem protectFileOrFolderAtPath:self.legacyDatabaseFilePath_WAL];
// Protect the entire new database directory.
[OWSFileSystem protectFolderAtPath:self.sharedDataDatabaseDirPath];
[OWSFileSystem protectFileOrFolderAtPath:self.sharedDataDatabaseDirPath];
}
- (BOOL)userSetPassword {

View file

@ -1,5 +1,5 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import <Foundation/Foundation.h>
@ -11,11 +11,10 @@ static const NSUInteger ddLogLevel = DDLogLevelAll;
#else
static const NSUInteger ddLogLevel = DDLogLevelInfo;
#endif
#import "Asserts.h"
#import "Constraints.h"
#import "NSObject+OWS.h"
#import "OWSAnalytics.h"
#import "OWSAsserts.h"
#import "OWSDispatch.h"
#import "iOSVersions.h"

View file

@ -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;

View file

@ -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<AppContext> currentAppContext = nil;
id<AppContext> CurrentAppContext(void)

View file

@ -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"];

View file

@ -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<NSString *, id> *dictionary = self.dictionaryRepresentation;
for (NSString *key in dictionary) {
[self removeObjectForKey:key];

View file

@ -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];
}

View file

@ -2,6 +2,8 @@
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
NS_ASSUME_NONNULL_BEGIN
#ifndef OWSAssert
#ifdef DEBUG
@ -115,3 +117,11 @@
#define OWSSingletonAssert()
#endif
// 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

View file

@ -0,0 +1,14 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import "OWSAsserts.h"
NS_ASSUME_NONNULL_BEGIN
void AssertIsOnMainThread()
{
OWSCAssert([NSThread isMainThread]);
}
NS_ASSUME_NONNULL_END

View file

@ -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];
}
});
}

View file

@ -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

View file

@ -1,5 +1,5 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSDispatch.h"
@ -40,8 +40,4 @@ NS_ASSUME_NONNULL_BEGIN
@end
void AssertIsOnMainThread() {
OWSCAssert([NSThread isMainThread]);
}
NS_ASSUME_NONNULL_END

View file

@ -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

View file

@ -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

View file

@ -1,5 +1,5 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import <Foundation/Foundation.h>
@ -21,7 +21,7 @@
#import <SignalMessaging/VersionMigrations.h>
#import <SignalServiceKit/AppContext.h>
#import <SignalServiceKit/AppVersion.h>
#import <SignalServiceKit/Asserts.h>
#import <SignalServiceKit/NSObject+OWS.h>
#import <SignalServiceKit/OWSAsserts.h>
#import <SignalServiceKit/OWSMessageSender.h>
#import <SignalServiceKit/TSAccountManager.h>

View file

@ -1,5 +1,5 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import <Availability.h>
@ -15,7 +15,7 @@
static const NSUInteger ddLogLevel = DDLogLevelInfo;
#endif
#import <SignalServiceKit/Asserts.h>
#import <SignalServiceKit/OWSAsserts.h>
#import <SignalServiceKit/Constraints.h>
#import <SignalServiceKit/OWSAnalytics.h>
#import <SignalServiceKit/OWSDispatch.h>

View file

@ -1,9 +1,10 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "ShareAppExtensionContext.h"
#import <SignalMessaging/UIViewController+OWS.h>
#import <SignalServiceKit/OWSStorage.h>
NS_ASSUME_NONNULL_BEGIN
@ -58,24 +59,40 @@ 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__);
[NSNotificationCenter.defaultCenter postNotificationName:OWSApplicationWillEnterForegroundNotification object:nil];
}
#pragma mark -