Merge change 1699 into donut
* changes: Make IDevice#getSyncService() throws an IOException.
This commit is contained in:
@@ -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)}.
|
||||||
*/
|
*/
|
||||||
@@ -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() {
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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