am 83674be9: Merge change 1699 into donut
Merge commit '83674be98d72991dc907cd47bd5a73c68c949c35' * commit '83674be98d72991dc907cd47bd5a73c68c949c35': Make IDevice#getSyncService() throws an IOException.
This commit is contained in:
committed by
The Android Open Source Project
commit
91d128f0f0
@@ -37,7 +37,7 @@ import java.util.regex.Pattern;
|
|||||||
* <p/><b>{@link #init(boolean)} must be called before anything is done.</b>
|
* <p/><b>{@link #init(boolean)} must be called before anything is done.</b>
|
||||||
*/
|
*/
|
||||||
public final class AndroidDebugBridge {
|
public final class AndroidDebugBridge {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Minimum and maximum version of adb supported. This correspond to
|
* Minimum and maximum version of adb supported. This correspond to
|
||||||
* ADB_SERVER_VERSION found in //device/tools/adb/adb.h
|
* ADB_SERVER_VERSION found in //device/tools/adb/adb.h
|
||||||
@@ -48,7 +48,7 @@ public final class AndroidDebugBridge {
|
|||||||
|
|
||||||
private final static Pattern sAdbVersion = Pattern.compile(
|
private final static Pattern sAdbVersion = Pattern.compile(
|
||||||
"^.*(\\d+)\\.(\\d+)\\.(\\d+)$"); //$NON-NLS-1$
|
"^.*(\\d+)\\.(\\d+)\\.(\\d+)$"); //$NON-NLS-1$
|
||||||
|
|
||||||
private final static String ADB = "adb"; //$NON-NLS-1$
|
private final static String ADB = "adb"; //$NON-NLS-1$
|
||||||
private final static String DDMS = "ddms"; //$NON-NLS-1$
|
private final static String DDMS = "ddms"; //$NON-NLS-1$
|
||||||
|
|
||||||
@@ -212,7 +212,7 @@ public final class AndroidDebugBridge {
|
|||||||
monitorThread.quit();
|
monitorThread.quit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether the ddmlib is setup to support monitoring and interacting with
|
* 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 Device}s.
|
||||||
@@ -220,7 +220,7 @@ public final class AndroidDebugBridge {
|
|||||||
static boolean getClientSupport() {
|
static boolean getClientSupport() {
|
||||||
return sClientSupport;
|
return sClientSupport;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a {@link AndroidDebugBridge} that is not linked to any particular executable.
|
* Creates a {@link AndroidDebugBridge} that is not linked to any particular executable.
|
||||||
* <p/>This bridge will expect adb to be running. It will not be able to start/stop/restart
|
* <p/>This bridge will expect adb to be running. It will not be able to start/stop/restart
|
||||||
@@ -325,6 +325,7 @@ public final class AndroidDebugBridge {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Disconnects the current debug bridge, and destroy the object.
|
* Disconnects the current debug bridge, and destroy the object.
|
||||||
|
* <p/>This also stops the current adb host server.
|
||||||
* <p/>
|
* <p/>
|
||||||
* A new object will have to be created with {@link #createBridge(String, boolean)}.
|
* A new object will have to be created with {@link #createBridge(String, boolean)}.
|
||||||
*/
|
*/
|
||||||
@@ -454,21 +455,21 @@ public final class AndroidDebugBridge {
|
|||||||
|
|
||||||
return new Device[0];
|
return new Device[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether the bridge has acquired the initial list from adb after being created.
|
* 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
|
* <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
|
* 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 Device} list has been
|
||||||
* built before the call to {@link #getDevices()}.
|
* 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 Device} objects is to create a
|
||||||
* {@link IDeviceChangeListener} object.
|
* {@link IDeviceChangeListener} object.
|
||||||
*/
|
*/
|
||||||
public boolean hasInitialDeviceList() {
|
public boolean hasInitialDeviceList() {
|
||||||
if (mDeviceMonitor != null) {
|
if (mDeviceMonitor != null) {
|
||||||
return mDeviceMonitor.hasInitialDeviceList();
|
return mDeviceMonitor.hasInitialDeviceList();
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -515,7 +516,7 @@ public final class AndroidDebugBridge {
|
|||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new bridge.
|
* Creates a new bridge.
|
||||||
* @param osLocation the location of the command line tool
|
* @param osLocation the location of the command line tool
|
||||||
@@ -529,7 +530,7 @@ public final class AndroidDebugBridge {
|
|||||||
|
|
||||||
checkAdbVersion();
|
checkAdbVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new bridge not linked to any particular adb executable.
|
* Creates a new bridge not linked to any particular adb executable.
|
||||||
*/
|
*/
|
||||||
@@ -591,7 +592,7 @@ public final class AndroidDebugBridge {
|
|||||||
Log.logAndDisplay(LogLevel.ERROR, ADB,
|
Log.logAndDisplay(LogLevel.ERROR, ADB,
|
||||||
"Failed to parse the output of 'adb version'"); //$NON-NLS-1$
|
"Failed to parse the output of 'adb version'"); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.logAndDisplay(LogLevel.ERROR, ADB,
|
Log.logAndDisplay(LogLevel.ERROR, ADB,
|
||||||
"Failed to get the adb version: " + e.getMessage()); //$NON-NLS-1$
|
"Failed to get the adb version: " + e.getMessage()); //$NON-NLS-1$
|
||||||
@@ -609,7 +610,7 @@ public final class AndroidDebugBridge {
|
|||||||
* <p/>
|
* <p/>
|
||||||
* Returns true when a version number has been found so that we can stop scanning,
|
* Returns true when a version number has been found so that we can stop scanning,
|
||||||
* whether the version number is in the acceptable range or not.
|
* whether the version number is in the acceptable range or not.
|
||||||
*
|
*
|
||||||
* @param line The line to scan.
|
* @param line The line to scan.
|
||||||
* @return True if a version number was found (whether it is acceptable or not).
|
* @return True if a version number was found (whether it is acceptable or not).
|
||||||
*/
|
*/
|
||||||
@@ -666,7 +667,7 @@ public final class AndroidDebugBridge {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Kills the debug bridge.
|
* Kills the debug bridge, and the adb host server.
|
||||||
* @return true if success
|
* @return true if success
|
||||||
*/
|
*/
|
||||||
boolean stop() {
|
boolean stop() {
|
||||||
@@ -740,7 +741,7 @@ public final class AndroidDebugBridge {
|
|||||||
listenersCopy = sDeviceListeners.toArray(
|
listenersCopy = sDeviceListeners.toArray(
|
||||||
new IDeviceChangeListener[sDeviceListeners.size()]);
|
new IDeviceChangeListener[sDeviceListeners.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Notify the listeners
|
// Notify the listeners
|
||||||
for (IDeviceChangeListener listener : listenersCopy) {
|
for (IDeviceChangeListener listener : listenersCopy) {
|
||||||
// we attempt to catch any exception so that a bad listener doesn't kill our
|
// we attempt to catch any exception so that a bad listener doesn't kill our
|
||||||
@@ -776,7 +777,7 @@ public final class AndroidDebugBridge {
|
|||||||
listenersCopy = sDeviceListeners.toArray(
|
listenersCopy = sDeviceListeners.toArray(
|
||||||
new IDeviceChangeListener[sDeviceListeners.size()]);
|
new IDeviceChangeListener[sDeviceListeners.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Notify the listeners
|
// Notify the listeners
|
||||||
for (IDeviceChangeListener listener : listenersCopy) {
|
for (IDeviceChangeListener listener : listenersCopy) {
|
||||||
// we attempt to catch any exception so that a bad listener doesn't kill our
|
// we attempt to catch any exception so that a bad listener doesn't kill our
|
||||||
@@ -812,7 +813,7 @@ public final class AndroidDebugBridge {
|
|||||||
listenersCopy = sDeviceListeners.toArray(
|
listenersCopy = sDeviceListeners.toArray(
|
||||||
new IDeviceChangeListener[sDeviceListeners.size()]);
|
new IDeviceChangeListener[sDeviceListeners.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Notify the listeners
|
// Notify the listeners
|
||||||
for (IDeviceChangeListener listener : listenersCopy) {
|
for (IDeviceChangeListener listener : listenersCopy) {
|
||||||
// we attempt to catch any exception so that a bad listener doesn't kill our
|
// we attempt to catch any exception so that a bad listener doesn't kill our
|
||||||
@@ -848,7 +849,7 @@ public final class AndroidDebugBridge {
|
|||||||
synchronized (sLock) {
|
synchronized (sLock) {
|
||||||
listenersCopy = sClientListeners.toArray(
|
listenersCopy = sClientListeners.toArray(
|
||||||
new IClientChangeListener[sClientListeners.size()]);
|
new IClientChangeListener[sClientListeners.size()]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Notify the listeners
|
// Notify the listeners
|
||||||
@@ -962,7 +963,7 @@ public final class AndroidDebugBridge {
|
|||||||
* @param errorOutput The array to store the stderr output. cannot be null.
|
* @param errorOutput The array to store the stderr output. cannot be null.
|
||||||
* @param stdOutput The array to store the stdout output. cannot be null.
|
* @param stdOutput The array to store the stdout output. cannot be null.
|
||||||
* @param displayStdOut If true this will display stdout as well
|
* @param displayStdOut If true this will display stdout as well
|
||||||
* @param waitforReaders if true, this will wait for the reader threads.
|
* @param waitforReaders if true, this will wait for the reader threads.
|
||||||
* @return the process return code.
|
* @return the process return code.
|
||||||
* @throws InterruptedException
|
* @throws InterruptedException
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -208,7 +208,7 @@ public final class Device implements IDevice {
|
|||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
* @see com.android.ddmlib.IDevice#getSyncService()
|
* @see com.android.ddmlib.IDevice#getSyncService()
|
||||||
*/
|
*/
|
||||||
public SyncService getSyncService() {
|
public SyncService getSyncService() throws IOException {
|
||||||
SyncService syncService = new SyncService(AndroidDebugBridge.sSocketAddr, this);
|
SyncService syncService = new SyncService(AndroidDebugBridge.sSocketAddr, this);
|
||||||
if (syncService.openSync()) {
|
if (syncService.openSync()) {
|
||||||
return syncService;
|
return syncService;
|
||||||
|
|||||||
@@ -118,9 +118,11 @@ public interface IDevice {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a {@link SyncService} object to push / pull files to and from the device.
|
* Returns a {@link SyncService} object to push / pull files to and from the device.
|
||||||
* @return <code>null</code> if the SyncService couldn't be created.
|
* @return <code>null</code> if the SyncService couldn't be created. This can happen if abd
|
||||||
|
* refuse to open the connection because the {@link IDevice} is invalid (or got disconnected).
|
||||||
|
* @throws IOException if the connection with adb failed.
|
||||||
*/
|
*/
|
||||||
public SyncService getSyncService();
|
public SyncService getSyncService() throws IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a {@link FileListingService} for this device.
|
* Returns a {@link FileListingService} for this device.
|
||||||
|
|||||||
@@ -209,9 +209,11 @@ public final class SyncService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Opens the sync connection. This must be called before any calls to push[File] / pull[File].
|
* Opens the sync connection. This must be called before any calls to push[File] / pull[File].
|
||||||
* @return true if the connection opened, false otherwise.
|
* @return true if the connection opened, false if adb refuse the connection. This can happen
|
||||||
|
* if the {@link Device} is invalid.
|
||||||
|
* @throws IOException If the connection to adb failed.
|
||||||
*/
|
*/
|
||||||
boolean openSync() {
|
boolean openSync() throws IOException {
|
||||||
try {
|
try {
|
||||||
mChannel = SocketChannel.open(mAddress);
|
mChannel = SocketChannel.open(mAddress);
|
||||||
mChannel.configureBlocking(false);
|
mChannel.configureBlocking(false);
|
||||||
@@ -236,13 +238,15 @@ public final class SyncService {
|
|||||||
if (mChannel != null) {
|
if (mChannel != null) {
|
||||||
try {
|
try {
|
||||||
mChannel.close();
|
mChannel.close();
|
||||||
} catch (IOException e1) {
|
} catch (IOException e2) {
|
||||||
// we do nothing, since we'll return false just below
|
// we want to throw the original exception, so we ignore this one.
|
||||||
}
|
}
|
||||||
mChannel = null;
|
mChannel = null;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -374,13 +374,13 @@ public class DeviceExplorer extends Panel {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}.start();
|
}.start();
|
||||||
|
|
||||||
return mTree;
|
return mTree;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void postCreation() {
|
protected void postCreation() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -418,61 +418,67 @@ public class DeviceExplorer extends Panel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// download the files
|
// download the files
|
||||||
SyncService sync = mCurrentDevice.getSyncService();
|
try {
|
||||||
if (sync != null) {
|
SyncService sync = mCurrentDevice.getSyncService();
|
||||||
ISyncProgressMonitor monitor = SyncService.getNullProgressMonitor();
|
if (sync != null) {
|
||||||
SyncResult result = sync.pullFile(keyEntry, keyFile.getAbsolutePath(), monitor);
|
ISyncProgressMonitor monitor = SyncService.getNullProgressMonitor();
|
||||||
if (result.getCode() != SyncService.RESULT_OK) {
|
SyncResult result = sync.pullFile(keyEntry, keyFile.getAbsolutePath(), monitor);
|
||||||
DdmConsole.printErrorToConsole(String.format(
|
if (result.getCode() != SyncService.RESULT_OK) {
|
||||||
"Failed to pull %1$s: %2$s", keyEntry.getName(), result.getMessage()));
|
DdmConsole.printErrorToConsole(String.format(
|
||||||
return;
|
"Failed to pull %1$s: %2$s", keyEntry.getName(), result.getMessage()));
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
result = sync.pullFile(dataEntry, dataFile.getAbsolutePath(), monitor);
|
result = sync.pullFile(dataEntry, dataFile.getAbsolutePath(), monitor);
|
||||||
if (result.getCode() != SyncService.RESULT_OK) {
|
if (result.getCode() != SyncService.RESULT_OK) {
|
||||||
DdmConsole.printErrorToConsole(String.format(
|
DdmConsole.printErrorToConsole(String.format(
|
||||||
"Failed to pull %1$s: %2$s", dataEntry.getName(), result.getMessage()));
|
"Failed to pull %1$s: %2$s", dataEntry.getName(), result.getMessage()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// now that we have the file, we need to launch traceview
|
// now that we have the file, we need to launch traceview
|
||||||
String[] command = new String[2];
|
String[] command = new String[2];
|
||||||
command[0] = DdmUiPreferences.getTraceview();
|
command[0] = DdmUiPreferences.getTraceview();
|
||||||
command[1] = path + File.separator + baseName;
|
command[1] = path + File.separator + baseName;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final Process p = Runtime.getRuntime().exec(command);
|
final Process p = Runtime.getRuntime().exec(command);
|
||||||
|
|
||||||
// create a thread for the output
|
// create a thread for the output
|
||||||
new Thread("Traceview output") {
|
new Thread("Traceview output") {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
// create a buffer to read the stderr output
|
// create a buffer to read the stderr output
|
||||||
InputStreamReader is = new InputStreamReader(p.getErrorStream());
|
InputStreamReader is = new InputStreamReader(p.getErrorStream());
|
||||||
BufferedReader resultReader = new BufferedReader(is);
|
BufferedReader resultReader = new BufferedReader(is);
|
||||||
|
|
||||||
// read the lines as they come. if null is returned, it's
|
// read the lines as they come. if null is returned, it's
|
||||||
// because the process finished
|
// because the process finished
|
||||||
try {
|
try {
|
||||||
while (true) {
|
while (true) {
|
||||||
String line = resultReader.readLine();
|
String line = resultReader.readLine();
|
||||||
if (line != null) {
|
if (line != null) {
|
||||||
DdmConsole.printErrorToConsole("Traceview: " + line);
|
DdmConsole.printErrorToConsole("Traceview: " + line);
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
// get the return code from the process
|
||||||
|
p.waitFor();
|
||||||
|
} catch (IOException e) {
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
|
||||||
}
|
}
|
||||||
// get the return code from the process
|
|
||||||
p.waitFor();
|
|
||||||
} catch (IOException e) {
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}.start();
|
||||||
}.start();
|
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
DdmConsole.printErrorToConsole(String.format(
|
||||||
|
"Failed to pull %1$s: %2$s", keyEntry.getName(), e.getMessage()));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -667,21 +673,21 @@ public class DeviceExplorer extends Panel {
|
|||||||
* @param localDirector the local directory in which to save the files.
|
* @param localDirector the local directory in which to save the files.
|
||||||
*/
|
*/
|
||||||
private void pullSelection(TreeItem[] items, final String localDirectory) {
|
private void pullSelection(TreeItem[] items, final String localDirectory) {
|
||||||
final SyncService sync = mCurrentDevice.getSyncService();
|
try {
|
||||||
if (sync != null) {
|
final SyncService sync = mCurrentDevice.getSyncService();
|
||||||
// make a list of the FileEntry.
|
if (sync != null) {
|
||||||
ArrayList<FileEntry> entries = new ArrayList<FileEntry>();
|
// make a list of the FileEntry.
|
||||||
for (TreeItem item : items) {
|
ArrayList<FileEntry> entries = new ArrayList<FileEntry>();
|
||||||
Object data = item.getData();
|
for (TreeItem item : items) {
|
||||||
if (data instanceof FileEntry) {
|
Object data = item.getData();
|
||||||
entries.add((FileEntry)data);
|
if (data instanceof FileEntry) {
|
||||||
|
entries.add((FileEntry)data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
final FileEntry[] entryArray = entries.toArray(
|
||||||
final FileEntry[] entryArray = entries.toArray(
|
new FileEntry[entries.size()]);
|
||||||
new FileEntry[entries.size()]);
|
|
||||||
|
|
||||||
// get a progressdialog
|
// get a progressdialog
|
||||||
try {
|
|
||||||
new ProgressMonitorDialog(mParent.getShell()).run(true, true,
|
new ProgressMonitorDialog(mParent.getShell()).run(true, true,
|
||||||
new IRunnableWithProgress() {
|
new IRunnableWithProgress() {
|
||||||
public void run(IProgressMonitor monitor)
|
public void run(IProgressMonitor monitor)
|
||||||
@@ -699,13 +705,10 @@ public class DeviceExplorer extends Panel {
|
|||||||
sync.close();
|
sync.close();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (InvocationTargetException e) {
|
|
||||||
DdmConsole.printErrorToConsole( "Failed to pull selection");
|
|
||||||
DdmConsole.printErrorToConsole(e.getMessage());
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
DdmConsole.printErrorToConsole("Failed to pull selection");
|
|
||||||
DdmConsole.printErrorToConsole(e.getMessage());
|
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
DdmConsole.printErrorToConsole( "Failed to pull selection");
|
||||||
|
DdmConsole.printErrorToConsole(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -715,9 +718,9 @@ public class DeviceExplorer extends Panel {
|
|||||||
* @param local the destination filepath
|
* @param local the destination filepath
|
||||||
*/
|
*/
|
||||||
private void pullFile(final FileEntry remote, final String local) {
|
private void pullFile(final FileEntry remote, final String local) {
|
||||||
final SyncService sync = mCurrentDevice.getSyncService();
|
try {
|
||||||
if (sync != null) {
|
final SyncService sync = mCurrentDevice.getSyncService();
|
||||||
try {
|
if (sync != null) {
|
||||||
new ProgressMonitorDialog(mParent.getShell()).run(true, true,
|
new ProgressMonitorDialog(mParent.getShell()).run(true, true,
|
||||||
new IRunnableWithProgress() {
|
new IRunnableWithProgress() {
|
||||||
public void run(IProgressMonitor monitor)
|
public void run(IProgressMonitor monitor)
|
||||||
@@ -734,13 +737,10 @@ public class DeviceExplorer extends Panel {
|
|||||||
sync.close();
|
sync.close();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (InvocationTargetException e) {
|
|
||||||
DdmConsole.printErrorToConsole( "Failed to pull selection");
|
|
||||||
DdmConsole.printErrorToConsole(e.getMessage());
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
DdmConsole.printErrorToConsole("Failed to pull selection");
|
|
||||||
DdmConsole.printErrorToConsole(e.getMessage());
|
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
DdmConsole.printErrorToConsole( "Failed to pull selection");
|
||||||
|
DdmConsole.printErrorToConsole(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -750,9 +750,9 @@ public class DeviceExplorer extends Panel {
|
|||||||
* @param remoteDirectory
|
* @param remoteDirectory
|
||||||
*/
|
*/
|
||||||
private void pushFiles(final String[] localFiles, final FileEntry remoteDirectory) {
|
private void pushFiles(final String[] localFiles, final FileEntry remoteDirectory) {
|
||||||
final SyncService sync = mCurrentDevice.getSyncService();
|
try {
|
||||||
if (sync != null) {
|
final SyncService sync = mCurrentDevice.getSyncService();
|
||||||
try {
|
if (sync != null) {
|
||||||
new ProgressMonitorDialog(mParent.getShell()).run(true, true,
|
new ProgressMonitorDialog(mParent.getShell()).run(true, true,
|
||||||
new IRunnableWithProgress() {
|
new IRunnableWithProgress() {
|
||||||
public void run(IProgressMonitor monitor)
|
public void run(IProgressMonitor monitor)
|
||||||
@@ -769,14 +769,10 @@ public class DeviceExplorer extends Panel {
|
|||||||
sync.close();
|
sync.close();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (InvocationTargetException e) {
|
|
||||||
DdmConsole.printErrorToConsole("Failed to push the items");
|
|
||||||
DdmConsole.printErrorToConsole(e.getMessage());
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
DdmConsole.printErrorToConsole("Failed to push the items");
|
|
||||||
DdmConsole.printErrorToConsole(e.getMessage());
|
|
||||||
}
|
}
|
||||||
return;
|
} catch (Exception e) {
|
||||||
|
DdmConsole.printErrorToConsole("Failed to push the items");
|
||||||
|
DdmConsole.printErrorToConsole(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -786,9 +782,9 @@ public class DeviceExplorer extends Panel {
|
|||||||
* @param remoteDirectory the remote destination directory on the device
|
* @param remoteDirectory the remote destination directory on the device
|
||||||
*/
|
*/
|
||||||
private void pushFile(final String local, final String remoteDirectory) {
|
private void pushFile(final String local, final String remoteDirectory) {
|
||||||
final SyncService sync = mCurrentDevice.getSyncService();
|
try {
|
||||||
if (sync != null) {
|
final SyncService sync = mCurrentDevice.getSyncService();
|
||||||
try {
|
if (sync != null) {
|
||||||
new ProgressMonitorDialog(mParent.getShell()).run(true, true,
|
new ProgressMonitorDialog(mParent.getShell()).run(true, true,
|
||||||
new IRunnableWithProgress() {
|
new IRunnableWithProgress() {
|
||||||
public void run(IProgressMonitor monitor)
|
public void run(IProgressMonitor monitor)
|
||||||
@@ -812,14 +808,10 @@ public class DeviceExplorer extends Panel {
|
|||||||
sync.close();
|
sync.close();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (InvocationTargetException e) {
|
|
||||||
DdmConsole.printErrorToConsole("Failed to push the item(s).");
|
|
||||||
DdmConsole.printErrorToConsole(e.getMessage());
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
DdmConsole.printErrorToConsole("Failed to push the item(s).");
|
|
||||||
DdmConsole.printErrorToConsole(e.getMessage());
|
|
||||||
}
|
}
|
||||||
return;
|
} catch (Exception e) {
|
||||||
|
DdmConsole.printErrorToConsole("Failed to push the item(s).");
|
||||||
|
DdmConsole.printErrorToConsole(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -848,63 +848,70 @@ public final class AndroidLaunchController implements IDebugBridgeChangeListener
|
|||||||
* @return true if the install succeeded.
|
* @return true if the install succeeded.
|
||||||
*/
|
*/
|
||||||
private boolean doSyncApp(DelayedLaunchInfo launchInfo, IDevice device) {
|
private boolean doSyncApp(DelayedLaunchInfo launchInfo, IDevice device) {
|
||||||
SyncService sync = device.getSyncService();
|
try {
|
||||||
if (sync != null) {
|
SyncService sync = device.getSyncService();
|
||||||
IPath path = launchInfo.getPackageFile().getLocation();
|
if (sync != null) {
|
||||||
String message = String.format("Uploading %1$s onto device '%2$s'",
|
IPath path = launchInfo.getPackageFile().getLocation();
|
||||||
path.lastSegment(), device.getSerialNumber());
|
String message = String.format("Uploading %1$s onto device '%2$s'",
|
||||||
AdtPlugin.printToConsole(launchInfo.getProject(), message);
|
path.lastSegment(), device.getSerialNumber());
|
||||||
|
AdtPlugin.printToConsole(launchInfo.getProject(), message);
|
||||||
|
|
||||||
String osLocalPath = path.toOSString();
|
String osLocalPath = path.toOSString();
|
||||||
String apkName = launchInfo.getPackageFile().getName();
|
String apkName = launchInfo.getPackageFile().getName();
|
||||||
String remotePath = "/data/local/tmp/" + apkName; //$NON-NLS-1$
|
String remotePath = "/data/local/tmp/" + apkName; //$NON-NLS-1$
|
||||||
|
|
||||||
SyncResult result = sync.pushFile(osLocalPath, remotePath,
|
SyncResult result = sync.pushFile(osLocalPath, remotePath,
|
||||||
SyncService.getNullProgressMonitor());
|
SyncService.getNullProgressMonitor());
|
||||||
|
|
||||||
if (result.getCode() != SyncService.RESULT_OK) {
|
if (result.getCode() != SyncService.RESULT_OK) {
|
||||||
String msg = String.format("Failed to upload %1$s on '%2$s': %3$s",
|
String msg = String.format("Failed to upload %1$s on '%2$s': %3$s",
|
||||||
apkName, device.getSerialNumber(), result.getMessage());
|
apkName, device.getSerialNumber(), result.getMessage());
|
||||||
|
AdtPlugin.printErrorToConsole(launchInfo.getProject(), msg);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now that the package is uploaded, we can install it properly.
|
||||||
|
// This will check that there isn't another apk declaring the same package, or
|
||||||
|
// that another install used a different key.
|
||||||
|
boolean installResult = installPackage(launchInfo, remotePath, device);
|
||||||
|
|
||||||
|
// now we delete the app we sync'ed
|
||||||
|
try {
|
||||||
|
device.executeShellCommand("rm " + remotePath, new MultiLineReceiver() { //$NON-NLS-1$
|
||||||
|
@Override
|
||||||
|
public void processNewLines(String[] lines) {
|
||||||
|
// pass
|
||||||
|
}
|
||||||
|
public boolean isCancelled() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (IOException e) {
|
||||||
|
AdtPlugin.printErrorToConsole(launchInfo.getProject(), String.format(
|
||||||
|
"Failed to delete temporary package: %1$s", e.getMessage()));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if the installation succeeded, we register it.
|
||||||
|
if (installResult) {
|
||||||
|
ApkInstallManager.getInstance().registerInstallation(
|
||||||
|
launchInfo.getProject(), device);
|
||||||
|
}
|
||||||
|
|
||||||
|
return installResult;
|
||||||
|
} else {
|
||||||
|
String msg = String.format(
|
||||||
|
"Failed to upload %1$s on device '%2$s': Unable to open sync connection!",
|
||||||
|
launchInfo.getPackageFile().getName(), device.getSerialNumber());
|
||||||
AdtPlugin.printErrorToConsole(launchInfo.getProject(), msg);
|
AdtPlugin.printErrorToConsole(launchInfo.getProject(), msg);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
// Now that the package is uploaded, we can install it properly.
|
String msg = String.format(
|
||||||
// This will check that there isn't another apk declaring the same package, or
|
"Failed to upload %1$s on device '%2$s': Unable to open sync connection!",
|
||||||
// that another install used a different key.
|
launchInfo.getPackageFile().getName(), device.getSerialNumber());
|
||||||
boolean installResult = installPackage(launchInfo, remotePath, device);
|
AdtPlugin.printErrorToConsole(launchInfo.getProject(), msg, e.getMessage());
|
||||||
|
|
||||||
// now we delete the app we sync'ed
|
|
||||||
try {
|
|
||||||
device.executeShellCommand("rm " + remotePath, new MultiLineReceiver() { //$NON-NLS-1$
|
|
||||||
@Override
|
|
||||||
public void processNewLines(String[] lines) {
|
|
||||||
// pass
|
|
||||||
}
|
|
||||||
public boolean isCancelled() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} catch (IOException e) {
|
|
||||||
AdtPlugin.printErrorToConsole(launchInfo.getProject(), String.format(
|
|
||||||
"Failed to delete temporary package: %1$s", e.getMessage()));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// if the installation succeeded, we register it.
|
|
||||||
if (installResult) {
|
|
||||||
ApkInstallManager.getInstance().registerInstallation(
|
|
||||||
launchInfo.getProject(), device);
|
|
||||||
}
|
|
||||||
|
|
||||||
return installResult;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String msg = String.format(
|
|
||||||
"Failed to upload %1$s on device '%2$s': Unable to open sync connection!",
|
|
||||||
launchInfo.getPackageFile().getName(), device.getSerialNumber());
|
|
||||||
AdtPlugin.printErrorToConsole(launchInfo.getProject(), msg);
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user