fix(android): sync input service state to enable-keyboard without the UI (#17064)

* Sync the Android input service state to enable-keyboard from Kotlin

enable-keyboard mirrors whether InputService is running, but only the
Flutter UI updated it. When the service was turned on from system
settings while the UI was not running, the option stayed N and new
connections were denied keyboard permission until the app was opened.

InputService now reports its state directly, and MainService reports it
again once startServer has set the config directory.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JAxkkiaGp2k8okvs4MpCUq

* Stop the Android UI from resetting enable-keyboard on start

ServerModel set enable-keyboard to N on every mobile UI start and relied
on the input state message to set it back. Until that message arrived,
open connections lost keyboard permission. Android now keeps the option
in step with InputService natively, so keep the reset on iOS only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JAxkkiaGp2k8okvs4MpCUq

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
RustDeskandClaude Opus 5.5 authored and GitHub committed 2026-11-15 22:58:13 +08:00
1 parent fcb485bb90
commit 506e111460
5 files changed
+25 -2

No files matched your search

@@ -35,6 +35,7 @@ import kotlin.math.max
import hbb.MessageOuterClass.KeyEvent
import hbb.MessageOuterClass.KeyboardMode
import hbb.KeyEventConverter
import ffi.FFI
// const val BUTTON_UP = 2
// const val BUTTON_BACK = 0x08
@@ -79,6 +80,8 @@ class InputService : AccessibilityService() {
}
private fun notifyInputState() {
// The Flutter UI may not be running to forward this, e.g. when enabled from system settings.
FFI.setInputServiceOpen(isOpen)
val inputState = isOpen.toString()
Handler(Looper.getMainLooper()).post {
MainActivity.flutterMethodChannel?.invokeMethod(
@@ -254,6 +254,7 @@ class MainService : Service() {
val homePath = applicationContext.getExternalFilesDir(null)?.absolutePath
?: applicationContext.filesDir.absolutePath
FFI.startServer(configPath, homePath, "")
FFI.setInputServiceOpen(InputService.isOpen)
createForegroundNotification()
}
@@ -29,4 +29,5 @@ object FFI {
external fun onClipboardUpdate(clips: ByteBuffer)
external fun isServiceClipboardEnabled(): Boolean
external fun setDocumentLogsEnabled(enabled: Boolean)
external fun setInputServiceOpen(open: Boolean)
}
+2 -2
View File
@@ -191,8 +191,8 @@ class ServerModel with ChangeNotifier {
});
}
// Initial keyboard status is off on mobile
if (isMobile) {
// Initial keyboard status is off on iOS; Android syncs it from InputService natively.
if (isIOS) {
bind.mainSetOption(key: kOptionEnableKeyboard, value: 'N');
}
}
+18
View File
@@ -3186,4 +3186,22 @@ pub mod server_side {
) -> jboolean {
jboolean::from(crate::server::is_clipboard_service_ok())
}
/// Keeps `enable-keyboard` in step with InputService when the Flutter UI is not running.
#[no_mangle]
pub unsafe extern "system" fn Java_ffi_FFI_setInputServiceOpen(
_env: JNIEnv,
_class: JClass,
open: jboolean,
) {
// Config must not load before startServer sets APP_DIR; MainService syncs again after it.
if config::APP_DIR.read().unwrap().is_empty() {
return;
}
let key = super::keys::OPTION_ENABLE_KEYBOARD;
let value = if open == 0 { "N" } else { "Y" };
if let Err(e) = super::main_set_option(key.to_owned(), value.to_owned()) {
log::error!("Failed to sync input service state: {}", e);
}
}
}