Skip to content

Commit

Permalink
fix: Mount master with libsu
Browse files Browse the repository at this point in the history
Change-Id: I8ff9c6117acec45428c65eed7a01ab564f907788
  • Loading branch information
XayahSuSuSu committed Oct 6, 2023
1 parent a1dfd03 commit c3be45e
Showing 1 changed file with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.xayah.libpickyou.ui.activity

import android.app.Activity
import android.app.Application
import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.activity.ComponentActivity
Expand All @@ -12,6 +14,7 @@ import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.runtime.LaunchedEffect
import androidx.core.view.WindowCompat
import com.google.accompanist.permissions.ExperimentalPermissionsApi
import com.topjohnwu.superuser.Shell
import com.xayah.libpickyou.R
import com.xayah.libpickyou.ui.components.ContentList
import com.xayah.libpickyou.ui.components.PickYouScaffold
Expand All @@ -23,6 +26,36 @@ import com.xayah.libpickyou.util.RemoteRootService
internal class LibPickYouActivity : ComponentActivity() {
private val viewModel: LibPickYouViewModel by viewModels()

companion object {
class EnvInitializer : Shell.Initializer() {
companion object {
fun initShell(shell: Shell) {
shell.newJob()
.add("nsenter -t 1 -m su") // Switch to global namespace
.add("set -o pipefail") // Ensure that the exit code of each command is correct.
.exec()
}
}

override fun onInit(context: Context, shell: Shell): Boolean {
initShell(shell)
return true
}
}
}

override fun attachBaseContext(context: Context) {
val base: Context = if (context is Application) context.baseContext else context
super.attachBaseContext(base)
Shell.setDefaultBuilder(
Shell.Builder.create()
.setFlags(Shell.FLAG_MOUNT_MASTER or Shell.FLAG_REDIRECT_STDERR)
.setInitializers(EnvInitializer::class.java)
.setContext(base)
.setTimeout(3)
)
}

@ExperimentalPermissionsApi
@ExperimentalAnimationApi
@ExperimentalMaterial3Api
Expand Down

0 comments on commit c3be45e

Please sign in to comment.