-
- All Implemented Interfaces:
-
java.io.Closeable,java.lang.AutoCloseable
public class AdbConnection implements Closeable
This class represents an ADB connection.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public classAdbConnection.Builder
-
Method Summary
Modifier and Type Method Description static AdbConnectioncreate(@NonNull() String host, int port, @NonNull() PrivateKey privateKey, @NonNull() Certificate certificate)Creates a AdbConnection object associated with the socket and crypto object specified. static AdbConnectioncreate(@NonNull() String host, int port, @NonNull() PrivateKey privateKey, @NonNull() Certificate certificate, int api)Creates a AdbConnection object associated with the socket and crypto object specified. voidsetDeviceName(@NonNull() String deviceName)Set a name for the device. intgetProtocolVersion()Get the version of the ADB protocol supported by the ADB daemon. intgetMaxData()Get the max data size supported by the ADB daemon. booleanisConnectionEstablished()Whether a connection has been established. booleanisConnected()Whether the underlying socket is connected to an ADB daemon and is not in a closed state. booleanconnect()Same as connect without throwing anything if the first authentication attemptfails. booleanconnect(long timeout, @NonNull() TimeUnit unit, boolean throwOnUnauthorised)Connects to the remote device. AdbStreamopen(int service, @NonNull() Array<String> args)Opens an AdbStream object corresponding to the specified destination.This routine will block until the connection completes. AdbStreamopen(@NonNull() String destination)Opens an AdbStream object corresponding to the specified destination.This routine will block until the connection completes. voidclose()This routine closes the Adb connection and underlying socket -
-
Method Detail
-
create
@WorkerThread()@NonNull() static AdbConnection create(@NonNull() String host, int port, @NonNull() PrivateKey privateKey, @NonNull() Certificate certificate)
Creates a AdbConnection object associated with the socket and crypto object specified.
-
create
@WorkerThread()@NonNull() static AdbConnection create(@NonNull() String host, int port, @NonNull() PrivateKey privateKey, @NonNull() Certificate certificate, int api)
Creates a AdbConnection object associated with the socket and crypto object specified.
-
setDeviceName
void setDeviceName(@NonNull() String deviceName)
Set a name for the device. Default is “Unknown Device”.
- Parameters:
deviceName- Name of the device, could be the app label, hostname or user@hostname.
-
getProtocolVersion
int getProtocolVersion()
Get the version of the ADB protocol supported by the ADB daemon. The result may depend on the API versionspecified and whether the connection has been established. In API 29 (Android 9) or later, the daemon returns A_VERSION_SKIP_CHECKSUM regardless of the protocol used to create the connection. So, if mApi is set to API 28 or earlier but the OS version is Android 9 or later, before establishing theconnection, it returns A_VERSION_MIN, and after establishing the connection, it returns A_VERSION_SKIP_CHECKSUM. In other cases, it always returns A_VERSION_MIN.
-
getMaxData
int getMaxData()
Get the max data size supported by the ADB daemon. A connection have to be attempted before calling this methodand shall be blocked if the connection is in progress.
-
isConnectionEstablished
boolean isConnectionEstablished()
Whether a connection has been established. A connection has been established if a CONNECT request has beenreceived from the ADB daemon.
-
isConnected
boolean isConnected()
Whether the underlying socket is connected to an ADB daemon and is not in a closed state.
-
connect
boolean connect()
Same as connect without throwing anything if the first authentication attemptfails.
-
connect
boolean connect(long timeout, @NonNull() TimeUnit unit, boolean throwOnUnauthorised)
Connects to the remote device. This routine will block until the connection completes or the timeout elapses.
- Parameters:
timeout- the time to wait for the lockunit- the time unit of the timeout argumentthrowOnUnauthorised- Whether to throw an AdbAuthenticationFailedException if the peer rejects out first authentication attempt
-
open
@NonNull() AdbStream open(int service, @NonNull() Array<String> args)
Opens an AdbStream object corresponding to the specified destination.This routine will block until the connection completes.
- Parameters:
service- The service to open.args- Additional arguments supported by the service (see the corresponding constant to learn more).
-
open
@NonNull() AdbStream open(@NonNull() String destination)
Opens an AdbStream object corresponding to the specified destination.This routine will block until the connection completes.
- Parameters:
destination- The destination to open on the target
-
close
void close()
This routine closes the Adb connection and underlying socket
-
-
-
-