Addressing issues with background decryption.

- Simplifying background timeout strategy for reliabilty.
- Adding Notifications settings.
- Dropping support for VOIP Push < 8.2 because buggy.
This commit is contained in:
Frederic Jacobs 2015-04-28 14:41:50 +02:00
parent 2d41a3e25e
commit 1550c61216
16 changed files with 197 additions and 86 deletions

View File

@ -2,18 +2,14 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSContactsUsageDescription</key>
<string>Signal uses your AddressBook as contacts list. We do not store your contacts on the server.</string>
<key>NSMicrophoneUsageDescription</key>
<string>Signal needs access to your microphone to make and receive phone calls.</string>
<key>CFBundleGetInfoString</key>
<string></string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleGetInfoString</key>
<string></string>
<key>CFBundleIcons</key>
<dict/>
<key>CFBundleIcons~ipad</key>
@ -44,7 +40,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>2.0.21</string>
<string>2.0.22</string>
<key>LOGS_EMAIL</key>
<string>support@whispersystems.org</string>
<key>LOGS_URL</key>
@ -53,6 +49,10 @@
<string>public.app-category.social-networking</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSContactsUsageDescription</key>
<string>Signal uses your AddressBook as contacts list. We do not store your contacts on the server.</string>
<key>NSMicrophoneUsageDescription</key>
<string>Signal needs access to your microphone to make and receive phone calls.</string>
<key>UIAppFonts</key>
<array>
<string>HelveticaNeueLTStd-Bd.otf</string>

View File

