Fields Summary |
---|
public static final String | PLUGIN_ID |
private static final String | ADB_LOCATION |
private static DdmsPlugin | sPluginThe singleton instance |
private static String | sAdbLocationLocation of the adb command line executable |
private static IDebugLauncher | sRunningAppDebugLauncherDebug Launcher for already running apps |
private org.eclipse.ui.console.MessageConsole | mDdmsConsoleConsole for DDMS log message |
private ImageLoader | mLoaderImage loader object |
private com.android.ddmlib.Device | mCurrentDevice |
private com.android.ddmlib.Client | mCurrentClient |
private boolean | mListeningToUiSelection |
private final ArrayList | mListeners |
private org.eclipse.swt.graphics.Color | mRed |
private boolean | mDdmlibInitialized |
Methods Summary |
---|
public synchronized void | addSelectionListener(com.android.ide.eclipse.ddms.DdmsPlugin$ISelectionListener listener)
mListeners.add(listener);
// notify the new listener of the current selection
listener.selectionChanged(mCurrentDevice);
listener.selectionChanged(mCurrentClient);
|
public void | deviceChanged(com.android.ddmlib.Device device, int changeMask)Sent when a device data changed, or when clients are started/terminated on the device.
This is sent from a non UI thread.
// if we are listening to selection coming from the ui, then we do nothing, as
// any change in the devices/clients, will be handled by the UI, and we'll receive
// selection notification through our implementation of IUiSelectionListener.
if (mListeningToUiSelection == false) {
// check if this is our device
if (device == mCurrentDevice) {
if (mCurrentClient == null) {
handleDefaultSelection(device);
} else {
// get the clients and make sure ours is still in there.
Client[] clients = device.getClients();
boolean foundClient = false;
for (Client client : clients) {
if (client == mCurrentClient) {
foundClient = true;
break;
}
}
// if we haven't found our client, lets look for a new one
if (foundClient == false) {
mCurrentClient = null;
handleDefaultSelection(device);
}
}
}
}
|
public void | deviceConnected(com.android.ddmlib.Device device)Sent when the a device is connected to the {@link AndroidDebugBridge}.
This is sent from a non UI thread.
// if we are listening to selection coming from the ui, then we do nothing, as
// any change in the devices/clients, will be handled by the UI, and we'll receive
// selection notification through our implementation of IUiSelectionListener.
if (mListeningToUiSelection == false) {
if (mCurrentDevice == null) {
handleDefaultSelection(device);
}
}
|
public void | deviceDisconnected(com.android.ddmlib.Device device)Sent when the a device is disconnected to the {@link AndroidDebugBridge}.
This is sent from a non UI thread.
// if we are listening to selection coming from the ui, then we do nothing, as
// any change in the devices/clients, will be handled by the UI, and we'll receive
// selection notification through our implementation of IUiSelectionListener.
if (mListeningToUiSelection == false) {
// test if the disconnected device was the default selection.
if (mCurrentDevice == device) {
// try to find a new device
AndroidDebugBridge bridge = AndroidDebugBridge.getBridge();
if (bridge != null) {
// get the device list
Device[] devices = bridge.getDevices();
// check if we still have devices
if (devices.length == 0) {
handleDefaultSelection((Device)null);
} else {
handleDefaultSelection(devices[0]);
}
} else {
handleDefaultSelection((Device)null);
}
}
}
|
public static java.lang.String | getAdb()
return sAdbLocation;
|
public static com.android.ide.eclipse.ddms.DdmsPlugin | getDefault()Returns the shared instance
return sPlugin;
|
public static org.eclipse.swt.widgets.Display | getDisplay()
IWorkbench bench = sPlugin.getWorkbench();
if (bench != null) {
return bench.getDisplay();
}
return null;
|
public static ImageLoader | getImageLoader()Return the image loader for the plugin
if (sPlugin != null) {
return sPlugin.mLoader;
}
return null;
|
private static java.lang.String | getMessageTag(java.lang.String tag)Creates a string containing the current date/time, and the tag
Calendar c = Calendar.getInstance();
if (tag == null) {
return String.format("[%1$tF %1$tT]", c);
}
return String.format("[%1$tF %1$tT - %2$s]", c, tag);
|
public static com.android.ide.eclipse.ddms.DdmsPlugin$IDebugLauncher | getRunningAppDebugLauncher()
return sRunningAppDebugLauncher;
|
private void | handleDefaultSelection(com.android.ddmlib.Device device)Handles a default selection of a {@link Device} and {@link Client}.
// because the listener expect to receive this from the UI thread, and this is called
// from the AndroidDebugBridge notifications, we need to run this in the UI thread.
try {
Display display = getDisplay();
display.asyncExec(new Runnable() {
public void run() {
// set the new device if different.
boolean newDevice = false;
if (mCurrentDevice != device) {
mCurrentDevice = device;
newDevice = true;
// notify of the new default device
for (ISelectionListener listener : mListeners) {
listener.selectionChanged(mCurrentDevice);
}
}
if (device != null) {
// if this is a device switch or the same device but we didn't find a valid
// client the last time, we go look for a client to use again.
if (newDevice || mCurrentClient == null) {
// now get the new client
Client[] clients = device.getClients();
if (clients.length > 0) {
handleDefaultSelection(clients[0]);
} else {
handleDefaultSelection((Client)null);
}
}
} else {
handleDefaultSelection((Client)null);
}
}
});
} catch (SWTException e) {
// display is disposed. Do nothing since we're quitting anyway.
}
|
private void | handleDefaultSelection(com.android.ddmlib.Client client)
mCurrentClient = client;
// notify of the new default client
for (ISelectionListener listener : mListeners) {
listener.selectionChanged(mCurrentClient);
}
|
private synchronized void | initDdmlib()
if (mDdmlibInitialized == false) {
// set the preferences.
PreferenceInitializer.setupPreferences();
// init the lib
AndroidDebugBridge.init(true /* debugger support */);
mDdmlibInitialized = true;
}
|
private static synchronized void | printToStream(org.eclipse.ui.console.MessageConsoleStream stream, java.lang.String tag, java.lang.String message)Prints a message, associated with a project to the specified stream
String dateTag = getMessageTag(tag);
stream.print(dateTag);
stream.println(message);
|
public synchronized void | removeSelectionListener(com.android.ide.eclipse.ddms.DdmsPlugin$ISelectionListener listener)
mListeners.remove(listener);
|
public synchronized void | selectionChanged(com.android.ddmlib.Device selectedDevice, com.android.ddmlib.Client selectedClient)Sent when a new {@link Device} and {@link Client} are selected.
if (mCurrentDevice != selectedDevice) {
mCurrentDevice = selectedDevice;
// notify of the new default device
for (ISelectionListener listener : mListeners) {
listener.selectionChanged(mCurrentDevice);
}
}
if (mCurrentClient != selectedClient) {
mCurrentClient = selectedClient;
// notify of the new default client
for (ISelectionListener listener : mListeners) {
listener.selectionChanged(mCurrentClient);
}
}
|
public static void | setAdb(java.lang.String adb, boolean startAdb)Set the location of the adb executable and optionally starts adb
sAdbLocation = adb;
// store the location for future ddms only start.
sPlugin.getPreferenceStore().setValue(ADB_LOCATION, sAdbLocation);
// starts the server in a thread in case this is blocking.
if (startAdb) {
new Thread() {
@Override
public void run() {
// init ddmlib if needed
getDefault().initDdmlib();
// create and start the bridge
AndroidDebugBridge.createBridge(sAdbLocation, false /* forceNewBridge */);
}
}.start();
}
|
public synchronized void | setListeningState(boolean state)
mListeningToUiSelection = state;
|
public static void | setRunningAppDebugLauncher(com.android.ide.eclipse.ddms.DdmsPlugin$IDebugLauncher launcher)Sets the launcher responsible for connecting the debugger to running applications.
sRunningAppDebugLauncher = launcher;
// if the process view is already running, give it the launcher.
// This method could be called from a non ui thread, so we make sure to do that
// in the ui thread.
Display display = getDisplay();
if (display != null && display.isDisposed() == false) {
display.asyncExec(new Runnable() {
public void run() {
DeviceView dv = DeviceView.getInstance();
if (dv != null) {
dv.setDebugLauncher(sRunningAppDebugLauncher);
}
}
});
}
|
public void | start(org.osgi.framework.BundleContext context)
super.start(context);
final Display display = getDisplay();
// get the eclipse store
final IPreferenceStore eclipseStore = getPreferenceStore();
AndroidDebugBridge.addDeviceChangeListener(this);
DdmUiPreferences.setStore(eclipseStore);
//DdmUiPreferences.displayCharts();
// set the consoles.
mDdmsConsole = new MessageConsole("DDMS", null); // $NON-NLS-1$
ConsolePlugin.getDefault().getConsoleManager().addConsoles(
new IConsole[] {
mDdmsConsole
});
final MessageConsoleStream consoleStream = mDdmsConsole.newMessageStream();
final MessageConsoleStream errorConsoleStream = mDdmsConsole.newMessageStream();
mRed = new Color(display, 0xFF, 0x00, 0x00);
// because this can be run, in some cases, by a non UI thread, and because
// changing the console properties update the UI, we need to make this change
// in the UI thread.
display.asyncExec(new Runnable() {
public void run() {
errorConsoleStream.setColor(mRed);
}
});
// set up the ddms log to use the ddms console.
Log.setLogOutput(new ILogOutput() {
public void printLog(LogLevel logLevel, String tag, String message) {
if (logLevel.getPriority() >= LogLevel.ERROR.getPriority()) {
printToStream(errorConsoleStream, tag, message);
ConsolePlugin.getDefault().getConsoleManager().showConsoleView(mDdmsConsole);
} else {
printToStream(consoleStream, tag, message);
}
}
public void printAndPromptLog(final LogLevel logLevel, final String tag,
final String message) {
printLog(logLevel, tag, message);
// dialog box only run in UI thread..
display.asyncExec(new Runnable() {
public void run() {
Shell shell = display.getActiveShell();
if (logLevel == LogLevel.ERROR) {
MessageDialog.openError(shell, tag, message);
} else {
MessageDialog.openWarning(shell, tag, message);
}
}
});
}
});
// create the loader that's able to load the images
mLoader = new ImageLoader(this);
// set the listener for the preference change
Preferences prefs = getPluginPreferences();
prefs.addPropertyChangeListener(new IPropertyChangeListener() {
public void propertyChange(PropertyChangeEvent event) {
// get the name of the property that changed.
String property = event.getProperty();
if (PreferenceInitializer.ATTR_DEBUG_PORT_BASE.equals(property)) {
DdmPreferences.setDebugPortBase(
eclipseStore.getInt(PreferenceInitializer.ATTR_DEBUG_PORT_BASE));
} else if (PreferenceInitializer.ATTR_SELECTED_DEBUG_PORT.equals(property)) {
DdmPreferences.setSelectedDebugPort(
eclipseStore.getInt(PreferenceInitializer.ATTR_SELECTED_DEBUG_PORT));
} else if (PreferenceInitializer.ATTR_THREAD_INTERVAL.equals(property)) {
DdmUiPreferences.setThreadRefreshInterval(
eclipseStore.getInt(PreferenceInitializer.ATTR_THREAD_INTERVAL));
} else if (PreferenceInitializer.ATTR_LOG_LEVEL.equals(property)) {
DdmPreferences.setLogLevel(
eclipseStore.getString(PreferenceInitializer.ATTR_LOG_LEVEL));
}
}
});
// read the adb location from the prefs to attempt to start it properly without
// having to wait for ADT to start
sAdbLocation = eclipseStore.getString(ADB_LOCATION);
// start it in a thread to return from start() asap.
new Thread() {
@Override
public void run() {
// init ddmlib if needed
getDefault().initDdmlib();
// create and start the first bridge
AndroidDebugBridge.createBridge(sAdbLocation, true /* forceNewBridge */);
}
}.start();
|
public void | stop(org.osgi.framework.BundleContext context)
AndroidDebugBridge.removeDeviceChangeListener(this);
AndroidDebugBridge.terminate();
mRed.dispose();
sPlugin = null;
super.stop(context);
|