attachListener method

void attachListener(
  1. ThreatCallback callback
)

Attaches instance of ThreatCallback to Talsec. If ThreatCallback is already attached, current one will be detached and replaced with callback.

When invoked, functions starts listening to onThreatDetected and turns stream events into function callbacks of ThreatCallback.

When threat is detected, respective callback of ThreatCallback is invoked.

Implementation

void attachListener(ThreatCallback callback) {
  detachListener();
  _streamSubscription ??= onThreatDetected.listen((event) {
    switch (event) {
      case Threat.hooks:
        callback.onHooks?.call();
        break;
      case Threat.debug:
        callback.onDebug?.call();
        break;
      case Threat.passcode:
        callback.onPasscode?.call();
        break;
      case Threat.deviceId:
        callback.onDeviceID?.call();
        break;
      case Threat.simulator:
        callback.onSimulator?.call();
        break;
      case Threat.appIntegrity:
        callback.onAppIntegrity?.call();
        break;
      case Threat.obfuscationIssues:
        callback.onObfuscationIssues?.call();
        break;
      case Threat.deviceBinding:
        callback.onDeviceBinding?.call();
        break;
      case Threat.unofficialStore:
        callback.onUnofficialStore?.call();
        break;
      case Threat.privilegedAccess:
        callback.onPrivilegedAccess?.call();
        break;
      case Threat.secureHardwareNotAvailable:
        callback.onSecureHardwareNotAvailable?.call();
        break;
      case Threat.systemVPN:
        callback.onSystemVPN?.call();
        break;
      case Threat.devMode:
        callback.onDevMode?.call();
        break;
    }
  });
}