@ -60,10 +60,10 @@
// the phone directory being looked up during tests.
loggingIsEnabled = TRUE;
[DebugLogger.sharedInstance enableTTYLogging];
#elif RELEASE
loggingIsEnabled = Environment.preferences.loggingIsEnabled;
#endif
[self verifyBackgroundBeforeKeysAvailableLaunch];
if (loggingIsEnabled) {
[DebugLogger.sharedInstance enableFileLogging];
@ -260,6 +260,22 @@
[[PushManager sharedManager] application:application handleActionWithIdentifier:identifier forLocalNotification:notification completionHandler:completionHandler];
}
/**
* Signal requires an iPhone to be unlocked after reboot to be able to access keying material.
*/
- (void)verifyBackgroundBeforeKeysAvailableLaunch {
if ([self applicationIsActive]) {
return;
}
if (![[TSStorageManager sharedManager] databasePasswordAccessible]) {
UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.alertBody = NSLocalizedString(@"PHONE_NEEDS_UNLOCK", nil);
[[UIApplication sharedApplication] presentLocalNotificationNow:notification];
exit(0);
}
}
- (BOOL)applicationIsActive {
UIApplication *app = [UIApplication sharedApplication];

View File

@ -242,7 +242,7 @@
<constraint firstAttribute="width" constant="250" id="siA-1a-pO1"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
<variation key="default">
<mask key="constraints">
@ -1129,7 +1129,7 @@ A0 09 9A FF A8 8A 09 99</string>
<constraint firstAttribute="width" constant="126" id="IoY-EK-Qhk"/>
</constraints>
<fontDescription key="fontDescription" name="HelveticaNeue-Thin" family="Helvetica Neue" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
<variation key="default">
<mask key="constraints">
@ -2138,7 +2138,7 @@ A0 09 9A FF A8 8A 09 99</string>
<constraint firstAttribute="width" constant="244" id="Y66-3d-yJI"/>
</constraints>
<fontDescription key="fontDescription" name="HelveticaNeue-Medium" family="Helvetica Neue" pointSize="19"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
<variation key="default">
<mask key="constraints">
@ -3777,7 +3777,7 @@ A0 09 9A FF A8 8A 09 99</string>
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="static" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" id="FhQ-dM-1mj">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" cocoaTouchSystemColor="groupTableViewBackgroundColor"/>
<color key="backgroundColor" red="0.93725490196078431" green="0.93725490196078431" blue="0.95686274509803926" alpha="1" colorSpace="calibratedRGB"/>
<view key="tableFooterView" contentMode="scaleToFill" id="Ezq-Cw-na2">
<rect key="frame" x="0.0" y="600" width="600" height="568"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
@ -3818,7 +3818,7 @@ A0 09 9A FF A8 8A 09 99</string>
<constraint firstAttribute="height" constant="29" id="Qtv-Rd-0jb"/>
</constraints>
<fontDescription key="fontDescription" name="HelveticaNeue-Medium" family="Helvetica Neue" pointSize="22"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
<variation key="default">
<mask key="constraints">
@ -3983,7 +3983,7 @@ A0 09 9A FF A8 8A 09 99</string>
</constraint>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
<variation key="default">
<mask key="constraints">
@ -4110,7 +4110,7 @@ A0 09 9A FF A8 8A 09 99</string>
</constraint>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
<variation key="default">
<mask key="constraints">
@ -4173,7 +4173,7 @@ A0 09 9A FF A8 8A 09 99</string>
</constraint>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
<variation key="default">
<mask key="constraints">
@ -4204,10 +4204,10 @@ A0 09 9A FF A8 8A 09 99</string>
<exclude reference="BaC-fn-VoA"/>
</mask>
<mask key="constraints">
<exclude reference="gMd-UT-AWs"/>
<exclude reference="U1d-NR-s31"/>
<exclude reference="zfO-kb-UBa"/>
<exclude reference="Tae-ZO-Fxf"/>
<exclude reference="U1d-NR-s31"/>
<exclude reference="gMd-UT-AWs"/>
<exclude reference="zfO-kb-UBa"/>
</mask>
</variation>
<variation key="heightClass=regular-widthClass=compact">
@ -4215,10 +4215,10 @@ A0 09 9A FF A8 8A 09 99</string>
<include reference="BaC-fn-VoA"/>
</mask>
<mask key="constraints">
<include reference="gMd-UT-AWs"/>
<exclude reference="U1d-NR-s31"/>
<exclude reference="zfO-kb-UBa"/>
<include reference="Tae-ZO-Fxf"/>
<exclude reference="U1d-NR-s31"/>
<include reference="gMd-UT-AWs"/>
<exclude reference="zfO-kb-UBa"/>
</mask>
</variation>
</tableViewCellContentView>
@ -4236,7 +4236,7 @@ A0 09 9A FF A8 8A 09 99</string>
</constraint>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
<variation key="default">
<mask key="constraints">
@ -4299,7 +4299,7 @@ A0 09 9A FF A8 8A 09 99</string>
</constraint>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
<variation key="default">
<mask key="constraints">
@ -4518,7 +4518,7 @@ A0 09 9A FF A8 8A 09 99</string>
</constraint>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
<variation key="default">
<mask key="constraints">
@ -4798,9 +4798,6 @@ A0 09 9A FF A8 8A 09 99</string>
<fontDescription key="fontDescription" type="boldSystem" pointSize="17"/>
<color key="textColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
<nil key="highlightedColor"/>
<variation key="heightClass=regular-widthClass=compact" misplaced="YES">
<rect key="frame" x="10" y="274" width="130" height="21"/>
</variation>
</label>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
@ -4848,7 +4845,7 @@ A0 09 9A FF A8 8A 09 99</string>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Title" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="a4j-OQ-ala">
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" name="HelveticaNeue-Medium" family="Helvetica Neue" pointSize="20"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
<variation key="heightClass=regular-widthClass=compact">
<fontDescription key="fontDescription" name="HelveticaNeue-Medium" family="Helvetica Neue" pointSize="18"/>

View File

@ -44,6 +44,9 @@ typedef NS_ENUM(NSUInteger, TSImageQuality) {
- (BOOL)soundInForeground;
- (void)setSoundInForeground:(BOOL)enabled;
- (BOOL)hasRegisteredVOIPPush;
-(void)setHasRegisteredVOIPPush:(BOOL)enabled;
- (TSImageQuality)imageUploadQuality;
- (void)setImageUploadQuality:(TSImageQuality)quality;

View File

@ -28,6 +28,7 @@
#define HAS_ARCHIVED_A_MESSAGE_KEY @"User archived a message"
#define kSignalVersionKey @"SignalUpdateVersionKey"
#define PLAY_SOUND_IN_FOREGROUND_KEY @"NotificationSoundInForeground"
#define HAS_REGISTERED_VOIP_PUSH @"VOIPPushEnabled"
#define BloomFilterCacheName @"bloomfilter"
@ -142,6 +143,16 @@
}
- (BOOL)hasRegisteredVOIPPush {
NSNumber *preference = [self tryGetValueForKey:HAS_REGISTERED_VOIP_PUSH];
if (preference) {
return [preference boolValue];
} else{
return YES;
}
}
-(TSImageQuality)imageUploadQuality {
// always return average image quality
return TSImageQualityMedium;
@ -159,6 +170,10 @@
[self setValueForKey:FRESH_INSTALL_TUTORIALS_ENABLED_KEY toValue:@(enabled)];
}
-(void)setHasRegisteredVOIPPush:(BOOL)enabled {
[self setValueForKey:HAS_REGISTERED_VOIP_PUSH toValue:@(enabled)];
}
-(void) setContactImagesEnabled:(BOOL)enabled {
[self setValueForKey:CONTACT_IMAGES_ENABLED_KEY toValue:@(enabled)];
}

View File

@ -40,7 +40,8 @@
NSString *currentVersion = [Environment.preferences setAndGetCurrentVersion];
BOOL isCurrentlyMigrating = [VersionMigrations isMigratingTo2Dot0];
BOOL needsToRegisterPush = [VersionMigrations needsRegisterPush];
BOOL VOIPRegistration = [[PushManager sharedManager] supportsVOIPPush]
&& ![Environment.preferences hasRegisteredVOIPPush];
if (!previousVersion) {
DDLogError(@"No previous version found. Possibly first launch since install.");
return;
@ -58,6 +59,20 @@
[self clearVideoCache];
[self blockingPushRegistration];
}
if (VOIPRegistration) {
[PushManager.sharedManager registrationAndRedPhoneTokenRequestWithSuccess:^(NSData *pushToken, NSData *voipToken, NSString *signupToken) {
[TSAccountManager registerWithRedPhoneToken:signupToken
pushToken:pushToken
voipToken:voipToken
success:^{[Environment.preferences setHasRegisteredVOIPPush:YES];}
failure:^(NSError *error) {
DDLogError(@"Couldn't register with TextSecure server: %@", error.debugDescription);
}];
} failure:^(NSError *error) {
DDLogError(@"Couldn't register with RedPhone server.");
}];
}
}
+ (BOOL)isMigrating{
@ -243,6 +258,7 @@
[[PushManager sharedManager] requestPushTokenWithSuccess:^(NSData *pushToken, NSData *voipToken) {
[TSAccountManager registerForPushNotifications:pushToken voipToken:voipToken success:^{
[[NSUserDefaults standardUserDefaults] removeObjectForKey:NEEDS_TO_REGISTER_PUSH_KEY];
[waitingController dismissViewControllerAnimated:YES completion:nil];
} failure:failure];
} failure:failure];
}

