From 92a994f37ab4a4b48f9927b6bef2524e5923918e Mon Sep 17 00:00:00 2001 From: seasonyuu Date: Mon, 16 Nov 2026 22:12:06 +0800 Subject: [PATCH 01/14] fix(android): correct host permission and compatibility handling Fix host permission checks, Bluetooth availability, desktop readiness and media runtime compatibility. Include the associated regression tests. --- .github/scripts/install-android-packages.sh | 3 +- common/src/main/AndroidManifest.xml | 5 +++ .../com/shilapi/xcertplay/web/WebSession.kt | 6 ++-- .../moe/feng/wheelplay/WheelPlayActivity.kt | 13 +++++--- .../moe/feng/wheelplay/WheelPlayBluetooth.kt | 18 ++++++++++- .../feng/wheelplay/WheelPlaySessionService.kt | 2 +- .../desktop/ShizukuDesktopUserService.kt | 8 +++-- .../feng/wheelplay/WheelPlayBluetoothTest.kt | 32 +++++++++++++++++++ scripts/test-media-presentation.mjs | 9 ++++-- test/ci-android-toolchain.test.js | 4 ++- 10 files changed, 84 insertions(+), 16 deletions(-) create mode 100644 common/src/test/java/moe/feng/wheelplay/WheelPlayBluetoothTest.kt diff --git a/.github/scripts/install-android-packages.sh b/.github/scripts/install-android-packages.sh index 0a3db9fd..7233bc22 100644 --- a/.github/scripts/install-android-packages.sh +++ b/.github/scripts/install-android-packages.sh @@ -11,7 +11,8 @@ fi missing=() for package in "$@"; do - directory="${ANDROID_HOME}/${package//;/\/}" + relative=${package//;/\/} + directory="${ANDROID_HOME}/${relative}" if [[ -f "$directory/package.xml" || -f "$directory/source.properties" ]]; then echo "Using installed SDK package: $package" else diff --git a/common/src/main/AndroidManifest.xml b/common/src/main/AndroidManifest.xml index f1a34196..52d71586 100644 --- a/common/src/main/AndroidManifest.xml +++ b/common/src/main/AndroidManifest.xml @@ -15,6 +15,11 @@ + + + + + diff --git a/common/src/main/java/com/shilapi/xcertplay/web/WebSession.kt b/common/src/main/java/com/shilapi/xcertplay/web/WebSession.kt index 4d6cfa4c..ce89a2f7 100644 --- a/common/src/main/java/com/shilapi/xcertplay/web/WebSession.kt +++ b/common/src/main/java/com/shilapi/xcertplay/web/WebSession.kt @@ -422,7 +422,7 @@ internal object WebSession { } } catch (e: Exception) { next.stop() - error = context.getString(UiR.string.error_listener_start, port, e.userMessage(context)) + error = context.getString(UiR.string.error_listener_start, port.toString(), e.userMessage(context)) } } @@ -445,9 +445,9 @@ internal object WebSession { next.stopPreservingPairing() return context.getString( UiR.string.error_listener_start_kept_previous, - port, + port.toString(), e.userMessage(context), - httpPort, + httpPort.toString(), ) } try { diff --git a/common/src/main/java/moe/feng/wheelplay/WheelPlayActivity.kt b/common/src/main/java/moe/feng/wheelplay/WheelPlayActivity.kt index 473b54a3..2a2c2156 100644 --- a/common/src/main/java/moe/feng/wheelplay/WheelPlayActivity.kt +++ b/common/src/main/java/moe/feng/wheelplay/WheelPlayActivity.kt @@ -1047,16 +1047,21 @@ class WheelPlayActivity : AppCompatActivity() { if (adapter == null || !adapter.isEnabled) { dialogs.message(getString(UiR.string.ui_turn_on_bluetooth), getString(UiR.string.ui_turn_on_bluetooth_on_this_android_device_and_pair), listOf(settings)); return } - val devices = runCatching { adapter.bondedDevices.sortedBy { it.name ?: "" } }.getOrDefault(emptyList()) + val devices = try { + adapter.bondedDevices.map { it.address to (it.name ?: getString(UiR.string.ui_paired_device)) } + .sortedBy { it.second } + } catch (_: SecurityException) { + dialogs.message(getString(UiR.string.ui_open_bluetooth_settings), getString(UiR.string.ui_pair_this_android_device_in_settings_bluetooth_on_your), listOf(settings)); return + } if (devices.isEmpty()) { dialogs.message(getString(UiR.string.ui_pair_your_iphone_first), getString(UiR.string.ui_pair_this_android_device_in_settings_bluetooth_on_your), listOf(settings)); return } dialogs.choices(getString(UiR.string.ui_choose_iphone), devices.map { device -> - val name = device.name ?: getString(UiR.string.ui_paired_device) - if (devices.count { it.name == device.name } > 1) "$name · ${device.address.takeLast(5)}" else name + val name = device.second + if (devices.count { it.second == name } > 1) "$name · ${device.first.takeLast(5)}" else name }, extra = WheelPlayDialogs.Action(getString(UiR.string.ui_pair_another_device), settings.run), onCancel = { pendingWireless = false }) { index -> val device = devices[index] - WheelPlayPreferences.savePhone(this, device.address, device.name ?: "iPhone") + WheelPlayPreferences.savePhone(this, device.first, device.second) val start = pendingWireless; pendingWireless = false render() if (start) connect(true) diff --git a/common/src/main/java/moe/feng/wheelplay/WheelPlayBluetooth.kt b/common/src/main/java/moe/feng/wheelplay/WheelPlayBluetooth.kt index 5206a5a9..21fffc4d 100644 --- a/common/src/main/java/moe/feng/wheelplay/WheelPlayBluetooth.kt +++ b/common/src/main/java/moe/feng/wheelplay/WheelPlayBluetooth.kt @@ -1,12 +1,28 @@ package moe.feng.wheelplay import android.bluetooth.BluetoothManager +import android.Manifest +import android.os.Build +import android.content.pm.PackageManager import android.content.Context import android.provider.Settings internal object WheelPlayBluetooth { fun localAddress(context: Context): String? { - val adapter = runCatching { context.getSystemService(BluetoothManager::class.java)?.adapter?.address }.getOrNull() + // LOCAL_MAC_ADDRESS is privileged. Ordinary installations skip this API and use the + // existing optional setting fallback; never request a permission they cannot be granted. + val adapter = if ((Build.VERSION.SDK_INT < 31 || + context.checkSelfPermission(Manifest.permission.BLUETOOTH_CONNECT) == PackageManager.PERMISSION_GRANTED) && + context.checkSelfPermission("android.permission.LOCAL_MAC_ADDRESS") == PackageManager.PERMISSION_GRANTED) { + try { + // Optional privileged-device path, guarded above. Do not request this privileged + // permission in the ordinary APK; lint requires a declaration even with this guard. + @android.annotation.SuppressLint("MissingPermission") + val address = context.getSystemService(BluetoothManager::class.java)?.adapter?.address + address + } + catch (_: SecurityException) { null } + } else null val setting = runCatching { Settings.Secure.getString(context.contentResolver, "bluetooth_address") }.getOrNull() return listOfNotNull(adapter, setting).firstOrNull { Regex("(?i)([0-9a-f]{2}:){5}[0-9a-f]{2}").matches(it) && diff --git a/common/src/main/java/moe/feng/wheelplay/WheelPlaySessionService.kt b/common/src/main/java/moe/feng/wheelplay/WheelPlaySessionService.kt index ec99ee76..eecdf0af 100644 --- a/common/src/main/java/moe/feng/wheelplay/WheelPlaySessionService.kt +++ b/common/src/main/java/moe/feng/wheelplay/WheelPlaySessionService.kt @@ -224,7 +224,7 @@ class WheelPlaySessionService : Service() { .setContentTitle(getString(R.string.app_name)) .setContentText( if (WebSession.running) - getString(UiR.string.notification_streaming_running, port) + getString(UiR.string.notification_streaming_running, port.toString()) else getString(UiR.string.ui_preparing_streaming_service) ) .addAction( diff --git a/common/src/main/java/moe/feng/wheelplay/projection/desktop/ShizukuDesktopUserService.kt b/common/src/main/java/moe/feng/wheelplay/projection/desktop/ShizukuDesktopUserService.kt index c141cd7d..c9f9822d 100644 --- a/common/src/main/java/moe/feng/wheelplay/projection/desktop/ShizukuDesktopUserService.kt +++ b/common/src/main/java/moe/feng/wheelplay/projection/desktop/ShizukuDesktopUserService.kt @@ -121,8 +121,12 @@ class ShizukuDesktopUserService(context: Context) : IDesktopService.Stub() { if (Build.VERSION.SDK_INT >= 33) flags = flags or (1 shl 10) or (1 shl 11) // TRUSTED, OWN_DISPLAY_GROUP if (Build.VERSION.SDK_INT >= 34) flags = flags or (1 shl 14) // OWN_FOCUS val virtualDisplay = desktopOperation(DesktopErrorCode.DISPLAY_FAILED) { - requireNotNull(displays.createVirtualDisplay("WheelPlay Android desktop", requested.width, - requested.height, requested.dpi, target, flags)) { "Virtual displays are unsupported" } + // AOSP DisplayManager hidden flags are intentionally used by this shell-UID service. + // Their bits are version-gated above; SDK IntDef omits them (android16-release). + @android.annotation.SuppressLint("WrongConstant") + val created = displays.createVirtualDisplay("WheelPlay Android desktop", requested.width, + requested.height, requested.dpi, target, flags) + requireNotNull(created) { "Virtual displays are unsupported" } }.also { display = it } val displayId = virtualDisplay.display.displayId desktopCheck(displayId > 0, DesktopErrorCode.DISPLAY_FAILED) { "Refusing the default display" } diff --git a/common/src/test/java/moe/feng/wheelplay/WheelPlayBluetoothTest.kt b/common/src/test/java/moe/feng/wheelplay/WheelPlayBluetoothTest.kt new file mode 100644 index 00000000..2ccf4b55 --- /dev/null +++ b/common/src/test/java/moe/feng/wheelplay/WheelPlayBluetoothTest.kt @@ -0,0 +1,32 @@ +package moe.feng.wheelplay + +import android.content.Context +import android.content.ContextWrapper +import android.content.pm.PackageManager +import android.provider.Settings +import org.junit.Assert.* +import org.junit.Test +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner +import org.robolectric.RuntimeEnvironment +import org.robolectric.annotation.Config + +@RunWith(RobolectricTestRunner::class) +@Config(sdk = [31]) +class WheelPlayBluetoothTest { + @Test fun deniedPrivilegedPermissionSkipsAdapterAndKeepsOptionalSettingFallback() { + val context = object : ContextWrapper(RuntimeEnvironment.getApplication()) { + override fun checkSelfPermission(permission: String) = PackageManager.PERMISSION_DENIED + override fun getSystemService(name: String): Any? { + check(name != Context.BLUETOOTH_SERVICE) { "Must not read the adapter without permission" } + return super.getSystemService(name) + } + } + Settings.Secure.putString(context.contentResolver, "bluetooth_address", "12:34:56:78:9A:BC") + assertEquals("12:34:56:78:9A:BC", WheelPlayBluetooth.localAddress(context)) + Settings.Secure.putString(context.contentResolver, "bluetooth_address", "02:00:00:00:00:00") + assertNull(WheelPlayBluetooth.localAddress(context)) + Settings.Secure.putString(context.contentResolver, "bluetooth_address", null) + assertNull(WheelPlayBluetooth.localAddress(context)) + } +} diff --git a/scripts/test-media-presentation.mjs b/scripts/test-media-presentation.mjs index 9ab7c90d..d815b623 100644 --- a/scripts/test-media-presentation.mjs +++ b/scripts/test-media-presentation.mjs @@ -191,9 +191,12 @@ try { }; document.addEventListener('fullscreenchange',()=>fullscreenTrace.push({event:!!document.fullscreenElement})); document.addEventListener('fullscreenerror',()=>fullscreenTrace.push({event:'error'}));`); + // Finish PIN entry before measuring the button: the keypad can move the scroll viewport. + await evaluate(`document.getElementById('keypad-done').click()`); await command('Page.bringToFront'); + await evaluate(`document.getElementById('connect').scrollIntoView({block:'center'});new Promise(resolve=>requestAnimationFrame(()=>requestAnimationFrame(resolve)))`); const startButton = await evaluate(`(() => { - const button=document.getElementById('connect');button.scrollIntoView({block:'center'}); + const button=document.getElementById('connect'); const rect=button.getBoundingClientRect();return {x:rect.left+rect.width/2,y:rect.top+rect.height/2}; })()`); await command('Input.dispatchMouseEvent', { type: 'mousePressed', ...startButton, button: 'left', clickCount: 1 }); @@ -469,8 +472,8 @@ try { await command('Browser.grantPermissions',{origin:`http://127.0.0.1:${server.address().port}`,permissions:['clipboardReadWrite','clipboardSanitizedWrite']}); await evaluate(`navigator.clipboard.writeText('098765')`,{userGesture:true}); await evaluate(`document.getElementById('code-digit-1').focus({preventScroll:true})`); - await command('Input.dispatchKeyEvent',{type:'keyDown',key:'v',code:'KeyV',modifiers:2,windowsVirtualKeyCode:86}); - await command('Input.dispatchKeyEvent',{type:'keyUp',key:'v',code:'KeyV',modifiers:2,windowsVirtualKeyCode:86}); + await command('Input.dispatchKeyEvent',{type:'keyDown',key:'v',code:'KeyV',modifiers:process.platform === 'darwin' ? 4 : 2,windowsVirtualKeyCode:86,...(process.platform === 'darwin' ? {commands:['paste']} : {})}); + await command('Input.dispatchKeyEvent',{type:'keyUp',key:'v',code:'KeyV',modifiers:process.platform === 'darwin' ? 4 : 2,windowsVirtualKeyCode:86}); await wait(`document.getElementById('code').value==='098765'`); await tapKey('keypad-clear'); for (const digit of '012') await tapKey('keypad-'+digit); diff --git a/test/ci-android-toolchain.test.js b/test/ci-android-toolchain.test.js index 4157194f..ce889a92 100644 --- a/test/ci-android-toolchain.test.js +++ b/test/ci-android-toolchain.test.js @@ -21,7 +21,8 @@ printf '%s\\n' "$@" > "$SDK_CALL_LOG" if [[ "\${MOCK_SDKMANAGER_FAIL:-0}" == 1 ]]; then exit 7; fi shift 2 for package in "$@"; do - directory="$ANDROID_HOME/\${package//;/\\/}" + relative=\${package//;/\\/} + directory="$ANDROID_HOME/$relative" mkdir -p "$directory" printf 'installed' > "$directory/package.xml" done @@ -48,6 +49,7 @@ test('SDK cold start installs all packages and a warm run skips sdkmanager entir const f = sdkFixture(t); assert.equal(f.run().status, 0); assert.deepEqual(f.calls(), [`--sdk_root=${f.sdk}`, '--install', ...packages]); + for (const id of packages) assert.equal(existsSync(join(f.sdk, ...id.split(';'), 'package.xml')), true); rmSync(f.log); assert.equal(f.run().status, 0); assert.equal(existsSync(f.log), false); From 9ba327e5bb4fb2453cae4ad6c6f906e29a2c19c1 Mon Sep 17 00:00:00 2001 From: seasonyuu Date: Mon, 16 Nov 2026 22:12:06 +0800 Subject: [PATCH 02/14] refactor(ui): share the settings theme with projection plugins Extract the reusable settings theme into ui-theme while preserving the host appearance. --- common/build.gradle.kts | 1 + .../feng/wheelplay/ui/theme/WheelPlayTheme.kt | 20 +------------- settings.gradle.kts | 1 + ui-theme/build.gradle.kts | 18 +++++++++++++ .../wheelplay/ui/WheelPlaySettingsTheme.kt | 27 +++++++++++++++++++ 5 files changed, 48 insertions(+), 19 deletions(-) create mode 100644 ui-theme/build.gradle.kts create mode 100644 ui-theme/src/main/java/moe/feng/wheelplay/ui/WheelPlaySettingsTheme.kt diff --git a/common/build.gradle.kts b/common/build.gradle.kts index f7721ca6..546636da 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -36,6 +36,7 @@ dependencies { implementation(libs.androidx.remote.core) implementation(libs.androidx.remote.player.core) implementation(libs.androidx.remote.player.view) + implementation(project(":ui-theme")) implementation("dev.rikka.shizuku:api:13.1.5") implementation("dev.rikka.shizuku:provider:13.1.5") implementation(project(":projection-plugin-api")) diff --git a/common/src/main/java/moe/feng/wheelplay/ui/theme/WheelPlayTheme.kt b/common/src/main/java/moe/feng/wheelplay/ui/theme/WheelPlayTheme.kt index 2501d8c5..9cf83341 100644 --- a/common/src/main/java/moe/feng/wheelplay/ui/theme/WheelPlayTheme.kt +++ b/common/src/main/java/moe/feng/wheelplay/ui/theme/WheelPlayTheme.kt @@ -2,26 +2,8 @@ package moe.feng.wheelplay.ui.theme import androidx.compose.runtime.Composable -import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.darkColorScheme -import androidx.compose.ui.graphics.Color @Composable internal fun WheelPlayTheme(content: @Composable () -> Unit) { - MaterialTheme( - colorScheme = - darkColorScheme( - primary = Color(0xffb4d9b1), - onPrimary = Color(0xff20391f), - secondaryContainer = Color(0xff3c4b39), - onSecondaryContainer = Color(0xffd9e7d3), - background = Color(0xff11161a), - surface = Color(0xff11161a), - surfaceContainer = Color(0xff1c2428), - onSurface = Color(0xffe2e8e3), - onSurfaceVariant = Color(0xffc1c9be), - outline = Color(0xff8b9389), - ), - content = content, - ) + moe.feng.wheelplay.ui.WheelPlaySettingsTheme(content) } diff --git a/settings.gradle.kts b/settings.gradle.kts index 976f16d2..35da8439 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -32,3 +32,4 @@ include(":mobile") include(":shared") include(":projection-plugin-api") include(":projection-plugin-sample") +include(":ui-theme") diff --git a/ui-theme/build.gradle.kts b/ui-theme/build.gradle.kts new file mode 100644 index 00000000..2b1c5d2c --- /dev/null +++ b/ui-theme/build.gradle.kts @@ -0,0 +1,18 @@ +plugins { + id("com.android.library") + alias(libs.plugins.kotlin.compose) +} +android { + namespace = "moe.feng.wheelplay.ui" + compileSdk = 36 + defaultConfig { minSdk = 28 } + buildFeatures { compose = true } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 + } +} +dependencies { + implementation(platform(libs.androidx.compose.bom)) + implementation(libs.androidx.compose.material3) +} diff --git a/ui-theme/src/main/java/moe/feng/wheelplay/ui/WheelPlaySettingsTheme.kt b/ui-theme/src/main/java/moe/feng/wheelplay/ui/WheelPlaySettingsTheme.kt new file mode 100644 index 00000000..8a9aae5d --- /dev/null +++ b/ui-theme/src/main/java/moe/feng/wheelplay/ui/WheelPlaySettingsTheme.kt @@ -0,0 +1,27 @@ +// SPDX-License-Identifier: AGPL-3.0-only +package moe.feng.wheelplay.ui + +import androidx.compose.runtime.Composable +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.darkColorScheme +import androidx.compose.ui.graphics.Color + +@Composable +fun WheelPlaySettingsTheme(content: @Composable () -> Unit) { + MaterialTheme( + colorScheme = + darkColorScheme( + primary = Color(0xffb4d9b1), + onPrimary = Color(0xff20391f), + secondaryContainer = Color(0xff3c4b39), + onSecondaryContainer = Color(0xffd9e7d3), + background = Color(0xff11161a), + surface = Color(0xff11161a), + surfaceContainer = Color(0xff1c2428), + onSurface = Color(0xffe2e8e3), + onSurfaceVariant = Color(0xffc1c9be), + outline = Color(0xff8b9389), + ), + content = content, + ) +} From bbf488ce418895417375f91c936640195479d4c3 Mon Sep 17 00:00:00 2001 From: seasonyuu Date: Mon, 16 Nov 2026 22:12:06 +0800 Subject: [PATCH 03/14] feat(plugin): extend projection transport and host controls Add encoded video transport, display size negotiation, host settings commands, preparation and pairing callbacks. Connect browser source selection and controls to the plugin runtime, with protocol and host regression coverage. --- common/src/main/assets/web/app.js | 64 +++++-- common/src/main/assets/web/index.html | 4 +- common/src/main/assets/web/source-control.js | 20 +++ common/src/main/assets/web/style.css | 2 +- .../projection/BrowserProjectionVideo.kt | 2 + .../projection/ImageOutputDiagnostics.kt | 20 +++ .../projection/plugin/EncodedPluginVideo.kt | 102 +++++++++++ .../projection/plugin/PluginAvcStream.kt | 142 ++++++++++++++++ .../projection/plugin/PluginPreparation.kt | 27 +++ .../projection/plugin/PluginSettingsBridge.kt | 44 +++++ .../projection/plugin/ProjectionPlugins.kt | 7 +- .../projection/plugin/RemotePluginSession.kt | 87 +++++++++- .../xcertplay/web/BrowserSourceControl.kt | 62 +++++++ .../shilapi/xcertplay/web/BrowserStrings.kt | 26 +++ .../com/shilapi/xcertplay/web/LanWebServer.kt | 14 ++ .../com/shilapi/xcertplay/web/WebSession.kt | 58 +++---- .../shilapi/xcertplay/web/WebVideoSource.kt | 2 + .../moe/feng/wheelplay/AirPlayPersistence.kt | 8 + .../moe/feng/wheelplay/WheelPlayActivity.kt | 99 ++++++++--- .../moe/feng/wheelplay/ui/WheelPlayScreen.kt | 11 ++ .../moe/feng/wheelplay/ui/WheelPlayUiState.kt | 4 +- .../projection/plugin/PluginAvcStreamTest.kt | 63 +++++++ .../plugin/PluginKeyframeWaitTest.kt | 50 ++++++ .../plugin/PluginPreparationTest.kt | 29 ++++ .../plugin/PluginSettingsBridgeTest.kt | 46 +++++ .../plugin/RemotePluginSessionTest.kt | 160 ++++++++++++++++++ .../xcertplay/web/BrowserSourceControlTest.kt | 93 ++++++++++ .../moe/feng/wheelplay/LocalizationTest.kt | 6 +- .../feng/wheelplay/SourceNavigationTest.kt | 36 +++- docs/PROJECTION_PLUGINS.md | 92 +++++++++- .../plugin/PluginSurfaceIntegrationTest.kt | 4 +- .../wheelplay/plugin/IProjectionHost.aidl | 4 + .../wheelplay/plugin/IProjectionPlugin.aidl | 5 + .../feng/wheelplay/plugin/EncodedVideoWire.kt | 33 ++++ .../feng/wheelplay/plugin/ProjectionPlugin.kt | 55 +++++- .../plugin/ProjectionPluginService.kt | 93 ++++++++-- .../wheelplay/plugin/EncodedVideoWireTest.kt | 32 ++++ .../plugin/ProjectionPluginServiceTest.kt | 118 ++++++++++++- scripts/preview.mjs | 2 +- scripts/test-media-presentation.mjs | 21 ++- .../xcertplay/projection/ProjectionRuntime.kt | 43 ++++- .../xcertplay/web/FramePublishScheduler.kt | 3 +- .../xcertplay/web/OffscreenVideoOutput.kt | 2 + shared/src/main/res/values-zh-rCN/strings.xml | 41 ++++- shared/src/main/res/values-zh-rTW/strings.xml | 41 ++++- shared/src/main/res/values/strings.xml | 41 ++++- .../projection/ProjectionRuntimeTest.kt | 38 +++++ .../web/FramePublishSchedulerTest.kt | 13 ++ test/localization.test.js | 2 +- test/pairing.test.js | 2 +- test/source-control.test.js | 17 ++ test/stream-client.test.js | 56 +++--- 52 files changed, 1886 insertions(+), 160 deletions(-) create mode 100644 common/src/main/assets/web/source-control.js create mode 100644 common/src/main/java/com/shilapi/xcertplay/projection/ImageOutputDiagnostics.kt create mode 100644 common/src/main/java/com/shilapi/xcertplay/projection/plugin/EncodedPluginVideo.kt create mode 100644 common/src/main/java/com/shilapi/xcertplay/projection/plugin/PluginAvcStream.kt create mode 100644 common/src/main/java/com/shilapi/xcertplay/projection/plugin/PluginPreparation.kt create mode 100644 common/src/main/java/com/shilapi/xcertplay/projection/plugin/PluginSettingsBridge.kt create mode 100644 common/src/main/java/com/shilapi/xcertplay/web/BrowserSourceControl.kt create mode 100644 common/src/test/java/com/shilapi/xcertplay/projection/plugin/PluginAvcStreamTest.kt create mode 100644 common/src/test/java/com/shilapi/xcertplay/projection/plugin/PluginKeyframeWaitTest.kt create mode 100644 common/src/test/java/com/shilapi/xcertplay/projection/plugin/PluginPreparationTest.kt create mode 100644 common/src/test/java/com/shilapi/xcertplay/projection/plugin/PluginSettingsBridgeTest.kt create mode 100644 common/src/test/java/com/shilapi/xcertplay/web/BrowserSourceControlTest.kt create mode 100644 projection-plugin-api/src/main/java/moe/feng/wheelplay/plugin/EncodedVideoWire.kt create mode 100644 projection-plugin-api/src/test/java/moe/feng/wheelplay/plugin/EncodedVideoWireTest.kt create mode 100644 test/source-control.test.js diff --git a/common/src/main/assets/web/app.js b/common/src/main/assets/web/app.js index e5e91c0a..ffba0d1d 100644 --- a/common/src/main/assets/web/app.js +++ b/common/src/main/assets/web/app.js @@ -1,3 +1,4 @@ +import { sourcePanel } from './source-control.js'; import { t } from './text.js'; import { createDesktopInput } from './desktop-input.js'; // A surface inversely scaled inside the visual viewport cancels browser zoom. @@ -378,7 +379,7 @@ export function createControlOutbox(socket, { if (kind === 'move' && tail && tail.kind === 'move' && tail.type === data.type && tail.eventKind === data.kind) tail.json = json; else if (touches.length < 64) touches.push({ kind, json, type: data.type, eventKind: data.kind }); else { fail(); return false; } - } else if (['rtc-start', 'rtc-answer', 'rtc-ready', 'rtc-fallback', 'phone-connect', 'image-format', 'location-start', 'location-stop', 'location-clear', 'media-command'].includes(data.type)) { + } else if (['rtc-start', 'rtc-answer', 'rtc-ready', 'rtc-fallback', 'phone-connect', 'source-action', 'image-format', 'location-start', 'location-stop', 'location-clear', 'media-command'].includes(data.type)) { if (signals.length >= 8 || json.length > 32768) { fail(); return false; } if (data.type.startsWith('location-')) locationFix = null; signals.push(json); @@ -1010,6 +1011,8 @@ if (typeof document !== 'undefined') { const webpSupport = probeWebp(); Object.defineProperty(window, 'wheelplayStats', { configurable: true, get: () => JSON.parse(JSON.stringify(performanceStats)) }); let rtc = null, rtcRequested = false, rtcFps = null; + let sourceControl = null, sourceRequest = null, sourceReply = '', sourceSequence = 0; + let sourceRequestTimer = null; let socket = null, stopped = true, paired = false, retry = null, attempts = 0; let width = 1280, height = 720, live = false, lastStatus = 0, rtcMedia = {}; let heartbeat = null, movePending = false, moveGeneration = 0, outbox = null; @@ -1377,6 +1380,15 @@ if (typeof document !== 'undefined') { for (const surface of [...screens, video, canvas, heldFrame].filter(Boolean)) surface.classList.toggle('stale', !value.visible); touchSurface.classList.toggle('stale', !live); $('waiting').hidden = value.visible; + const panel = sourcePanel(sourceControl, value, !!rendererStats.fallbackReason); + $('stage').textContent = t(panel.title, panel.name || ''); + $('source-action').hidden = !panel.action; + $('source-action').disabled = sourceRequest !== null; + $('source-action').textContent = t(panel.label || 'web_source_connect', panel.name || ''); + $('source-message').textContent = sourceReply || (!sourceControl?.activeId && sourceControl?.notice) || t(panel.hint, panel.name || ''); + $('media-retry').hidden = !panel.retry; + $('source-stop').hidden = !value.visible || sourceControl?.action !== 'stop'; + $('source-stop').disabled = sourceRequest !== null; $('desktop-back').disabled = !live; if (!live && (pointers.size || desktop.active)) release(); const rtcVisible = rtc && value.visible && value.frame?.transport === 'rtc'; @@ -1386,7 +1398,7 @@ if (typeof document !== 'undefined') { const transport = rtcVisible ? `${rtc.codec === 'H265' ? 'HEVC' : 'H.264'} / WebRTC / ${rendererLabel}${rtcFps === null ? '' : ` · ${rtcFps} fps`}` : `${value.frame?.mime === 'image/webp' ? 'WebP' : 'JPEG'}${fallbackLabel}`; $('status').textContent = value.state === 'recovering' ? t('web_video_recovering', transport) : value.visible ? value.interactive ? t('web_transport_touch_connected', transport, rtc?.recovering ? t('web_waiting_for_recovery') : '') : - t('web_video_input_unavailable', transport) : t('web_connected_waiting_for_iphone_video'); + t('web_video_input_unavailable', transport) : t('web_source_waiting'); $('media-message').hidden = !value.visible || value.interactive; $('media-message').textContent = value.visible && !value.interactive ? $('status').textContent : ''; renderDebug(); @@ -1550,8 +1562,9 @@ if (typeof document !== 'undefined') { }, }); $('message').textContent = ''; - $('phone-connect').disabled = false; - $('phone-connect-message').textContent = t("web_keep_wheelplay_in_the_foreground_on_android_tap_connect"); + sourceControl = null; sourceRequest = null; sourceReply = ''; clearTimeout(sourceRequestTimer); + $('media-retry').disabled = false; + presentation.refresh(); $('pairing').hidden = true; $('display').hidden = false; $('topbar').hidden = true; lastViewportSignature = ''; @@ -1585,15 +1598,22 @@ if (typeof document !== 'undefined') { } rtc.receive(data); return; } - if (data.type === 'phone-connect-result') { - $('phone-connect').disabled = false; - $('phone-connect-message').textContent = data.message; - return; + if (data.type === 'source-action-result') { + if (data.requestId !== sourceRequest) return; + sourceRequest = null; clearTimeout(sourceRequestTimer); + const messages = { requested: 'web_source_request_sent', configure: 'web_source_android_help', + stopped: 'web_source_stopped', pending: 'web_source_pending', stale: 'web_source_changed', failed: 'web_source_failed' }; + sourceReply = t(messages[data.result] || 'web_source_failed'); + presentation.refresh(); send({ type: 'ping' }); return; } if (data.type === 'busy') { const message = data.message; disconnect(); $('message').textContent = message; return; } if (data.type === 'status') { + if (sourceControl?.revision !== data.sourceControl?.revision) { + sourceReply = ''; sourceRequest = null; clearTimeout(sourceRequestTimer); + } + sourceControl = data.sourceControl?.version === 1 ? data.sourceControl : null; performanceStats.source = data.performance?.source ?? null; performanceStats.transport = data.performance?.transport ?? null; performanceStats.image = data.performance?.image ?? null; @@ -1611,7 +1631,8 @@ if (typeof document !== 'undefined') { jpeg.cancelPending(); if (rtcMedia.revision !== presentation.current.revision) { rtc.close(); rtcRequested = false; } } - $('stage').textContent = data.stage || t("web_waiting_for_iphone_video"); + $('source-detail').textContent = data.sourceError ? data.stage || '' : ''; + $('source-detail').hidden = !data.sourceError; rtc.progress(data.rtcFrames || 0); if (data.rtcAvailable && !rtcRequested && !rtc.active && typeof RTCPeerConnection !== 'undefined' && (mode !== 'track-canvas' || processorSupported())) { @@ -1648,6 +1669,7 @@ if (typeof document !== 'undefined') { clearTimeout(connectTimer); if (socket !== ws) return; if (settingsDialog.open) settingsDialog.close(); + clearTimeout(sourceRequestTimer); sourceRequest = null; sourceControl = null; sourceReply = ''; if (outbox) { outbox.close(); outbox = null; } cancelMove(); socket = null; pointers.clear(); desktop.release(false); pointerInput = false; keyboardInput = false; backButton = false; $('desktop-back').hidden = true; @@ -1720,13 +1742,23 @@ if (typeof document !== 'undefined') { } })(); }); - $('phone-connect').addEventListener('click', () => { - if (!paired || !send({ type: 'phone-connect' })) { - $('phone-connect-message').textContent = t("web_browser_connection_interrupted_pair_again_and_retry"); - return; - } - $('phone-connect').disabled = true; - $('phone-connect-message').textContent = t("web_requesting_iphone_connection"); + function requestSourceAction() { + if (!sourceControl?.action || sourceRequest || !socket || socket.readyState !== WebSocket.OPEN) return; + const requestId = String(++sourceSequence); + if (!send({ type: 'source-action', requestId, action: sourceControl.action, + sourceId: sourceControl.activeId || sourceControl.selectedId, revision: sourceControl.revision })) return; + sourceRequest = requestId; sourceReply = t('web_source_pending'); presentation.refresh(); + sourceRequestTimer = setTimeout(() => { + if (sourceRequest !== requestId) return; + sourceRequest = null; sourceReply = t('web_source_failed'); presentation.refresh(); + }, 10000); + } + $('source-action').addEventListener('click', requestSourceAction); + $('source-stop').addEventListener('click', requestSourceAction); + $('media-retry').addEventListener('click', () => { + // Reopen only the browser transport. The Android source and its SDK keep running. + $('media-retry').disabled = true; + socket?.close(); }); async function toggleFullscreen() { try { diff --git a/common/src/main/assets/web/index.html b/common/src/main/assets/web/index.html index 062c9e15..0c963392 100644 --- a/common/src/main/assets/web/index.html +++ b/common/src/main/assets/web/index.html @@ -61,7 +61,7 @@

{{ui_settings}}

-
+