diff --git a/Signal.xcodeproj/project.pbxproj b/Signal.xcodeproj/project.pbxproj index 34b462877..99e04856b 100644 --- a/Signal.xcodeproj/project.pbxproj +++ b/Signal.xcodeproj/project.pbxproj @@ -303,6 +303,8 @@ 458E38371D668EBF0094BD24 /* OWSDeviceProvisioningURLParser.m in Sources */ = {isa = PBXBuildFile; fileRef = 458E38361D668EBF0094BD24 /* OWSDeviceProvisioningURLParser.m */; }; 458E383A1D6699FA0094BD24 /* OWSDeviceProvisioningURLParserTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 458E38391D6699FA0094BD24 /* OWSDeviceProvisioningURLParserTest.m */; }; 459311FC1D75C948008DD4F0 /* OWSDeviceTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 459311FB1D75C948008DD4F0 /* OWSDeviceTableViewCell.m */; }; + 4598198E204E2F28009414F2 /* OWS108CallLoggingPreference.h in Headers */ = {isa = PBXBuildFile; fileRef = 4598198C204E2F28009414F2 /* OWS108CallLoggingPreference.h */; }; + 4598198F204E2F28009414F2 /* OWS108CallLoggingPreference.m in Sources */ = {isa = PBXBuildFile; fileRef = 4598198D204E2F28009414F2 /* OWS108CallLoggingPreference.m */; }; 45A2F005204473A3002E978A /* NewMessage.aifc in Resources */ = {isa = PBXBuildFile; fileRef = 45A2F004204473A3002E978A /* NewMessage.aifc */; }; 45A663C51F92EC760027B59E /* GroupTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45A663C41F92EC760027B59E /* GroupTableViewCell.swift */; }; 45A6DAD61EBBF85500893231 /* ReminderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45A6DAD51EBBF85500893231 /* ReminderView.swift */; }; @@ -878,6 +880,8 @@ 459311FB1D75C948008DD4F0 /* OWSDeviceTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSDeviceTableViewCell.m; sourceTree = ""; }; 4597E94E1D8313C100040CDE /* sq */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = sq; path = translations/sq.lproj/Localizable.strings; sourceTree = ""; }; 4597E94F1D8313CB00040CDE /* bg */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = bg; path = translations/bg.lproj/Localizable.strings; sourceTree = ""; }; + 4598198C204E2F28009414F2 /* OWS108CallLoggingPreference.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OWS108CallLoggingPreference.h; sourceTree = ""; }; + 4598198D204E2F28009414F2 /* OWS108CallLoggingPreference.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OWS108CallLoggingPreference.m; sourceTree = ""; }; 45A2F004204473A3002E978A /* NewMessage.aifc */ = {isa = PBXFileReference; lastKnownFileType = file; name = NewMessage.aifc; path = Signal/AudioFiles/NewMessage.aifc; sourceTree = SOURCE_ROOT; }; 45A663C41F92EC760027B59E /* GroupTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GroupTableViewCell.swift; sourceTree = ""; }; 45A6DAD51EBBF85500893231 /* ReminderView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ReminderView.swift; sourceTree = ""; }; @@ -1346,6 +1350,8 @@ 346129F11FD5F31400532771 /* OWS106EnsureProfileComplete.swift */, 4503F1C2204711D200CEE724 /* OWS107LegacySounds.h */, 4503F1C1204711D200CEE724 /* OWS107LegacySounds.m */, + 4598198C204E2F28009414F2 /* OWS108CallLoggingPreference.h */, + 4598198D204E2F28009414F2 /* OWS108CallLoggingPreference.m */, 346129931FD1E30000532771 /* OWSDatabaseMigration.h */, 346129941FD1E30000532771 /* OWSDatabaseMigration.m */, 346129E51FD5C0C600532771 /* OWSDatabaseMigrationRunner.h */, @@ -2196,6 +2202,7 @@ 34480B611FD0A98800BC14EF /* UIColor+OWS.h in Headers */, 453518961FC63DBF00210559 /* SignalMessaging.h in Headers */, 3461295A1FD1D74C00532771 /* Environment.h in Headers */, + 4598198E204E2F28009414F2 /* OWS108CallLoggingPreference.h in Headers */, 34480B631FD0A98800BC14EF /* UIView+OWS.h in Headers */, 451F8A4B1FD715E1005CB9DA /* OWSGroupAvatarBuilder.h in Headers */, 347850721FDAEB17007B8332 /* OWSUserProfile.h in Headers */, @@ -2979,6 +2986,7 @@ 451F8A481FD715BA005CB9DA /* OWSContactAvatarBuilder.m in Sources */, 4503F1C3204711D300CEE724 /* OWS107LegacySounds.m in Sources */, 346129A61FD1F09100532771 /* OWSContactsManager.m in Sources */, + 4598198F204E2F28009414F2 /* OWS108CallLoggingPreference.m in Sources */, 346129D21FD2085A00532771 /* CommonStrings.swift in Sources */, 45F59A082028E4FB00E8D2B0 /* OWSAudioSession.swift in Sources */, 34612A071FD7238600532771 /* OWSContactsSyncing.m in Sources */, diff --git a/SignalMessaging/environment/migrations/OWS108CallLoggingPreference.h b/SignalMessaging/environment/migrations/OWS108CallLoggingPreference.h new file mode 100644 index 000000000..dce3b59e7 --- /dev/null +++ b/SignalMessaging/environment/migrations/OWS108CallLoggingPreference.h @@ -0,0 +1,13 @@ +// +// Copyright (c) 2018 Open Whisper Systems. All rights reserved. +// + +#import "OWSDatabaseMigration.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface OWS108CallLoggingPreference : OWSDatabaseMigration + +@end + +NS_ASSUME_NONNULL_END diff --git a/SignalMessaging/environment/migrations/OWS108CallLoggingPreference.m b/SignalMessaging/environment/migrations/OWS108CallLoggingPreference.m new file mode 100644 index 000000000..04552234f --- /dev/null +++ b/SignalMessaging/environment/migrations/OWS108CallLoggingPreference.m @@ -0,0 +1,31 @@ +// +// Copyright (c) 2018 Open Whisper Systems. All rights reserved. +// + +#import "OWS108CallLoggingPreference.h" +#import "Environment.h" +#import "OWSPreferences.h" +#import + +NS_ASSUME_NONNULL_BEGIN + +// Increment a similar constant for every future DBMigration +static NSString *const OWS108CallLoggingPreferenceId = @"108"; + +@implementation OWS108CallLoggingPreference + ++ (NSString *)migrationId +{ + return OWS108CallLoggingPreferenceId; +} + +- (void)runUpWithTransaction:(YapDatabaseReadWriteTransaction *)transaction +{ + OWSAssert(transaction); + + [[Environment preferences] applyCallLoggingSettingsForLegacyUsersWithTransaction:transaction]; +} + +@end + +NS_ASSUME_NONNULL_END diff --git a/SignalMessaging/utils/OWSPreferences.h b/SignalMessaging/utils/OWSPreferences.h index f68aeb28e..0f9369769 100644 --- a/SignalMessaging/utils/OWSPreferences.h +++ b/SignalMessaging/utils/OWSPreferences.h @@ -64,6 +64,8 @@ extern NSString *const OWSPreferencesKeyEnableDebugLog; #pragma mark - Legacy CallKit settings +- (void)applyCallLoggingSettingsForLegacyUsersWithTransaction:(YapDatabaseReadWriteTransaction *)transaction; + - (BOOL)isCallKitEnabled; - (void)setIsCallKitEnabled:(BOOL)flag; diff --git a/SignalMessaging/utils/OWSPreferences.m b/SignalMessaging/utils/OWSPreferences.m index afdda8394..312e033fd 100644 --- a/SignalMessaging/utils/OWSPreferences.m +++ b/SignalMessaging/utils/OWSPreferences.m @@ -7,6 +7,7 @@ #import #import #import +#import NS_ASSUME_NONNULL_BEGIN @@ -52,16 +53,35 @@ NSString *const OWSPreferencesKeySystemCallLogEnabled = @"OWSPreferencesKeySyste - (nullable id)tryGetValueForKey:(NSString *)key { OWSAssert(key != nil); - return [TSStorageManager.dbReadConnection objectForKey:key inCollection:OWSPreferencesSignalDatabaseCollection]; + + __block id result; + [TSStorageManager.dbReadConnection readWithBlock:^(YapDatabaseReadTransaction *_Nonnull transaction) { + result = [self tryGetValueForKey:key transaction:transaction]; + }]; + return result; +} + +- (nullable id)tryGetValueForKey:(NSString *)key transaction:(YapDatabaseReadTransaction *)transaction +{ + OWSAssert(key != nil); + return [transaction objectForKey:key inCollection:OWSPreferencesSignalDatabaseCollection]; } - (void)setValueForKey:(NSString *)key toValue:(nullable id)value +{ + [TSStorageManager.dbReadWriteConnection + readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) { + [self setValueForKey:key toValue:value transaction:transaction]; + }]; +} + +- (void)setValueForKey:(NSString *)key + toValue:(nullable id)value + transaction:(YapDatabaseReadWriteTransaction *)transaction { OWSAssert(key != nil); - [TSStorageManager.dbReadWriteConnection setObject:value - forKey:key - inCollection:OWSPreferencesSignalDatabaseCollection]; + [transaction setObject:value forKey:key inCollection:OWSPreferencesSignalDatabaseCollection]; } #pragma mark - Specific Preferences @@ -184,21 +204,7 @@ NSString *const OWSPreferencesKeySystemCallLogEnabled = @"OWSPreferencesKeySyste } NSNumber *preference = [self tryGetValueForKey:OWSPreferencesKeySystemCallLogEnabled]; - - if (preference) { - return preference.boolValue; - } else { - // For legacy users, who may have previously intentionally disabled CallKit because they - // didn't want their calls showing up in the call log, we want to disable call logging - NSNumber *callKitPreference = [self tryGetValueForKey:OWSPreferencesKeyCallKitEnabled]; - if (callKitPreference && !callKitPreference.boolValue) { - // user explicitly opted out of callKit, so disable system call logging. - return NO; - } - } - - // For everyone else, including new users, enable by default. - return YES; + return preference ? preference.boolValue : YES; } - (void)setIsSystemCallLogEnabled:(BOOL)flag @@ -224,11 +230,41 @@ NSString *const OWSPreferencesKeySystemCallLogEnabled = @"OWSPreferencesKeySyste // Therefore in versions of iOS after 11, we have no need of call privacy. #pragma mark Legacy CallKit +// Be a little conservative with system call logging with legacy users, even though it's +// not synced to iCloud, users could be concerned to suddenly see caller names in their +// recent calls list. +- (void)applyCallLoggingSettingsForLegacyUsersWithTransaction:(YapDatabaseReadWriteTransaction *)transaction +{ + NSNumber *_Nullable callKitPreference = + [self tryGetValueForKey:OWSPreferencesKeyCallKitEnabled transaction:transaction]; + BOOL wasUsingCallKit = callKitPreference ? [callKitPreference boolValue] : YES; + + NSNumber *_Nullable callKitPrivacyPreference = + [self tryGetValueForKey:OWSPreferencesKeyCallKitPrivacyEnabled transaction:transaction]; + BOOL wasUsingCallKitPrivacy = callKitPrivacyPreference ? callKitPrivacyPreference.boolValue : YES; + + BOOL shouldLogCallsInRecents = ^{ + if (wasUsingCallKit && !wasUsingCallKitPrivacy) { + // User was using CallKit and explicitly opted in to showing names/numbers, + // so it's OK to continue to show names/numbers in the system recents list. + return YES; + } else { + // User was not previously showing names/numbers in the system + // recents list, so don't opt them in. + return NO; + } + }(); + + [self setValueForKey:OWSPreferencesKeySystemCallLogEnabled + toValue:@(shouldLogCallsInRecents) + transaction:transaction]; +} + - (BOOL)isCallKitEnabled { if (@available(iOS 11, *)) { - OWSFail(@"%@ CallKit privacy is irrelevant for iOS11+", self.logTag); - return NO; + OWSFail(@"%@ CallKit is always enabled for iOS11+", self.logTag); + return YES; } NSNumber *preference = [self tryGetValueForKey:OWSPreferencesKeyCallKitEnabled]; @@ -238,7 +274,7 @@ NSString *const OWSPreferencesKeySystemCallLogEnabled = @"OWSPreferencesKeySyste - (void)setIsCallKitEnabled:(BOOL)flag { if (@available(iOS 11, *)) { - OWSFail(@"%@ CallKit privacy is irrelevant for iOS11+", self.logTag); + OWSFail(@"%@ CallKit is always enabled for iOS11+", self.logTag); return; } @@ -249,7 +285,7 @@ NSString *const OWSPreferencesKeySystemCallLogEnabled = @"OWSPreferencesKeySyste - (BOOL)isCallKitEnabledSet { if (@available(iOS 11, *)) { - OWSFail(@"%@ CallKit privacy is irrelevant for iOS11+", self.logTag); + OWSFail(@"%@ CallKit is always enabled for iOS11+", self.logTag); return NO; }