mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-11-25 23:30:28 +00:00
fix(android): move the log toggle native into ffi.FFI (#16993)
* fix(android): move the log toggle native into ffi.FFI Custom clients move the Kotlin classes out of com.carriez.flutter_hbb. DocumentLogs declared setEnabled as a native method, so its export Java_com_carriez_flutter_1hbb_DocumentLogs_setEnabled did not link there and the app crashed on start with UnsatisfiedLinkError. The ffi package keeps its name, so declare the native in ffi.FFI like the others and call it from DocumentLogs. Fixes rustdesk/rustdesk-server-pro#1035 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JAxkkiaGp2k8okvs4MpCUq * ci(android): fail when a JNI native is outside ffi.FFI Only ffi.FFI survives the package rename custom clients do. Check in the Android build that every Rust JNI export is Java_ffi_FFI_* and that no Kotlin file but ffi.kt declares an external fun, and write the rule down in AGENTS.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JAxkkiaGp2k8okvs4MpCUq * ci(android): report every JNI rule violation and check class lookups Run the checks independently so one CI round lists both the Rust and the Kotlin offenders, and also fail on a Rust lookup of an app class by name. Note in AGENTS.md that a Kotlin method Rust calls by name needs @Keep to survive R8. 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:
1 parent
1ac53ccb1b
commit
3ccb4c4b5b
5 files changed
+24
-3
No files matched your search
@@ -1512,6 +1512,20 @@ jobs:
|
||||
with:
|
||||
submodules: recursive
|
||||
|
||||
- name: Check JNI natives are in ffi.FFI
|
||||
# Custom clients rename com.carriez.flutter_hbb; only ffi.FFI keeps its name.
|
||||
shell: bash
|
||||
run: |
|
||||
bad=0
|
||||
grep -rnE --include='*.rs' 'fn Java_' src libs | grep -v 'fn Java_ffi_FFI_' && bad=1
|
||||
grep -rl --include='*.kt' 'external fun' flutter/android \
|
||||
| grep -vx 'flutter/android/app/src/main/kotlin/ffi.kt' && bad=1
|
||||
grep -rn --include='*.rs' 'com/carriez' src libs && bad=1
|
||||
if [ "$bad" = 1 ]; then
|
||||
echo "::error::Declare Android natives in ffi.FFI, export them as Java_ffi_FFI_*, and do not look up app classes by name (see AGENTS.md)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Install flutter
|
||||
uses: subosito/flutter-action@1a449444c387b1966244ae4d4f8c696479add0b2 # v2
|
||||
with:
|
||||
|
||||
@@ -80,6 +80,12 @@ workspace member. `base::config::keys` re-exports the handful of keys
|
||||
* Web bridge (committed): edit `flutter/lib/web/bridge.dart` directly. Follow the existing patterns there for `SyncReturn<T>` / `Future<T>` and the `dart:js` glue.
|
||||
* Native bridge (`flutter/lib/generated_bridge.dart`, `src/bridge_generated.rs`, `src/bridge_generated.io.rs`): these are gitignored and regenerated by the project's CI codegen. Manually editing them locally is fine for development testing, but those edits do not persist into commits.
|
||||
|
||||
## Android JNI
|
||||
|
||||
* Custom clients move the Kotlin classes out of `com.carriez.flutter_hbb` into their own package; only the `ffi` package keeps its name. A `Java_com_carriez_flutter_1hbb_*` export therefore does not link there and the app crashes with `UnsatisfiedLinkError`.
|
||||
* Declare every `external fun` in `ffi.FFI` (`flutter/android/app/src/main/kotlin/ffi.kt`) and export it from Rust as `Java_ffi_FFI_*`. A class elsewhere that needs one calls it through `FFI`.
|
||||
* From Rust, reach app classes only through objects Kotlin passed in (`call_method` on a `GlobalRef`), never by a class name such as `find_class("com/carriez/...")`. Mark each Kotlin method Rust calls this way `@Keep`, or R8 renames it in release builds and the call fails with `NoSuchMethodError`.
|
||||
|
||||
## Web (Flutter Web) Architecture
|
||||
|
||||
Flutter Web in this repo is **not** "Dart compiled to JS via Flutter alone". The runtime is split:
|
||||
|
||||
@@ -7,6 +7,7 @@ import android.os.ParcelFileDescriptor
|
||||
import android.provider.DocumentsContract
|
||||
import android.provider.DocumentsContract.Document
|
||||
import android.util.Log
|
||||
import ffi.FFI
|
||||
import java.io.FileNotFoundException
|
||||
import java.io.IOException
|
||||
import java.util.UUID
|
||||
@@ -31,8 +32,7 @@ internal class DocumentLogs(private val context: Context) {
|
||||
setEnabled(grant() != null)
|
||||
}
|
||||
|
||||
@androidx.annotation.Keep
|
||||
private external fun setEnabled(enabled: Boolean)
|
||||
private fun setEnabled(enabled: Boolean) = FFI.setDocumentLogsEnabled(enabled)
|
||||
|
||||
private fun grant(): Uri? = prefs.getString(LOG_GRANT, null)?.let(Uri::parse)
|
||||
|
||||
|
||||
@@ -28,4 +28,5 @@ object FFI {
|
||||
external fun getBuildinOption(key: String): String
|
||||
external fun onClipboardUpdate(clips: ByteBuffer)
|
||||
external fun isServiceClipboardEnabled(): Boolean
|
||||
external fun setDocumentLogsEnabled(enabled: Boolean)
|
||||
}
|
||||
@@ -26,7 +26,7 @@ const DEFAULT_LOG_FILE_COUNT: usize = 90;
|
||||
static PUBLIC_LOGS_ENABLED: AtomicBool = AtomicBool::new(true);
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "system" fn Java_com_carriez_flutter_1hbb_DocumentLogs_setEnabled(
|
||||
pub extern "system" fn Java_ffi_FFI_setDocumentLogsEnabled(
|
||||
_env: jni::JNIEnv,
|
||||
_instance: jni::objects::JObject,
|
||||
enabled: jni::sys::jboolean,
|
||||
|
||||
Reference in new issue
Block a user