-
Notifications
You must be signed in to change notification settings - Fork 429
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle subscription-related iOS use cases (#2597)
Task/Issue URL: https://app.asana.com/0/414235014887631/1206844393131400/f This PR does the necessary work for the PP launch. Steps to test this PR: Check different scenarios according to https://app.asana.com/0/0/1206812323779606/f Make sure the followings are handled correctly: waitlist users, entitlement check, entry points, etc.
- Loading branch information
1 parent
2deb813
commit 9c0553e
Showing
22 changed files
with
572 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// | ||
// DefaultNetworkProtectionVisibility.swift | ||
// DuckDuckGo | ||
// | ||
// Copyright © 2024 DuckDuckGo. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
#if NETWORK_PROTECTION | ||
|
||
import Foundation | ||
import BrowserServicesKit | ||
import Waitlist | ||
import NetworkProtection | ||
import Core | ||
|
||
struct DefaultNetworkProtectionVisibility: NetworkProtectionFeatureVisibility { | ||
private let privacyConfigurationManager: PrivacyConfigurationManaging | ||
private let networkProtectionTokenStore: NetworkProtectionTokenStore? | ||
private let networkProtectionAccessManager: NetworkProtectionAccess? | ||
private let featureFlagger: FeatureFlagger | ||
private let userDefaults: UserDefaults | ||
|
||
init(privacyConfigurationManager: PrivacyConfigurationManaging = ContentBlocking.shared.privacyConfigurationManager, | ||
networkProtectionTokenStore: NetworkProtectionTokenStore? = NetworkProtectionKeychainTokenStore(), | ||
networkProtectionAccessManager: NetworkProtectionAccess? = NetworkProtectionAccessController(), | ||
featureFlagger: FeatureFlagger = AppDependencyProvider.shared.featureFlagger, | ||
userDefaults: UserDefaults = .networkProtectionGroupDefaults) { | ||
self.privacyConfigurationManager = privacyConfigurationManager | ||
self.networkProtectionTokenStore = networkProtectionTokenStore | ||
self.networkProtectionAccessManager = networkProtectionAccessManager | ||
self.featureFlagger = featureFlagger | ||
self.userDefaults = userDefaults | ||
} | ||
|
||
/// A lite version with fewer dependencies | ||
/// We need this to run shouldMonitorEntitlement() check inside the token store | ||
static func forTokenStore() -> DefaultNetworkProtectionVisibility { | ||
DefaultNetworkProtectionVisibility(networkProtectionTokenStore: nil, networkProtectionAccessManager: nil) | ||
} | ||
|
||
func isWaitlistBetaActive() -> Bool { | ||
privacyConfigurationManager.privacyConfig.isSubfeatureEnabled(NetworkProtectionSubfeature.waitlistBetaActive) | ||
} | ||
|
||
func isWaitlistUser() -> Bool { | ||
guard let networkProtectionTokenStore, let networkProtectionAccessManager else { | ||
preconditionFailure("networkProtectionTokenStore and networkProtectionAccessManager must be non-nil") | ||
} | ||
|
||
let hasLegacyAuthToken = { | ||
guard let authToken = try? networkProtectionTokenStore.fetchToken(), | ||
!authToken.hasPrefix(NetworkProtectionKeychainTokenStore.authTokenPrefix) else { | ||
return false | ||
} | ||
return true | ||
}() | ||
let hasBeenInvited = { | ||
let vpnAccessType = networkProtectionAccessManager.networkProtectionAccessType() | ||
return vpnAccessType == .waitlistInvited || vpnAccessType == .inviteCodeInvited | ||
}() | ||
|
||
return hasLegacyAuthToken || hasBeenInvited | ||
} | ||
|
||
// todo - https://app.asana.com/0/0/1206844038943626/f | ||
func isPrivacyProLaunched() -> Bool { | ||
if let subscriptionOverrideEnabled = userDefaults.subscriptionOverrideEnabled { | ||
#if ALPHA || DEBUG | ||
return subscriptionOverrideEnabled | ||
#else | ||
return false | ||
#endif | ||
} | ||
|
||
return featureFlagger.isFeatureOn(.subscription) | ||
} | ||
|
||
// todo - https://app.asana.com/0/0/1206844038943626/f | ||
func shouldMonitorEntitlement() -> Bool { | ||
isPrivacyProLaunched() | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.