Merge branch 'charlesmchen/corruptMessageNotifications'

pull/1/head
Matthew Chen 7 years ago
commit 0bead4c685

@ -206,7 +206,13 @@
transaction:(YapDatabaseReadWriteTransaction *)transaction transaction:(YapDatabaseReadWriteTransaction *)transaction
{ {
OWSAssert(message); OWSAssert(message);
OWSAssert(thread);
if (!thread) {
OWSProdLogAndFail(
@"%@ unexpected notification not associated with a thread: %@.", self.logTag, [message class]);
[self notifyUserForThreadlessErrorMessage:message transaction:transaction];
return;
}
NSString *messageText = [message previewTextWithTransaction:transaction]; NSString *messageText = [message previewTextWithTransaction:transaction];
@ -253,6 +259,40 @@
}]; }];
} }
- (void)notifyUserForThreadlessErrorMessage:(TSErrorMessage *)message
transaction:(YapDatabaseReadWriteTransaction *)transaction;
{
OWSAssert(message);
NSString *messageText = [message previewTextWithTransaction:transaction];
[transaction
addCompletionQueue:nil
completionBlock:^() {
BOOL shouldPlaySound = [self shouldPlaySoundForNotification];
if (([UIApplication sharedApplication].applicationState != UIApplicationStateActive) && messageText) {
UILocalNotification *notification = [[UILocalNotification alloc] init];
if (shouldPlaySound) {
OWSSound sound = [OWSSounds globalNotificationSound];
notification.soundName = [OWSSounds filenameForSound:sound];
}
NSString *alertBodyString = messageText;
notification.alertBody = alertBodyString;
[[PushManager sharedManager] presentNotification:notification checkForCancel:NO];
} else {
if (shouldPlaySound && [Environment.preferences soundInForeground]) {
OWSSound sound = [OWSSounds globalNotificationSound];
SystemSoundID soundId = [OWSSounds systemSoundIDForSound:sound quiet:YES];
// Vibrate, respect silent switch, respect "Alert" volume, not media volume.
AudioServicesPlayAlertSound(soundId);
}
}
}];
}
- (void)notifyUserForIncomingMessage:(TSIncomingMessage *)message - (void)notifyUserForIncomingMessage:(TSIncomingMessage *)message
inThread:(TSThread *)thread inThread:(TSThread *)thread
contactsManager:(id<ContactsManagerProtocol>)contactsManager contactsManager:(id<ContactsManagerProtocol>)contactsManager