View File

@ -85,6 +85,14 @@
#endif
#ifndef NSFoundationVersionNumber_iOS_8_2_0
#define NSFoundationVersionNumber_iOS_8_2_0 1142 //extracted with NSLog(@"%f", NSFoundationVersionNumber)
#endif
#ifdef NSFoundationVersionNumber_iOS_8_2_0
#define _iOS_8_2_0 NSFoundationVersionNumber_iOS_8_2_0
#endif
/**
Add a Singelton implementation to the .m File
*/

View File

@ -65,6 +65,7 @@ typedef void (^registrationTokensSuccessBlock)(NSData *pushToken, NSData *voipTo
@property TOCFutureSource *pushKitNotificationFutureSource;
-(TOCFuture*)registerPushKitNotificationFuture;
- (BOOL)supportsVOIPPush;
#pragma mark Push Notifications Delegate Methods

View File

@ -168,7 +168,7 @@
#pragma mark PushKit
-(void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(NSString *)type
- (void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(NSString *)type
{
[[PushManager sharedManager].pushKitNotificationFutureSource trySetResult:credentials.token];
}
@ -178,12 +178,27 @@
[self application:[UIApplication sharedApplication] didReceiveRemoteNotification:payload.dictionaryPayload];
}
-(TOCFuture*)registerPushKitNotificationFuture{
self.pushKitNotificationFutureSource = [TOCFutureSource new];
PKPushRegistry* voipRegistry = [[PKPushRegistry alloc] initWithQueue:dispatch_get_main_queue()];
voipRegistry.delegate = self;
voipRegistry.desiredPushTypes = [NSSet setWithObject:PKPushTypeVoIP];
return self.pushKitNotificationFutureSource.future;
- (TOCFuture*)registerPushKitNotificationFuture{
if ([self supportsVOIPPush]) {
self.pushKitNotificationFutureSource = [TOCFutureSource new];
PKPushRegistry* voipRegistry = [[PKPushRegistry alloc] initWithQueue:dispatch_get_main_queue()];
voipRegistry.delegate = self;
voipRegistry.desiredPushTypes = [NSSet setWithObject:PKPushTypeVoIP];
return self.pushKitNotificationFutureSource.future;
} else {
TOCFutureSource *futureSource = [TOCFutureSource new];
[futureSource trySetResult:nil];
[Environment.preferences setHasRegisteredVOIPPush:FALSE];
return futureSource.future;
}
}
- (BOOL)supportsVOIPPush {
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(_iOS_8_2_0)) {
return YES;
} else {
return NO;
}
}
#pragma mark Register device for Push Notification locally
@ -287,24 +302,17 @@
}
- (UIUserNotificationCategory*)userNotificationsMessageCategory{
UIMutableUserNotificationAction *action_accept = [UIMutableUserNotificationAction new];
action_accept.identifier = Signal_Message_View_Identifier;
action_accept.title = NSLocalizedString(@"View", @"");
action_accept.activationMode = UIUserNotificationActivationModeForeground;
action_accept.destructive = NO;
action_accept.authenticationRequired = YES;
UIMutableUserNotificationAction *action_decline = [UIMutableUserNotificationAction new];
action_decline.identifier = Signal_Message_MarkAsRead_Identifier;
action_decline.title = NSLocalizedString(@"Mark as read", @"");
action_decline.activationMode = UIUserNotificationActivationModeBackground;
action_decline.destructive = NO;
action_decline.authenticationRequired = NO;
UIMutableUserNotificationAction *action_view = [UIMutableUserNotificationAction new];
action_view.identifier = Signal_Message_View_Identifier;
action_view.title = NSLocalizedString(@"View", @"");
action_view.activationMode = UIUserNotificationActivationModeForeground;
action_view.destructive = NO;
action_view.authenticationRequired = YES;
UIMutableUserNotificationCategory *messageCategory = [UIMutableUserNotificationCategory new];
messageCategory.identifier = Signal_Message_Category;
[messageCategory setActions:@[action_accept, action_decline] forContext:UIUserNotificationActionContextMinimal];
[messageCategory setActions:@[action_accept, action_decline] forContext:UIUserNotificationActionContextDefault];
[messageCategory setActions:@[action_view] forContext:UIUserNotificationActionContextMinimal];
[messageCategory setActions:@[action_view] forContext:UIUserNotificationActionContextDefault];
return messageCategory;
}

View File

@ -410,7 +410,9 @@
}
- (void)notifyUserForIncomingMessage:(TSIncomingMessage*)message from:(NSString*)name inThread:(TSThread*)thread {
if ([UIApplication sharedApplication].applicationState != UIApplicationStateActive) {
NSString *messageDescription = message.description;
if ([UIApplication sharedApplication].applicationState != UIApplicationStateActive && messageDescription) {
UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.category = Signal_Message_Category;
notification.userInfo = @{Signal_Thread_UserInfo_Key:thread.uniqueId};
@ -423,9 +425,9 @@
sender = message.authorId;
}
notification.alertBody = [NSString stringWithFormat:@"New message from %@ in group \"%@\": %@", sender, name, message.description];
notification.alertBody = [NSString stringWithFormat:@"New message from %@ in group \"%@\": %@", sender, name, messageDescription];
} else {
notification.alertBody = [NSString stringWithFormat:@"%@: %@", name, message.description];
notification.alertBody = [NSString stringWithFormat:@"%@: %@", name, messageDescription];
}
break;
case NotificationNameNoPreview:{

View File

@ -18,7 +18,11 @@
self.HTTPMethod = @"PUT";
self.parameters = [NSMutableDictionary dictionaryWithObjects:@[identifier, voipId] forKeys:@[@"apnRegistrationId", @"voipRegistrationId"]];
self.parameters = [@{@"apnRegistrationId":identifier} mutableCopy];
if (voipId) {
[self.parameters setObject:voipId forKeyedSubscript:@"voipRegistrationId"];
}
return self;
}

View File

@ -37,6 +37,8 @@ NSString * const SocketConnectingNotification = @"SocketConnectingNotification";
@property (nonatomic, retain) NSTimer *backgroundConnectTimer;
@property (nonatomic) UIBackgroundTaskIdentifier fetchingTaskIdentifier;
@property BOOL didFetchInBackground;
@end
@implementation TSSocketManager
@ -131,6 +133,7 @@ NSString * const SocketConnectingNotification = @"SocketConnectingNotification";
- (void) webSocket:(SRWebSocket *)webSocket didReceiveMessage:(NSData*)data {
WebSocketMessage *wsMessage = [WebSocketMessage parseFromData:data];
self.didFetchInBackground = YES;
if (wsMessage.type == WebSocketMessageTypeRequest) {
[self processWebSocketRequestMessage:wsMessage.request];
@ -232,42 +235,30 @@ NSString * const SocketConnectingNotification = @"SocketConnectingNotification";
TSSocketManager *sharedInstance = [TSSocketManager sharedManager];
if (sharedInstance.fetchingTaskIdentifier == 0) {
sharedInstance.didFetchInBackground = NO;
sharedInstance.fetchingTaskIdentifier = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
if (!sharedInstance.didFetchInBackground) {
[sharedInstance backgroundConnectTimedOut];
}
sharedInstance.fetchingTaskIdentifier = 0;
[TSSocketManager resignActivity];
}];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSTimer * timer = [NSTimer timerWithTimeInterval:kBackgroundConnectTimer
target:sharedInstance
selector:@selector(closeBackgroundTask)
userInfo:nil
repeats:NO];
[[NSRunLoop mainRunLoop] addTimer:timer
forMode:NSDefaultRunLoopMode];
});
[self becomeActive];
}
}
- (void)closeBackgroundTask {
UIBackgroundTaskIdentifier identifier = self.fetchingTaskIdentifier;
self.fetchingTaskIdentifier = 0;
if ([_websocket readyState] != SR_OPEN) {
[self backgroundConnectTimedOut];
}
self.fetchingTaskIdentifier = 0;
[TSSocketManager resignActivity];
[[UIApplication sharedApplication] endBackgroundTask:identifier];
}
- (void)backgroundConnectTimedOut {
UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.alertBody = NSLocalizedString(@"APN_FETCHED_FAILED", nil);
notification.alertBody = NSLocalizedString(@"APN_FETCHED_FAILED", nil);
[[UIApplication sharedApplication] presentLocalNotificationNow:notification];
}

