From d00c8921587a94631c0e36ca260dc49f324bdc9a Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Fri, 31 Mar 2017 18:36:30 -0400 Subject: [PATCH 1/4] Apply assert to ensure singletons are only created once. // FREEBIE --- Podfile | 4 ++-- Podfile.lock | 9 +++------ Signal/src/network/PushManager.h | 2 ++ Signal/src/network/PushManager.m | 2 ++ 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Podfile b/Podfile index 52b196b6c..8d8b3f33d 100644 --- a/Podfile +++ b/Podfile @@ -5,8 +5,8 @@ target 'Signal' do pod 'SocketRocket', :git => 'https://github.com/facebook/SocketRocket.git' pod 'AxolotlKit', git: 'https://github.com/WhisperSystems/SignalProtocolKit.git' #pod 'AxolotlKit', path: '../SignalProtocolKit' - pod 'SignalServiceKit', git: 'https://github.com/WhisperSystems/SignalServiceKit.git' - #pod 'SignalServiceKit', path: '../SignalServiceKit' + #pod 'SignalServiceKit', git: 'https://github.com/WhisperSystems/SignalServiceKit.git' + pod 'SignalServiceKit', path: '../SignalServiceKit' pod 'OpenSSL' pod 'SCWaveformView', '~> 1.0' pod 'JSQMessagesViewController' diff --git a/Podfile.lock b/Podfile.lock index 6fa28f32d..4b8703c08 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -116,14 +116,14 @@ DEPENDENCIES: - OpenSSL - PureLayout - SCWaveformView (~> 1.0) - - SignalServiceKit (from `https://github.com/WhisperSystems/SignalServiceKit.git`) + - SignalServiceKit (from `../SignalServiceKit`) - SocketRocket (from `https://github.com/facebook/SocketRocket.git`) EXTERNAL SOURCES: AxolotlKit: :git: https://github.com/WhisperSystems/SignalProtocolKit.git SignalServiceKit: - :git: https://github.com/WhisperSystems/SignalServiceKit.git + :path: ../SignalServiceKit SocketRocket: :git: https://github.com/facebook/SocketRocket.git @@ -131,9 +131,6 @@ CHECKOUT OPTIONS: AxolotlKit: :commit: cbf2f47d59dd54d6d720fe787f835bd767443bb6 :git: https://github.com/WhisperSystems/SignalProtocolKit.git - SignalServiceKit: - :commit: 8b5f82eb6d8393074987697cea6986b55fec800e - :git: https://github.com/WhisperSystems/SignalServiceKit.git SocketRocket: :commit: 877ac7438be3ad0b45ef5ca3969574e4b97112bf :git: https://github.com/facebook/SocketRocket.git @@ -161,6 +158,6 @@ SPEC CHECKSUMS: UnionFind: c33be5adb12983981d6e827ea94fc7f9e370f52d YapDatabase: b1e43555a34a5298e23a045be96817a5ef0da58f -PODFILE CHECKSUM: a060377074cb361576f346a58d1503b3bd708440 +PODFILE CHECKSUM: cb02bca5a68f5b03df77200dae4ce1235a007807 COCOAPODS: 1.2.0 diff --git a/Signal/src/network/PushManager.h b/Signal/src/network/PushManager.h index a2849c877..97039713a 100644 --- a/Signal/src/network/PushManager.h +++ b/Signal/src/network/PushManager.h @@ -39,6 +39,8 @@ typedef void (^pushTokensSuccessBlock)(NSString *pushToken, NSString *voipToken) @interface PushManager : NSObject +- (instancetype)init NS_UNAVAILABLE; + + (PushManager *)sharedManager; /** diff --git a/Signal/src/network/PushManager.m b/Signal/src/network/PushManager.m index 5fff2fdfb..420fab28e 100644 --- a/Signal/src/network/PushManager.m +++ b/Signal/src/network/PushManager.m @@ -77,6 +77,8 @@ _callBackgroundTask = UIBackgroundTaskInvalid; _currentNotifications = [NSMutableArray array]; + OWSSingletonAssert(); + return self; } From 8374ca149eabe5d87cf3dd5692c6314dfb2e103f Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Fri, 31 Mar 2017 18:45:51 -0400 Subject: [PATCH 2/4] Apply assert to ensure singletons are only created once. // FREEBIE --- Signal/src/contact/OWSContactsManager.m | 2 ++ Signal/src/environment/Environment.m | 2 ++ Signal/src/environment/NotificationsManager.m | 2 ++ Signal/src/environment/PropertyListPreferences.m | 12 ++++++++++++ Signal/src/util/Pastelog.m | 2 ++ 5 files changed, 20 insertions(+) diff --git a/Signal/src/contact/OWSContactsManager.m b/Signal/src/contact/OWSContactsManager.m index 8001c7f84..ce7c32f86 100644 --- a/Signal/src/contact/OWSContactsManager.m +++ b/Signal/src/contact/OWSContactsManager.m @@ -41,6 +41,8 @@ NSString *const OWSContactsManagerSignalRecipientsDidChangeNotification = _latestContactsById = @{}; _avatarCache = [NSCache new]; + OWSSingletonAssert(); + return self; } diff --git a/Signal/src/environment/Environment.m b/Signal/src/environment/Environment.m index 76da3d1b1..a2f3d474c 100644 --- a/Signal/src/environment/Environment.m +++ b/Signal/src/environment/Environment.m @@ -52,6 +52,8 @@ static Environment *environment = nil; _networkManager = networkManager; _messageSender = messageSender; + OWSSingletonAssert(); + return self; } diff --git a/Signal/src/environment/NotificationsManager.m b/Signal/src/environment/NotificationsManager.m index 038d6a051..bf8edcb27 100644 --- a/Signal/src/environment/NotificationsManager.m +++ b/Signal/src/environment/NotificationsManager.m @@ -37,6 +37,8 @@ NSURL *newMessageURL = [[NSBundle mainBundle] URLForResource:@"NewMessage" withExtension:@"aifc"]; AudioServicesCreateSystemSoundID((__bridge CFURLRef)newMessageURL, &_newMessageSound); + OWSSingletonAssert(); + return self; } diff --git a/Signal/src/environment/PropertyListPreferences.m b/Signal/src/environment/PropertyListPreferences.m index e2f628bc7..7f65b46ec 100644 --- a/Signal/src/environment/PropertyListPreferences.m +++ b/Signal/src/environment/PropertyListPreferences.m @@ -29,6 +29,18 @@ NSString *const PropertyListPreferencesKeyHasDeclinedNoContactsView = @"hasDecli @implementation PropertyListPreferences +- (instancetype)init +{ + self = [super init]; + if (!self) { + return self; + } + + OWSSingletonAssert(); + + return self; +} + #pragma mark - Helpers - (void)clear { diff --git a/Signal/src/util/Pastelog.m b/Signal/src/util/Pastelog.m index f8a990256..c5bbb53cf 100644 --- a/Signal/src/util/Pastelog.m +++ b/Signal/src/util/Pastelog.m @@ -103,6 +103,8 @@ -(instancetype)init { if (self = [super init]) { self.responseData = [NSMutableData data]; + + OWSSingletonAssert(); } return self; } From 5ff454fd902002abbb03bcd18ded14ce97459fbc Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Fri, 31 Mar 2017 23:25:30 -0400 Subject: [PATCH 3/4] Fix double creation of NotificationsManager singleton. // FREEBIE --- Podfile.lock | 2 +- .../Notifications/CallNotificationsAdapter.swift | 2 +- Signal/src/environment/NotificationsManager.m | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Podfile.lock b/Podfile.lock index 4b8703c08..4eac84301 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -123,7 +123,7 @@ EXTERNAL SOURCES: AxolotlKit: :git: https://github.com/WhisperSystems/SignalProtocolKit.git SignalServiceKit: - :path: ../SignalServiceKit + :path: "../SignalServiceKit" SocketRocket: :git: https://github.com/facebook/SocketRocket.git diff --git a/Signal/src/UserInterface/Notifications/CallNotificationsAdapter.swift b/Signal/src/UserInterface/Notifications/CallNotificationsAdapter.swift index 3cfd2ca12..d2363ab3c 100644 --- a/Signal/src/UserInterface/Notifications/CallNotificationsAdapter.swift +++ b/Signal/src/UserInterface/Notifications/CallNotificationsAdapter.swift @@ -21,7 +21,7 @@ class CallNotificationsAdapter: NSObject { // if #available(iOS 10.0, *) { // adaptee = UserNotificationsAdaptee() // } else { - adaptee = NotificationsManager() + adaptee = Environment.getCurrent().notificationsManager // } } diff --git a/Signal/src/environment/NotificationsManager.m b/Signal/src/environment/NotificationsManager.m index bf8edcb27..1a2d8261c 100644 --- a/Signal/src/environment/NotificationsManager.m +++ b/Signal/src/environment/NotificationsManager.m @@ -17,12 +17,14 @@ @interface NotificationsManager () -@property SystemSoundID newMessageSound; +@property (nonatomic) SystemSoundID newMessageSound; @property (nonatomic, readonly) NSMutableDictionary *currentNotifications; @property (nonatomic, readonly) NotificationType notificationPreviewType; @end +#pragma mark - + @implementation NotificationsManager - (instancetype)init From f604cfb5535628fd9c0d94bdf950da812c36d2ec Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Mon, 3 Apr 2017 14:53:23 -0400 Subject: [PATCH 4/4] Apply assert to ensure singletons are only created once & filter incoming messages using the blacklist. // FREEBIE --- Podfile | 4 ++-- Podfile.lock | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Podfile b/Podfile index 8d8b3f33d..52b196b6c 100644 --- a/Podfile +++ b/Podfile @@ -5,8 +5,8 @@ target 'Signal' do pod 'SocketRocket', :git => 'https://github.com/facebook/SocketRocket.git' pod 'AxolotlKit', git: 'https://github.com/WhisperSystems/SignalProtocolKit.git' #pod 'AxolotlKit', path: '../SignalProtocolKit' - #pod 'SignalServiceKit', git: 'https://github.com/WhisperSystems/SignalServiceKit.git' - pod 'SignalServiceKit', path: '../SignalServiceKit' + pod 'SignalServiceKit', git: 'https://github.com/WhisperSystems/SignalServiceKit.git' + #pod 'SignalServiceKit', path: '../SignalServiceKit' pod 'OpenSSL' pod 'SCWaveformView', '~> 1.0' pod 'JSQMessagesViewController' diff --git a/Podfile.lock b/Podfile.lock index 4eac84301..9d586765a 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -116,14 +116,14 @@ DEPENDENCIES: - OpenSSL - PureLayout - SCWaveformView (~> 1.0) - - SignalServiceKit (from `../SignalServiceKit`) + - SignalServiceKit (from `https://github.com/WhisperSystems/SignalServiceKit.git`) - SocketRocket (from `https://github.com/facebook/SocketRocket.git`) EXTERNAL SOURCES: AxolotlKit: :git: https://github.com/WhisperSystems/SignalProtocolKit.git SignalServiceKit: - :path: "../SignalServiceKit" + :git: https://github.com/WhisperSystems/SignalServiceKit.git SocketRocket: :git: https://github.com/facebook/SocketRocket.git @@ -131,6 +131,9 @@ CHECKOUT OPTIONS: AxolotlKit: :commit: cbf2f47d59dd54d6d720fe787f835bd767443bb6 :git: https://github.com/WhisperSystems/SignalProtocolKit.git + SignalServiceKit: + :commit: e4ec7298441e82c8c5cd0678ea165dc3e12b2986 + :git: https://github.com/WhisperSystems/SignalServiceKit.git SocketRocket: :commit: 877ac7438be3ad0b45ef5ca3969574e4b97112bf :git: https://github.com/facebook/SocketRocket.git @@ -158,6 +161,6 @@ SPEC CHECKSUMS: UnionFind: c33be5adb12983981d6e827ea94fc7f9e370f52d YapDatabase: b1e43555a34a5298e23a045be96817a5ef0da58f -PODFILE CHECKSUM: cb02bca5a68f5b03df77200dae4ce1235a007807 +PODFILE CHECKSUM: a060377074cb361576f346a58d1503b3bd708440 COCOAPODS: 1.2.0