@ -279,6 +279,10 @@ NSString *const Signal_Message_MarkAsRead_Identifier = @"Signal_Message_MarkAsRe
- (void)markAllInThreadAsRead:(NSDictionary *)userInfo completionHandler:(void (^)(void))completionHandler - (void)markAllInThreadAsRead:(NSDictionary *)userInfo completionHandler:(void (^)(void))completionHandler
{ {
NSString *threadId = userInfo[Signal_Thread_UserInfo_Key]; NSString *threadId = userInfo[Signal_Thread_UserInfo_Key];
if (!threadId) {
OWSProdLogAndFail(@"%@ missing thread id for notification.", self.logTag);
return;
}
TSThread *thread = [TSThread fetchObjectWithUniqueID:threadId]; TSThread *thread = [TSThread fetchObjectWithUniqueID:threadId];
[OWSPrimaryStorage.dbReadWriteConnection [OWSPrimaryStorage.dbReadWriteConnection

@ -14,4 +14,8 @@ public class NoopNotificationsManager: NSObject, NotificationsProtocol {
public func notifyUser(for error: TSErrorMessage, thread: TSThread, transaction: YapDatabaseReadWriteTransaction) { public func notifyUser(for error: TSErrorMessage, thread: TSThread, transaction: YapDatabaseReadWriteTransaction) {
Logger.warn("\(self.logTag) in \(#function), skipping notification for: \(error.description)") Logger.warn("\(self.logTag) in \(#function), skipping notification for: \(error.description)")
} }
public func notifyUser(forThreadlessErrorMessage error: TSErrorMessage, transaction: YapDatabaseReadWriteTransaction) {
Logger.warn("\(self.logTag) in \(#function), skipping notification for: \(error.description)")
}
} }

@ -56,6 +56,8 @@ typedef NS_ENUM(int32_t, TSErrorMessageType) {
+ (instancetype)corruptedMessageWithEnvelope:(OWSSignalServiceProtosEnvelope *)envelope + (instancetype)corruptedMessageWithEnvelope:(OWSSignalServiceProtosEnvelope *)envelope
withTransaction:(YapDatabaseReadWriteTransaction *)transaction; withTransaction:(YapDatabaseReadWriteTransaction *)transaction;
+ (instancetype)corruptedMessageInUnknownThread;
+ (instancetype)invalidVersionWithEnvelope:(OWSSignalServiceProtosEnvelope *)envelope + (instancetype)invalidVersionWithEnvelope:(OWSSignalServiceProtosEnvelope *)envelope
withTransaction:(YapDatabaseReadWriteTransaction *)transaction; withTransaction:(YapDatabaseReadWriteTransaction *)transaction;

@ -92,6 +92,11 @@ NSUInteger TSErrorMessageSchemaVersion = 1;
return [self initWithTimestamp:envelope.timestamp inThread:contactThread failedMessageType:errorMessageType]; return [self initWithTimestamp:envelope.timestamp inThread:contactThread failedMessageType:errorMessageType];
} }
- (instancetype)initWithFailedMessageType:(TSErrorMessageType)errorMessageType
{
return [self initWithTimestamp:[NSDate ows_millisecondTimeStamp] inThread:nil failedMessageType:errorMessageType];
}
- (OWSInteractionType)interactionType - (OWSInteractionType)interactionType
{ {
return OWSInteractionType_Error; return OWSInteractionType_Error;
@ -147,6 +152,11 @@ NSUInteger TSErrorMessageSchemaVersion = 1;
failedMessageType:TSErrorMessageInvalidMessage]; failedMessageType:TSErrorMessageInvalidMessage];
} }
+ (instancetype)corruptedMessageInUnknownThread
{
return [[self alloc] initWithFailedMessageType:TSErrorMessageInvalidMessage];
}
+ (instancetype)invalidVersionWithEnvelope:(OWSSignalServiceProtosEnvelope *)envelope + (instancetype)invalidVersionWithEnvelope:(OWSSignalServiceProtosEnvelope *)envelope
withTransaction:(YapDatabaseReadWriteTransaction *)transaction withTransaction:(YapDatabaseReadWriteTransaction *)transaction
{ {

@ -6,6 +6,7 @@
#import "AppContext.h" #import "AppContext.h"
#import "AppReadiness.h" #import "AppReadiness.h"
#import "NSArray+OWS.h" #import "NSArray+OWS.h"
#import "NotificationsProtocol.h"
#import "OWSBackgroundTask.h" #import "OWSBackgroundTask.h"
#import "OWSMessageManager.h" #import "OWSMessageManager.h"
#import "OWSPrimaryStorage+SessionStore.h" #import "OWSPrimaryStorage+SessionStore.h"
@ -14,7 +15,9 @@
#import "OWSSignalServiceProtos.pb.h" #import "OWSSignalServiceProtos.pb.h"
#import "OWSStorage.h" #import "OWSStorage.h"
#import "TSDatabaseView.h" #import "TSDatabaseView.h"
#import "TSErrorMessage.h"
#import "TSYapDatabaseObject.h" #import "TSYapDatabaseObject.h"
#import "TextSecureKitEnv.h"
#import "Threading.h" #import "Threading.h"
#import <YapDatabase/YapDatabaseAutoView.h> #import <YapDatabase/YapDatabaseAutoView.h>
#import <YapDatabase/YapDatabaseConnection.h> #import <YapDatabase/YapDatabaseConnection.h>
@ -382,6 +385,9 @@ NSString *const OWSMessageContentJobFinderExtensionGroup = @"OWSMessageContentJo
} @catch (NSException *exception) { } @catch (NSException *exception) {
OWSProdLogAndFail(@"%@ Received an invalid envelope: %@", self.logTag, exception.debugDescription); OWSProdLogAndFail(@"%@ Received an invalid envelope: %@", self.logTag, exception.debugDescription);
// TODO: Add analytics. // TODO: Add analytics.
TSErrorMessage *errorMessage = [TSErrorMessage corruptedMessageInUnknownThread];
[[TextSecureKitEnv sharedEnv].notificationsManager notifyUserForThreadlessErrorMessage:errorMessage
transaction:transaction];
} }
[processedJobs addObject:job]; [processedJobs addObject:job];

@ -170,6 +170,13 @@ NS_ASSUME_NONNULL_BEGIN
} @catch (NSException *exception) { } @catch (NSException *exception) {
OWSProdLogAndFail(@"%@ Received an invalid envelope: %@", self.logTag, exception.debugDescription); OWSProdLogAndFail(@"%@ Received an invalid envelope: %@", self.logTag, exception.debugDescription);
OWSProdFail([OWSAnalyticsEvents messageManagerErrorInvalidProtocolMessage]); OWSProdFail([OWSAnalyticsEvents messageManagerErrorInvalidProtocolMessage]);
[[OWSPrimaryStorage.sharedManager newDatabaseConnection]
readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
TSErrorMessage *errorMessage = [TSErrorMessage corruptedMessageInUnknownThread];
[[TextSecureKitEnv sharedEnv].notificationsManager notifyUserForThreadlessErrorMessage:errorMessage
transaction:transaction];
}];
} }
failureBlock(); failureBlock();

