flutter_device_guard

pub package license

Detect device integrity issues on Android and iOS for fintech-grade security.

Features

Threat Android iOS
Emulator / Simulator ✅ ✅
Root ✅ —
Jailbreak — ✅
VPN ✅ ✅
Mock Location ✅ ✅
Screen Recording ✅ ✅
Debugger Attached ✅ ✅

Getting Started

Add flutter_device_guard to your pubspec.yaml:

dependencies:
  flutter_device_guard: ^1.0.0

Then run:

flutter pub get

Platform Requirements

  • Android: minSdk 21+
  • iOS: iOS 12.0+

Usage

Quick Check

import 'package:flutter_device_guard/flutter_device_guard.dart';

final isRooted = await DeviceGuard().checkThreat(ThreatType.rooted);
print('Rooted: $isRooted');

Full Integrity Report

final report = await DeviceGuard().checkAllThreats();

if (!report.isDeviceSafe) {
  for (final threat in report.threats) {
    print('${threat.type}: ${threat.description} [${threat.severity}]');
  }
}

Check Specific Threats

final report = await DeviceGuard().checkThreats([
  ThreatType.emulator,
  ThreatType.vpnDetected,
  ThreatType.debuggerAttached,
]);

Get Threat Details

final threat = await DeviceGuard().getThreatDetails(ThreatType.vpnDetected);
if (threat != null) {
  print('VPN: ${threat.description} (severity: ${threat.severity})');
  print('Metadata: ${threat.metadata}');
}

Custom Configuration

DeviceGuard().initialize(
  config: DeviceGuardConfig(
    cacheExpiry: const Duration(minutes: 10),
    enableCaching: true,
    threatsToCheck: [
      ThreatType.rooted,
      ThreatType.vpnDetected,
      ThreatType.mockLocationEnabled,
    ],
    onThreatDetected: (threat) {
      print('⚠️ ${threat.type}: ${threat.description}');
    },
  ),
);

Continuous Monitoring

// Monitor all configured threats
DeviceGuard()
    .monitorThreats(checkInterval: const Duration(seconds: 15))
    .listen((threat) {
  print('Threat: ${threat.type}');
});

// Monitor a single threat
DeviceGuard()
    .monitorThreat(ThreatType.screenRecording)
    .listen((detected) {
  print('Screen recording: $detected');
});

Reset Cache

DeviceGuard().resetCache();

API Reference

DeviceGuard

Method Description
initialize({DeviceGuardConfig}) Set custom configuration
checkThreat(ThreatType) Returns bool — is threat present?
getThreatDetails(ThreatType) Returns DeviceThreat? with full info
checkAllThreats() Returns DeviceIntegrityReport for all configured threats
checkThreats(List<ThreatType>) Returns DeviceIntegrityReport for selected threats
monitorThreats({Duration}) Stream<DeviceThreat> — continuous monitoring
monitorThreat(ThreatType) Stream<bool> — monitor single threat
resetCache() Clear the detection cache

ThreatType

emulator, rooted, jailbroken, vpnDetected, mockLocationEnabled, screenRecording, debuggerAttached, unknown

ThreatSeverity

critical, high, medium, low

DeviceIntegrityReport

Property / Method Description
isDeviceSafe true if no threats detected
threats List<DeviceThreat>
threatsCount Number of threats
hasThreat(ThreatType) Check for specific threat
hasThreatOfSeverity(ThreatSeverity) Check by severity
threatsBySeverity(ThreatSeverity) Filter by severity

Architecture

lib/
├── flutter_device_guard.dart          # Main export
└── src/
    ├── device_guard.dart              # Core singleton API
    ├── config/
    │   ├── device_guard_config.dart   # Configuration
    │   └── detection_cache.dart       # Caching layer
    ├── detectors/
    │   ├── base_detector.dart         # Abstract base
    │   ├── emulator_detector.dart
    │   ├── root_detector.dart         # Root + Jailbreak
    │   ├── vpn_detector.dart
    │   ├── mock_location_detector.dart
    │   ├── debugger_detector.dart
    │   └── screen_recorder_detector.dart
    └── models/
        ├── device_threat.dart         # ThreatType, DeviceThreat, Report
        └── detection_result.dart      # DetectionResult wrapper

Error Handling

All detectors follow a fail-open strategy: if a detection call fails (missing permission, unavailable API, etc.) the detector returns null (no threat detected) rather than blocking the user. Use DetectionResult for fine-grained error handling when needed.

Security Considerations

  • Enable code obfuscation for release builds.
  • Avoid logging detection results in production.
  • Combine with server-side validation for defence in depth.
  • Consider using the onThreatDetected callback for analytics.

Troubleshooting

Issue Solution
MissingPluginException Ensure native build completed; run flutter clean && flutter pub get
False positive on emulator Some device models match emulator fingerprints — report via issues
VPN not detected on iOS Requires network proxy settings; some VPN configurations may not be visible

License

MIT — see LICENSE.

Libraries

flutter_device_guard
Flutter Device Guard — detect device integrity issues on Android and iOS for fintech security.