From fdd3c513caa77b44907c36feee0bc572fa1be49c Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Tue, 11 Aug 2020 11:25:26 -0300 Subject: [PATCH] Rework Groups v2 & CDS feature flags. --- Signal/src/Models/AccountManager.swift | 4 ++-- .../DebugUI/DebugUIMessages+OWS.swift | 4 ++-- .../ViewControllers/DebugUI/DebugUIStress.m | 2 +- .../ViewControllers/ProfileViewController.m | 2 +- .../RecipientPickerViewController.m | 4 ++-- SignalMessaging/profiles/OWSProfileManager.m | 2 +- .../src/Account/TSAccountManager.m | 2 +- SignalServiceKit/src/Contacts/SignalAccount.m | 2 +- .../src/Contacts/SignalServiceAddress.swift | 2 +- .../Network/API/Requests/OWSRequestFactory.m | 2 +- .../Network/API/SignalServiceProfile.swift | 2 +- .../src/Protos/Generated/SSKProto.swift | 20 +++++++++---------- .../Generated/StorageServiceProto.swift | 2 +- .../src/Security/OWSFingerprint.m | 2 +- .../src/TestUtils/TestProtocolRunner.swift | 4 ++-- SignalServiceKit/src/Util/FeatureFlags.swift | 12 +---------- .../src/Util/RemoteConfigManager.swift | 18 ++++++++++++++++- .../MessageProcessingIntegrationTest.swift | 2 +- 18 files changed, 47 insertions(+), 41 deletions(-) diff --git a/Signal/src/Models/AccountManager.swift b/Signal/src/Models/AccountManager.swift index 65af936e24..d3d0efc06e 100644 --- a/Signal/src/Models/AccountManager.swift +++ b/Signal/src/Models/AccountManager.swift @@ -149,7 +149,7 @@ public class AccountManager: NSObject { return firstly { self.registerForTextSecure(verificationCode: verificationCode, pin: pin, checkForAvailableTransfer: checkForAvailableTransfer) }.then { response -> Promise in - assert(!FeatureFlags.allowUUIDOnlyContacts || response.uuid != nil) + assert(!RemoteConfig.allowUUIDOnlyContacts || response.uuid != nil) self.tsAccountManager.uuidAwaitingVerification = response.uuid self.databaseStorage.write { transaction in @@ -469,7 +469,7 @@ public class AccountManager: NSObject { _ = self.ensureUuid().catch { error in // Until we're in a UUID-only world, don't require a // local UUID. - if FeatureFlags.allowUUIDOnlyContacts { + if RemoteConfig.allowUUIDOnlyContacts { owsFailDebug("error: \(error)") } Logger.warn("error: \(error)") diff --git a/Signal/src/ViewControllers/DebugUI/DebugUIMessages+OWS.swift b/Signal/src/ViewControllers/DebugUI/DebugUIMessages+OWS.swift index a461c4b467..f02a02840a 100644 --- a/Signal/src/ViewControllers/DebugUI/DebugUIMessages+OWS.swift +++ b/Signal/src/ViewControllers/DebugUI/DebugUIMessages+OWS.swift @@ -53,7 +53,7 @@ public extension DebugUIMessages { @objc class func receiveUUIDEnvelopeInNewThread() { - assert(FeatureFlags.allowUUIDOnlyContacts) + assert(RemoteConfig.allowUUIDOnlyContacts) let senderClient = FakeSignalClient.generate(e164Identifier: nil) let localClient = LocalSignalClient() @@ -74,7 +74,7 @@ public extension DebugUIMessages { @objc class func createUUIDGroup() { - assert(FeatureFlags.allowUUIDOnlyContacts) + assert(RemoteConfig.allowUUIDOnlyContacts) let uuidMembers = (0...3).map { _ in CommonGenerator.address(hasPhoneNumber: false) } let members = uuidMembers + [TSAccountManager.localAddress!] diff --git a/Signal/src/ViewControllers/DebugUI/DebugUIStress.m b/Signal/src/ViewControllers/DebugUI/DebugUIStress.m index db8a0958ec..d8b7713fe5 100644 --- a/Signal/src/ViewControllers/DebugUI/DebugUIStress.m +++ b/Signal/src/ViewControllers/DebugUI/DebugUIStress.m @@ -574,7 +574,7 @@ NS_ASSUME_NONNULL_BEGIN } [recipientAddresses addObject:self.tsAccountManager.localAddress]; - if (SSKFeatureFlags.allowUUIDOnlyContacts) { + if (RemoteConfig.allowUUIDOnlyContacts) { for (int i = 0; i < 3; i++) { [recipientAddresses addObject:[[SignalServiceAddress alloc] initWithUuid:[NSUUID UUID] phoneNumber:nil]]; } diff --git a/Signal/src/ViewControllers/ProfileViewController.m b/Signal/src/ViewControllers/ProfileViewController.m index e8c85cc84d..2a939a91b1 100644 --- a/Signal/src/ViewControllers/ProfileViewController.m +++ b/Signal/src/ViewControllers/ProfileViewController.m @@ -746,7 +746,7 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat case ProfileViewMode_Registration: return false; case ProfileViewMode_AppSettings: - return SSKFeatureFlags.usernames; + return RemoteConfig.usernames; } } diff --git a/Signal/src/ViewControllers/RecipientPicker/RecipientPickerViewController.m b/Signal/src/ViewControllers/RecipientPicker/RecipientPickerViewController.m index a3fcc8d9d8..43793e4689 100644 --- a/Signal/src/ViewControllers/RecipientPicker/RecipientPickerViewController.m +++ b/Signal/src/ViewControllers/RecipientPicker/RecipientPickerViewController.m @@ -138,7 +138,7 @@ const NSUInteger kMinimumSearchLength = 2; UISearchBar *searchBar = [OWSSearchBar new]; _searchBar = searchBar; searchBar.delegate = self; - if (SSKFeatureFlags.usernames) { + if (RemoteConfig.usernames) { searchBar.placeholder = NSLocalizedString(@"SEARCH_BY_NAME_OR_USERNAME_OR_NUMBER_PLACEHOLDER_TEXT", @"Placeholder text indicating the user can search for contacts by name, username, or phone number."); } else { @@ -825,7 +825,7 @@ const NSUInteger kMinimumSearchLength = 2; } // Username lookup - if (SSKFeatureFlags.usernames) { + if (RemoteConfig.usernames) { NSString *usernameMatch = self.searchText; NSString *_Nullable localUsername = self.profileManager.localUsername; diff --git a/SignalMessaging/profiles/OWSProfileManager.m b/SignalMessaging/profiles/OWSProfileManager.m index 5994d465d5..bcb612778d 100644 --- a/SignalMessaging/profiles/OWSProfileManager.m +++ b/SignalMessaging/profiles/OWSProfileManager.m @@ -639,7 +639,7 @@ const NSString *kNSNotificationKey_WasLocallyInitiated = @"kNSNotificationKey_Wa if (localUUID) { [whitelistedUUIDS removeObject:localUUID]; } else { - if (SSKFeatureFlags.allowUUIDOnlyContacts) { + if (RemoteConfig.allowUUIDOnlyContacts) { OWSFailDebug(@"Missing localUUID"); } } diff --git a/SignalServiceKit/src/Account/TSAccountManager.m b/SignalServiceKit/src/Account/TSAccountManager.m index ae017e36b3..e9af16c852 100644 --- a/SignalServiceKit/src/Account/TSAccountManager.m +++ b/SignalServiceKit/src/Account/TSAccountManager.m @@ -498,7 +498,7 @@ NSString *const TSAccountManager_DeviceId = @"TSAccountManager_DeviceId"; [self.keyValueStore setString:localNumber key:TSAccountManager_RegisteredNumberKey transaction:transaction]; if (localUuid == nil) { - OWSAssert(!SSKFeatureFlags.allowUUIDOnlyContacts); + OWSAssert(!RemoteConfig.allowUUIDOnlyContacts); } else { [self.keyValueStore setString:localUuid.UUIDString key:TSAccountManager_RegisteredUUIDKey diff --git a/SignalServiceKit/src/Contacts/SignalAccount.m b/SignalServiceKit/src/Contacts/SignalAccount.m index 49c1255572..461e72e0b2 100644 --- a/SignalServiceKit/src/Contacts/SignalAccount.m +++ b/SignalServiceKit/src/Contacts/SignalAccount.m @@ -114,7 +114,7 @@ NSUInteger const SignalAccountSchemaVersion = 1; } OWSAssertDebug(recipientPhoneNumber != nil || recipientUUID != nil); - OWSAssertDebug(recipientPhoneNumber != nil || SSKFeatureFlags.allowUUIDOnlyContacts); + OWSAssertDebug(recipientPhoneNumber != nil || RemoteConfig.allowUUIDOnlyContacts); _contact = contact; _contactAvatarHash = contactAvatarHash; diff --git a/SignalServiceKit/src/Contacts/SignalServiceAddress.swift b/SignalServiceKit/src/Contacts/SignalServiceAddress.swift index 7fa0b01079..f0502b1e06 100644 --- a/SignalServiceKit/src/Contacts/SignalServiceAddress.swift +++ b/SignalServiceKit/src/Contacts/SignalServiceAddress.swift @@ -273,7 +273,7 @@ public class SignalServiceAddress: NSObject, NSCopying, NSSecureCoding, Codable @objc public var serviceIdentifier: String? { - if FeatureFlags.allowUUIDOnlyContacts, + if RemoteConfig.allowUUIDOnlyContacts, uuid != nil { guard let uuidString = uuidString else { owsFailDebug("uuidString was unexpectedly nil") diff --git a/SignalServiceKit/src/Network/API/Requests/OWSRequestFactory.m b/SignalServiceKit/src/Network/API/Requests/OWSRequestFactory.m index 9b18783ea2..af520f50b1 100644 --- a/SignalServiceKit/src/Network/API/Requests/OWSRequestFactory.m +++ b/SignalServiceKit/src/Network/API/Requests/OWSRequestFactory.m @@ -498,7 +498,7 @@ NSString *const OWSRequestKey_AuthKey = @"AuthKey"; + (NSDictionary *)deviceCapabilities { NSMutableDictionary *capabilities = [NSMutableDictionary new]; - if (SSKFeatureFlags.uuidCapabilities) { + if (RemoteConfig.uuidCapabilities) { capabilities[@"uuid"] = @(YES); } if (RemoteConfig.groupsV2GoodCitizen) { diff --git a/SignalServiceKit/src/Network/API/SignalServiceProfile.swift b/SignalServiceKit/src/Network/API/SignalServiceProfile.swift index f228afad5d..b7a1971ebf 100644 --- a/SignalServiceKit/src/Network/API/SignalServiceProfile.swift +++ b/SignalServiceKit/src/Network/API/SignalServiceProfile.swift @@ -66,7 +66,7 @@ public class SignalServiceProfile: NSObject { if let value: Bool = try capabilities.optional(key: "uuid") { self.supportsUUID = value } else { - if FeatureFlags.uuidCapabilities { + if RemoteConfig.uuidCapabilities { owsFailDebug("Missing uuid capability.") } // The capability has been retired from the service. diff --git a/SignalServiceKit/src/Protos/Generated/SSKProto.swift b/SignalServiceKit/src/Protos/Generated/SSKProto.swift index 213790c7dd..710d97b5c0 100644 --- a/SignalServiceKit/src/Protos/Generated/SSKProto.swift +++ b/SignalServiceKit/src/Protos/Generated/SSKProto.swift @@ -348,7 +348,7 @@ public class SSKProtoEnvelope: NSObject, Codable { let phoneNumber: String? = { guard hasSourceE164 else { // Shouldn’t happen in prod yet - assert(FeatureFlags.allowUUIDOnlyContacts) + assert(RemoteConfig.allowUUIDOnlyContacts) return nil } @@ -2658,7 +2658,7 @@ public class SSKProtoDataMessageQuote: NSObject, Codable { let phoneNumber: String? = { guard hasAuthorE164 else { // Shouldn’t happen in prod yet - assert(FeatureFlags.allowUUIDOnlyContacts) + assert(RemoteConfig.allowUUIDOnlyContacts) return nil } @@ -4814,7 +4814,7 @@ public class SSKProtoDataMessageReaction: NSObject, Codable { let phoneNumber: String? = { guard hasAuthorE164 else { // Shouldn’t happen in prod yet - assert(FeatureFlags.allowUUIDOnlyContacts) + assert(RemoteConfig.allowUUIDOnlyContacts) return nil } @@ -6329,7 +6329,7 @@ public class SSKProtoVerified: NSObject, Codable { let phoneNumber: String? = { guard hasDestinationE164 else { // Shouldn’t happen in prod yet - assert(FeatureFlags.allowUUIDOnlyContacts) + assert(RemoteConfig.allowUUIDOnlyContacts) return nil } @@ -6558,7 +6558,7 @@ public class SSKProtoSyncMessageSentUnidentifiedDeliveryStatus: NSObject, Codabl let phoneNumber: String? = { guard hasDestinationE164 else { // Shouldn’t happen in prod yet - assert(FeatureFlags.allowUUIDOnlyContacts) + assert(RemoteConfig.allowUUIDOnlyContacts) return nil } @@ -6854,7 +6854,7 @@ public class SSKProtoSyncMessageSent: NSObject, Codable { let phoneNumber: String? = { guard hasDestinationE164 else { // Shouldn’t happen in prod yet - assert(FeatureFlags.allowUUIDOnlyContacts) + assert(RemoteConfig.allowUUIDOnlyContacts) return nil } @@ -7730,7 +7730,7 @@ public class SSKProtoSyncMessageRead: NSObject, Codable { let phoneNumber: String? = { guard hasSenderE164 else { // Shouldn’t happen in prod yet - assert(FeatureFlags.allowUUIDOnlyContacts) + assert(RemoteConfig.allowUUIDOnlyContacts) return nil } @@ -8376,7 +8376,7 @@ public class SSKProtoSyncMessageViewOnceOpen: NSObject, Codable { let phoneNumber: String? = { guard hasSenderE164 else { // Shouldn’t happen in prod yet - assert(FeatureFlags.allowUUIDOnlyContacts) + assert(RemoteConfig.allowUUIDOnlyContacts) return nil } @@ -8984,7 +8984,7 @@ public class SSKProtoSyncMessageMessageRequestResponse: NSObject, Codable { let phoneNumber: String? = { guard hasThreadE164 else { // Shouldn’t happen in prod yet - assert(FeatureFlags.allowUUIDOnlyContacts) + assert(RemoteConfig.allowUUIDOnlyContacts) return nil } @@ -11059,7 +11059,7 @@ public class SSKProtoContactDetails: NSObject, Codable { let phoneNumber: String? = { guard hasContactE164 else { // Shouldn’t happen in prod yet - assert(FeatureFlags.allowUUIDOnlyContacts) + assert(RemoteConfig.allowUUIDOnlyContacts) return nil } diff --git a/SignalServiceKit/src/Protos/Generated/StorageServiceProto.swift b/SignalServiceKit/src/Protos/Generated/StorageServiceProto.swift index 7d84cb8e99..5fe37893b1 100644 --- a/SignalServiceKit/src/Protos/Generated/StorageServiceProto.swift +++ b/SignalServiceKit/src/Protos/Generated/StorageServiceProto.swift @@ -1542,7 +1542,7 @@ public class StorageServiceProtoContactRecord: NSObject, Codable { let phoneNumber: String? = { guard hasServiceE164 else { // Shouldn’t happen in prod yet - assert(FeatureFlags.allowUUIDOnlyContacts) + assert(RemoteConfig.allowUUIDOnlyContacts) return nil } diff --git a/SignalServiceKit/src/Security/OWSFingerprint.m b/SignalServiceKit/src/Security/OWSFingerprint.m index 6bd12238d0..59e46f21e8 100644 --- a/SignalServiceKit/src/Security/OWSFingerprint.m +++ b/SignalServiceKit/src/Security/OWSFingerprint.m @@ -95,7 +95,7 @@ static uint32_t const OWSFingerprintDefaultHashIterations = 5200; - (uint32_t)scannableFingerprintVersion { - if (!SSKFeatureFlags.uuidSafetyNumbers) { + if (!RemoteConfig.uuidSafetyNumbers) { return OWSFingerprintPreUUIDScannableFormatVersion; } diff --git a/SignalServiceKit/src/TestUtils/TestProtocolRunner.swift b/SignalServiceKit/src/TestUtils/TestProtocolRunner.swift index 9ea9ef7111..5e75776706 100644 --- a/SignalServiceKit/src/TestUtils/TestProtocolRunner.swift +++ b/SignalServiceKit/src/TestUtils/TestProtocolRunner.swift @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 Open Whisper Systems. All rights reserved. +// Copyright (c) 2020 Open Whisper Systems. All rights reserved. // import Foundation @@ -73,7 +73,7 @@ public extension SignalClient { } var address: SignalServiceAddress { - if FeatureFlags.allowUUIDOnlyContacts { + if RemoteConfig.allowUUIDOnlyContacts { return SignalServiceAddress(uuid: uuid, phoneNumber: e164Identifier) } else { return SignalServiceAddress(phoneNumber: e164Identifier!) diff --git a/SignalServiceKit/src/Util/FeatureFlags.swift b/SignalServiceKit/src/Util/FeatureFlags.swift index f346822c94..e8c0136477 100644 --- a/SignalServiceKit/src/Util/FeatureFlags.swift +++ b/SignalServiceKit/src/Util/FeatureFlags.swift @@ -112,9 +112,6 @@ public class FeatureFlags: BaseFlags { return build.includes(.beta) ? .fail : .failDebug } - @objc - public static let uuidCapabilities = groupsV2 - @objc public static var storageModeDescription: String { return "\(storageMode)" @@ -134,20 +131,13 @@ public class FeatureFlags: BaseFlags { @objc public static let strictYDBExtensions = build.includes(.beta) - @objc - public static let allowUUIDOnlyContacts = groupsV2 - - @objc - public static let uuidSafetyNumbers = allowUUIDOnlyContacts - @objc public static let phoneNumberPrivacy = false @objc public static let complainAboutSlowDBWrites = true - @objc - public static let usernames = allowUUIDOnlyContacts && build.includes(.dev) + static let canUseUsernames = build.includes(.dev) @objc public static var calling: Bool { diff --git a/SignalServiceKit/src/Util/RemoteConfigManager.swift b/SignalServiceKit/src/Util/RemoteConfigManager.swift index 97f515f1ed..4653f9a527 100644 --- a/SignalServiceKit/src/Util/RemoteConfigManager.swift +++ b/SignalServiceKit/src/Util/RemoteConfigManager.swift @@ -64,7 +64,6 @@ public class RemoteConfig: BaseFlags { @objc public static var uuidSafetyNumbers: Bool { guard modernContactDiscovery else { return false } - guard FeatureFlags.uuidSafetyNumbers else { return false } return isEnabled(.uuidSafetyNumbers) } @@ -111,6 +110,23 @@ public class RemoteConfig: BaseFlags { return isEnabled(.mentions) } + @objc + public static var uuidCapabilities: Bool { + modernContactDiscovery + } + + @objc + public static var allowUUIDOnlyContacts: Bool { + modernContactDiscovery + } + + @objc + public static var usernames: Bool { + modernContactDiscovery && FeatureFlags.canUseUsernames + } + + // MARK: - + private static func isEnabled(_ flag: Flags.SupportedIsEnabledFlags, defaultValue: Bool = false) -> Bool { guard let remoteConfig = SSKEnvironment.shared.remoteConfigManager.cachedConfig else { return defaultValue diff --git a/SignalServiceKit/tests/Messages/MessageProcessingIntegrationTest.swift b/SignalServiceKit/tests/Messages/MessageProcessingIntegrationTest.swift index ba98e67d6e..88e8a7bbaf 100644 --- a/SignalServiceKit/tests/Messages/MessageProcessingIntegrationTest.swift +++ b/SignalServiceKit/tests/Messages/MessageProcessingIntegrationTest.swift @@ -126,7 +126,7 @@ class MessageProcessingIntegrationTest: SSKBaseTestSwift { } func test_contactMessage_UUIDEnvelope() { - guard FeatureFlags.allowUUIDOnlyContacts else { + guard RemoteConfig.allowUUIDOnlyContacts else { // This test is known to be failing. // It's intended as TDD for the upcoming UUID work. return