Package 

Class AdbConnection

  • 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 class AdbConnection.Builder
    • Field Summary

      Fields 
      Modifier and Type Field Description
      public final static String TAG
    • Method Summary

      Modifier and Type Method Description
      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.
      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.
      void setDeviceName(@NonNull() String deviceName) Set a name for the device.
      int getProtocolVersion() Get the version of the ADB protocol supported by the ADB daemon.
      int getMaxData() Get the max data size supported by the ADB daemon.
      boolean isConnectionEstablished() Whether a connection has been established.
      boolean isConnected() Whether the underlying socket is connected to an ADB daemon and is not in a closed state.
      boolean connect() Same as connect without throwing anything if the first authentication attemptfails.
      boolean connect(long timeout, @NonNull() TimeUnit unit, boolean throwOnUnauthorised) Connects to the remote device.
      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.
      AdbStream open(@NonNull() String destination) Opens an AdbStream object corresponding to the specified destination.This routine will block until the connection completes.
      void close() This routine closes the Adb connection and underlying socket
      • Methods inherited from class java.io.Closeable

        close
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • 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 lock
        unit - the time unit of the timeout argument
        throwOnUnauthorised - 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