Configure trusted networks in profile

This commit is contained in:
Davide De Rosa 2019-11-21 09:28:28 +01:00
parent 1fd2d18653
commit 2c4dea7b43
3 changed files with 25 additions and 17 deletions

View File

@ -191,17 +191,26 @@ class ProductManager: NSObject {
func reviewPurchases() {
let service = TransientStore.shared.service
reloadReceipt(andNotify: false)
var shouldReinstall = false
var anyRefund = 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.trustedNetworks.includesMobile || !service.preferences.trustedNetworks.includedWiFis.isEmpty {
service.preferences.trustedNetworks.includesMobile = false
service.preferences.trustedNetworks.includedWiFis.removeAll()
// reset trusted networks for ALL profiles (must load first)
for key in service.allProfileKeys() {
guard let profile = service.profile(withKey: key) else {
continue
}
if profile.trustedNetworks.includesMobile || !profile.trustedNetworks.includedWiFis.isEmpty {
profile.trustedNetworks.includesMobile = false
profile.trustedNetworks.includedWiFis.removeAll()
anyRefund = true
}
}
if anyRefund {
log.debug("\tRefunded")
shouldReinstall = true
}
}
@ -213,7 +222,7 @@ class ProductManager: NSObject {
service.removeProfile(ProfileKey(.host, id))
}
log.debug("\tRefunded")
shouldReinstall = true
anyRefund = true
}
}
@ -222,12 +231,11 @@ class ProductManager: NSObject {
if !isEligible(forProvider: name) {
service.removeProfile(ProfileKey(name))
log.debug("\tRefunded provider: \(name)")
shouldReinstall = true
anyRefund = true
}
}
// no refunds
guard shouldReinstall else {
guard anyRefund else {
return
}

View File

@ -429,7 +429,7 @@ class ServiceViewController: UIViewController, StrongTableHost {
private func toggleTrustedConnectionPolicy(_ isOn: Bool, sender: ToggleTableViewCell) {
let completionHandler: () -> Void = {
self.service.preferences.trustedNetworks.policy = isOn ? .disconnect : .ignore
self.uncheckedProfile.trustedNetworks.policy = isOn ? .disconnect : .ignore
if self.vpn.isEnabled {
self.vpn.reinstall(completionHandler: nil)
}
@ -933,7 +933,7 @@ extension ServiceViewController: UITableViewDataSource, UITableViewDelegate, Tog
case .trustedMobile:
let cell = Cells.toggle.dequeue(from: tableView, for: indexPath, tag: row.rawValue, delegate: self)
cell.caption = L10n.Core.Service.Cells.TrustedMobile.caption
cell.isOn = service.preferences.trustedNetworks.includesMobile
cell.isOn = uncheckedProfile.trustedNetworks.includesMobile
return cell
case .trustedWiFi:
@ -952,7 +952,7 @@ extension ServiceViewController: UITableViewDataSource, UITableViewDelegate, Tog
case .trustedPolicy:
let cell = Cells.toggle.dequeue(from: tableView, for: indexPath, tag: row.rawValue, delegate: self)
cell.caption = L10n.Core.Service.Cells.TrustedPolicy.caption
cell.isOn = (service.preferences.trustedNetworks.policy == .disconnect)
cell.isOn = (uncheckedProfile.trustedNetworks.policy == .disconnect)
return cell
// diagnostics
@ -1241,7 +1241,7 @@ extension ServiceViewController: UITableViewDataSource, UITableViewDelegate, Tog
}
trustedNetworks.delegate = self
trustedNetworks.load(from: service.preferences)
trustedNetworks.load(from: uncheckedProfile)
model.set(trustedNetworks.rows.map { mappedTrustedNetworksRow($0) }, forSection: .trusted)
}
@ -1315,7 +1315,7 @@ extension ServiceViewController: UITextFieldDelegate {
extension ServiceViewController: TrustedNetworksUIDelegate {
func trustedNetworksCouldDisconnect(_: TrustedNetworksUI) -> Bool {
return (service.preferences.trustedNetworks.policy == .disconnect) && (vpn.status != .disconnected)
return (uncheckedProfile.trustedNetworks.policy == .disconnect) && (vpn.status != .disconnected)
}
func trustedNetworksShouldConfirmDisconnection(_: TrustedNetworksUI, triggeredAt rowIndex: Int, completionHandler: @escaping () -> Void) {
@ -1344,8 +1344,8 @@ extension ServiceViewController: TrustedNetworksUIDelegate {
}
func trustedNetworksShouldReinstall(_: TrustedNetworksUI) {
service.preferences.trustedNetworks.includesMobile = trustedNetworks.trustsMobileNetwork
service.preferences.trustedNetworks.includedWiFis = trustedNetworks.trustedWifis
uncheckedProfile.trustedNetworks.includesMobile = trustedNetworks.trustsMobileNetwork
uncheckedProfile.trustedNetworks.includedWiFis = trustedNetworks.trustedWifis
if vpn.isEnabled {
vpn.reinstall(completionHandler: nil)
}

@ -1 +1 @@
Subproject commit 25e986e7ceb534805618cfa3b0846373d4e90378
Subproject commit 81e8280ec55e4f0ebe4f8233e13ef46593137a6a