Merge branch 'mkirk/manually-disable' into release/2.39.0

pull/2/head
Michael Kirk 6 years ago
commit 91945dbce6

@ -138,10 +138,17 @@ NS_ASSUME_NONNULL_BEGIN
@"Table header for the 'censorship circumvention' section.");
BOOL isAnySocketOpen = TSSocketManager.shared.highestSocketState == OWSWebSocketStateOpen;
if (OWSSignalService.sharedInstance.hasCensoredPhoneNumber) {
censorshipSection.footerTitle
= NSLocalizedString(@"SETTINGS_ADVANCED_CENSORSHIP_CIRCUMVENTION_FOOTER_AUTO_ENABLED",
if (OWSSignalService.sharedInstance.isCensorshipCircumventionManuallyDisabled) {
censorshipSection.footerTitle
= NSLocalizedString(@"SETTINGS_ADVANCED_CENSORSHIP_CIRCUMVENTION_FOOTER_MANUALLY_DISABLED",
@"Table footer for the 'censorship circumvention' section shown when censorship circumvention has "
@"been manually disabled.");
} else {
censorshipSection.footerTitle = NSLocalizedString(
@"SETTINGS_ADVANCED_CENSORSHIP_CIRCUMVENTION_FOOTER_AUTO_ENABLED",
@"Table footer for the 'censorship circumvention' section shown when censorship circumvention has been "
@"auto-enabled based on local phone number.");
}
} else if (isAnySocketOpen) {
censorshipSection.footerTitle
= NSLocalizedString(@"SETTINGS_ADVANCED_CENSORSHIP_CIRCUMVENTION_FOOTER_WEBSOCKET_CONNECTED",
@ -170,20 +177,22 @@ NS_ASSUME_NONNULL_BEGIN
// censorship circumvention unnecessarily, e.g. if they just don't have a valid
// internet connection.
OWSTableSwitchBlock isCensorshipCircumventionOnBlock = ^{
if (OWSSignalService.sharedInstance.hasCensoredPhoneNumber) {
return YES;
} else {
return OWSSignalService.sharedInstance.isCensorshipCircumventionManuallyActivated;
}
return OWSSignalService.sharedInstance.isCensorshipCircumventionActive;
};
Reachability *reachability = self.reachability;
OWSTableSwitchBlock isManualCensorshipCircumventionOnEnabledBlock = ^{
BOOL isAnySocketOpen = TSSocketManager.shared.highestSocketState == OWSWebSocketStateOpen;
BOOL value = (OWSSignalService.sharedInstance.isCensorshipCircumventionManuallyActivated
|| (!OWSSignalService.sharedInstance.hasCensoredPhoneNumber && !isAnySocketOpen
&& reachability.isReachable));
return value;
OWSSignalService *service = OWSSignalService.sharedInstance;
if (service.isCensorshipCircumventionActive) {
return YES;
} else if (service.hasCensoredPhoneNumber && service.isCensorshipCircumventionManuallyDisabled) {
return YES;
} else if (TSSocketManager.shared.highestSocketState == OWSWebSocketStateOpen) {
return NO;
} else {
return reachability.isReachable;
}
};
[censorshipSection
addItem:[OWSTableItem switchItemWithText:NSLocalizedString(@"SETTINGS_ADVANCED_CENSORSHIP_CIRCUMVENTION",
@"Label for the 'manual censorship circumvention' switch.")
@ -286,7 +295,14 @@ NS_ASSUME_NONNULL_BEGIN
- (void)didToggleEnableCensorshipCircumventionSwitch:(UISwitch *)sender
{
OWSSignalService.sharedInstance.isCensorshipCircumventionManuallyActivated = sender.isOn;
OWSSignalService *service = OWSSignalService.sharedInstance;
if (sender.isOn) {
service.isCensorshipCircumventionManuallyDisabled = NO;
service.isCensorshipCircumventionManuallyActivated = YES;
} else {
service.isCensorshipCircumventionManuallyDisabled = YES;
service.isCensorshipCircumventionManuallyActivated = NO;
}
[self updateTableContents];
}

@ -2033,6 +2033,9 @@
/* Table footer for the 'censorship circumvention' section shown when censorship circumvention has been auto-enabled based on local phone number. */
"SETTINGS_ADVANCED_CENSORSHIP_CIRCUMVENTION_FOOTER_AUTO_ENABLED" = "Censorship circumvention has been activated based on your account's phone number.";
/* Table footer for the 'censorship circumvention' section shown when censorship circumvention has been manually disabled. */
"SETTINGS_ADVANCED_CENSORSHIP_CIRCUMVENTION_FOOTER_MANUALLY_DISABLED" = "You have manually disabled censorship circumvention.";
/* Table footer for the 'censorship circumvention' section shown when the app is not connected to the internet. */
"SETTINGS_ADVANCED_CENSORSHIP_CIRCUMVENTION_FOOTER_NO_CONNECTION" = "Censorship circumvention can only be activated when connected to the internet.";
@ -2390,9 +2393,6 @@
/* Pressing this button moves an archived thread from the archive back to the inbox */
"UNARCHIVE_ACTION" = "Unarchive";
/* In Inbox view, last message label for thread with corrupted attachment. */
"UNKNOWN_ATTACHMENT_LABEL" = "Unknown attachment";
/* Message shown in conversation view that offers to block an unknown user. */
"UNKNOWN_CONTACT_BLOCK_OFFER" = "User not in your contacts. Would you like to block this user?";

@ -1,5 +1,5 @@
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
//
#import "OWSReadReceiptManager.h"
@ -524,22 +524,9 @@ NSString *const OWSReadReceiptManagerAreReadReceiptsEnabled = @"areReadReceiptsE
{
// We don't need to worry about races around this cached value.
if (!self.areReadReceiptsEnabledCached) {
// Default to NO.
self.areReadReceiptsEnabledCached = @([self.dbConnection boolForKey:OWSReadReceiptManagerAreReadReceiptsEnabled
inCollection:OWSReadReceiptManagerCollection]);
}
return [self.areReadReceiptsEnabledCached boolValue];
}
- (BOOL)areReadReceiptsEnabledWithTransaction:(YapDatabaseReadTransaction *)transaction
{
if (!self.areReadReceiptsEnabledCached) {
[self.dbConnection readWithBlock:^(YapDatabaseReadTransaction *_Nonnull transaction) {
// Default to NO.
self.areReadReceiptsEnabledCached = [transaction objectForKey:OWSReadReceiptManagerAreReadReceiptsEnabled
inCollection:OWSReadReceiptManagerCollection];
}];
inCollection:OWSReadReceiptManagerCollection
defaultValue:NO]);
}
return [self.areReadReceiptsEnabledCached boolValue];

@ -19,6 +19,7 @@ extern NSString *const OWSFrontingHost_GoogleQatar;
// returns best censorship configuration for country code. Will return a default if one hasn't
// been specifically configured.
+ (instancetype)censorshipConfigurationWithCountryCode:(NSString *)countryCode;
+ (instancetype)defaultConfiguration;
+ (BOOL)isCensoredPhoneNumber:(NSString *)e164PhoneNumber;

@ -38,22 +38,27 @@ NSString *const OWSFrontingHost_Default = @"www.google.com";
OWSAssertDebug(countryMetadadata);
NSString *_Nullable specifiedDomain = countryMetadadata.frontingDomain;
NSURL *baseURL;
AFSecurityPolicy *securityPolicy;
if (specifiedDomain.length > 0) {
NSString *frontingURLString = [NSString stringWithFormat:@"https://%@", specifiedDomain];
baseURL = [NSURL URLWithString:frontingURLString];
securityPolicy = [self securityPolicyForDomain:(NSString *)specifiedDomain];
} else {
NSString *frontingURLString = [NSString stringWithFormat:@"https://%@", OWSFrontingHost_Default];
baseURL = [NSURL URLWithString:frontingURLString];
securityPolicy = [self securityPolicyForDomain:OWSFrontingHost_Default];
if (specifiedDomain.length == 0) {
return self.defaultConfiguration;
}
OWSAssertDebug(baseURL);
NSString *frontingURLString = [NSString stringWithFormat:@"https://%@", specifiedDomain];
NSURL *_Nullable baseURL = [NSURL URLWithString:frontingURLString];
if (baseURL == nil) {
OWSFailDebug(@"baseURL was unexpectedly nil with specifiedDomain: %@", specifiedDomain);
return self.defaultConfiguration;
}
AFSecurityPolicy *securityPolicy = [self securityPolicyForDomain:specifiedDomain];
OWSAssertDebug(securityPolicy);
return [[OWSCensorshipConfiguration alloc] initWithDomainFrontBaseURL:baseURL securityPolicy:securityPolicy];
}
+ (instancetype)defaultConfiguration
{
NSString *frontingURLString = [NSString stringWithFormat:@"https://%@", OWSFrontingHost_Default];
NSURL *baseURL = [NSURL URLWithString:frontingURLString];
AFSecurityPolicy *securityPolicy = [self securityPolicyForDomain:OWSFrontingHost_Default];
return [[OWSCensorshipConfiguration alloc] initWithDomainFrontBaseURL:baseURL securityPolicy:securityPolicy];
}
@ -107,7 +112,6 @@ NSString *const OWSFrontingHost_Default = @"www.google.com";
};
}
// Returns nil if the phone number is not known to be censored
+ (BOOL)isCensoredPhoneNumber:(NSString *)e164PhoneNumber;
{
return [self censoredCountryCodeWithPhoneNumber:e164PhoneNumber].length > 0;

@ -24,6 +24,7 @@ extern NSString *const kNSNotificationName_IsCensorshipCircumventionActiveDidCha
@property (atomic, readonly) BOOL isCensorshipCircumventionActive;
@property (atomic, readonly) BOOL hasCensoredPhoneNumber;
@property (atomic) BOOL isCensorshipCircumventionManuallyActivated;
@property (atomic) BOOL isCensorshipCircumventionManuallyDisabled;
@property (atomic, nullable) NSString *manualCensorshipCircumventionCountryCode;
/// For interacting with the Signal Service

@ -18,6 +18,8 @@ NS_ASSUME_NONNULL_BEGIN
NSString *const kOWSPrimaryStorage_OWSSignalService = @"kTSStorageManager_OWSSignalService";
NSString *const kOWSPrimaryStorage_isCensorshipCircumventionManuallyActivated
= @"kTSStorageManager_isCensorshipCircumventionManuallyActivated";
NSString *const kOWSPrimaryStorage_isCensorshipCircumventionManuallyDisabled
= @"kTSStorageManager_isCensorshipCircumventionManuallyDisabled";
NSString *const kOWSPrimaryStorage_ManualCensorshipCircumventionDomain
= @"kTSStorageManager_ManualCensorshipCircumventionDomain";
NSString *const kOWSPrimaryStorage_ManualCensorshipCircumventionCountryCode
@ -28,8 +30,6 @@ NSString *const kNSNotificationName_IsCensorshipCircumventionActiveDidChange =
@interface OWSSignalService ()
@property (nonatomic, nullable, readonly) OWSCensorshipConfiguration *censorshipConfiguration;
@property (atomic) BOOL hasCensoredPhoneNumber;
@property (atomic) BOOL isCensorshipCircumventionActive;
@ -104,7 +104,8 @@ NSString *const kNSNotificationName_IsCensorshipCircumventionActiveDidChange =
{
return
[[OWSPrimaryStorage dbReadConnection] boolForKey:kOWSPrimaryStorage_isCensorshipCircumventionManuallyActivated
inCollection:kOWSPrimaryStorage_OWSSignalService];
inCollection:kOWSPrimaryStorage_OWSSignalService
defaultValue:NO];
}
- (void)setIsCensorshipCircumventionManuallyActivated:(BOOL)value
@ -116,10 +117,34 @@ NSString *const kNSNotificationName_IsCensorshipCircumventionActiveDidChange =
[self updateIsCensorshipCircumventionActive];
}
- (BOOL)isCensorshipCircumventionManuallyDisabled
{
return [[OWSPrimaryStorage dbReadConnection] boolForKey:kOWSPrimaryStorage_isCensorshipCircumventionManuallyDisabled
inCollection:kOWSPrimaryStorage_OWSSignalService
defaultValue:NO];
}
- (void)setIsCensorshipCircumventionManuallyDisabled:(BOOL)value
{
[[OWSPrimaryStorage dbReadWriteConnection] setObject:@(value)
forKey:kOWSPrimaryStorage_isCensorshipCircumventionManuallyDisabled
inCollection:kOWSPrimaryStorage_OWSSignalService];
[self updateIsCensorshipCircumventionActive];
}
- (void)updateIsCensorshipCircumventionActive
{
self.isCensorshipCircumventionActive
= (self.isCensorshipCircumventionManuallyActivated || self.hasCensoredPhoneNumber);
if (self.isCensorshipCircumventionManuallyDisabled) {
self.isCensorshipCircumventionActive = NO;
} else if (self.isCensorshipCircumventionManuallyActivated) {
self.isCensorshipCircumventionActive = YES;
} else if (self.hasCensoredPhoneNumber) {
self.isCensorshipCircumventionActive = YES;
} else {
self.isCensorshipCircumventionActive = NO;
}
}
- (void)setIsCensorshipCircumventionActive:(BOOL)isCensorshipCircumventionActive
@ -150,8 +175,9 @@ NSString *const kNSNotificationName_IsCensorshipCircumventionActiveDidChange =
- (AFHTTPSessionManager *)buildSignalServiceSessionManager
{
if (self.isCensorshipCircumventionActive) {
OWSLogInfo(@"using reflector HTTPSessionManager via: %@", self.censorshipConfiguration.domainFrontBaseURL);
return self.reflectorSignalServiceSessionManager;
OWSCensorshipConfiguration *censorshipConfiguration = [self buildCensorshipConfiguration];
OWSLogInfo(@"using reflector HTTPSessionManager via: %@", censorshipConfiguration.domainFrontBaseURL);
return [self reflectorSignalServiceSessionManagerWithCensorshipConfiguration:censorshipConfiguration];
} else {
return self.defaultSignalServiceSessionManager;
}
@ -174,10 +200,9 @@ NSString *const kNSNotificationName_IsCensorshipCircumventionActiveDidChange =
return sessionManager;
}
- (AFHTTPSessionManager *)reflectorSignalServiceSessionManager
- (AFHTTPSessionManager *)reflectorSignalServiceSessionManagerWithCensorshipConfiguration:
(OWSCensorshipConfiguration *)censorshipConfiguration
{
OWSCensorshipConfiguration *censorshipConfiguration = self.censorshipConfiguration;
NSURLSessionConfiguration *sessionConf = NSURLSessionConfiguration.ephemeralSessionConfiguration;
AFHTTPSessionManager *sessionManager =
[[AFHTTPSessionManager alloc] initWithBaseURL:censorshipConfiguration.domainFrontBaseURL
@ -186,7 +211,8 @@ NSString *const kNSNotificationName_IsCensorshipCircumventionActiveDidChange =
sessionManager.securityPolicy = censorshipConfiguration.domainFrontSecurityPolicy;
sessionManager.requestSerializer = [AFJSONRequestSerializer serializer];
[sessionManager.requestSerializer setValue:self.censorshipConfiguration.signalServiceReflectorHost forHTTPHeaderField:@"Host"];
[sessionManager.requestSerializer setValue:censorshipConfiguration.signalServiceReflectorHost
forHTTPHeaderField:@"Host"];
sessionManager.responseSerializer = [AFJSONResponseSerializer serializer];
// Disable default cookie handling for all requests.
sessionManager.requestSerializer.HTTPShouldHandleCookies = NO;
@ -199,8 +225,9 @@ NSString *const kNSNotificationName_IsCensorshipCircumventionActiveDidChange =
- (AFHTTPSessionManager *)CDNSessionManager
{
if (self.isCensorshipCircumventionActive) {
OWSLogInfo(@"using reflector CDNSessionManager via: %@", self.censorshipConfiguration.domainFrontBaseURL);
return self.reflectorCDNSessionManager;
OWSCensorshipConfiguration *censorshipConfiguration = [self buildCensorshipConfiguration];
OWSLogInfo(@"using reflector CDNSessionManager via: %@", censorshipConfiguration.domainFrontBaseURL);
return [self reflectorCDNSessionManagerWithCensorshipConfiguration:censorshipConfiguration];
} else {
return self.defaultCDNSessionManager;
}
@ -223,12 +250,11 @@ NSString *const kNSNotificationName_IsCensorshipCircumventionActiveDidChange =
return sessionManager;
}
- (AFHTTPSessionManager *)reflectorCDNSessionManager
- (AFHTTPSessionManager *)reflectorCDNSessionManagerWithCensorshipConfiguration:
(OWSCensorshipConfiguration *)censorshipConfiguration
{
NSURLSessionConfiguration *sessionConf = NSURLSessionConfiguration.ephemeralSessionConfiguration;
OWSCensorshipConfiguration *censorshipConfiguration = self.censorshipConfiguration;
AFHTTPSessionManager *sessionManager =
[[AFHTTPSessionManager alloc] initWithBaseURL:censorshipConfiguration.domainFrontBaseURL
sessionConfiguration:sessionConf];
@ -257,8 +283,10 @@ NSString *const kNSNotificationName_IsCensorshipCircumventionActiveDidChange =
#pragma mark - Manual Censorship Circumvention
- (nullable OWSCensorshipConfiguration *)censorshipConfiguration
- (OWSCensorshipConfiguration *)buildCensorshipConfiguration
{
OWSAssertDebug(self.isCensorshipCircumventionActive);
if (self.isCensorshipCircumventionManuallyActivated) {
NSString *countryCode = self.manualCensorshipCircumventionCountryCode;
if (countryCode.length == 0) {
@ -272,9 +300,13 @@ NSString *const kNSNotificationName_IsCensorshipCircumventionActiveDidChange =
return configuration;
}
OWSCensorshipConfiguration *configuration =
OWSCensorshipConfiguration *_Nullable configuration =
[OWSCensorshipConfiguration censorshipConfigurationWithPhoneNumber:TSAccountManager.localNumber];
return configuration;
if (configuration != nil) {
return configuration;
}
return OWSCensorshipConfiguration.defaultConfiguration;
}
- (nullable NSString *)manualCensorshipCircumventionCountryCode

@ -1,5 +1,5 @@
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
//
#import <YapDatabase/YapDatabaseConnection.h>
@ -13,7 +13,6 @@ NS_ASSUME_NONNULL_BEGIN
@interface YapDatabaseConnection (OWS)
- (BOOL)hasObjectForKey:(NSString *)key inCollection:(NSString *)collection;
- (BOOL)boolForKey:(NSString *)key inCollection:(NSString *)collection;
- (BOOL)boolForKey:(NSString *)key inCollection:(NSString *)collection defaultValue:(BOOL)defaultValue;
- (double)doubleForKey:(NSString *)key inCollection:(NSString *)collection defaultValue:(double)defaultValue;
- (int)intForKey:(NSString *)key inCollection:(NSString *)collection;

@ -51,11 +51,6 @@ NS_ASSUME_NONNULL_BEGIN
return [self objectForKey:key inCollection:collection ofExpectedType:[NSString class]];
}
- (BOOL)boolForKey:(NSString *)key inCollection:(NSString *)collection
{
return [self boolForKey:key inCollection:collection defaultValue:NO];
}
- (BOOL)boolForKey:(NSString *)key inCollection:(NSString *)collection defaultValue:(BOOL)defaultValue
{
NSNumber *_Nullable value = [self objectForKey:key inCollection:collection ofExpectedType:[NSNumber class]];

@ -12,7 +12,6 @@ NS_ASSUME_NONNULL_BEGIN
@interface YapDatabaseReadTransaction (OWS)
- (BOOL)boolForKey:(NSString *)key inCollection:(NSString *)collection;
- (BOOL)boolForKey:(NSString *)key inCollection:(NSString *)collection defaultValue:(BOOL)defaultValue;
- (int)intForKey:(NSString *)key inCollection:(NSString *)collection;
- (nullable NSDate *)dateForKey:(NSString *)key inCollection:(NSString *)collection;

@ -36,14 +36,6 @@ NS_ASSUME_NONNULL_BEGIN
return [self objectForKey:key inCollection:collection ofExpectedType:[NSString class]];
}
- (BOOL)boolForKey:(NSString *)key inCollection:(NSString *)collection
{
OWSAssertDebug(key.length > 0);
OWSAssertDebug(collection.length > 0);
return [self boolForKey:key inCollection:collection defaultValue:NO];
}
- (BOOL)boolForKey:(NSString *)key inCollection:(NSString *)collection defaultValue:(BOOL)defaultValue
{
OWSAssertDebug(key.length > 0);

Loading…
Cancel
Save