1. sync from flutter and pass app_dir from MainService.kt to backend server when app start on boot.
2. add start_service when start on boot.
This commit is contained in:
parent
be2fa3e444
commit
f26088765e
@ -34,6 +34,7 @@ class BootReceiver : BroadcastReceiver() {
|
|||||||
|
|
||||||
val it = Intent(context, MainService::class.java).apply {
|
val it = Intent(context, MainService::class.java).apply {
|
||||||
action = ACT_INIT_MEDIA_PROJECTION_AND_SERVICE
|
action = ACT_INIT_MEDIA_PROJECTION_AND_SERVICE
|
||||||
|
putExtra(EXT_INIT_FROM_BOOT, true)
|
||||||
}
|
}
|
||||||
Toast.makeText(context, "RustDesk is Open", Toast.LENGTH_LONG).show()
|
Toast.makeText(context, "RustDesk is Open", Toast.LENGTH_LONG).show()
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
@ -15,7 +15,6 @@ import android.os.Build
|
|||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.view.WindowManager
|
import android.view.WindowManager
|
||||||
import androidx.annotation.RequiresApi
|
|
||||||
import com.hjq.permissions.XXPermissions
|
import com.hjq.permissions.XXPermissions
|
||||||
import io.flutter.embedding.android.FlutterActivity
|
import io.flutter.embedding.android.FlutterActivity
|
||||||
import io.flutter.embedding.engine.FlutterEngine
|
import io.flutter.embedding.engine.FlutterEngine
|
||||||
@ -31,7 +30,6 @@ class MainActivity : FlutterActivity() {
|
|||||||
private val logTag = "mMainActivity"
|
private val logTag = "mMainActivity"
|
||||||
private var mainService: MainService? = null
|
private var mainService: MainService? = null
|
||||||
|
|
||||||
@RequiresApi(Build.VERSION_CODES.M)
|
|
||||||
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
|
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
|
||||||
super.configureFlutterEngine(flutterEngine)
|
super.configureFlutterEngine(flutterEngine)
|
||||||
if (MainService.isReady) {
|
if (MainService.isReady) {
|
||||||
@ -208,6 +206,17 @@ class MainActivity : FlutterActivity() {
|
|||||||
result.success(false)
|
result.success(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
SYNC_APP_DIR_CONFIG_PATH -> {
|
||||||
|
if (call.arguments is String) {
|
||||||
|
val prefs = getSharedPreferences(KEY_SHARED_PREFERENCES, MODE_PRIVATE)
|
||||||
|
val edit = prefs.edit()
|
||||||
|
edit.putString(KEY_APP_DIR_CONFIG_PATH, call.arguments as String)
|
||||||
|
edit.apply()
|
||||||
|
result.success(true)
|
||||||
|
} else {
|
||||||
|
result.success(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
else -> {
|
else -> {
|
||||||
result.error("-1", "No such method", null)
|
result.error("-1", "No such method", null)
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,7 @@ import androidx.annotation.RequiresApi
|
|||||||
import androidx.core.app.ActivityCompat
|
import androidx.core.app.ActivityCompat
|
||||||
import androidx.core.app.NotificationCompat
|
import androidx.core.app.NotificationCompat
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
|
import io.flutter.embedding.android.FlutterActivity
|
||||||
import java.util.concurrent.Executors
|
import java.util.concurrent.Executors
|
||||||
import kotlin.concurrent.thread
|
import kotlin.concurrent.thread
|
||||||
import org.json.JSONException
|
import org.json.JSONException
|
||||||
@ -143,7 +144,11 @@ class MainService : Service() {
|
|||||||
|
|
||||||
// jvm call rust
|
// jvm call rust
|
||||||
private external fun init(ctx: Context)
|
private external fun init(ctx: Context)
|
||||||
private external fun startServer()
|
|
||||||
|
/// When app start on boot, app_dir will not be passed from flutter
|
||||||
|
/// so pass a app_dir here to rust server
|
||||||
|
private external fun startServer(app_dir: String)
|
||||||
|
private external fun startService()
|
||||||
private external fun onVideoFrameUpdate(buf: ByteBuffer)
|
private external fun onVideoFrameUpdate(buf: ByteBuffer)
|
||||||
private external fun onAudioFrameUpdate(buf: ByteBuffer)
|
private external fun onAudioFrameUpdate(buf: ByteBuffer)
|
||||||
private external fun translateLocale(localeName: String, input: String): String
|
private external fun translateLocale(localeName: String, input: String): String
|
||||||
@ -199,7 +204,12 @@ class MainService : Service() {
|
|||||||
}
|
}
|
||||||
updateScreenInfo(resources.configuration.orientation)
|
updateScreenInfo(resources.configuration.orientation)
|
||||||
initNotification()
|
initNotification()
|
||||||
startServer()
|
|
||||||
|
// keep the config dir same with flutter
|
||||||
|
val prefs = applicationContext.getSharedPreferences(KEY_SHARED_PREFERENCES, FlutterActivity.MODE_PRIVATE)
|
||||||
|
val configPath = prefs.getString(KEY_APP_DIR_CONFIG_PATH, "") ?: ""
|
||||||
|
startServer(configPath)
|
||||||
|
|
||||||
createForegroundNotification()
|
createForegroundNotification()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -279,6 +289,10 @@ class MainService : Service() {
|
|||||||
super.onStartCommand(intent, flags, startId)
|
super.onStartCommand(intent, flags, startId)
|
||||||
if (intent?.action == ACT_INIT_MEDIA_PROJECTION_AND_SERVICE) {
|
if (intent?.action == ACT_INIT_MEDIA_PROJECTION_AND_SERVICE) {
|
||||||
createForegroundNotification()
|
createForegroundNotification()
|
||||||
|
|
||||||
|
if (intent.getBooleanExtra(EXT_INIT_FROM_BOOT, false)) {
|
||||||
|
startService()
|
||||||
|
}
|
||||||
Log.d(logTag, "service starting: ${startId}:${Thread.currentThread()}")
|
Log.d(logTag, "service starting: ${startId}:${Thread.currentThread()}")
|
||||||
val mediaProjectionManager =
|
val mediaProjectionManager =
|
||||||
getSystemService(MEDIA_PROJECTION_SERVICE) as MediaProjectionManager
|
getSystemService(MEDIA_PROJECTION_SERVICE) as MediaProjectionManager
|
||||||
|
@ -27,6 +27,7 @@ import java.util.*
|
|||||||
const val ACT_REQUEST_MEDIA_PROJECTION = "REQUEST_MEDIA_PROJECTION"
|
const val ACT_REQUEST_MEDIA_PROJECTION = "REQUEST_MEDIA_PROJECTION"
|
||||||
const val ACT_INIT_MEDIA_PROJECTION_AND_SERVICE = "INIT_MEDIA_PROJECTION_AND_SERVICE"
|
const val ACT_INIT_MEDIA_PROJECTION_AND_SERVICE = "INIT_MEDIA_PROJECTION_AND_SERVICE"
|
||||||
const val ACT_LOGIN_REQ_NOTIFY = "LOGIN_REQ_NOTIFY"
|
const val ACT_LOGIN_REQ_NOTIFY = "LOGIN_REQ_NOTIFY"
|
||||||
|
const val EXT_INIT_FROM_BOOT = "EXT_INIT_FROM_BOOT"
|
||||||
const val EXT_MEDIA_PROJECTION_RES_INTENT = "MEDIA_PROJECTION_RES_INTENT"
|
const val EXT_MEDIA_PROJECTION_RES_INTENT = "MEDIA_PROJECTION_RES_INTENT"
|
||||||
const val EXT_LOGIN_REQ_NOTIFY = "LOGIN_REQ_NOTIFY"
|
const val EXT_LOGIN_REQ_NOTIFY = "LOGIN_REQ_NOTIFY"
|
||||||
|
|
||||||
@ -41,9 +42,11 @@ const val RES_FAILED = -100
|
|||||||
const val START_ACTION = "start_action"
|
const val START_ACTION = "start_action"
|
||||||
const val GET_START_ON_BOOT_OPT = "get_start_on_boot_opt"
|
const val GET_START_ON_BOOT_OPT = "get_start_on_boot_opt"
|
||||||
const val SET_START_ON_BOOT_OPT = "set_start_on_boot_opt"
|
const val SET_START_ON_BOOT_OPT = "set_start_on_boot_opt"
|
||||||
|
const val SYNC_APP_DIR_CONFIG_PATH = "sync_app_dir"
|
||||||
|
|
||||||
const val KEY_SHARED_PREFERENCES = "KEY_SHARED_PREFERENCES"
|
const val KEY_SHARED_PREFERENCES = "KEY_SHARED_PREFERENCES"
|
||||||
const val KEY_START_ON_BOOT_OPT = "KEY_START_ON_BOOT_OPT"
|
const val KEY_START_ON_BOOT_OPT = "KEY_START_ON_BOOT_OPT"
|
||||||
|
const val KEY_APP_DIR_CONFIG_PATH = "KEY_APP_DIR_CONFIG_PATH"
|
||||||
|
|
||||||
@SuppressLint("ConstantLocale")
|
@SuppressLint("ConstantLocale")
|
||||||
val LOCAL_NAME = Locale.getDefault().toString()
|
val LOCAL_NAME = Locale.getDefault().toString()
|
||||||
|
@ -153,6 +153,7 @@ class AndroidChannel {
|
|||||||
static final kStartAction = "start_action";
|
static final kStartAction = "start_action";
|
||||||
static final kGetStartOnBootOpt = "get_start_on_boot_opt";
|
static final kGetStartOnBootOpt = "get_start_on_boot_opt";
|
||||||
static final kSetStartOnBootOpt = "set_start_on_boot_opt";
|
static final kSetStartOnBootOpt = "set_start_on_boot_opt";
|
||||||
|
static final kSyncAppDirConfigPath = "sync_app_dir";
|
||||||
}
|
}
|
||||||
|
|
||||||
/// flutter/packages/flutter/lib/src/services/keyboard_key.dart -> _keyLabels
|
/// flutter/packages/flutter/lib/src/services/keyboard_key.dart -> _keyLabels
|
||||||
|
@ -153,6 +153,7 @@ void runMainApp(bool startService) async {
|
|||||||
void runMobileApp() async {
|
void runMobileApp() async {
|
||||||
await initEnv(kAppTypeMain);
|
await initEnv(kAppTypeMain);
|
||||||
if (isAndroid) androidChannelInit();
|
if (isAndroid) androidChannelInit();
|
||||||
|
platformFFI.syncAndroidServiceAppDirConfigPath();
|
||||||
runApp(App());
|
runApp(App());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +57,6 @@ class PlatformFFI {
|
|||||||
F5Dart? _session_next_rgba;
|
F5Dart? _session_next_rgba;
|
||||||
F6Dart? _session_register_texture;
|
F6Dart? _session_register_texture;
|
||||||
|
|
||||||
|
|
||||||
static get localeName => Platform.localeName;
|
static get localeName => Platform.localeName;
|
||||||
|
|
||||||
static get isMain => instance._appType == kAppTypeMain;
|
static get isMain => instance._appType == kAppTypeMain;
|
||||||
@ -162,7 +161,8 @@ class PlatformFFI {
|
|||||||
dylib.lookupFunction<F4, F4Dart>("session_get_rgba_size");
|
dylib.lookupFunction<F4, F4Dart>("session_get_rgba_size");
|
||||||
_session_next_rgba =
|
_session_next_rgba =
|
||||||
dylib.lookupFunction<F5, F5Dart>("session_next_rgba");
|
dylib.lookupFunction<F5, F5Dart>("session_next_rgba");
|
||||||
_session_register_texture = dylib.lookupFunction<F6, F6Dart>("session_register_texture");
|
_session_register_texture =
|
||||||
|
dylib.lookupFunction<F6, F6Dart>("session_register_texture");
|
||||||
try {
|
try {
|
||||||
// SYSTEM user failed
|
// SYSTEM user failed
|
||||||
_dir = (await getApplicationDocumentsDirectory()).path;
|
_dir = (await getApplicationDocumentsDirectory()).path;
|
||||||
@ -301,4 +301,8 @@ class PlatformFFI {
|
|||||||
if (!isAndroid) return Future<bool>(() => false);
|
if (!isAndroid) return Future<bool>(() => false);
|
||||||
return await _toAndroidChannel.invokeMethod(method, arguments);
|
return await _toAndroidChannel.invokeMethod(method, arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void syncAndroidServiceAppDirConfigPath() {
|
||||||
|
invokeMethod(AndroidChannel.kSyncAppDirConfigPath, _dir);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1361,7 +1361,7 @@ pub fn send_url_scheme(_url: String) {
|
|||||||
|
|
||||||
#[cfg(target_os = "android")]
|
#[cfg(target_os = "android")]
|
||||||
pub mod server_side {
|
pub mod server_side {
|
||||||
use hbb_common::log;
|
use hbb_common::{log, config};
|
||||||
use jni::{
|
use jni::{
|
||||||
objects::{JClass, JString},
|
objects::{JClass, JString},
|
||||||
sys::jstring,
|
sys::jstring,
|
||||||
@ -1374,11 +1374,25 @@ pub mod server_side {
|
|||||||
pub unsafe extern "system" fn Java_com_carriez_flutter_1hbb_MainService_startServer(
|
pub unsafe extern "system" fn Java_com_carriez_flutter_1hbb_MainService_startServer(
|
||||||
env: JNIEnv,
|
env: JNIEnv,
|
||||||
_class: JClass,
|
_class: JClass,
|
||||||
|
app_dir: JString,
|
||||||
) {
|
) {
|
||||||
log::debug!("startServer from java");
|
log::debug!("startServer from jvm");
|
||||||
|
if let Ok(app_dir) = env.get_string(app_dir) {
|
||||||
|
*config::APP_DIR.write().unwrap() = app_dir.into();
|
||||||
|
}
|
||||||
std::thread::spawn(move || start_server(true));
|
std::thread::spawn(move || start_server(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "system" fn Java_com_carriez_flutter_1hbb_MainService_startService(
|
||||||
|
env: JNIEnv,
|
||||||
|
_class: JClass,
|
||||||
|
) {
|
||||||
|
log::debug!("startService from jvm");
|
||||||
|
config::Config::set_option("stop-service".into(), "".into());
|
||||||
|
crate::rendezvous_mediator::RendezvousMediator::restart();
|
||||||
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "system" fn Java_com_carriez_flutter_1hbb_MainService_translateLocale(
|
pub unsafe extern "system" fn Java_com_carriez_flutter_1hbb_MainService_translateLocale(
|
||||||
env: JNIEnv,
|
env: JNIEnv,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user