am 2589180d: First pass at making adb connection timeout configurable.
Merge commit '2589180d6d095659c1f16f8747186aec58b14ea8' into eclair-plus-aosp * commit '2589180d6d095659c1f16f8747186aec58b14ea8': First pass at making adb connection timeout configurable.
This commit is contained in:
@@ -40,8 +40,6 @@ final class AdbHelper {
|
||||
|
||||
static final int WAIT_TIME = 5; // spin-wait sleep, in ms
|
||||
|
||||
public static final int STD_TIMEOUT = 5000; // standard delay, in ms
|
||||
|
||||
static final String DEFAULT_ENCODING = "ISO-8859-1"; //$NON-NLS-1$
|
||||
|
||||
/** do not instantiate */
|
||||
@@ -576,7 +574,7 @@ final class AdbHelper {
|
||||
*/
|
||||
static boolean read(SocketChannel chan, byte[] data) {
|
||||
try {
|
||||
read(chan, data, -1, STD_TIMEOUT);
|
||||
read(chan, data, -1, DdmPreferences.getTimeOut());
|
||||
} catch (IOException e) {
|
||||
Log.d("ddms", "readAll: IOException: " + e.getMessage());
|
||||
return false;
|
||||
@@ -636,7 +634,7 @@ final class AdbHelper {
|
||||
*/
|
||||
static boolean write(SocketChannel chan, byte[] data) {
|
||||
try {
|
||||
write(chan, data, -1, STD_TIMEOUT);
|
||||
write(chan, data, -1, DdmPreferences.getTimeOut());
|
||||
} catch (IOException e) {
|
||||
Log.e("ddms", e);
|
||||
return false;
|
||||
|
||||
@@ -40,6 +40,8 @@ public final class DdmPreferences {
|
||||
public final static int DEFAULT_DEBUG_PORT_BASE = 8600;
|
||||
/** Default value for the logcat {@link LogLevel} */
|
||||
public final static LogLevel DEFAULT_LOG_LEVEL = LogLevel.ERROR;
|
||||
/** Default timeout values for adb connection (milliseconds) */
|
||||
public static final int DEFAULT_TIMEOUT = 5000; // standard delay, in ms
|
||||
|
||||
private static boolean sThreadUpdate = DEFAULT_INITIAL_THREAD_UPDATE;
|
||||
private static boolean sInitialHeapUpdate = DEFAULT_INITIAL_HEAP_UPDATE;
|
||||
@@ -47,6 +49,7 @@ public final class DdmPreferences {
|
||||
private static int sSelectedDebugPort = DEFAULT_SELECTED_DEBUG_PORT;
|
||||
private static int sDebugPortBase = DEFAULT_DEBUG_PORT_BASE;
|
||||
private static LogLevel sLogLevel = DEFAULT_LOG_LEVEL;
|
||||
private static int sTimeOut = DEFAULT_TIMEOUT;
|
||||
|
||||
/**
|
||||
* Returns the initial {@link Client} flag for thread updates.
|
||||
@@ -75,7 +78,7 @@ public final class DdmPreferences {
|
||||
/**
|
||||
* Sets the initial {@link Client} flag for heap updates.
|
||||
* <p/>If <code>true</code>, the {@link ClientData} will automatically be updated with
|
||||
* the VM heap information whenever a GC happens.
|
||||
* the VM heap information whenever a GC happens.
|
||||
* <p/>This change takes effect right away, for newly created {@link Client} objects.
|
||||
*/
|
||||
public static void setInitialHeapUpdate(boolean state) {
|
||||
@@ -137,7 +140,23 @@ public final class DdmPreferences {
|
||||
|
||||
Log.setLevel(sLogLevel);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the timeout to be used in adb connections (milliseconds).
|
||||
*/
|
||||
public static int getTimeOut() {
|
||||
return sTimeOut;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the timeout value for adb connection.
|
||||
* <p/>This change takes effect for newly created connections only.
|
||||
* @param timeOut the timeout value (milliseconds).
|
||||
*/
|
||||
public static void setTimeOut(int timeOut) {
|
||||
sTimeOut = timeOut;
|
||||
}
|
||||
|
||||
/**
|
||||
* Non accessible constructor.
|
||||
*/
|
||||
|
||||
@@ -566,7 +566,7 @@ public final class EmulatorConsole {
|
||||
}
|
||||
|
||||
// write the command
|
||||
AdbHelper.write(mSocketChannel, bCommand, bCommand.length, AdbHelper.STD_TIMEOUT);
|
||||
AdbHelper.write(mSocketChannel, bCommand, bCommand.length, DdmPreferences.getTimeOut());
|
||||
|
||||
result = true;
|
||||
} catch (IOException e) {
|
||||
|
||||
@@ -222,7 +222,7 @@ public final class SyncService {
|
||||
AdbHelper.setDevice(mChannel, mDevice);
|
||||
|
||||
byte[] request = AdbHelper.formAdbRequest("sync:"); // $NON-NLS-1$
|
||||
AdbHelper.write(mChannel, request, -1, AdbHelper.STD_TIMEOUT);
|
||||
AdbHelper.write(mChannel, request, -1, DdmPreferences.getTimeOut());
|
||||
|
||||
AdbResponse resp = AdbHelper.readAdbResponse(mChannel, false /* readDiagString */);
|
||||
|
||||
@@ -559,6 +559,9 @@ public final class SyncService {
|
||||
ISyncProgressMonitor monitor) {
|
||||
byte[] msg = null;
|
||||
byte[] pullResult = new byte[8];
|
||||
|
||||
final int timeOut = DdmPreferences.getTimeOut();
|
||||
|
||||
try {
|
||||
byte[] remotePathContent = remotePath.getBytes(AdbHelper.DEFAULT_ENCODING);
|
||||
|
||||
@@ -570,11 +573,11 @@ public final class SyncService {
|
||||
msg = createFileReq(ID_RECV, remotePathContent);
|
||||
|
||||
// and send it.
|
||||
AdbHelper.write(mChannel, msg, -1, AdbHelper.STD_TIMEOUT);
|
||||
AdbHelper.write(mChannel, msg, -1, timeOut);
|
||||
|
||||
// read the result, in a byte array containing 2 ints
|
||||
// (id, size)
|
||||
AdbHelper.read(mChannel, pullResult, -1, AdbHelper.STD_TIMEOUT);
|
||||
AdbHelper.read(mChannel, pullResult, -1, timeOut);
|
||||
|
||||
// check we have the proper data back
|
||||
if (checkResult(pullResult, ID_DATA) == false &&
|
||||
@@ -626,10 +629,10 @@ public final class SyncService {
|
||||
|
||||
try {
|
||||
// now read the length we received
|
||||
AdbHelper.read(mChannel, data, length, AdbHelper.STD_TIMEOUT);
|
||||
AdbHelper.read(mChannel, data, length, timeOut);
|
||||
|
||||
// get the header for the next packet.
|
||||
AdbHelper.read(mChannel, pullResult, -1, AdbHelper.STD_TIMEOUT);
|
||||
AdbHelper.read(mChannel, pullResult, -1, timeOut);
|
||||
} catch (IOException e) {
|
||||
return new SyncResult(RESULT_CONNECTION_ERROR, e);
|
||||
}
|
||||
@@ -705,6 +708,8 @@ public final class SyncService {
|
||||
FileInputStream fis = null;
|
||||
byte[] msg;
|
||||
|
||||
final int timeOut = DdmPreferences.getTimeOut();
|
||||
|
||||
try {
|
||||
byte[] remotePathContent = remotePath.getBytes(AdbHelper.DEFAULT_ENCODING);
|
||||
|
||||
@@ -733,7 +738,7 @@ public final class SyncService {
|
||||
// and send it. We use a custom try/catch block to make the difference between
|
||||
// file and network IO exceptions.
|
||||
try {
|
||||
AdbHelper.write(mChannel, msg, -1, AdbHelper.STD_TIMEOUT);
|
||||
AdbHelper.write(mChannel, msg, -1, timeOut);
|
||||
} catch (IOException e) {
|
||||
return new SyncResult(RESULT_CONNECTION_ERROR, e);
|
||||
}
|
||||
@@ -771,7 +776,7 @@ public final class SyncService {
|
||||
|
||||
// now write it
|
||||
try {
|
||||
AdbHelper.write(mChannel, mBuffer, readCount+8, AdbHelper.STD_TIMEOUT);
|
||||
AdbHelper.write(mChannel, mBuffer, readCount+8, timeOut);
|
||||
} catch (IOException e) {
|
||||
return new SyncResult(RESULT_CONNECTION_ERROR, e);
|
||||
}
|
||||
@@ -792,19 +797,19 @@ public final class SyncService {
|
||||
msg = createReq(ID_DONE, (int)time);
|
||||
|
||||
// and send it.
|
||||
AdbHelper.write(mChannel, msg, -1, AdbHelper.STD_TIMEOUT);
|
||||
AdbHelper.write(mChannel, msg, -1, timeOut);
|
||||
|
||||
// read the result, in a byte array containing 2 ints
|
||||
// (id, size)
|
||||
byte[] result = new byte[8];
|
||||
AdbHelper.read(mChannel, result, -1 /* full length */, AdbHelper.STD_TIMEOUT);
|
||||
AdbHelper.read(mChannel, result, -1 /* full length */, timeOut);
|
||||
|
||||
if (checkResult(result, ID_OKAY) == false) {
|
||||
if (checkResult(result, ID_FAIL)) {
|
||||
// read some error message...
|
||||
int len = ArrayHelper.swap32bitFromArray(result, 4);
|
||||
|
||||
AdbHelper.read(mChannel, mBuffer, len, AdbHelper.STD_TIMEOUT);
|
||||
AdbHelper.read(mChannel, mBuffer, len, timeOut);
|
||||
|
||||
// output the result?
|
||||
String message = new String(mBuffer, 0, len);
|
||||
@@ -832,12 +837,12 @@ public final class SyncService {
|
||||
// create the stat request message.
|
||||
byte[] msg = createFileReq(ID_STAT, path);
|
||||
|
||||
AdbHelper.write(mChannel, msg, -1 /* full length */, AdbHelper.STD_TIMEOUT);
|
||||
AdbHelper.write(mChannel, msg, -1 /* full length */, DdmPreferences.getTimeOut());
|
||||
|
||||
// read the result, in a byte array containing 4 ints
|
||||
// (id, mode, size, time)
|
||||
byte[] statResult = new byte[16];
|
||||
AdbHelper.read(mChannel, statResult, -1 /* full length */, AdbHelper.STD_TIMEOUT);
|
||||
AdbHelper.read(mChannel, statResult, -1 /* full length */, DdmPreferences.getTimeOut());
|
||||
|
||||
// check we have the proper data back
|
||||
if (checkResult(statResult, ID_STAT) == false) {
|
||||
|
||||
Reference in New Issue
Block a user