From 9240a095ae49649d6e9cbc8c873e2d8cdbfa1002 Mon Sep 17 00:00:00 2001 From: Frederic Jacobs Date: Tue, 5 Aug 2014 05:44:43 +0200 Subject: [PATCH] Travis CI-support and iOS8 push notifications //FREEBIE --- .travis.yml | 7 +- Signal.xcodeproj/project.pbxproj | 2 + Signal/Signal-Prefix.pch | 1 + Signal/src/environment/Release.m | 6 +- Signal/src/environment/iOSVersions.h | 96 +++++++++++++++++++ Signal/src/network/PushManager.m | 41 +++++++- Signal/test/network/rtp/RtpPacketTests.m | 4 + .../test/network/rtp/srtp/SecureStreamTest.m | 5 + .../network/rtp/zrtp/HandshakePacketTest.m | 5 + Signal/test/network/rtp/zrtp/ZrtpTest.m | 1 + .../network/tcp/LowLatencyConnectorTest.m | 4 + .../test/network/tcp/tls/NetworkStreamTest.m | 4 + 12 files changed, 165 insertions(+), 11 deletions(-) create mode 100644 Signal/src/environment/iOSVersions.h diff --git a/.travis.yml b/.travis.yml index bfddfa22d..f0502d3f9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,5 @@ language: objective-c -cache: cocoapods - -script: xcodebuild test -workspace Signal.xcworkspace -scheme Signal -sdk iphonesimulator ONLY_ACTIVE_ARCH=YES +xcode_sdk: iphonesimulator7.1 +install: true +xcode_workspace: Signal.xcworkspace +xcode_scheme: Signal diff --git a/Signal.xcodeproj/project.pbxproj b/Signal.xcodeproj/project.pbxproj index e469f7710..e0327dbe6 100644 --- a/Signal.xcodeproj/project.pbxproj +++ b/Signal.xcodeproj/project.pbxproj @@ -1113,6 +1113,7 @@ B621B06F198C69A100D36C3D /* zh_TW */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = zh_TW; path = Localizable.strings; sourceTree = ""; }; B624C4E5198FD2830009264A /* whisperFake.cer */ = {isa = PBXFileReference; lastKnownFileType = file; name = whisperFake.cer; path = Signal/test/whisperFake.cer; sourceTree = SOURCE_ROOT; }; B657DDC91911A40500F45B0C /* Signal.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = Signal.entitlements; sourceTree = ""; }; + B661C211198EE2EA00548CA1 /* iOSVersions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = iOSVersions.h; path = src/environment/iOSVersions.h; sourceTree = ""; }; B67ADDC21989FF8700E1A773 /* CallServerRequestsManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CallServerRequestsManager.h; sourceTree = ""; }; B67ADDC31989FF8700E1A773 /* CallServerRequestsManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CallServerRequestsManager.m; sourceTree = ""; }; B67EBF5C19194AC60084CCFD /* Settings.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; name = Settings.bundle; path = SettingsBundle/Settings.bundle; sourceTree = SOURCE_ROOT; }; @@ -2878,6 +2879,7 @@ D221A099169C9E5E00537ABF /* main.m */, D221A095169C9E5E00537ABF /* Signal-Info.plist */, D221A09B169C9E5E00537ABF /* Signal-Prefix.pch */, + B661C211198EE2EA00548CA1 /* iOSVersions.h */, E1C407C117F0C246007BEE65 /* whisperReal.cer */, B624C4E5198FD2830009264A /* whisperFake.cer */, ); diff --git a/Signal/Signal-Prefix.pch b/Signal/Signal-Prefix.pch index 9af74af72..c61d02035 100644 --- a/Signal/Signal-Prefix.pch +++ b/Signal/Signal-Prefix.pch @@ -15,4 +15,5 @@ static const int ddLogLevel = LOG_LEVEL_ERROR; #endif + #import "iOSVersions.h" #endif diff --git a/Signal/src/environment/Release.m b/Signal/src/environment/Release.m index 4ad38e3a6..8699c23a7 100644 --- a/Signal/src/environment/Release.m +++ b/Signal/src/environment/Release.m @@ -70,10 +70,10 @@ static unsigned char DH3K_PRIME[]={ return [Environment environmentWithLogging:[DiscardingLog discardingLog] andErrorNoter:^(id error, id relatedInfo, bool causedTermination) {} andServerPort:31337 - andMasterServerHostName:@"testing.whispersystems.org" - andDefaultRelayName:@"testing" + andMasterServerHostName:@"master.whispersystems.org" + andDefaultRelayName:@"relay" andRelayServerHostNameSuffix:@"whispersystems.org" - andCertificate:[Certificate certificateFromResourcePath:@"whisperReal" ofType:@"der"] + andCertificate:[Certificate certificateFromResourcePath:@"whisperReal" ofType:@"cer"] andCurrentRegionCodeForPhoneNumbers:@"US" andSupportedKeyAgreementProtocols:[self supportedKeyAgreementProtocols] andPhoneManager:nil diff --git a/Signal/src/environment/iOSVersions.h b/Signal/src/environment/iOSVersions.h new file mode 100644 index 000000000..3252f883d --- /dev/null +++ b/Signal/src/environment/iOSVersions.h @@ -0,0 +1,96 @@ +// +// iOSVersions.h +// Signal +// +// Created by Frederic Jacobs on 03/08/14. +// Copyright (c) 2014 Open Whisper Systems. All rights reserved. +// + +#import +#include + +// Source: https://github.com/carlj/CJAMacros/blob/master/CJAMacros/CJAMacros.h + +/** + Runtime check for the current version Nummer. + checks ( CURRENT_VERSION_NUMBR == GIVEN_VERSION_NUMBER) + @_gVersion - the given Version Number. aka (_iOS_7_0 or NSFoundationVersionNumber_iOS_7_0 and so on) + */ +#define SYSTEM_VERSION_EQUAL_TO(_gVersion) ( floor(NSFoundationVersionNumber) == _gVersion ) + +/** + Runtime check for the current version Nummer. + checks CURRENT_VERSION_NUMBER > GIVEN_VERSION_NUMBER + @_gVersion - the given Version Number. aka (_iOS_7_0 or NSFoundationVersionNumber_iOS_7_0 and so on) + */ +#define SYSTEM_VERSION_GREATER_THAN(_gVersion) ( floor(NSFoundationVersionNumber) > _gVersion ) + +/** + Runtime check for the current version Nummer. + checks CURRENT_VERSION_NUMBER >= GIVEN_VERSION_NUMBER + @_gVersion - the given Version Number. aka (_iOS_7_0 or NSFoundationVersionNumber_iOS_7_0 and so on) + */ +#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(_gVersion) ( floor(NSFoundationVersionNumber) >= _gVersion ) + + +/** + Runtime check for the current version Nummer. + checks CURRENT_VERSION_NUMBER < GIVEN_VERSION_NUMBER + @_gVersion - the given Version Number. aka (_iOS_7_0 or NSFoundationVersionNumber_iOS_7_0 and so on) + */ +#define SYSTEM_VERSION_LESS_THAN(_gVersion) ( floor(NSFoundationVersionNumber) < _gVersion ) + + +/** + Runtime check for the current version Nummer. + checks CURRENT_VERSION_NUMBER <= GIVEN_VERSION_NUMBER + @_gVersion - the given Version Number. aka (_iOS_7_0 or NSFoundationVersionNumber_iOS_7_0 and so on) + */ +#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(_gVersion) ( floor(NSFoundationVersionNumber) <= _gVersion ) + + +//If the symbol for iOS 7 isnt defined, define it. +#ifndef NSFoundationVersionNumber_iOS_7_0 +#define NSFoundationVersionNumber_iOS_7_0 1047.00 //extracted from iOS 7 Header +#endif + +#ifdef NSFoundationVersionNumber_iOS_7_0 +#define _iOS_7_0 NSFoundationVersionNumber_iOS_7_0 +#endif + +//If the symbol for iOS 7.1 isnt defined, define it. +#ifndef NSFoundationVersionNumber_iOS_7_1 +#define NSFoundationVersionNumber_iOS_7_1 1047.25 //extracted from iOS 8 Header +#endif + +#ifdef NSFoundationVersionNumber_iOS_7_1 +#define _iOS_7_1 NSFoundationVersionNumber_iOS_7_1 +#endif + +//If the symbol for iOS 8 isnt defined, define it. +#ifndef NSFoundationVersionNumber_iOS_8_0 +#define NSFoundationVersionNumber_iOS_8_0 1134.10 //extracted with NSLog(@"%f", NSFoundationVersionNumber) +#endif + +#ifdef NSFoundationVersionNumber_iOS_8_0 +#define _iOS_8_0 NSFoundationVersionNumber_iOS_8_0 +#endif + + +/** + Add a Singelton implementation to the .m File + */ + +#define MacrosSingletonImplemantion \ ++ (instancetype)sharedInstance { \ +\ +static dispatch_once_t onceToken; \ +static id sharedInstance = nil; \ +dispatch_once(&onceToken, ^{ \ +sharedInstance = [self.class new]; \ +}); \ +\ +return sharedInstance; \ +} + +#define CJAMacrosSingletonInterface + (instancetype)sharedInstance; diff --git a/Signal/src/network/PushManager.m b/Signal/src/network/PushManager.m index 361f5e961..ef91ca23c 100644 --- a/Signal/src/network/PushManager.m +++ b/Signal/src/network/PushManager.m @@ -34,9 +34,7 @@ UIRemoteNotificationType notificationTypes = [[UIApplication sharedApplication] enabledRemoteNotificationTypes]; BOOL needsPushSettingChangeAlert = NO; - - // enhancement: do custom message depending on the setting? - + if (notificationTypes == UIRemoteNotificationTypeNone) { needsPushSettingChangeAlert = YES; } else if (notificationTypes == UIRemoteNotificationTypeBadge) { @@ -60,7 +58,7 @@ [self askForPushRegistration]; } } - + } - (void)askForPushRegistrationWithSuccess:(void (^)())success failure:(void (^)())failure{ @@ -70,7 +68,38 @@ } - (void)askForPushRegistration{ - [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeBadge)]; + + if(SYSTEM_VERSION_LESS_THAN(_iOS_8_0)){ + [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeBadge)]; + } else{ +#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_7_1 + UIMutableUserNotificationAction *action_accept = [[UIMutableUserNotificationAction alloc]init]; + action_accept.identifier = @"Signal_Call_Accept"; + action_accept.title = @"Pick up"; + action_accept.activationMode = UIUserNotificationActivationModeForeground; + action_accept.destructive = YES; + action_accept.authenticationRequired = NO; + + UIMutableUserNotificationAction *action_decline = [[UIMutableUserNotificationAction alloc]init]; + action_decline.identifier = @"Signal_Call_Decline"; + action_decline.title = @"Pick up"; + action_decline.activationMode = UIUserNotificationActivationModeForeground; + action_decline.destructive = YES; + action_decline.authenticationRequired = NO; + + UIMutableUserNotificationCategory *callCategory = [[UIMutableUserNotificationCategory alloc] init]; + callCategory.identifier = @"Signal_IncomingCall"; + [callCategory setActions:@[action_accept, action_decline] forContext:UIUserNotificationActionContextDefault]; + + NSSet *categories = [NSSet setWithObject:callCategory]; + + [[UIApplication sharedApplication] registerForRemoteNotifications]; + [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeSound) categories:categories]]; + +#endif + + } + self.retries = 3; } @@ -114,4 +143,6 @@ } } + + @end diff --git a/Signal/test/network/rtp/RtpPacketTests.m b/Signal/test/network/rtp/RtpPacketTests.m index 4195d0aac..61603df16 100644 --- a/Signal/test/network/rtp/RtpPacketTests.m +++ b/Signal/test/network/rtp/RtpPacketTests.m @@ -8,6 +8,10 @@ @implementation RtpPacketTests +- (void)setUp{ + [Environment setCurrent:[Release unitTestEnvironment:@[]]]; +} + -(void) testRawDataSimple { RtpPacket* r = [RtpPacket rtpPacketWithVersion:2 andPadding:0 diff --git a/Signal/test/network/rtp/srtp/SecureStreamTest.m b/Signal/test/network/rtp/srtp/SecureStreamTest.m index a52f748aa..804fd088e 100644 --- a/Signal/test/network/rtp/srtp/SecureStreamTest.m +++ b/Signal/test/network/rtp/srtp/SecureStreamTest.m @@ -8,6 +8,11 @@ @end @implementation SecureStreamTest + +-(void)setUp{ + [Environment setCurrent:[Release unitTestEnvironment:@[]]]; +} + -(void) testPerturbedRoundTrip { for (int repeat = 0; repeat < 10; repeat++) { NSData* key = generatePseudoRandomData(16); diff --git a/Signal/test/network/rtp/zrtp/HandshakePacketTest.m b/Signal/test/network/rtp/zrtp/HandshakePacketTest.m index cb23b5908..73f9684b6 100644 --- a/Signal/test/network/rtp/zrtp/HandshakePacketTest.m +++ b/Signal/test/network/rtp/zrtp/HandshakePacketTest.m @@ -9,6 +9,11 @@ @end @implementation HandshakePacketTest + +- (void)setUp{ + [Environment setCurrent:[Release unitTestEnvironment:@[]]]; +} + -(void) testHelloPacket { [Environment setCurrent:testEnv]; HashChain* h = [HashChain hashChainWithSeed:[NSData dataWithLength:32]]; diff --git a/Signal/test/network/rtp/zrtp/ZrtpTest.m b/Signal/test/network/rtp/zrtp/ZrtpTest.m index f7f202230..724cf10b0 100644 --- a/Signal/test/network/rtp/zrtp/ZrtpTest.m +++ b/Signal/test/network/rtp/zrtp/ZrtpTest.m @@ -22,6 +22,7 @@ bool pm(HandshakePacket* p1, HandshakePacket* p2) { @implementation ZrtpTest - (void)setUp{ + [Environment setCurrent:[Release unitTestEnvironment:@[]]]; [SGNKeychainUtil generateSignaling]; [Environment setCurrent:testEnv]; } diff --git a/Signal/test/network/tcp/LowLatencyConnectorTest.m b/Signal/test/network/tcp/LowLatencyConnectorTest.m index 241b0edf2..db11547be 100644 --- a/Signal/test/network/tcp/LowLatencyConnectorTest.m +++ b/Signal/test/network/tcp/LowLatencyConnectorTest.m @@ -14,6 +14,10 @@ @implementation LowLatencyConnectorTest +- (void)setUp{ + [Environment setCurrent:[Release unitTestEnvironment:@[]]]; +} + -(void) testLowLatencyConnect_example { [Environment setCurrent:testEnvWith(ENVIRONMENT_TESTING_OPTION_ALLOW_NETWORK_STREAM_TO_NON_SECURE_END_POINTS)]; diff --git a/Signal/test/network/tcp/tls/NetworkStreamTest.m b/Signal/test/network/tcp/tls/NetworkStreamTest.m index 0ace5a07a..b6f0543ec 100644 --- a/Signal/test/network/tcp/tls/NetworkStreamTest.m +++ b/Signal/test/network/tcp/tls/NetworkStreamTest.m @@ -21,6 +21,10 @@ @implementation NetworkStreamTest +- (void)setUp{ + [Environment setCurrent:[Release unitTestEnvironment:@[]]]; +} + -(void) testReplies { [Environment setCurrent:testEnvWith(ENVIRONMENT_TESTING_OPTION_ALLOW_NETWORK_STREAM_TO_NON_SECURE_END_POINTS)];