From 9ce5afedd54aaf96e348e17e9e8c7396da4b9c94 Mon Sep 17 00:00:00 2001 From: Sam Symons Date: Thu, 27 Jun 2024 15:32:01 +1200 Subject: [PATCH 1/2] Update VPN metadata to include entitlement (#3002) Task/Issue URL: https://app.asana.com/0/414235014887631/1207672846964315/f Tech Design URL: CC: Description: This PR updates the metadata collector to include entitlement status. --- DuckDuckGo/Feedback/VPNFeedbackFormView.swift | 3 +- .../Feedback/VPNMetadataCollector.swift | 28 ++++++++----------- ...NetworkProtectionDebugViewController.swift | 3 +- 3 files changed, 13 insertions(+), 21 deletions(-) diff --git a/DuckDuckGo/Feedback/VPNFeedbackFormView.swift b/DuckDuckGo/Feedback/VPNFeedbackFormView.swift index fd116f15e6..b74eca8b17 100644 --- a/DuckDuckGo/Feedback/VPNFeedbackFormView.swift +++ b/DuckDuckGo/Feedback/VPNFeedbackFormView.swift @@ -25,8 +25,7 @@ import NetworkProtection @available(iOS 15.0, *) struct VPNFeedbackFormCategoryView: View { @Environment(\.dismiss) private var dismiss - let collector = DefaultVPNMetadataCollector(statusObserver: AppDependencyProvider.shared.connectionObserver, - tokenStore: AppDependencyProvider.shared.networkProtectionKeychainTokenStore) + let collector = DefaultVPNMetadataCollector(statusObserver: AppDependencyProvider.shared.connectionObserver) var body: some View { VStack { diff --git a/DuckDuckGo/Feedback/VPNMetadataCollector.swift b/DuckDuckGo/Feedback/VPNMetadataCollector.swift index b439d4c0f9..8345ec44b5 100644 --- a/DuckDuckGo/Feedback/VPNMetadataCollector.swift +++ b/DuckDuckGo/Feedback/VPNMetadataCollector.swift @@ -65,8 +65,8 @@ struct VPNMetadata: Encodable { } struct PrivacyProInfo: Encodable { - let hasToken: Bool - let subscriptionActive: Bool + let hasPrivacyProAccount: Bool + let hasVPNEntitlement: Bool } struct LastDisconnectError: Encodable { @@ -114,18 +114,18 @@ protocol VPNMetadataCollector { final class DefaultVPNMetadataCollector: VPNMetadataCollector { private let statusObserver: ConnectionStatusObserver private let serverInfoObserver: ConnectionServerInfoObserver - private let tokenStore: NetworkProtectionTokenStore + private let accountManager: AccountManager private let settings: VPNSettings private let defaults: UserDefaults init(statusObserver: ConnectionStatusObserver, serverInfoObserver: ConnectionServerInfoObserver = ConnectionServerInfoObserverThroughSession(), - tokenStore: NetworkProtectionTokenStore, + accountManager: AccountManager = AppDependencyProvider.shared.subscriptionManager.accountManager, settings: VPNSettings = .init(defaults: .networkProtectionGroupDefaults), defaults: UserDefaults = .networkProtectionGroupDefaults) { self.statusObserver = statusObserver self.serverInfoObserver = serverInfoObserver - self.tokenStore = tokenStore + self.accountManager = accountManager self.settings = settings self.defaults = defaults } @@ -136,7 +136,7 @@ final class DefaultVPNMetadataCollector: VPNMetadataCollector { let networkInfoMetadata = await collectNetworkInformation() let vpnState = await collectVPNState() let vpnSettingsState = collectVPNSettingsState() - let privacyProInfo = collectPrivacyProInfo() + let privacyProInfo = await collectPrivacyProInfo() return VPNMetadata( appInfo: appInfoMetadata, @@ -253,20 +253,14 @@ final class DefaultVPNMetadataCollector: VPNMetadataCollector { ) } - func collectPrivacyProInfo() -> VPNMetadata.PrivacyProInfo { - var hasToken: Bool { - guard let token = try? tokenStore.fetchToken(), - !token.hasPrefix(NetworkProtectionKeychainTokenStore.authTokenPrefix) else { - return false - } - return true - } - + func collectPrivacyProInfo() async -> VPNMetadata.PrivacyProInfo { + let hasVPNEntitlement = (try? await accountManager.hasEntitlement(forProductName: .networkProtection).get()) ?? false return .init( - hasToken: hasToken, - subscriptionActive: AppDependencyProvider.shared.subscriptionManager.accountManager.isUserAuthenticated + hasPrivacyProAccount: accountManager.isUserAuthenticated, + hasVPNEntitlement: hasVPNEntitlement ) } + } private extension NSError { diff --git a/DuckDuckGo/NetworkProtectionDebugViewController.swift b/DuckDuckGo/NetworkProtectionDebugViewController.swift index 27cdd8d7ac..472402a443 100644 --- a/DuckDuckGo/NetworkProtectionDebugViewController.swift +++ b/DuckDuckGo/NetworkProtectionDebugViewController.swift @@ -654,8 +654,7 @@ shouldShowVPNShortcut: \(vpnVisibility.shouldShowVPNShortcut() ? "YES" : "NO") @MainActor private func refreshMetadata() async { - let collector = DefaultVPNMetadataCollector(statusObserver: AppDependencyProvider.shared.connectionObserver, - tokenStore: AppDependencyProvider.shared.networkProtectionKeychainTokenStore) + let collector = DefaultVPNMetadataCollector(statusObserver: AppDependencyProvider.shared.connectionObserver) self.vpnMetadata = await collector.collectMetadata() self.tableView.reloadData() } From c032c18f33832158eb0f0938d1306e0f03db4dbd Mon Sep 17 00:00:00 2001 From: Diego Rey Mendez Date: Thu, 27 Jun 2024 10:06:03 +0200 Subject: [PATCH 2/2] VPN uninstall not stopping agent in App Store build (#2999) Task/Issue URL: https://app.asana.com/0/1207603085593419/1207659744300515/f macOS PR: https://github.com/duckduckgo/macos-browser/pull/2911 BSK PR: https://github.com/duckduckgo/BrowserServicesKit/pull/866 ## Description These changes are macOS specific, so we're just updating BSK to include the latest changes. --- DuckDuckGo.xcodeproj/project.pbxproj | 2 +- .../project.xcworkspace/xcshareddata/swiftpm/Package.resolved | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/DuckDuckGo.xcodeproj/project.pbxproj b/DuckDuckGo.xcodeproj/project.pbxproj index be1b537455..5b61754c94 100644 --- a/DuckDuckGo.xcodeproj/project.pbxproj +++ b/DuckDuckGo.xcodeproj/project.pbxproj @@ -9822,7 +9822,7 @@ repositoryURL = "https://github.com/DuckDuckGo/BrowserServicesKit"; requirement = { kind = exactVersion; - version = 161.1.2; + version = 161.1.3; }; }; 9F8FE9472BAE50E50071E372 /* XCRemoteSwiftPackageReference "lottie-spm" */ = { diff --git a/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index d8ca804f52..1b08c71358 100644 --- a/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -32,8 +32,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/DuckDuckGo/BrowserServicesKit", "state" : { - "revision" : "cde956dec771bb7196ab3f4b07e00254e433d58d", - "version" : "161.1.2" + "revision" : "d44d7dcc1f267d78b8d1ad54e276c156040d42e0", + "version" : "161.1.3" } }, {