Revert refunded features on launch

This commit is contained in:
Davide De Rosa 2019-11-09 12:40:48 +01:00
parent 441b1059cf
commit 495e714737
3 changed files with 63 additions and 3 deletions

View File

@ -27,6 +27,9 @@ import UIKit
import TunnelKit
import PassepartoutCore
import Convenience
import SwiftyBeaver
private let log = SwiftyBeaver.self
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDelegate {
@ -79,6 +82,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDele
func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
ProductManager.shared.reviewPurchases()
}
func applicationWillTerminate(_ application: UIApplication) {

View File

@ -96,7 +96,7 @@ class ProductManager: NSObject {
// MARK: In-app eligibility
private func reloadReceipt() {
private func reloadReceipt(andNotify: Bool = true) {
guard let url = Bundle.main.appStoreReceiptURL else {
log.warning("No App Store receipt found!")
return
@ -140,7 +140,9 @@ class ProductManager: NSObject {
}
log.info("Purchased features: \(purchasedFeatures)")
NotificationCenter.default.post(name: ProductManager.didReloadReceipt, object: nil)
if andNotify {
NotificationCenter.default.post(name: ProductManager.didReloadReceipt, object: nil)
}
}
func isFullVersion() -> Bool {
@ -169,6 +171,60 @@ class ProductManager: NSObject {
func isEligibleForFeedback() -> Bool {
return AppConstants.Flags.isBeta || !purchasedFeatures.isEmpty
}
// MARK: Review
func reviewPurchases() {
let service = TransientStore.shared.service
reloadReceipt(andNotify: false)
var shouldReinstall = false
// review features and potentially revert them if they were used (Siri is handled in AppDelegate)
log.debug("Checking 'Trusted networks'")
if !isEligible(forFeature: .trustedNetworks) {
if service.preferences.trustsMobileNetwork || !service.preferences.trustedWifis.isEmpty {
service.preferences.trustsMobileNetwork = false
service.preferences.trustedWifis.removeAll()
log.debug("\tRefunded")
shouldReinstall = true
}
}
log.debug("Checking 'Unlimited hosts'")
if !isEligible(forFeature: .unlimitedHosts) {
let ids = service.ids(forContext: .host)
if ids.count > AppConstants.InApp.limitedNumberOfHosts {
for id in ids {
service.removeProfile(ProfileKey(.host, id))
}
log.debug("\tRefunded")
shouldReinstall = true
}
}
log.debug("Checking providers")
for name in service.currentProviderNames() {
if !isEligible(forProvider: name) {
service.removeProfile(ProfileKey(name))
log.debug("\tRefunded provider: \(name)")
shouldReinstall = true
}
}
// no refunds
guard shouldReinstall else {
return
}
//
// save reverts and remove fraud VPN profile
TransientStore.shared.serialize(withProfiles: true)
VPN.shared.uninstall(completionHandler: nil)
NotificationCenter.default.post(name: ProductManager.didReloadReceipt, object: nil)
}
}
extension ConnectionService {

@ -1 +1 @@
Subproject commit 7476e0751d1a64efca0180a1e31f0e24f04fce84
Subproject commit dad47f3581ab25d966d204de93634d82b9fe808b