am 83674be9: Merge change 1699 into donut

Merge commit '83674be98d72991dc907cd47bd5a73c68c949c35'

* commit '83674be98d72991dc907cd47bd5a73c68c949c35':
  Make IDevice#getSyncService() throws an IOException.
This commit is contained in:
Android (Google) Code Review
2009-05-14 16:03:04 -07:00
committed by The Android Open Source Project
6 changed files with 177 additions and 171 deletions

View File

@@ -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() {

View File

@@ -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;

View File

@@ -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.

View File

@@ -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;
} }

View File

@@ -418,6 +418,7 @@ public class DeviceExplorer extends Panel {
} }
// download the files // download the files
try {
SyncService sync = mCurrentDevice.getSyncService(); SyncService sync = mCurrentDevice.getSyncService();
if (sync != null) { if (sync != null) {
ISyncProgressMonitor monitor = SyncService.getNullProgressMonitor(); ISyncProgressMonitor monitor = SyncService.getNullProgressMonitor();
@@ -474,6 +475,11 @@ public class DeviceExplorer extends Panel {
} 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,6 +673,7 @@ 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) {
try {
final SyncService sync = mCurrentDevice.getSyncService(); final SyncService sync = mCurrentDevice.getSyncService();
if (sync != null) { if (sync != null) {
// make a list of the FileEntry. // make a list of the FileEntry.
@@ -681,7 +688,6 @@ public class DeviceExplorer extends Panel {
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) {
try {
final SyncService sync = mCurrentDevice.getSyncService(); final SyncService sync = mCurrentDevice.getSyncService();
if (sync != null) { if (sync != null) {
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)
@@ -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) {
try {
final SyncService sync = mCurrentDevice.getSyncService(); final SyncService sync = mCurrentDevice.getSyncService();
if (sync != null) { if (sync != null) {
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)
@@ -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) {
try {
final SyncService sync = mCurrentDevice.getSyncService(); final SyncService sync = mCurrentDevice.getSyncService();
if (sync != null) { if (sync != null) {
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)
@@ -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());
} }
} }

View File

@@ -848,6 +848,7 @@ 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) {
try {
SyncService sync = device.getSyncService(); SyncService sync = device.getSyncService();
if (sync != null) { if (sync != null) {
IPath path = launchInfo.getPackageFile().getLocation(); IPath path = launchInfo.getPackageFile().getLocation();
@@ -898,12 +899,18 @@ public final class AndroidLaunchController implements IDebugBridgeChangeListener
} }
return installResult; return installResult;
} } else {
String msg = String.format( String msg = String.format(
"Failed to upload %1$s on device '%2$s': Unable to open sync connection!", "Failed to upload %1$s on device '%2$s': Unable to open sync connection!",
launchInfo.getPackageFile().getName(), device.getSerialNumber()); launchInfo.getPackageFile().getName(), device.getSerialNumber());
AdtPlugin.printErrorToConsole(launchInfo.getProject(), msg); AdtPlugin.printErrorToConsole(launchInfo.getProject(), msg);
}
} catch (IOException e) {
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, e.getMessage());
}
return false; return false;
} }