StreamVault is a TV-first free IPTV player for Android TV built with Kotlin, Jetpack Compose, Room, Hilt, and Media3.
Kotlin iptv-player
Test plugin Messenger playback handoff
David Nashashdaa6491ddcfb
diff --git a/app/src/test/java/com/streamvault/app/plugins/PluginMessengerClientTest.kt b/app/src/test/java/com/streamvault/app/plugins/PluginMessengerClientTest.ktnew file mode 100644index 00000000..2aceda5b--- /dev/null+++ b/app/src/test/java/com/streamvault/app/plugins/PluginMessengerClientTest.kt@@ -0,0 +1,147 @@+package com.streamvault.app.plugins++import android.content.ComponentName+import android.content.Context+import android.content.Intent+import android.content.ServiceConnection+import android.os.Bundle+import android.os.Handler+import android.os.HandlerThread+import android.os.Looper+import android.os.Message+import android.os.Messenger+import android.os.RemoteException+import com.google.common.truth.Truth.assertThat+import com.streamvault.feature.system.api.StreamVaultPluginContract+import java.util.concurrent.TimeUnit+import java.util.concurrent.atomic.AtomicReference+import kotlinx.coroutines.Dispatchers+import kotlinx.coroutines.async+import kotlinx.coroutines.runBlocking+import org.junit.Test+import org.junit.runner.RunWith+import org.mockito.kotlin.any+import org.mockito.kotlin.eq+import org.mockito.kotlin.mock+import org.mockito.kotlin.whenever+import org.mockito.kotlin.doAnswer+import org.robolectric.RobolectricTestRunner+import org.robolectric.Shadows.shadowOf++@RunWith(RobolectricTestRunner::class)+class PluginMessengerClientTest {+ @Test+ fun `handler failure response is returned with request identity and unbinds service`() =+ roundTrip(+ response = { request ->+ Bundle().apply {+ putBoolean(StreamVaultPluginContract.KEY_HANDLED, true)+ putBoolean(StreamVaultPluginContract.KEY_SUCCESS, false)+ putString(StreamVaultPluginContract.KEY_MESSAGE, "Torrent engine unavailable")+ }+ },+ ) { result, request, unbinds ->+ assertThat(result.getBoolean(StreamVaultPluginContract.KEY_HANDLED)).isTrue()+ assertThat(result.getBoolean(StreamVaultPluginContract.KEY_SUCCESS)).isFalse()+ assertThat(result.getString(StreamVaultPluginContract.KEY_MESSAGE))+ .isEqualTo("Torrent engine unavailable")+ assertValidPlaybackRequest(request)+ assertThat(unbinds).isEqualTo(1)+ }++ @Test+ fun `successful magnet response returns safe stream URL and unbinds service`() =+ roundTrip(+ response = { _ ->+ Bundle().apply {+ putBoolean(StreamVaultPluginContract.KEY_HANDLED, true)+ putBoolean(StreamVaultPluginContract.KEY_SUCCESS, true)+ putString(StreamVaultPluginContract.KEY_OUTPUT_URL, "http://127.0.0.1:6878/stream/test")+ }+ },+ ) { result, request, unbinds ->+ assertThat(result.getBoolean(StreamVaultPluginContract.KEY_HANDLED)).isTrue()+ assertThat(result.getBoolean(StreamVaultPluginContract.KEY_SUCCESS)).isTrue()+ assertThat(result.getString(StreamVaultPluginContract.KEY_OUTPUT_URL))+ .isEqualTo("http://127.0.0.1:6878/stream/test")+ assertValidPlaybackRequest(request)+ assertThat(unbinds).isEqualTo(1)+ }++ private fun roundTrip(+ response: (Message) -> Bundle,+ verify: (Bundle, Bundle, Int) -> Unit,+ ) = runBlocking {+ val worker = HandlerThread("plugin-messenger-test").apply { start() }+ val seenRequest = AtomicReference<Bundle>()+ val service = Messenger(Handler(worker.looper) { request ->+ seenRequest.set(Bundle(request.data))+ val reply = Message.obtain().apply {+ data = response(request).apply {+ putString(+ StreamVaultPluginContract.KEY_REQUEST_ID,+ request.data.getString(StreamVaultPluginContract.KEY_REQUEST_ID),+ )+ }+ }+ try {+ request.replyTo.send(reply)+ } catch (error: RemoteException) {+ throw AssertionError("Test plugin could not reply", error)+ }+ true+ })+ val context = mock<Context>()+ whenever(context.applicationContext).thenReturn(context)+ var unbinds = 0+ doAnswer { invocation ->+ val intent = invocation.getArgument<Intent>(0)+ val connection = invocation.getArgument<ServiceConnection>(1)+ connection.onServiceConnected(+ intent.component,+ service.binder,+ )+ true+ }.whenever(context).bindService(any(), any(), eq(Context.BIND_AUTO_CREATE))+ doAnswer { unbinds++; null }.whenever(context).unbindService(any())++ try {+ val client = PluginMessengerClient(context)+ val call = async(Dispatchers.IO) {+ client.send(+ packageName = "com.example.torrent",+ serviceClassName = "com.example.torrent.PluginService",+ what = StreamVaultPluginContract.MSG_PREPARE_PLAYBACK,+ data = Bundle().apply {+ putString(+ StreamVaultPluginContract.KEY_INPUT_URL,+ "magnet:?xt=urn:btih:0123456789abcdef",+ )+ },+ timeoutMillis = 2_000L,+ )+ }++ val mainLooper = shadowOf(Looper.getMainLooper())+ val deadline = System.nanoTime() + TimeUnit.SECONDS.toNanos(5)+ while (!call.isCompleted && System.nanoTime() < deadline) {+ mainLooper.idle()+ Thread.sleep(10)+ }+ mainLooper.idle()++ assertThat(call.isCompleted).isTrue()+ verify(call.await(), checkNotNull(seenRequest.get()), unbinds)+ } finally {+ worker.quitSafely()+ }+ }++ private fun assertValidPlaybackRequest(request: Bundle) {+ assertThat(request.getInt(StreamVaultPluginContract.KEY_API_VERSION))+ .isEqualTo(StreamVaultPluginContract.API_VERSION)+ assertThat(request.getString(StreamVaultPluginContract.KEY_REQUEST_ID)).isNotEmpty()+ assertThat(request.getString(StreamVaultPluginContract.KEY_INPUT_URL))+ .isEqualTo("magnet:?xt=urn:btih:0123456789abcdef")+ }+}diff --git a/docs/STREMIO_UX_AND_FUNCTIONALITY_PLAN.md b/docs/STREMIO_UX_AND_FUNCTIONALITY_PLAN.mdindex 77f5ac0b..34ed61d5 100644--- a/docs/STREMIO_UX_AND_FUNCTIONALITY_PLAN.md+++ b/docs/STREMIO_UX_AND_FUNCTIONALITY_PLAN.md@@ -1,7 +1,7 @@# Stremio and Extensions UX and functionality improvement plan- Date: 2026-10-16.-- Status: Implementation in progress; catalog replacement, focus restoration, backup compatibility, and playback handoff regressions are covered. Debug APK is installed on the requested emulator; configured-emulator UX and real-torrent acceptance remain pending.+- Status: Implementation checks are complete, including plugin Messenger request/reply coverage. Debug APK is installed on the requested emulator; configured-emulator UX and real-torrent acceptance remain pending.- Reviewed baseline: `f1ac7d3d` on `feature/stremio-addons`.- Worktree: `D:\antigravity-scratch\iptv-player\.worktrees\stremio-addons`.@@ -183,9 +183,8 @@ Addresses R1-R2.- [x] Cover direct HTTP header scoping, invalid headers, unavailable torrentcapability, explicit magnet plugin routing, safe/unsafe loopback output, andpopulated supported upgrade origins.-- [ ] Add a plugin-manager binder-level test for handler-reported failure and- successful magnet handoff. Current tests cover the policy and UI availability- decisions without invoking the Android Messenger call path.+- [x] Exercise the Android Messenger bind/request/reply/unbind path for both a+ handler-reported failure and successful magnet preparation response.Gate: targeted playback tests pass, supported database upgrades validate thefinal Room schema and foreign keys, and a current debug APK builds.@@ -287,7 +286,10 @@ unclassified `hide_stremio_addons` preference; the registry and backupimport/export mappings were fixed, and the full suite then passed. The debug APK`1.0.19-debug` built and installed on `emulator-5558`. That emulator is currentlyat first-run provider setup, so add-on management focus could not be exercised-there. These checks do not establish visual quality or real torrent playback.+there. `PluginMessengerClientTest` now exercises the Messenger round trip for a+reported handler failure and a successful magnet preparation reply, including+request metadata and service unbinding. These checks do not establish visual+quality or real torrent playback.| Area | Required evidence after implementation || --- | --- |@@ -298,7 +300,7 @@ there. These checks do not establish visual quality or real torrent playback.| Catalog requests | Tests cover selected-only loading, required/unsupported extras, stale-response cancellation, page retry retaining previous items, and explicit refresh/cache behavior. || Sources and series | Tests cover exact episode IDs, long episode lists, progressive providers, partial failures, retry, and rapid episode changes; user verifies the source-picker flow. || Navigation | User verifies player-to-title-to-browse Back behavior and retained selection, filters, scroll, and focus; automated state/navigation checks cover the same contracts where practical. |-| Playback and subtitles | Tests cover direct HTTP headers, invalid headers, magnet capability/routing/output policy, handoff headers, resume identity, and inline/add-on subtitles. Plugin Messenger failure/success integration and real stream/torrent acceptance remain open. |+| Playback and subtitles | Tests cover direct HTTP headers, invalid headers, magnet capability/routing/output policy, Messenger handler failure/success replies, handoff headers, resume identity, and inline/add-on subtitles. Real stream/torrent acceptance remains open. || Database upgrade | Migration tests use populated supported historical variants and verify final schema, episode uniqueness, Xtream columns, preserved data, and foreign keys. || Visibility | Tests retain independent Hide Stremio Add-ons behavior and prevent content access through hidden Stremio routes. |