Skip to content

API reference

Everything is exported from one import:

import 'package:device_shield/device_shield.dart';

A static class. There’s nothing to initialise, and no method throws.

Method Returns Notes
check() Future<SecurityReport> Runs every check below
checkRoot() Future<CheckResult> Android; notApplicable on iOS
checkJailbreak() Future<CheckResult> iOS devices; notApplicable on Android and the iOS Simulator
checkEmulator() Future<CheckResult> Android emulator or iOS Simulator
checkDebugger() Future<CheckResult>
checkMockLocation() Future<MockLocationResult> Location signals need your app’s location permission

On Android, checks run on a background thread and one at a time. A check that takes longer than 5 seconds comes back as failed.

Member Type Notes
screenshots Stream<void> Fires after a screenshot. Android 14+ and iOS
screenRecordingChanges Stream<bool> true when recording or mirroring starts. iOS
isScreenRecorded() Future<bool?> Current state; null where it can’t be determined
setScreenshotProtection(bool) Future<ProtectionResult> See Screenshot protection
setAppSwitcherProtection(bool) Future<ProtectionResult> See App-switcher protection

The streams share one native connection, so you can listen to them from as many places as you like.

Member Type Meaning
type CheckType root, jailbreak, emulator, debugger or mockLocation
status CheckStatus detected, clear, notApplicable or failed
detected bool status == CheckStatus.detected
signals List<Signal> Every signal that fired, including weak ones
error String? Why it failed, when status is failed

A CheckResult with two extra fields:

Member Type Meaning
locationPermissionGranted bool Your app has location permission
locationAvailable bool A recent location was available to inspect
Member Type Meaning
id String For example su_binary_path. See Signals
strength SignalStrength strong, medium or weak
Member Type Meaning
root, jailbreak, emulator, debugger CheckResult One per check
mockLocation MockLocationResult
all List<CheckResult> Every result
detections List<CheckResult> Results with detected
anyDetected bool Any check detected its condition
anyFailed bool Any check couldn’t run. Treat the report as incomplete
Value Meaning
applied The platform confirmed the change is in effect
unsupported Not available on this platform
failed Couldn’t be made, for example because no window exists yet. Try again once your UI is showing

0.1.0 replaces the pre-release API:

0.0.x 0.1.0
DeviceShield.initialize(config: …) Not needed
RootDetector(nativeBridge: DefaultNativeBridge()).check() DeviceShield.checkRoot()
result.evidence['signals'] result.signals (with strengths)
result.detected (any signal) result.detected (weighted; see Detection results)
DeviceShield.subscribe(…) / registerDetector(…) / addRule(…) Removed. Call the checks when you need them
DeviceShield.onScreenshot(handler) DeviceShield.screenshots.listen(…)
enableScreenshotProtection() / disableScreenshotProtection() setScreenshotProtection(bool)
DeviceShieldException and error codes Removed. Failures are CheckStatus.failed or ProtectionResult.failed