aboutsummaryrefslogtreecommitdiff
path: root/vendor/libadb-android
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/libadb-android')
-rw-r--r--vendor/libadb-android/libadb/src/main/java/io/github/muntashirakon/adb/AbsAdbConnectionManager.java5
-rw-r--r--vendor/libadb-android/libadb/src/main/java/io/github/muntashirakon/adb/AdbConnection.java41
-rw-r--r--vendor/libadb-android/libadb/src/main/java/io/github/muntashirakon/adb/AdbStream.java4
3 files changed, 41 insertions, 9 deletions
diff --git a/vendor/libadb-android/libadb/src/main/java/io/github/muntashirakon/adb/AbsAdbConnectionManager.java b/vendor/libadb-android/libadb/src/main/java/io/github/muntashirakon/adb/AbsAdbConnectionManager.java
index 967c47a..8452a86 100644
--- a/vendor/libadb-android/libadb/src/main/java/io/github/muntashirakon/adb/AbsAdbConnectionManager.java
+++ b/vendor/libadb-android/libadb/src/main/java/io/github/muntashirakon/adb/AbsAdbConnectionManager.java
@@ -411,7 +411,7 @@ public abstract class AbsAdbConnectionManager implements Closeable {
synchronized (mLock) {
if (mAdbConnection != null && mAdbConnection.isConnected()) {
try {
- return mAdbConnection.open(destination);
+ return mAdbConnection.open(destination, mTimeout, mTimeoutUnit);
} catch (AdbPairingRequiredException e) {
throw new IllegalStateException(e);
}
@@ -437,7 +437,8 @@ public abstract class AbsAdbConnectionManager implements Closeable {
synchronized (mLock) {
if (mAdbConnection != null && mAdbConnection.isConnected()) {
try {
- return mAdbConnection.open(service, args);
+ return mAdbConnection.open(LocalServices.getDestination(service, args),
+ mTimeout, mTimeoutUnit);
} catch (AdbPairingRequiredException e) {
throw new IllegalStateException(e);
}
diff --git a/vendor/libadb-android/libadb/src/main/java/io/github/muntashirakon/adb/AdbConnection.java b/vendor/libadb-android/libadb/src/main/java/io/github/muntashirakon/adb/AdbConnection.java
index a21cb66..7674adc 100644
--- a/vendor/libadb-android/libadb/src/main/java/io/github/muntashirakon/adb/AdbConnection.java
+++ b/vendor/libadb-android/libadb/src/main/java/io/github/muntashirakon/adb/AdbConnection.java
@@ -16,6 +16,7 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.ConnectException;
+import java.net.SocketTimeoutException;
import java.net.Socket;
import java.security.PrivateKey;
import java.security.cert.Certificate;
@@ -496,24 +497,50 @@ public class AdbConnection implements Closeable {
@NonNull
public AdbStream open(@NonNull String destination)
throws IOException, InterruptedException, AdbPairingRequiredException {
+ return open(destination, Long.MAX_VALUE, TimeUnit.MILLISECONDS);
+ }
+
+ @NonNull
+ public AdbStream open(@NonNull String destination, long timeout, @NonNull TimeUnit unit)
+ throws IOException, InterruptedException, AdbPairingRequiredException {
int localId = ++mLastLocalId;
if (!mConnectAttempted) {
throw new IllegalStateException("connect() must be called first");
}
- waitForConnection(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
+ if (!waitForConnection(timeout, unit)) {
+ throw new SocketTimeoutException("ADB connection timed out.");
+ }
// Add this stream to this list of half-open streams
AdbStream stream = new AdbStream(this, localId);
mOpenedStreams.put(localId, stream);
- // Send OPEN
- sendPacket(AdbProtocol.generateOpen(localId, Objects.requireNonNull(destination)));
-
- // Wait for the connection thread to receive the OKAY
- synchronized (stream) {
- stream.wait();
+ long timeoutMillis = unit.toMillis(timeout);
+ long deadline = timeoutMillis == Long.MAX_VALUE
+ ? Long.MAX_VALUE : System.currentTimeMillis() + timeoutMillis;
+ try {
+ // Send OPEN only after publishing the half-open stream so an
+ // immediate response cannot race past the lookup table.
+ sendPacket(AdbProtocol.generateOpen(localId, Objects.requireNonNull(destination)));
+ synchronized (stream) {
+ while (!stream.isOpen() && !stream.isClosed()) {
+ if (deadline == Long.MAX_VALUE) {
+ stream.wait();
+ continue;
+ }
+ long remaining = deadline - System.currentTimeMillis();
+ if (remaining <= 0) {
+ throw new SocketTimeoutException("ADB stream open timed out: " + destination);
+ }
+ stream.wait(remaining);
+ }
+ }
+ } catch (IOException | InterruptedException e) {
+ mOpenedStreams.remove(localId, stream);
+ stream.notifyClose(false);
+ throw e;
}
// Check if the OPEN request was rejected
diff --git a/vendor/libadb-android/libadb/src/main/java/io/github/muntashirakon/adb/AdbStream.java b/vendor/libadb-android/libadb/src/main/java/io/github/muntashirakon/adb/AdbStream.java
index 6d24c06..62754b0 100644
--- a/vendor/libadb-android/libadb/src/main/java/io/github/muntashirakon/adb/AdbStream.java
+++ b/vendor/libadb-android/libadb/src/main/java/io/github/muntashirakon/adb/AdbStream.java
@@ -119,6 +119,10 @@ public class AdbStream implements Closeable {
mWriteReady.set(true);
}
+ boolean isOpen() {
+ return mRemoteId != 0 && !mIsClosed;
+ }
+
/**
* Called by the connection thread to notify that the stream was closed by the peer.
*/