Skip to content

Commit

Permalink
Listen for shizuku binder in Application
Browse files Browse the repository at this point in the history
  • Loading branch information
LinZong committed Aug 18, 2024
1 parent 85ed449 commit 1d03455
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
15 changes: 15 additions & 0 deletions app/src/main/java/moe/nemesiss/hostman/HostmanApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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) {
Expand Down
10 changes: 0 additions & 10 deletions app/src/main/java/moe/nemesiss/hostman/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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 {
Expand All @@ -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) {
Expand Down

0 comments on commit 1d03455

Please sign in to comment.