-
Notifications
You must be signed in to change notification settings - Fork 423
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
NetP feature usage pixels #2027
Changes from all commits
b4dc48a
71ba83a
6b556f8
3f72a9e
fb16b56
496a7d9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// | ||
// NetworkProtectionDebugUtilities.swift | ||
// DuckDuckGo | ||
// | ||
// Copyright © 2023 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. | ||
// | ||
|
||
import Common | ||
import Foundation | ||
|
||
#if NETWORK_PROTECTION | ||
import NetworkProtection | ||
import NetworkExtension | ||
|
||
/// Utility code to help implement our debug menu options for Network Protection. | ||
/// | ||
final class NetworkProtectionDebugUtilities { | ||
|
||
// MARK: - Registation Key | ||
|
||
func expireRegistrationKeyNow() async { | ||
guard let activeSession = try? await ConnectionSessionUtilities.activeSession() else { | ||
return | ||
} | ||
|
||
try? activeSession.sendProviderMessage(.expireRegistrationKey) | ||
} | ||
} | ||
|
||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,14 +33,17 @@ final class NetworkProtectionDebugViewController: UITableViewController { | |
private let titles = [ | ||
Sections.keychain: "Keychain", | ||
Sections.debugFeature: "Debug Features", | ||
Sections.simulateFailure: "Simulate Failure" | ||
Sections.simulateFailure: "Simulate Failure", | ||
Sections.registrationKey: "Registration Key" | ||
|
||
] | ||
|
||
enum Sections: Int, CaseIterable { | ||
|
||
case keychain | ||
case debugFeature | ||
case simulateFailure | ||
case registrationKey | ||
|
||
} | ||
|
||
|
@@ -63,6 +66,12 @@ final class NetworkProtectionDebugViewController: UITableViewController { | |
|
||
} | ||
|
||
enum RegistrationKeyRows: Int, CaseIterable { | ||
|
||
case expireNow | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the future we could add last rekey date here, so it's easy to see how well this is working in real-world scenarios, but we don't need to do it here. We have a project dedicated to the debug menu which tbh I would like to break up into tasks, so it can be done as a part of that. |
||
|
||
} | ||
|
||
private let debugFeatures: NetworkProtectionDebugFeatures | ||
private let tokenStore: NetworkProtectionTokenStore | ||
|
||
|
@@ -109,6 +118,10 @@ final class NetworkProtectionDebugViewController: UITableViewController { | |
|
||
case .simulateFailure: | ||
configure(cell, forSimulateFailureAtRow: indexPath.row) | ||
|
||
case .registrationKey: | ||
configure(cell, forRegistrationKeyRow: indexPath.row) | ||
|
||
case.none: | ||
break | ||
} | ||
|
@@ -121,6 +134,7 @@ final class NetworkProtectionDebugViewController: UITableViewController { | |
case .keychain: return KeychainRows.allCases.count | ||
case .debugFeature: return DebugFeatureRows.allCases.count | ||
case .simulateFailure: return SimulateFailureRows.allCases.count | ||
case .registrationKey: return RegistrationKeyRows.allCases.count | ||
case .none: return 0 | ||
|
||
} | ||
|
@@ -137,6 +151,8 @@ final class NetworkProtectionDebugViewController: UITableViewController { | |
didSelectDebugFeature(at: indexPath) | ||
case .simulateFailure: | ||
didSelectSimulateFailure(at: indexPath) | ||
case .registrationKey: | ||
didSelectRegistationKeyAction(at: indexPath) | ||
case .none: | ||
break | ||
} | ||
|
@@ -198,6 +214,28 @@ final class NetworkProtectionDebugViewController: UITableViewController { | |
} | ||
} | ||
|
||
// MARK: Registration Key | ||
|
||
private func configure(_ cell: UITableViewCell, forRegistrationKeyRow row: Int) { | ||
switch RegistrationKeyRows(rawValue: row) { | ||
case .expireNow: | ||
cell.textLabel?.text = "Expire Now" | ||
case .none: | ||
break | ||
} | ||
} | ||
|
||
private func didSelectRegistationKeyAction(at indexPath: IndexPath) { | ||
switch RegistrationKeyRows(rawValue: indexPath.row) { | ||
case .expireNow: | ||
Task { | ||
await NetworkProtectionDebugUtilities().expireRegistrationKeyNow() | ||
} | ||
case .none: | ||
break | ||
} | ||
} | ||
|
||
// MARK: Selection Actions | ||
|
||
private func clearAuthToken() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice 👍