public class AndroidDebugBridge
extends java.lang.Object
This is the central point to communicate with any devices, emulators, or the applications running on them.
init(boolean) must be called before anything is done.
| Modifier and Type | Class and Description |
|---|---|
static interface |
AndroidDebugBridge.IClientChangeListener
Classes which implement this interface provide methods that deal
with
Client changes. |
static interface |
AndroidDebugBridge.IDebugBridgeChangeListener
Classes which implement this interface provide a method that deals with
AndroidDebugBridge changes (including restarts). |
static interface |
AndroidDebugBridge.IDeviceChangeListener
Classes which implement this interface provide methods that deal
with
IDevice addition, deletion, and changes. |
| Modifier and Type | Method and Description |
|---|---|
static void |
addClientChangeListener(AndroidDebugBridge.IClientChangeListener listener)
Adds the listener to the collection of listeners who will be notified when a
Client
property changed, by sending it one of the messages defined in the AndroidDebugBridge.IClientChangeListener interface. |
static void |
addDebugBridgeChangeListener(AndroidDebugBridge.IDebugBridgeChangeListener listener)
Adds the listener to the collection of listeners who will be notified when a new
AndroidDebugBridge is connected, by sending it one of the messages defined
in the AndroidDebugBridge.IDebugBridgeChangeListener interface. |
static void |
addDeviceChangeListener(AndroidDebugBridge.IDeviceChangeListener listener)
Adds the listener to the collection of listeners who will be notified when a
IDevice
is connected, disconnected, or when its properties or its Client list changed, by
sending it one of the messages defined in the AndroidDebugBridge.IDeviceChangeListener interface. |
static AndroidDebugBridge |
createBridge()
Creates a
AndroidDebugBridge that is not linked to any particular executable. |
static AndroidDebugBridge |
createBridge(java.lang.String osLocation,
boolean forceNewBridge)
Creates a new debug bridge from the location of the command line tool.
|
static void |
disableFakeAdbServerMode() |
static void |
disconnectBridge()
Disconnects the current debug bridge, and destroy the object.
|
static void |
enableFakeAdbServerMode(int port) |
static com.google.common.util.concurrent.ListenableFuture<AdbVersion> |
getAdbVersion(java.io.File adb) |
static AndroidDebugBridge |
getBridge()
Returns the current debug bridge.
|
int |
getConnectionAttemptCount()
Returns the number of times the
AndroidDebugBridge object attempted to connect
to the adb daemon. |
IDevice[] |
getDevices()
Returns the devices.
|
com.google.common.util.concurrent.ListenableFuture<java.util.List<AdbDevice>> |
getRawDeviceList()
Returns the set of devices reported by the adb command-line.
|
int |
getRestartAttemptCount()
Returns the number of times the
AndroidDebugBridge object attempted to restart
the adb daemon. |
static java.net.InetSocketAddress |
getSocketAddress()
Returns the socket address of the ADB server on the host.
|
boolean |
hasInitialDeviceList()
Returns whether the bridge has acquired the initial list from adb after being created.
|
static void |
init(boolean clientSupport)
Initializes the
ddm library. |
static void |
init(boolean clientSupport,
boolean useLibusb,
java.util.Map<java.lang.String,java.lang.String> env) |
static void |
initIfNeeded(boolean clientSupport)
Initialized the library only if needed.
|
boolean |
isConnected()
Returns whether the
AndroidDebugBridge object is still connected to the adb daemon. |
static void |
removeClientChangeListener(AndroidDebugBridge.IClientChangeListener listener)
Removes the listener from the collection of listeners who will be notified when a
Client property changes. |
static void |
removeDebugBridgeChangeListener(AndroidDebugBridge.IDebugBridgeChangeListener listener)
Removes the listener from the collection of listeners who will be notified when a new
AndroidDebugBridge is started. |
static void |
removeDeviceChangeListener(AndroidDebugBridge.IDeviceChangeListener listener)
|
boolean |
restart()
Restarts adb, but not the services around it.
|
void |
setSelectedClient(Client selectedClient)
Sets the client to accept debugger connection on the custom "Selected debug port".
|
static void |
terminate()
Terminates the ddm library.
|
public static void initIfNeeded(boolean clientSupport)
clientSupport - Indicates whether the library should enable the monitoring and
interaction with applications running on the devices.init(boolean)public static void init(boolean clientSupport)
ddm library.
This must be called once before any call to
createBridge(String, boolean).
The library can be initialized in 2 ways:
true.false.ddmlib to connect a debugger to them.Only one tool can run in mode 1 at the same time.
Note that mode 1 does not prevent debugging of applications running on devices. Mode 1
lets debuggers connect to ddmlib which acts as a proxy between the debuggers and
the applications to debug. See Client.getDebuggerListenPort().
The preferences of ddmlib should also be initialized with whatever default
values were changed from the default values.
When the application quits, terminate() should be called.
clientSupport - Indicates whether the library should enable the monitoring and
interaction with applications running on the devices.createBridge(String, boolean),
DdmPreferencespublic static void init(boolean clientSupport,
boolean useLibusb,
@NonNull
java.util.Map<java.lang.String,java.lang.String> env)
public static void enableFakeAdbServerMode(int port)
public static void disableFakeAdbServerMode()
public static void terminate()
public static java.net.InetSocketAddress getSocketAddress()
public static AndroidDebugBridge createBridge()
AndroidDebugBridge that is not linked to any particular executable.
This bridge will expect adb to be running. It will not be able to start/stop/restart adb.
If a bridge has already been started, it is directly returned with no changes (similar
to calling getBridge()).
@Nullable public static AndroidDebugBridge createBridge(@NonNull java.lang.String osLocation, boolean forceNewBridge)
Any existing server will be disconnected, unless the location is the same and
forceNewBridge is set to false.
osLocation - the location of the command line tool 'adb'forceNewBridge - force creation of a new bridge even if one with the same location
already exists.@Nullable public static AndroidDebugBridge getBridge()
null if none were created.public static void disconnectBridge()
This also stops the current adb host server.
A new object will have to be created with createBridge(String, boolean).
public static void addDebugBridgeChangeListener(@NonNull
AndroidDebugBridge.IDebugBridgeChangeListener listener)
AndroidDebugBridge is connected, by sending it one of the messages defined
in the AndroidDebugBridge.IDebugBridgeChangeListener interface.listener - The listener which should be notified.public static void removeDebugBridgeChangeListener(AndroidDebugBridge.IDebugBridgeChangeListener listener)
AndroidDebugBridge is started.listener - The listener which should no longer be notified.public static void addDeviceChangeListener(@NonNull
AndroidDebugBridge.IDeviceChangeListener listener)
IDevice
is connected, disconnected, or when its properties or its Client list changed, by
sending it one of the messages defined in the AndroidDebugBridge.IDeviceChangeListener interface.listener - The listener which should be notified.public static void removeDeviceChangeListener(AndroidDebugBridge.IDeviceChangeListener listener)
IDevice is connected, disconnected, or when its properties or its Client list
changed.listener - The listener which should no longer be notified.public static void addClientChangeListener(AndroidDebugBridge.IClientChangeListener listener)
Client
property changed, by sending it one of the messages defined in the AndroidDebugBridge.IClientChangeListener interface.listener - The listener which should be notified.public static void removeClientChangeListener(AndroidDebugBridge.IClientChangeListener listener)
Client property changes.listener - The listener which should no longer be notified.@NonNull public IDevice[] getDevices()
hasInitialDeviceList()public boolean hasInitialDeviceList()
Calling getDevices() right after createBridge(String, boolean) will
generally result in an empty list. This is due to the internal asynchronous communication
mechanism with adb that does not guarantee that the IDevice list has been
built before the call to getDevices().
The recommended way to get the list of IDevice objects is to create a
AndroidDebugBridge.IDeviceChangeListener object.
public void setSelectedClient(Client selectedClient)
selectedClient - the client. Can be null.public boolean isConnected()
AndroidDebugBridge object is still connected to the adb daemon.public int getConnectionAttemptCount()
AndroidDebugBridge object attempted to connect
to the adb daemon.public int getRestartAttemptCount()
AndroidDebugBridge object attempted to restart
the adb daemon.public static com.google.common.util.concurrent.ListenableFuture<AdbVersion> getAdbVersion(@NonNull java.io.File adb)
public com.google.common.util.concurrent.ListenableFuture<java.util.List<AdbDevice>> getRawDeviceList()
getDevices() list via another channel. Code that just needs to access the list of devices
should call getDevices() instead.public boolean restart()