View File

@ -22,6 +22,7 @@ extern NSString *const TSUIDatabaseConnectionDidUpdateNotification;
+ (instancetype)sharedManager;
- (void)setupDatabase;
- (void)deleteThreadsAndMessages;
- (BOOL)databasePasswordAccessible;
- (void)wipeSignalStorage;
- (YapDatabase*)database;

View File

@ -146,6 +146,22 @@ static NSString * keychainDBPassAccount = @"TSDatabasePass";
return databasePath;
}
- (BOOL)databasePasswordAccessible {
[SSKeychain setAccessibilityType:kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly];
NSError *error;
NSString *dbPassword = [SSKeychain passwordForService:keychainService account:keychainDBPassAccount error:&error];
if (dbPassword && !error) {
return YES;
}
if (error) {
DDLogWarn(@"Database password couldn't be accessed: %@", error.localizedDescription);
}
return NO;
}
- (NSData*)databasePassword {
[SSKeychain setAccessibilityType:kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly];
NSString *dbPassword = [SSKeychain passwordForService:keychainService account:keychainDBPassAccount];

View File

@ -10,14 +10,18 @@
#import <PastelogKit/Pastelog.h>
#import "Environment.h"
#import "PreferencesUtil.h"
#import "DebugLogger.h"
#import "TSAccountManager.h"
#import "PreferencesUtil.h"
#import "PushManager.h"
@interface AdvancedSettingsTableViewController ()
@property (strong, nonatomic) UITableViewCell * enableLogCell;
@property (strong, nonatomic) UITableViewCell * submitLogCell;
@property NSArray *sectionsArray;
@property (strong, nonatomic) UITableViewCell *enableLogCell;
@property (strong, nonatomic) UITableViewCell *submitLogCell;
@property (strong, nonatomic) UITableViewCell *registerPushCell;
@property (strong, nonatomic) UISwitch * enableLogSwitch;
@end
@ -26,11 +30,14 @@
- (void)viewDidLoad {
[super viewDidLoad];
[self.navigationController.navigationBar setTranslucent:NO];
[self.navigationController.navigationBar setTranslucent:NO];
self.tableView.tableFooterView = [[UIView alloc]initWithFrame:CGRectZero];
}
-(instancetype)init {
self.sectionsArray = @[NSLocalizedString(@"LOGGING_SECTION", nil),
NSLocalizedString(@"PUSH_REGISTER_TITLE", nil)];
return [super initWithStyle:UITableViewStyleGrouped];
}
@ -55,32 +62,45 @@
self.enableLogCell.accessoryView = self.enableLogSwitch;
//Send Log
self.submitLogCell = [[UITableViewCell alloc]init];
self.submitLogCell.textLabel.text = NSLocalizedString(@"SETTINGS_ADVANCED_SUBMIT_DEBUGLOG", @"");
self.registerPushCell = [[UITableViewCell alloc] init];
self.registerPushCell.textLabel.text = NSLocalizedString(@"REREGISTER_FOR_PUSH", nil);
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
return (NSInteger)[self.sectionsArray count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.enableLogSwitch.isOn ? 2 : 1;
switch (section) {
case 0:
return self.enableLogSwitch.isOn ? 2 : 1;
case 1:
return 1;
default:
return 0;
}
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return @"Logging";
return [self.sectionsArray objectAtIndex:(NSUInteger)section];
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
switch (indexPath.row) {
case 0: return self.enableLogCell;
case 1: return self.submitLogCell;
if (indexPath.section == 0) {
switch (indexPath.row) {
case 0: return self.enableLogCell;
case 1: return self.enableLogSwitch.isOn ? self.submitLogCell:self.registerPushCell;
}
} else {
return self.registerPushCell;
}
NSAssert(false, @"No Cell configured");
@ -92,10 +112,23 @@
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if (indexPath.row == 1)
if ([tableView cellForRowAtIndexPath:indexPath] == self.submitLogCell)
{
[Pastelog submitLogs];
} else if ([tableView cellForRowAtIndexPath:indexPath] == self.registerPushCell) {
__block failedPushRegistrationBlock failure = ^(NSError *error) {
SignalAlertView(NSLocalizedString(@"PUSH_REGISTER_TITLE", nil),
NSLocalizedString(@"REGISTRATION_BODY", nil));
};
[[PushManager sharedManager] requestPushTokenWithSuccess:^(NSData *pushToken, NSData *voipToken) {
[TSAccountManager registerForPushNotifications:pushToken voipToken:voipToken success:^{
SignalAlertView(NSLocalizedString(@"PUSH_REGISTER_TITLE", nil),
NSLocalizedString(@"PUSH_REGISTER_SUCCESS", nil));
} failure:failure];
} failure:failure];
}
}
#pragma mark - Actions