Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add controller VPN uninstall pixels #822

Merged
merged 5 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@

import Foundation

public enum DebugCommand: Codable {
public enum VPNCommand: Codable {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename for clarity since this is more than debug commands now.

case expireRegistrationKey
case removeSystemExtension
case removeVPNConfiguration
case sendTestNotification
case uninstallVPN
case disableConnectOnDemandAndShutDown
}

public enum ExtensionRequest: Codable {
case changeTunnelSetting(_ change: VPNSettings.Change)
case debugCommand(_ command: DebugCommand)
case command(_ command: VPNCommand)
}
9 changes: 6 additions & 3 deletions Sources/NetworkProtection/PacketTunnelProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -948,8 +948,8 @@ open class PacketTunnelProvider: NEPacketTunnelProvider {
case .changeTunnelSetting(let change):
handleSettingChangeAppRequest(change, completionHandler: completionHandler)
completionHandler?(nil)
case .debugCommand(let command):
handleDebugCommand(command, completionHandler: completionHandler)
case .command(let command):
handle(command, completionHandler: completionHandler)
}
}

Expand Down Expand Up @@ -1012,7 +1012,7 @@ open class PacketTunnelProvider: NEPacketTunnelProvider {
}
}

private func handleDebugCommand(_ command: DebugCommand, completionHandler: ((Data?) -> Void)? = nil) {
private func handle(_ command: VPNCommand, completionHandler: ((Data?) -> Void)? = nil) {
switch command {
case .removeSystemExtension:
// Since the system extension is being removed we may as well reset all state
Expand All @@ -1030,6 +1030,9 @@ open class PacketTunnelProvider: NEPacketTunnelProvider {
case .removeVPNConfiguration:
// Since the VPN configuration is being removed we may as well reset all state
handleResetAllState(completionHandler: completionHandler)
case .uninstallVPN:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New command to avoid having to make two IPC calls from the client app to uninstall.

// Since the VPN configuration is being removed we may as well reset all state
handleResetAllState(completionHandler: completionHandler)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,12 @@ public final class VPNConfigurationManager {

public init() {}

public func removeVPNConfiguration() async {
let tunnels = try? await NETunnelProviderManager.loadAllFromPreferences()
public func removeVPNConfiguration() async throws {
let tunnels = try await NETunnelProviderManager.loadAllFromPreferences()

if let tunnels = tunnels {
for tunnel in tunnels {
tunnel.connection.stopVPNTunnel()
try? await tunnel.removeFromPreferences()
}
for tunnel in tunnels {
tunnel.connection.stopVPNTunnel()
try await tunnel.removeFromPreferences()
}
}
}
Loading