Skip to content

Commit

Permalink
Address Ship Review issues with entitlement expiration (#2628)
Browse files Browse the repository at this point in the history
Task/Issue URL: https://app.asana.com/0/1203137811378537/1206896148261286/f
Tech Design URL:
CC:

Description:

This PR addresses some Ship Review issues with entitlement expiration not being picked up by adding entitlementsDidChange and accountDidSignOut notification handling

Steps to test this PR:

Subscribe to PP
Remove sub from device
VPN should stop and be removed from Settings.app
Revoke the entitlements
Open another app and go back to the app
The app should detect the entitlement change and show messaging & stop the VPN
  • Loading branch information
quanganhdo authored Mar 22, 2024
1 parent 40fbb49 commit 07e7aa7
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions DuckDuckGo/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1355,6 +1355,18 @@ class MainViewController: UIViewController {
self?.onNetworkProtectionAccountSignIn(notification)
}
.store(in: &vpnCancellables)
NotificationCenter.default.publisher(for: .entitlementsDidChange)
.receive(on: DispatchQueue.main)
.sink { [weak self] notification in
self?.onEntitlementsChange(notification)
}
.store(in: &vpnCancellables)
NotificationCenter.default.publisher(for: .accountDidSignOut)
.receive(on: DispatchQueue.main)
.sink { [weak self] notification in
self?.onNetworkProtectionAccountSignOut(notification)
}
.store(in: &vpnCancellables)

NotificationCenter.default.publisher(for: .vpnEntitlementMessagingDidChange)
.receive(on: DispatchQueue.main)
Expand Down Expand Up @@ -1409,6 +1421,27 @@ class MainViewController: UIViewController {
tunnelDefaults.resetEntitlementMessaging()
os_log("[NetP Subscription] Reset expired entitlement messaging", log: .networkProtection, type: .info)
}

@objc
private func onEntitlementsChange(_ notification: Notification) {
Task {
guard case .success(false) = await AccountManager().hasEntitlement(for: .networkProtection) else { return }

tunnelDefaults.enableEntitlementMessaging()

let controller = NetworkProtectionTunnelController()
await controller.stop()
}
}

@objc
private func onNetworkProtectionAccountSignOut(_ notification: Notification) {
Task {
let controller = NetworkProtectionTunnelController()
await controller.stop()
await controller.removeVPN()
}
}
#endif

@objc
Expand Down

0 comments on commit 07e7aa7

Please sign in to comment.