From 1d034551c99bf98aecca1f9272a9b52bd02d5d98 Mon Sep 17 00:00:00 2001 From: LinZong Date: Sun, 18 Aug 2024 17:47:54 +0800 Subject: [PATCH] Listen for shizuku binder in Application --- .../moe/nemesiss/hostman/HostmanApplication.kt | 15 +++++++++++++++ .../java/moe/nemesiss/hostman/MainActivity.kt | 10 ---------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/moe/nemesiss/hostman/HostmanApplication.kt b/app/src/main/java/moe/nemesiss/hostman/HostmanApplication.kt index 11d537f..302aec4 100644 --- a/app/src/main/java/moe/nemesiss/hostman/HostmanApplication.kt +++ b/app/src/main/java/moe/nemesiss/hostman/HostmanApplication.kt @@ -4,7 +4,9 @@ import android.app.Application import android.content.Context import android.os.Build import android.util.Log +import moe.nemesiss.hostman.model.viewmodel.ShizukuStateModel import org.lsposed.hiddenapibypass.HiddenApiBypass +import rikka.shizuku.Shizuku import rikka.sui.Sui class HostmanApplication : Application() { @@ -16,6 +18,19 @@ class HostmanApplication : Application() { Log.w("HostmanApplication", "Sui had been initialized. isSui: $sui") } + override fun onCreate() { + super.onCreate() + Shizuku.addBinderReceivedListenerSticky(ShizukuStateModel) + Shizuku.addBinderDeadListener(ShizukuStateModel) + Shizuku.addRequestPermissionResultListener(ShizukuStateModel) + } + + override fun onTerminate() { + Shizuku.removeBinderReceivedListener(ShizukuStateModel) + Shizuku.removeBinderDeadListener(ShizukuStateModel) + Shizuku.removeRequestPermissionResultListener(ShizukuStateModel) + super.onTerminate() + } override fun attachBaseContext(base: Context?) { super.attachBaseContext(base) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { diff --git a/app/src/main/java/moe/nemesiss/hostman/MainActivity.kt b/app/src/main/java/moe/nemesiss/hostman/MainActivity.kt index 939bc2a..96a739e 100644 --- a/app/src/main/java/moe/nemesiss/hostman/MainActivity.kt +++ b/app/src/main/java/moe/nemesiss/hostman/MainActivity.kt @@ -28,7 +28,6 @@ import kotlinx.coroutines.launch import moe.nemesiss.hostman.model.viewmodel.ShizukuState import moe.nemesiss.hostman.model.viewmodel.ShizukuStateModel import moe.nemesiss.hostman.ui.theme.HostmanTheme -import rikka.shizuku.Shizuku class MainActivity : ComponentActivity() { @@ -37,9 +36,6 @@ class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - Shizuku.addBinderReceivedListenerSticky(viewModel) - Shizuku.addBinderDeadListener(viewModel) - Shizuku.addRequestPermissionResultListener(viewModel) setContent { HostmanTheme { @@ -58,12 +54,6 @@ class MainActivity : ComponentActivity() { } } - override fun onDestroy() { - Shizuku.removeBinderReceivedListener(viewModel) - Shizuku.removeBinderDeadListener(viewModel) - Shizuku.removeRequestPermissionResultListener(viewModel) - super.onDestroy() - } @Composable fun ShizukuStatePanel(state: ShizukuState) {