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