Rename app preferences class.

// FREEBIE
This commit is contained in:
Matthew Chen 2017-09-14 15:45:04 -04:00
parent c7fab5b920
commit 80e5f281c6
23 changed files with 354 additions and 363 deletions

View File

@ -254,7 +254,7 @@
76EB054018170B33006006FC /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 76EB03C318170B33006006FC /* AppDelegate.m */; };
76EB057A18170B33006006FC /* OWSContactsManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 76EB040918170B33006006FC /* OWSContactsManager.m */; };
76EB058218170B33006006FC /* Environment.m in Sources */ = {isa = PBXBuildFile; fileRef = 76EB041318170B33006006FC /* Environment.m */; };
76EB058818170B33006006FC /* PropertyListPreferences.m in Sources */ = {isa = PBXBuildFile; fileRef = 76EB041918170B33006006FC /* PropertyListPreferences.m */; };
76EB058818170B33006006FC /* OWSPreferences.m in Sources */ = {isa = PBXBuildFile; fileRef = 76EB041918170B33006006FC /* OWSPreferences.m */; };
76EB058A18170B33006006FC /* Release.m in Sources */ = {isa = PBXBuildFile; fileRef = 76EB041B18170B33006006FC /* Release.m */; };
76EB062618170B33006006FC /* Queue.m in Sources */ = {isa = PBXBuildFile; fileRef = 76EB04D518170B33006006FC /* Queue.m */; };
76EB063A18170B33006006FC /* FunctionalUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = 76EB04EB18170B33006006FC /* FunctionalUtil.m */; };
@ -316,7 +316,7 @@
B660F7181C29988E00687D6E /* CryptoTools.m in Sources */ = {isa = PBXBuildFile; fileRef = 7038632418F70C0700D4A43F /* CryptoTools.m */; };
B660F71B1C29988E00687D6E /* Environment.m in Sources */ = {isa = PBXBuildFile; fileRef = 76EB041318170B33006006FC /* Environment.m */; };
B660F71C1C29988E00687D6E /* DebugLogger.m in Sources */ = {isa = PBXBuildFile; fileRef = B6C93C4D199567AD00EDF894 /* DebugLogger.m */; };
B660F71F1C29988E00687D6E /* PropertyListPreferences.m in Sources */ = {isa = PBXBuildFile; fileRef = 76EB041918170B33006006FC /* PropertyListPreferences.m */; };
B660F71F1C29988E00687D6E /* OWSPreferences.m in Sources */ = {isa = PBXBuildFile; fileRef = 76EB041918170B33006006FC /* OWSPreferences.m */; };
B660F7201C29988E00687D6E /* Release.m in Sources */ = {isa = PBXBuildFile; fileRef = 76EB041B18170B33006006FC /* Release.m */; };
B660F7211C29988E00687D6E /* SignalKeyingStorage.m in Sources */ = {isa = PBXBuildFile; fileRef = B6B1013B196D213F007E3930 /* SignalKeyingStorage.m */; };
B660F7221C29988E00687D6E /* VersionMigrations.m in Sources */ = {isa = PBXBuildFile; fileRef = B60C16641988999D00E97A6C /* VersionMigrations.m */; };
@ -722,8 +722,8 @@
76EB040918170B33006006FC /* OWSContactsManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSContactsManager.m; sourceTree = "<group>"; };
76EB041218170B33006006FC /* Environment.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Environment.h; sourceTree = "<group>"; };
76EB041318170B33006006FC /* Environment.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Environment.m; sourceTree = "<group>"; };
76EB041818170B33006006FC /* PropertyListPreferences.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PropertyListPreferences.h; sourceTree = "<group>"; };
76EB041918170B33006006FC /* PropertyListPreferences.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PropertyListPreferences.m; sourceTree = "<group>"; };
76EB041818170B33006006FC /* OWSPreferences.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSPreferences.h; sourceTree = "<group>"; };
76EB041918170B33006006FC /* OWSPreferences.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSPreferences.m; sourceTree = "<group>"; };
76EB041A18170B33006006FC /* Release.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Release.h; sourceTree = "<group>"; };
76EB041B18170B33006006FC /* Release.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Release.m; sourceTree = "<group>"; };
76EB04D418170B33006006FC /* Queue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Queue.h; sourceTree = "<group>"; };
@ -1390,16 +1390,16 @@
76EB041118170B33006006FC /* environment */ = {
isa = PBXGroup;
children = (
B6C93C4C199567AD00EDF894 /* DebugLogger.h */,
B6C93C4D199567AD00EDF894 /* DebugLogger.m */,
76EB041218170B33006006FC /* Environment.h */,
76EB041318170B33006006FC /* Environment.m */,
4505C2BD1E648E6E00CEBF41 /* ExperienceUpgrades */,
45666F731D9BFDB9008FE134 /* Migrations */,
B6258B311C29E2E60014138E /* NotificationsManager.h */,
B6258B321C29E2E60014138E /* NotificationsManager.m */,
76EB041218170B33006006FC /* Environment.h */,
76EB041318170B33006006FC /* Environment.m */,
B6C93C4C199567AD00EDF894 /* DebugLogger.h */,
B6C93C4D199567AD00EDF894 /* DebugLogger.m */,
76EB041818170B33006006FC /* PropertyListPreferences.h */,
76EB041918170B33006006FC /* PropertyListPreferences.m */,
76EB041818170B33006006FC /* OWSPreferences.h */,
76EB041918170B33006006FC /* OWSPreferences.m */,
76EB041A18170B33006006FC /* Release.h */,
76EB041B18170B33006006FC /* Release.m */,
B6B1013A196D213F007E3930 /* SignalKeyingStorage.h */,
@ -2405,7 +2405,7 @@
34B3F8941E8DF1710035BE1A /* HomeViewController.m in Sources */,
34E8BF381EE9E2FD00F5F4CA /* FingerprintViewScanController.m in Sources */,
346B66311F4E29B200E5122F /* CropScaleImageViewController.swift in Sources */,
76EB058818170B33006006FC /* PropertyListPreferences.m in Sources */,
76EB058818170B33006006FC /* OWSPreferences.m in Sources */,
34330A611E788EA900DF2FB9 /* AttachmentUploadView.m in Sources */,
45E5A6991F61E6DE001E4A8A /* MarqueeLabel.swift in Sources */,
34B3F87D1E8DF1700035BE1A /* FullImageViewController.m in Sources */,
@ -2435,7 +2435,7 @@
B660F7181C29988E00687D6E /* CryptoTools.m in Sources */,
B660F71B1C29988E00687D6E /* Environment.m in Sources */,
B660F71C1C29988E00687D6E /* DebugLogger.m in Sources */,
B660F71F1C29988E00687D6E /* PropertyListPreferences.m in Sources */,
B660F71F1C29988E00687D6E /* OWSPreferences.m in Sources */,
451DA3CA1F148A9F008E2423 /* DeviceSleepManager.swift in Sources */,
B660F7201C29988E00687D6E /* Release.m in Sources */,
45BB93391E688E14001E3939 /* UIDevice+featureSupport.swift in Sources */,

View File

@ -12,10 +12,10 @@
#import "OWSContactsManager.h"
#import "OWSContactsSyncing.h"
#import "OWSNavigationController.h"
#import "OWSPreferences.h"
#import "OWSProfileManager.h"
#import "OWSStaleNotificationObserver.h"
#import "Pastelog.h"
#import "PropertyListPreferences.h"
#import "PushManager.h"
#import "RegistrationViewController.h"
#import "Release.h"
@ -95,7 +95,7 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
loggingIsEnabled = TRUE;
[DebugLogger.sharedLogger enableTTYLogging];
#elif RELEASE
loggingIsEnabled = PropertyListPreferences.loggingIsEnabled;
loggingIsEnabled = OWSPreferences.loggingIsEnabled;
#endif
if (loggingIsEnabled) {
[DebugLogger.sharedLogger enableFileLogging];

View File

@ -13,14 +13,14 @@ class AccountManager: NSObject {
let TAG = "[AccountManager]"
let textSecureAccountManager: TSAccountManager
let networkManager: TSNetworkManager
let preferences: PropertyListPreferences
let preferences: OWSPreferences
var pushManager: PushManager {
// dependency injection hack since PushManager has *alot* of dependencies, and would induce a cycle.
return PushManager.shared()
}
required init(textSecureAccountManager: TSAccountManager, preferences: PropertyListPreferences) {
required init(textSecureAccountManager: TSAccountManager, preferences: OWSPreferences) {
self.networkManager = textSecureAccountManager.networkManager
self.textSecureAccountManager = textSecureAccountManager
self.preferences = preferences

View File

@ -10,16 +10,16 @@ class SyncPushTokensJob: NSObject {
let TAG = "[SyncPushTokensJob]"
let pushManager: PushManager
let accountManager: AccountManager
let preferences: PropertyListPreferences
let preferences: OWSPreferences
var uploadOnlyIfStale = true
required init(pushManager: PushManager, accountManager: AccountManager, preferences: PropertyListPreferences) {
required init(pushManager: PushManager, accountManager: AccountManager, preferences: OWSPreferences) {
self.pushManager = pushManager
self.accountManager = accountManager
self.preferences = preferences
}
class func run(pushManager: PushManager, accountManager: AccountManager, preferences: PropertyListPreferences) -> Promise<Void> {
class func run(pushManager: PushManager, accountManager: AccountManager, preferences: OWSPreferences) -> Promise<Void> {
let job = self.init(pushManager: pushManager, accountManager: accountManager, preferences: preferences)
return job.run()
}
@ -73,7 +73,7 @@ class SyncPushTokensJob: NSObject {
// MARK - objc wrappers, since objc can't use swift parameterized types
@objc class func run(pushManager: PushManager, accountManager: AccountManager, preferences: PropertyListPreferences) -> AnyPromise {
@objc class func run(pushManager: PushManager, accountManager: AccountManager, preferences: OWSPreferences) -> AnyPromise {
let promise: Promise<Void> = self.run(pushManager: pushManager, accountManager: accountManager, preferences: preferences)
return AnyPromise(promise)
}

View File

@ -22,13 +22,13 @@
#import "OWSLogger.h"
#import "OWSMessageEditing.h"
#import "OWSNavigationController.h"
#import "OWSPreferences.h"
#import "OWSProfileManager.h"
#import "OWSProgressView.h"
#import "OWSViewController.h"
#import "OWSWebRTCDataProtos.pb.h"
#import "PrivacySettingsTableViewController.h"
#import "ProfileViewController.h"
#import "PropertyListPreferences.h"
#import "PushManager.h"
#import "Release.h"
#import "TSMessageAdapter.h"

View File

@ -7,8 +7,8 @@
#import "DomainFrontingCountryViewController.h"
#import "Environment.h"
#import "OWSCountryMetadata.h"
#import "OWSPreferences.h"
#import "Pastelog.h"
#import "PropertyListPreferences.h"
#import "PushManager.h"
#import "Signal-Swift.h"
#import "TSAccountManager.h"
@ -90,12 +90,12 @@ NS_ASSUME_NONNULL_BEGIN
OWSTableSection *loggingSection = [OWSTableSection new];
loggingSection.headerTitle = NSLocalizedString(@"LOGGING_SECTION", nil);
[loggingSection addItem:[OWSTableItem switchItemWithText:NSLocalizedString(@"SETTINGS_ADVANCED_DEBUGLOG", @"")
isOn:[PropertyListPreferences loggingIsEnabled]
isOn:[OWSPreferences loggingIsEnabled]
target:weakSelf
selector:@selector(didToggleEnableLogSwitch:)]];
if ([PropertyListPreferences loggingIsEnabled]) {
if ([OWSPreferences loggingIsEnabled]) {
[loggingSection
addItem:[OWSTableItem actionItemWithText:NSLocalizedString(@"SETTINGS_ADVANCED_SUBMIT_DEBUGLOG", @"")
actionBlock:^{
@ -263,8 +263,8 @@ NS_ASSUME_NONNULL_BEGIN
} else {
[[DebugLogger sharedLogger] enableFileLogging];
}
[PropertyListPreferences setLoggingEnabled:sender.isOn];
[OWSPreferences setLoggingEnabled:sender.isOn];
[self updateTableContents];
}

View File

@ -13,7 +13,6 @@
#import "OWSNavigationController.h"
#import "PrivacySettingsTableViewController.h"
#import "ProfileViewController.h"
#import "PropertyListPreferences.h"
#import "PushManager.h"
#import "Signal-Swift.h"
#import "UIUtil.h"

View File

@ -32,7 +32,6 @@
#import "OWSOutgoingMessageCollectionViewCell.h"
#import "OWSSystemMessageCell.h"
#import "OWSUnreadIndicatorCell.h"
#import "PropertyListPreferences.h"
#import "Signal-Swift.h"
#import "SignalKeyingStorage.h"
#import "TSAttachmentPointer.h"

View File

@ -13,7 +13,6 @@
#import "OWSNavigationController.h"
#import "OWSProfileManager.h"
#import "ProfileViewController.h"
#import "PropertyListPreferences.h"
#import "PushManager.h"
#import "Signal-Swift.h"
#import "TSAccountManager.h"

View File

@ -4,7 +4,6 @@
#import "NotificationSettingsOptionsViewController.h"
#import "Environment.h"
#import "PropertyListPreferences.h"
@implementation NotificationSettingsOptionsViewController
@ -23,7 +22,7 @@
OWSTableSection *section = [OWSTableSection new];
section.footerTitle = NSLocalizedString(@"NOTIFICATIONS_FOOTER_WARNING", nil);
PropertyListPreferences *prefs = [Environment preferences];
OWSPreferences *prefs = [Environment preferences];
NotificationType selectedNotifType = [prefs notificationPreviewType];
for (NSNumber *option in
@[ @(NotificationNamePreview), @(NotificationNameNoPreview), @(NotificationNoNameNoPreview) ]) {

View File

@ -5,7 +5,7 @@
#import "NotificationSettingsViewController.h"
#import "Environment.h"
#import "NotificationSettingsOptionsViewController.h"
#import "PropertyListPreferences.h"
#import "OWSPreferences.h"
@implementation NotificationSettingsViewController
@ -29,7 +29,7 @@
__weak NotificationSettingsViewController *weakSelf = self;
PropertyListPreferences *prefs = [Environment preferences];
OWSPreferences *prefs = [Environment preferences];
OWSTableSection *backgroundSection = [OWSTableSection new];
backgroundSection.headerTitle = NSLocalizedString(@"NOTIFICATIONS_SECTION_BACKGROUND", nil);

View File

@ -3,9 +3,9 @@
//
#import "PrivacySettingsTableViewController.h"
#import "OWSPreferences.h"
#import "BlockListViewController.h"
#import "Environment.h"
#import "PropertyListPreferences.h"
#import "Signal-Swift.h"
NS_ASSUME_NONNULL_BEGIN

View File

@ -2,10 +2,10 @@
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "PropertyListPreferences.h"
#import "OWSPreferences.h"
#import "TSGroupModel.h"
#import "TSStorageHeaders.h"
#import <Foundation/Foundation.h>
/**
*
@ -46,7 +46,7 @@
@property (nonatomic, readonly) TSNetworkManager *networkManager;
@property (nonatomic, readonly) NotificationsManager *notificationsManager;
@property (nonatomic, readonly) OWSMessageSender *messageSender;
@property (nonatomic, readonly) PropertyListPreferences *preferences;
@property (nonatomic, readonly) OWSPreferences *preferences;
@property (nonatomic, readonly) HomeViewController *homeViewController;
@ -55,7 +55,7 @@
+ (Environment *)getCurrent;
+ (void)setCurrent:(Environment *)curEnvironment;
+ (PropertyListPreferences *)preferences;
+ (OWSPreferences *)preferences;
+ (void)resetAppData;

View File

@ -154,18 +154,18 @@ static Environment *environment = nil;
return _notificationsManager;
}
+ (PropertyListPreferences *)preferences
+ (OWSPreferences *)preferences
{
OWSAssert([Environment getCurrent] != nil);
OWSAssert([Environment getCurrent].preferences != nil);
return [Environment getCurrent].preferences;
}
- (PropertyListPreferences *)preferences
- (OWSPreferences *)preferences
{
@synchronized (self) {
if (!_preferences) {
_preferences = [PropertyListPreferences new];
_preferences = [OWSPreferences new];
}
}

View File

@ -5,7 +5,7 @@
#import "OWS102MoveLoggingPreferenceToUserDefaults.h"
#import "DebugLogger.h"
#import "Environment.h"
#import "PropertyListPreferences.h"
#import "OWSPreferences.h"
// Increment a similar constant for every future DBMigration
static NSString *const OWS102MoveLoggingPreferenceToUserDefaultsMigrationId = @"102";
@ -22,12 +22,12 @@ static NSString *const OWS102MoveLoggingPreferenceToUserDefaultsMigrationId = @"
DDLogWarn(@"[OWS102MoveLoggingPreferenceToUserDefaultsMigrationId] copying existing logging preference to "
@"NSUserDefaults");
NSNumber *existingValue = [transaction objectForKey:PropertyListPreferencesKeyEnableDebugLog
inCollection:PropertyListPreferencesSignalDatabaseCollection];
NSNumber *existingValue =
[transaction objectForKey:OWSPreferencesKeyEnableDebugLog inCollection:OWSPreferencesSignalDatabaseCollection];
if (existingValue) {
DDLogInfo(@"%@ assigning existing value: %@", self.tag, existingValue);
[PropertyListPreferences setLoggingEnabled:[existingValue boolValue]];
[OWSPreferences setLoggingEnabled:[existingValue boolValue]];
if (![existingValue boolValue]) {
DDLogInfo(@"%@ Disabling file logger after one-time log settings migration.", self.tag);

View File

@ -11,7 +11,7 @@ NS_ASSUME_NONNULL_BEGIN
@class TSContactThread;
@class OWSContactsManager;
@class SignalCall;
@class PropertyListPreferences;
@class OWSPreferences;
@interface NotificationsManager : NSObject <NotificationsProtocol, OWSCallNotificationsAdaptee>

View File

@ -5,7 +5,7 @@
#import "NotificationsManager.h"
#import "Environment.h"
#import "OWSContactsManager.h"
#import "PropertyListPreferences.h"
#import "OWSPreferences.h"
#import "PushManager.h"
#import "Signal-Swift.h"
#import <AudioToolbox/AudioServices.h>
@ -373,7 +373,7 @@ NSString *const kNotificationsManagerNewMesssageSoundName = @"NewMessage.aifc";
- (NotificationType)notificationPreviewType
{
PropertyListPreferences *prefs = [Environment getCurrent].preferences;
OWSPreferences *prefs = [Environment getCurrent].preferences;
return prefs.notificationPreviewType;
}

View File

@ -14,10 +14,10 @@ typedef NS_ENUM(NSUInteger, NotificationType) {
};
// Used when migrating logging to NSUserDefaults.
extern NSString *const PropertyListPreferencesSignalDatabaseCollection;
extern NSString *const PropertyListPreferencesKeyEnableDebugLog;
extern NSString *const OWSPreferencesSignalDatabaseCollection;
extern NSString *const OWSPreferencesKeyEnableDebugLog;
@interface PropertyListPreferences : NSObject
@interface OWSPreferences : NSObject
#pragma mark - Helpers

View File

@ -0,0 +1,306 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import "OWSPreferences.h"
#import "TSStorageHeaders.h"
NS_ASSUME_NONNULL_BEGIN
double const OWSPreferencesDefaultCallStreamDESBufferLevel = 0.5;
NSString *const OWSPreferencesSignalDatabaseCollection = @"SignalPreferences";
NSString *const OWSPreferencesKeyCallStreamDESBufferLevel = @"CallStreamDesiredBufferLevel";
NSString *const OWSPreferencesKeyScreenSecurity = @"Screen Security Key";
NSString *const OWSPreferencesKeyEnableDebugLog = @"Debugging Log Enabled Key";
NSString *const OWSPreferencesKeyNotificationPreviewType = @"Notification Preview Type Key";
NSString *const OWSPreferencesKeyHasSentAMessage = @"User has sent a message";
NSString *const OWSPreferencesKeyHasArchivedAMessage = @"User archived a message";
NSString *const OWSPreferencesKeyPlaySoundInForeground = @"NotificationSoundInForeground";
NSString *const OWSPreferencesKeyHasRegisteredVoipPush = @"VOIPPushEnabled";
NSString *const OWSPreferencesKeyLastRecordedPushToken = @"LastRecordedPushToken";
NSString *const OWSPreferencesKeyLastRecordedVoipToken = @"LastRecordedVoipToken";
NSString *const OWSPreferencesKeyCallKitEnabled = @"CallKitEnabled";
NSString *const OWSPreferencesKeyCallKitPrivacyEnabled = @"CallKitPrivacyEnabled";
NSString *const OWSPreferencesKeyCallsHideIPAddress = @"CallsHideIPAddress";
NSString *const OWSPreferencesKeyHasDeclinedNoContactsView = @"hasDeclinedNoContactsView";
NSString *const OWSPreferencesKeyIOSUpgradeNagVersion = @"iOSUpgradeNagVersion";
@implementation OWSPreferences
- (instancetype)init
{
self = [super init];
if (!self) {
return self;
}
OWSSingletonAssert();
return self;
}
#pragma mark - Helpers
- (void)clear {
@synchronized(self) {
NSString *appDomain = NSBundle.mainBundle.bundleIdentifier;
[NSUserDefaults.standardUserDefaults removePersistentDomainForName:appDomain];
}
}
- (nullable id)tryGetValueForKey:(NSString *)key
{
ows_require(key != nil);
return [TSStorageManager.sharedManager objectForKey:key inCollection:OWSPreferencesSignalDatabaseCollection];
}
- (void)setValueForKey:(NSString *)key toValue:(nullable id)value
{
ows_require(key != nil);
[TSStorageManager.sharedManager setObject:value forKey:key inCollection:OWSPreferencesSignalDatabaseCollection];
}
#pragma mark - Specific Preferences
- (NSTimeInterval)getCachedOrDefaultDesiredBufferDepth
{
id v = [self tryGetValueForKey:OWSPreferencesKeyCallStreamDESBufferLevel];
if (v == nil)
return OWSPreferencesDefaultCallStreamDESBufferLevel;
return [v doubleValue];
}
- (void)setCachedDesiredBufferDepth:(double)value
{
ows_require(value >= 0);
[self setValueForKey:OWSPreferencesKeyCallStreamDESBufferLevel toValue:@(value)];
}
- (BOOL)screenSecurityIsEnabled
{
NSNumber *preference = [self tryGetValueForKey:OWSPreferencesKeyScreenSecurity];
return preference ? [preference boolValue] : YES;
}
- (BOOL)getHasSentAMessage
{
NSNumber *preference = [self tryGetValueForKey:OWSPreferencesKeyHasSentAMessage];
if (preference) {
return [preference boolValue];
} else {
return NO;
}
}
- (BOOL)getHasArchivedAMessage
{
NSNumber *preference = [self tryGetValueForKey:OWSPreferencesKeyHasArchivedAMessage];
if (preference) {
return [preference boolValue];
} else {
return NO;
}
}
- (BOOL)hasRegisteredVOIPPush
{
NSNumber *preference = [self tryGetValueForKey:OWSPreferencesKeyHasRegisteredVoipPush];
if (preference) {
return [preference boolValue];
} else {
return YES;
}
}
- (void)setScreenSecurity:(BOOL)flag
{
[self setValueForKey:OWSPreferencesKeyScreenSecurity toValue:@(flag)];
}
- (void)setHasRegisteredVOIPPush:(BOOL)enabled
{
[self setValueForKey:OWSPreferencesKeyHasRegisteredVoipPush toValue:@(enabled)];
}
+ (BOOL)loggingIsEnabled
{
NSNumber *preference = [NSUserDefaults.standardUserDefaults objectForKey:OWSPreferencesKeyEnableDebugLog];
if (preference) {
return [preference boolValue];
} else {
return YES;
}
}
+ (void)setLoggingEnabled:(BOOL)flag
{
// Logging preferences are stored in UserDefaults instead of the database, so that we can (optionally) start
// logging before the database is initialized. This is important because sometimes there are problems *with* the
// database initialization, and without logging it would be hard to track down.
[NSUserDefaults.standardUserDefaults setObject:@(flag) forKey:OWSPreferencesKeyEnableDebugLog];
[NSUserDefaults.standardUserDefaults synchronize];
}
- (void)setHasSentAMessage:(BOOL)enabled
{
[self setValueForKey:OWSPreferencesKeyHasSentAMessage toValue:@(enabled)];
}
- (void)setHasArchivedAMessage:(BOOL)enabled
{
[self setValueForKey:OWSPreferencesKeyHasArchivedAMessage toValue:@(enabled)];
}
- (BOOL)hasDeclinedNoContactsView
{
NSNumber *preference = [self tryGetValueForKey:OWSPreferencesKeyHasDeclinedNoContactsView];
// Default to NO.
return preference ? [preference boolValue] : NO;
}
- (void)setHasDeclinedNoContactsView:(BOOL)value
{
[self setValueForKey:OWSPreferencesKeyHasDeclinedNoContactsView toValue:@(value)];
}
- (void)setIOSUpgradeNagVersion:(NSString *)value
{
[self setValueForKey:OWSPreferencesKeyIOSUpgradeNagVersion toValue:value];
}
- (nullable NSString *)iOSUpgradeNagVersion
{
return [self tryGetValueForKey:OWSPreferencesKeyIOSUpgradeNagVersion];
}
#pragma mark - Calling
#pragma mark CallKit
- (BOOL)isCallKitEnabled
{
NSNumber *preference = [self tryGetValueForKey:OWSPreferencesKeyCallKitEnabled];
return preference ? [preference boolValue] : YES;
}
- (void)setIsCallKitEnabled:(BOOL)flag
{
[self setValueForKey:OWSPreferencesKeyCallKitEnabled toValue:@(flag)];
}
- (BOOL)isCallKitEnabledSet
{
NSNumber *preference = [self tryGetValueForKey:OWSPreferencesKeyCallKitEnabled];
return preference != nil;
}
- (BOOL)isCallKitPrivacyEnabled
{
NSNumber *preference = [self tryGetValueForKey:OWSPreferencesKeyCallKitPrivacyEnabled];
return preference ? [preference boolValue] : YES;
}
- (void)setIsCallKitPrivacyEnabled:(BOOL)flag
{
[self setValueForKey:OWSPreferencesKeyCallKitPrivacyEnabled toValue:@(flag)];
}
- (BOOL)isCallKitPrivacySet
{
NSNumber *preference = [self tryGetValueForKey:OWSPreferencesKeyCallKitPrivacyEnabled];
return preference != nil;
}
#pragma mark direct call connectivity (non-TURN)
// Allow callers to connect directly, when desirable, vs. enforcing TURN only proxy connectivity
- (BOOL)doCallsHideIPAddress
{
NSNumber *preference = [self tryGetValueForKey:OWSPreferencesKeyCallsHideIPAddress];
return preference ? [preference boolValue] : NO;
}
- (void)setDoCallsHideIPAddress:(BOOL)flag
{
[self setValueForKey:OWSPreferencesKeyCallsHideIPAddress toValue:@(flag)];
}
#pragma mark Notification Preferences
- (BOOL)soundInForeground
{
NSNumber *preference = [self tryGetValueForKey:OWSPreferencesKeyPlaySoundInForeground];
if (preference) {
return [preference boolValue];
} else {
return YES;
}
}
- (void)setSoundInForeground:(BOOL)enabled
{
[self setValueForKey:OWSPreferencesKeyPlaySoundInForeground toValue:@(enabled)];
}
- (void)setNotificationPreviewType:(NotificationType)type
{
[self setValueForKey:OWSPreferencesKeyNotificationPreviewType toValue:@(type)];
}
- (NotificationType)notificationPreviewType
{
NSNumber *preference = [self tryGetValueForKey:OWSPreferencesKeyNotificationPreviewType];
if (preference) {
return [preference unsignedIntegerValue];
} else {
return NotificationNamePreview;
}
}
- (NSString *)nameForNotificationPreviewType:(NotificationType)notificationType
{
switch (notificationType) {
case NotificationNamePreview:
return NSLocalizedString(@"NOTIFICATIONS_SENDER_AND_MESSAGE", nil);
case NotificationNameNoPreview:
return NSLocalizedString(@"NOTIFICATIONS_SENDER_ONLY", nil);
case NotificationNoNameNoPreview:
return NSLocalizedString(@"NOTIFICATIONS_NONE", nil);
default:
DDLogWarn(@"Undefined NotificationType in Settings");
return @"";
}
}
#pragma mark - Push Tokens
- (void)setPushToken:(NSString *)value
{
[self setValueForKey:OWSPreferencesKeyLastRecordedPushToken toValue:value];
}
- (nullable NSString *)getPushToken
{
return [self tryGetValueForKey:OWSPreferencesKeyLastRecordedPushToken];
}
- (void)setVoipToken:(NSString *)value
{
[self setValueForKey:OWSPreferencesKeyLastRecordedVoipToken toValue:value];
}
- (nullable NSString *)getVoipToken
{
return [self tryGetValueForKey:OWSPreferencesKeyLastRecordedVoipToken];
}
@end
NS_ASSUME_NONNULL_END

View File

@ -1,309 +0,0 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import "PropertyListPreferences.h"
#import "TSStorageHeaders.h"
NS_ASSUME_NONNULL_BEGIN
double const PropertyListPreferencesDefaultCallStreamDESBufferLevel = 0.5;
NSString *const PropertyListPreferencesSignalDatabaseCollection = @"SignalPreferences";
NSString *const PropertyListPreferencesKeyCallStreamDESBufferLevel = @"CallStreamDesiredBufferLevel";
NSString *const PropertyListPreferencesKeyScreenSecurity = @"Screen Security Key";
NSString *const PropertyListPreferencesKeyEnableDebugLog = @"Debugging Log Enabled Key";
NSString *const PropertyListPreferencesKeyNotificationPreviewType = @"Notification Preview Type Key";
NSString *const PropertyListPreferencesKeyHasSentAMessage = @"User has sent a message";
NSString *const PropertyListPreferencesKeyHasArchivedAMessage = @"User archived a message";
NSString *const PropertyListPreferencesKeyPlaySoundInForeground = @"NotificationSoundInForeground";
NSString *const PropertyListPreferencesKeyHasRegisteredVoipPush = @"VOIPPushEnabled";
NSString *const PropertyListPreferencesKeyLastRecordedPushToken = @"LastRecordedPushToken";
NSString *const PropertyListPreferencesKeyLastRecordedVoipToken = @"LastRecordedVoipToken";
NSString *const PropertyListPreferencesKeyCallKitEnabled = @"CallKitEnabled";
NSString *const PropertyListPreferencesKeyCallKitPrivacyEnabled = @"CallKitPrivacyEnabled";
NSString *const PropertyListPreferencesKeyCallsHideIPAddress = @"CallsHideIPAddress";
NSString *const PropertyListPreferencesKeyHasDeclinedNoContactsView = @"hasDeclinedNoContactsView";
NSString *const PropertyListPreferencesKeyIOSUpgradeNagVersion = @"iOSUpgradeNagVersion";
@implementation PropertyListPreferences
- (instancetype)init
{
self = [super init];
if (!self) {
return self;
}
OWSSingletonAssert();
return self;
}
#pragma mark - Helpers
- (void)clear {
@synchronized(self) {
NSString *appDomain = NSBundle.mainBundle.bundleIdentifier;
[NSUserDefaults.standardUserDefaults removePersistentDomainForName:appDomain];
}
}
- (nullable id)tryGetValueForKey:(NSString *)key
{
ows_require(key != nil);
return
[TSStorageManager.sharedManager objectForKey:key inCollection:PropertyListPreferencesSignalDatabaseCollection];
}
- (void)setValueForKey:(NSString *)key toValue:(nullable id)value
{
ows_require(key != nil);
[TSStorageManager.sharedManager setObject:value
forKey:key
inCollection:PropertyListPreferencesSignalDatabaseCollection];
}
#pragma mark - Specific Preferences
- (NSTimeInterval)getCachedOrDefaultDesiredBufferDepth
{
id v = [self tryGetValueForKey:PropertyListPreferencesKeyCallStreamDESBufferLevel];
if (v == nil)
return PropertyListPreferencesDefaultCallStreamDESBufferLevel;
return [v doubleValue];
}
- (void)setCachedDesiredBufferDepth:(double)value
{
ows_require(value >= 0);
[self setValueForKey:PropertyListPreferencesKeyCallStreamDESBufferLevel toValue:@(value)];
}
- (BOOL)screenSecurityIsEnabled
{
NSNumber *preference = [self tryGetValueForKey:PropertyListPreferencesKeyScreenSecurity];
return preference ? [preference boolValue] : YES;
}
- (BOOL)getHasSentAMessage
{
NSNumber *preference = [self tryGetValueForKey:PropertyListPreferencesKeyHasSentAMessage];
if (preference) {
return [preference boolValue];
} else {
return NO;
}
}
- (BOOL)getHasArchivedAMessage
{
NSNumber *preference = [self tryGetValueForKey:PropertyListPreferencesKeyHasArchivedAMessage];
if (preference) {
return [preference boolValue];
} else {
return NO;
}
}
- (BOOL)hasRegisteredVOIPPush
{
NSNumber *preference = [self tryGetValueForKey:PropertyListPreferencesKeyHasRegisteredVoipPush];
if (preference) {
return [preference boolValue];
} else {
return YES;
}
}
- (void)setScreenSecurity:(BOOL)flag
{
[self setValueForKey:PropertyListPreferencesKeyScreenSecurity toValue:@(flag)];
}
- (void)setHasRegisteredVOIPPush:(BOOL)enabled
{
[self setValueForKey:PropertyListPreferencesKeyHasRegisteredVoipPush toValue:@(enabled)];
}
+ (BOOL)loggingIsEnabled
{
NSNumber *preference = [NSUserDefaults.standardUserDefaults objectForKey:PropertyListPreferencesKeyEnableDebugLog];
if (preference) {
return [preference boolValue];
} else {
return YES;
}
}
+ (void)setLoggingEnabled:(BOOL)flag
{
// Logging preferences are stored in UserDefaults instead of the database, so that we can (optionally) start
// logging before the database is initialized. This is important because sometimes there are problems *with* the
// database initialization, and without logging it would be hard to track down.
[NSUserDefaults.standardUserDefaults setObject:@(flag) forKey:PropertyListPreferencesKeyEnableDebugLog];
[NSUserDefaults.standardUserDefaults synchronize];
}
- (void)setHasSentAMessage:(BOOL)enabled
{
[self setValueForKey:PropertyListPreferencesKeyHasSentAMessage toValue:@(enabled)];
}
- (void)setHasArchivedAMessage:(BOOL)enabled
{
[self setValueForKey:PropertyListPreferencesKeyHasArchivedAMessage toValue:@(enabled)];
}
- (BOOL)hasDeclinedNoContactsView
{
NSNumber *preference = [self tryGetValueForKey:PropertyListPreferencesKeyHasDeclinedNoContactsView];
// Default to NO.
return preference ? [preference boolValue] : NO;
}
- (void)setHasDeclinedNoContactsView:(BOOL)value
{
[self setValueForKey:PropertyListPreferencesKeyHasDeclinedNoContactsView toValue:@(value)];
}
- (void)setIOSUpgradeNagVersion:(NSString *)value
{
[self setValueForKey:PropertyListPreferencesKeyIOSUpgradeNagVersion toValue:value];
}
- (nullable NSString *)iOSUpgradeNagVersion
{
return [self tryGetValueForKey:PropertyListPreferencesKeyIOSUpgradeNagVersion];
}
#pragma mark - Calling
#pragma mark CallKit
- (BOOL)isCallKitEnabled
{
NSNumber *preference = [self tryGetValueForKey:PropertyListPreferencesKeyCallKitEnabled];
return preference ? [preference boolValue] : YES;
}
- (void)setIsCallKitEnabled:(BOOL)flag
{
[self setValueForKey:PropertyListPreferencesKeyCallKitEnabled toValue:@(flag)];
}
- (BOOL)isCallKitEnabledSet
{
NSNumber *preference = [self tryGetValueForKey:PropertyListPreferencesKeyCallKitEnabled];
return preference != nil;
}
- (BOOL)isCallKitPrivacyEnabled
{
NSNumber *preference = [self tryGetValueForKey:PropertyListPreferencesKeyCallKitPrivacyEnabled];
return preference ? [preference boolValue] : YES;
}
- (void)setIsCallKitPrivacyEnabled:(BOOL)flag
{
[self setValueForKey:PropertyListPreferencesKeyCallKitPrivacyEnabled toValue:@(flag)];
}
- (BOOL)isCallKitPrivacySet
{
NSNumber *preference = [self tryGetValueForKey:PropertyListPreferencesKeyCallKitPrivacyEnabled];
return preference != nil;
}
#pragma mark direct call connectivity (non-TURN)
// Allow callers to connect directly, when desirable, vs. enforcing TURN only proxy connectivity
- (BOOL)doCallsHideIPAddress
{
NSNumber *preference = [self tryGetValueForKey:PropertyListPreferencesKeyCallsHideIPAddress];
return preference ? [preference boolValue] : NO;
}
- (void)setDoCallsHideIPAddress:(BOOL)flag
{
[self setValueForKey:PropertyListPreferencesKeyCallsHideIPAddress toValue:@(flag)];
}
#pragma mark Notification Preferences
- (BOOL)soundInForeground
{
NSNumber *preference = [self tryGetValueForKey:PropertyListPreferencesKeyPlaySoundInForeground];
if (preference) {
return [preference boolValue];
} else {
return YES;
}
}
- (void)setSoundInForeground:(BOOL)enabled
{
[self setValueForKey:PropertyListPreferencesKeyPlaySoundInForeground toValue:@(enabled)];
}
- (void)setNotificationPreviewType:(NotificationType)type
{
[self setValueForKey:PropertyListPreferencesKeyNotificationPreviewType toValue:@(type)];
}
- (NotificationType)notificationPreviewType
{
NSNumber *preference = [self tryGetValueForKey:PropertyListPreferencesKeyNotificationPreviewType];
if (preference) {
return [preference unsignedIntegerValue];
} else {
return NotificationNamePreview;
}
}
- (NSString *)nameForNotificationPreviewType:(NotificationType)notificationType
{
switch (notificationType) {
case NotificationNamePreview:
return NSLocalizedString(@"NOTIFICATIONS_SENDER_AND_MESSAGE", nil);
case NotificationNameNoPreview:
return NSLocalizedString(@"NOTIFICATIONS_SENDER_ONLY", nil);
case NotificationNoNameNoPreview:
return NSLocalizedString(@"NOTIFICATIONS_NONE", nil);
default:
DDLogWarn(@"Undefined NotificationType in Settings");
return @"";
}
}
#pragma mark - Push Tokens
- (void)setPushToken:(NSString *)value
{
[self setValueForKey:PropertyListPreferencesKeyLastRecordedPushToken toValue:value];
}
- (nullable NSString *)getPushToken
{
return [self tryGetValueForKey:PropertyListPreferencesKeyLastRecordedPushToken];
}
- (void)setVoipToken:(NSString *)value
{
[self setValueForKey:PropertyListPreferencesKeyLastRecordedVoipToken toValue:value];
}
- (nullable NSString *)getVoipToken
{
return [self tryGetValueForKey:PropertyListPreferencesKeyLastRecordedVoipToken];
}
@end
NS_ASSUME_NONNULL_END

View File

@ -7,7 +7,6 @@
#import "Environment.h"
#import "LockInteractionController.h"
#import "OWSDatabaseMigrationRunner.h"
#import "PropertyListPreferences.h"
#import "PushManager.h"
#import "SignalKeyingStorage.h"
#import "TSAccountManager.h"

View File

@ -6,7 +6,6 @@
#import "AppDelegate.h"
#import "NSData+ows_StripToken.h"
#import "OWSContactsManager.h"
#import "PropertyListPreferences.h"
#import "Signal-Swift.h"
#import "ThreadUtil.h"
#import <SignalServiceKit/NSDate+millisecondTimeStamp.h>

View File

@ -43,7 +43,7 @@ class TokenObtainingTSAccountManager: VerifyingTSAccountManager {
class AccountManagerTest: XCTestCase {
let tsAccountManager = FailingTSAccountManager(networkManager: TSNetworkManager.shared(), storageManager: TSStorageManager.shared())
var preferences = PropertyListPreferences()
var preferences = OWSPreferences()
func testRegisterWhenEmptyCode() {
let accountManager = AccountManager(textSecureAccountManager: tsAccountManager, preferences: self.preferences)