5c41474e6a
Schedule reconnects with idle-tolerant alarms, keep a watchdog and wake lock, and restart after task removal so delivery continues while the app is closed. Request battery exemption, stop retrying on expired sessions, persist connection diagnostics, and expose the status in Settings.
95 lines
2.7 KiB
Dart
95 lines
2.7 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:pipelines_app/features/notification_service/notification_service_bridge.dart';
|
|
|
|
/// A scripted background service: records calls and reports [current].
|
|
class FakeNotificationService implements NotificationServiceBridge {
|
|
FakeNotificationService({NotificationServiceStatus? status})
|
|
: current =
|
|
status ??
|
|
const NotificationServiceStatus(
|
|
enabled: true,
|
|
configured: true,
|
|
state: DeliveryState.connected,
|
|
notificationsAllowed: true,
|
|
batteryExempt: false,
|
|
);
|
|
|
|
NotificationServiceStatus current;
|
|
List<NotificationConnectionEvent> events = const [];
|
|
final calls = <(String, Map<String, Object?>)>[];
|
|
final _changes = StreamController<NotificationServiceStatus>.broadcast();
|
|
bool batteryGranted = true;
|
|
|
|
void push(NotificationServiceStatus status) {
|
|
current = status;
|
|
_changes.add(status);
|
|
}
|
|
|
|
NotificationServiceStatus copy({
|
|
bool? enabled,
|
|
DeliveryState? state,
|
|
bool? notificationsAllowed,
|
|
bool? batteryExempt,
|
|
}) => NotificationServiceStatus(
|
|
enabled: enabled ?? current.enabled,
|
|
configured: current.configured,
|
|
state: state ?? current.state,
|
|
notificationsAllowed: notificationsAllowed ?? current.notificationsAllowed,
|
|
batteryExempt: batteryExempt ?? current.batteryExempt,
|
|
);
|
|
|
|
@override
|
|
bool get supported => true;
|
|
|
|
@override
|
|
Stream<NotificationServiceStatus> get changes => _changes.stream;
|
|
|
|
@override
|
|
Future<NotificationServiceStatus> status() async {
|
|
calls.add(('status', const {}));
|
|
return current;
|
|
}
|
|
|
|
@override
|
|
Future<NotificationServiceStatus> start() async {
|
|
calls.add(('start', const {}));
|
|
return current;
|
|
}
|
|
|
|
@override
|
|
Future<NotificationServiceStatus> configure({
|
|
required String serverId,
|
|
required List<String> endpoints,
|
|
required String cookie,
|
|
}) async {
|
|
calls.add((
|
|
'configure',
|
|
{'serverId': serverId, 'endpoints': endpoints, 'cookie': cookie},
|
|
));
|
|
return current;
|
|
}
|
|
|
|
@override
|
|
Future<NotificationServiceStatus> setEnabled(bool enabled) async {
|
|
calls.add(('setEnabled', {'enabled': enabled}));
|
|
current = copy(
|
|
enabled: enabled,
|
|
state: enabled ? DeliveryState.connecting : DeliveryState.off,
|
|
);
|
|
return current;
|
|
}
|
|
|
|
@override
|
|
Future<bool> requestBatteryExemption() async {
|
|
calls.add(('requestBatteryExemption', const {}));
|
|
if (batteryGranted) current = copy(batteryExempt: true);
|
|
return true;
|
|
}
|
|
|
|
// Not recorded in [calls]: the log is re-read after every action, and the
|
|
// tests assert on the action calls themselves.
|
|
@override
|
|
Future<List<NotificationConnectionEvent>> connectionEvents() async => events;
|
|
}
|