@ -6,6 +6,7 @@
#import "AppContext.h" #import "AppContext.h"
#import "AppReadiness.h" #import "AppReadiness.h"
#import "NSArray+OWS.h" #import "NSArray+OWS.h"
#import "NotificationsProtocol.h"
#import "OWSBackgroundTask.h" #import "OWSBackgroundTask.h"
#import "OWSBatchMessageProcessor.h" #import "OWSBatchMessageProcessor.h"
#import "OWSMessageDecrypter.h" #import "OWSMessageDecrypter.h"
@ -14,7 +15,9 @@
#import "OWSSignalServiceProtos.pb.h" #import "OWSSignalServiceProtos.pb.h"
#import "OWSStorage.h" #import "OWSStorage.h"
#import "TSDatabaseView.h" #import "TSDatabaseView.h"
#import "TSErrorMessage.h"
#import "TSYapDatabaseObject.h" #import "TSYapDatabaseObject.h"
#import "TextSecureKitEnv.h"
#import "Threading.h" #import "Threading.h"
#import <YapDatabase/YapDatabaseAutoView.h> #import <YapDatabase/YapDatabaseAutoView.h>
#import <YapDatabase/YapDatabaseConnection.h> #import <YapDatabase/YapDatabaseConnection.h>
@ -322,6 +325,14 @@ NSString *const OWSMessageDecryptJobFinderExtensionGroup = @"OWSMessageProcessin
} @catch (NSException *exception) { } @catch (NSException *exception) {
OWSProdLogAndFail(@"%@ Could not parse proto: %@", self.logTag, exception.debugDescription); OWSProdLogAndFail(@"%@ Could not parse proto: %@", self.logTag, exception.debugDescription);
// TODO: Add analytics. // TODO: Add analytics.
[[OWSPrimaryStorage.sharedManager newDatabaseConnection]
readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
TSErrorMessage *errorMessage = [TSErrorMessage corruptedMessageInUnknownThread];
[[TextSecureKitEnv sharedEnv].notificationsManager notifyUserForThreadlessErrorMessage:errorMessage
transaction:transaction];
}];
dispatch_async(self.serialQueue, ^{ dispatch_async(self.serialQueue, ^{
completion(NO); completion(NO);
}); });

@ -8,15 +8,19 @@
#import "Cryptography.h" #import "Cryptography.h"
#import "NSNotificationCenter+OWS.h" #import "NSNotificationCenter+OWS.h"
#import "NSTimer+OWS.h" #import "NSTimer+OWS.h"
#import "NotificationsProtocol.h"
#import "OWSBackgroundTask.h" #import "OWSBackgroundTask.h"
#import "OWSMessageManager.h" #import "OWSMessageManager.h"
#import "OWSMessageReceiver.h" #import "OWSMessageReceiver.h"
#import "OWSPrimaryStorage.h"
#import "OWSSignalService.h" #import "OWSSignalService.h"
#import "OWSSignalServiceProtos.pb.h" #import "OWSSignalServiceProtos.pb.h"
#import "OWSWebsocketSecurityPolicy.h" #import "OWSWebsocketSecurityPolicy.h"
#import "SubProtocol.pb.h" #import "SubProtocol.pb.h"
#import "TSAccountManager.h" #import "TSAccountManager.h"
#import "TSConstants.h" #import "TSConstants.h"
#import "TSErrorMessage.h"
#import "TextSecureKitEnv.h"
#import "Threading.h" #import "Threading.h"
static const CGFloat kSocketHeartbeatPeriodSeconds = 30.f; static const CGFloat kSocketHeartbeatPeriodSeconds = 30.f;
@ -403,6 +407,13 @@ NSString *const kNSNotification_SocketManagerStateDidChange = @"kNSNotification_
} @catch (NSException *exception) { } @catch (NSException *exception) {
OWSProdLogAndFail(@"%@ Received an invalid envelope: %@", self.logTag, exception.debugDescription); OWSProdLogAndFail(@"%@ Received an invalid envelope: %@", self.logTag, exception.debugDescription);
// TODO: Add analytics. // TODO: Add analytics.
[[OWSPrimaryStorage.sharedManager newDatabaseConnection] readWriteWithBlock:^(
YapDatabaseReadWriteTransaction *transaction) {
TSErrorMessage *errorMessage = [TSErrorMessage corruptedMessageInUnknownThread];
[[TextSecureKitEnv sharedEnv].notificationsManager notifyUserForThreadlessErrorMessage:errorMessage
transaction:transaction];
}];
} }
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{

@ -22,6 +22,9 @@ NS_ASSUME_NONNULL_BEGIN
thread:(TSThread *)thread thread:(TSThread *)thread
transaction:(YapDatabaseReadWriteTransaction *)transaction; transaction:(YapDatabaseReadWriteTransaction *)transaction;
- (void)notifyUserForThreadlessErrorMessage:(TSErrorMessage *)error
transaction:(YapDatabaseReadWriteTransaction *)transaction;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

Loading…
Cancel
Save