Skip to content

Commit

Permalink
Add subscription status to the macOS metadata (#2680)
Browse files Browse the repository at this point in the history
Task/Issue URL: https://app.asana.com/0/1199230911884351/1207144276620677/f
Tech Design URL:
CC:

Description:

This PR adds the Privacy Pro status to the VPN metadata. It also reports if the user was a beta user (i.e. they have an old-style auth token) just in case we see anything strange related to that.
  • Loading branch information
samsymons authored Apr 26, 2024
1 parent b71ef58 commit 2abb32f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
28 changes: 27 additions & 1 deletion DuckDuckGo/VPNFeedbackForm/VPNMetadataCollector.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import NetworkProtection
import NetworkExtension
import NetworkProtectionIPC
import NetworkProtectionUI
import Subscription

struct VPNMetadata: Encodable {

Expand Down Expand Up @@ -72,12 +73,19 @@ struct VPNMetadata: Encodable {
let notificationsAgentIsRunning: Bool
}

struct PrivacyProInfo: Encodable {
let betaParticipant: Bool
let hasPrivacyProAccount: Bool
let hasVPNEntitlement: Bool
}

let appInfo: AppInfo
let deviceInfo: DeviceInfo
let networkInfo: NetworkInfo
let vpnState: VPNState
let vpnSettingsState: VPNSettingsState
let loginItemState: LoginItemState
let privacyProInfo: PrivacyProInfo

func toPrettyPrintedJSON() -> String? {
let encoder = JSONEncoder()
Expand Down Expand Up @@ -138,14 +146,16 @@ final class DefaultVPNMetadataCollector: VPNMetadataCollector {
let vpnState = await collectVPNState()
let vpnSettingsState = collectVPNSettingsState()
let loginItemState = collectLoginItemState()
let privacyProInfo = await collectPrivacyProInfo()

return VPNMetadata(
appInfo: appInfoMetadata,
deviceInfo: deviceInfoMetadata,
networkInfo: networkInfoMetadata,
vpnState: vpnState,
vpnSettingsState: vpnSettingsState,
loginItemState: loginItemState
loginItemState: loginItemState,
privacyProInfo: privacyProInfo
)
}

Expand Down Expand Up @@ -283,4 +293,20 @@ final class DefaultVPNMetadataCollector: VPNMetadataCollector {
)
}

func collectPrivacyProInfo() async -> VPNMetadata.PrivacyProInfo {
let accountManager = AccountManager(subscriptionAppGroup: Bundle.main.appGroup(bundle: .subs))
let waitlistStore = WaitlistKeychainStore(
waitlistIdentifier: NetworkProtectionWaitlist.identifier,
keychainAppGroup: NetworkProtectionWaitlist.keychainAppGroup
)

let hasVPNEntitlement = (try? await accountManager.hasEntitlement(for: .networkProtection).get()) ?? false

return .init(
betaParticipant: waitlistStore.isInvited,
hasPrivacyProAccount: accountManager.isUserAuthenticated,
hasVPNEntitlement: hasVPNEntitlement
)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,20 @@ private class MockVPNMetadataCollector: VPNMetadataCollector {
notificationsAgentIsRunning: true
)

let privacyProInfo = VPNMetadata.PrivacyProInfo(
betaParticipant: false,
hasPrivacyProAccount: true,
hasVPNEntitlement: true
)

return VPNMetadata(
appInfo: appInfo,
deviceInfo: deviceInfo,
networkInfo: networkInfo,
vpnState: vpnState,
vpnSettingsState: vpnSettingsState,
loginItemState: loginItemState
loginItemState: loginItemState,
privacyProInfo: privacyProInfo
)
}

Expand Down

0 comments on commit 2abb32f

Please sign in to comment.