From ff7acf898b48359275a5b09b82ed926a945233f8 Mon Sep 17 00:00:00 2001 From: Lena Date: Wed, 1 Jul 2026 00:00:00 +0000 Subject: app: fix session lifecycle, teardown, and opus playback Opus playback never worked: feed() called dequeueInputBuffer() on a codec in async-callback mode, which always throws, so every packet was silently dropped. Feed input through the async callback with a bounded pending queue instead. Make bring-up transactional: roll back partially opened streams and the server shell on failure, join reader threads on stop, and close the owning ADB streams before releasing sinks. Replace the openAbstract watchdog thread with a real timeout in the vendored AdbConnection.open(), which also removes the half-open stream from the lookup table on failure. Harden the activity: release owned Surfaces, gate callbacks on a destroyed flag and a session generation, serialize reconnect, and handle target replacement via singleTask + onNewIntent. Propagate device-list write failures instead of swallowing them, bound the clipboard payload and the video pending queue against hostile peers, and discard incomplete recordings instead of keeping corrupt files. Use the mediaPlayback foreground-service type; Android 15 stops dataSync services after six hours. Drop the unused ACCESS_NETWORK_STATE permission. --- .../muntashirakon/adb/AbsAdbConnectionManager.java | 5 +-- .../io/github/muntashirakon/adb/AdbConnection.java | 41 ++++++++++++++++++---- .../io/github/muntashirakon/adb/AdbStream.java | 4 +++ 3 files changed, 41 insertions(+), 9 deletions(-) (limited to 'vendor/libadb-android/libadb') 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. */ -- cgit v1.2.3