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
@@ -325,6 +325,7 @@ public final class AndroidDebugBridge {
|
||||
|
||||
/**
|
||||
* Disconnects the current debug bridge, and destroy the object.
|
||||
* <p/>This also stops the current adb host server.
|
||||
* <p/>
|
||||
* 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
|
||||
*/
|
||||
boolean stop() {
|
||||
|
||||
@@ -208,7 +208,7 @@ public final class Device implements IDevice {
|
||||
* (non-Javadoc)
|
||||
* @see com.android.ddmlib.IDevice#getSyncService()
|
||||
*/
|
||||
public SyncService getSyncService() {
|
||||
public SyncService getSyncService() throws IOException {
|
||||
SyncService syncService = new SyncService(AndroidDebugBridge.sSocketAddr, this);
|
||||
if (syncService.openSync()) {
|
||||
return syncService;
|
||||
|
||||
@@ -118,9 +118,11 @@ public interface IDevice {
|
||||
|
||||
/**
|
||||
* 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.
|
||||
|
||||
@@ -209,9 +209,11 @@ public final class SyncService {
|
||||
|
||||
/**
|
||||
* 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 {
|
||||
mChannel = SocketChannel.open(mAddress);
|
||||
mChannel.configureBlocking(false);
|
||||
@@ -236,13 +238,15 @@ public final class SyncService {
|
||||
if (mChannel != null) {
|
||||
try {
|
||||
mChannel.close();
|
||||
} catch (IOException e1) {
|
||||
// we do nothing, since we'll return false just below
|
||||
} catch (IOException e2) {
|
||||
// we want to throw the original exception, so we ignore this one.
|
||||
}
|
||||
mChannel = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
throw e;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -418,6 +418,7 @@ public class DeviceExplorer extends Panel {
|
||||
}
|
||||
|
||||
// download the files
|
||||
try {
|
||||
SyncService sync = mCurrentDevice.getSyncService();
|
||||
if (sync != null) {
|
||||
ISyncProgressMonitor monitor = SyncService.getNullProgressMonitor();
|
||||
@@ -474,6 +475,11 @@ public class DeviceExplorer extends Panel {
|
||||
} 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.
|
||||
*/
|
||||
private void pullSelection(TreeItem[] items, final String localDirectory) {
|
||||
try {
|
||||
final SyncService sync = mCurrentDevice.getSyncService();
|
||||
if (sync != null) {
|
||||
// make a list of the FileEntry.
|
||||
@@ -681,7 +688,6 @@ public class DeviceExplorer extends Panel {
|
||||
new FileEntry[entries.size()]);
|
||||
|
||||
// get a progressdialog
|
||||
try {
|
||||
new ProgressMonitorDialog(mParent.getShell()).run(true, true,
|
||||
new IRunnableWithProgress() {
|
||||
public void run(IProgressMonitor monitor)
|
||||
@@ -699,13 +705,10 @@ public class DeviceExplorer extends Panel {
|
||||
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
|
||||
*/
|
||||
private void pullFile(final FileEntry remote, final String local) {
|
||||
try {
|
||||
final SyncService sync = mCurrentDevice.getSyncService();
|
||||
if (sync != null) {
|
||||
try {
|
||||
new ProgressMonitorDialog(mParent.getShell()).run(true, true,
|
||||
new IRunnableWithProgress() {
|
||||
public void run(IProgressMonitor monitor)
|
||||
@@ -734,13 +737,10 @@ public class DeviceExplorer extends Panel {
|
||||
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
|
||||
*/
|
||||
private void pushFiles(final String[] localFiles, final FileEntry remoteDirectory) {
|
||||
try {
|
||||
final SyncService sync = mCurrentDevice.getSyncService();
|
||||
if (sync != null) {
|
||||
try {
|
||||
new ProgressMonitorDialog(mParent.getShell()).run(true, true,
|
||||
new IRunnableWithProgress() {
|
||||
public void run(IProgressMonitor monitor)
|
||||
@@ -769,14 +769,10 @@ public class DeviceExplorer extends Panel {
|
||||
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
|
||||
*/
|
||||
private void pushFile(final String local, final String remoteDirectory) {
|
||||
try {
|
||||
final SyncService sync = mCurrentDevice.getSyncService();
|
||||
if (sync != null) {
|
||||
try {
|
||||
new ProgressMonitorDialog(mParent.getShell()).run(true, true,
|
||||
new IRunnableWithProgress() {
|
||||
public void run(IProgressMonitor monitor)
|
||||
@@ -812,14 +808,10 @@ public class DeviceExplorer extends Panel {
|
||||
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,6 +848,7 @@ public final class AndroidLaunchController implements IDebugBridgeChangeListener
|
||||
* @return true if the install succeeded.
|
||||
*/
|
||||
private boolean doSyncApp(DelayedLaunchInfo launchInfo, IDevice device) {
|
||||
try {
|
||||
SyncService sync = device.getSyncService();
|
||||
if (sync != null) {
|
||||
IPath path = launchInfo.getPackageFile().getLocation();
|
||||
@@ -898,12 +899,18 @@ public final class AndroidLaunchController implements IDebugBridgeChangeListener
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
} 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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user