Skip to content

Commit

Permalink
fix: Android 29, crash on restart and reconn (rustdesk#10054)
Browse files Browse the repository at this point in the history
Signed-off-by: fufesou <[email protected]>
  • Loading branch information
fufesou authored Nov 25, 2024
1 parent 30a11bf commit d61c99b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ import com.hjq.permissions.XXPermissions
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodChannel
import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel.MethodCallHandler
import io.flutter.plugin.common.MethodChannel.Result
import kotlin.concurrent.thread


Expand Down Expand Up @@ -66,7 +62,6 @@ class MainActivity : FlutterActivity() {
channelTag
)
initFlutterChannel(flutterMethodChannel!!)
flutterEngine.plugins.add(ContextPlugin())
thread { setCodecInfo() }
}

Expand Down Expand Up @@ -417,16 +412,3 @@ class MainActivity : FlutterActivity() {
}
}
}

// https://cjycode.com/flutter_rust_bridge/guides/how-to/ndk-init
class ContextPlugin : FlutterPlugin, MethodCallHandler {
override fun onAttachedToEngine(flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
FFI.initContext(flutterPluginBinding.applicationContext)
}
override fun onMethodCall(call: MethodCall, result: Result) {
result.notImplemented()
}

override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) {
}
}
1 change: 0 additions & 1 deletion flutter/android/app/src/main/kotlin/ffi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ object FFI {
}

external fun init(ctx: Context)
external fun initContext(ctx: Context)
external fun setClipboardManager(clipboardManager: RdClipboardManager)
external fun startServer(app_dir: String, custom_client_config: String)
external fun startService()
Expand Down
30 changes: 9 additions & 21 deletions libs/scrap/src/android/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,18 +205,6 @@ pub extern "system" fn Java_ffi_FFI_init(env: JNIEnv, _class: JClass, ctx: JObje
}
}

#[no_mangle]
pub extern "system" fn Java_ffi_FFI_initContext(env: JNIEnv, _class: JClass, ctx: JObject) {
log::debug!("MainActivity initContext from java");
if let Ok(jvm) = env.get_java_vm() {
if let Ok(context) = env.new_global_ref(ctx) {
let java_vm = jvm.get_java_vm_pointer() as *mut c_void;
let context_jobject = context.as_obj().as_raw() as *mut c_void;
init_ndk_context(java_vm, context_jobject);
}
}
}

#[no_mangle]
pub extern "system" fn Java_ffi_FFI_setClipboardManager(
env: JNIEnv,
Expand Down Expand Up @@ -482,12 +470,12 @@ fn init_ndk_context(java_vm: *mut c_void, context_jobject: *mut c_void) {
*lock = true;
}

// // https://cjycode.com/flutter_rust_bridge/guides/how-to/ndk-init
// #[no_mangle]
// pub extern "C" fn JNI_OnLoad(vm: jni::JavaVM, res: *mut std::os::raw::c_void) -> jni::sys::jint {
// if let Ok(env) = vm.get_env() {
// let vm = vm.get_java_vm_pointer() as *mut std::os::raw::c_void;
// init_ndk_context(vm, res);
// }
// jni::JNIVersion::V6.into()
// }
// https://cjycode.com/flutter_rust_bridge/guides/how-to/ndk-init
#[no_mangle]
pub extern "C" fn JNI_OnLoad(vm: jni::JavaVM, res: *mut std::os::raw::c_void) -> jni::sys::jint {
if let Ok(env) = vm.get_env() {
let vm = vm.get_java_vm_pointer() as *mut std::os::raw::c_void;
init_ndk_context(vm, res);
}
jni::JNIVersion::V6.into()
}

0 comments on commit d61c99b

Please sign in to comment.