Documentation

Go to Portal Website

USB Connection Detection

PlanPlatformsMASVS
TeamAndroidMASVS-RESILIENCE-4

Overview

USB Connection Detection monitors active USB data-transfer connections in real time and triggers a configurable response when the Android device is connected to a USB host in any data-capable mode. This control enables applications to detect when users connect their devices to computers or forensic equipment that could extract data, execute ADB commands, or perform packet capture.

Unlike charge-only USB connections (which are benign), data-transfer modes enable file access, debugging interfaces, or network tethering capabilities that pose security risks. This control continuously monitors the system's USB state and fires only when data-capable modes are active.

How It Works

The control registers a broadcast receiver for Android's android.hardware.usb.action.USB_STATE intent, a system-protected broadcast that fires whenever USB connection state changes. When a USB cable is connected, the intent includes boolean extras indicating which USB functions are active.

Detection Logic

The control evaluates the following USB function flags in the broadcast intent extras:

ModeExtra KeyRisk
MTP (Media Transfer Protocol)mtpFile system access, full media library exposure
PTP (Picture Transfer Protocol)ptpCamera roll and photo access
ADB (Android Debug Bridge)adbShell access, app debugging, data extraction
RNDIS (USB Tethering)rndisNetwork traffic interception, packet sniffing
NCM (Network Control Model)ncmModern USB tethering with network access
MIDI (Musical Instrument Digital Interface)midiMIDI device communication

If the device is connected (connected=true) AND any of these function flags is true, the control triggers the configured response. Pure charge-only connections (no function flags set) do not fire.

State Tracking

The control includes intelligent state management:

Modes Detected

High-Risk Modes

MTP (Media Transfer Protocol) and PTP (Picture Transfer Protocol) grant the connected USB host full read/write access to the device's storage or camera roll. An attacker with physical access can:

ADB (Android Debug Bridge) is the most dangerous mode, enabling:

Moderate-Risk Modes

RNDIS and NCM (USB Tethering) share the device's mobile data connection with the USB host. While seemingly benign, these modes enable:

MIDI is the lowest-risk mode, used for connecting musical instruments. While typically benign, it represents an active data connection and is included for completeness.

Threats Mitigated

Response Type

This is a response control—it does not block or prevent USB connections (which would break legitimate charging and accessories). Instead, it:

The response is idempotent per connection: the alert fires once when the data mode is detected and will not fire again until the cable is disconnected and reconnected.

Use Cases

Enterprise & MDM

Financial Services

Healthcare (HIPAA Compliance)

High-Security Applications

Support Matrix

PlatformMinimum VersionImplementation
AndroidAPI 26 (Android 8.0)Native C++ broadcast receiver
iOSNot supportedUSB accessories use different APIs; host mode unavailable to sandboxed apps

How to Enable the Control

Navigate to Detection & Response from the AppTego portal, and expand the Runtime Attack Detection section. Under this section you will find the USB Connection Detection control. Click Enable Configuration, choose the response action, and save the configuration for the next build or for it to be applied with a live push (if enabled).

API Configuration Example

{
  "UsbConnectionDetectionResponse": {
    "detection": true,
    "action": "alert",
    "title": "USB Connection Detection",
    "message": "A USB data connection was detected. Please disconnect USB data access before continuing.",
    "buttons": ["OK"],
    "actions": ["close"],
    "redirects": [""]
  }
}
FieldPurpose
detectionEnables usb connection detection.
actionSelects the response style, such as alert, close, log, or warn.
title / messageUser-facing text shown when a response is displayed.
buttons / actions / redirectsDefines the available response buttons and their outcomes.

Configuration

Enable the control in your MobileDefender configuration:

{
  "UsbConnectionDetectionResponse": {
    "detection": true,
    "action": "alert",
    "title": "USB Data Connection Detected",
    "message": "Your device is connected to a computer with file access enabled. Disconnect immediately if this was not intentional.",
    "buttons": ["Disconnect", "I Understand"],
    "actions": ["close", "continue"]
  }
}

Parameters

Caveats

Charge-Only Connections

The control does not fire for pure charge-only USB connections. If the device is connected to a power source (wall adapter, battery pack) or a "charging only" mode is active, no alert will trigger. This is intentional to avoid alert fatigue.

System Permission

android.hardware.usb.action.USB_STATE is a system-protected broadcast that cannot be spoofed by third-party apps. The control registers with RECEIVER_NOT_EXPORTED flag, ensuring only the Android system can deliver the broadcast.

Initial State

The control processes the sticky broadcast immediately on registration, so if the app is launched while a USB data connection is already active, the alert will fire within seconds of startup.

No Prevention Capability

This control is detection-only. It cannot prevent, block, or disable USB connections at the OS level. To block USB data access, organizations must use MDM policies or hardware-based security solutions.

Performance

The broadcast receiver is lightweight and does not poll or perform continuous checks. The control only executes when the Android system delivers a USB state change broadcast, resulting in zero battery or CPU impact during normal operation.