Method for Android to support remote adb control debugging by using Frpc
By embedding the Frpc client in Android devices, combining dynamic configuration management, two-way security authentication and intelligent tunnel maintenance, the problems of complex configuration, low security and poor network penetration capabilities of traditional Android device remote debugging solutions are solved, and efficient and secure remote debugging is achieved, suitable for IoT devices and smart terminals.
Patent Information
- Application Number
- CN202510623529.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-15
- Publication Date
- 2025-08-15
AI Technical Summary
The remote debugging solution of traditional Android devices is complex in configuration, low security, and poor network penetration capabilities, which especially affects development efficiency and stability in complex network environments.
The Frpc client is embedded in Android devices, combined with dynamic configuration management, two-way security authentication and intelligent tunnel maintenance, ADB traffic reverse proxy transmission is realized through TLS1.3 encrypted tunnel, supporting hot load updates and certificate two-way verification, and designing an index back-avoidance and reconnection strategy.
Reduce configuration complexity by 83%, improve connection speed by 5 times, reduce data leakage risk by 97%, supports seamless debugging across NAT networks, and improves system security and stability.
Smart Images

Figure CN120499249A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of mobile device remote debugging, and in particular to a method for implementing remote ADB debugging of Android devices based on Frpc, which is particularly suitable for secure remote maintenance scenarios of IoT devices in complex network environments. Background Art
[0002] ADB (Android Debug Bridge) is an essential debugging tool for developing and maintaining Android devices. Traditional ADB debugging relies on direct USB connection or a local area network (LAN) environment. When the device is in a public network or behind a NAT network, complex NAT penetration configuration, such as port mapping and DDNS dynamic domain name resolution, is required. This places high demands on developers' network configuration skills and is cumbersome and error-prone.
[0003] Existing remote debugging solutions have many security risks. For example, directly opening the public network port will expose the device debugging interface, increasing the risk of malicious attacks. When relying on third-party remote debugging services, the security and privacy of data transmission are difficult to be effectively guaranteed, and the network node jump of the third-party service may increase debugging delays, affecting development efficiency.
[0004] Furthermore, traditional solutions rely on fixed IP addresses. When the device's network environment changes (such as switching mobile networks or restarting routers), the dynamic change of the IP address can cause connection interruptions and require reconfiguration, seriously affecting the stability and convenience of remote debugging. With the widespread adoption of IoT devices and the deployment of a large number of intelligent terminal devices in complex network environments, the limitations of traditional ADB remote debugging solutions have become increasingly apparent. There is an urgent need for a remote debugging solution that is secure, efficient, easy to configure, and has strong network penetration capabilities. Summary of the Invention
[0005] In response to the problems of complex configuration, low security, and poor network penetration in the existing technology, the present invention provides a remote ADB debugging method and system for Android devices based on Frpc. Through core technologies such as dynamic configuration management, two-way security authentication, and intelligent tunnel maintenance, it achieves safe and efficient remote debugging, reduces configuration complexity, and improves connection stability and data transmission security.
[0006] The present invention provides an Android method for supporting remote ADB control debugging using Frpc, comprising the following steps:
[0007] S1: Embed a Frpc client on the Android device, wherein the Frpc client includes a configuration management module, a security authentication module, and a network adaptation module;
[0008] S2: The server generates an access token with a time limit and sends a configuration file containing the token, server address and port to the target device;
[0009] S3: The configuration management module on the device side parses and stores the configuration file to generate an Frpc configuration file;
[0010] S4: The device-side Frpc client and the server-side Frp service establish a TLS1.3 encrypted tunnel and perform two-way certificate verification;
[0011] S5: The server distributes ADB data traffic to the ADB client on the developer's PC through a reverse proxy, enabling remote debugging. This technical solution implements cross-network ADB debugging by embedding the Frpc client on the device and cooperating with the server, breaking through the limitations of traditional ADB's reliance on USB direct connection or LAN, and supporting remote debugging.
[0012] Further describing the aforementioned solution, the configuration management module supports hot reloading of configuration changes. When a token expires or configuration parameters are updated, the configuration is automatically updated without restarting the device. It also features a memory-file dual caching mechanism and version rollback capabilities. This hot reloading of configuration changes enables the system to dynamically respond to configuration changes without restarting the device, improving system flexibility and availability. The dual caching mechanism and version rollback capabilities enhance the reliability of configuration management.
[0013] Further describing the aforementioned solution, the security authentication module implements mutual certificate authentication (mTLS). The device loads an X.509 certificate chain, exchanges a PSK pre-shared key with the server, and uses the HMAC-SHA256 algorithm to sign data, ensuring the legitimacy of the communicating parties and the integrity of the data. Mutual certificate authentication (mTLS) combines PSK pre-shared keys with HMAC-SHA256 data signatures to build a multi-layered security protection system, ensuring the legitimacy of the communicating parties and preventing data tampering during transmission.
[0014] Further describing the aforementioned solution, the network adaptation module employs an exponential backoff reconnection strategy. When a network interruption occurs, the device automatically attempts to reconnect, with the reconnection interval increasing exponentially with the number of failures. Simultaneously, a heartbeat packet mechanism monitors the connection status in real time to ensure the continued availability of the tunnel. This exponential backoff reconnection strategy mitigates the impact of frequent reconnections on network resources, while the heartbeat packet mechanism monitors the connection status in real time. The combination of these two significantly improves system availability in unstable network environments.
[0015] Further describing the above solution, the TLS encrypted tunnel uses the AES-GCM 256-bit encryption algorithm to encrypt and transmit ADB protocol traffic to prevent data leakage. It supports TCP, UDP, and KCP proxy types, which can be dynamically selected according to the network environment. The support of multiple proxy types enables the system to select the optimal transmission protocol according to different network environments, thereby improving transmission efficiency.
[0016] Further describing the aforementioned solution, the server dynamically allocates access addresses, generates a unique domain name and port for each connected device, and returns this address to the device. Developers can connect to this address using the adb connect command for remote debugging. Dynamically allocating unique domain names and ports solves the problem of traditional solutions relying on fixed IP addresses, enabling the system to adapt to changes in the device's network environment while simplifying the developer's connection operations.
[0017] Further describing the aforementioned solution, the configuration file is in JSON format and contains server address, port, token, proxy type, and certificate path parameters. Upon receiving the configuration package, the device verifies the digital signature to ensure the integrity and immutability of the configuration data. The JSON-formatted configuration file is easy to parse and extend, and the digital signature verification ensures that the configuration data is not tampered with during transmission, ensuring the security and reliability of the system configuration.
[0018] To further describe the above solution, the Frpc client on the device side establishes a local connection with the ADB daemon, forwards the ADB protocol data to the Frpc client, and transmits it to the server side through an encrypted tunnel, thereby realizing two-way transmission of ADB commands and data.
[0019] Further describing the aforementioned solution, the server verifies the validity of the device certificate, including its validity period, revocation status, and issuing authority, and generates and manages access tokens. These tokens are encrypted using the HMAC-SHA256 algorithm and contain the device's identity and validity period, automatically expiring upon expiration. Strict certificate verification ensures that only legitimate devices can access the system. HMAC-SHA256-based token encryption and expiration management prevents token fraud and improves system security.
[0020] Further describing the aforementioned solution, the network adaptation module preserves the debugging session state, such as open ports and ongoing file transfers, during the reconnection process, automatically resuming the session upon restoration. In the event of a man-in-the-middle attack, a session disconnect mechanism is activated, disconnecting the connection and recording the attack log. This session persistence feature eliminates the need to re-establish the debugging environment after network interruption recovery, improving debugging efficiency. The session disconnect mechanism promptly terminates the connection in the event of an attack, preventing data leakage and enhancing system security.
[0021] Compared with the prior art, the present invention has the following beneficial effects:
[0022] Reduced configuration complexity: By dynamically delivering configuration files and automatically generating Frpc configurations, there is no need to manually configure complex network parameters, reducing configuration complexity by 83% in public network environments.
[0023] Improve connection speed: Optimize the TLS handshake process and dynamically allocate access addresses, making connection establishment five times faster than traditional solutions.
[0024] Enhanced security: Using TLS1.3 encrypted tunnel, two-way certificate verification, and AES-GCM 256 encryption, the risk of data leakage is reduced by 97%, effectively defending against man-in-the-middle attacks and malicious intrusions.
[0025] Powerful network penetration capability: supports seamless debugging across NAT networks. The device does not require a public IP address. Remote access to intranet devices is achieved through reverse proxy technology, making it suitable for complex network environments such as IoT devices.
[0026] High stability: The exponential backoff reconnection strategy and heartbeat packet mechanism ensure rapid recovery in disconnected environments and maintain the continuity of debugging sessions. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0028] Figure 1 A schematic diagram of the system architecture provided by an embodiment of the present invention;
[0029] Figure 2 A schematic diagram of a specific implementation scheme provided by an embodiment of the present invention;
[0030] Figure 3 A schematic diagram of the secure tunnel establishment process provided by an embodiment of the present invention.
[0031] The above drawings illustrate specific embodiments of the present invention, which will be described in more detail below. These drawings and the accompanying description are not intended to limit the scope of the present invention in any way, but rather to illustrate the concept of the present invention to those skilled in the art by reference to specific embodiments. DETAILED DESCRIPTION
[0032] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of them. All other embodiments obtained by ordinary technicians in this field based on the embodiments of the present invention without making any creative efforts shall fall within the scope of protection of the present invention.
[0033] To make the technical solutions and advantages of the present invention more clear, the embodiments of the present invention will be described in further detail below with reference to the accompanying drawings.
[0034] See also Figure 1-Figure 3 As shown, the present invention provides an Android method for supporting remote ADB control debugging using Frpc, including the following steps: first, embedding a Frpc client on the Android device. This Frpc client integrates three core functional units: a configuration management module, a security authentication module, and a network adaptation module. The configuration management module is responsible for processing device-side parameter configuration and supports parsing, storing, and dynamically updating configuration files containing information such as server addresses, ports, and access tokens. The security authentication module establishes a two-way security authentication system to ensure the identity legitimacy and data integrity of communications between the device and the server. The network adaptation module is designed for complex network environments and features connection status monitoring and intelligent reconnection functions to ensure the continuous availability of the tunnel.
[0035] The server then generates a time-sensitive access token, encrypted using the HMAC-SHA256 algorithm and containing key information such as the device identifier and expiration date, ensuring its uniqueness and security. The server encapsulates the token along with parameters such as the server address and port number into a JSON-formatted configuration file and sends it to the target device via a secure channel. The configuration file is digitally signed during transmission. Upon receipt, the device first performs an integrity check, verifying the signature using the server's public key to ensure the configuration data has not been tampered with.
[0036] After receiving a verified configuration file, the device-side configuration management module initiates the parsing process, converting the JSON-formatted configuration data into an internal structure recognizable by the device and storing it in a secure storage area. Simultaneously, based on the parsed parameters, a configuration file conforming to the Frpc format is generated. This file contains server connection information, authentication parameters, and proxy type, providing the necessary configuration for subsequent tunnel establishment. The configuration management module supports a hot reload mechanism, automatically updating the configuration when a token expires or configuration parameters are updated without restarting the device. A dual memory and file caching mechanism and version rollback capabilities ensure reliable and flexible configuration management.
[0037] Next, the device-side Frpc client and the server-side Frp service establish a TLS1.3 encrypted tunnel. This process includes strict two-way certificate verification. The device side loads the certificate chain in X.509 format, which includes the device-specific certificate and CA root certificate. The server side verifies the validity of the device certificate through the certificate authentication center, including checking the certificate validity period, revocation status and issuing authority chain. At the same time, both parties enhance authentication security through the pre-shared key (PSK) mechanism, and the key is stored in the device's trusted execution environment to ensure that it is not illegally obtained. After the TLS handshake is completed, the tunnel uses the AES-GCM 256-bit encryption algorithm to encrypt and transmit the ADB protocol traffic to prevent data leakage. It supports multiple proxy types such as TCP, UDP, KCP, etc., and can be dynamically selected according to the network environment to achieve efficient and secure data transmission.
[0038] Finally, the server distributes the ADB data traffic to the ADB client on the developer's PC through a reverse proxy. After the device successfully establishes a tunnel, the server dynamically assigns it a unique access address, which includes a domain name and port. The developer connects to this address using the adb connect command, and the ADB client initiates a connection request to the server. The server queries the device connection mapping table based on the port number, locates the corresponding device-side tunnel, and forwards the debugging commands and data to the target device through the reverse proxy, enabling two-way transmission of ADB protocol data. During this process, the server verifies the validity of the device-side certificate, generates and manages access tokens, ensuring that only legitimate devices can access the system. The token automatically expires upon expiration, further enhancing system security.
[0039] The network adaptation module plays a key role throughout the debugging process. Upon detecting a network outage, it automatically attempts to reconnect, with the reconnection interval increasing exponentially with the number of failures to minimize the impact of frequent reconnections on network resources. Furthermore, a heartbeat mechanism monitors the connection status in real time to ensure the continued availability of the tunnel. During reconnection, the debugging session status, such as open ports and ongoing file transfers, is preserved, and the session is automatically resumed upon connection restoration. In the event of a man-in-the-middle attack, the session fuse mechanism is activated, disconnecting the connection and recording the attack log, ensuring the continuity and security of the debugging process.
[0040] The Frpc client on the device establishes a local connection with the ADB daemon, forwarding ADB protocol data to the Frpc client, which then transmits it to the server through an encrypted tunnel, enabling bidirectional transmission of ADB commands and data. The configuration file, which includes parameters such as the proxy type and certificate path, provides detailed configuration for tunnel establishment and data transmission. Upon receiving the configuration package, the device verifies the digital signature to ensure the integrity and immutability of the configuration data.
[0041] Through the above steps, the present invention builds a system architecture that includes dynamic configuration management, two-way security authentication, and intelligent tunnel maintenance. This solves the problems of traditional ADB remote debugging solutions, such as complex configuration, low security, reliance on fixed IP addresses, and poor network penetration. In public network environments, it can reduce configuration complexity by 83%, increase connection establishment speed by five times, reduce the risk of data leakage by 97% through AES-GCM256 encryption, and support seamless debugging across NAT networks, providing a secure and efficient solution for remote maintenance in IoT devices, smart terminals, and other fields.
[0042] like Figure 1 As shown, the system is divided into three layers: device-side components (inside Android devices), server-side components, and client-side components (developer PCs). The ADB daemon of the device-side component is responsible for local debugging services; the configuration management module is used to handle configuration file loading and updates; and the security authentication module implements two-way certificate verification. Data flow: ADB daemon → Frpc Client → secure tunnel. The server-side component functions as follows: receiving encrypted tunnel data, performing reverse proxy operations, and distributing traffic to the developer terminal. Client-side component (developer PC): The ADB client tool connects to the target device via the proxy address. The interaction process: Frpc on the device establishes a TLS encrypted channel → the server receives and forwards the request → the developer PC accesses via the assigned domain name / port.
[0043] In particular, the configuration management module is responsible for the full life cycle management of device-side configuration parameters. It adopts a layered architecture design, including the core class ConfigManager and the data structure ConfigData, to implement dynamic loading, secure storage and hot update functions of configuration.
[0044] The configuration management class (ConfigManager) serves as the core control unit and provides the following key methods:
[0045] parseConfig(jsonData): Parses the JSON configuration package sent by the server and verifies the HMAC-SHA256 digital signature to ensure that the configuration data has not been tampered with.
[0046] generateFrpcIni(): Generates a standard Frpc configuration file (frpc.ini) based on the parsed configuration parameters, including key information such as server address, port, authentication token, and proxy type.
[0047] updateToken(newToken): Dynamically refreshes the authentication token, supporting automatic renewal of token expiration without interrupting the debugging session.
[0048] getCurrentConfig(): Gets the runtime configuration status in real time for the network module and authentication module to call.
[0049] Configuration data structure (ConfigData)
[0050] Stores core configuration parameters. The fields are defined as follows:
[0051] server_addr: supports both domain name (such as frp.example.com) and IP address modes to adapt to different network environments.
[0052] server_port: The default port is 7000, which can be expanded to other ports through configuration.
[0053] token: An access token encrypted using the HMAC-SHA256 algorithm, containing the device's unique identifier and validity period (e.g., 24 hours).
[0054] proxy_type: transport protocol type enumeration value (TCP / UDP / KCP), supports dynamic switching based on network quality.
[0055] The operation process is as follows
[0056] Configuration reception and verification: After the device receives the encrypted configuration package sent by the server, it first verifies the digital signature using the server's public key to ensure the integrity of the configuration data.
[0057] Parsing and storage: The parseConfig() method is used to convert JSON data into a ConfigData instance. Format verification (such as port range check and token format verification) is also performed. Once the verification passes, the data is persistently stored in the device's secure partition.
[0058] Hot reload and restart: When configuration parameters change (such as token expiration or server address update), ConfigManager triggers the Frpc client to restart, and the new configuration can be applied without restarting the device.
[0059] Double caching and version rollback: A memory-file dual caching mechanism is used. The current active configuration is stored in memory to improve access speed, and the file storage is used as a persistent backup. The three most recent valid configuration versions are recorded, and when the new configuration fails to load, it automatically rolls back to the stable version.
[0060] Hot reload configuration changes: Supports dynamic configuration updates without restarting the device, with a response time of less than 500ms, meeting the real-time configuration adjustment needs in remote operation and maintenance scenarios.
[0061] Secure storage mechanism: Configuration files are stored in the device's Trusted Execution Environment (TEE), and sensitive fields (such as tokens) are encrypted using AES-256 to prevent malicious reading.
[0062] Version control capabilities: Implement change auditing by configuring version numbers and timestamps, support manual / automatic rollback, and improve system fault tolerance.
[0063] In particular, the TLS1.3 secure tunnel establishment process is as follows Figure 3 As shown, it is divided into the following stages:
[0064] Startup detection: After the device starts, the Frpc client first checks whether / data / frpc / config.json exists. If not, it generates a default configuration (including the server domain name frp.example.com, port 7000, and a temporary self-signed certificate) to ensure fast access during the first startup.
[0065] Bidirectional authentication: The device loads the X.509 certificate chain (including the device certificate, CA intermediate certificates, and root certificates) stored in the Trusted Execution Environment (TEE) and performs a TLS 1.3 handshake with the server. During the handshake, both parties exchange certificates and verify their validity (including certificate validity periods and CRL revocation lists). A pre-shared key (PSK) (derived from the device's unique ID and a random number generated by the server) is used to enhance authentication security and prevent man-in-the-middle attacks.
[0066] Channel construction: Select the transport protocol based on the proxy_type in ConfigData (e.g., TCP for stable networks, KCP for high-latency networks), create a proxy tunnel, and bind the local ADB port. The tunnel supports traffic statistics, monitoring upload / download rates in real time, providing data support for subsequent QoS adjustments.
[0067] Maintenance: Connection status is monitored via a heartbeat mechanism (a ping packet is sent every 30 seconds). A reconnection is triggered if no response is received for three consecutive times. Data transmission utilizes AES-GCM 256-bit encryption to ensure the confidentiality and integrity of ADB commands (such as adb shell and file transfers) over public networks. The network adaptation module dynamically adjusts the maximum transmission unit (MTU) based on the round-trip time (RTT). For example, on 4G networks, the MTU is automatically lowered to reduce fragmentation and improve transmission efficiency.
[0068] Exception branch:
[0069] Trigger an alarm notification when the certificate expires;
[0070] Preserve debugging session state after network interruption;
[0071] Initiate session circuit breaking when encountering a man-in-the-middle attack.
[0072] Other embodiments of the present invention will readily occur to those skilled in the art after considering the specification and practicing the present invention. This application is intended to cover any variations, uses, or adaptations of the present invention that follow the general principles of the present invention and include common knowledge or customary techniques in the art not disclosed herein. The description and examples are to be considered as exemplary only, and the true scope and spirit of the invention are indicated by the following claims.
[0073] It should be understood that the present invention is not limited to the exact construction described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present invention is limited only by the appended claims.
Claims
1. Android uses Frpc to support remote adb control debugging method, which is characterized by: The following steps are involved: S1: Embed a Frpc client on the Android device, wherein the Frpc client includes a configuration management module, a security authentication module, and a network adaptation module; S2: The server generates an access token with a time limit and sends a configuration file containing the token, server address and port to the target device; S3: The configuration management module on the device side parses and stores the configuration file to generate an Frpc configuration file; S4: The device-side Frpc client and the server-side Frp service establish a TLS1.3 encrypted tunnel and perform two-way certificate verification; S5: The server distributes ADB data traffic to the ADB client on the developer's PC through a reverse proxy to achieve remote debugging.
2. The method for supporting remote adb control debugging using Frpc on Android according to claim 1, characterized in that: The configuration management module supports hot loading of configuration changes. When the token expires or the configuration parameters are updated, the configuration can be automatically updated without restarting the device. It also has a memory-file dual cache mechanism and version rollback capabilities.
3. The method for supporting remote adb control debugging using Frpc on Android according to claim 1, characterized in that: The security authentication module implements two-way certificate verification (mTLS). The device side loads the certificate chain in X.509 format, exchanges the PSK pre-shared key with the server side, and uses the HMAC-SHA256 algorithm to sign the data to ensure the identity legitimacy and data integrity of both communicating parties.
4. The method for supporting remote adb control debugging using Frpc on Android according to claim 1, wherein: The network adaptation module adopts an exponential backoff reconnection strategy. When the network is interrupted, the device automatically attempts to reconnect. The reconnection interval increases exponentially with the number of failures. At the same time, the connection status is monitored in real time through the heartbeat packet mechanism to ensure the continuous availability of the tunnel.
5. The method for supporting remote adb control debugging using Frpc on Android according to claim 1, characterized in that: The TLS encrypted tunnel uses the AES-GCM 256-bit encryption algorithm to encrypt and transmit ADB protocol traffic to prevent data leakage. It supports TCP, UDP, and KCP proxy types and can be dynamically selected according to the network environment.
6. The method for supporting remote adb control debugging using Frpc on Android according to claim 1, characterized in that: The server dynamically allocates access addresses, generates a unique domain name and port for each connected device, and returns the address to the device. Developers connect to the address through the adb connect command for remote debugging.
7. The method for supporting remote adb control debugging using Frpc on Android according to claim 1, characterized in that: The configuration file is in JSON format and includes server address, port, token, proxy type, and certificate path parameters. After receiving the configuration package, the device verifies the digital signature to ensure the integrity and non-tamperability of the configuration data.
8. The method for supporting remote adb control debugging using Frpc on Android according to claim 1, characterized in that: The Frpc client on the device side establishes a local connection with the ADB daemon, forwards the ADB protocol data to the Frpc client, and transmits it to the server side through an encrypted tunnel, realizing two-way transmission of ADB commands and data.
9. The Android method of using Frpc to support remote adb control debugging according to claim 1, characterized in that: The server verifies the validity of the device certificate, including the certificate validity period, revocation status and issuing authority, generates and manages the access token, which is encrypted using the HMAC-SHA256 algorithm and contains the device identification and validity period. It automatically becomes invalid after expiration.
10. The method for supporting remote adb control debugging using Frpc on Android according to claim 1, characterized in that: The network adaptation module retains the debugging session status during the reconnection process, such as the open ports and ongoing file transfers, and automatically resumes the session after the connection is restored. When encountering a man-in-the-middle attack, the session fuse mechanism is activated, the connection is disconnected, and the attack log is recorded.
Citation Information
Cited By
Wireless debugging port extranet forwarding method and system under Gawan 5.0 system
CN120825710A
A wireless debugging port external network forwarding method and system under a honghong 5.0 system
CN120825710B
Remote debugging method and system based on Internet of Things cloud platform and proxy gateway
CN121367710A
A secure remote control method and device for an intranet cluster device
CN122533870A