mirror of
https://github.com/block/buzz.git
synced 2026-11-28 04:01:45 +00:00
Follow-up to [#9804 handle Android push wakes](https://github.com/block/buzz/pull/9804), from its review: a confirmed age restriction now applies to Android push wakes, as it already does on iOS. ## What it does - A new native `AgeRestriction` holds a confirmed restriction for the life of the app process. Like the iOS restriction session, nothing is saved: a later launch starts unrestricted and the age check runs again. - The age gate's purge (`purgeAgeRestrictedNotifications`) now runs on Android. It sets the restriction and cancels every notification Buzz has posted. Restore (`restoreAgeRestrictedNotifications`) clears it. Both were iOS-only before. - On Android the restriction is released only when an age check in the current engine finishes without restricting (allowed, or failing open). The process can outlive the engine, for example after Back from the restricted screen, and a reopened app starts its age state as allowed, so releasing on that first build would lift a restriction the process still holds before the new check answers. A retired check releases nothing. iOS keeps restoring from the push bootstrap as before. - The purge starts as soon as the age check confirms a restriction, not when the restricted screen first draws. The check can answer while Buzz is in the background, where Flutter draws no frames until the user returns, so before this wakes kept posting until then. This also closes the same gap on iOS. The restricted screen still retries a failed purge, and a retry that a resume has replaced stays quiet, so a late failure can't purge again. - While the restriction holds, a push wake is skipped before it fetches anything, the same way as when notifications are turned off. - Every post from a wake (conversations and the generic "New activity") checks the restriction under the same lock the purge takes. So a wake already running when the restriction arrives posts nothing after the purge, and a post already in progress finishes before the purge cancels it. ## Decisions - **Process lifetime, as on iOS.** Wakes run in the app's process, so an in-memory flag covers every wake while the confirming process lives. A wake that starts a fresh process (after the app was killed) is not restricted until the app runs its check again. That matches iOS, where the restriction ends with the process holding its lock. - **No release-config change here.** `BUZZ_AGE_GATING_ENABLED` is still set only for iOS builds, and no build sets the Firebase config yet. Adding either to an Android build is a separate release change. ### Validation Added tests: [`AgeRestrictionTest.kt`](https://github.com/block/buzz/blob/android-push-age-gate/mobile/android/app/src/test/kotlin/xyz/block/buzz/mobile/AgeRestrictionTest.kt) covers restrict, release and a post that is in progress when the restriction arrives. [`push_bridge_test.dart`](https://github.com/block/buzz/blob/android-push-age-gate/mobile/test/shared/push/push_bridge_test.dart) now covers the purge and restore calls on iOS and Android. The age gate's outcome table now runs on Android and counts releases: none while the check is pending, one after an adult, error, malformed or timed-out result, none after a minor. [`age_signal_provider_test.dart`](https://github.com/block/buzz/blob/android-push-age-gate/mobile/test/features/age_gate/age_signal_provider_test.dart)'s upper-bound table now also checks that a confirmed restriction starts the purge with no widget or frame involved. [`age_gate_app_test.dart`](https://github.com/block/buzz/blob/android-push-age-gate/mobile/test/features/age_gate/age_gate_app_test.dart)'s purge retry test now uses the real notifier, with a resume while the first purge is still running. On a Pixel 9a (Android 16), a debug build with a local test relay. A temporary debug hook called the native restrict and release directly, because the phone was locked and Flutter doesn't draw frames behind the lock screen: 1. Allowed: a wake posted the new message. 2. Restrict: the posted notification was removed. 3. While restricted: a wake logged `wake ignored foreground=false restricted=true` and posted nothing. 4. Release: the next wake posted both the message that arrived during the restriction and the new one. The Dart side calling purge and restore is covered by the bridge test above. ## Regressions None expected: without age gating enabled, the restriction is never set on Android. --------- Signed-off-by: Tom Brow <tomb@block.xyz> Co-authored-by: studio <dc2fc481343672df31a689840c09299972e704dac592e0da6f18486646a7ee3e@localhost>
587 lines
20 KiB
Dart
587 lines
20 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
|
import 'dart:convert';
|
|
|
|
import 'package:buzz/app.dart';
|
|
import 'package:buzz/features/age_gate/age_restriction_page.dart';
|
|
import 'package:buzz/features/age_gate/age_signal_push_bootstrap.dart';
|
|
import 'package:buzz/features/age_gate/age_signal_provider.dart';
|
|
import 'package:buzz/features/channels/unread_badge/unread_badge_provider.dart';
|
|
import 'package:buzz/features/home/home_page.dart';
|
|
import 'package:buzz/features/pairing/pairing_provider.dart';
|
|
import 'package:buzz/shared/auth/auth.dart';
|
|
import 'package:buzz/shared/huddle/huddle.dart';
|
|
import 'package:nostr/nostr.dart' as nostr;
|
|
import '../../shared/community/community_storage_test.dart'
|
|
show FakeSecureStorage;
|
|
import 'package:buzz/shared/push/push_bootstrap.dart';
|
|
import 'package:buzz/shared/relay/relay.dart';
|
|
import 'package:buzz/shared/theme/theme_provider.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
void main() {
|
|
TestWidgetsFlutterBinding.ensureInitialized();
|
|
setUp(() => FlutterSecureStorage.setMockInitialValues({}));
|
|
const appBadgeChannel = MethodChannel('app_badge_plus');
|
|
|
|
tearDown(() {
|
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
|
.setMockMethodCallHandler(ageSignalChannel, null);
|
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
|
.setMockMethodCallHandler(appBadgeChannel, null);
|
|
});
|
|
|
|
testWidgets(
|
|
'an in-flight credential commit cannot reopen restricted access',
|
|
(tester) async {
|
|
SharedPreferences.setMockInitialValues({});
|
|
final prefs = await SharedPreferences.getInstance();
|
|
final storage = _PausedCommunityStorage();
|
|
final age = _MutableAgeSignalNotifier();
|
|
var connections = 0;
|
|
final relay = RelaySessionNotifier(
|
|
socketFactory:
|
|
({
|
|
required wsUrl,
|
|
required nsec,
|
|
required onMessage,
|
|
required onConnected,
|
|
required onDisconnected,
|
|
}) {
|
|
connections++;
|
|
throw StateError(
|
|
'Restricted authentication must not open a socket',
|
|
);
|
|
},
|
|
);
|
|
final container = ProviderContainer(
|
|
overrides: [
|
|
savedPrefsProvider.overrideWithValue(prefs),
|
|
communityStorageProvider.overrideWithValue(storage),
|
|
communitySnapshotWriterProvider.overrideWithValue((_) async {}),
|
|
ageSignalProvider.overrideWith(() => age),
|
|
relaySessionProvider.overrideWith(() => relay),
|
|
pairingProvider.overrideWith(
|
|
() => PairingNotifier(
|
|
credentialValidator:
|
|
({required relayUrl, required nsec}) async {},
|
|
),
|
|
),
|
|
],
|
|
);
|
|
addTearDown(container.dispose);
|
|
await container.read(authProvider.future);
|
|
final listener = container.listen(relaySessionProvider, (_, _) {});
|
|
addTearDown(listener.close);
|
|
await tester.pumpWidget(
|
|
UncontrolledProviderScope(container: container, child: const App()),
|
|
);
|
|
await tester.pump();
|
|
final code = base64Url.encode(
|
|
utf8.encode(
|
|
jsonEncode({
|
|
'relayUrl': 'https://relay.example',
|
|
'nsec': nostr.Keys.generate().nsec,
|
|
}),
|
|
),
|
|
);
|
|
final pairing = container.read(pairingProvider.notifier).pair(code);
|
|
await tester.pump();
|
|
expect(storage.started.isCompleted, isTrue);
|
|
age.setState(AgeSignalState.restricted);
|
|
await tester.pump();
|
|
expect(find.byType(AgeRestrictionPage), findsOneWidget);
|
|
storage.release.complete();
|
|
await pairing;
|
|
await tester.pump();
|
|
expect((await storage.loadAll()), hasLength(1));
|
|
expect(
|
|
(await container.read(authProvider.future)).status,
|
|
AuthStatus.authenticated,
|
|
);
|
|
expect(container.read(pairingProvider).status, PairingStatus.idle);
|
|
expect(find.byType(AgeRestrictionPage), findsOneWidget);
|
|
expect(
|
|
container.read(relaySessionProvider).status,
|
|
SessionStatus.disconnected,
|
|
);
|
|
expect(connections, 0);
|
|
expect(
|
|
container.read(huddleSessionProvider).phase,
|
|
HuddleSessionPhase.idle,
|
|
);
|
|
await tester.pumpWidget(const SizedBox.shrink());
|
|
listener.close();
|
|
container.dispose();
|
|
await tester.pump(const Duration(milliseconds: 1));
|
|
},
|
|
);
|
|
|
|
test('backs off repeated snapshot transition failures', () {
|
|
expect(ageSignalPushSnapshotRetryDelay(0), const Duration(seconds: 5));
|
|
expect(ageSignalPushSnapshotRetryDelay(1), const Duration(seconds: 10));
|
|
expect(ageSignalPushSnapshotRetryDelay(5), const Duration(seconds: 160));
|
|
expect(ageSignalPushSnapshotRetryDelay(6), const Duration(minutes: 5));
|
|
expect(ageSignalPushSnapshotRetryDelay(100), const Duration(minutes: 5));
|
|
});
|
|
|
|
for (final restrict in [false, true]) {
|
|
testWidgets('pending legacy pairing follows restriction=$restrict', (
|
|
tester,
|
|
) async {
|
|
SharedPreferences.setMockInitialValues({});
|
|
final prefs = await SharedPreferences.getInstance();
|
|
final age = _MutableAgeSignalNotifier();
|
|
final auth = _RecordingPairAuthNotifier();
|
|
final validation = Completer<void>();
|
|
final pairing = PairingNotifier(
|
|
credentialValidator: ({required relayUrl, required nsec}) =>
|
|
validation.future,
|
|
);
|
|
final container = ProviderContainer(
|
|
overrides: [
|
|
savedPrefsProvider.overrideWithValue(prefs),
|
|
authProvider.overrideWith(() => auth),
|
|
ageSignalProvider.overrideWith(() => age),
|
|
pairingProvider.overrideWith(() => pairing),
|
|
],
|
|
);
|
|
addTearDown(container.dispose);
|
|
await tester.pumpWidget(
|
|
UncontrolledProviderScope(container: container, child: const App()),
|
|
);
|
|
await tester.pump();
|
|
final code = base64Url.encode(
|
|
utf8.encode(
|
|
jsonEncode({
|
|
'relayUrl': 'https://relay.example',
|
|
'nsec': 'pending-key',
|
|
}),
|
|
),
|
|
);
|
|
final pending = container.read(pairingProvider.notifier).pair(code);
|
|
expect(container.read(pairingProvider).status, PairingStatus.connecting);
|
|
if (restrict) age.setState(AgeSignalState.restricted);
|
|
await tester.pump();
|
|
validation.complete();
|
|
await pending;
|
|
expect(auth.imports, restrict ? 0 : 1);
|
|
expect(
|
|
container.read(pairingProvider).status,
|
|
restrict ? PairingStatus.idle : PairingStatus.success,
|
|
);
|
|
await tester.pumpWidget(const SizedBox.shrink());
|
|
});
|
|
}
|
|
|
|
testWidgets('blocks authenticated app content', (tester) async {
|
|
SharedPreferences.setMockInitialValues({});
|
|
final prefs = await SharedPreferences.getInstance();
|
|
|
|
await tester.pumpWidget(
|
|
ProviderScope(
|
|
overrides: [
|
|
authProvider.overrideWith(() => _AuthenticatedAuthNotifier()),
|
|
ageSignalProvider.overrideWith(() => _BlockingAgeSignalNotifier()),
|
|
savedPrefsProvider.overrideWithValue(prefs),
|
|
],
|
|
child: const AgeSignalPushBootstrap(child: App()),
|
|
),
|
|
);
|
|
await tester.pump();
|
|
|
|
expect(find.byType(AgeRestrictionPage), findsOneWidget);
|
|
expect(find.byType(HomePage), findsNothing);
|
|
});
|
|
|
|
testWidgets('clears the app badge only after a confirmed restriction', (
|
|
tester,
|
|
) async {
|
|
final badgeCounts = <int>[];
|
|
final ageSignal = _MutableAgeSignalNotifier();
|
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
|
.setMockMethodCallHandler(appBadgeChannel, (call) async {
|
|
if (call.method == 'updateBadge') {
|
|
badgeCounts.add(
|
|
(call.arguments as Map<Object?, Object?>)['count']! as int,
|
|
);
|
|
}
|
|
return null;
|
|
});
|
|
SharedPreferences.setMockInitialValues({});
|
|
final prefs = await SharedPreferences.getInstance();
|
|
|
|
await tester.pumpWidget(
|
|
ProviderScope(
|
|
overrides: [
|
|
authProvider.overrideWith(() => _UnauthenticatedAuthNotifier()),
|
|
ageSignalProvider.overrideWith(() => ageSignal),
|
|
unreadBadgeProvider.overrideWithValue(
|
|
const UnreadBadgeState(highPriorityCount: 7),
|
|
),
|
|
savedPrefsProvider.overrideWithValue(prefs),
|
|
],
|
|
child: const App(),
|
|
),
|
|
);
|
|
await tester.pump();
|
|
|
|
expect(badgeCounts, isNotEmpty);
|
|
expect(badgeCounts.last, 7);
|
|
|
|
ageSignal.setState(AgeSignalState.allowed);
|
|
await tester.pump();
|
|
expect(badgeCounts.last, 7);
|
|
|
|
ageSignal.setState(AgeSignalState.restricted);
|
|
await tester.pump();
|
|
expect(badgeCounts.last, 0);
|
|
});
|
|
|
|
testWidgets(
|
|
'opens app and restores push snapshots without a native age check',
|
|
(tester) async {
|
|
final relaySession = _CountingRelaySessionNotifier();
|
|
var requests = 0;
|
|
var snapshotRestorations = 0;
|
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
|
.setMockMethodCallHandler(ageSignalChannel, (call) {
|
|
requests += 1;
|
|
throw PlatformException(code: 'unavailable');
|
|
});
|
|
SharedPreferences.setMockInitialValues({});
|
|
final prefs = await SharedPreferences.getInstance();
|
|
|
|
await tester.pumpWidget(
|
|
ProviderScope(
|
|
overrides: [
|
|
authProvider.overrideWith(() => _AuthenticatedAuthNotifier()),
|
|
relaySessionProvider.overrideWith(() => relaySession),
|
|
ageAllowedNotificationRestorerProvider.overrideWithValue(() async {
|
|
snapshotRestorations += 1;
|
|
if (snapshotRestorations == 1) {
|
|
throw StateError('injected restoration failure');
|
|
}
|
|
}),
|
|
ageSignalPushSnapshotRetryWaitProvider.overrideWithValue(
|
|
(_) async {},
|
|
),
|
|
savedPrefsProvider.overrideWithValue(prefs),
|
|
],
|
|
child: const AgeSignalPushBootstrap(child: App()),
|
|
),
|
|
);
|
|
|
|
await tester.pump();
|
|
await tester.pump();
|
|
|
|
expect(find.bySemanticsLabel('Checking age eligibility'), findsNothing);
|
|
expect(find.byType(HomePage), findsOneWidget);
|
|
// Home may also host a nested conversation navigator.
|
|
expect(find.byType(MaterialApp), findsOneWidget);
|
|
expect(relaySession.builds, 1);
|
|
expect(requests, ageGatingEnabled ? 1 : 0);
|
|
await tester.pump();
|
|
await tester.pump();
|
|
expect(snapshotRestorations, 2);
|
|
},
|
|
// iOS restores from the push bootstrap, retrying a failure.
|
|
variant: TargetPlatformVariant.only(TargetPlatform.iOS),
|
|
);
|
|
|
|
for (final outcome in ['minor', 'adult', 'error', 'malformed', 'timeout']) {
|
|
testWidgets('normal app and push start before native $outcome result', (
|
|
tester,
|
|
) async {
|
|
// On Android only a check that finishes allowed releases the native
|
|
// restriction, which a live process may still hold from an earlier
|
|
// engine; the first, still-pending build releases nothing.
|
|
final response = Completer<Object?>();
|
|
var requests = 0;
|
|
var restrictions = 0;
|
|
var restores = 0;
|
|
final relaySession = _CountingRelaySessionNotifier();
|
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
|
.setMockMethodCallHandler(ageSignalChannel, (_) {
|
|
requests += 1;
|
|
return response.future;
|
|
});
|
|
SharedPreferences.setMockInitialValues({});
|
|
final prefs = await SharedPreferences.getInstance();
|
|
await tester.pumpWidget(
|
|
ProviderScope(
|
|
overrides: [
|
|
authProvider.overrideWith(() => _AuthenticatedAuthNotifier()),
|
|
relaySessionProvider.overrideWith(() => relaySession),
|
|
ageSignalProvider.overrideWith(
|
|
() =>
|
|
AgeSignalNotifier(requestTimeout: const Duration(seconds: 1)),
|
|
),
|
|
ageAllowedNotificationRestorerProvider.overrideWithValue(
|
|
() async => restores++,
|
|
),
|
|
ageRestrictedNotificationPurgerProvider.overrideWithValue(() async {
|
|
restrictions++;
|
|
}),
|
|
savedPrefsProvider.overrideWithValue(prefs),
|
|
],
|
|
child: const AgeSignalPushBootstrap(child: App()),
|
|
),
|
|
);
|
|
await tester.pump();
|
|
expect(find.byType(HomePage), findsOneWidget);
|
|
expect(find.byType(BuzzPushBootstrap), findsOneWidget);
|
|
expect(relaySession.builds, 1);
|
|
expect(requests, 1);
|
|
expect(restores, 0);
|
|
|
|
if (outcome == 'timeout') {
|
|
await tester.pump(const Duration(seconds: 2));
|
|
response.complete({'status': 'signal', 'ageUpper': 17});
|
|
} else if (outcome == 'error') {
|
|
response.completeError(PlatformException(code: 'unavailable'));
|
|
} else if (outcome == 'malformed') {
|
|
response.complete({'status': 'signal', 'ageUpper': '17'});
|
|
} else {
|
|
response.complete({
|
|
'status': 'signal',
|
|
'ageUpper': outcome == 'minor' ? 17 : 18,
|
|
});
|
|
}
|
|
await tester.pump();
|
|
await tester.pump();
|
|
final restricted = outcome == 'minor';
|
|
expect(restrictions, restricted ? 1 : 0);
|
|
expect(restores, restricted ? 0 : 1);
|
|
expect(
|
|
find.byType(AgeRestrictionPage),
|
|
restricted ? findsOneWidget : findsNothing,
|
|
);
|
|
expect(find.byType(HomePage), restricted ? findsNothing : findsOneWidget);
|
|
expect(
|
|
find.byType(BuzzPushBootstrap),
|
|
restricted ? findsNothing : findsOneWidget,
|
|
);
|
|
await tester.pumpWidget(const SizedBox.shrink());
|
|
await tester.pump();
|
|
}, variant: TargetPlatformVariant.only(TargetPlatform.android));
|
|
}
|
|
|
|
testWidgets(
|
|
'purges restricted notifications before community storage recovers',
|
|
(tester) async {
|
|
var purges = 0;
|
|
|
|
await tester.pumpWidget(
|
|
ProviderScope(
|
|
retry: (_, _) => null,
|
|
overrides: [
|
|
ageSignalProvider.overrideWith(() => _BlockingAgeSignalNotifier()),
|
|
communityListProvider.overrideWith(
|
|
() => _UnavailableCommunityListNotifier(),
|
|
),
|
|
ageRestrictedNotificationPurgerProvider.overrideWithValue(() async {
|
|
purges += 1;
|
|
}),
|
|
],
|
|
child: const AgeSignalPushBootstrap(child: SizedBox()),
|
|
),
|
|
);
|
|
await tester.pump();
|
|
|
|
expect(purges, 1);
|
|
},
|
|
);
|
|
|
|
testWidgets('retries a failed restricted notification purge', (tester) async {
|
|
var purges = 0;
|
|
final firstPurge = Completer<void>();
|
|
final container = ProviderContainer(
|
|
overrides: [
|
|
ageSignalProvider.overrideWith(
|
|
() => AgeSignalNotifier(
|
|
requestSignal: () async => {'status': 'signal', 'ageUpper': 17},
|
|
),
|
|
),
|
|
communityListProvider.overrideWith(
|
|
() => _UnavailableCommunityListNotifier(),
|
|
),
|
|
ageAllowedNotificationRestorerProvider.overrideWithValue(() async {}),
|
|
ageRestrictedNotificationPurgerProvider.overrideWithValue(() {
|
|
purges += 1;
|
|
return switch (purges) {
|
|
1 => firstPurge.future,
|
|
2 => Future.error(
|
|
StateError('injected notification purge failure'),
|
|
),
|
|
_ => Future.value(),
|
|
};
|
|
}),
|
|
ageRestrictedNotificationMaintenanceScheduleProvider.overrideWithValue(
|
|
(_) => () {},
|
|
),
|
|
ageSignalPushSnapshotRetryWaitProvider.overrideWithValue((_) async {}),
|
|
],
|
|
);
|
|
addTearDown(container.dispose);
|
|
await container.read(ageSignalProvider.notifier).request();
|
|
expect(container.read(ageSignalProvider), AgeSignalState.restricted);
|
|
|
|
await tester.pumpWidget(
|
|
UncontrolledProviderScope(
|
|
container: container,
|
|
child: const AgeSignalPushBootstrap(child: SizedBox()),
|
|
),
|
|
);
|
|
await tester.pump();
|
|
expect(purges, 1);
|
|
|
|
// A resume while the confirmed purge is still running retires the effect
|
|
// waiting on it. The new effect purges, fails once and retries.
|
|
for (final state in [
|
|
AppLifecycleState.inactive,
|
|
AppLifecycleState.hidden,
|
|
AppLifecycleState.paused,
|
|
AppLifecycleState.hidden,
|
|
AppLifecycleState.inactive,
|
|
AppLifecycleState.resumed,
|
|
]) {
|
|
tester.binding.handleAppLifecycleStateChanged(state);
|
|
}
|
|
await tester.pump();
|
|
await tester.pump();
|
|
expect(purges, 3);
|
|
|
|
firstPurge.completeError(StateError('injected notification purge failure'));
|
|
await tester.pump();
|
|
await tester.pump();
|
|
|
|
expect(purges, 3);
|
|
});
|
|
|
|
testWidgets(
|
|
'retries a successful purge for interactions donated by stale extensions',
|
|
(tester) async {
|
|
var purges = 0;
|
|
final scheduledMaintenance = <VoidCallback>[];
|
|
|
|
await tester.pumpWidget(
|
|
ProviderScope(
|
|
overrides: [
|
|
ageSignalProvider.overrideWith(() => _BlockingAgeSignalNotifier()),
|
|
communityListProvider.overrideWith(
|
|
() => _UnavailableCommunityListNotifier(),
|
|
),
|
|
ageRestrictedNotificationPurgerProvider.overrideWithValue(() async {
|
|
purges += 1;
|
|
}),
|
|
ageRestrictedNotificationMaintenanceScheduleProvider
|
|
.overrideWithValue((callback) {
|
|
scheduledMaintenance.add(callback);
|
|
return () {};
|
|
}),
|
|
],
|
|
child: const AgeSignalPushBootstrap(child: SizedBox()),
|
|
),
|
|
);
|
|
await tester.pump();
|
|
expect(purges, 1);
|
|
expect(scheduledMaintenance, hasLength(1));
|
|
|
|
for (
|
|
var attempt = 0;
|
|
attempt < ageRestrictedNotificationMaintenancePurgeLimit;
|
|
attempt += 1
|
|
) {
|
|
scheduledMaintenance.removeAt(0)();
|
|
await tester.pump();
|
|
await tester.pump();
|
|
}
|
|
|
|
expect(purges, 1 + ageRestrictedNotificationMaintenancePurgeLimit);
|
|
expect(scheduledMaintenance, isEmpty);
|
|
},
|
|
);
|
|
}
|
|
|
|
class _AuthenticatedAuthNotifier extends AuthNotifier {
|
|
@override
|
|
Future<AuthState> build() async {
|
|
return const AuthState(status: AuthStatus.authenticated);
|
|
}
|
|
}
|
|
|
|
class _UnauthenticatedAuthNotifier extends AuthNotifier {
|
|
@override
|
|
Future<AuthState> build() async {
|
|
return const AuthState(status: AuthStatus.unauthenticated);
|
|
}
|
|
}
|
|
|
|
class _MutableAgeSignalNotifier extends AgeSignalNotifier {
|
|
@override
|
|
AgeSignalState build() => AgeSignalState.allowed;
|
|
|
|
@override
|
|
Future<void> request() async {}
|
|
|
|
void setState(AgeSignalState next) => state = next;
|
|
}
|
|
|
|
class _BlockingAgeSignalNotifier extends AgeSignalNotifier {
|
|
@override
|
|
AgeSignalState build() => AgeSignalState.restricted;
|
|
|
|
@override
|
|
Future<void> request() async {}
|
|
}
|
|
|
|
class _CountingRelaySessionNotifier extends RelaySessionNotifier {
|
|
int builds = 0;
|
|
|
|
@override
|
|
SessionState build() {
|
|
builds += 1;
|
|
return const SessionState(status: SessionStatus.disconnected);
|
|
}
|
|
}
|
|
|
|
class _UnavailableCommunityListNotifier extends CommunityListNotifier {
|
|
@override
|
|
Future<List<Community>> build() async {
|
|
throw StateError('secure storage unavailable');
|
|
}
|
|
}
|
|
|
|
class _RecordingPairAuthNotifier extends _UnauthenticatedAuthNotifier {
|
|
int imports = 0;
|
|
|
|
@override
|
|
Future<void> authenticateWithCommunity(
|
|
Community community, {
|
|
bool Function()? shouldContinue,
|
|
bool activate = true,
|
|
}) async {
|
|
if (shouldContinue != null && !shouldContinue()) return;
|
|
imports += 1;
|
|
}
|
|
}
|
|
|
|
class _PausedCommunityStorage extends CommunityStorage {
|
|
_PausedCommunityStorage() : super(secure: FakeSecureStorage());
|
|
final started = Completer<void>();
|
|
final release = Completer<void>();
|
|
|
|
@override
|
|
Future<void> save(Community community) async {
|
|
started.complete();
|
|
await release.future;
|
|
await super.save(community);
|
|
}
|
|
}
|