getSecuritySnapshot method

Future<DeviceSecuritySnapshot> getSecuritySnapshot()

Retrieves a consolidated snapshot of all security statuses at once.

This is useful for performing a single, comprehensive security check (e.g., during app startup or login) without having to manage multiple subscriptions.

Note: The status checks time out after 2 seconds and default to false to prevent the app from hanging if the native platform fails to respond.

Implementation

Future<DeviceSecuritySnapshot> getSecuritySnapshot() async {
  // Fire them all off concurrently for speed
  final results = await Future.wait([
    getDeviceId(),
    getUsbConnectedStatus().first.timeout(
      const Duration(seconds: 2),
      onTimeout: () {
        debugPrint('Usb connected status timed out');
        return false;
      },
    ),
    getDebugModeStatus().first.timeout(
      const Duration(seconds: 2),
      onTimeout: () {
        debugPrint('Debug mode status timed out');
        return false;
      },
    ),
    getVpnConnectionStatus().first.timeout(
      const Duration(seconds: 2),
      onTimeout: () {
        debugPrint('Vpn connection status timed out');
        return false;
      },
    ),
  ]);
  return DeviceSecuritySnapshot(
    deviceId: results[0] as String?,
    isUsbConnected: (results[1] as bool?) ?? false,
    isDebugMode: (results[2] as bool?) ?? false,
    isVpnConnected: (results[3] as bool?) ?? false,
  );
}