From 5c3bc3c9b3853c1aa74fb80fa4e6cd22ff58b3c9 Mon Sep 17 00:00:00 2001 From: ykisana Date: Fri, 13 Nov 2026 05:38:40 -0600 Subject: [PATCH] refactor: require a passed key check to lift blocks Lifting a block now needs a KeyProof, which only a passed key or location check creates. ProtectedAction (.tighten/.weaken) replaces the separate allowBypass flag, and unblocks take an UnblockGrant that only exists when the proof covers the target. --- .../Intents/AppUnblockIntentPerformer.swift | 15 +++-- .../Modifiers/ProtectedActionModifier.swift | 8 +-- .../Modifiers/ScreenTimeGuardModifier.swift | 6 +- Normal/Modifiers/WidgetActionResponder.swift | 29 +++++---- Normal/Services/BlockActions.swift | 6 +- Normal/Services/Keys/KeyCheckFlow.swift | 32 +++++----- Normal/Services/Keys/KeyProof.swift | 26 ++++++++ Normal/Services/Keys/ProtectedAction.swift | 24 ++++++++ Normal/Services/ScreenTimeProviding.swift | 2 +- Normal/Services/ScreenTimeService.swift | 16 ++++- Normal/Services/UnblockTarget.swift | 6 +- .../Components/KeyProtectedToggle.swift | 13 ++-- .../KeySelect/KeySelectModifier.swift | 12 ++-- .../TimedUnlock/TimedUnlockBannerView.swift | 6 +- .../TimedUnlock/UnblockDurationSheet.swift | 6 +- Normal/Views/Groups/GroupListCardView.swift | 40 +++++++------ Normal/Views/Groups/GroupsView.swift | 13 ++-- Normal/Views/Home/AppDeleteToggleView.swift | 10 ++-- Normal/Views/Home/HomeView.swift | 52 ++++++++-------- Normal/Views/Home/MainBlockButtonView.swift | 11 ++-- .../Settings/AdultContentToggleView.swift | 6 +- NormalTests/Services/BlockActionsTests.swift | 8 ++- NormalTests/Services/KeyCheckFlowTests.swift | 35 ++++++++--- NormalTests/Services/KeyProofTests.swift | 59 +++++++++++++++++++ .../Services/ScreenTimeServiceTests.swift | 24 ++++++-- NormalTests/Services/UnblockTargetTests.swift | 22 ++++--- .../TestSupport/FakeScreenTimeService.swift | 6 +- .../TestSupport/StatefulScreenTimeSpy.swift | 2 +- 28 files changed, 323 insertions(+), 172 deletions(-) create mode 100644 Normal/Services/Keys/KeyProof.swift create mode 100644 Normal/Services/Keys/ProtectedAction.swift create mode 100644 NormalTests/Services/KeyProofTests.swift diff --git a/Normal/Intents/AppUnblockIntentPerformer.swift b/Normal/Intents/AppUnblockIntentPerformer.swift index 29fa2ad..5b7eb48 100644 --- a/Normal/Intents/AppUnblockIntentPerformer.swift +++ b/Normal/Intents/AppUnblockIntentPerformer.swift @@ -55,9 +55,10 @@ final class AppUnblockIntentPerformer: UnblockIntentPerforming { let location = await locationVerifier.check(keys: keys) try Task.checkCancellation() + let proof: KeyProof switch location { case .verified: - break + proof = KeyProof(keyGroupID: request.groupID) case .outOfRange: throw UnblockIntentError.notAtLocation(radiusKind) case .needsAlways: @@ -74,8 +75,10 @@ final class AppUnblockIntentPerformer: UnblockIntentPerforming { case let .settled(outcome): return outcome case let .ready(settings, target): - guard let length = settings.unblockLength(for: request.duration) else { return .continueInApp(.checkKey) } - return try start(target, for: length, settings: settings) + guard let length = settings.unblockLength(for: request.duration), + let grant = UnblockGrant(target, proof: proof) + else { return .continueInApp(.checkKey) } + return try start(grant, for: length, settings: settings) } } @@ -107,10 +110,10 @@ final class AppUnblockIntentPerformer: UnblockIntentPerforming { return .ready(settings, target) } - private func start(_ target: UnblockTarget, for length: UnblockLength, settings: Settings) throws -> UnblockOutcome { + private func start(_ grant: UnblockGrant, for length: UnblockLength, settings: Settings) throws -> UnblockOutcome { do { try BlockActions.unblock( - target, + grant, for: length, settings: settings, screenTimeService: intents.screenTimeService, @@ -123,7 +126,7 @@ final class AppUnblockIntentPerformer: UnblockIntentPerforming { if syncsExternalSurfaces { intents.syncExternalSurfaces(settings: settings) } - return .unblocked(name: target.name, length: length) + return .unblocked(name: grant.target.name, length: length) } private func keyType(for request: UnblockRequest, keys: [Key], settings: Settings?) -> KeyType? { diff --git a/Normal/Modifiers/ProtectedActionModifier.swift b/Normal/Modifiers/ProtectedActionModifier.swift index d631d2f..23a4222 100644 --- a/Normal/Modifiers/ProtectedActionModifier.swift +++ b/Normal/Modifiers/ProtectedActionModifier.swift @@ -1,8 +1,7 @@ import SwiftUI struct ProtectedActionModifier: ViewModifier { - @Binding var action: (@MainActor () -> Void)? - var allowBypass: Bool + @Binding var action: ProtectedAction? var defaultKeyType: KeyType? var requestedKeyType: KeyType? var keyGroupID: UUID? @@ -13,7 +12,6 @@ struct ProtectedActionModifier: ViewModifier { .screenTimeGuard(action: $action) .keySelect( action: $action, - allowBypass: allowBypass, defaultKeyType: defaultKeyType, requestedKeyType: requestedKeyType, keyGroupID: keyGroupID, @@ -24,8 +22,7 @@ struct ProtectedActionModifier: ViewModifier { extension View { func protectedAction( - _ action: Binding<(@MainActor () -> Void)?>, - allowBypass: Bool = false, + _ action: Binding, defaultKeyType: KeyType? = nil, requestedKeyType: KeyType? = nil, keyGroupID: UUID? = nil, @@ -33,7 +30,6 @@ extension View { ) -> some View { modifier(ProtectedActionModifier( action: action, - allowBypass: allowBypass, defaultKeyType: defaultKeyType, requestedKeyType: requestedKeyType, keyGroupID: keyGroupID, diff --git a/Normal/Modifiers/ScreenTimeGuardModifier.swift b/Normal/Modifiers/ScreenTimeGuardModifier.swift index cb64974..92931c6 100644 --- a/Normal/Modifiers/ScreenTimeGuardModifier.swift +++ b/Normal/Modifiers/ScreenTimeGuardModifier.swift @@ -2,8 +2,8 @@ import SwiftUI struct ScreenTimeGuardModifier: ViewModifier { @Environment(ScreenTimeService.self) private var screenTimeService - @Binding var action: (@MainActor () -> Void)? - @State private var deferred: (@MainActor () -> Void)? + @Binding var action: ProtectedAction? + @State private var deferred: ProtectedAction? func body(content: Content) -> some View { content.onChange(of: action != nil) { _, hasAction in @@ -24,7 +24,7 @@ struct ScreenTimeGuardModifier: ViewModifier { } extension View { - func screenTimeGuard(action: Binding<(@MainActor () -> Void)?>) -> some View { + func screenTimeGuard(action: Binding) -> some View { modifier(ScreenTimeGuardModifier(action: action)) } } diff --git a/Normal/Modifiers/WidgetActionResponder.swift b/Normal/Modifiers/WidgetActionResponder.swift index ff2510a..f0cdb3b 100644 --- a/Normal/Modifiers/WidgetActionResponder.swift +++ b/Normal/Modifiers/WidgetActionResponder.swift @@ -15,16 +15,15 @@ private struct WidgetActionResponder: ViewModifier { let coordinator: NavigationCoordinator @Binding var selectedTab: AppTab - @State private var authAction: (@MainActor () -> Void)? + @State private var authAction: ProtectedAction? @State private var active: ActiveRequest? @State private var heldRequest: ActionRequest? - @State private var durationTarget: UnblockTarget? + @State private var durationGrant: UnblockGrant? private struct ActiveRequest { let token: UUID let target: UnblockTarget let keyType: KeyType? - let allowBypass: Bool } private var unblockDurations: [TimedUnblockDuration] { @@ -35,13 +34,12 @@ private struct WidgetActionResponder: ViewModifier { content .protectedAction( $authAction, - allowBypass: active?.allowBypass ?? false, requestedKeyType: active?.keyType, keyGroupID: active?.target.groupID, requestID: active?.token ) - .sheet(item: $durationTarget, onDismiss: durationSheetDismissed) { target in - UnblockDurationSheet(target: target) + .sheet(item: $durationGrant, onDismiss: durationSheetDismissed) { grant in + UnblockDurationSheet(grant: grant) } .onOpenURL { coordinator.handle(url: $0) } .onChange(of: coordinator.pendingAction) { _, request in resolve(request) } @@ -72,7 +70,7 @@ private struct WidgetActionResponder: ViewModifier { private func takeInboxRequest() { guard scenePhase == .active, screenTimeService.authorizationState == .authorized, - durationTarget == nil, + durationGrant == nil, let request = unlockInbox.take(), let settings = allSettings.first, let target = target(for: request.groupID), @@ -92,7 +90,7 @@ private struct WidgetActionResponder: ViewModifier { private func resolve(_ request: ActionRequest?) { guard let request else { return } coordinator.clearPendingAction() - guard durationTarget == nil else { + guard durationGrant == nil else { heldRequest = request return } @@ -101,12 +99,12 @@ private struct WidgetActionResponder: ViewModifier { switch request.action { case let .unblock(unblock): guard let target = target(for: unblock.groupID) else { return } - present(ActiveRequest(token: request.token, target: target, keyType: unblock.keyType, allowBypass: false)) - authAction = { unlock(target, duration: unblock.duration) } + present(ActiveRequest(token: request.token, target: target, keyType: unblock.keyType)) + authAction = .weaken { unlock(target, duration: unblock.duration, proof: $0) } case let .blockGroup(groupID): guard let group = groups.first(where: { $0.id == groupID }) else { return } - present(ActiveRequest(token: request.token, target: .group(group), keyType: nil, allowBypass: true)) - authAction = { block(group) } + present(ActiveRequest(token: request.token, target: .group(group), keyType: nil)) + authAction = .tighten { block(group) } } } @@ -128,13 +126,14 @@ private struct WidgetActionResponder: ViewModifier { active = request } - private func unlock(_ target: UnblockTarget, duration request: UnlockDurationRequest) { + private func unlock(_ target: UnblockTarget, duration request: UnlockDurationRequest, proof: KeyProof) { + guard let grant = UnblockGrant(target, proof: proof) else { return } guard let settings = allSettings.first, let length = settings.unblockLength(for: request) else { - durationTarget = target + durationGrant = grant return } try? BlockActions.unblock( - target, + grant, for: length, settings: settings, screenTimeService: screenTimeService, diff --git a/Normal/Services/BlockActions.swift b/Normal/Services/BlockActions.swift index 679ed6d..88020ae 100644 --- a/Normal/Services/BlockActions.swift +++ b/Normal/Services/BlockActions.swift @@ -29,7 +29,7 @@ enum BlockActions { } static func unblock( - _ target: UnblockTarget, + _ grant: UnblockGrant, for length: UnblockLength, settings: Settings, screenTimeService: any ScreenTimeProviding, @@ -38,13 +38,13 @@ enum BlockActions { switch length { case let .timed(duration): try timedUnblockService.start( - target, + grant, duration: duration, settings: settings, screenTimeService: screenTimeService ) case .permanent: - screenTimeService.unblockPermanently(target, settings: settings) + screenTimeService.unblockPermanently(grant, settings: settings) } } diff --git a/Normal/Services/Keys/KeyCheckFlow.swift b/Normal/Services/Keys/KeyCheckFlow.swift index d3582e0..acf8e1f 100644 --- a/Normal/Services/Keys/KeyCheckFlow.swift +++ b/Normal/Services/Keys/KeyCheckFlow.swift @@ -13,8 +13,8 @@ final class KeyCheckFlow { struct Request { let id = UUID() let keys: [Key] + let keyGroupID: UUID? let availableKeyTypes: [KeyType] - let allowBypass: Bool let defaultKeyType: KeyType? var requestedKeyType: KeyType? } @@ -45,26 +45,28 @@ final class KeyCheckFlow { private(set) var stage: Stage = .idle private(set) var request: Request? + private(set) var allowsBypass = false private(set) var sheetScreen: SheetScreen = .picker private(set) var finishedRequestID: UUID? private let nfc: any KeyScanning private let qr: any QRScanning @ObservationIgnored private var qrScanRequestID: UUID? - @ObservationIgnored private var action: (@MainActor () -> Void)? + @ObservationIgnored private var action: ProtectedAction? init(nfc: any KeyScanning, qr: any QRScanning) { self.nfc = nfc self.qr = qr } - func start(_ request: Request, action: (@MainActor () -> Void)?) { + func start(_ request: Request, action: ProtectedAction) { stopQRScan() self.request = request self.action = action + allowsBypass = action.allowsBypass switch KeySelectLogic.decide( availableKeyTypes: request.availableKeyTypes, - allowBypass: request.allowBypass, + allowBypass: allowsBypass, defaultKeyType: request.defaultKeyType, requestedKeyType: request.requestedKeyType ) { @@ -84,9 +86,9 @@ final class KeyCheckFlow { } func requestBypass(skippingConfirmation: Bool) { - guard stage == .choosing, request?.allowBypass == true else { return } + guard stage == .choosing, allowsBypass else { return } if skippingConfirmation { - complete() + complete(with: nil) } else { sheetScreen = .bypassConfirm stage = .confirmingBypass @@ -94,8 +96,8 @@ final class KeyCheckFlow { } func confirmBypass() { - guard stage == .confirmingBypass, request?.allowBypass == true else { return } - complete() + guard stage == .confirmingBypass, allowsBypass else { return } + complete(with: nil) } func returnFromBypassConfirm() { @@ -111,8 +113,8 @@ final class KeyCheckFlow { } func locationVerified(requestID: UUID) { - guard stage == .checkingLocation, request?.id == requestID else { return } - complete() + guard stage == .checkingLocation, let request, request.id == requestID else { return } + complete(with: KeyProof(keyGroupID: request.keyGroupID)) } func keySheetClosed() { @@ -150,6 +152,7 @@ final class KeyCheckFlow { stage = .idle request = nil action = nil + allowsBypass = false } private func begin(_ keyType: KeyType) { @@ -178,16 +181,16 @@ final class KeyCheckFlow { if qrScanRequestID == requestID { qrScanRequestID = nil } - guard request?.id == requestID else { return } + guard let request, request.id == requestID else { return } if result == .success { - complete() + complete(with: KeyProof(keyGroupID: request.keyGroupID)) } else { finish() } } - private func complete() { - action?() + private func complete(with proof: KeyProof?) { + action?.run(with: proof) finish() } @@ -196,6 +199,7 @@ final class KeyCheckFlow { stage = .idle request = nil action = nil + allowsBypass = false } private func stopQRScan() { diff --git a/Normal/Services/Keys/KeyProof.swift b/Normal/Services/Keys/KeyProof.swift new file mode 100644 index 0000000..a550ada --- /dev/null +++ b/Normal/Services/Keys/KeyProof.swift @@ -0,0 +1,26 @@ +import Foundation + +struct KeyProof: Equatable { + let keyGroupID: UUID? + + var coversAllApps: Bool { + keyGroupID == nil + } + + func covers(_ target: UnblockTarget) -> Bool { + coversAllApps || keyGroupID == target.groupID + } +} + +struct UnblockGrant: Identifiable { + let target: UnblockTarget + + init?(_ target: UnblockTarget, proof: KeyProof) { + guard proof.covers(target) else { return nil } + self.target = target + } + + var id: String { + target.id + } +} diff --git a/Normal/Services/Keys/ProtectedAction.swift b/Normal/Services/Keys/ProtectedAction.swift new file mode 100644 index 0000000..61bca11 --- /dev/null +++ b/Normal/Services/Keys/ProtectedAction.swift @@ -0,0 +1,24 @@ +import Foundation + +enum ProtectedAction { + case tighten(@MainActor () -> Void) + case weaken(@MainActor (KeyProof) -> Void) + + var allowsBypass: Bool { + if case .tighten = self { + return true + } + return false + } + + func run(with proof: KeyProof?) { + switch self { + case let .tighten(action): + action() + case let .weaken(action): + if let proof { + action(proof) + } + } + } +} diff --git a/Normal/Services/ScreenTimeProviding.swift b/Normal/Services/ScreenTimeProviding.swift index af4ecde..a8353f0 100644 --- a/Normal/Services/ScreenTimeProviding.swift +++ b/Normal/Services/ScreenTimeProviding.swift @@ -13,7 +13,7 @@ protocol ScreenTimeProviding: AnyObject { func requestAuthorization() async func ensureAuthorized() async -> Bool func enablePreventAppDelete() - func disablePreventAppDelete() + func disablePreventAppDelete(_ proof: KeyProof) func blockAll( selection: FamilyActivitySelection, customDomains: [String], diff --git a/Normal/Services/ScreenTimeService.swift b/Normal/Services/ScreenTimeService.swift index f17fb66..58e7636 100644 --- a/Normal/Services/ScreenTimeService.swift +++ b/Normal/Services/ScreenTimeService.swift @@ -98,7 +98,8 @@ final class ScreenTimeService: ScreenTimeProviding { reconcile { $0.setAppDeletionBlocked(true, at: clock()) } } - func disablePreventAppDelete() { + func disablePreventAppDelete(_ proof: KeyProof) { + guard proof.coversAllApps else { return } reconcile { $0.setAppDeletionBlocked(false, at: clock()) } } @@ -166,8 +167,17 @@ final class ScreenTimeService: ScreenTimeProviding { notifyUpdate() } - func setAdultContentBlocked(_ blocked: Bool) { - sharedStore.setAdultContentEnabled(blocked) + func blockAdultContent() { + setAdultContentEnabled(true) + } + + func allowAdultContent(_ proof: KeyProof) { + guard proof.coversAllApps else { return } + setAdultContentEnabled(false) + } + + private func setAdultContentEnabled(_ enabled: Bool) { + sharedStore.setAdultContentEnabled(enabled) reconcile() } diff --git a/Normal/Services/UnblockTarget.swift b/Normal/Services/UnblockTarget.swift index 59869f3..86c4f00 100644 --- a/Normal/Services/UnblockTarget.swift +++ b/Normal/Services/UnblockTarget.swift @@ -53,11 +53,12 @@ enum UnblockTarget: Identifiable { extension TimedUnblockService { func start( - _ target: UnblockTarget, + _ grant: UnblockGrant, duration: TimedUnblockDuration, settings: Settings, screenTimeService: any ScreenTimeProviding ) throws { + let target = grant.target switch target { case let .all(mainSelection): try startMain( @@ -83,7 +84,8 @@ extension ScreenTimeProviding { blockStatus(selection: target.selection, customDomains: target.customDomains(settings: settings)) } - func unblockPermanently(_ target: UnblockTarget, settings: Settings) { + func unblockPermanently(_ grant: UnblockGrant, settings: Settings) { + let target = grant.target switch target { case .all: unblockAll(blockAllPreventsAppDelete: settings.blockAllPreventsAppDelete) diff --git a/Normal/Shared/Components/KeyProtectedToggle.swift b/Normal/Shared/Components/KeyProtectedToggle.swift index 824a98a..0f4c8a6 100644 --- a/Normal/Shared/Components/KeyProtectedToggle.swift +++ b/Normal/Shared/Components/KeyProtectedToggle.swift @@ -4,23 +4,22 @@ struct KeyProtectedToggle: View { let title: LocalizedStringKey let isOn: Bool var defaultKeyType: KeyType? - let onChange: @MainActor (Bool) -> Void + let onEnable: @MainActor () -> Void + let onDisable: @MainActor (KeyProof) -> Void - @State private var authAction: (@MainActor () -> Void)? - @State private var pendingValue: Bool? + @State private var authAction: ProtectedAction? private var binding: Binding { Binding( get: { isOn }, - set: { newValue in - pendingValue = newValue - authAction = { onChange(newValue) } + set: { isOn in + authAction = isOn ? .tighten { onEnable() } : .weaken { proof in onDisable(proof) } } ) } var body: some View { Toggle(title, isOn: binding) - .protectedAction($authAction, allowBypass: pendingValue == true, defaultKeyType: defaultKeyType) + .protectedAction($authAction, defaultKeyType: defaultKeyType) } } diff --git a/Normal/Views/BlockUnblockViews/KeySelect/KeySelectModifier.swift b/Normal/Views/BlockUnblockViews/KeySelect/KeySelectModifier.swift index 836335b..bd4cfcc 100644 --- a/Normal/Views/BlockUnblockViews/KeySelect/KeySelectModifier.swift +++ b/Normal/Views/BlockUnblockViews/KeySelect/KeySelectModifier.swift @@ -7,8 +7,7 @@ struct KeySelectModifier: ViewModifier { @Query private var keys: [Key] @Query private var allSettings: [Settings] - @Binding var action: (@MainActor () -> Void)? - var allowBypass: Bool + @Binding var action: ProtectedAction? var defaultKeyType: KeyType? var requestedKeyType: KeyType? var keyGroupID: UUID? @@ -69,7 +68,7 @@ struct KeySelectModifier: ViewModifier { NavigationStack { KeySelectView( availableKeyTypes: flow.request?.availableKeyTypes ?? [], - allowBypass: flow.request?.allowBypass ?? false, + allowBypass: flow.allowsBypass, onSelect: flow.choose, onBypass: { flow.requestBypass(skippingConfirmation: settings.skipBlockWithoutKeyConfirmation) } ) @@ -133,12 +132,13 @@ struct KeySelectModifier: ViewModifier { } private func start() { + guard let action else { return } let scopedKeys = Key.scoped(keys, toGroup: keyGroupID) flow.start( KeyCheckFlow.Request( keys: scopedKeys, + keyGroupID: keyGroupID, availableKeyTypes: KeyType.selectable(registered: scopedKeys.map(\.type)), - allowBypass: allowBypass, defaultKeyType: defaultKeyType, requestedKeyType: requestedKeyType ), @@ -149,8 +149,7 @@ struct KeySelectModifier: ViewModifier { extension View { func keySelect( - action: Binding<(@MainActor () -> Void)?>, - allowBypass: Bool = false, + action: Binding, defaultKeyType: KeyType? = nil, requestedKeyType: KeyType? = nil, keyGroupID: UUID? = nil, @@ -158,7 +157,6 @@ extension View { ) -> some View { modifier(KeySelectModifier( action: action, - allowBypass: allowBypass, defaultKeyType: defaultKeyType, requestedKeyType: requestedKeyType, keyGroupID: keyGroupID, diff --git a/Normal/Views/BlockUnblockViews/TimedUnlock/TimedUnlockBannerView.swift b/Normal/Views/BlockUnblockViews/TimedUnlock/TimedUnlockBannerView.swift index 2ea3ab1..2a9203d 100644 --- a/Normal/Views/BlockUnblockViews/TimedUnlock/TimedUnlockBannerView.swift +++ b/Normal/Views/BlockUnblockViews/TimedUnlock/TimedUnlockBannerView.swift @@ -9,8 +9,7 @@ struct TimedUnblockBannerView: View { let selection: FamilyActivitySelection var customDomains: [String] = [] - @Binding var authAction: (@MainActor () -> Void)? - @Binding var allowBypass: Bool + @Binding var authAction: ProtectedAction? private var settings: Settings { allSettings.unwrapped @@ -42,8 +41,7 @@ struct TimedUnblockBannerView: View { prominent: false, tint: .orange ) { - allowBypass = true - authAction = { + authAction = .tighten { timedUnblockService.cancelMain( selection: selection, customDomains: effectiveCustomDomains, diff --git a/Normal/Views/BlockUnblockViews/TimedUnlock/UnblockDurationSheet.swift b/Normal/Views/BlockUnblockViews/TimedUnlock/UnblockDurationSheet.swift index d601e3d..0e206ca 100644 --- a/Normal/Views/BlockUnblockViews/TimedUnlock/UnblockDurationSheet.swift +++ b/Normal/Views/BlockUnblockViews/TimedUnlock/UnblockDurationSheet.swift @@ -6,7 +6,7 @@ struct UnblockDurationSheet: View { @Environment(ScreenTimeService.self) private var screenTimeService @Query private var allSettings: [Settings] - let target: UnblockTarget + let grant: UnblockGrant var onUnblock: () -> Void = {} private var settings: Settings { @@ -14,7 +14,7 @@ struct UnblockDurationSheet: View { } private var title: String { - switch target { + switch grant.target { case .all: "Unblock All" case let .group(group): "Unblock \(group.name)" } @@ -27,7 +27,7 @@ struct UnblockDurationSheet: View { initialDuration: settings.defaultDuration, onConfirm: { length in try BlockActions.unblock( - target, + grant, for: length, settings: settings, screenTimeService: screenTimeService, diff --git a/Normal/Views/Groups/GroupListCardView.swift b/Normal/Views/Groups/GroupListCardView.swift index 23e1c43..c6b9b87 100644 --- a/Normal/Views/Groups/GroupListCardView.swift +++ b/Normal/Views/Groups/GroupListCardView.swift @@ -14,10 +14,9 @@ struct GroupListCardView: View { let appGroup: AppGroup // Hosted on the stable GroupsView list rather than this card: a sheet attached to // a card row whose block/unblock buttons swap gets wedged and won't re-present. - @Binding var authAction: (@MainActor () -> Void)? - @Binding var allowBypass: Bool + @Binding var authAction: ProtectedAction? @Binding var pendingGroupID: UUID? - @Binding var pendingDurationGroup: AppGroup? + @Binding var durationGrant: UnblockGrant? @State private var isEditing = false @State private var isReselecting = false @@ -117,9 +116,8 @@ struct GroupListCardView: View { ) } - private func requestAction(allowBypass: Bool, _ action: @escaping @MainActor () -> Void) { + private func requestAction(_ action: ProtectedAction) { pendingGroupID = appGroup.id - self.allowBypass = allowBypass authAction = action } @@ -206,7 +204,7 @@ struct GroupListCardView: View { .foregroundStyle(.secondary) Spacer() Button { - requestAction(allowBypass: true, blockGroup) + requestAction(.tighten(blockGroup)) } label: { Text("Block Now").font(.caption.weight(.semibold)) } @@ -233,7 +231,7 @@ struct GroupListCardView: View { prominent: true, tint: .blue ) { - requestAction(allowBypass: true, blockGroup) + requestAction(.tighten(blockGroup)) } .accessibilityIdentifier("group.blockButton") .disabled(!hasGlobalKey) @@ -245,19 +243,23 @@ struct GroupListCardView: View { systemImage: "lock.open.fill", prominent: false ) { - requestAction(allowBypass: false) { - if let duration = settings.defaultDuration { - try? timedUnblockService.start( - .group(appGroup), - duration: duration, - settings: settings, - screenTimeService: screenTimeService - ) - } else { - pendingDurationGroup = appGroup - } - } + requestAction(.weaken(unblockGroup)) } .accessibilityIdentifier("group.unblockButton") } + + private func unblockGroup(_ proof: KeyProof) { + guard let grant = UnblockGrant(.group(appGroup), proof: proof) else { return } + guard let duration = settings.defaultDuration else { + durationGrant = grant + return + } + try? BlockActions.unblock( + grant, + for: .timed(duration), + settings: settings, + screenTimeService: screenTimeService, + timedUnblockService: timedUnblockService + ) + } } diff --git a/Normal/Views/Groups/GroupsView.swift b/Normal/Views/Groups/GroupsView.swift index 384f602..ea090ae 100644 --- a/Normal/Views/Groups/GroupsView.swift +++ b/Normal/Views/Groups/GroupsView.swift @@ -11,10 +11,9 @@ struct GroupsView: View { @Query private var allSettings: [Settings] @State private var isShowingSheet = false - @State private var authAction: (@MainActor () -> Void)? - @State private var allowBypass = false + @State private var authAction: ProtectedAction? @State private var pendingGroupID: UUID? - @State private var pendingDurationGroup: AppGroup? + @State private var durationGrant: UnblockGrant? private var hasSelection: Bool { selectedApps.first?.selection.isEmpty == false @@ -56,9 +55,8 @@ struct GroupsView: View { GroupListCardView( appGroup: group, authAction: $authAction, - allowBypass: $allowBypass, pendingGroupID: $pendingGroupID, - pendingDurationGroup: $pendingDurationGroup + durationGrant: $durationGrant ) }, onMove: move) .safeAreaInset(edge: .bottom) { @@ -72,12 +70,11 @@ struct GroupsView: View { // triggered it, instead of on the card row. .protectedAction( $authAction, - allowBypass: allowBypass, defaultKeyType: allSettings.unwrapped.defaultKeyType, keyGroupID: pendingGroupID ) - .sheet(item: $pendingDurationGroup) { group in - UnblockDurationSheet(target: .group(group)) + .sheet(item: $durationGrant) { grant in + UnblockDurationSheet(grant: grant) } } } diff --git a/Normal/Views/Home/AppDeleteToggleView.swift b/Normal/Views/Home/AppDeleteToggleView.swift index baa683a..5a14884 100644 --- a/Normal/Views/Home/AppDeleteToggleView.swift +++ b/Normal/Views/Home/AppDeleteToggleView.swift @@ -9,12 +9,10 @@ struct AppDeleteToggleView: View { ) { KeyProtectedToggle( title: "Prevent App Deletion", - isOn: screenTimeService.isAppDeleteDisabled - ) { enabled in - enabled - ? screenTimeService.enablePreventAppDelete() - : screenTimeService.disablePreventAppDelete() - } + isOn: screenTimeService.isAppDeleteDisabled, + onEnable: { screenTimeService.enablePreventAppDelete() }, + onDisable: { screenTimeService.disablePreventAppDelete($0) } + ) .accessibilityIdentifier("home.preventDeleteToggle") } } diff --git a/Normal/Views/Home/HomeView.swift b/Normal/Views/Home/HomeView.swift index fdb601d..4e0d3a5 100644 --- a/Normal/Views/Home/HomeView.swift +++ b/Normal/Views/Home/HomeView.swift @@ -12,9 +12,8 @@ struct HomeView: View { @Query private var keys: [Key] @Query private var allSettings: [Settings] - @State private var authAction: (@MainActor () -> Void)? - @State private var allowBypass = false - @State private var showTimedUnblockSheet = false + @State private var authAction: ProtectedAction? + @State private var durationGrant: UnblockGrant? private var mainSelection: SelectedApps? { selectedApps.first @@ -35,15 +34,13 @@ struct HomeView: View { TimedUnblockBannerView( selection: mainSelection.selection, customDomains: mainSelection.customDomains, - authAction: $authAction, - allowBypass: $allowBypass + authAction: $authAction ) MainBlockButtonView( mainSelection: mainSelection, authAction: $authAction, - allowBypass: $allowBypass, onBlock: { blockMain(mainSelection) }, - onUnblock: { unblockMain(mainSelection) } + onUnblock: { unblockMain(mainSelection, proof: $0) } ) BlockStatusView(mainSelection: mainSelection) AppDeleteToggleView() @@ -54,20 +51,15 @@ struct HomeView: View { } } } - .protectedAction($authAction, allowBypass: allowBypass, defaultKeyType: settings.defaultKeyType) - .sheet(isPresented: $showTimedUnblockSheet) { timedUnblockSheet } + .protectedAction($authAction, defaultKeyType: settings.defaultKeyType) + .sheet(item: $durationGrant) { grant in + UnblockDurationSheet(grant: grant, onUnblock: recordUnblockForReview) + } .navigationTitle("Home") .settingsToolbar() } } - @ViewBuilder - private var timedUnblockSheet: some View { - if let mainSelection { - UnblockDurationSheet(target: .all(mainSelection), onUnblock: recordUnblockForReview) - } - } - private func blockMain(_ selection: SelectedApps) { BlockActions.blockAll( mainSelection: selection, @@ -77,20 +69,22 @@ struct HomeView: View { ) } - private func unblockMain(_ selection: SelectedApps) { - if let duration = settings.defaultDuration { - do { - try timedUnblockService.start( - .all(selection), - duration: duration, - settings: settings, - screenTimeService: screenTimeService - ) - recordUnblockForReview() - } catch {} - } else { - showTimedUnblockSheet = true + private func unblockMain(_ selection: SelectedApps, proof: KeyProof) { + guard let grant = UnblockGrant(.all(selection), proof: proof) else { return } + guard let duration = settings.defaultDuration else { + durationGrant = grant + return } + do { + try BlockActions.unblock( + grant, + for: .timed(duration), + settings: settings, + screenTimeService: screenTimeService, + timedUnblockService: timedUnblockService + ) + recordUnblockForReview() + } catch {} } private func recordUnblockForReview() { diff --git a/Normal/Views/Home/MainBlockButtonView.swift b/Normal/Views/Home/MainBlockButtonView.swift index babf996..a263c2d 100644 --- a/Normal/Views/Home/MainBlockButtonView.swift +++ b/Normal/Views/Home/MainBlockButtonView.swift @@ -8,10 +8,9 @@ struct MainBlockButtonView: View { @Query private var keys: [Key] let mainSelection: SelectedApps - @Binding var authAction: (@MainActor () -> Void)? - @Binding var allowBypass: Bool + @Binding var authAction: ProtectedAction? let onBlock: @MainActor () -> Void - let onUnblock: @MainActor () -> Void + let onUnblock: @MainActor (KeyProof) -> Void private var settings: Settings { allSettings.unwrapped @@ -54,8 +53,7 @@ struct MainBlockButtonView: View { private var blockRow: some View { Button { - allowBypass = true - authAction = onBlock + authAction = .tighten { onBlock() } } label: { HStack { Label("Block All", systemImage: "lock.fill") @@ -70,8 +68,7 @@ struct MainBlockButtonView: View { private var unblockRow: some View { Button { - allowBypass = false - authAction = onUnblock + authAction = .weaken { onUnblock($0) } } label: { HStack { Label("Unblock All", systemImage: "lock.open.fill") diff --git a/Normal/Views/Settings/AdultContentToggleView.swift b/Normal/Views/Settings/AdultContentToggleView.swift index a3688e6..2a47509 100644 --- a/Normal/Views/Settings/AdultContentToggleView.swift +++ b/Normal/Views/Settings/AdultContentToggleView.swift @@ -8,8 +8,10 @@ struct AdultContentToggleView: View { KeyProtectedToggle( title: "Block Adult Websites", isOn: screenTimeService.isAdultContentBlocked, - defaultKeyType: defaultKeyType - ) { screenTimeService.setAdultContentBlocked($0) } + defaultKeyType: defaultKeyType, + onEnable: { screenTimeService.blockAdultContent() }, + onDisable: { screenTimeService.allowAdultContent($0) } + ) .accessibilityIdentifier("settings.blockAdultContentToggle") } } diff --git a/NormalTests/Services/BlockActionsTests.swift b/NormalTests/Services/BlockActionsTests.swift index 45dcbfb..c2e5f94 100644 --- a/NormalTests/Services/BlockActionsTests.swift +++ b/NormalTests/Services/BlockActionsTests.swift @@ -10,6 +10,10 @@ struct BlockActionsTests { private let activity = FakeDeviceActivityCenter() private let store = FakeSharedStore() + private func grant(_ target: UnblockTarget) throws -> UnblockGrant { + try #require(UnblockGrant(target, proof: KeyProof(keyGroupID: nil))) + } + private func makeTimedUnblock() -> TimedUnblockService { TimedUnblockService(activityCenter: activity, sharedStore: store, onExpiration: {}) } @@ -121,7 +125,7 @@ struct BlockActionsTests { let group = AppGroup(name: "Social", selection: FamilyActivitySelection()) try BlockActions.unblock( - .group(group), + grant(.group(group)), for: .timed(.oneHour), settings: makeSettings(), screenTimeService: screenTime, @@ -137,7 +141,7 @@ struct BlockActionsTests { let group = AppGroup(name: "Social", selection: FamilyActivitySelection()) try BlockActions.unblock( - .group(group), + grant(.group(group)), for: .permanent, settings: makeSettings(), screenTimeService: screenTime, diff --git a/NormalTests/Services/KeyCheckFlowTests.swift b/NormalTests/Services/KeyCheckFlowTests.swift index ddbae25..d56652c 100644 --- a/NormalTests/Services/KeyCheckFlowTests.swift +++ b/NormalTests/Services/KeyCheckFlowTests.swift @@ -11,6 +11,7 @@ struct KeyCheckFlowTests { private final class Counter { var runs = 0 + var proofs: [KeyProof] = [] } init() { @@ -24,20 +25,23 @@ struct KeyCheckFlowTests { private func request( _ keys: [Key], available: [KeyType], - allowBypass: Bool = false, + keyGroupID: UUID? = nil, defaultKeyType: KeyType? = nil ) -> KeyCheckFlow.Request { KeyCheckFlow.Request( keys: keys, + keyGroupID: keyGroupID, availableKeyTypes: available, - allowBypass: allowBypass, defaultKeyType: defaultKeyType ) } - private func start(_ request: KeyCheckFlow.Request) { + private func start(_ request: KeyCheckFlow.Request, allowBypass: Bool = false) { let counter = counter - flow.start(request, action: { counter.runs += 1 }) + let action: ProtectedAction = allowBypass + ? .tighten { counter.runs += 1 } + : .weaken { counter.proofs.append($0); counter.runs += 1 } + flow.start(request, action: action) } private func waitUntil(_ condition: () -> Bool) async { @@ -80,6 +84,17 @@ struct KeyCheckFlowTests { #expect(counter.runs == 1) } + @Test func passingKeyHandsTheActionAProofForTheRequestsGroup() async { + let groupID = UUID() + start(request([key(.nfc, "tag")], available: [.nfc], keyGroupID: groupID)) + await waitUntil { nfc.isScanning } + + nfc.present("tag") + await waitUntil { flow.stage == .idle } + + #expect(counter.proofs == [KeyProof(keyGroupID: groupID)]) + } + @Test func rejectedTagEndsWithoutTheAction() async { start(request([key(.nfc, "tag")], available: [.nfc])) await waitUntil { nfc.isScanning } @@ -187,20 +202,23 @@ struct KeyCheckFlowTests { @Test func bypassNeedsPermission() { start(qrAndNFC) + #expect(!flow.allowsBypass) flow.requestBypass(skippingConfirmation: true) #expect(flow.stage == .choosing) #expect(counter.runs == 0) } @Test func bypassWithoutConfirmationRunsTheAction() { - start(request([key(.qr, "code")], available: [.qr], allowBypass: true)) + start(request([key(.qr, "code")], available: [.qr]), allowBypass: true) + #expect(flow.allowsBypass) flow.requestBypass(skippingConfirmation: true) #expect(counter.runs == 1) + #expect(!flow.allowsBypass) #expect(flow.stage == .idle) } @Test func bypassConfirmationRunsTheAction() { - start(request([key(.qr, "code")], available: [.qr], allowBypass: true)) + start(request([key(.qr, "code")], available: [.qr]), allowBypass: true) flow.requestBypass(skippingConfirmation: false) #expect(flow.stage == .confirmingBypass) #expect(flow.sheetScreen == .bypassConfirm) @@ -212,7 +230,7 @@ struct KeyCheckFlowTests { } @Test func goingBackFromTheConfirmationShowsThePicker() { - start(request([key(.qr, "code")], available: [.qr], allowBypass: true)) + start(request([key(.qr, "code")], available: [.qr]), allowBypass: true) flow.requestBypass(skippingConfirmation: false) flow.returnFromBypassConfirm() #expect(flow.stage == .choosing) @@ -220,7 +238,7 @@ struct KeyCheckFlowTests { } @Test func confirmationCannotRunANewerRequest() { - start(request([key(.qr, "code")], available: [.qr], allowBypass: true)) + start(request([key(.qr, "code")], available: [.qr]), allowBypass: true) flow.requestBypass(skippingConfirmation: false) start(qrAndNFC) @@ -250,6 +268,7 @@ struct KeyCheckFlowTests { flow.locationVerified(requestID: request.id) #expect(counter.runs == 1) + #expect(counter.proofs == [KeyProof(keyGroupID: nil)]) #expect(flow.stage == .idle) } diff --git a/NormalTests/Services/KeyProofTests.swift b/NormalTests/Services/KeyProofTests.swift new file mode 100644 index 0000000..5f17c5d --- /dev/null +++ b/NormalTests/Services/KeyProofTests.swift @@ -0,0 +1,59 @@ +import FamilyControls +import Foundation +@testable import Normal +import Testing + +@MainActor +struct KeyProofTests { + private let main = SelectedApps(selection: FamilyActivitySelection()) + private let social = AppGroup(name: "Social", selection: FamilyActivitySelection()) + private let work = AppGroup(name: "Work", selection: FamilyActivitySelection()) + + private final class Counter { + var runs = 0 + } + + @Test func globalKeyCoversEverything() { + let proof = KeyProof(keyGroupID: nil) + #expect(proof.coversAllApps) + #expect(proof.covers(.all(main))) + #expect(proof.covers(.group(social))) + } + + @Test func groupKeyCoversOnlyItsGroup() { + let proof = KeyProof(keyGroupID: social.id) + #expect(!proof.coversAllApps) + #expect(!proof.covers(.all(main))) + #expect(proof.covers(.group(social))) + #expect(!proof.covers(.group(work))) + } + + @Test func grantNeedsAProofThatCoversItsTarget() { + let proof = KeyProof(keyGroupID: social.id) + #expect(UnblockGrant(.group(social), proof: proof)?.target.groupID == social.id) + #expect(UnblockGrant(.all(main), proof: proof) == nil) + #expect(UnblockGrant(.group(work), proof: proof) == nil) + } + + @Test func onlyTighteningAllowsBypass() { + #expect(ProtectedAction.tighten {}.allowsBypass) + #expect(!ProtectedAction.weaken { _ in }.allowsBypass) + } + + @Test func weakeningRunsOnlyWithAProof() { + let counter = Counter() + let action = ProtectedAction.weaken { _ in counter.runs += 1 } + + action.run(with: nil) + #expect(counter.runs == 0) + + action.run(with: KeyProof(keyGroupID: nil)) + #expect(counter.runs == 1) + } + + @Test func tighteningRunsWithoutAProof() { + let counter = Counter() + ProtectedAction.tighten { counter.runs += 1 }.run(with: nil) + #expect(counter.runs == 1) + } +} diff --git a/NormalTests/Services/ScreenTimeServiceTests.swift b/NormalTests/Services/ScreenTimeServiceTests.swift index a8e2963..274adf7 100644 --- a/NormalTests/Services/ScreenTimeServiceTests.swift +++ b/NormalTests/Services/ScreenTimeServiceTests.swift @@ -49,17 +49,33 @@ struct ScreenTimeServiceTests { @Test func adultContentFilterFollowsTheSetting() { let (service, shields) = makeService() - service.setAdultContentBlocked(true) + service.blockAdultContent() #expect(shields.currentShields().blocksAdultContent) #expect(service.isAdultContentBlocked) - service.setAdultContentBlocked(false) + service.allowAdultContent(KeyProof(keyGroupID: nil)) #expect(!shields.currentShields().blocksAdultContent) #expect(!service.isAdultContentBlocked) } + @Test func groupKeyCannotTurnOffAppWideProtections() { + let (service, shields) = makeService() + service.enablePreventAppDelete() + service.blockAdultContent() + let groupProof = KeyProof(keyGroupID: UUID()) + + service.disablePreventAppDelete(groupProof) + service.allowAdultContent(groupProof) + + #expect(service.isAppDeleteDisabled) + #expect(shields.currentShields().blocksAdultContent) + + service.disablePreventAppDelete(KeyProof(keyGroupID: nil)) + #expect(!service.isAppDeleteDisabled) + } + @Test func adultContentFilterIsIndependentOfBlockAll() { let (service, shields) = makeService() - service.setAdultContentBlocked(true) + service.blockAdultContent() #expect(service.activeShieldCount() == 0) service.blockAll(selection: TokenFixtures.selection(apps: [1]), blockAllPreventsAppDelete: true) @@ -71,7 +87,7 @@ struct ScreenTimeServiceTests { @Test func removeAllRestrictionsLiftsAdultContentFilter() { let (service, shields) = makeService() - service.setAdultContentBlocked(true) + service.blockAdultContent() service.blockAll(selection: TokenFixtures.selection(apps: [1]), blockAllPreventsAppDelete: true) service.removeAllRestrictions() diff --git a/NormalTests/Services/UnblockTargetTests.swift b/NormalTests/Services/UnblockTargetTests.swift index 5045921..0d1b4a3 100644 --- a/NormalTests/Services/UnblockTargetTests.swift +++ b/NormalTests/Services/UnblockTargetTests.swift @@ -13,6 +13,10 @@ struct UnblockTargetTests { service = TimedUnblockService(activityCenter: activity, sharedStore: store, onExpiration: {}) } + private func grant(_ target: UnblockTarget) throws -> UnblockGrant { + try #require(UnblockGrant(target, proof: KeyProof(keyGroupID: nil))) + } + private func settings(customDomains: Bool) -> Settings { let settings = Settings() settings.enableCustomDomains = customDomains @@ -23,7 +27,7 @@ struct UnblockTargetTests { @Test func startingAllStartsTheMainUnblock() throws { let main = SelectedApps(selection: FamilyActivitySelection(), customDomains: ["a.com"]) - try service.start(.all(main), duration: .oneHour, settings: settings(customDomains: true), screenTimeService: screenTime) + try service.start(grant(.all(main)), duration: .oneHour, settings: settings(customDomains: true), screenTimeService: screenTime) #expect(service.isMainUnblockActive) #expect(store.timedUnblocks.first?.customDomains == ["a.com"]) @@ -33,7 +37,7 @@ struct UnblockTargetTests { @Test func startingAGroupStartsItsUnblock() throws { let group = AppGroup(name: "Social", selection: FamilyActivitySelection(), customDomains: ["b.com"]) - try service.start(.group(group), duration: .oneHour, settings: settings(customDomains: true), screenTimeService: screenTime) + try service.start(grant(.group(group)), duration: .oneHour, settings: settings(customDomains: true), screenTimeService: screenTime) #expect(service.isGroupUnblockActive(groupId: group.id)) #expect(store.timedUnblocks.first?.customDomains == ["b.com"]) @@ -43,25 +47,25 @@ struct UnblockTargetTests { @Test func customDomainsAreLeftOutWhenTurnedOff() throws { let group = AppGroup(name: "Social", selection: FamilyActivitySelection(), customDomains: ["b.com"]) - try service.start(.group(group), duration: .oneHour, settings: settings(customDomains: false), screenTimeService: screenTime) + try service.start(grant(.group(group)), duration: .oneHour, settings: settings(customDomains: false), screenTimeService: screenTime) #expect(store.timedUnblocks.first?.customDomains == []) } - @Test func permanentlyUnblockingAllUnblocksEverything() { + @Test func permanentlyUnblockingAllUnblocksEverything() throws { let main = SelectedApps(selection: FamilyActivitySelection()) - screenTime.unblockPermanently(.all(main), settings: settings(customDomains: true)) + try screenTime.unblockPermanently(grant(.all(main)), settings: settings(customDomains: true)) #expect(screenTime.unblockAllCalled) #expect(screenTime.unblockAllPreventsAppDelete == false) #expect(!screenTime.unblockCalled) } - @Test func permanentlyUnblockingAGroupUnblocksItsSelection() { + @Test func permanentlyUnblockingAGroupUnblocksItsSelection() throws { let group = AppGroup(name: "Social", selection: FamilyActivitySelection(), customDomains: ["b.com"]) - screenTime.unblockPermanently(.group(group), settings: settings(customDomains: true)) + try screenTime.unblockPermanently(grant(.group(group)), settings: settings(customDomains: true)) #expect(screenTime.unblockCalled) #expect(screenTime.unblockCustomDomains == ["b.com"]) @@ -75,13 +79,13 @@ struct UnblockTargetTests { @Test func groupWithATimerCannotBeUnblockedAgain() throws { let group = AppGroup(name: "Social", selection: FamilyActivitySelection()) - try service.start(.group(group), duration: .oneHour, settings: settings(customDomains: false), screenTimeService: screenTime) + try service.start(grant(.group(group)), duration: .oneHour, settings: settings(customDomains: false), screenTimeService: screenTime) #expect(!UnblockTarget.group(group).canUnblock(status: .some, timedUnblockService: service)) } @Test func allAppsWithATimerCannotBeUnblockedAgain() throws { let main = SelectedApps(selection: FamilyActivitySelection()) - try service.start(.all(main), duration: .oneHour, settings: settings(customDomains: false), screenTimeService: screenTime) + try service.start(grant(.all(main)), duration: .oneHour, settings: settings(customDomains: false), screenTimeService: screenTime) #expect(!UnblockTarget.all(main).canUnblock(status: .all, timedUnblockService: service)) } } diff --git a/NormalTests/TestSupport/FakeScreenTimeService.swift b/NormalTests/TestSupport/FakeScreenTimeService.swift index ef816f9..c3ff1da 100644 --- a/NormalTests/TestSupport/FakeScreenTimeService.swift +++ b/NormalTests/TestSupport/FakeScreenTimeService.swift @@ -63,7 +63,7 @@ final class FakeScreenTimeService: ScreenTimeProviding { enablePreventAppDeleteCalled = true } - func disablePreventAppDelete() { + func disablePreventAppDelete(_: KeyProof) { disablePreventAppDeleteCalled = true } @@ -85,13 +85,13 @@ final class FakeScreenTimeService: ScreenTimeProviding { unblockAllCalled = true unblockAllPreventsAppDelete = blockAllPreventsAppDelete if blockAllPreventsAppDelete { - disablePreventAppDelete() + disablePreventAppDeleteCalled = true } } func removeAllRestrictions() { removeAllRestrictionsCalled = true - disablePreventAppDelete() + disablePreventAppDeleteCalled = true } func block(selection: FamilyActivitySelection, customDomains: [String] = []) { diff --git a/NormalTests/TestSupport/StatefulScreenTimeSpy.swift b/NormalTests/TestSupport/StatefulScreenTimeSpy.swift index 319bf0a..65f8381 100644 --- a/NormalTests/TestSupport/StatefulScreenTimeSpy.swift +++ b/NormalTests/TestSupport/StatefulScreenTimeSpy.swift @@ -44,7 +44,7 @@ final class StatefulScreenTimeSpy: ScreenTimeProviding { checkInvariant() } - func disablePreventAppDelete() { + func disablePreventAppDelete(_: KeyProof) { appDeleteDisabled = false checkInvariant() }