getDeviceSecurityStatus method

Future<DeviceSecurityStatus> getDeviceSecurityStatus()

Get device security status

Implementation

Future<DeviceSecurityStatus> getDeviceSecurityStatus() async {
  try {
    final isRooted = await _checkRootStatus();
    final isJailbroken = await _checkJailbreakStatus();
    final isEmulator = await _checkEmulatorStatus();
    final isDebuggerAttached = await _checkDebuggerStatus();
    final hasProxy = await _checkProxyStatus();
    final hasVPN = await _checkVPNStatus();
    final isScreenCaptureBlocked = _config?.enableScreenshotBlocking ?? false;
    final isSSLValid = await _checkSSLStatus();
    final isDeveloperModeEnabled = await _checkDeveloperModeStatus();
    final isUsbCableAttached = await _checkUsbCableStatus();

    final riskScore = _calculateRiskScore(
      isRooted: isRooted,
      isJailbroken: isJailbroken,
      isEmulator: isEmulator,
      isDebuggerAttached: isDebuggerAttached,
      hasProxy: hasProxy,
      hasVPN: hasVPN,
      isDeveloperModeEnabled: isDeveloperModeEnabled,
    );

    return DeviceSecurityStatus(
      isRooted: isRooted,
      isJailbroken: isJailbroken,
      isEmulator: isEmulator,
      isDebuggerAttached: isDebuggerAttached,
      hasProxy: hasProxy,
      hasVPN: hasVPN,
      isScreenCaptureBlocked: isScreenCaptureBlocked,
      isSSLValid: isSSLValid,
      isBiometricAvailable: _config?.enableBiometricAuth ?? false,
      isCodeObfuscated: _config?.enableCodeObfuscation ?? true,
      isDeveloperModeEnabled: isDeveloperModeEnabled,
      isUsbCableAttached: isUsbCableAttached,
      riskScore: riskScore,
      isSecure: riskScore < 0.3 && _activeThreats.isEmpty,
      activeThreats: List.from(_activeThreats),
    );
  } catch (e) {
    _logSecurityEvent(
      'Device security status check failed: $e',
      LogLevel.error,
    );
    // Return default status on error
    return DeviceSecurityStatus(
      isRooted: false,
      isJailbroken: false,
      isEmulator: false,
      isDebuggerAttached: false,
      hasProxy: false,
      hasVPN: false,
      isScreenCaptureBlocked: false,
      isSSLValid: true,
      isBiometricAvailable: false,
      isCodeObfuscated: true,
      isDeveloperModeEnabled: false,
      isUsbCableAttached: false,
      riskScore: 0.0,
      isSecure: true,
      activeThreats: [],
    );
  }
}