diff options
author | Xavier Ducrohet <xav@android.com> | 2009-05-14 18:19:52 -0700 |
---|---|---|
committer | Xavier Ducrohet <xav@android.com> | 2009-05-15 14:01:12 -0700 |
commit | 5542fe492293223a81e604a49aa6fa55b1719847 (patch) | |
tree | 5a8377e382e930e99c7ebe0b729ae2c2833cbf22 | |
parent | c28e97a0db9c383cd656cb51f3b720dfb53b8d21 (diff) | |
download | sdk-5542fe492293223a81e604a49aa6fa55b1719847.zip sdk-5542fe492293223a81e604a49aa6fa55b1719847.tar.gz sdk-5542fe492293223a81e604a49aa6fa55b1719847.tar.bz2 |
Make the ddmlib API use IDevice instead of Device
Device is now private. All the API is using IDevice.
Updated ddms, ADT, hierarchyviewer and other tools that relied on ddmlib.
41 files changed, 841 insertions, 819 deletions
diff --git a/ddms/app/src/com/android/ddms/DebugPortProvider.java b/ddms/app/src/com/android/ddms/DebugPortProvider.java index 89cc190..76a86b7 100644 --- a/ddms/app/src/com/android/ddms/DebugPortProvider.java +++ b/ddms/app/src/com/android/ddms/DebugPortProvider.java @@ -16,7 +16,7 @@ package com.android.ddms; -import com.android.ddmlib.Device; +import com.android.ddmlib.IDevice; import com.android.ddmlib.DebugPortManager.IDebugPortProvider; import org.eclipse.jface.preference.IPreferenceStore; @@ -53,15 +53,15 @@ public class DebugPortProvider implements IDebugPortProvider { /** * Returns a static debug port for the specified application running on the - * specified {@link Device}. + * specified {@link IDevice}. * @param device The device the application is running on. * @param appName The application name, as defined in the * AndroidManifest.xml package attribute. * @return The static debug port or {@link #NO_STATIC_PORT} if there is none setup. * - * @see IDebugPortProvider#getPort(Device, String) + * @see IDebugPortProvider#getPort(IDevice, String) */ - public int getPort(Device device, String appName) { + public int getPort(IDevice device, String appName) { if (mMap != null) { Map<String, Integer> deviceMap = mMap.get(device.getSerialNumber()); if (deviceMap != null) { @@ -107,7 +107,7 @@ public class DebugPortProvider implements IDebugPortProvider { if (entry.length == 3) { deviceName = entry[2]; } else { - deviceName = Device.FIRST_EMULATOR_SN; + deviceName = IDevice.FIRST_EMULATOR_SN; } // get the device map diff --git a/ddms/app/src/com/android/ddms/DeviceCommandDialog.java b/ddms/app/src/com/android/ddms/DeviceCommandDialog.java index 2a1342e..befb994 100644 --- a/ddms/app/src/com/android/ddms/DeviceCommandDialog.java +++ b/ddms/app/src/com/android/ddms/DeviceCommandDialog.java @@ -17,7 +17,7 @@ package com.android.ddms; -import com.android.ddmlib.Device; +import com.android.ddmlib.IDevice; import com.android.ddmlib.IShellOutputReceiver; import com.android.ddmlib.Log; @@ -96,7 +96,7 @@ public class DeviceCommandDialog extends Dialog { * Prepare and display the dialog. * @param currentDevice */ - public void open(Device currentDevice) { + public void open(IDevice currentDevice) { Shell parent = getParent(); Shell shell = new Shell(parent, getStyle()); shell.setText("Remote Command"); @@ -219,13 +219,13 @@ public class DeviceCommandDialog extends Dialog { private String mCommand; private Text mText; private int mResult; - private Device mDevice; + private IDevice mDevice; /** * Constructor; pass in the text widget that will receive the output. * @param device */ - public Gatherer(Shell shell, Device device, String command, Text text) { + public Gatherer(Shell shell, IDevice device, String command, Text text) { mShell = shell; mDevice = device; mCommand = command; @@ -307,7 +307,7 @@ public class DeviceCommandDialog extends Dialog { * We have to run the command in a thread so that the UI continues * to work. */ - private void executeCommand(Shell shell, Device device) { + private void executeCommand(Shell shell, IDevice device) { Gatherer gath = new Gatherer(shell, device, commandString(), mText); gath.start(); } diff --git a/ddms/app/src/com/android/ddms/StaticPortEditDialog.java b/ddms/app/src/com/android/ddms/StaticPortEditDialog.java index 6330126..b224967 100644 --- a/ddms/app/src/com/android/ddms/StaticPortEditDialog.java +++ b/ddms/app/src/com/android/ddms/StaticPortEditDialog.java @@ -16,7 +16,7 @@ package com.android.ddms; -import com.android.ddmlib.Device; +import com.android.ddmlib.IDevice; import org.eclipse.swt.SWT; import org.eclipse.swt.events.ModifyEvent; @@ -75,7 +75,7 @@ public class StaticPortEditDialog extends Dialog { public StaticPortEditDialog(Shell parent, ArrayList<Integer> ports) { super(parent, SWT.DIALOG_TRIM | SWT.BORDER | SWT.APPLICATION_MODAL); mPorts = ports; - mDeviceSn = Device.FIRST_EMULATOR_SN; + mDeviceSn = IDevice.FIRST_EMULATOR_SN; } /** diff --git a/ddms/app/src/com/android/ddms/UIThread.java b/ddms/app/src/com/android/ddms/UIThread.java index ff89e2c..86cab20 100644 --- a/ddms/app/src/com/android/ddms/UIThread.java +++ b/ddms/app/src/com/android/ddms/UIThread.java @@ -18,7 +18,7 @@ package com.android.ddms; import com.android.ddmlib.AndroidDebugBridge; import com.android.ddmlib.Client; -import com.android.ddmlib.Device; +import com.android.ddmlib.IDevice; import com.android.ddmlib.Log; import com.android.ddmlib.Log.ILogOutput; import com.android.ddmlib.Log.LogLevel; @@ -90,7 +90,7 @@ import java.util.ArrayList; /** * This acts as the UI builder. This cannot be its own thread since this prevent using AWT in an * SWT application. So this class mainly builds the ui, and manages communication between the panels - * when {@link Device} / {@link Client} selection changes. + * when {@link IDevice} / {@link Client} selection changes. */ public class UIThread implements IUiSelectionListener { /* @@ -153,7 +153,7 @@ public class UIThread implements IUiSelectionListener { // the table we show in the left-hand pane private DevicePanel mDevicePanel; - private Device mCurrentDevice = null; + private IDevice mCurrentDevice = null; private Client mCurrentClient = null; // status line at the bottom of the app window @@ -166,7 +166,7 @@ public class UIThread implements IUiSelectionListener { private ToolItem mTBCauseGc; private ImageLoader mDdmsImageLoader; - private ImageLoader mDdmuiLibImageLoader; + private ImageLoader mDdmuiLibImageLoader; private final class FilterStorage implements ILogFilterStorageManager { @@ -238,7 +238,7 @@ public class UIThread implements IUiSelectionListener { private Shell mExplorerShell = null; private EmulatorControlPanel mEmulatorPanel; - + private EventLogPanel mEventLogPanel; private class TableFocusListener implements ITableFocusListener { @@ -333,7 +333,7 @@ public class UIThread implements IUiSelectionListener { // create the image loaders for DDMS and DDMUILIB mDdmsImageLoader = new ImageLoader(this.getClass()); mDdmuiLibImageLoader = new ImageLoader(DevicePanel.class); - + shell.setImage(ImageHelper.loadImage(mDdmsImageLoader, mDisplay, "ddms-icon.png", //$NON-NLS-1$ 100, 50, null)); @@ -883,7 +883,7 @@ public class UIThread implements IUiSelectionListener { p.setTableFocusListener(mTableListener); } } - + mStatusLine.setText(""); } @@ -892,7 +892,7 @@ public class UIThread implements IUiSelectionListener { */ private void createDevicePanelToolBar(ToolBar toolBar) { Display display = toolBar.getDisplay(); - + // add "show thread updates" button mTBShowThreadUpdates = new ToolItem(toolBar, SWT.CHECK); mTBShowThreadUpdates.setImage(ImageHelper.loadImage(mDdmuiLibImageLoader, display, @@ -949,7 +949,7 @@ public class UIThread implements IUiSelectionListener { mDevicePanel.killSelectedClient(); } }); - + new ToolItem(toolBar, SWT.SEPARATOR); // add "cause GC" button @@ -1130,7 +1130,7 @@ public class UIThread implements IUiSelectionListener { mClearAction = new ToolItemAction(toolBar, SWT.PUSH); mClearAction.item.setToolTipText("Clear Log"); - + mClearAction.item.setImage(ImageHelper.loadImage(mDdmuiLibImageLoader, mDisplay, "clear.png", //$NON-NLS-1$ DevicePanel.ICON_WIDTH, DevicePanel.ICON_WIDTH, null)); @@ -1239,12 +1239,12 @@ public class UIThread implements IUiSelectionListener { item = new TabItem(tabFolder, SWT.NONE); item.setText("Event Log"); item.setToolTipText("Event Log"); - + // create the composite that will hold the toolbar and the event log panel. Composite eventLogTopComposite = new Composite(tabFolder, SWT.NONE); item.setControl(eventLogTopComposite); eventLogTopComposite.setLayout(new GridLayout(1, false)); - + // create the toolbar and the actions ToolBar toolbar = new ToolBar(eventLogTopComposite, SWT.HORIZONTAL); toolbar.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); @@ -1260,7 +1260,7 @@ public class UIThread implements IUiSelectionListener { clearAction.item.setImage(ImageHelper.loadImage(mDdmuiLibImageLoader, comp.getDisplay(), "clear.png", //$NON-NLS-1$ DevicePanel.ICON_WIDTH, DevicePanel.ICON_WIDTH, null)); - + new ToolItem(toolbar, SWT.SEPARATOR); ToolItemAction saveAction = new ToolItemAction(toolbar, SWT.PUSH); @@ -1283,7 +1283,7 @@ public class UIThread implements IUiSelectionListener { // create the event log panel mEventLogPanel = new EventLogPanel(mDdmuiLibImageLoader); - + // set the external actions mEventLogPanel.setActions(optionsAction, clearAction, saveAction, loadAction, importBugAction); @@ -1450,13 +1450,13 @@ public class UIThread implements IUiSelectionListener { } /** - * Sent when a new {@link Device} and {@link Client} are selected. + * Sent when a new {@link IDevice} and {@link Client} are selected. * @param selectedDevice the selected device. If null, no devices are selected. * @param selectedClient The selected client. If null, no clients are selected. * * @see IUiSelectionListener */ - public void selectionChanged(Device selectedDevice, Client selectedClient) { + public void selectionChanged(IDevice selectedDevice, Client selectedClient) { if (mCurrentDevice != selectedDevice) { mCurrentDevice = selectedDevice; for (TablePanel panel : mPanels) { diff --git a/ddms/libs/ddmlib/src/com/android/ddmlib/AdbHelper.java b/ddms/libs/ddmlib/src/com/android/ddmlib/AdbHelper.java index 42022fe..5f0f271 100644 --- a/ddms/libs/ddmlib/src/com/android/ddmlib/AdbHelper.java +++ b/ddms/libs/ddmlib/src/com/android/ddmlib/AdbHelper.java @@ -29,7 +29,7 @@ import java.nio.channels.SocketChannel; /** * Helper class to handle requests and connections to adb. * <p/>{@link DebugBridgeServer} is the public API to connection to adb, while {@link AdbHelper} - * does the low level stuff. + * does the low level stuff. * <p/>This currently uses spin-wait non-blocking I/O. A Selector would be more efficient, * but seems like overkill for what we're doing here. */ @@ -272,14 +272,14 @@ final class AdbHelper { try { adbChan = SocketChannel.open(adbSockAddr); adbChan.configureBlocking(false); - + // if the device is not -1, then we first tell adb we're looking to talk // to a specific device setDevice(adbChan, device); - + if (write(adbChan, request) == false) throw new IOException("failed asking for frame buffer"); - + AdbResponse resp = readAdbResponse(adbChan, false /* readDiagString */); if (!resp.ioSuccess || !resp.okay) { Log.w("ddms", "Got timeout or unhappy response from ADB fb req: " @@ -287,7 +287,7 @@ final class AdbHelper { adbChan.close(); return null; } - + reply = new byte[16]; if (read(adbChan, reply) == false) { Log.w("ddms", "got partial reply from ADB fb:"); @@ -297,19 +297,19 @@ final class AdbHelper { } ByteBuffer buf = ByteBuffer.wrap(reply); buf.order(ByteOrder.LITTLE_ENDIAN); - + imageParams.bpp = buf.getInt(); imageParams.size = buf.getInt(); imageParams.width = buf.getInt(); imageParams.height = buf.getInt(); - + Log.d("ddms", "image params: bpp=" + imageParams.bpp + ", size=" + imageParams.size + ", width=" + imageParams.width + ", height=" + imageParams.height); - + if (write(adbChan, nudge) == false) throw new IOException("failed nudging"); - + reply = new byte[imageParams.size]; if (read(adbChan, reply) == false) { Log.w("ddms", "got truncated reply from ADB fb data"); @@ -416,34 +416,34 @@ final class AdbHelper { public static void runLogService(InetSocketAddress adbSockAddr, Device device, String logName, LogReceiver rcvr) throws IOException { SocketChannel adbChan = null; - + try { adbChan = SocketChannel.open(adbSockAddr); adbChan.configureBlocking(false); - + // if the device is not -1, then we first tell adb we're looking to talk // to a specific device setDevice(adbChan, device); - + byte[] request = formAdbRequest("log:" + logName); if (write(adbChan, request) == false) { throw new IOException("failed to submit the log command"); } - + AdbResponse resp = readAdbResponse(adbChan, false /* readDiagString */); if (!resp.ioSuccess || !resp.okay) { throw new IOException("Device rejected log command: " + resp.message); } - + byte[] data = new byte[16384]; ByteBuffer buf = ByteBuffer.wrap(data); while (true) { int count; - + if (rcvr != null && rcvr.isCancelled()) { break; } - + count = adbChan.read(buf); if (count < 0) { break; @@ -465,7 +465,7 @@ final class AdbHelper { } } } - + /** * Creates a port forwarding between a local and a remote port. * @param adbSockAddr the socket address to connect to adb @@ -473,7 +473,7 @@ final class AdbHelper { * @param localPort the local port to forward * @param remotePort the remote port. * @return <code>true</code> if success. - * @throws IOException + * @throws IOException */ public static boolean createForward(InetSocketAddress adbSockAddr, Device device, int localPort, int remotePort) throws IOException { @@ -482,15 +482,15 @@ final class AdbHelper { try { adbChan = SocketChannel.open(adbSockAddr); adbChan.configureBlocking(false); - + byte[] request = formAdbRequest(String.format( "host-serial:%1$s:forward:tcp:%2$d;tcp:%3$d", //$NON-NLS-1$ - device.serialNumber, localPort, remotePort)); - + device.getSerialNumber(), localPort, remotePort)); + if (write(adbChan, request) == false) { throw new IOException("failed to submit the forward command."); } - + AdbResponse resp = readAdbResponse(adbChan, false /* readDiagString */); if (!resp.ioSuccess || !resp.okay) { throw new IOException("Device rejected command: " + resp.message); @@ -500,7 +500,7 @@ final class AdbHelper { adbChan.close(); } } - + return true; } @@ -520,15 +520,15 @@ final class AdbHelper { try { adbChan = SocketChannel.open(adbSockAddr); adbChan.configureBlocking(false); - + byte[] request = formAdbRequest(String.format( "host-serial:%1$s:killforward:tcp:%2$d;tcp:%3$d", //$NON-NLS-1$ - device.serialNumber, localPort, remotePort)); - + device.getSerialNumber(), localPort, remotePort)); + if (!write(adbChan, request)) { throw new IOException("failed to submit the remove forward command."); } - + AdbResponse resp = readAdbResponse(adbChan, false /* readDiagString */); if (!resp.ioSuccess || !resp.okay) { throw new IOException("Device rejected command: " + resp.message); @@ -563,7 +563,7 @@ final class AdbHelper { } return result; } - + /** * Reads from the socket until the array is filled, or no more data is coming (because * the socket closed or the timeout expired). @@ -572,7 +572,7 @@ final class AdbHelper { * mode for timeouts to work * @param data the buffer to store the read data into. * @return "true" if all data was read. - * @throws IOException + * @throws IOException */ static boolean read(SocketChannel chan, byte[] data) { try { @@ -581,7 +581,7 @@ final class AdbHelper { Log.d("ddms", "readAll: IOException: " + e.getMessage()); return false; } - + return true; } @@ -597,7 +597,7 @@ final class AdbHelper { * @param data the buffer to store the read data into. * @param length the length to read or -1 to fill the data buffer completely * @param timeout The timeout value. A timeout of zero means "wait forever". - * @throws IOException + * @throws IOException */ static void read(SocketChannel chan, byte[] data, int length, int timeout) throws IOException { ByteBuffer buf = ByteBuffer.wrap(data, 0, length != -1 ? length : data.length); @@ -653,7 +653,7 @@ final class AdbHelper { * @param data the buffer to send. * @param length the length to write or -1 to send the whole buffer. * @param timeout The timeout value. A timeout of zero means "wait forever". - * @throws IOException + * @throws IOException */ static void write(SocketChannel chan, byte[] data, int length, int timeout) throws IOException { @@ -697,7 +697,7 @@ final class AdbHelper { // if the device is not -1, then we first tell adb we're looking to talk // to a specific device if (device != null) { - String msg = "host:transport:" + device.serialNumber; //$NON-NLS-1$ + String msg = "host:transport:" + device.getSerialNumber(); //$NON-NLS-1$ byte[] device_query = formAdbRequest(msg); if (write(adbChan, device_query) == false) diff --git a/ddms/libs/ddmlib/src/com/android/ddmlib/AndroidDebugBridge.java b/ddms/libs/ddmlib/src/com/android/ddmlib/AndroidDebugBridge.java index c587b4e..9d6294a 100644 --- a/ddms/libs/ddmlib/src/com/android/ddmlib/AndroidDebugBridge.java +++ b/ddms/libs/ddmlib/src/com/android/ddmlib/AndroidDebugBridge.java @@ -107,7 +107,7 @@ public final class AndroidDebugBridge { /** * Classes which implement this interface provide methods that deal - * with {@link Device} addition, deletion, and changes. + * with {@link IDevice} addition, deletion, and changes. */ public interface IDeviceChangeListener { /** @@ -116,7 +116,7 @@ public final class AndroidDebugBridge { * This is sent from a non UI thread. * @param device the new device. */ - public void deviceConnected(Device device); + public void deviceConnected(IDevice device); /** * Sent when the a device is connected to the {@link AndroidDebugBridge}. @@ -124,7 +124,7 @@ public final class AndroidDebugBridge { * This is sent from a non UI thread. * @param device the new device. */ - public void deviceDisconnected(Device device); + public void deviceDisconnected(IDevice device); /** * Sent when a device data changed, or when clients are started/terminated on the device. @@ -132,10 +132,10 @@ public final class AndroidDebugBridge { * This is sent from a non UI thread. * @param device the device that was updated. * @param changeMask the mask describing what changed. It can contain any of the following - * values: {@link Device#CHANGE_BUILD_INFO}, {@link Device#CHANGE_STATE}, - * {@link Device#CHANGE_CLIENT_LIST} + * values: {@link IDevice#CHANGE_BUILD_INFO}, {@link IDevice#CHANGE_STATE}, + * {@link IDevice#CHANGE_CLIENT_LIST} */ - public void deviceChanged(Device device, int changeMask); + public void deviceChanged(IDevice device, int changeMask); } /** @@ -215,7 +215,7 @@ public final class AndroidDebugBridge { /** * Returns whether the ddmlib is setup to support monitoring and interacting with - * {@link Client}s running on the {@link Device}s. + * {@link Client}s running on the {@link IDevice}s. */ static boolean getClientSupport() { return sClientSupport; @@ -391,7 +391,7 @@ public final class AndroidDebugBridge { } /** - * Adds the listener to the collection of listeners who will be notified when a {@link Device} + * Adds the listener to the collection of listeners who will be notified when a {@link IDevice} * is connected, disconnected, or when its properties or its {@link Client} list changed, * by sending it one of the messages defined in the {@link IDeviceChangeListener} interface. * @param listener The listener which should be notified. @@ -406,7 +406,7 @@ public final class AndroidDebugBridge { /** * Removes the listener from the collection of listeners who will be notified when a - * {@link Device} is connected, disconnected, or when its properties or its {@link Client} + * {@link IDevice} is connected, disconnected, or when its properties or its {@link Client} * list changed. * @param listener The listener which should no longer be notified. */ @@ -446,23 +446,23 @@ public final class AndroidDebugBridge { * Returns the devices. * @see #hasInitialDeviceList() */ - public Device[] getDevices() { + public IDevice[] getDevices() { synchronized (sLock) { if (mDeviceMonitor != null) { return mDeviceMonitor.getDevices(); } } - return new Device[0]; + return new IDevice[0]; } /** * Returns whether the bridge has acquired the initial list from adb after being created. * <p/>Calling {@link #getDevices()} right after {@link #createBridge(String, boolean)} will * generally result in an empty list. This is due to the internal asynchronous communication - * mechanism with <code>adb</code> that does not guarantee that the {@link Device} list has been + * mechanism with <code>adb</code> that does not guarantee that the {@link IDevice} list has been * built before the call to {@link #getDevices()}. - * <p/>The recommended way to get the list of {@link Device} objects is to create a + * <p/>The recommended way to get the list of {@link IDevice} objects is to create a * {@link IDeviceChangeListener} object. */ public boolean hasInitialDeviceList() { @@ -719,19 +719,19 @@ public final class AndroidDebugBridge { } /** - * Notify the listener of a new {@link Device}. + * Notify the listener of a new {@link IDevice}. * <p/> * The notification of the listeners is done in a synchronized block. It is important to - * expect the listeners to potentially access various methods of {@link Device} as well as + * expect the listeners to potentially access various methods of {@link IDevice} as well as * {@link #getDevices()} which use internal locks. * <p/> * For this reason, any call to this method from a method of {@link DeviceMonitor}, - * {@link Device} which is also inside a synchronized block, should first synchronize on + * {@link IDevice} which is also inside a synchronized block, should first synchronize on * the {@link AndroidDebugBridge} lock. Access to this lock is done through {@link #getLock()}. - * @param device the new <code>Device</code>. + * @param device the new <code>IDevice</code>. * @see #getLock() */ - void deviceConnected(Device device) { + void deviceConnected(IDevice device) { // because the listeners could remove themselves from the list while processing // their event callback, we make a copy of the list and iterate on it instead of // the main list. @@ -755,19 +755,19 @@ public final class AndroidDebugBridge { } /** - * Notify the listener of a disconnected {@link Device}. + * Notify the listener of a disconnected {@link IDevice}. * <p/> * The notification of the listeners is done in a synchronized block. It is important to - * expect the listeners to potentially access various methods of {@link Device} as well as + * expect the listeners to potentially access various methods of {@link IDevice} as well as * {@link #getDevices()} which use internal locks. * <p/> * For this reason, any call to this method from a method of {@link DeviceMonitor}, - * {@link Device} which is also inside a synchronized block, should first synchronize on + * {@link IDevice} which is also inside a synchronized block, should first synchronize on * the {@link AndroidDebugBridge} lock. Access to this lock is done through {@link #getLock()}. - * @param device the disconnected <code>Device</code>. + * @param device the disconnected <code>IDevice</code>. * @see #getLock() */ - void deviceDisconnected(Device device) { + void deviceDisconnected(IDevice device) { // because the listeners could remove themselves from the list while processing // their event callback, we make a copy of the list and iterate on it instead of // the main list. @@ -791,19 +791,19 @@ public final class AndroidDebugBridge { } /** - * Notify the listener of a modified {@link Device}. + * Notify the listener of a modified {@link IDevice}. * <p/> * The notification of the listeners is done in a synchronized block. It is important to - * expect the listeners to potentially access various methods of {@link Device} as well as + * expect the listeners to potentially access various methods of {@link IDevice} as well as * {@link #getDevices()} which use internal locks. * <p/> * For this reason, any call to this method from a method of {@link DeviceMonitor}, - * {@link Device} which is also inside a synchronized block, should first synchronize on + * {@link IDevice} which is also inside a synchronized block, should first synchronize on * the {@link AndroidDebugBridge} lock. Access to this lock is done through {@link #getLock()}. - * @param device the modified <code>Device</code>. + * @param device the modified <code>IDevice</code>. * @see #getLock() */ - void deviceChanged(Device device, int changeMask) { + void deviceChanged(IDevice device, int changeMask) { // because the listeners could remove themselves from the list while processing // their event callback, we make a copy of the list and iterate on it instead of // the main list. @@ -830,11 +830,11 @@ public final class AndroidDebugBridge { * Notify the listener of a modified {@link Client}. * <p/> * The notification of the listeners is done in a synchronized block. It is important to - * expect the listeners to potentially access various methods of {@link Device} as well as + * expect the listeners to potentially access various methods of {@link IDevice} as well as * {@link #getDevices()} which use internal locks. * <p/> * For this reason, any call to this method from a method of {@link DeviceMonitor}, - * {@link Device} which is also inside a synchronized block, should first synchronize on + * {@link IDevice} which is also inside a synchronized block, should first synchronize on * the {@link AndroidDebugBridge} lock. Access to this lock is done through {@link #getLock()}. * @param device the modified <code>Client</code>. * @param changeMask the mask indicating what changed in the <code>Client</code> diff --git a/ddms/libs/ddmlib/src/com/android/ddmlib/ChunkHandler.java b/ddms/libs/ddmlib/src/com/android/ddmlib/ChunkHandler.java index 441b024..74fa318 100644 --- a/ddms/libs/ddmlib/src/com/android/ddmlib/ChunkHandler.java +++ b/ddms/libs/ddmlib/src/com/android/ddmlib/ChunkHandler.java @@ -199,7 +199,7 @@ abstract class ChunkHandler { protected static Client checkDebuggerPortForAppName(Client client, String appName) { IDebugPortProvider provider = DebugPortManager.getProvider(); if (provider != null) { - Device device = client.getDevice(); + Device device = client.getDeviceImpl(); int newPort = provider.getPort(device, appName); if (newPort != IDebugPortProvider.NO_STATIC_PORT && diff --git a/ddms/libs/ddmlib/src/com/android/ddmlib/Client.java b/ddms/libs/ddmlib/src/com/android/ddmlib/Client.java index 866d578..64fbef6 100644 --- a/ddms/libs/ddmlib/src/com/android/ddmlib/Client.java +++ b/ddms/libs/ddmlib/src/com/android/ddmlib/Client.java @@ -133,7 +133,7 @@ public class Client { mConnState = ST_INIT; mClientData = new ClientData(pid); - + mThreadUpdateEnabled = DdmPreferences.getInitialThreadUpdate(); mHeapUpdateEnabled = DdmPreferences.getInitialHeapUpdate(); } @@ -147,9 +147,15 @@ public class Client { } /** - * Returns the {@link Device} on which this Client is running. + * Returns the {@link IDevice} on which this Client is running. */ - public Device getDevice() { + public IDevice getDevice() { + return mDevice; + } + + /** Returns the {@link Device} on which this Client is running. + */ + Device getDeviceImpl() { return mDevice; } @@ -238,7 +244,7 @@ public class Client { update(CHANGE_THREAD_MODE); } - + /** * Returns whether the thread update is enabled. */ @@ -268,7 +274,7 @@ public class Client { public void requestThreadStackTrace(int threadId) { HandleThread.requestThreadStackCallRefresh(this, threadId); } - + /** * Enables or disables the heap update. * <p/>If <code>true</code>, any GC will cause the client to send its heap information. @@ -320,7 +326,7 @@ public class Client { return false; } - + /** * Enables or disables the Allocation tracker for this client. * <p/>If enabled, the VM will start tracking allocation informations. A call to @@ -336,7 +342,7 @@ public class Client { Log.e("ddmlib", e); } } - + /** * Sends a request to the VM to send the enable status of the allocation tracking. * This is asynchronous. @@ -350,9 +356,9 @@ public class Client { HandleHeap.sendREAQ(this); } catch (IOException e) { Log.e("ddmlib", e); - } + } } - + /** * Sends a request to the VM to send the information about all the allocations that have * happened since the call to {@link #enableAllocationTracker(boolean)} with <var>enable</var> @@ -457,7 +463,7 @@ public class Client { } mConnState = ST_AWAIT_SHAKE; - + return true; } @@ -638,7 +644,7 @@ public class Client { */ Log.e("ddms", "Receiving data in state = " + mConnState); } - + return null; } @@ -753,7 +759,7 @@ public class Client { mDevice.removeClient(this, notify); } - + /** * Returns whether this {@link Client} has a valid connection to the application VM. */ diff --git a/ddms/libs/ddmlib/src/com/android/ddmlib/DebugPortManager.java b/ddms/libs/ddmlib/src/com/android/ddmlib/DebugPortManager.java index 9392127..defdc0e 100644 --- a/ddms/libs/ddmlib/src/com/android/ddmlib/DebugPortManager.java +++ b/ddms/libs/ddmlib/src/com/android/ddmlib/DebugPortManager.java @@ -19,12 +19,12 @@ package com.android.ddmlib; import com.android.ddmlib.Device; /** - * Centralized point to provide a {@link IDebugPortProvider} to ddmlib. - * + * Centralized point to provide a {@link IDebugPortProvider} to ddmlib. + * * <p/>When {@link Client} objects are created, they start listening for debuggers on a specific - * port. The default behavior is to start with {@link DdmPreferences#getDebugPortBase()} and + * port. The default behavior is to start with {@link DdmPreferences#getDebugPortBase()} and * increment this value for each new <code>Client</code>. - * + * * <p/>This {@link DebugPortManager} allows applications using ddmlib to provide a custom * port provider on a per-<code>Client</code> basis, depending on the device/emulator they are * running on, and/or their names. @@ -48,7 +48,7 @@ public class DebugPortManager { * @return The non-random debugger port or {@link #NO_STATIC_PORT} if the {@link Client} * should use the automatic debugger port provider. */ - public int getPort(Device device, String appName); + public int getPort(IDevice device, String appName); } private static IDebugPortProvider sProvider = null; @@ -63,7 +63,7 @@ public class DebugPortManager { } /** - * Returns the + * Returns the * @return */ static IDebugPortProvider getProvider() { diff --git a/ddms/libs/ddmlib/src/com/android/ddmlib/Device.java b/ddms/libs/ddmlib/src/com/android/ddmlib/Device.java index 37b33cf..d9d1275 100644 --- a/ddms/libs/ddmlib/src/com/android/ddmlib/Device.java +++ b/ddms/libs/ddmlib/src/com/android/ddmlib/Device.java @@ -16,7 +16,6 @@ package com.android.ddmlib; -import com.android.ddmlib.Client; import com.android.ddmlib.log.LogReceiver; import java.io.IOException; @@ -30,50 +29,20 @@ import java.util.Map; /** * A Device. It can be a physical device or an emulator. - * - * TODO: make this class package-protected, and shift all callers to use IDevice */ -public final class Device implements IDevice { - /** - * The state of a device. - */ - public static enum DeviceState { - BOOTLOADER("bootloader"), //$NON-NLS-1$ - OFFLINE("offline"), //$NON-NLS-1$ - ONLINE("device"); //$NON-NLS-1$ - - private String mState; - - DeviceState(String state) { - mState = state; - } - - /** - * Returns a {@link DeviceState} from the string returned by <code>adb devices</code>. - * @param state the device state. - * @return a {@link DeviceState} object or <code>null</code> if the state is unknown. - */ - public static DeviceState getState(String state) { - for (DeviceState deviceState : values()) { - if (deviceState.mState.equals(state)) { - return deviceState; - } - } - return null; - } - } +final class Device implements IDevice { /** Emulator Serial Number regexp. */ final static String RE_EMULATOR_SN = "emulator-(\\d+)"; //$NON-NLS-1$ /** Serial number of the device */ - String serialNumber = null; + private String mSerialNumber = null; /** Name of the AVD */ - String mAvdName = null; + private String mAvdName = null; /** State of the device. */ - DeviceState state = null; + private DeviceState mState = null; /** Device properties. */ private final Map<String, String> mProperties = new HashMap<String, String>(); @@ -91,22 +60,42 @@ public final class Device implements IDevice { * @see com.android.ddmlib.IDevice#getSerialNumber() */ public String getSerialNumber() { - return serialNumber; + return mSerialNumber; } + /** {@inheritDoc} */ public String getAvdName() { return mAvdName; } + /** + * Sets the name of the AVD + */ + void setAvdName(String avdName) { + if (isEmulator() == false) { + throw new IllegalArgumentException( + "Cannot set the AVD name of the device is not an emulator"); + } + + mAvdName = avdName; + } /* * (non-Javadoc) * @see com.android.ddmlib.IDevice#getState() */ public DeviceState getState() { - return state; + return mState; } + /** + * Changes the state of the device. + */ + void setState(DeviceState state) { + mState = state; + } + + /* * (non-Javadoc) * @see com.android.ddmlib.IDevice#getProperties() @@ -134,7 +123,7 @@ public final class Device implements IDevice { @Override public String toString() { - return serialNumber; + return mSerialNumber; } /* @@ -142,7 +131,7 @@ public final class Device implements IDevice { * @see com.android.ddmlib.IDevice#isOnline() */ public boolean isOnline() { - return state == DeviceState.ONLINE; + return mState == DeviceState.ONLINE; } /* @@ -150,7 +139,7 @@ public final class Device implements IDevice { * @see com.android.ddmlib.IDevice#isEmulator() */ public boolean isEmulator() { - return serialNumber.matches(RE_EMULATOR_SN); + return mSerialNumber.matches(RE_EMULATOR_SN); } /* @@ -158,7 +147,7 @@ public final class Device implements IDevice { * @see com.android.ddmlib.IDevice#isOffline() */ public boolean isOffline() { - return state == DeviceState.OFFLINE; + return mState == DeviceState.OFFLINE; } /* @@ -166,7 +155,7 @@ public final class Device implements IDevice { * @see com.android.ddmlib.IDevice#isBootLoader() */ public boolean isBootLoader() { - return state == DeviceState.BOOTLOADER; + return mState == DeviceState.BOOTLOADER; } /* @@ -305,8 +294,10 @@ public final class Device implements IDevice { } - Device(DeviceMonitor monitor) { + Device(DeviceMonitor monitor, String serialNumber, DeviceState deviceState) { mMonitor = monitor; + mSerialNumber = serialNumber; + mState = deviceState; } DeviceMonitor getMonitor() { diff --git a/ddms/libs/ddmlib/src/com/android/ddmlib/DeviceMonitor.java b/ddms/libs/ddmlib/src/com/android/ddmlib/DeviceMonitor.java index 87e023a..3382067 100644 --- a/ddms/libs/ddmlib/src/com/android/ddmlib/DeviceMonitor.java +++ b/ddms/libs/ddmlib/src/com/android/ddmlib/DeviceMonitor.java @@ -18,7 +18,7 @@ package com.android.ddmlib; import com.android.ddmlib.AdbHelper.AdbResponse; import com.android.ddmlib.DebugPortManager.IDebugPortProvider; -import com.android.ddmlib.Device.DeviceState; +import com.android.ddmlib.IDevice.DeviceState; import java.io.IOException; import java.io.UnsupportedEncodingException; @@ -112,11 +112,11 @@ final class DeviceMonitor { boolean isMonitoring() { return mMonitoring; } - + int getConnectionAttemptCount() { return mConnectionAttempt; } - + int getRestartAttemptCount() { return mRestartAttemptCount; } @@ -129,7 +129,7 @@ final class DeviceMonitor { return mDevices.toArray(new Device[mDevices.size()]); } } - + boolean hasInitialDeviceList() { return mInitialDeviceListDone; } @@ -184,11 +184,11 @@ final class DeviceMonitor { if (mMonitoring) { // read the length of the incoming message int length = readLength(mMainAdbConnection, mLengthBuffer); - + if (length >= 0) { // read the incoming message processIncomingDeviceData(length); - + // flag the fact that we have build the list at least once. mInitialDeviceListDone = true; } @@ -278,20 +278,19 @@ final class DeviceMonitor { */ private void processIncomingDeviceData(int length) throws IOException { ArrayList<Device> list = new ArrayList<Device>(); - + if (length > 0) { byte[] buffer = new byte[length]; String result = read(mMainAdbConnection, buffer); - + String[] devices = result.split("\n"); // $NON-NLS-1$ for (String d : devices) { String[] param = d.split("\t"); // $NON-NLS-1$ if (param.length == 2) { // new adb uses only serial numbers to identify devices - Device device = new Device(this); - device.serialNumber = param[0]; - device.state = DeviceState.getState(param[1]); + Device device = new Device(this, param[0] /*serialnumber*/, + DeviceState.getState(param[1])); //add the device to the list list.add(device); @@ -319,24 +318,24 @@ final class DeviceMonitor { // * if we do not find it, we remove it from the current list. // Once this is done, the new list contains device we aren't monitoring yet, so we // add them to the list, and start monitoring them. - + for (int d = 0 ; d < mDevices.size() ;) { Device device = mDevices.get(d); - + // look for a similar device in the new list. int count = newList.size(); boolean foundMatch = false; for (int dd = 0 ; dd < count ; dd++) { Device newDevice = newList.get(dd); // see if it matches in id and serial number. - if (newDevice.serialNumber.equals(device.serialNumber)) { + if (newDevice.getSerialNumber().equals(device.getSerialNumber())) { foundMatch = true; - + // update the state if needed. - if (device.state != newDevice.state) { - device.state = newDevice.state; + if (device.getState() != newDevice.getState()) { + device.setState(newDevice.getState()); device.update(Device.CHANGE_STATE); - + // if the device just got ready/online, we need to start // monitoring it. if (device.isOnline()) { @@ -344,7 +343,7 @@ final class DeviceMonitor { if (startMonitoringDevice(device) == false) { Log.e("DeviceMonitor", "Failed to start monitoring " - + device.serialNumber); + + device.getSerialNumber()); } } @@ -353,13 +352,13 @@ final class DeviceMonitor { } } } - + // remove the new device from the list since it's been used newList.remove(dd); break; } } - + if (foundMatch == false) { // the device is gone, we need to remove it, and keep current index // to process the next one. @@ -370,21 +369,21 @@ final class DeviceMonitor { d++; } } - + // at this point we should still have some new devices in newList, so we // process them. for (Device newDevice : newList) { // add them to the list mDevices.add(newDevice); mServer.deviceConnected(newDevice); - + // start monitoring them. if (AndroidDebugBridge.getClientSupport() == true) { if (newDevice.isOnline()) { startMonitoringDevice(newDevice); } } - + // look for their build info. if (newDevice.isOnline()) { queryNewDeviceForInfo(newDevice); @@ -398,7 +397,7 @@ final class DeviceMonitor { private void removeDevice(Device device) { device.clearClientList(); mDevices.remove(device); - + SocketChannel channel = device.getClientMonitoringSocket(); if (channel != null) { try { @@ -419,12 +418,12 @@ final class DeviceMonitor { // first get the list of properties. device.executeShellCommand(GetPropReceiver.GETPROP_COMMAND, new GetPropReceiver(device)); - + // now get the emulator Virtual Device name (if applicable). if (device.isEmulator()) { EmulatorConsole console = EmulatorConsole.getConsole(device); if (console != null) { - device.mAvdName = console.getAvdName(); + device.setAvdName(console.getAvdName()); } } } catch (IOException e) { @@ -510,7 +509,7 @@ final class DeviceMonitor { MonitorThread monitorThread = MonitorThread.getInstance(); for (Client client : clients) { - Device device = client.getDevice(); + Device device = client.getDeviceImpl(); int pid = client.getClientData().getPid(); monitorThread.dropClient(client, false /* notify */); @@ -623,10 +622,10 @@ final class DeviceMonitor { if (length > 0) { byte[] buffer = new byte[length]; String result = read(monitorSocket, buffer); - + // split each line in its own list and create an array of integer pid String[] pids = result.split("\n"); //$NON-NLS-1$ - + for (String pid : pids) { try { pidList.add(Integer.valueOf(pid)); @@ -662,7 +661,7 @@ final class DeviceMonitor { for (int c = 0 ; c < clients.size() ;) { Client client = clients.get(c); int pid = client.getClientData().getPid(); - + // look for a matching pid Integer match = null; for (Integer matchingPid : pidList) { @@ -671,7 +670,7 @@ final class DeviceMonitor { break; } } - + if (match != null) { pidList.remove(match); c++; // move on to the next client. @@ -705,7 +704,7 @@ final class DeviceMonitor { * @return */ private void openClient(Device device, int pid, int port, MonitorThread monitorThread) { - + SocketChannel clientSocket; try { clientSocket = AdbHelper.createPassThroughConnection( @@ -721,7 +720,7 @@ final class DeviceMonitor { "Failed to connect to client '" + pid + "': " + ioe.getMessage()); return ; } - + createClient(device, pid, clientSocket, port, monitorThread); } @@ -814,7 +813,7 @@ final class DeviceMonitor { } } } - + /** * Reads the length of the next message from a socket. * @param socket The {@link SocketChannel} to read from. diff --git a/ddms/libs/ddmlib/src/com/android/ddmlib/EmulatorConsole.java b/ddms/libs/ddmlib/src/com/android/ddmlib/EmulatorConsole.java index f3986ed..75347c6 100644 --- a/ddms/libs/ddmlib/src/com/android/ddmlib/EmulatorConsole.java +++ b/ddms/libs/ddmlib/src/com/android/ddmlib/EmulatorConsole.java @@ -41,7 +41,7 @@ import java.util.regex.Pattern; * code removes <code>\r</code> and waits for <code>\n</code>. * <p/>However this means you <i>may</i> receive <code>\r\n</code> when reading from the console. * <p/> - * <b>This API will change in the near future.</b> + * <b>This API will change in the near future.</b> */ public final class EmulatorConsole { @@ -65,7 +65,7 @@ public final class EmulatorConsole { private final static String COMMAND_NETWORK_STATUS = "network status\r\n"; //$NON-NLS-1$ private final static String COMMAND_NETWORK_SPEED = "network speed %1$s\r\n"; //$NON-NLS-1$ private final static String COMMAND_NETWORK_LATENCY = "network delay %1$s\r\n"; //$NON-NLS-1$ - private final static String COMMAND_GPS = + private final static String COMMAND_GPS = "geo nmea $GPGGA,%1$02d%2$02d%3$02d.%4$03d," + //$NON-NLS-1$ "%5$03d%6$09.6f,%7$c,%8$03d%9$09.6f,%10$c," + //$NON-NLS-1$ "1,10,0.0,0.0,0,0.0,0,0.0,0000\r\n"; //$NON-NLS-1$ @@ -202,9 +202,9 @@ public final class EmulatorConsole { * @param d The device that the console links to. * @return an <code>EmulatorConsole</code> object or <code>null</code> if the connection failed. */ - public static synchronized EmulatorConsole getConsole(Device d) { + public static synchronized EmulatorConsole getConsole(IDevice d) { // we need to make sure that the device is an emulator - Matcher m = sEmulatorRegexp.matcher(d.serialNumber); + Matcher m = sEmulatorRegexp.matcher(d.getSerialNumber()); if (m.matches()) { // get the port number. This is the console port. int port; @@ -308,7 +308,7 @@ public final class EmulatorConsole { RemoveConsole(mPort); } } - + public synchronized String getAvdName() { if (sendCommand(COMMAND_AVD_NAME)) { String[] result = readLines(); @@ -323,7 +323,7 @@ public final class EmulatorConsole { } } } - + return null; } @@ -517,18 +517,18 @@ public final class EmulatorConsole { String command = String.format(COMMAND_NETWORK_LATENCY, NETWORK_LATENCIES[selectionIndex]); return processCommand(command); } - + public synchronized String sendLocation(double longitude, double latitude, double elevation) { - + Calendar c = Calendar.getInstance(); - + double absLong = Math.abs(longitude); int longDegree = (int)Math.floor(absLong); char longDirection = 'E'; if (longitude < 0) { longDirection = 'W'; } - + double longMinute = (absLong - Math.floor(absLong)) * 60; double absLat = Math.abs(latitude); @@ -537,15 +537,15 @@ public final class EmulatorConsole { if (latitude < 0) { latDirection = 'S'; } - + double latMinute = (absLat - Math.floor(absLat)) * 60; - + String command = String.format(COMMAND_GPS, c.get(Calendar.HOUR_OF_DAY), c.get(Calendar.MINUTE), c.get(Calendar.SECOND), c.get(Calendar.MILLISECOND), latDegree, latMinute, latDirection, longDegree, longMinute, longDirection); - + return processCommand(command); } @@ -617,7 +617,7 @@ public final class EmulatorConsole { ByteBuffer buf = ByteBuffer.wrap(mBuffer, 0, mBuffer.length); int numWaits = 0; boolean stop = false; - + while (buf.position() != buf.limit() && stop == false) { int count; diff --git a/ddms/libs/ddmlib/src/com/android/ddmlib/IDevice.java b/ddms/libs/ddmlib/src/com/android/ddmlib/IDevice.java index a54af8a..3a2bd55 100755 --- a/ddms/libs/ddmlib/src/com/android/ddmlib/IDevice.java +++ b/ddms/libs/ddmlib/src/com/android/ddmlib/IDevice.java @@ -16,7 +16,6 @@ package com.android.ddmlib; -import com.android.ddmlib.Device.DeviceState; import com.android.ddmlib.log.LogReceiver; import java.io.IOException; @@ -41,6 +40,35 @@ public interface IDevice { public static final int CHANGE_BUILD_INFO = 0x0004; /** + * The state of a device. + */ + public static enum DeviceState { + BOOTLOADER("bootloader"), //$NON-NLS-1$ + OFFLINE("offline"), //$NON-NLS-1$ + ONLINE("device"); //$NON-NLS-1$ + + private String mState; + + DeviceState(String state) { + mState = state; + } + + /** + * Returns a {@link DeviceState} from the string returned by <code>adb devices</code>. + * @param state the device state. + * @return a {@link DeviceState} object or <code>null</code> if the state is unknown. + */ + public static DeviceState getState(String state) { + for (DeviceState deviceState : values()) { + if (deviceState.mState.equals(state)) { + return deviceState; + } + } + return null; + } + } + + /** * Returns the serial number of the device. */ public String getSerialNumber(); diff --git a/ddms/libs/ddmlib/src/com/android/ddmlib/MonitorThread.java b/ddms/libs/ddmlib/src/com/android/ddmlib/MonitorThread.java index 79eb5bb..3089c2e 100644 --- a/ddms/libs/ddmlib/src/com/android/ddmlib/MonitorThread.java +++ b/ddms/libs/ddmlib/src/com/android/ddmlib/MonitorThread.java @@ -103,7 +103,7 @@ final class MonitorThread extends Thread { /** - * Sets or changes the port number for "debug selected". + * Sets or changes the port number for "debug selected". */ synchronized void setDebugSelectedPort(int port) throws IllegalStateException { if (mInstance == null) { @@ -206,7 +206,7 @@ final class MonitorThread extends Thread { } while (!mQuit) { - + try { /* * sync with new registrations: we wait until addClient is done before going through @@ -215,7 +215,7 @@ final class MonitorThread extends Thread { */ synchronized (mClientList) { } - + // (re-)open the "debug selected" port, if it's not opened yet or // if the port changed. try { @@ -234,7 +234,7 @@ final class MonitorThread extends Thread { Log.e("ddms", ioe); mNewDebugSelectedPort = mDebugSelectedPort; // no retry } - + int count; try { count = mSelector.select(); @@ -244,20 +244,20 @@ final class MonitorThread extends Thread { } catch (CancelledKeyException cke) { continue; } - + if (count == 0) { // somebody called wakeup() ? // Log.i("ddms", "selector looping"); continue; } - + Set<SelectionKey> keys = mSelector.selectedKeys(); Iterator<SelectionKey> iter = keys.iterator(); - + while (iter.hasNext()) { SelectionKey key = iter.next(); iter.remove(); - + try { if (key.attachment() instanceof Client) { processClientActivity(key); @@ -300,7 +300,7 @@ final class MonitorThread extends Thread { */ private void processClientActivity(SelectionKey key) { Client client = (Client)key.attachment(); - + try { if (key.isReadable() == false || key.isValid() == false) { Log.d("ddms", "Invalid key from " + client + ". Dropping client."); @@ -423,7 +423,7 @@ final class MonitorThread extends Thread { * @param notify */ synchronized void dropClient(Client client, boolean notify) { - if (mInstance == null) { + if (mInstance == null) { return; } @@ -551,13 +551,13 @@ final class MonitorThread extends Thread { // we should drop the client, but also attempt to reopen it. // This is done by the DeviceMonitor. - client.getDevice().getMonitor().addClientToDropAndReopen(client, + client.getDeviceImpl().getMonitor().addClientToDropAndReopen(client, IDebugPortProvider.NO_STATIC_PORT); } else { Log.i("ddms", " (recycling client connection as well)"); // we should drop the client, but also attempt to reopen it. // This is done by the DeviceMonitor. - client.getDevice().getMonitor().addClientToDropAndReopen(client, + client.getDeviceImpl().getMonitor().addClientToDropAndReopen(client, IDebugPortProvider.NO_STATIC_PORT); } } @@ -644,7 +644,7 @@ final class MonitorThread extends Thread { } } } - + /* * Broadcast an event to all message handlers. */ @@ -719,7 +719,7 @@ final class MonitorThread extends Thread { } mDebugSelectedChan.register(mSelector, SelectionKey.OP_ACCEPT, this); - + return true; } catch (java.net.BindException e) { displayDebugSelectedBindError(mNewDebugSelectedPort); @@ -727,7 +727,7 @@ final class MonitorThread extends Thread { // do not attempt to reopen it. mDebugSelectedChan = null; mNewDebugSelectedPort = -1; - + return false; } } diff --git a/ddms/libs/ddmlib/src/com/android/ddmlib/log/EventLogParser.java b/ddms/libs/ddmlib/src/com/android/ddmlib/log/EventLogParser.java index 85e99c1..0b2ce69 100644 --- a/ddms/libs/ddmlib/src/com/android/ddmlib/log/EventLogParser.java +++ b/ddms/libs/ddmlib/src/com/android/ddmlib/log/EventLogParser.java @@ -16,7 +16,7 @@ package com.android.ddmlib.log; -import com.android.ddmlib.Device; +import com.android.ddmlib.IDevice; import com.android.ddmlib.Log; import com.android.ddmlib.MultiLineReceiver; import com.android.ddmlib.log.EventContainer.EventValueType; @@ -55,7 +55,7 @@ public final class EventLogParser { private final static int EVENT_TYPE_LONG = 1; private final static int EVENT_TYPE_STRING = 2; private final static int EVENT_TYPE_LIST = 3; - + private final static Pattern PATTERN_SIMPLE_TAG = Pattern.compile( "^(\\d+)\\s+([A-Za-z0-9_]+)\\s*$"); //$NON-NLS-1$ private final static Pattern PATTERN_TAG_WITH_DESC = Pattern.compile( @@ -67,9 +67,9 @@ public final class EventLogParser { "(\\d\\d)-(\\d\\d)\\s(\\d\\d):(\\d\\d):(\\d\\d).(\\d{3})\\s+I/([a-zA-Z0-9_]+)\\s*\\(\\s*(\\d+)\\):\\s+(.*)"); //$NON-NLS-1$ private final TreeMap<Integer, String> mTagMap = new TreeMap<Integer, String>(); - + private final TreeMap<Integer, EventValueDescription[]> mValueDescriptionMap = - new TreeMap<Integer, EventValueDescription[]>(); + new TreeMap<Integer, EventValueDescription[]>(); public EventLogParser() { } @@ -82,7 +82,7 @@ public final class EventLogParser { * @param device The device. * @return <code>true</code> if success, <code>false</code> if failure or cancellation. */ - public boolean init(Device device) { + public boolean init(IDevice device) { // read the event tag map file on the device. try { device.executeShellCommand("cat " + EVENT_TAG_MAP_FILE, //$NON-NLS-1$ @@ -103,7 +103,7 @@ public final class EventLogParser { return true; } - + /** * Inits the parser with the content of a tag file. * @param tagFileContent the lines of a tag file. @@ -115,7 +115,7 @@ public final class EventLogParser { } return true; } - + /** * Inits the parser with a specified event-log-tags file. * @param filePath @@ -124,7 +124,7 @@ public final class EventLogParser { public boolean init(String filePath) { try { BufferedReader reader = new BufferedReader(new FileReader(filePath)); - + String line = null; do { line = reader.readLine(); @@ -132,13 +132,13 @@ public final class EventLogParser { processTagLine(line); } } while (line != null); - + return true; } catch (IOException e) { return false; } } - + /** * Processes a line from the event-log-tags file. * @param line the line to process @@ -154,7 +154,7 @@ public final class EventLogParser { if (name != null && mTagMap.get(value) == null) { mTagMap.put(value, name); } - + // special case for the GC tag. We ignore what is in the file, // and take what the custom GcEventContainer class tells us. // This is due to the event encoding several values on 2 longs. @@ -163,12 +163,12 @@ public final class EventLogParser { mValueDescriptionMap.put(value, GcEventContainer.getValueDescriptions()); } else { - + String description = m.group(3); if (description != null && description.length() > 0) { EventValueDescription[] desc = processDescription(description); - + if (desc != null) { mValueDescriptionMap.put(value, desc); } @@ -189,12 +189,12 @@ public final class EventLogParser { } } } - + private EventValueDescription[] processDescription(String description) { String[] descriptions = description.split("\\s*,\\s*"); //$NON-NLS-1$ - + ArrayList<EventValueDescription> list = new ArrayList<EventValueDescription>(); - + for (String desc : descriptions) { Matcher m = PATTERN_DESCRIPTION.matcher(desc); if (m.matches()) { @@ -208,15 +208,15 @@ public final class EventLogParser { // just ignore this description if the value is not recognized. // TODO: log the error. } - + typeString = m.group(3); if (typeString != null && typeString.length() > 0) { //skip the | typeString = typeString.substring(1); - + typeValue = Integer.parseInt(typeString); ValueType valueType = ValueType.getValueType(typeValue); - + list.add(new EventValueDescription(name, eventValueType, valueType)); } else { list.add(new EventValueDescription(name, eventValueType)); @@ -233,15 +233,15 @@ public final class EventLogParser { String.format("Can't parse %1$s", description)); //$NON-NLS-1$ } } - + if (list.size() == 0) { return null; } - + return list.toArray(new EventValueDescription[list.size()]); - + } - + public EventContainer parse(LogEntry entry) { if (entry.len < 4) { return null; @@ -251,7 +251,7 @@ public final class EventLogParser { int tagValue = ArrayHelper.swap32bitFromArray(entry.data, inOffset); inOffset += 4; - + String tag = mTagMap.get(tagValue); if (tag == null) { Log.e("EventLogParser", String.format("unknown tag number: %1$d", tagValue)); @@ -275,10 +275,10 @@ public final class EventLogParser { } else { event = new EventContainer(entry, tagValue, data); } - + return event; } - + public EventContainer parse(String textLogLine) { // line will look like // 04-29 23:16:16.691 I/dvm_gc_info( 427): <data> @@ -289,7 +289,7 @@ public final class EventLogParser { if (textLogLine.length() == 0) { return null; } - + // parse the header first Matcher m = TEXT_LOG_LINE.matcher(textLogLine); if (m.matches()) { @@ -300,7 +300,7 @@ public final class EventLogParser { int minutes = Integer.parseInt(m.group(4)); int seconds = Integer.parseInt(m.group(5)); int milliseconds = Integer.parseInt(m.group(6)); - + // convert into seconds since epoch and nano-seconds. Calendar cal = Calendar.getInstance(); cal.set(cal.get(Calendar.YEAR), month-1, day, hours, minutes, seconds); @@ -308,7 +308,7 @@ public final class EventLogParser { int nsec = milliseconds * 1000000; String tag = m.group(7); - + // get the numerical tag value int tagValue = -1; Set<Entry<Integer, String>> tagSet = mTagMap.entrySet(); @@ -318,18 +318,18 @@ public final class EventLogParser { break; } } - + if (tagValue == -1) { return null; } - + int pid = Integer.parseInt(m.group(8)); - + Object data = parseTextData(m.group(9), tagValue); if (data == null) { return null; } - + // now we can allocate and return the EventContainer EventContainer event = null; if (tagValue == GcEventContainer.GC_EVENT_TAG) { @@ -337,20 +337,20 @@ public final class EventLogParser { } else { event = new EventContainer(tagValue, pid, -1 /* tid */, sec, nsec, data); } - + return event; } catch (NumberFormatException e) { return null; } } - + return null; } - + public Map<Integer, String> getTagMap() { return mTagMap; } - + public Map<Integer, EventValueDescription[]> getEventInfoMap() { return mValueDescriptionMap; } @@ -370,7 +370,7 @@ public final class EventLogParser { if (eventData.length - dataOffset < 1) return -1; - + int offset = dataOffset; int type = eventData[offset++]; @@ -385,7 +385,7 @@ public final class EventLogParser { return -1; ival = ArrayHelper.swap32bitFromArray(eventData, offset); offset += 4; - + list.add(new Integer(ival)); } break; @@ -396,7 +396,7 @@ public final class EventLogParser { return -1; lval = ArrayHelper.swap64bitFromArray(eventData, offset); offset += 8; - + list.add(new Long(lval)); } break; @@ -410,7 +410,7 @@ public final class EventLogParser { if (eventData.length - offset < strLen) return -1; - + // get the string try { String str = new String(eventData, offset, strLen, "UTF-8"); //$NON-NLS-1$ @@ -434,7 +434,7 @@ public final class EventLogParser { if (result == -1) { return result; } - + offset += result; } @@ -446,59 +446,59 @@ public final class EventLogParser { String.format("Unknown binary event type %1$d", type)); //$NON-NLS-1$ return -1; } - + return offset - dataOffset; } - + private Object parseTextData(String data, int tagValue) { // first, get the description of what we're supposed to parse EventValueDescription[] desc = mValueDescriptionMap.get(tagValue); - + if (desc == null) { // TODO parse and create string values. return null; } - + if (desc.length == 1) { return getObjectFromString(data, desc[0].getEventValueType()); } else if (data.startsWith("[") && data.endsWith("]")) { data = data.substring(1, data.length() - 1); - + // get each individual values as String String[] values = data.split(","); - + if (tagValue == GcEventContainer.GC_EVENT_TAG) { // special case for the GC event! Object[] objects = new Object[2]; - + objects[0] = getObjectFromString(values[0], EventValueType.LONG); objects[1] = getObjectFromString(values[1], EventValueType.LONG); - + return objects; } else { // must be the same number as the number of descriptors. if (values.length != desc.length) { return null; } - + Object[] objects = new Object[values.length]; - + for (int i = 0 ; i < desc.length ; i++) { Object obj = getObjectFromString(values[i], desc[i].getEventValueType()); if (obj == null) { return null; } - objects[i] = obj; + objects[i] = obj; } - + return objects; } } - + return null; } - + private Object getObjectFromString(String value, EventValueType type) { try { switch (type) { @@ -512,14 +512,14 @@ public final class EventLogParser { } catch (NumberFormatException e) { // do nothing, we'll return null. } - + return null; } /** - * Recreates the event-log-tags at the specified file path. + * Recreates the event-log-tags at the specified file path. * @param filePath the file path to write the file. - * @throws IOException + * @throws IOException */ public void saveTags(String filePath) throws IOException { File destFile = new File(filePath); @@ -527,16 +527,16 @@ public final class EventLogParser { FileOutputStream fos = null; try { - + fos = new FileOutputStream(destFile); - + for (Integer key : mTagMap.keySet()) { // get the tag name String tagName = mTagMap.get(key); - + // get the value descriptions EventValueDescription[] descriptors = mValueDescriptionMap.get(key); - + String line = null; if (descriptors != null) { StringBuilder sb = new StringBuilder(); @@ -557,12 +557,12 @@ public final class EventLogParser { sb.append("|)"); //$NON-NLS-1$ } sb.append("\n"); //$NON-NLS-1$ - + line = sb.toString(); } else { line = String.format("%1$d %2$s\n", key, tagName); //$NON-NLS-1$ } - + byte[] buffer = line.getBytes(); fos.write(buffer); } diff --git a/ddms/libs/ddmlib/tests/src/com/android/ddmlib/testrunner/RemoteAndroidTestRunnerTest.java b/ddms/libs/ddmlib/tests/src/com/android/ddmlib/testrunner/RemoteAndroidTestRunnerTest.java index 864e219..04b42cc 100644 --- a/ddms/libs/ddmlib/tests/src/com/android/ddmlib/testrunner/RemoteAndroidTestRunnerTest.java +++ b/ddms/libs/ddmlib/tests/src/com/android/ddmlib/testrunner/RemoteAndroidTestRunnerTest.java @@ -22,7 +22,6 @@ import com.android.ddmlib.IDevice; import com.android.ddmlib.IShellOutputReceiver; import com.android.ddmlib.RawImage; import com.android.ddmlib.SyncService; -import com.android.ddmlib.Device.DeviceState; import com.android.ddmlib.log.LogReceiver; import java.io.IOException; @@ -100,7 +99,7 @@ public class RemoteAndroidTestRunnerTest extends TestCase { final String extraArgValue = "blahValue"; mRunner.addInstrumentationArg(extraArgName, extraArgValue); mRunner.run(new EmptyListener()); - assertStringsEquals(String.format("am instrument -w -r -e %s %s %s/%s", extraArgName, + assertStringsEquals(String.format("am instrument -w -r -e %s %s %s/%s", extraArgName, extraArgValue, TEST_PACKAGE, TEST_RUNNER), mMockDevice.getLastShellCommand()); } diff --git a/ddms/libs/ddmuilib/src/com/android/ddmuilib/DevicePanel.java b/ddms/libs/ddmuilib/src/com/android/ddmuilib/DevicePanel.java index 81b757e..d9d6fa1 100644 --- a/ddms/libs/ddmuilib/src/com/android/ddmuilib/DevicePanel.java +++ b/ddms/libs/ddmuilib/src/com/android/ddmuilib/DevicePanel.java @@ -20,11 +20,11 @@ import com.android.ddmlib.AndroidDebugBridge; import com.android.ddmlib.Client; import com.android.ddmlib.ClientData; import com.android.ddmlib.DdmPreferences; -import com.android.ddmlib.Device; +import com.android.ddmlib.IDevice; import com.android.ddmlib.AndroidDebugBridge.IClientChangeListener; import com.android.ddmlib.AndroidDebugBridge.IDebugBridgeChangeListener; import com.android.ddmlib.AndroidDebugBridge.IDeviceChangeListener; -import com.android.ddmlib.Device.DeviceState; +import com.android.ddmlib.IDevice.DeviceState; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.viewers.ILabelProviderListener; @@ -69,16 +69,16 @@ public final class DevicePanel extends Panel implements IDebugBridgeChangeListen private final static int CLIENT_COL_THREAD = 2; private final static int CLIENT_COL_HEAP = 3; private final static int CLIENT_COL_PORT = 4; - + public final static int ICON_WIDTH = 16; public final static String ICON_THREAD = "thread.png"; //$NON-NLS-1$ public final static String ICON_HEAP = "heap.png"; //$NON-NLS-1$ public final static String ICON_HALT = "halt.png"; //$NON-NLS-1$ public final static String ICON_GC = "gc.png"; //$NON-NLS-1$ - private Device mCurrentDevice; + private IDevice mCurrentDevice; private Client mCurrentClient; - + private Tree mTree; private TreeViewer mTreeViewer; @@ -92,8 +92,8 @@ public final class DevicePanel extends Panel implements IDebugBridgeChangeListen private Image mDebugErrorImage; private final ArrayList<IUiSelectionListener> mListeners = new ArrayList<IUiSelectionListener>(); - - private final ArrayList<Device> mDevicesToExpand = new ArrayList<Device>(); + + private final ArrayList<IDevice> mDevicesToExpand = new ArrayList<IDevice>(); private IImageLoader mLoader; @@ -102,13 +102,13 @@ public final class DevicePanel extends Panel implements IDebugBridgeChangeListen /** * A Content provider for the {@link TreeViewer}. * <p/> - * The input is a {@link AndroidDebugBridge}. First level elements are {@link Device} objects, + * The input is a {@link AndroidDebugBridge}. First level elements are {@link IDevice} objects, * and second level elements are {@link Client} object. */ private class ContentProvider implements ITreeContentProvider { public Object[] getChildren(Object parentElement) { - if (parentElement instanceof Device) { - return ((Device)parentElement).getClients(); + if (parentElement instanceof IDevice) { + return ((IDevice)parentElement).getClients(); } return new Object[0]; } @@ -121,8 +121,8 @@ public final class DevicePanel extends Panel implements IDebugBridgeChangeListen } public boolean hasChildren(Object element) { - if (element instanceof Device) { - return ((Device)element).hasClients(); + if (element instanceof IDevice) { + return ((IDevice)element).hasClients(); } // Clients never have children. @@ -147,13 +147,13 @@ public final class DevicePanel extends Panel implements IDebugBridgeChangeListen /** * A Label Provider for the {@link TreeViewer} in {@link DevicePanel}. It provides - * labels and images for {@link Device} and {@link Client} objects. + * labels and images for {@link IDevice} and {@link Client} objects. */ private class LabelProvider implements ITableLabelProvider { public Image getColumnImage(Object element, int columnIndex) { - if (columnIndex == DEVICE_COL_SERIAL && element instanceof Device) { - Device device = (Device)element; + if (columnIndex == DEVICE_COL_SERIAL && element instanceof IDevice) { + IDevice device = (IDevice)element; if (device.isEmulator()) { return mEmulatorImage; } @@ -192,17 +192,17 @@ public final class DevicePanel extends Panel implements IDebugBridgeChangeListen } public String getColumnText(Object element, int columnIndex) { - if (element instanceof Device) { - Device device = (Device)element; + if (element instanceof IDevice) { + IDevice device = (IDevice)element; switch (columnIndex) { case DEVICE_COL_SERIAL: return device.getSerialNumber(); case DEVICE_COL_STATE: return getStateString(device); case DEVICE_COL_BUILD: { - String version = device.getProperty(Device.PROP_BUILD_VERSION); + String version = device.getProperty(IDevice.PROP_BUILD_VERSION); if (version != null) { - String debuggable = device.getProperty(Device.PROP_DEBUGGABLE); + String debuggable = device.getProperty(IDevice.PROP_DEBUGGABLE); if (device.isEmulator()) { String avdName = device.getAvdName(); if (avdName == null) { @@ -279,15 +279,15 @@ public final class DevicePanel extends Panel implements IDebugBridgeChangeListen /** * Classes which implement this interface provide methods that deals - * with {@link Device} and {@link Client} selection changes coming from the ui. + * with {@link IDevice} and {@link Client} selection changes coming from the ui. */ public interface IUiSelectionListener { /** - * Sent when a new {@link Device} and {@link Client} are selected. + * Sent when a new {@link IDevice} and {@link Client} are selected. * @param selectedDevice the selected device. If null, no devices are selected. * @param selectedClient The selected client. If null, no clients are selected. */ - public void selectionChanged(Device selectedDevice, Client selectedClient); + public void selectionChanged(IDevice selectedDevice, Client selectedClient); } /** @@ -359,7 +359,7 @@ public final class DevicePanel extends Panel implements IDebugBridgeChangeListen return mTree; } - + /** * Sets the focus to the proper control inside the panel. */ @@ -371,7 +371,7 @@ public final class DevicePanel extends Panel implements IDebugBridgeChangeListen @Override protected void postCreation() { // ask for notification of changes in AndroidDebugBridge (a new one is created when - // adb is restarted from a different location), Device and Client objects. + // adb is restarted from a different location), IDevice and Client objects. AndroidDebugBridge.addDebugBridgeChangeListener(this); AndroidDebugBridge.addDeviceChangeListener(this); AndroidDebugBridge.addClientChangeListener(this); @@ -391,10 +391,10 @@ public final class DevicePanel extends Panel implements IDebugBridgeChangeListen } /** - * Returns the selected {@link Device}. If a {@link Client} is selected, it returns the - * Device object containing the client. + * Returns the selected {@link IDevice}. If a {@link Client} is selected, it returns the + * IDevice object containing the client. */ - public Device getSelectedDevice() { + public IDevice getSelectedDevice() { return mCurrentDevice; } @@ -404,7 +404,7 @@ public final class DevicePanel extends Panel implements IDebugBridgeChangeListen public void killSelectedClient() { if (mCurrentClient != null) { Client client = mCurrentClient; - + // reset the selection to the device. TreePath treePath = new TreePath(new Object[] { mCurrentDevice }); TreeSelection treeSelection = new TreeSelection(treePath); @@ -413,7 +413,7 @@ public final class DevicePanel extends Panel implements IDebugBridgeChangeListen client.kill(); } } - + /** * Forces a GC on the selected {@link Client}. */ @@ -422,13 +422,13 @@ public final class DevicePanel extends Panel implements IDebugBridgeChangeListen mCurrentClient.executeGarbageCollector(); } } - + public void setEnabledHeapOnSelectedClient(boolean enable) { if (mCurrentClient != null) { mCurrentClient.setHeapUpdateEnabled(enable); } } - + public void setEnabledThreadOnSelectedClient(boolean enable) { if (mCurrentClient != null) { mCurrentClient.setThreadUpdateEnabled(enable); @@ -476,9 +476,9 @@ public final class DevicePanel extends Panel implements IDebugBridgeChangeListen * This is sent from a non UI thread. * @param device the new device. * - * @see IDeviceChangeListener#deviceConnected(Device) + * @see IDeviceChangeListener#deviceConnected(IDevice) */ - public void deviceConnected(Device device) { + public void deviceConnected(IDevice device) { exec(new Runnable() { public void run() { if (mTree.isDisposed() == false) { @@ -511,11 +511,11 @@ public final class DevicePanel extends Panel implements IDebugBridgeChangeListen * This is sent from a non UI thread. * @param device the new device. * - * @see IDeviceChangeListener#deviceDisconnected(Device) + * @see IDeviceChangeListener#deviceDisconnected(IDevice) */ - public void deviceDisconnected(Device device) { + public void deviceDisconnected(IDevice device) { deviceConnected(device); - + // just in case, we remove it from the list of devices to expand. synchronized (mDevicesToExpand) { mDevicesToExpand.remove(device); @@ -529,9 +529,9 @@ public final class DevicePanel extends Panel implements IDebugBridgeChangeListen * @param device the device that was updated. * @param changeMask the mask indicating what changed. * - * @see IDeviceChangeListener#deviceChanged(Device) + * @see IDeviceChangeListener#deviceChanged(IDevice) */ - public void deviceChanged(final Device device, int changeMask) { + public void deviceChanged(final IDevice device, int changeMask) { boolean expand = false; synchronized (mDevicesToExpand) { int index = mDevicesToExpand.indexOf(device); @@ -540,7 +540,7 @@ public final class DevicePanel extends Panel implements IDebugBridgeChangeListen expand = true; } } - + final boolean finalExpand = expand; exec(new Runnable() { @@ -549,22 +549,22 @@ public final class DevicePanel extends Panel implements IDebugBridgeChangeListen // look if the current device is selected. This is done in case the current // client of this particular device was killed. In this case, we'll need to // manually reselect the device. - - Device selectedDevice = getSelectedDevice(); + + IDevice selectedDevice = getSelectedDevice(); // refresh the device mTreeViewer.refresh(device); - + // if the selected device was the changed device and the new selection is // empty, we reselect the device. if (selectedDevice == device && mTreeViewer.getSelection().isEmpty()) { mTreeViewer.setSelection(new TreeSelection(new TreePath( new Object[] { device }))); } - + // notify the listener of a possible selection change. notifyListeners(); - + if (finalExpand) { mTreeViewer.setExpandedState(device, true); } @@ -606,7 +606,7 @@ public final class DevicePanel extends Panel implements IDebugBridgeChangeListen // make sure the device is expanded. Normally the setSelection below // will auto expand, but the children of device may not already exist // at this time. Forcing an expand will make the TreeViewer create them. - Device device = client.getDevice(); + IDevice device = client.getDevice(); if (mTreeViewer.getExpandedState(device) == false) { mTreeViewer.setExpandedState(device, true); } @@ -615,11 +615,11 @@ public final class DevicePanel extends Panel implements IDebugBridgeChangeListen TreePath treePath = new TreePath(new Object[] { device, client}); TreeSelection treeSelection = new TreeSelection(treePath); mTreeViewer.setSelection(treeSelection); - + if (mAdvancedPortSupport) { client.setAsSelectedClient(); } - + // notify the listener of a possible selection change. notifyListeners(device, client); } @@ -676,7 +676,7 @@ public final class DevicePanel extends Panel implements IDebugBridgeChangeListen * Returns a display string representing the state of the device. * @param d the device */ - private static String getStateString(Device d) { + private static String getStateString(IDevice d) { DeviceState deviceState = d.getState(); if (deviceState == DeviceState.ONLINE) { return "Online"; @@ -704,32 +704,32 @@ public final class DevicePanel extends Panel implements IDebugBridgeChangeListen AndroidDebugBridge.removeClientChangeListener(this); } } - + private void notifyListeners() { // get the selection TreeItem[] items = mTree.getSelection(); Client client = null; - Device device = null; + IDevice device = null; if (items.length == 1) { Object object = items[0].getData(); if (object instanceof Client) { client = (Client)object; device = client.getDevice(); - } else if (object instanceof Device) { - device = (Device)object; + } else if (object instanceof IDevice) { + device = (IDevice)object; } } notifyListeners(device, client); } - - private void notifyListeners(Device selectedDevice, Client selectedClient) { + + private void notifyListeners(IDevice selectedDevice, Client selectedClient) { if (selectedDevice != mCurrentDevice || selectedClient != mCurrentClient) { mCurrentDevice = selectedDevice; mCurrentClient = selectedClient; - + for (IUiSelectionListener listener : mListeners) { // notify the listener with a try/catch-all to make sure this thread won't die // because of an uncaught exception before all the listeners were notified. @@ -740,5 +740,5 @@ public final class DevicePanel extends Panel implements IDebugBridgeChangeListen } } } - + } diff --git a/ddms/libs/ddmuilib/src/com/android/ddmuilib/EmulatorControlPanel.java b/ddms/libs/ddmuilib/src/com/android/ddmuilib/EmulatorControlPanel.java index 5583760..4410d3a 100644 --- a/ddms/libs/ddmuilib/src/com/android/ddmuilib/EmulatorControlPanel.java +++ b/ddms/libs/ddmuilib/src/com/android/ddmuilib/EmulatorControlPanel.java @@ -16,7 +16,7 @@ package com.android.ddmuilib; -import com.android.ddmlib.Device; +import com.android.ddmlib.IDevice; import com.android.ddmlib.EmulatorConsole; import com.android.ddmlib.EmulatorConsole.GsmMode; import com.android.ddmlib.EmulatorConsole.GsmStatus; @@ -75,7 +75,7 @@ public class EmulatorControlPanel extends SelectionDependentPanel { // default location: Patio outside Charlie's private final static double DEFAULT_LONGITUDE = -122.084095; private final static double DEFAULT_LATITUDE = 37.422006; - + private final static String SPEED_FORMAT = "Speed: %1$dX"; @@ -106,7 +106,7 @@ public class EmulatorControlPanel extends SelectionDependentPanel { "EDGE", "UMTS", }; - + private final static int[] PLAY_SPEEDS = new int[] { 1, 2, 5, 10, 20, 50 }; private final static String RE_PHONE_NUMBER = "^[+#0-9]+$"; //$NON-NLS-1$ @@ -149,7 +149,7 @@ public class EmulatorControlPanel extends SelectionDependentPanel { private Button mCancelButton; private TabFolder mLocationFolders; - + private Button mDecimalButton; private Button mSexagesimalButton; private CoordinateControls mLongitudeControls; @@ -177,7 +177,7 @@ public class EmulatorControlPanel extends SelectionDependentPanel { private int mPlayDirection = 1; private int mSpeed; private int mSpeedIndex; - + private final SelectionAdapter mDirectionButtonAdapter = new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { @@ -188,7 +188,7 @@ public class EmulatorControlPanel extends SelectionDependentPanel { b.setSelection(true); return; } - + // now handle selection change. if (b == mGpxForwardButton || b == mKmlForwardButton) { mGpxBackwardButton.setSelection(false); @@ -196,7 +196,7 @@ public class EmulatorControlPanel extends SelectionDependentPanel { mKmlBackwardButton.setSelection(false); mKmlForwardButton.setSelection(true); mPlayDirection = 1; - + } else { mGpxBackwardButton.setSelection(true); mGpxForwardButton.setSelection(false); @@ -206,27 +206,27 @@ public class EmulatorControlPanel extends SelectionDependentPanel { } } }; - + private final SelectionAdapter mSpeedButtonAdapter = new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { mSpeedIndex = (mSpeedIndex+1) % PLAY_SPEEDS.length; mSpeed = PLAY_SPEEDS[mSpeedIndex]; - + mGpxSpeedButton.setText(String.format(SPEED_FORMAT, mSpeed)); mGpxPlayControls.pack(); mKmlSpeedButton.setText(String.format(SPEED_FORMAT, mSpeed)); mKmlPlayControls.pack(); - + if (mPlayingThread != null) { mPlayingThread.interrupt(); } - } + } }; private Composite mKmlPlayControls; private Composite mGpxPlayControls; - + public EmulatorControlPanel(IImageLoader imageLoader) { mImageLoader = imageLoader; } @@ -274,11 +274,11 @@ public class EmulatorControlPanel extends SelectionDependentPanel { scollingParent.setMinSize(top.computeSize(r.width, SWT.DEFAULT)); } }); - + createRadioControls(top); createCallControls(top); - + createLocationControls(top); doEnable(false); @@ -379,7 +379,7 @@ public class EmulatorControlPanel extends SelectionDependentPanel { Label l = new Label(g1, SWT.NONE); l.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); } - + /** * Create Voice/SMS call/hang up controls * @param top @@ -517,7 +517,7 @@ public class EmulatorControlPanel extends SelectionDependentPanel { } }); } - + /** * Create Location controls. * @param top @@ -526,15 +526,15 @@ public class EmulatorControlPanel extends SelectionDependentPanel { Label l = new Label(top, SWT.NONE); l.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); l.setText("Location Controls"); - + mLocationFolders = new TabFolder(top, SWT.NONE); mLocationFolders.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - + Composite manualLocationComp = new Composite(mLocationFolders, SWT.NONE); TabItem item = new TabItem(mLocationFolders, SWT.NONE); item.setText("Manual"); item.setControl(manualLocationComp); - + createManualLocationControl(manualLocationComp); mPlayImage = mImageLoader.loadImage("play.png", mParent.getDisplay()); // $NON-NLS-1$ @@ -544,7 +544,7 @@ public class EmulatorControlPanel extends SelectionDependentPanel { item = new TabItem(mLocationFolders, SWT.NONE); item.setText("GPX"); item.setControl(gpxLocationComp); - + createGpxLocationControl(gpxLocationComp); Composite kmlLocationComp = new Composite(mLocationFolders, SWT.NONE); @@ -552,7 +552,7 @@ public class EmulatorControlPanel extends SelectionDependentPanel { item = new TabItem(mLocationFolders, SWT.NONE); item.setText("KML"); item.setControl(kmlLocationComp); - + createKmlLocationControl(kmlLocationComp); } @@ -572,63 +572,63 @@ public class EmulatorControlPanel extends SelectionDependentPanel { // composite to hold and switching between the 2 modes. final Composite content = new Composite(manualLocationComp, SWT.NONE); content.setLayout(sl = new StackLayout()); - + // decimal display final Composite decimalContent = new Composite(content, SWT.NONE); decimalContent.setLayout(gl = new GridLayout(2, false)); gl.marginHeight = gl.marginWidth = 0; - + mLongitudeControls = new CoordinateControls(); mLatitudeControls = new CoordinateControls(); - + label = new Label(decimalContent, SWT.NONE); label.setText("Longitude"); - + mLongitudeControls.createDecimalText(decimalContent); - + label = new Label(decimalContent, SWT.NONE); label.setText("Latitude"); - + mLatitudeControls.createDecimalText(decimalContent); // sexagesimal content final Composite sexagesimalContent = new Composite(content, SWT.NONE); sexagesimalContent.setLayout(gl = new GridLayout(7, false)); gl.marginHeight = gl.marginWidth = 0; - + label = new Label(sexagesimalContent, SWT.NONE); label.setText("Longitude"); - + mLongitudeControls.createSexagesimalDegreeText(sexagesimalContent); - + label = new Label(sexagesimalContent, SWT.NONE); label.setText("\u00B0"); // degree character - + mLongitudeControls.createSexagesimalMinuteText(sexagesimalContent); - + label = new Label(sexagesimalContent, SWT.NONE); label.setText("'"); mLongitudeControls.createSexagesimalSecondText(sexagesimalContent); - + label = new Label(sexagesimalContent, SWT.NONE); label.setText("\""); label = new Label(sexagesimalContent, SWT.NONE); label.setText("Latitude"); - + mLatitudeControls.createSexagesimalDegreeText(sexagesimalContent); - + label = new Label(sexagesimalContent, SWT.NONE); label.setText("\u00B0"); - + mLatitudeControls.createSexagesimalMinuteText(sexagesimalContent); - + label = new Label(sexagesimalContent, SWT.NONE); label.setText("'"); mLatitudeControls.createSexagesimalSecondText(sexagesimalContent); - + label = new Label(sexagesimalContent, SWT.NONE); label.setText("\""); @@ -647,7 +647,7 @@ public class EmulatorControlPanel extends SelectionDependentPanel { content.layout(); } }); - + Button sendButton = new Button(manualLocationComp, SWT.PUSH); sendButton.setText("Send"); sendButton.addSelectionListener(new SelectionAdapter() { @@ -659,7 +659,7 @@ public class EmulatorControlPanel extends SelectionDependentPanel { } } }); - + mLongitudeControls.setValue(DEFAULT_LONGITUDE); mLatitudeControls.setValue(DEFAULT_LATITUDE); } @@ -681,7 +681,7 @@ public class EmulatorControlPanel extends SelectionDependentPanel { gd.heightHint = 100; mGpxWayPointTable.setHeaderVisible(true); mGpxWayPointTable.setLinesVisible(true); - + TableHelper.createTableColumn(mGpxWayPointTable, "Name", SWT.LEFT, "Some Name", PREFS_WAYPOINT_COL_NAME, store); @@ -701,7 +701,7 @@ public class EmulatorControlPanel extends SelectionDependentPanel { final TableViewer gpxWayPointViewer = new TableViewer(mGpxWayPointTable); gpxWayPointViewer.setContentProvider(new WayPointContentProvider()); gpxWayPointViewer.setLabelProvider(new WayPointLabelProvider()); - + gpxWayPointViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { ISelection selection = event.getSelection(); @@ -710,7 +710,7 @@ public class EmulatorControlPanel extends SelectionDependentPanel { Object selectedObject = structuredSelection.getFirstElement(); if (selectedObject instanceof WayPoint) { WayPoint wayPoint = (WayPoint)selectedObject; - + if (mEmulatorConsole != null && mPlayingTrack == false) { processCommandResult(mEmulatorConsole.sendLocation( wayPoint.getLongitude(), wayPoint.getLatitude(), @@ -748,7 +748,7 @@ public class EmulatorControlPanel extends SelectionDependentPanel { final TableViewer gpxTrackViewer = new TableViewer(mGpxTrackTable); gpxTrackViewer.setContentProvider(new TrackContentProvider()); gpxTrackViewer.setLabelProvider(new TrackLabelProvider()); - + gpxTrackViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { ISelection selection = event.getSelection(); @@ -757,19 +757,19 @@ public class EmulatorControlPanel extends SelectionDependentPanel { Object selectedObject = structuredSelection.getFirstElement(); if (selectedObject instanceof Track) { Track track = (Track)selectedObject; - + if (mEmulatorConsole != null && mPlayingTrack == false) { TrackPoint[] points = track.getPoints(); processCommandResult(mEmulatorConsole.sendLocation( points[0].getLongitude(), points[0].getLatitude(), points[0].getElevation())); } - + mPlayGpxButton.setEnabled(true); mGpxBackwardButton.setEnabled(true); mGpxForwardButton.setEnabled(true); mGpxSpeedButton.setEnabled(true); - + return; } } @@ -780,7 +780,7 @@ public class EmulatorControlPanel extends SelectionDependentPanel { mGpxSpeedButton.setEnabled(false); } }); - + mGpxUploadButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { @@ -799,7 +799,7 @@ public class EmulatorControlPanel extends SelectionDependentPanel { } } }); - + mGpxPlayControls = new Composite(gpxLocationComp, SWT.NONE); GridLayout gl; mGpxPlayControls.setLayout(gl = new GridLayout(5, false)); @@ -828,14 +828,14 @@ public class EmulatorControlPanel extends SelectionDependentPanel { mPlayingThread.interrupt(); } } - } + } }); - + Label separator = new Label(mGpxPlayControls, SWT.SEPARATOR | SWT.VERTICAL); separator.setLayoutData(gd = new GridData( GridData.VERTICAL_ALIGN_FILL | GridData.GRAB_VERTICAL)); gd.heightHint = 0; - + mGpxBackwardButton = new Button(mGpxPlayControls, SWT.TOGGLE | SWT.FLAT); mGpxBackwardButton.setImage(mImageLoader.loadImage("backward.png", mParent.getDisplay())); // $NON-NLS-1$ mGpxBackwardButton.setSelection(false); @@ -852,7 +852,7 @@ public class EmulatorControlPanel extends SelectionDependentPanel { mGpxSpeedButton.setText(String.format(SPEED_FORMAT, mSpeed)); mGpxSpeedButton.addSelectionListener(mSpeedButtonAdapter); - + mPlayGpxButton.setEnabled(false); mGpxBackwardButton.setEnabled(false); mGpxForwardButton.setEnabled(false); @@ -877,7 +877,7 @@ public class EmulatorControlPanel extends SelectionDependentPanel { gd.heightHint = 200; mKmlWayPointTable.setHeaderVisible(true); mKmlWayPointTable.setLinesVisible(true); - + TableHelper.createTableColumn(mKmlWayPointTable, "Name", SWT.LEFT, "Some Name", PREFS_WAYPOINT_COL_NAME, store); @@ -911,7 +911,7 @@ public class EmulatorControlPanel extends SelectionDependentPanel { KmlParser parser = new KmlParser(fileName); if (parser.parse()) { kmlWayPointViewer.setInput(parser.getWayPoints()); - + mPlayKmlButton.setEnabled(true); mKmlBackwardButton.setEnabled(true); mKmlForwardButton.setEnabled(true); @@ -920,7 +920,7 @@ public class EmulatorControlPanel extends SelectionDependentPanel { } } }); - + kmlWayPointViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { ISelection selection = event.getSelection(); @@ -929,7 +929,7 @@ public class EmulatorControlPanel extends SelectionDependentPanel { Object selectedObject = structuredSelection.getFirstElement(); if (selectedObject instanceof WayPoint) { WayPoint wayPoint = (WayPoint)selectedObject; - + if (mEmulatorConsole != null && mPlayingTrack == false) { processCommandResult(mEmulatorConsole.sendLocation( wayPoint.getLongitude(), wayPoint.getLatitude(), @@ -939,9 +939,9 @@ public class EmulatorControlPanel extends SelectionDependentPanel { } } }); - - - + + + mKmlPlayControls = new Composite(kmlLocationComp, SWT.NONE); GridLayout gl; mKmlPlayControls.setLayout(gl = new GridLayout(5, false)); @@ -965,14 +965,14 @@ public class EmulatorControlPanel extends SelectionDependentPanel { mPlayingThread.interrupt(); } } - } + } }); - + Label separator = new Label(mKmlPlayControls, SWT.SEPARATOR | SWT.VERTICAL); separator.setLayoutData(gd = new GridData( GridData.VERTICAL_ALIGN_FILL | GridData.GRAB_VERTICAL)); gd.heightHint = 0; - + mKmlBackwardButton = new Button(mKmlPlayControls, SWT.TOGGLE | SWT.FLAT); mKmlBackwardButton.setImage(mImageLoader.loadImage("backward.png", mParent.getDisplay())); // $NON-NLS-1$ mKmlBackwardButton.setSelection(false); @@ -989,7 +989,7 @@ public class EmulatorControlPanel extends SelectionDependentPanel { mKmlSpeedButton.setText(String.format(SPEED_FORMAT, mSpeed)); mKmlSpeedButton.addSelectionListener(mSpeedButtonAdapter); - + mPlayKmlButton.setEnabled(false); mKmlBackwardButton.setEnabled(false); mKmlForwardButton.setEnabled(false); @@ -1039,7 +1039,7 @@ public class EmulatorControlPanel extends SelectionDependentPanel { * Callback on device selection change. * @param device the new selected device */ - public void handleNewDevice(Device device) { + public void handleNewDevice(IDevice device) { if (mParent.isDisposed()) { return; } @@ -1061,7 +1061,7 @@ public class EmulatorControlPanel extends SelectionDependentPanel { // get the gsm status gsm = mEmulatorConsole.getGsmStatus(); netstatus = mEmulatorConsole.getNetworkStatus(); - + if (gsm == null || netstatus == null) { mEmulatorConsole = null; } @@ -1073,7 +1073,7 @@ public class EmulatorControlPanel extends SelectionDependentPanel { if (d.isDisposed() == false) { final GsmStatus f_gsm = gsm; final NetworkStatus f_netstatus = netstatus; - + d.asyncExec(new Runnable() { public void run() { if (f_gsm.voice != GsmMode.UNKNOWN) { @@ -1109,7 +1109,7 @@ public class EmulatorControlPanel extends SelectionDependentPanel { synchronized (this) { enable = mEmulatorConsole != null; } - + enable(enable); } } @@ -1240,10 +1240,10 @@ public class EmulatorControlPanel extends SelectionDependentPanel { } catch (SWTException e) { // we're quitting, just ignore } - + return false; } - + return true; } @@ -1264,13 +1264,13 @@ public class EmulatorControlPanel extends SelectionDependentPanel { try { TrackPoint[] trackPoints = track.getPoints(); int count = trackPoints.length; - + // get the start index. int start = 0; if (mPlayDirection == -1) { start = count - 1; } - + for (int p = start; p >= 0 && p < count; p += mPlayDirection) { if (mPlayingTrack == false) { return; @@ -1299,7 +1299,7 @@ public class EmulatorControlPanel extends SelectionDependentPanel { if (delta < 0) { delta = -delta; } - + long startTime = System.currentTimeMillis(); try { @@ -1308,7 +1308,7 @@ public class EmulatorControlPanel extends SelectionDependentPanel { if (mPlayingTrack == false) { return; } - + // we got interrupted, lets make sure we can play do { long waited = System.currentTimeMillis() - startTime; @@ -1351,7 +1351,7 @@ public class EmulatorControlPanel extends SelectionDependentPanel { mPlayingThread.start(); } } - + private void playKml(final WayPoint[] trackPoints) { // no need to synchronize this check, the worst that can happen, is we start the thread // for nothing. @@ -1365,13 +1365,13 @@ public class EmulatorControlPanel extends SelectionDependentPanel { public void run() { try { int count = trackPoints.length; - + // get the start index. int start = 0; if (mPlayDirection == -1) { start = count - 1; } - + for (int p = start; p >= 0 && p < count; p += mPlayDirection) { if (mPlayingTrack == false) { return; @@ -1399,7 +1399,7 @@ public class EmulatorControlPanel extends SelectionDependentPanel { if (delta < 0) { delta = -delta; } - + long startTime = System.currentTimeMillis(); try { @@ -1408,7 +1408,7 @@ public class EmulatorControlPanel extends SelectionDependentPanel { if (mPlayingTrack == false) { return; } - + // we got interrupted, lets make sure we can play do { long waited = System.currentTimeMillis() - startTime; @@ -1449,6 +1449,6 @@ public class EmulatorControlPanel extends SelectionDependentPanel { }; mPlayingThread.start(); - } + } } } diff --git a/ddms/libs/ddmuilib/src/com/android/ddmuilib/ScreenShotDialog.java b/ddms/libs/ddmuilib/src/com/android/ddmuilib/ScreenShotDialog.java index dad54dc..b9bb10c 100644 --- a/ddms/libs/ddmuilib/src/com/android/ddmuilib/ScreenShotDialog.java +++ b/ddms/libs/ddmuilib/src/com/android/ddmuilib/ScreenShotDialog.java @@ -16,7 +16,7 @@ package com.android.ddmuilib; -import com.android.ddmlib.Device; +import com.android.ddmlib.IDevice; import com.android.ddmlib.Log; import com.android.ddmlib.RawImage; @@ -47,7 +47,7 @@ public class ScreenShotDialog extends Dialog { private Label mBusyLabel; private Label mImageLabel; private Button mSave; - private Device mDevice; + private IDevice mDevice; /** @@ -66,9 +66,9 @@ public class ScreenShotDialog extends Dialog { /** * Prepare and display the dialog. - * @param device The {@link Device} from which to get the screenshot. + * @param device The {@link IDevice} from which to get the screenshot. */ - public void open(Device device) { + public void open(IDevice device) { mDevice = device; Shell parent = getParent(); diff --git a/ddms/libs/ddmuilib/src/com/android/ddmuilib/SelectionDependentPanel.java b/ddms/libs/ddmuilib/src/com/android/ddmuilib/SelectionDependentPanel.java index 4b5fe56..e6d2211 100644 --- a/ddms/libs/ddmuilib/src/com/android/ddmuilib/SelectionDependentPanel.java +++ b/ddms/libs/ddmuilib/src/com/android/ddmuilib/SelectionDependentPanel.java @@ -17,20 +17,20 @@ package com.android.ddmuilib; import com.android.ddmlib.Client; -import com.android.ddmlib.Device; +import com.android.ddmlib.IDevice; /** * A Panel that requires {@link Device}/{@link Client} selection notifications. */ public abstract class SelectionDependentPanel extends Panel { - private Device mCurrentDevice = null; + private IDevice mCurrentDevice = null; private Client mCurrentClient = null; /** * Returns the current {@link Device}. * @return the current device or null if none are selected. */ - protected final Device getCurrentDevice() { + protected final IDevice getCurrentDevice() { return mCurrentDevice; } @@ -46,7 +46,7 @@ public abstract class SelectionDependentPanel extends Panel { * Sent when a new device is selected. * @param selectedDevice the selected device. */ - public final void deviceSelected(Device selectedDevice) { + public final void deviceSelected(IDevice selectedDevice) { if (selectedDevice != mCurrentDevice) { mCurrentDevice = selectedDevice; deviceSelected(); diff --git a/ddms/libs/ddmuilib/src/com/android/ddmuilib/explorer/DeviceExplorer.java b/ddms/libs/ddmuilib/src/com/android/ddmuilib/explorer/DeviceExplorer.java index 34f575f..4652b31 100644 --- a/ddms/libs/ddmuilib/src/com/android/ddmuilib/explorer/DeviceExplorer.java +++ b/ddms/libs/ddmuilib/src/com/android/ddmuilib/explorer/DeviceExplorer.java @@ -16,7 +16,7 @@ package com.android.ddmuilib.explorer; -import com.android.ddmlib.Device; +import com.android.ddmlib.IDevice; import com.android.ddmlib.FileListingService; import com.android.ddmlib.IShellOutputReceiver; import com.android.ddmlib.SyncService; @@ -99,7 +99,7 @@ public class DeviceExplorer extends Panel { private Image mPackageImage; private Image mOtherImage; - private Device mCurrentDevice; + private IDevice mCurrentDevice; private String mDefaultSave; @@ -631,7 +631,7 @@ public class DeviceExplorer extends Panel { /** * Sets the new device to explorer */ - public void switchDevice(final Device device) { + public void switchDevice(final IDevice device) { if (device != mCurrentDevice) { mCurrentDevice = device; // now we change the input. but we need to do that in the diff --git a/ddms/libs/ddmuilib/src/com/android/ddmuilib/log/event/EventLogPanel.java b/ddms/libs/ddmuilib/src/com/android/ddmuilib/log/event/EventLogPanel.java index 2621c6a..11138d1 100644 --- a/ddms/libs/ddmuilib/src/com/android/ddmuilib/log/event/EventLogPanel.java +++ b/ddms/libs/ddmuilib/src/com/android/ddmuilib/log/event/EventLogPanel.java @@ -17,7 +17,7 @@ package com.android.ddmuilib.log.event; import com.android.ddmlib.Client; -import com.android.ddmlib.Device; +import com.android.ddmlib.IDevice; import com.android.ddmlib.Log; import com.android.ddmlib.Log.LogLevel; import com.android.ddmlib.log.EventContainer; @@ -80,7 +80,7 @@ public class EventLogPanel extends TablePanel implements ILogListener, private IImageLoader mImageLoader; - private Device mCurrentLoggedDevice; + private IDevice mCurrentLoggedDevice; private String mCurrentLogFile; private LogReceiver mCurrentLogReceiver; private EventLogParser mCurrentEventLogParser; @@ -94,7 +94,7 @@ public class EventLogPanel extends TablePanel implements ILogListener, private final ArrayList<EventContainer> mNewEvents = new ArrayList<EventContainer>(); /** indicates a pending ui thread display */ private boolean mPendingDisplay = false; - + /** list of all the custom event displays */ private final ArrayList<EventDisplay> mEventDisplays = new ArrayList<EventDisplay>(); @@ -107,7 +107,7 @@ public class EventLogPanel extends TablePanel implements ILogListener, private ICommonAction mSaveAction; private ICommonAction mLoadAction; private ICommonAction mImportAction; - + /** file containing the current log raw data. */ private File mTempFile = null; @@ -209,10 +209,10 @@ public class EventLogPanel extends TablePanel implements ILogListener, // get the new EventDisplay list mEventDisplays.clear(); mEventDisplays.addAll(dialog.getEventDisplays()); - + // since the list of EventDisplay changed, we store it. saveEventDisplays(); - + rebuildUi(); } } @@ -220,7 +220,7 @@ public class EventLogPanel extends TablePanel implements ILogListener, Log.e("EventLog", e); //$NON-NLS-1$ } } - + /** * Clears the log. * <p/> @@ -240,7 +240,7 @@ public class EventLogPanel extends TablePanel implements ILogListener, Log.e("EventLog", e); //$NON-NLS-1$ } } - + /** * Saves the content of the event log into a file. The log is saved in the same * binary format than on the device. @@ -254,16 +254,16 @@ public class EventLogPanel extends TablePanel implements ILogListener, FileInputStream fis = new FileInputStream(mTempFile); FileOutputStream fos = new FileOutputStream(destFile); byte[] buffer = new byte[1024]; - + int count; - + while ((count = fis.read(buffer)) != -1) { fos.write(buffer, 0, count); } - + fos.close(); fis.close(); - + // now we save the tag file filePath = filePath + TAG_FILE_EXT; mCurrentEventLogParser.saveTags(filePath); @@ -293,16 +293,16 @@ public class EventLogPanel extends TablePanel implements ILogListener, } } - + public void importBugReport(String filePath) { try { BugReportImporter importer = new BugReportImporter(filePath); - + String[] tags = importer.getTags(); String[] log = importer.getLog(); - + startEventLogFromContent(tags, log); - + } catch (FileNotFoundException e) { Log.logAndDisplay(LogLevel.ERROR, "Import", "Unable to import bug report: " + e.getMessage()); @@ -324,7 +324,7 @@ public class EventLogPanel extends TablePanel implements ILogListener, public void deviceSelected() { startEventLog(getCurrentDevice()); } - + /* * (non-Javadoc) * @see com.android.ddmlib.AndroidDebugBridge.IClientChangeListener#clientChanged(com.android.ddmlib.Client, int) @@ -359,7 +359,7 @@ public class EventLogPanel extends TablePanel implements ILogListener, // init some store stuff store.setDefault(PREFS_DISPLAY_WIDTH, DEFAULT_DISPLAY_WIDTH); store.setDefault(PREFS_DISPLAY_HEIGHT, DEFAULT_DISPLAY_HEIGHT); - + mBottomParentPanel = new ScrolledComposite(parent, SWT.V_SCROLL); mBottomParentPanel.setLayoutData(new GridData(GridData.FILL_BOTH)); mBottomParentPanel.setExpandHorizontal(true); @@ -383,7 +383,7 @@ public class EventLogPanel extends TablePanel implements ILogListener, // create the ui createDisplayUi(); - + return mBottomParentPanel; } @@ -402,12 +402,12 @@ public class EventLogPanel extends TablePanel implements ILogListener, public void setFocus() { mBottomParentPanel.setFocus(); } - + /** * Starts a new logcat and set mCurrentLogCat as the current receiver. * @param device the device to connect logcat to. */ - private void startEventLog(final Device device) { + private void startEventLog(final IDevice device) { if (device == mCurrentLoggedDevice) { return; } @@ -448,10 +448,10 @@ public class EventLogPanel extends TablePanel implements ILogListener, mCurrentEventLogParser = new EventLogParser(); mCurrentEventLogParser.init(device); } - + // update the event display with the new parser. updateEventDisplays(); - + // prepare the temp file that will contain the raw data mTempFile = File.createTempFile("android-event-", ".log"); @@ -464,7 +464,7 @@ public class EventLogPanel extends TablePanel implements ILogListener, }.start(); } } - + private void startEventLogFromFiles(final String fileName) { // if we have a logcat already running if (mCurrentLogReceiver != null) { @@ -475,7 +475,7 @@ public class EventLogPanel extends TablePanel implements ILogListener, // create a new output receiver mCurrentLogReceiver = new LogReceiver(this); - + mSaveAction.setEnabled(false); // start the logcat in a different thread @@ -493,10 +493,10 @@ public class EventLogPanel extends TablePanel implements ILogListener, return; } } - + // update the event display with the new parser. updateEventDisplays(); - + runLocalEventLogService(fileName, mCurrentLogReceiver); } catch (Exception e) { Log.e("EventLog", e); @@ -516,7 +516,7 @@ public class EventLogPanel extends TablePanel implements ILogListener, // create a new output receiver mCurrentLogReceiver = new LogReceiver(this); - + mSaveAction.setEnabled(false); // start the logcat in a different thread @@ -531,10 +531,10 @@ public class EventLogPanel extends TablePanel implements ILogListener, return; } } - + // update the event display with the new parser. updateEventDisplays(); - + runLocalEventLogService(log, mCurrentLogReceiver); } catch (Exception e) { Log.e("EventLog", e); @@ -563,7 +563,7 @@ public class EventLogPanel extends TablePanel implements ILogListener, resetUI(inUiThread); } - + if (mTempFile != null) { mTempFile.delete(); mTempFile = null; @@ -593,7 +593,7 @@ public class EventLogPanel extends TablePanel implements ILogListener, } } } - + private void resetUiFromUiThread() { synchronized(mLock) { for (EventDisplay eventDisplay : mEventDisplays) { @@ -618,11 +618,11 @@ public class EventLogPanel extends TablePanel implements ILogListener, rowLayout.fill = true; rowLayout.type = SWT.HORIZONTAL; mBottomPanel.setLayout(rowLayout); - + IPreferenceStore store = DdmUiPreferences.getStore(); int displayWidth = store.getInt(PREFS_DISPLAY_WIDTH); int displayHeight = store.getInt(PREFS_DISPLAY_HEIGHT); - + for (EventDisplay eventDisplay : mEventDisplays) { Control c = eventDisplay.createComposite(mBottomPanel, mCurrentEventLogParser, this); if (c != null) { @@ -631,7 +631,7 @@ public class EventLogPanel extends TablePanel implements ILogListener, rd.width = displayWidth; c.setLayoutData(rd); } - + Table table = eventDisplay.getTable(); if (table != null) { addTableToFocusListener(table); @@ -642,7 +642,7 @@ public class EventLogPanel extends TablePanel implements ILogListener, mBottomParentPanel.setMinSize(mBottomPanel.computeSize(SWT.DEFAULT, SWT.DEFAULT)); mBottomParentPanel.layout(); } - + /** * Rebuild the display ui. */ @@ -652,26 +652,26 @@ public class EventLogPanel extends TablePanel implements ILogListener, // we need to rebuild the ui. First we get rid of it. mBottomPanel.dispose(); mBottomPanel = null; - + prepareDisplayUi(); createDisplayUi(); - + // and fill it - + boolean start_event = false; synchronized (mNewEvents) { mNewEvents.addAll(0, mEvents); - + if (mPendingDisplay == false) { mPendingDisplay = true; start_event = true; } } - + if (start_event) { scheduleUIEventHandler(); } - + Rectangle r = mBottomParentPanel.getClientArea(); mBottomParentPanel.setMinSize(mBottomPanel.computeSize(r.width, SWT.DEFAULT)); @@ -682,7 +682,7 @@ public class EventLogPanel extends TablePanel implements ILogListener, /** * Processes a new {@link LogEntry} by parsing it with {@link EventLogParser} and displaying it. * @param entry The new log entry - * @see LogReceiver.ILogListener#newEntry(LogEntry) + * @see LogReceiver.ILogListener#newEntry(LogEntry) */ @WorkerThread public void newEntry(LogEntry entry) { @@ -695,24 +695,24 @@ public class EventLogPanel extends TablePanel implements ILogListener, } } } - + @WorkerThread private void handleNewEvent(EventContainer event) { // add the event to the generic list mEvents.add(event); - + // add to the list of events that needs to be displayed, and trigger a // new display if needed. boolean start_event = false; synchronized (mNewEvents) { mNewEvents.add(event); - + if (mPendingDisplay == false) { mPendingDisplay = true; start_event = true; } } - + if (start_event == false) { // we're done return; @@ -737,7 +737,7 @@ public class EventLogPanel extends TablePanel implements ILogListener, } }); } catch (SWTException e) { - // if the ui is disposed, do nothing + // if the ui is disposed, do nothing } } @@ -766,7 +766,7 @@ public class EventLogPanel extends TablePanel implements ILogListener, for (EventDisplay eventDisplay : mEventDisplays) { eventDisplay.startMultiEventDisplay(); } - + // display the new events EventContainer event = null; boolean need_to_reloop = false; @@ -803,7 +803,7 @@ public class EventLogPanel extends TablePanel implements ILogListener, for (EventDisplay eventDisplay : mEventDisplays) { eventDisplay.endMultiEventDisplay(); } - + // if needed, ask the UI thread to re-run this method. if (need_to_reloop) { scheduleUIEventHandler(); @@ -816,10 +816,10 @@ public class EventLogPanel extends TablePanel implements ILogListener, private void loadEventDisplays() { IPreferenceStore store = DdmUiPreferences.getStore(); String storage = store.getString(PREFS_EVENT_DISPLAY); - + if (storage.length() > 0) { String[] values = storage.split(Pattern.quote(EVENT_DISPLAY_STORAGE_SEPARATOR)); - + for (String value : values) { EventDisplay eventDisplay = EventDisplay.load(value); if (eventDisplay != null) { @@ -834,10 +834,10 @@ public class EventLogPanel extends TablePanel implements ILogListener, */ private void saveEventDisplays() { IPreferenceStore store = DdmUiPreferences.getStore(); - + boolean first = true; StringBuilder sb = new StringBuilder(); - + for (EventDisplay eventDisplay : mEventDisplays) { String storage = eventDisplay.getStorageString(); if (storage != null) { @@ -846,7 +846,7 @@ public class EventLogPanel extends TablePanel implements ILogListener, } else { first = false; } - + sb.append(storage); } } @@ -870,7 +870,7 @@ public class EventLogPanel extends TablePanel implements ILogListener, for (EventDisplay eventDisplay : mEventDisplays) { eventDisplay.setNewLogParser(mCurrentEventLogParser); } - + mOptionsAction.setEnabled(true); mClearAction.setEnabled(true); if (mCurrentLogFile == null) { @@ -897,21 +897,21 @@ public class EventLogPanel extends TablePanel implements ILogListener, * Runs an event log service out of a local file. * @param fileName the full file name of the local file containing the event log. * @param logReceiver the receiver that will handle the log - * @throws IOException + * @throws IOException */ @WorkerThread private void runLocalEventLogService(String fileName, LogReceiver logReceiver) throws IOException { byte[] buffer = new byte[256]; - + FileInputStream fis = new FileInputStream(fileName); - + int count; while ((count = fis.read(buffer)) != -1) { logReceiver.parseNewData(buffer, 0, count); } } - + @WorkerThread private void runLocalEventLogService(String[] log, LogReceiver currentLogReceiver) { synchronized (mLock) { diff --git a/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogPanel.java b/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogPanel.java index bd8b75c..154e2fa 100644 --- a/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogPanel.java +++ b/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogPanel.java @@ -16,7 +16,7 @@ package com.android.ddmuilib.logcat; -import com.android.ddmlib.Device; +import com.android.ddmlib.IDevice; import com.android.ddmlib.Log; import com.android.ddmlib.MultiLineReceiver; import com.android.ddmlib.Log.LogLevel; @@ -163,13 +163,13 @@ public class LogPanel extends SelectionDependentPanel { private int mFilterMode = FILTER_NONE; /** Device currently running logcat */ - private Device mCurrentLoggedDevice = null; + private IDevice mCurrentLoggedDevice = null; private ICommonAction mDeleteFilterAction; private ICommonAction mEditFilterAction; private ICommonAction[] mLogLevelActions; - + /** message data, separated from content for multi line messages */ protected static class LogMessageInfo { public LogLevel logLevel; @@ -183,7 +183,7 @@ public class LogPanel extends SelectionDependentPanel { * log message, to reuse the info regarding level, pid, etc... */ private LogMessageInfo mLastMessageInfo = null; - + private boolean mPendingAsyncRefresh = false; /** loader for the images. the implementation will varie between standalone @@ -481,7 +481,7 @@ public class LogPanel extends SelectionDependentPanel { * Starts a new logcat and set mCurrentLogCat as the current receiver. * @param device the device to connect logcat to. */ - public void startLogCat(final Device device) { + public void startLogCat(final IDevice device) { if (device == mCurrentLoggedDevice) { return; } @@ -491,7 +491,7 @@ public class LogPanel extends SelectionDependentPanel { stopLogCat(false); mCurrentLoggedDevice = null; } - + resetUI(false); if (device != null) { @@ -696,7 +696,7 @@ public class LogPanel extends SelectionDependentPanel { synchronized (mBuffer) { FileDialog dlg = new FileDialog(mParent.getShell(), SWT.SAVE); String fileName; - + dlg.setText("Save log..."); dlg.setFileName("log.txt"); String defaultPath = mDefaultLogSave; @@ -710,7 +710,7 @@ public class LogPanel extends SelectionDependentPanel { dlg.setFilterExtensions(new String[] { "*.txt" }); - + fileName = dlg.open(); if (fileName != null) { mDefaultLogSave = dlg.getFilterPath(); @@ -928,7 +928,7 @@ public class LogPanel extends SelectionDependentPanel { t.setLinesVisible(false); if (mGlobalListener != null) { - addTableToFocusListener(t); + addTableToFocusListener(t); } // create a controllistener that will handle the resizing of all the @@ -1064,7 +1064,7 @@ public class LogPanel extends SelectionDependentPanel { } /** - * Process new Log lines coming from {@link LogCatOuputReceiver}. + * Process new Log lines coming from {@link LogCatOuputReceiver}. * @param lines the new lines */ protected void processLogLines(String[] lines) { @@ -1074,10 +1074,10 @@ public class LogPanel extends SelectionDependentPanel { if (lines.length > STRING_BUFFER_LENGTH) { Log.e("LogCat", "Receiving more lines than STRING_BUFFER_LENGTH"); } - + // parse the lines and create LogMessage that are stored in a temporary list final ArrayList<LogMessage> newMessages = new ArrayList<LogMessage>(); - + synchronized (mBuffer) { for (String line : lines) { // ignore empty lines. @@ -1087,7 +1087,7 @@ public class LogPanel extends SelectionDependentPanel { if (matcher.matches()) { // this is a header line, parse the header and keep it around. mLastMessageInfo = new LogMessageInfo(); - + mLastMessageInfo.time = matcher.group(1); mLastMessageInfo.pidString = matcher.group(2); mLastMessageInfo.pid = Integer.valueOf(mLastMessageInfo.pidString); @@ -1097,7 +1097,7 @@ public class LogPanel extends SelectionDependentPanel { // This is not a header line. // Create a new LogMessage and process it. LogMessage mc = new LogMessage(); - + if (mLastMessageInfo == null) { // The first line of output wasn't preceded // by a header line; make something up so @@ -1109,34 +1109,34 @@ public class LogPanel extends SelectionDependentPanel { mLastMessageInfo.logLevel = LogLevel.INFO; mLastMessageInfo.tag = "<unknown>"; //$NON-NLS1$ } - + // If someone printed a log message with // embedded '\n' characters, there will // one header line followed by multiple text lines. // Use the last header that we saw. mc.data = mLastMessageInfo; - + // tabs seem to display as only 1 tab so we replace the leading tabs // by 4 spaces. mc.msg = line.replaceAll("\t", " "); //$NON-NLS-1$ //$NON-NLS-2$ - + // process the new LogMessage. processNewMessage(mc); - + // store the new LogMessage newMessages.add(mc); } } } - + // if we don't have a pending Runnable that will do the refresh, we ask the Display // to run one in the UI thread. if (mPendingAsyncRefresh == false) { mPendingAsyncRefresh = true; - + try { Display display = mFolders.getDisplay(); - + // run in sync because this will update the buffer start/end indices display.asyncExec(new Runnable() { public void run() { @@ -1165,7 +1165,7 @@ public class LogPanel extends SelectionDependentPanel { f.flush(); } } - + if (mDefaultFilter != null) { mDefaultFilter.flush(); } @@ -1209,7 +1209,7 @@ public class LogPanel extends SelectionDependentPanel { // increment the next usable slot index mBufferEnd = (mBufferEnd + 1) % STRING_BUFFER_LENGTH; } - + LogMessage oldMessage = null; // record the message that was there before @@ -1381,7 +1381,7 @@ public class LogPanel extends SelectionDependentPanel { initDefaultFilter(); return; } - + filter.clear(); if (mBufferStart != -1) { @@ -1482,13 +1482,13 @@ public class LogPanel extends SelectionDependentPanel { if (mDefaultFilter != null) { mDefaultFilter.resetTempFiltering(); } - + // now we need to figure out the new temp filtering // split each word String[] segments = text.split(" "); //$NON-NLS-1$ - + ArrayList<String> keywords = new ArrayList<String>(segments.length); - + // loop and look for temp id/tag int tempPid = -1; String tempTag = null; @@ -1511,12 +1511,12 @@ public class LogPanel extends SelectionDependentPanel { keywords.add(s); } } - + // set the temp filtering in the filters if (tempPid != -1 || tempTag != null || keywords.size() > 0) { String[] keywordsArray = keywords.toArray( new String[keywords.size()]); - + for (LogFilter f : mFilters) { if (tempPid != -1) { f.setTempPidFiltering(tempPid); @@ -1526,7 +1526,7 @@ public class LogPanel extends SelectionDependentPanel { } f.setTempKeywordFiltering(keywordsArray); } - + if (mDefaultFilter != null) { if (tempPid != -1) { mDefaultFilter.setTempPidFiltering(tempPid); @@ -1535,10 +1535,10 @@ public class LogPanel extends SelectionDependentPanel { mDefaultFilter.setTempTagFiltering(tempTag); } mDefaultFilter.setTempKeywordFiltering(keywordsArray); - + } } - + initFilter(mCurrentFilter); } } diff --git a/dumpeventlog/src/com/android/dumpeventlog/DumpEventLog.java b/dumpeventlog/src/com/android/dumpeventlog/DumpEventLog.java index 6c528e1..695573c 100644 --- a/dumpeventlog/src/com/android/dumpeventlog/DumpEventLog.java +++ b/dumpeventlog/src/com/android/dumpeventlog/DumpEventLog.java @@ -17,7 +17,7 @@ package com.android.dumpeventlog; import com.android.ddmlib.AndroidDebugBridge; -import com.android.ddmlib.Device; +import com.android.ddmlib.IDevice; import com.android.ddmlib.Log; import com.android.ddmlib.Log.ILogOutput; import com.android.ddmlib.Log.LogLevel; @@ -30,7 +30,7 @@ import java.io.FileOutputStream; import java.io.IOException; /** - * Connects to a device using ddmlib and dumps its event log as long as the device is connected. + * Connects to a device using ddmlib and dumps its event log as long as the device is connected. */ public class DumpEventLog { @@ -74,7 +74,7 @@ public class DumpEventLog { System.out.println("Usage: dumpeventlog <device s/n> <filepath>"); return; } - + // redirect the log output to /dev/null Log.setLogOutput(new ILogOutput() { public void printAndPromptLog(LogLevel logLevel, String tag, String message) { @@ -85,13 +85,13 @@ public class DumpEventLog { // pass } }); - + // init the lib AndroidDebugBridge.init(false /* debugger support */); - + try { AndroidDebugBridge bridge = AndroidDebugBridge.createBridge(); - + // we can't just ask for the device list right away, as the internal thread getting // them from ADB may not be done getting the first list. // Since we don't really want getDevices() to be blocking, we wait here manually. @@ -103,7 +103,7 @@ public class DumpEventLog { } catch (InterruptedException e) { // pass } - + // let's not wait > 10 sec. if (count > 100) { System.err.println("Timeout getting device list!"); @@ -112,9 +112,9 @@ public class DumpEventLog { } // now get the devices - Device[] devices = bridge.getDevices(); - - for (Device device : devices) { + IDevice[] devices = bridge.getDevices(); + + for (IDevice device : devices) { if (device.getSerialNumber().equals(args[0])) { try { grabLogFrom(device, args[1]); @@ -126,20 +126,20 @@ public class DumpEventLog { return; } } - + System.err.println("Could not find " + args[0]); } finally { AndroidDebugBridge.terminate(); } } - private static void grabLogFrom(Device device, String filePath) throws IOException { + private static void grabLogFrom(IDevice device, String filePath) throws IOException { LogWriter writer = new LogWriter(filePath); LogReceiver receiver = new LogReceiver(writer); writer.setReceiver(receiver); device.runEventLogService(receiver); - + writer.done(); } } diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/AndroidLaunchController.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/AndroidLaunchController.java index f178597..5992fab 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/AndroidLaunchController.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/AndroidLaunchController.java @@ -19,7 +19,6 @@ package com.android.ide.eclipse.adt.internal.launch; import com.android.ddmlib.AndroidDebugBridge; import com.android.ddmlib.Client; import com.android.ddmlib.ClientData; -import com.android.ddmlib.Device; import com.android.ddmlib.IDevice; import com.android.ddmlib.Log; import com.android.ddmlib.MultiLineReceiver; @@ -1381,9 +1380,9 @@ public final class AndroidLaunchController implements IDebugBridgeChangeListener * This is sent from a non UI thread. * @param device the new device. * - * @see IDeviceChangeListener#deviceConnected(Device) + * @see IDeviceChangeListener#deviceConnected(IDevice) */ - public void deviceConnected(Device device) { + public void deviceConnected(IDevice device) { synchronized (sListLock) { // look if there's an app waiting for a device if (mWaitingForEmulatorLaunches.size() > 0) { @@ -1415,10 +1414,10 @@ public final class AndroidLaunchController implements IDebugBridgeChangeListener * This is sent from a non UI thread. * @param device the new device. * - * @see IDeviceChangeListener#deviceDisconnected(Device) + * @see IDeviceChangeListener#deviceDisconnected(IDevice) */ @SuppressWarnings("unchecked") - public void deviceDisconnected(Device device) { + public void deviceDisconnected(IDevice device) { // any pending launch on this device must be canceled. String message = "%1$s disconnected! Cancelling '%2$s'!"; synchronized (sListLock) { @@ -1451,9 +1450,9 @@ public final class AndroidLaunchController implements IDebugBridgeChangeListener * @param device the device that was updated. * @param changeMask the mask indicating what changed. * - * @see IDeviceChangeListener#deviceChanged(Device, int) + * @see IDeviceChangeListener#deviceChanged(IDevice, int) */ - public void deviceChanged(Device device, int changeMask) { + public void deviceChanged(IDevice device, int changeMask) { // We could check if any starting device we care about is now ready, but we can wait for // its home app to show up, so... } diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/DeviceChooserDialog.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/DeviceChooserDialog.java index 2d2b5df..a403f5a 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/DeviceChooserDialog.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/DeviceChooserDialog.java @@ -18,10 +18,9 @@ package com.android.ide.eclipse.adt.internal.launch; import com.android.ddmlib.AndroidDebugBridge; import com.android.ddmlib.Client; -import com.android.ddmlib.Device; import com.android.ddmlib.IDevice; import com.android.ddmlib.AndroidDebugBridge.IDeviceChangeListener; -import com.android.ddmlib.Device.DeviceState; +import com.android.ddmlib.IDevice.DeviceState; import com.android.ddmuilib.IImageLoader; import com.android.ddmuilib.ImageHelper; import com.android.ddmuilib.TableHelper; @@ -99,7 +98,7 @@ public class DeviceChooserDialog extends Dialog implements IDeviceChangeListener private boolean mDisableAvdSelectionChange = false; /** - * Basic Content Provider for a table full of {@link Device} objects. The input is + * Basic Content Provider for a table full of {@link IDevice} objects. The input is * a {@link AndroidDebugBridge}. */ private class ContentProvider implements IStructuredContentProvider { @@ -123,13 +122,13 @@ public class DeviceChooserDialog extends Dialog implements IDeviceChangeListener /** * A Label Provider for the {@link TableViewer} in {@link DeviceChooserDialog}. - * It provides labels and images for {@link Device} objects. + * It provides labels and images for {@link IDevice} objects. */ private class LabelProvider implements ITableLabelProvider { public Image getColumnImage(Object element, int columnIndex) { - if (element instanceof Device) { - Device device = (Device)element; + if (element instanceof IDevice) { + IDevice device = (IDevice)element; switch (columnIndex) { case 0: return device.isEmulator() ? mEmulatorImage : mDeviceImage; @@ -175,8 +174,8 @@ public class DeviceChooserDialog extends Dialog implements IDeviceChangeListener } public String getColumnText(Object element, int columnIndex) { - if (element instanceof Device) { - Device device = (Device)element; + if (element instanceof IDevice) { + IDevice device = (IDevice)element; switch (columnIndex) { case 0: return device.getSerialNumber(); @@ -514,7 +513,7 @@ public class DeviceChooserDialog extends Dialog implements IDeviceChangeListener * Returns a display string representing the state of the device. * @param d the device */ - private static String getStateString(Device d) { + private static String getStateString(IDevice d) { DeviceState deviceState = d.getState(); if (deviceState == DeviceState.ONLINE) { return "Online"; @@ -533,9 +532,9 @@ public class DeviceChooserDialog extends Dialog implements IDeviceChangeListener * This is sent from a non UI thread. * @param device the new device. * - * @see IDeviceChangeListener#deviceConnected(Device) + * @see IDeviceChangeListener#deviceConnected(IDevice) */ - public void deviceConnected(Device device) { + public void deviceConnected(IDevice device) { final DeviceChooserDialog dialog = this; exec(new Runnable() { public void run() { @@ -565,9 +564,9 @@ public class DeviceChooserDialog extends Dialog implements IDeviceChangeListener * This is sent from a non UI thread. * @param device the new device. * - * @see IDeviceChangeListener#deviceDisconnected(Device) + * @see IDeviceChangeListener#deviceDisconnected(IDevice) */ - public void deviceDisconnected(Device device) { + public void deviceDisconnected(IDevice device) { deviceConnected(device); } @@ -578,10 +577,10 @@ public class DeviceChooserDialog extends Dialog implements IDeviceChangeListener * @param device the device that was updated. * @param changeMask the mask indicating what changed. * - * @see IDeviceChangeListener#deviceChanged(Device, int) + * @see IDeviceChangeListener#deviceChanged(IDevice, int) */ - public void deviceChanged(final Device device, int changeMask) { - if ((changeMask & (Device.CHANGE_STATE | Device.CHANGE_BUILD_INFO)) != 0) { + public void deviceChanged(final IDevice device, int changeMask) { + if ((changeMask & (IDevice.CHANGE_STATE | IDevice.CHANGE_BUILD_INFO)) != 0) { final DeviceChooserDialog dialog = this; exec(new Runnable() { public void run() { @@ -663,15 +662,15 @@ public class DeviceChooserDialog extends Dialog implements IDeviceChangeListener } else { int index = mDeviceTable.getSelectionIndex(); Object data = mViewer.getElementAt(index); - if (data instanceof Device) { - handleSelection((Device)data); + if (data instanceof IDevice) { + handleSelection((IDevice)data); } else { handleSelection(null); } } } - private void handleSelection(Device device) { + private void handleSelection(IDevice device) { mResponse.setDeviceToUse(device); enableOkButton(); } @@ -686,9 +685,9 @@ public class DeviceChooserDialog extends Dialog implements IDeviceChangeListener if (mDeviceTable.getSelectionCount() == 0) { AndroidDebugBridge bridge = AndroidDebugBridge.getBridge(); - Device[] devices = bridge.getDevices(); + IDevice[] devices = bridge.getDevices(); - for (Device device : devices) { + for (IDevice device : devices) { Client[] clients = device.getClients(); for (Client client : clients) { @@ -724,9 +723,9 @@ public class DeviceChooserDialog extends Dialog implements IDeviceChangeListener // loop through all the Avd and put the one that are not running in the list. if (mFullAvdList != null) { - Device[] devices = AndroidDebugBridge.getBridge().getDevices(); + IDevice[] devices = AndroidDebugBridge.getBridge().getDevices(); avdLoop: for (AvdInfo info : mFullAvdList) { - for (Device d : devices) { + for (IDevice d : devices) { if (info.getName().equals(d.getAvdName())) { continue avdLoop; } diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/project/ApkInstallManager.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/project/ApkInstallManager.java index 84101f5..f7556c0 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/project/ApkInstallManager.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/project/ApkInstallManager.java @@ -17,7 +17,6 @@ package com.android.ide.eclipse.adt.internal.project; import com.android.ddmlib.AndroidDebugBridge; -import com.android.ddmlib.Device; import com.android.ddmlib.IDevice; import com.android.ddmlib.AndroidDebugBridge.IDebugBridgeChangeListener; import com.android.ddmlib.AndroidDebugBridge.IDeviceChangeListener; @@ -40,15 +39,15 @@ import java.util.ArrayList; * always receive new APKs (since the APK could be uninstalled manually). * <p/> * Manually uninstalling an APK from a connected device will still be a problem, but this should - * be a limited use case. + * be a limited use case. * <p/> * This is a singleton. To get the instance, use {@link #getInstance()} */ public class ApkInstallManager implements IDeviceChangeListener, IDebugBridgeChangeListener, IProjectListener { - + private final static ApkInstallManager sThis = new ApkInstallManager(); - + /** * Internal struct to associate a project and a device. */ @@ -60,13 +59,13 @@ public class ApkInstallManager implements IDeviceChangeListener, IDebugBridgeCha IProject project; IDevice device; } - + private final ArrayList<ApkInstall> mInstallList = new ArrayList<ApkInstall>(); - + public static ApkInstallManager getInstance() { return sThis; } - + /** * Registers an installation of <var>project</var> onto <var>device</var> * @param project The project that was installed. @@ -77,7 +76,7 @@ public class ApkInstallManager implements IDeviceChangeListener, IDebugBridgeCha mInstallList.add(new ApkInstall(project, device)); } } - + /** * Returns whether a <var>project</var> was installed on the <var>device</var>. * @param project the project that may have been installed. @@ -113,7 +112,7 @@ public class ApkInstallManager implements IDeviceChangeListener, IDebugBridgeCha } } } - + private ApkInstallManager() { AndroidDebugBridge.addDeviceChangeListener(this); AndroidDebugBridge.addDebugBridgeChangeListener(this); @@ -138,7 +137,7 @@ public class ApkInstallManager implements IDeviceChangeListener, IDebugBridgeCha * (non-Javadoc) * @see com.android.ddmlib.AndroidDebugBridge.IDeviceChangeListener#deviceDisconnected(com.android.ddmlib.Device) */ - public void deviceDisconnected(Device device) { + public void deviceDisconnected(IDevice device) { synchronized (mInstallList) { for (int i = 0 ; i < mInstallList.size() ;) { ApkInstall install = mInstallList.get(i); @@ -174,7 +173,7 @@ public class ApkInstallManager implements IDeviceChangeListener, IDebugBridgeCha * (non-Javadoc) * @see com.android.ddmlib.AndroidDebugBridge.IDeviceChangeListener#deviceChanged(com.android.ddmlib.Device, int) */ - public void deviceChanged(Device device, int changeMask) { + public void deviceChanged(IDevice device, int changeMask) { // nothing to do. } @@ -183,7 +182,7 @@ public class ApkInstallManager implements IDeviceChangeListener, IDebugBridgeCha * (non-Javadoc) * @see com.android.ddmlib.AndroidDebugBridge.IDeviceChangeListener#deviceConnected(com.android.ddmlib.Device) */ - public void deviceConnected(Device device) { + public void deviceConnected(IDevice device) { // nothing to do. } diff --git a/eclipse/plugins/com.android.ide.eclipse.ddms/src/com/android/ide/eclipse/ddms/DdmsPlugin.java b/eclipse/plugins/com.android.ide.eclipse.ddms/src/com/android/ide/eclipse/ddms/DdmsPlugin.java index ccadce6..d559b0f 100644 --- a/eclipse/plugins/com.android.ide.eclipse.ddms/src/com/android/ide/eclipse/ddms/DdmsPlugin.java +++ b/eclipse/plugins/com.android.ide.eclipse.ddms/src/com/android/ide/eclipse/ddms/DdmsPlugin.java @@ -19,7 +19,7 @@ package com.android.ide.eclipse.ddms; import com.android.ddmlib.AndroidDebugBridge; import com.android.ddmlib.Client; import com.android.ddmlib.DdmPreferences; -import com.android.ddmlib.Device; +import com.android.ddmlib.IDevice; import com.android.ddmlib.Log; import com.android.ddmlib.AndroidDebugBridge.IDeviceChangeListener; import com.android.ddmlib.Log.ILogOutput; @@ -76,11 +76,11 @@ public final class DdmsPlugin extends AbstractUIPlugin implements IDeviceChangeL /** Image loader object */ private ImageLoader mLoader; - - private Device mCurrentDevice; + + private IDevice mCurrentDevice; private Client mCurrentClient; private boolean mListeningToUiSelection = false; - + private final ArrayList<ISelectionListener> mListeners = new ArrayList<ISelectionListener>(); private Color mRed; @@ -93,24 +93,24 @@ public final class DdmsPlugin extends AbstractUIPlugin implements IDeviceChangeL public interface IDebugLauncher { public boolean debug(String packageName, int port); } - + /** * Classes which implement this interface provide methods that deals - * with {@link Device} and {@link Client} selectionchanges. + * with {@link IDevice} and {@link Client} selectionchanges. */ public interface ISelectionListener { - + /** * Sent when a new {@link Client} is selected. * @param selectedClient The selected client. If null, no clients are selected. */ public void selectionChanged(Client selectedClient); - + /** - * Sent when a new {@link Device} is selected. + * Sent when a new {@link IDevice} is selected. * @param selectedDevice the selected device. If null, no devices are selected. */ - public void selectionChanged(Device selectedDevice); + public void selectionChanged(IDevice selectedDevice); } /** @@ -128,14 +128,14 @@ public final class DdmsPlugin extends AbstractUIPlugin implements IDeviceChangeL @Override public void start(BundleContext context) throws Exception { super.start(context); - + final Display display = getDisplay(); // get the eclipse store final IPreferenceStore eclipseStore = getPreferenceStore(); AndroidDebugBridge.addDeviceChangeListener(this); - + DdmUiPreferences.setStore(eclipseStore); //DdmUiPreferences.displayCharts(); @@ -186,12 +186,12 @@ public final class DdmsPlugin extends AbstractUIPlugin implements IDeviceChangeL } }); } - + }); // 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() { @@ -214,7 +214,7 @@ public final class DdmsPlugin extends AbstractUIPlugin implements IDeviceChangeL } } }); - + // 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); @@ -248,9 +248,9 @@ public final class DdmsPlugin extends AbstractUIPlugin implements IDeviceChangeL @Override public void stop(BundleContext context) throws Exception { AndroidDebugBridge.removeDeviceChangeListener(this); - + AndroidDebugBridge.terminate(); - + mRed.dispose(); sPlugin = null; @@ -303,15 +303,15 @@ public final class DdmsPlugin extends AbstractUIPlugin implements IDeviceChangeL }.start(); } } - + private synchronized void initDdmlib() { if (mDdmlibInitialized == false) { // set the preferences. PreferenceInitializer.setupPreferences(); - + // init the lib AndroidDebugBridge.init(true /* debugger support */); - + mDdmlibInitialized = true; } } @@ -342,10 +342,10 @@ public final class DdmsPlugin extends AbstractUIPlugin implements IDeviceChangeL public static IDebugLauncher getRunningAppDebugLauncher() { return sRunningAppDebugLauncher; } - + public synchronized void addSelectionListener(ISelectionListener listener) { mListeners.add(listener); - + // notify the new listener of the current selection listener.selectionChanged(mCurrentDevice); listener.selectionChanged(mCurrentClient); @@ -364,10 +364,10 @@ public final class DdmsPlugin extends AbstractUIPlugin implements IDeviceChangeL * <p/> * This is sent from a non UI thread. * @param device the new device. - * - * @see IDeviceChangeListener#deviceConnected(Device) + * + * @see IDeviceChangeListener#deviceConnected(IDevice) */ - public void deviceConnected(Device device) { + public void deviceConnected(IDevice device) { // 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. @@ -383,10 +383,10 @@ public final class DdmsPlugin extends AbstractUIPlugin implements IDeviceChangeL * <p/> * This is sent from a non UI thread. * @param device the new device. - * - * @see IDeviceChangeListener#deviceDisconnected(Device) + * + * @see IDeviceChangeListener#deviceDisconnected(IDevice) */ - public void deviceDisconnected(Device device) { + public void deviceDisconnected(IDevice device) { // 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. @@ -397,16 +397,16 @@ public final class DdmsPlugin extends AbstractUIPlugin implements IDeviceChangeL AndroidDebugBridge bridge = AndroidDebugBridge.getBridge(); if (bridge != null) { // get the device list - Device[] devices = bridge.getDevices(); - + IDevice[] devices = bridge.getDevices(); + // check if we still have devices if (devices.length == 0) { - handleDefaultSelection((Device)null); + handleDefaultSelection((IDevice)null); } else { handleDefaultSelection(devices[0]); } } else { - handleDefaultSelection((Device)null); + handleDefaultSelection((IDevice)null); } } } @@ -418,15 +418,15 @@ public final class DdmsPlugin extends AbstractUIPlugin implements IDeviceChangeL * This is sent from a non UI thread. * @param device the device that was updated. * @param changeMask the mask indicating what changed. - * - * @see IDeviceChangeListener#deviceChanged(Device) + * + * @see IDeviceChangeListener#deviceChanged(IDevice) */ - public void deviceChanged(Device device, int changeMask) { + public void deviceChanged(IDevice device, int changeMask) { // 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) { @@ -441,7 +441,7 @@ public final class DdmsPlugin extends AbstractUIPlugin implements IDeviceChangeL break; } } - + // if we haven't found our client, lets look for a new one if (foundClient == false) { mCurrentClient = null; @@ -453,11 +453,11 @@ public final class DdmsPlugin extends AbstractUIPlugin implements IDeviceChangeL } /** - * Sent when a new {@link Device} and {@link Client} are selected. + * Sent when a new {@link IDevice} and {@link Client} are selected. * @param selectedDevice the selected device. If null, no devices are selected. * @param selectedClient The selected client. If null, no clients are selected. */ - public synchronized void selectionChanged(Device selectedDevice, Client selectedClient) { + public synchronized void selectionChanged(IDevice selectedDevice, Client selectedClient) { if (mCurrentDevice != selectedDevice) { mCurrentDevice = selectedDevice; @@ -469,7 +469,7 @@ public final class DdmsPlugin extends AbstractUIPlugin implements IDeviceChangeL if (mCurrentClient != selectedClient) { mCurrentClient = selectedClient; - + // notify of the new default client for (ISelectionListener listener : mListeners) { listener.selectionChanged(mCurrentClient); @@ -478,15 +478,15 @@ public final class DdmsPlugin extends AbstractUIPlugin implements IDeviceChangeL } /** - * Handles a default selection of a {@link Device} and {@link Client}. + * Handles a default selection of a {@link IDevice} and {@link Client}. * @param device the selected device */ - private void handleDefaultSelection(final Device device) { + private void handleDefaultSelection(final IDevice device) { // 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. @@ -494,13 +494,13 @@ public final class DdmsPlugin extends AbstractUIPlugin implements IDeviceChangeL 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. @@ -522,16 +522,16 @@ public final class DdmsPlugin extends AbstractUIPlugin implements IDeviceChangeL // display is disposed. Do nothing since we're quitting anyway. } } - + private void handleDefaultSelection(Client client) { mCurrentClient = client; - + // notify of the new default client for (ISelectionListener listener : mListeners) { listener.selectionChanged(mCurrentClient); } } - + /** * Prints a message, associated with a project to the specified stream * @param stream The stream to write to @@ -545,7 +545,7 @@ public final class DdmsPlugin extends AbstractUIPlugin implements IDeviceChangeL stream.print(dateTag); stream.println(message); } - + /** * Creates a string containing the current date/time, and the tag * @param tag The tag associated to the message. Can be null diff --git a/eclipse/plugins/com.android.ide.eclipse.ddms/src/com/android/ide/eclipse/ddms/views/DeviceView.java b/eclipse/plugins/com.android.ide.eclipse.ddms/src/com/android/ide/eclipse/ddms/views/DeviceView.java index 62a528a..30172f5 100644 --- a/eclipse/plugins/com.android.ide.eclipse.ddms/src/com/android/ide/eclipse/ddms/views/DeviceView.java +++ b/eclipse/plugins/com.android.ide.eclipse.ddms/src/com/android/ide/eclipse/ddms/views/DeviceView.java @@ -20,7 +20,7 @@ package com.android.ide.eclipse.ddms.views; import com.android.ddmlib.Client; import com.android.ddmlib.ClientData; import com.android.ddmlib.AndroidDebugBridge; -import com.android.ddmlib.Device; +import com.android.ddmlib.IDevice; import com.android.ddmuilib.DevicePanel; import com.android.ddmuilib.ScreenShotDialog; import com.android.ddmuilib.DevicePanel.IUiSelectionListener; @@ -42,7 +42,7 @@ import org.eclipse.ui.PlatformUI; import org.eclipse.ui.part.ViewPart; public class DeviceView extends ViewPart implements IUiSelectionListener { - + private final static boolean USE_SELECTED_DEBUG_PORT = true; public static final String ID = @@ -69,7 +69,7 @@ public class DeviceView extends ViewPart implements IUiSelectionListener { public static DeviceView getInstance() { return sThis; } - + /** * Sets the {@link IDebugLauncher}. * @param debugLauncher @@ -89,7 +89,7 @@ public class DeviceView extends ViewPart implements IUiSelectionListener { mDeviceList = new DevicePanel(DdmsPlugin.getImageLoader(), USE_SELECTED_DEBUG_PORT); mDeviceList.createPanel(parent); mDeviceList.addSelectionListener(this); - + DdmsPlugin plugin = DdmsPlugin.getDefault(); mDeviceList.addSelectionListener(plugin); plugin.setListeningState(true); @@ -212,7 +212,7 @@ public class DeviceView extends ViewPart implements IUiSelectionListener { if (packageName != null) { if (mDebugLauncher.debug(packageName, currentClient.getDebuggerListenPort()) == false) { - + // if we get to this point, then we failed to find a project // that matched the application to debug Display display = DdmsPlugin.getDisplay(); @@ -233,7 +233,7 @@ public class DeviceView extends ViewPart implements IUiSelectionListener { if (mDebugLauncher == null) { mDebugAction.setEnabled(false); } - + placeActions(); } @@ -241,13 +241,13 @@ public class DeviceView extends ViewPart implements IUiSelectionListener { public void setFocus() { mDeviceList.setFocus(); } - + /** - * Sent when a new {@link Device} and {@link Client} are selected. + * Sent when a new {@link IDevice} and {@link Client} are selected. * @param selectedDevice the selected device. If null, no devices are selected. * @param selectedClient The selected client. If null, no clients are selected. */ - public void selectionChanged(Device selectedDevice, Client selectedClient) { + public void selectionChanged(IDevice selectedDevice, Client selectedClient) { // update the buttons doSelectionChanged(selectedClient); doSelectionChanged(selectedDevice); @@ -264,7 +264,7 @@ public class DeviceView extends ViewPart implements IUiSelectionListener { mDebugAction.setEnabled(mDebugLauncher != null); mKillAppAction.setEnabled(true); mGcAction.setEnabled(true); - + mUpdateHeapAction.setEnabled(true); mUpdateHeapAction.setChecked(selectedClient.isHeapUpdateEnabled()); @@ -278,7 +278,7 @@ public class DeviceView extends ViewPart implements IUiSelectionListener { bridge.setSelectedClient(null); } } - + mDebugAction.setEnabled(false); mKillAppAction.setEnabled(false); mGcAction.setEnabled(false); @@ -288,8 +288,8 @@ public class DeviceView extends ViewPart implements IUiSelectionListener { mUpdateThreadAction.setChecked(false); } } - - private void doSelectionChanged(Device selectedDevice) { + + private void doSelectionChanged(IDevice selectedDevice) { mCaptureAction.setEnabled(selectedDevice != null); } diff --git a/eclipse/plugins/com.android.ide.eclipse.ddms/src/com/android/ide/eclipse/ddms/views/FileExplorerView.java b/eclipse/plugins/com.android.ide.eclipse.ddms/src/com/android/ide/eclipse/ddms/views/FileExplorerView.java index 4f0dd2e..e79010c 100644 --- a/eclipse/plugins/com.android.ide.eclipse.ddms/src/com/android/ide/eclipse/ddms/views/FileExplorerView.java +++ b/eclipse/plugins/com.android.ide.eclipse.ddms/src/com/android/ide/eclipse/ddms/views/FileExplorerView.java @@ -17,7 +17,7 @@ package com.android.ide.eclipse.ddms.views; import com.android.ddmlib.Client; -import com.android.ddmlib.Device; +import com.android.ddmlib.IDevice; import com.android.ddmuilib.explorer.DeviceExplorer; import com.android.ide.eclipse.ddms.CommonAction; import com.android.ide.eclipse.ddms.DdmsPlugin; @@ -26,6 +26,7 @@ import com.android.ide.eclipse.ddms.DdmsPlugin.ISelectionListener; import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.IToolBarManager; import org.eclipse.jface.action.Separator; +import org.eclipse.swt.graphics.Device; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.IActionBars; import org.eclipse.ui.ISharedImages; @@ -128,7 +129,7 @@ public class FileExplorerView extends ViewPart implements ISelectionListener { toolBarManager.add(pushAction); toolBarManager.add(new Separator()); toolBarManager.add(deleteAction); - + mExplorer.createPanel(parent); DdmsPlugin.getDefault().addSelectionListener(this); @@ -146,20 +147,20 @@ public class FileExplorerView extends ViewPart implements ISelectionListener { public void selectionChanged(Client selectedClient) { // pass } - + /** * Sent when a new {@link Device} is selected. * @param selectedDevice the selected device. */ - public void selectionChanged(Device selectedDevice) { + public void selectionChanged(IDevice selectedDevice) { mExplorer.switchDevice(selectedDevice); } - + /** * Sent when there is no current selection. */ public void selectionRemoved() { - + } } diff --git a/eclipse/plugins/com.android.ide.eclipse.ddms/src/com/android/ide/eclipse/ddms/views/SelectionDependentViewPart.java b/eclipse/plugins/com.android.ide.eclipse.ddms/src/com/android/ide/eclipse/ddms/views/SelectionDependentViewPart.java index 48b2689..40dae43 100644 --- a/eclipse/plugins/com.android.ide.eclipse.ddms/src/com/android/ide/eclipse/ddms/views/SelectionDependentViewPart.java +++ b/eclipse/plugins/com.android.ide.eclipse.ddms/src/com/android/ide/eclipse/ddms/views/SelectionDependentViewPart.java @@ -16,12 +16,13 @@ package com.android.ide.eclipse.ddms.views; -import com.android.ide.eclipse.ddms.DdmsPlugin; -import com.android.ide.eclipse.ddms.DdmsPlugin.ISelectionListener; import com.android.ddmlib.Client; -import com.android.ddmlib.Device; +import com.android.ddmlib.IDevice; import com.android.ddmuilib.SelectionDependentPanel; +import com.android.ide.eclipse.ddms.DdmsPlugin; +import com.android.ide.eclipse.ddms.DdmsPlugin.ISelectionListener; +import org.eclipse.swt.graphics.Device; import org.eclipse.ui.part.ViewPart; /** @@ -29,17 +30,17 @@ import org.eclipse.ui.part.ViewPart; * from {@link DdmsPlugin} through the {@link ISelectionListener} interface. */ public abstract class SelectionDependentViewPart extends ViewPart implements ISelectionListener { - + private SelectionDependentPanel mPanel; - + protected final void setSelectionDependentPanel(SelectionDependentPanel panel) { // remember the panel mPanel = panel; - + // and add ourself as listener of selection events. DdmsPlugin.getDefault().addSelectionListener(this); } - + @Override public void dispose() { DdmsPlugin.getDefault().removeSelectionListener(this); @@ -49,20 +50,20 @@ public abstract class SelectionDependentViewPart extends ViewPart implements ISe /** * Sent when a new {@link Client} is selected. * @param selectedClient The selected client. - * + * * @see ISelectionListener */ public final void selectionChanged(Client selectedClient) { mPanel.clientSelected(selectedClient); } - + /** * Sent when a new {@link Device} is selected. * @param selectedDevice the selected device. * * @see ISelectionListener */ - public final void selectionChanged(Device selectedDevice) { + public final void selectionChanged(IDevice selectedDevice) { mPanel.deviceSelected(selectedDevice); } } diff --git a/eventanalyzer/src/com/android/eventanalyzer/EventAnalyzer.java b/eventanalyzer/src/com/android/eventanalyzer/EventAnalyzer.java index c520784..11444ec 100644 --- a/eventanalyzer/src/com/android/eventanalyzer/EventAnalyzer.java +++ b/eventanalyzer/src/com/android/eventanalyzer/EventAnalyzer.java @@ -17,7 +17,7 @@ package com.android.eventanalyzer; import com.android.ddmlib.AndroidDebugBridge; -import com.android.ddmlib.Device; +import com.android.ddmlib.IDevice; import com.android.ddmlib.Log; import com.android.ddmlib.Log.ILogOutput; import com.android.ddmlib.Log.LogLevel; @@ -42,19 +42,19 @@ import java.util.Set; import java.util.TreeMap; /** - * Connects to a device using ddmlib and analyze its event log. + * Connects to a device using ddmlib and analyze its event log. */ public class EventAnalyzer implements ILogListener { - + private final static int TAG_ACTIVITY_LAUNCH_TIME = 30009; private final static char DATA_SEPARATOR = ','; private final static String CVS_EXT = ".csv"; private final static String TAG_FILE_EXT = ".tag"; //$NON-NLS-1$ - + private EventLogParser mParser; - private TreeMap<String, ArrayList<Long>> mLaunchMap = new TreeMap<String, ArrayList<Long>>(); - + private TreeMap<String, ArrayList<Long>> mLaunchMap = new TreeMap<String, ArrayList<Long>>(); + String mInputTextFile = null; String mInputBinaryFile = null; String mInputDevice = null; @@ -65,47 +65,47 @@ public class EventAnalyzer implements ILogListener { public static void main(String[] args) { new EventAnalyzer().run(args); } - + private void run(String[] args) { if (args.length == 0) { printUsageAndQuit(); } - + int index = 0; do { String argument = args[index++]; if ("-s".equals(argument)) { checkInputValidity("-s"); - + if (index == args.length) { printUsageAndQuit(); } - + mInputDevice = args[index++]; } else if ("-fb".equals(argument)) { checkInputValidity("-fb"); - + if (index == args.length) { printUsageAndQuit(); } - + mInputBinaryFile = args[index++]; } else if ("-ft".equals(argument)) { checkInputValidity("-ft"); - + if (index == args.length) { printUsageAndQuit(); } - + mInputTextFile = args[index++]; } else if ("-F".equals(argument)) { checkInputValidity("-F"); - + if (index == args.length) { printUsageAndQuit(); } - + mInputFolder = args[index++]; } else if ("-t".equals(argument)) { if (index == args.length) { @@ -156,17 +156,17 @@ public class EventAnalyzer implements ILogListener { } else if (mInputDevice != null) { parseLogFromDevice(); } - + // analyze the data gathered by the parser methods analyzeData(); } catch (IOException e) { e.printStackTrace(); } } - + /** * Parses a binary event log file located at {@link #mInputBinaryFile}. - * @throws IOException + * @throws IOException */ private void parseBinaryLogFile() throws IOException { mParser = new EventLogParser(); @@ -183,13 +183,13 @@ public class EventAnalyzer implements ILogListener { printAndExit("Failed to get event tags from " + tagFile, false /* terminate*/); } } - + LogReceiver receiver = new LogReceiver(this); byte[] buffer = new byte[256]; - + FileInputStream fis = new FileInputStream(mInputBinaryFile); - + int count; while ((count = fis.read(buffer)) != -1) { receiver.parseNewData(buffer, 0, count); @@ -230,10 +230,10 @@ public class EventAnalyzer implements ILogListener { private void parseLogFromDevice() throws IOException { // init the lib AndroidDebugBridge.init(false /* debugger support */); - + try { AndroidDebugBridge bridge = AndroidDebugBridge.createBridge(); - + // we can't just ask for the device list right away, as the internal thread getting // them from ADB may not be done getting the first list. // Since we don't really want getDevices() to be blocking, we wait here manually. @@ -245,7 +245,7 @@ public class EventAnalyzer implements ILogListener { } catch (InterruptedException e) { // pass } - + // let's not wait > 10 sec. if (count > 100) { printAndExit("Timeout getting device list!", true /* terminate*/); @@ -253,21 +253,21 @@ public class EventAnalyzer implements ILogListener { } // now get the devices - Device[] devices = bridge.getDevices(); - - for (Device device : devices) { + IDevice[] devices = bridge.getDevices(); + + for (IDevice device : devices) { if (device.getSerialNumber().equals(mInputDevice)) { grabLogFrom(device); return; } } - + System.err.println("Could not find " + mInputDevice); } finally { AndroidDebugBridge.terminate(); } } - + /** * Parses the log files located in the folder, and its sub-folders. * @param folderPath the path to the folder. @@ -278,14 +278,14 @@ public class EventAnalyzer implements ILogListener { printAndExit(String.format("%1$s is not a valid folder", folderPath), false /* terminate */); } - + String[] files = f.list(new FilenameFilter() { public boolean accept(File dir, String name) { name = name.toLowerCase(); return name.endsWith(".tag") == false; } }); - + for (String file : files) { try { f = new File(folderPath + File.separator + file); @@ -300,18 +300,18 @@ public class EventAnalyzer implements ILogListener { } } - private void grabLogFrom(Device device) throws IOException { + private void grabLogFrom(IDevice device) throws IOException { mParser = new EventLogParser(); if (mParser.init(device) == false) { printAndExit("Failed to get event-log-tags from " + device.getSerialNumber(), true /* terminate*/); } - + LogReceiver receiver = new LogReceiver(this); device.runEventLogService(receiver); } - + /** * Analyze the data and writes it to {@link #mOutputFile} * @throws IOException @@ -326,23 +326,23 @@ public class EventAnalyzer implements ILogListener { writer = new BufferedWriter(new FileWriter(mOutputFile)); StringBuilder builder = new StringBuilder(); - + // write the list of launch start. One column per activity. Set<String> activities = mLaunchMap.keySet(); - + // write the column headers. for (String activity : activities) { builder.append(activity).append(DATA_SEPARATOR); } writer.write(builder.append('\n').toString()); - + // loop on the activities and write their values. boolean moreValues = true; int index = 0; while (moreValues) { moreValues = false; builder.setLength(0); - + for (String activity : activities) { // get the activity list. ArrayList<Long> list = mLaunchMap.get(activity); @@ -353,33 +353,33 @@ public class EventAnalyzer implements ILogListener { builder.append(DATA_SEPARATOR); } } - + // write the line. if (moreValues) { writer.write(builder.append('\n').toString()); } - + index++; } - + // write per-activity stats. for (String activity : activities) { builder.setLength(0); builder.append(activity).append(DATA_SEPARATOR); - + // get the activity list. ArrayList<Long> list = mLaunchMap.get(activity); - + // sort the list Collections.sort(list); - + // write min/max builder.append(list.get(0).longValue()).append(DATA_SEPARATOR); builder.append(list.get(list.size()-1).longValue()).append(DATA_SEPARATOR); - + // write median value builder.append(list.get(list.size()/2).longValue()).append(DATA_SEPARATOR); - + // compute and write average long total = 0; // despite being encoded on a long, the values are low enough that // a Long should be enough to compute the total @@ -387,7 +387,7 @@ public class EventAnalyzer implements ILogListener { total += value.longValue(); } builder.append(total / list.size()).append(DATA_SEPARATOR); - + // finally write the data. writer.write(builder.append('\n').toString()); } @@ -412,7 +412,7 @@ public class EventAnalyzer implements ILogListener { // parse and process the entry data. processEvent(mParser.parse(entry)); } - + private void processEvent(EventContainer event) { if (event != null && event.mTag == TAG_ACTIVITY_LAUNCH_TIME) { // get the activity name @@ -434,12 +434,12 @@ public class EventAnalyzer implements ILogListener { private void addLaunchTime(String name, Long value) { ArrayList<Long> list = mLaunchMap.get(name); - + if (list == null) { list = new ArrayList<Long>(); mLaunchMap.put(name, list); } - + list.add(value); } @@ -469,11 +469,11 @@ public class EventAnalyzer implements ILogListener { System.out.println("Options:"); System.out.println(" -t <file> The path to tag file to use in case the one associated with"); System.out.println(" the source is missing"); - + System.exit(1); } - - + + private static void printAndExit(String message, boolean terminate) { System.out.println(message); if (terminate) { diff --git a/hierarchyviewer/src/com/android/hierarchyviewer/device/DeviceBridge.java b/hierarchyviewer/src/com/android/hierarchyviewer/device/DeviceBridge.java index 850a238..0f60be6 100644 --- a/hierarchyviewer/src/com/android/hierarchyviewer/device/DeviceBridge.java +++ b/hierarchyviewer/src/com/android/hierarchyviewer/device/DeviceBridge.java @@ -17,7 +17,7 @@ package com.android.hierarchyviewer.device; import com.android.ddmlib.AndroidDebugBridge; -import com.android.ddmlib.Device; +import com.android.ddmlib.IDevice; import com.android.ddmlib.Log; import com.android.ddmlib.MultiLineReceiver; @@ -29,8 +29,8 @@ import java.util.regex.Pattern; public class DeviceBridge { private static AndroidDebugBridge bridge; - - private static final HashMap<Device, Integer> devicePortMap = new HashMap<Device, Integer>(); + + private static final HashMap<IDevice, Integer> devicePortMap = new HashMap<IDevice, Integer>(); private static int nextLocalPort = Configuration.DEFAULT_SERVER_PORT; public static void initDebugBridge() { @@ -57,11 +57,11 @@ public class DeviceBridge { AndroidDebugBridge.removeDeviceChangeListener(listener); } - public static Device[] getDevices() { + public static IDevice[] getDevices() { return bridge.getDevices(); } - public static boolean isViewServerRunning(Device device) { + public static boolean isViewServerRunning(IDevice device) { initDebugBridge(); final boolean[] result = new boolean[1]; try { @@ -75,11 +75,11 @@ public class DeviceBridge { return result[0]; } - public static boolean startViewServer(Device device) { + public static boolean startViewServer(IDevice device) { return startViewServer(device, Configuration.DEFAULT_SERVER_PORT); } - public static boolean startViewServer(Device device, int port) { + public static boolean startViewServer(IDevice device, int port) { initDebugBridge(); final boolean[] result = new boolean[1]; try { @@ -93,7 +93,7 @@ public class DeviceBridge { return result[0]; } - public static boolean stopViewServer(Device device) { + public static boolean stopViewServer(IDevice device) { initDebugBridge(); final boolean[] result = new boolean[1]; try { @@ -116,17 +116,17 @@ public class DeviceBridge { * <p/>This starts a port forwarding between a local port and a port on the device. * @param device */ - public static void setupDeviceForward(Device device) { + public static void setupDeviceForward(IDevice device) { synchronized (devicePortMap) { - if (device.getState() == Device.DeviceState.ONLINE) { + if (device.getState() == IDevice.DeviceState.ONLINE) { int localPort = nextLocalPort++; device.createForward(localPort, Configuration.DEFAULT_SERVER_PORT); devicePortMap.put(device, localPort); } } } - - public static void removeDeviceForward(Device device) { + + public static void removeDeviceForward(IDevice device) { synchronized (devicePortMap) { final Integer localPort = devicePortMap.get(device); if (localPort != null) { @@ -135,18 +135,18 @@ public class DeviceBridge { } } } - - public static int getDeviceLocalPort(Device device) { + + public static int getDeviceLocalPort(IDevice device) { synchronized (devicePortMap) { Integer port = devicePortMap.get(device); if (port != null) { return port; } - + Log.e("hierarchy", "Missing forwarded port for " + device.getSerialNumber()); return -1; } - + } private static String buildStartServerShellCommand(int port) { diff --git a/hierarchyviewer/src/com/android/hierarchyviewer/scene/CaptureLoader.java b/hierarchyviewer/src/com/android/hierarchyviewer/scene/CaptureLoader.java index 7cc44bc..c512ac2 100644 --- a/hierarchyviewer/src/com/android/hierarchyviewer/scene/CaptureLoader.java +++ b/hierarchyviewer/src/com/android/hierarchyviewer/scene/CaptureLoader.java @@ -16,7 +16,7 @@ package com.android.hierarchyviewer.scene; -import com.android.ddmlib.Device; +import com.android.ddmlib.IDevice; import com.android.hierarchyviewer.device.Configuration; import com.android.hierarchyviewer.device.Window; import com.android.hierarchyviewer.device.DeviceBridge; @@ -31,16 +31,16 @@ import java.net.Socket; import javax.imageio.ImageIO; public class CaptureLoader { - public static Image loadCapture(Device device, Window window, String params) { + public static Image loadCapture(IDevice device, Window window, String params) { Socket socket = null; BufferedInputStream in = null; BufferedWriter out = null; - + try { socket = new Socket(); socket.connect(new InetSocketAddress("127.0.0.1", DeviceBridge.getDeviceLocalPort(device))); - + out = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())); in = new BufferedInputStream(socket.getInputStream()); @@ -66,7 +66,7 @@ public class CaptureLoader { ex.printStackTrace(); } } - + return null; } } diff --git a/hierarchyviewer/src/com/android/hierarchyviewer/scene/ProfilesLoader.java b/hierarchyviewer/src/com/android/hierarchyviewer/scene/ProfilesLoader.java index 83b9113..b91db79 100644 --- a/hierarchyviewer/src/com/android/hierarchyviewer/scene/ProfilesLoader.java +++ b/hierarchyviewer/src/com/android/hierarchyviewer/scene/ProfilesLoader.java @@ -16,7 +16,7 @@ package com.android.hierarchyviewer.scene; -import com.android.ddmlib.Device; +import com.android.ddmlib.IDevice; import com.android.hierarchyviewer.device.Window; import com.android.hierarchyviewer.device.DeviceBridge; @@ -29,7 +29,7 @@ import java.io.BufferedReader; import java.io.InputStreamReader; public class ProfilesLoader { - public static double[] loadProfiles(Device device, Window window, String params) { + public static double[] loadProfiles(IDevice device, Window window, String params) { Socket socket = null; BufferedReader in = null; BufferedWriter out = null; diff --git a/hierarchyviewer/src/com/android/hierarchyviewer/scene/ViewHierarchyLoader.java b/hierarchyviewer/src/com/android/hierarchyviewer/scene/ViewHierarchyLoader.java index 1f3e278..6254262 100644 --- a/hierarchyviewer/src/com/android/hierarchyviewer/scene/ViewHierarchyLoader.java +++ b/hierarchyviewer/src/com/android/hierarchyviewer/scene/ViewHierarchyLoader.java @@ -16,7 +16,7 @@ package com.android.hierarchyviewer.scene; -import com.android.ddmlib.Device; +import com.android.ddmlib.IDevice; import com.android.hierarchyviewer.device.DeviceBridge; import com.android.hierarchyviewer.device.Window; @@ -36,19 +36,19 @@ import java.util.regex.Pattern; public class ViewHierarchyLoader { @SuppressWarnings("empty-statement") - public static ViewHierarchyScene loadScene(Device device, Window window) { + public static ViewHierarchyScene loadScene(IDevice device, Window window) { ViewHierarchyScene scene = new ViewHierarchyScene(); // Read the views tree Socket socket = null; BufferedReader in = null; BufferedWriter out = null; - + String line; - + try { System.out.println("==> Starting client"); - + socket = new Socket(); socket.connect(new InetSocketAddress("127.0.0.1", DeviceBridge.getDeviceLocalPort(device))); @@ -57,11 +57,11 @@ public class ViewHierarchyLoader { in = new BufferedReader(new InputStreamReader(socket.getInputStream())); System.out.println("==> DUMP"); - + out.write("DUMP " + window.encode()); out.newLine(); out.flush(); - + Stack<ViewNode> stack = new Stack<ViewNode>(); boolean setRoot = true; @@ -72,7 +72,7 @@ public class ViewHierarchyLoader { if ("DONE.".equalsIgnoreCase(line)) { break; } - + int whitespaceCount = countFrontWhitespace(line); if (lastWhitespaceCount < whitespaceCount) { stack.push(lastNode); @@ -86,7 +86,7 @@ public class ViewHierarchyLoader { lastWhitespaceCount = whitespaceCount; line = line.trim(); int index = line.indexOf(' '); - + lastNode = new ViewNode(); lastNode.name = line.substring(0, index); @@ -94,12 +94,12 @@ public class ViewHierarchyLoader { loadProperties(lastNode, line); scene.addNode(lastNode); - + if (setRoot) { scene.setRoot(lastNode); setRoot = false; } - + if (!stack.isEmpty()) { final ViewNode parent = stack.peek(); final String edge = parent.name + lastNode.name; @@ -128,7 +128,7 @@ public class ViewHierarchyLoader { Exceptions.printStackTrace(ex); } } - + System.out.println("==> DONE"); return scene; @@ -165,7 +165,7 @@ public class ViewHierarchyLoader { int length = Integer.parseInt(data.substring(index + 1, index2)); start = index2 + 1 + length; property.value = data.substring(index2 + 1, index2 + 1 + length); - + node.properties.add(property); node.namedProperties.put(property.name, property); diff --git a/hierarchyviewer/src/com/android/hierarchyviewer/scene/ViewManager.java b/hierarchyviewer/src/com/android/hierarchyviewer/scene/ViewManager.java index 2b7efd6..df2a63e 100644 --- a/hierarchyviewer/src/com/android/hierarchyviewer/scene/ViewManager.java +++ b/hierarchyviewer/src/com/android/hierarchyviewer/scene/ViewManager.java @@ -16,7 +16,7 @@ package com.android.hierarchyviewer.scene; -import com.android.ddmlib.Device; +import com.android.ddmlib.IDevice; import com.android.hierarchyviewer.device.Window; import com.android.hierarchyviewer.device.DeviceBridge; @@ -27,15 +27,15 @@ import java.net.InetSocketAddress; import java.net.Socket; public class ViewManager { - public static void invalidate(Device device, Window window, String params) { + public static void invalidate(IDevice device, Window window, String params) { sendCommand("INVALIDATE", device, window, params); } - public static void requestLayout(Device device, Window window, String params) { + public static void requestLayout(IDevice device, Window window, String params) { sendCommand("REQUEST_LAYOUT", device, window, params); } - private static void sendCommand(String command, Device device, Window window, String params) { + private static void sendCommand(String command, IDevice device, Window window, String params) { Socket socket = null; BufferedWriter out = null; diff --git a/hierarchyviewer/src/com/android/hierarchyviewer/scene/WindowsLoader.java b/hierarchyviewer/src/com/android/hierarchyviewer/scene/WindowsLoader.java index 6c14cb6..ef93707 100644 --- a/hierarchyviewer/src/com/android/hierarchyviewer/scene/WindowsLoader.java +++ b/hierarchyviewer/src/com/android/hierarchyviewer/scene/WindowsLoader.java @@ -16,7 +16,7 @@ package com.android.hierarchyviewer.scene; -import com.android.ddmlib.Device; +import com.android.ddmlib.IDevice; import com.android.hierarchyviewer.device.DeviceBridge; import com.android.hierarchyviewer.device.Window; @@ -30,7 +30,7 @@ import java.net.Socket; import java.util.ArrayList; public class WindowsLoader { - public static Window[] loadWindows(Device device) { + public static Window[] loadWindows(IDevice device) { Socket socket = null; BufferedReader in = null; BufferedWriter out = null; diff --git a/hierarchyviewer/src/com/android/hierarchyviewer/ui/ScreenViewer.java b/hierarchyviewer/src/com/android/hierarchyviewer/ui/ScreenViewer.java index e4144b1..7c17c90 100644 --- a/hierarchyviewer/src/com/android/hierarchyviewer/ui/ScreenViewer.java +++ b/hierarchyviewer/src/com/android/hierarchyviewer/ui/ScreenViewer.java @@ -1,6 +1,6 @@ package com.android.hierarchyviewer.ui; -import com.android.ddmlib.Device; +import com.android.ddmlib.IDevice; import com.android.ddmlib.RawImage; import com.android.hierarchyviewer.util.WorkerThread; import com.android.hierarchyviewer.scene.ViewNode; @@ -51,14 +51,14 @@ import java.util.concurrent.ExecutionException; class ScreenViewer extends JPanel implements ActionListener { private final Workspace workspace; - private final Device device; + private final IDevice device; private GetScreenshotTask task; private BufferedImage image; private int[] scanline; private volatile boolean isLoading; - private BufferedImage overlay; + private BufferedImage overlay; private AlphaComposite overlayAlpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f); private ScreenViewer.LoupeStatus status; @@ -73,7 +73,7 @@ class ScreenViewer extends JPanel implements ActionListener { private JSlider zoomSlider; - ScreenViewer(Workspace workspace, Device device, int spacing) { + ScreenViewer(Workspace workspace, IDevice device, int spacing) { setLayout(new BorderLayout()); setOpaque(false); @@ -92,7 +92,7 @@ class ScreenViewer extends JPanel implements ActionListener { SwingUtilities.invokeLater(new Runnable() { public void run() { - timer.start(); + timer.start(); } }); } @@ -463,7 +463,7 @@ class ScreenViewer extends JPanel implements ActionListener { g.fillRect(0, 0, getWidth(), getHeight()); g.setColor(Color.WHITE); - g.drawRect(0, 0, getWidth() - 1, getHeight() - 1); + g.drawRect(0, 0, getWidth() - 1, getHeight() - 1); } } } diff --git a/hierarchyviewer/src/com/android/hierarchyviewer/ui/Workspace.java b/hierarchyviewer/src/com/android/hierarchyviewer/ui/Workspace.java index d530c35..1361243 100644 --- a/hierarchyviewer/src/com/android/hierarchyviewer/ui/Workspace.java +++ b/hierarchyviewer/src/com/android/hierarchyviewer/ui/Workspace.java @@ -17,7 +17,7 @@ package com.android.hierarchyviewer.ui; import com.android.ddmlib.AndroidDebugBridge; -import com.android.ddmlib.Device; +import com.android.ddmlib.IDevice; import com.android.hierarchyviewer.device.DeviceBridge; import com.android.hierarchyviewer.device.Window; import com.android.hierarchyviewer.laf.UnifiedContentBorder; @@ -147,7 +147,7 @@ public class Workspace extends JFrame { private DevicesTableModel devicesTableModel; private WindowsTableModel windowsTableModel; - private Device currentDevice; + private IDevice currentDevice; private Window currentWindow = Window.FOCUSED_WINDOW; private JButton displayNodeButton; @@ -235,7 +235,7 @@ public class Workspace extends JFrame { } devicesTableModel = new DevicesTableModel(); - for (Device device : DeviceBridge.getDevices()) { + for (IDevice device : DeviceBridge.getDevices()) { DeviceBridge.setupDeviceForward(device); devicesTableModel.addDevice(device); } @@ -289,7 +289,7 @@ public class Workspace extends JFrame { setVisibleRowCount(profilingTable, 5); firstTableScroller.setMinimumSize(profilingTable.getPreferredScrollableViewportSize()); - + JSplitPane tablesSplitter = new JSplitPane(); tablesSplitter.setBorder(null); tablesSplitter.setOrientation(JSplitPane.VERTICAL_SPLIT); @@ -522,7 +522,7 @@ public class Workspace extends JFrame { showDevicesMenuItem.setEnabled(false); viewMenu.add(showDevicesMenuItem); - menuBar.add(viewMenu); + menuBar.add(viewMenu); viewHierarchyMenu.setText("Hierarchy"); @@ -855,7 +855,7 @@ public class Workspace extends JFrame { public void showDevicesSelector() { if (mainSplitter != null) { if (pixelPerfectPanel != null) { - screenViewer.start(); + screenViewer.start(); } mainPanel.remove(graphViewButton.isSelected() ? mainSplitter : pixelPerfectPanel); mainPanel.add(deviceSelector, BorderLayout.CENTER); @@ -864,7 +864,7 @@ public class Workspace extends JFrame { hideStatusBarComponents(); - saveMenuItem.setEnabled(false); + saveMenuItem.setEnabled(false); showDevicesMenuItem.setEnabled(false); showDevicesButton.setEnabled(false); displayNodeButton.setEnabled(false); @@ -926,7 +926,7 @@ public class Workspace extends JFrame { } public void cleanupDevices() { - for (Device device : devicesTableModel.getDevices()) { + for (IDevice device : devicesTableModel.getDevices()) { DeviceBridge.removeDeviceForward(device); } } @@ -989,7 +989,7 @@ public class Workspace extends JFrame { return null; } return new CaptureNodeTask(); - } + } public SwingWorker<?, ?> startServer() { return new StartServerTask(); @@ -1232,7 +1232,7 @@ public class Workspace extends JFrame { @Override protected void done() { - endTask(); + endTask(); } } @@ -1293,10 +1293,10 @@ public class Workspace extends JFrame { private class DevicesTableModel extends DefaultTableModel implements AndroidDebugBridge.IDeviceChangeListener { - private ArrayList<Device> devices; + private ArrayList<IDevice> devices; private DevicesTableModel() { - devices = new ArrayList<Device>(); + devices = new ArrayList<IDevice>(); } @Override @@ -1320,7 +1320,7 @@ public class Workspace extends JFrame { } @WorkerThread - public void deviceConnected(final Device device) { + public void deviceConnected(final IDevice device) { DeviceBridge.setupDeviceForward(device); SwingUtilities.invokeLater(new Runnable() { @@ -1331,7 +1331,7 @@ public class Workspace extends JFrame { } @WorkerThread - public void deviceDisconnected(final Device device) { + public void deviceDisconnected(final IDevice device) { DeviceBridge.removeDeviceForward(device); SwingUtilities.invokeLater(new Runnable() { @@ -1341,14 +1341,14 @@ public class Workspace extends JFrame { }); } - public void addDevice(Device device) { + public void addDevice(IDevice device) { if (!devices.contains(device)) { devices.add(device); fireTableDataChanged(); } } - public void removeDevice(Device device) { + public void removeDevice(IDevice device) { if (device.equals(currentDevice)) { reset(); } @@ -1360,12 +1360,12 @@ public class Workspace extends JFrame { } @WorkerThread - public void deviceChanged(Device device, int changeMask) { - if ((changeMask & Device.CHANGE_STATE) != 0 && + public void deviceChanged(IDevice device, int changeMask) { + if ((changeMask & IDevice.CHANGE_STATE) != 0 && device.isOnline()) { // if the device state changed and it's now online, we set up its port forwarding. DeviceBridge.setupDeviceForward(device); - } else if (device == currentDevice && (changeMask & Device.CHANGE_CLIENT_LIST) != 0) { + } else if (device == currentDevice && (changeMask & IDevice.CHANGE_CLIENT_LIST) != 0) { // if the changed device is the current one and the client list changed, we update // the UI. loadWindows().execute(); @@ -1378,12 +1378,12 @@ public class Workspace extends JFrame { return devices == null ? 0 : devices.size(); } - public Device getDevice(int index) { + public IDevice getDevice(int index) { return index < devices.size() ? devices.get(index) : null; } - public Device[] getDevices() { - return devices.toArray(new Device[devices.size()]); + public IDevice[] getDevices() { + return devices.toArray(new IDevice[devices.size()]); } } @@ -1441,7 +1441,7 @@ public class Workspace extends JFrame { public void clear() { windows.clear(); - windows.add(Window.FOCUSED_WINDOW); + windows.add(Window.FOCUSED_WINDOW); } public Window getWindow(int index) { @@ -1462,7 +1462,7 @@ public class Workspace extends JFrame { if (currentDevice != null) { if (!DeviceBridge.isViewServerRunning(currentDevice)) { DeviceBridge.startViewServer(currentDevice); - checkForServerOnCurrentDevice(); + checkForServerOnCurrentDevice(); } loadWindows().execute(); windowsTableModel.setVisible(true); diff --git a/screenshot/src/com/android/screenshot/Screenshot.java b/screenshot/src/com/android/screenshot/Screenshot.java index 40ceffa..06e1f6b 100644 --- a/screenshot/src/com/android/screenshot/Screenshot.java +++ b/screenshot/src/com/android/screenshot/Screenshot.java @@ -17,7 +17,7 @@ package com.android.screenshot; import com.android.ddmlib.AndroidDebugBridge; -import com.android.ddmlib.Device; +import com.android.ddmlib.IDevice; import com.android.ddmlib.Log; import com.android.ddmlib.RawImage; import com.android.ddmlib.Log.ILogOutput; @@ -30,7 +30,7 @@ import java.io.IOException; import javax.imageio.ImageIO; /** - * Connects to a device using ddmlib and dumps its event log as long as the device is connected. + * Connects to a device using ddmlib and dumps its event log as long as the device is connected. */ public class Screenshot { @@ -40,7 +40,7 @@ public class Screenshot { String serial = null; String filepath = null; boolean landscape = false; - + if (args.length == 0) { printUsageAndQuit(); } @@ -69,7 +69,7 @@ public class Screenshot { if (device || emulator) { printAndExit("-s conflicts with -d and -e", false /* terminate */); } - + serial = args[index++]; } else if ("-l".equals(argument)) { landscape = true; @@ -83,11 +83,11 @@ public class Screenshot { } } } while (index < args.length); - + if (filepath == null) { printUsageAndQuit(); } - + Log.setLogOutput(new ILogOutput() { public void printAndPromptLog(LogLevel logLevel, String tag, String message) { System.err.println(logLevel.getStringValue() + ":" + tag + ":" + message); @@ -97,7 +97,7 @@ public class Screenshot { System.err.println(logLevel.getStringValue() + ":" + tag + ":" + message); } }); - + // init the lib // [try to] ensure ADB is running String adbLocation = System.getProperty("com.android.screenshot.bindir"); //$NON-NLS-1$ @@ -108,11 +108,11 @@ public class Screenshot { } AndroidDebugBridge.init(false /* debugger support */); - + try { AndroidDebugBridge bridge = AndroidDebugBridge.createBridge( adbLocation, true /* forceNewBridge */); - + // we can't just ask for the device list right away, as the internal thread getting // them from ADB may not be done getting the first list. // Since we don't really want getDevices() to be blocking, we wait here manually. @@ -124,7 +124,7 @@ public class Screenshot { } catch (InterruptedException e) { // pass } - + // let's not wait > 10 sec. if (count > 100) { System.err.println("Timeout getting device list!"); @@ -133,16 +133,16 @@ public class Screenshot { } // now get the devices - Device[] devices = bridge.getDevices(); - + IDevice[] devices = bridge.getDevices(); + if (devices.length == 0) { printAndExit("No devices found!", true /* terminate */); } - - Device target = null; - + + IDevice target = null; + if (emulator || device) { - for (Device d : devices) { + for (IDevice d : devices) { // this test works because emulator and device can't both be true at the same // time. if (d.isEmulator() == emulator) { @@ -159,7 +159,7 @@ public class Screenshot { } } } else if (serial != null) { - for (Device d : devices) { + for (IDevice d : devices) { if (serial.equals(d.getSerialNumber())) { target = d; break; @@ -172,7 +172,7 @@ public class Screenshot { } target = devices[0]; } - + if (target != null) { try { System.out.println("Taking screenshot from: " + target.getSerialNumber()); @@ -188,11 +188,11 @@ public class Screenshot { AndroidDebugBridge.terminate(); } } - + /* * Grab an image from an ADB-connected device. */ - private static void getDeviceImage(Device device, String filepath, boolean landscape) + private static void getDeviceImage(IDevice device, String filepath, boolean landscape) throws IOException { RawImage rawImage; @@ -209,28 +209,28 @@ public class Screenshot { return; assert rawImage.bpp == 16; - + BufferedImage image; - + if (landscape) { // convert raw data to an Image image = new BufferedImage(rawImage.height, rawImage.width, BufferedImage.TYPE_INT_ARGB); - + byte[] buffer = rawImage.data; int index = 0; for (int y = 0 ; y < rawImage.height ; y++) { for (int x = 0 ; x < rawImage.width ; x++) { - + int value = buffer[index++] & 0x00FF; value |= (buffer[index++] << 8) & 0x0FF00; - + int r = ((value >> 11) & 0x01F) << 3; int g = ((value >> 5) & 0x03F) << 2; int b = ((value >> 0) & 0x01F) << 3; - + value = 0xFF << 24 | r << 16 | g << 8 | b; - + image.setRGB(y, rawImage.width - x - 1, value); } } @@ -238,31 +238,31 @@ public class Screenshot { // convert raw data to an Image image = new BufferedImage(rawImage.width, rawImage.height, BufferedImage.TYPE_INT_ARGB); - + byte[] buffer = rawImage.data; int index = 0; for (int y = 0 ; y < rawImage.height ; y++) { for (int x = 0 ; x < rawImage.width ; x++) { - + int value = buffer[index++] & 0x00FF; value |= (buffer[index++] << 8) & 0x0FF00; - + int r = ((value >> 11) & 0x01F) << 3; int g = ((value >> 5) & 0x03F) << 2; int b = ((value >> 0) & 0x01F) << 3; - + value = 0xFF << 24 | r << 16 | g << 8 | b; - + image.setRGB(x, y, value); } } } - + if (!ImageIO.write(image, "png", new File(filepath))) { throw new IOException("Failed to find png writer"); } } - + private static void printUsageAndQuit() { // 80 cols marker: 01234567890123456789012345678901234567890123456789012345678901234567890123456789 System.out.println("Usage: screenshot2 [-d | -e | -s SERIAL] [-l] OUT_FILE"); @@ -273,10 +273,10 @@ public class Screenshot { System.out.println(""); System.out.println(" -l Rotate images for landscape mode."); System.out.println(""); - + System.exit(1); } - + private static void printAndExit(String message, boolean terminate) { System.out.println(message); if (terminate) { |