app: remove interactive su request components

Following the removal of reactive interactive su prompting in magiskd,
remove the corresponding request activity and obsolete settings from
the app.

- Remove SuRequestActivity, SuRequestScreen, SuRequestViewModel, and
  SuRequestHandler.
- Remove tapjack protection, auto response, and request timeout
  settings and resources.
- Update Stub.kt manifest generator to drop the unexported activity
  placeholder.
- Simplify DynLoad activity mapping now that both stub and app declare
  a single activity.
- Bump magisk.stubVersion to 41.

Assisted-by: Gemini 3.8 Flash
This commit is contained in:
topjohnwu
2026-10-05 01:38:20 -07:00
committed by John Wu
parent a1cf051ac7
commit f093f847bb
18 changed files with 6 additions and 814 deletions
-12
View File
@@ -17,18 +17,6 @@
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".ui.surequest.SuRequestActivity"
android:directBootAware="true"
android:exported="false"
android:taskAffinity=""
tools:ignore="AppLinkUrlError">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
@@ -14,7 +14,6 @@ import com.topjohnwu.magisk.ui.module.ModuleViewModel
import com.topjohnwu.magisk.ui.settings.SettingsViewModel
import com.topjohnwu.magisk.ui.superuser.SuperuserGrantViewModel
import com.topjohnwu.magisk.ui.superuser.SuperuserViewModel
import com.topjohnwu.magisk.ui.surequest.SuRequestViewModel
val VMFactory: ViewModelProvider.Factory = viewModelFactory {
initializer { HomeViewModel(ServiceLocator.networkService) }
@@ -22,7 +21,6 @@ val VMFactory: ViewModelProvider.Factory = viewModelFactory {
initializer { SuperuserViewModel(ServiceLocator.policyDB) }
initializer { SuperuserGrantViewModel(ServiceLocator.policyDB) }
initializer { InstallViewModel(ServiceLocator.networkService) }
initializer { SuRequestViewModel(ServiceLocator.policyDB, ServiceLocator.timeoutPrefs) }
initializer { DenyListViewModel() }
initializer { FlashViewModel() }
initializer { ActionViewModel() }
@@ -396,23 +396,6 @@ private fun SuperuserSection(
shape = RoundedCornerShape(20.dp),
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceContainerLow)
) {
// Tapjack (SDK < S)
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
var tapjack by remember { mutableStateOf(Config.suTapjack) }
SettingsSwitch(
title = stringResource(CoreR.string.settings_su_tapjack_title),
summary = stringResource(CoreR.string.settings_su_tapjack_summary),
checked = tapjack,
onCheckedChange = {
tapjack = it
Config.suTapjack = it
}
)
HorizontalDivider(
modifier = Modifier.padding(horizontal = 16.dp),
color = MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.5f)
)
}
// Authentication
var suAuth by remember { mutableStateOf(Config.suAuth) }
@@ -506,52 +489,6 @@ private fun SuperuserSection(
color = MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.5f)
)
// Automatic Response
val autoResponseEntries = remember {
resources.getStringArray(CoreR.array.auto_response).toList()
}
var autoResponse by remember { mutableIntStateOf(Config.suAutoResponse) }
SettingsDropdown(
title = stringResource(CoreR.string.auto_response),
items = autoResponseEntries,
selectedIndex = autoResponse,
onSelectedIndexChange = { newIndex ->
val doIt = {
autoResponse = newIndex
Config.suAutoResponse = newIndex
}
if (Config.suAuth) viewModel.withAuth(doIt) else doIt()
}
)
HorizontalDivider(
modifier = Modifier.padding(horizontal = 16.dp),
color = MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.5f)
)
// Request Timeout
val timeoutEntries = remember {
resources.getStringArray(CoreR.array.request_timeout).toList()
}
val timeoutValues = remember { listOf(10, 15, 20, 30, 45, 60) }
var timeoutIndex by remember {
mutableIntStateOf(timeoutValues.indexOf(Config.suDefaultTimeout).coerceAtLeast(0))
}
SettingsDropdown(
title = stringResource(CoreR.string.request_timeout),
items = timeoutEntries,
selectedIndex = timeoutIndex,
onSelectedIndexChange = {
timeoutIndex = it
Config.suDefaultTimeout = timeoutValues[it]
}
)
HorizontalDivider(
modifier = Modifier.padding(horizontal = 16.dp),
color = MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.5f)
)
// SU Notification
val notifEntries = remember {
resources.getStringArray(CoreR.array.su_notification).toList()
@@ -1,120 +0,0 @@
package com.topjohnwu.magisk.ui.surequest
import android.content.Context
import android.content.Intent
import android.content.pm.ActivityInfo
import android.os.Build
import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import android.view.Window
import android.view.WindowManager
import android.view.accessibility.AccessibilityEvent
import android.view.accessibility.AccessibilityNodeInfo
import android.view.accessibility.AccessibilityNodeProvider
import androidx.activity.ComponentActivity
import androidx.activity.addCallback
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.ui.Modifier
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope
import com.topjohnwu.magisk.R
import com.topjohnwu.magisk.arch.VMFactory
import com.topjohnwu.magisk.core.base.ActivityExtension
import com.topjohnwu.magisk.core.base.UntrackedActivity
import com.topjohnwu.magisk.core.su.SuCallbackHandler
import com.topjohnwu.magisk.core.su.SuCallbackHandler.REQUEST
import com.topjohnwu.magisk.core.wrap
import com.topjohnwu.magisk.ui.MagiskTheme
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
class SuRequestActivity : ComponentActivity(), UntrackedActivity {
private val extension = ActivityExtension(this)
private val viewModel: SuRequestViewModel by lazy {
ViewModelProvider(this, VMFactory)[SuRequestViewModel::class.java]
}
override fun attachBaseContext(base: Context) {
super.attachBaseContext(base.wrap())
}
override fun onCreate(savedInstanceState: Bundle?) {
extension.onCreate(savedInstanceState)
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LOCKED
window.requestFeature(Window.FEATURE_NO_TITLE)
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
window.addFlags(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
window.setHideOverlayWindows(true)
}
setTheme(R.style.Floating)
super.onCreate(savedInstanceState)
setFinishOnTouchOutside(false)
onBackPressedDispatcher.addCallback(this) { viewModel.denyPressed() }
viewModel.finishActivity = { finish() }
viewModel.authenticate = { onSuccess ->
extension.withAuthentication { if (it) onSuccess() }
}
if (intent.action == Intent.ACTION_VIEW) {
val action = intent.getStringExtra("action")
if (action == REQUEST) {
viewModel.handleRequest(intent)
} else {
lifecycleScope.launch {
withContext(Dispatchers.IO) {
SuCallbackHandler.run(this@SuRequestActivity, action, intent.extras)
}
finish()
}
}
} else {
finish()
}
if (viewModel.useTapjackProtection) {
window.decorView.rootView.accessibilityDelegate = EmptyAccessibilityDelegate
}
setContent {
MagiskTheme {
Box(modifier = Modifier.fillMaxSize()) {
SuRequestScreen(viewModel = viewModel)
}
}
}
}
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
extension.onSaveInstanceState(outState)
}
override fun finish() {
super.finishAndRemoveTask()
}
override fun onDestroy() {
super.onDestroy()
viewModel.activityDestroyed()
}
private object EmptyAccessibilityDelegate : View.AccessibilityDelegate() {
override fun sendAccessibilityEvent(host: View, eventType: Int) {}
override fun performAccessibilityAction(host: View, action: Int, args: Bundle?) = true
override fun sendAccessibilityEventUnchecked(host: View, event: AccessibilityEvent) {}
override fun dispatchPopulateAccessibilityEvent(host: View, event: AccessibilityEvent) = true
override fun onPopulateAccessibilityEvent(host: View, event: AccessibilityEvent) {}
override fun onInitializeAccessibilityEvent(host: View, event: AccessibilityEvent) {}
override fun onInitializeAccessibilityNodeInfo(host: View, info: AccessibilityNodeInfo) {}
override fun addExtraDataToAccessibilityNodeInfo(host: View, info: AccessibilityNodeInfo, extraDataKey: String, arguments: Bundle?) {}
override fun onRequestSendAccessibilityEvent(host: ViewGroup, child: View, event: AccessibilityEvent): Boolean = false
override fun getAccessibilityNodeProvider(host: View): AccessibilityNodeProvider? = null
}
}
@@ -1,207 +0,0 @@
package com.topjohnwu.magisk.ui.surequest
import android.view.MotionEvent
import android.widget.Toast
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Slider
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.input.pointer.pointerInteropFilter
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringArrayResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.google.accompanist.drawablepainter.rememberDrawablePainter
import com.topjohnwu.magisk.core.ktx.toast
import com.topjohnwu.magisk.ui.component.MagiskDialog
import com.topjohnwu.magisk.ui.superuser.SharedUidBadge
import com.topjohnwu.magisk.core.R as CoreR
@OptIn(ExperimentalComposeUiApi::class)
@Composable
fun SuRequestScreen(
viewModel: SuRequestViewModel,
modifier: Modifier = Modifier
) {
val uiState by viewModel.uiState.collectAsStateWithLifecycle()
if (!uiState.showUi) return
val context = LocalContext.current
val icon = uiState.icon
val title = uiState.title
val packageName = uiState.packageName
val grantEnabled = uiState.grantEnabled
val denyCountdown = uiState.denyCountdown
val selectedPosition = uiState.selectedItemPosition
val timeoutEntries = stringArrayResource(CoreR.array.allow_timeout).toList()
// Slider order: Once(1), 10min(2), 20min(3), 30min(4), 60min(5), Forever(0)
val sliderToIndex = intArrayOf(1, 2, 3, 4, 5, 0)
val indexToSlider = remember {
IntArray(sliderToIndex.size).also { arr ->
sliderToIndex.forEachIndexed { slider, orig -> arr[orig] = slider }
}
}
val sliderValue = indexToSlider[selectedPosition].toFloat()
val sliderLabel by remember(sliderValue) {
derivedStateOf { timeoutEntries[sliderToIndex[sliderValue.toInt()]] }
}
val denyText = if (denyCountdown > 0) {
"${stringResource(CoreR.string.deny)} ($denyCountdown)"
} else {
stringResource(CoreR.string.deny)
}
MagiskDialog(
modifier = modifier,
dismissOnClickOutside = false,
onDismissRequest = { viewModel.denyPressed() },
title = {
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.fillMaxWidth()
) {
if (icon != null) {
Image(
painter = rememberDrawablePainter(icon),
contentDescription = null,
modifier = Modifier.size(44.dp)
)
Spacer(Modifier.width(14.dp))
}
Column(modifier = Modifier.weight(1f)) {
Row(verticalAlignment = Alignment.CenterVertically) {
Text(
text = title,
style = MaterialTheme.typography.titleLarge,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
)
if (uiState.isSharedUid) {
Spacer(Modifier.width(6.dp))
SharedUidBadge()
}
}
Text(
text = packageName,
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
)
}
}
},
confirmButton = {
TextButton(
enabled = grantEnabled,
onClick = { viewModel.grantPressed() },
modifier = if (uiState.useTapjackProtection) {
Modifier.pointerInteropFilter { event ->
if (event.flags and MotionEvent.FLAG_WINDOW_IS_OBSCURED != 0 ||
event.flags and MotionEvent.FLAG_WINDOW_IS_PARTIALLY_OBSCURED != 0
) {
if (event.action == MotionEvent.ACTION_UP) {
context.toast(
CoreR.string.touch_filtered_warning,
Toast.LENGTH_SHORT
)
}
true
} else {
false
}
}
} else Modifier
) {
Text(
text = stringResource(CoreR.string.grant),
style = MaterialTheme.typography.labelLarge,
)
}
},
dismissButton = {
TextButton(
onClick = { viewModel.denyPressed() }
) {
Text(
text = denyText,
style = MaterialTheme.typography.labelLarge,
)
}
}
) {
Column(
modifier = Modifier.verticalScroll(rememberScrollState()),
horizontalAlignment = Alignment.CenterHorizontally
) {
Card(
modifier = Modifier.fillMaxWidth(),
shape = RoundedCornerShape(12.dp),
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.errorContainer)
) {
Text(
text = stringResource(CoreR.string.su_warning),
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onErrorContainer,
fontWeight = FontWeight.Medium,
textAlign = TextAlign.Center,
modifier = Modifier
.fillMaxWidth()
.padding(12.dp)
)
}
Spacer(Modifier.height(16.dp))
Text(
text = "${stringResource(CoreR.string.grant)}: $sliderLabel",
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant,
modifier = Modifier
.fillMaxWidth()
.padding(start = 4.dp),
)
Spacer(Modifier.height(8.dp))
Slider(
value = sliderValue,
onValueChange = { value ->
viewModel.spinnerTouched()
val pos = value.toInt().coerceIn(0, sliderToIndex.lastIndex)
viewModel.setSelectedItemPosition(sliderToIndex[pos])
},
valueRange = 0f..5f,
steps = 4,
modifier = Modifier.fillMaxWidth()
)
}
}
}
@@ -1,188 +0,0 @@
package com.topjohnwu.magisk.ui.surequest
import android.content.Intent
import android.content.SharedPreferences
import android.graphics.drawable.Drawable
import android.os.CountDownTimer
import androidx.core.content.edit
import androidx.lifecycle.viewModelScope
import com.topjohnwu.magisk.arch.BaseViewModel
import com.topjohnwu.magisk.core.AppContext
import com.topjohnwu.magisk.core.Config
import com.topjohnwu.magisk.core.data.magiskdb.PolicyDao
import com.topjohnwu.magisk.core.ktx.getLabel
import com.topjohnwu.magisk.core.model.su.SuPolicy.Companion.ALLOW
import com.topjohnwu.magisk.core.model.su.SuPolicy.Companion.DENY
import com.topjohnwu.magisk.core.su.SuRequestHandler
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import java.util.concurrent.TimeUnit.SECONDS
class SuRequestViewModel(
policyDB: PolicyDao,
private val timeoutPrefs: SharedPreferences
) : BaseViewModel() {
data class UiState(
val showUi: Boolean = false,
val icon: Drawable? = null,
val title: String = "",
val packageName: String = "",
val isSharedUid: Boolean = false,
val selectedItemPosition: Int = 0,
val grantEnabled: Boolean = false,
val denyCountdown: Int = 0,
val useTapjackProtection: Boolean = false,
)
private val _uiState = MutableStateFlow(UiState())
val uiState: StateFlow<UiState> = _uiState.asStateFlow()
var authenticate: (onSuccess: () -> Unit) -> Unit = { it() }
var finishActivity: () -> Unit = {}
val useTapjackProtection get() = _uiState.value.useTapjackProtection
private val handler = SuRequestHandler(AppContext.packageManager, policyDB)
private val millis = SECONDS.toMillis(Config.suDefaultTimeout.toLong())
private var timer = SuTimer(millis, 1000)
private var initialized = false
private var responded = false
fun setSelectedItemPosition(position: Int) {
_uiState.update { it.copy(selectedItemPosition = position) }
}
fun grantPressed() {
cancelTimer()
if (Config.suAuth) {
authenticate { respond(ALLOW) }
} else {
respond(ALLOW)
}
}
fun denyPressed() {
respond(DENY)
}
fun spinnerTouched() {
cancelTimer()
}
fun handleRequest(intent: Intent) {
viewModelScope.launch(Dispatchers.Default) {
if (handler.start(intent))
showDialog()
else
finishActivity()
}
}
private fun showDialog() {
val pm = handler.pm
val info = handler.pkgInfo
val app = info.applicationInfo
val isSharedUid = info.sharedUserId != null
val icon: Drawable?
val title: String
val packageName: String
if (app == null) {
icon = pm.defaultActivityIcon
title = info.sharedUserId.toString()
packageName = info.sharedUserId.toString()
} else {
icon = app.loadIcon(pm)
title = app.getLabel(pm)
packageName = info.packageName
}
val selectedPos = timeoutPrefs.getInt(packageName, 0)
_uiState.update {
it.copy(
showUi = true,
icon = icon,
title = title,
packageName = packageName,
isSharedUid = isSharedUid,
selectedItemPosition = selectedPos,
useTapjackProtection = Config.suTapjack,
grantEnabled = false,
)
}
viewModelScope.launch {
delay(1000)
_uiState.update { it.copy(grantEnabled = true) }
}
timer.start()
initialized = true
}
fun activityDestroyed() {
if (initialized && !responded) {
respond(DENY)
}
}
override fun onCleared() {
super.onCleared()
timer.cancel()
if (initialized && !responded) {
responded = true
val pos = _uiState.value.selectedItemPosition
runBlocking(Dispatchers.IO) {
handler.respond(DENY, Config.Value.TIMEOUT_LIST[pos])
}
}
}
private fun respond(action: Int) {
if (!initialized || responded) return
responded = true
timer.cancel()
val pos = _uiState.value.selectedItemPosition
val pkg = _uiState.value.packageName
timeoutPrefs.edit { putInt(pkg, pos) }
viewModelScope.launch(Dispatchers.IO) {
handler.respond(action, Config.Value.TIMEOUT_LIST[pos])
withContext(Dispatchers.Main) {
finishActivity()
}
}
}
private fun cancelTimer() {
timer.cancel()
_uiState.update { it.copy(denyCountdown = 0) }
}
private inner class SuTimer(
millis: Long,
interval: Long
) : CountDownTimer(millis, interval) {
override fun onTick(remains: Long) {
_uiState.update {
it.copy(
denyCountdown = (remains / 1000).toInt() + 1
)
}
}
override fun onFinish() {
_uiState.update { it.copy(denyCountdown = 0) }
respond(DENY)
}
}
}
-5
View File
@@ -3,9 +3,4 @@
<style name="Main" parent="android:Theme.Material.Light.NoActionBar" />
<style name="Floating" parent="android:Theme.Material.Light.NoActionBar">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
</style>
</resources>
+2 -15
View File
@@ -137,29 +137,16 @@ private abstract class ManifestUpdater: DefaultTask() {
|</activity>""".ind(2)
)
cmpList.add("""
|<activity
| android:name="x.COMPONENT_PLACEHOLDER_3"
| android:directBootAware="true"
| android:exported="false"
| android:taskAffinity="">
| <intent-filter>
| <action android:name="android.intent.action.VIEW"/>
| <category android:name="android.intent.category.DEFAULT"/>
| </intent-filter>
|</activity>""".ind(2)
)
cmpList.add("""
|<service
| android:name="x.COMPONENT_PLACEHOLDER_4"
| android:name="x.COMPONENT_PLACEHOLDER_3"
| android:exported="false"
| android:foregroundServiceType="dataSync" />""".ind(2)
)
cmpList.add("""
|<service
| android:name="x.COMPONENT_PLACEHOLDER_5"
| android:name="x.COMPONENT_PLACEHOLDER_4"
| android:exported="false"
| android:permission="android.permission.BIND_JOB_SERVICE" />""".ind(2)
)
@@ -29,11 +29,8 @@ object Config : PreferenceConfig, DBConfig {
const val KEYSTORE = "keystore"
// prefs
const val SU_REQUEST_TIMEOUT = "su_request_timeout"
const val SU_AUTO_RESPONSE = "su_auto_response"
const val SU_NOTIFICATION = "su_notification"
const val SU_REAUTH = "su_reauth"
const val SU_TAPJACK = "su_tapjack"
const val SU_RESTRICT = "su_restrict"
const val CHECK_UPDATES = "check_update"
const val RELEASE_CHANNEL = "release_channel"
@@ -48,8 +45,7 @@ object Config : PreferenceConfig, DBConfig {
const val DOH = "doh"
const val RAND_NAME = "rand_name"
val NO_MIGRATION = setOf(ASKED_HOME, SU_REQUEST_TIMEOUT,
SU_AUTO_RESPONSE, SU_REAUTH, SU_TAPJACK)
val NO_MIGRATION = setOf(ASKED_HOME, SU_REAUTH)
}
object OldValue {
@@ -90,14 +86,6 @@ object Config : PreferenceConfig, DBConfig {
const val NO_NOTIFICATION = 0
const val NOTIFICATION_TOAST = 1
const val NOTIFICATION_STATUS_BAR = 2
// su auto response
const val SU_PROMPT = 0
const val SU_AUTO_DENY = 1
const val SU_AUTO_ALLOW = 2
// su timeout
val TIMEOUT_LIST = longArrayOf(0, -1, 10, 20, 30, 60)
}
@JvmField var keepVerity = false
@@ -143,9 +131,6 @@ object Config : PreferenceConfig, DBConfig {
var zygisk by dbSettings(Key.ZYGISK, Info.isEmulator)
var suManager by dbStrings(Key.SU_MANAGER, "", true)
var keyStoreRaw by dbStrings(Key.KEYSTORE, "", true)
var suDefaultTimeout by preferenceStrInt(Key.SU_REQUEST_TIMEOUT, 10)
var suAutoResponse by preferenceStrInt(Key.SU_AUTO_RESPONSE, Value.SU_PROMPT)
var suNotification by preferenceStrInt(Key.SU_NOTIFICATION, Value.NOTIFICATION_TOAST)
var rootMode by dbSettings(Key.ROOT_ACCESS, Value.ROOT_ACCESS_APPS_AND_ADB)
var suMntNamespaceMode by dbSettings(Key.SU_MNT_NS, Value.NAMESPACE_MODE_REQUESTER)
@@ -157,7 +142,6 @@ object Config : PreferenceConfig, DBConfig {
suBiometric = value
}
var suReAuth by preference(Key.SU_REAUTH, false)
var suTapjack by preference(Key.SU_TAPJACK, true)
var suRestrict by preference(Key.SU_RESTRICT, false)
private const val SU_FINGERPRINT = "su_fingerprint"
@@ -51,5 +51,4 @@ val shouldKeepResources = listOf(
R.string.app_changelog,
R.string.home_item_source,
R.drawable.ic_more,
R.array.allow_timeout,
)
@@ -20,7 +20,6 @@ import io.noties.markwon.utils.NoCopySpannableFactory
object ServiceLocator {
val deContext by lazy { AppContext.deviceProtectedContext }
val timeoutPrefs by lazy { deContext.getSharedPreferences("su_timeout", 0) }
// Database
val policyDB = PolicyDao()
@@ -4,7 +4,7 @@ import com.topjohnwu.magisk.core.data.magiskdb.MagiskDB
class SuPolicy(
val uid: Int,
var policy: Int = QUERY,
var policy: Int = DENY,
var remain: Long = -1L,
var logging: Boolean = true,
var notification: Boolean = true,
@@ -18,7 +18,6 @@ import timber.log.Timber
object SuCallbackHandler {
const val REQUEST = "request"
const val LOG = "log"
const val NOTIFY = "notify"
@@ -1,115 +0,0 @@
package com.topjohnwu.magisk.core.su
import android.content.Intent
import android.content.pm.PackageInfo
import android.content.pm.PackageManager
import com.topjohnwu.magisk.core.BuildConfig
import com.topjohnwu.magisk.core.Config
import com.topjohnwu.magisk.core.data.magiskdb.PolicyDao
import com.topjohnwu.magisk.core.di.ServiceLocator
import com.topjohnwu.magisk.core.ktx.getLabel
import com.topjohnwu.magisk.core.ktx.getPackageInfo
import com.topjohnwu.magisk.core.model.su.SuLog
import com.topjohnwu.magisk.core.model.su.SuPolicy
import com.topjohnwu.magisk.view.Notifications
import com.topjohnwu.superuser.Shell
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import timber.log.Timber
import java.io.DataOutputStream
import java.io.File
import java.io.FileOutputStream
import java.io.IOException
import java.util.concurrent.TimeUnit
class SuRequestHandler(
val pm: PackageManager,
private val policyDB: PolicyDao
) {
private lateinit var output: File
private lateinit var policy: SuPolicy
lateinit var pkgInfo: PackageInfo
private set
// Return true to indicate undetermined policy, require user interaction
suspend fun start(intent: Intent): Boolean {
if (!init(intent))
return false
// Never allow com.topjohnwu.magisk (could be malware)
if (pkgInfo.packageName == BuildConfig.APP_PACKAGE_NAME) {
Shell.cmd("(pm uninstall ${BuildConfig.APP_PACKAGE_NAME} >/dev/null 2>&1)&").exec()
return false
}
when (Config.suAutoResponse) {
Config.Value.SU_AUTO_DENY -> {
respond(SuPolicy.DENY, 0)
return false
}
Config.Value.SU_AUTO_ALLOW -> {
respond(SuPolicy.ALLOW, 0)
return false
}
}
return true
}
private suspend fun init(intent: Intent): Boolean {
val uid = intent.getIntExtra("uid", -1)
val pid = intent.getIntExtra("pid", -1)
val fifo = intent.getStringExtra("fifo")
if (uid <= 0 || pid <= 0 || fifo == null) {
Timber.e("Unexpected extras: uid=[${uid}], pid=[${pid}], fifo=[${fifo}]")
return false
}
output = File(fifo)
policy = policyDB.fetch(uid) ?: SuPolicy(uid)
try {
pkgInfo = pm.getPackageInfo(uid, pid) ?: PackageInfo().apply {
val name = pm.getNameForUid(uid) ?: throw PackageManager.NameNotFoundException()
// We only fill in sharedUserId and leave other fields uninitialized
sharedUserId = name.split(":")[0]
}
} catch (e: PackageManager.NameNotFoundException) {
Timber.e(e)
respond(SuPolicy.DENY, -1)
return false
}
if (!output.canWrite()) {
Timber.e("Cannot write to $output")
return false
}
return true
}
suspend fun respond(action: Int, time: Long) {
if (action == SuPolicy.ALLOW && Config.suRestrict) {
policy.policy = SuPolicy.RESTRICT
} else {
policy.policy = action
}
if (time >= 0) {
policy.remain = TimeUnit.MINUTES.toSeconds(time)
} else {
policy.remain = time
}
withContext(Dispatchers.IO) {
try {
DataOutputStream(FileOutputStream(output)).use {
it.writeInt(policy.policy)
it.flush()
}
} catch (e: IOException) {
Timber.e(e)
}
if (time >= 0) {
policyDB.update(policy)
SuEvents.notifyPolicyChanged()
}
}
}
}
-24
View File
@@ -1,14 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="allow_timeout">
<item>@string/forever</item>
<item>@string/once</item>
<item>@string/tenmin</item>
<item>@string/twentymin</item>
<item>@string/thirtymin</item>
<item>@string/sixtymin</item>
</string-array>
<string-array name="su_access">
<item>@string/settings_su_disable</item>
<item>@string/settings_su_app</item>
@@ -16,21 +7,6 @@
<item>@string/settings_su_app_adb</item>
</string-array>
<string-array name="request_timeout">
<item>@string/settings_su_request_10</item>
<item>@string/settings_su_request_15</item>
<item>@string/settings_su_request_20</item>
<item>@string/settings_su_request_30</item>
<item>@string/settings_su_request_45</item>
<item>@string/settings_su_request_60</item>
</string-array>
<string-array name="auto_response">
<item>@string/prompt</item>
<item>@string/deny</item>
<item>@string/grant</item>
</string-array>
<string-array name="su_notification">
<item>@string/none</item>
<item>@string/toast</item>
-20
View File
@@ -54,20 +54,10 @@
<string name="flash_screen_title">Installation</string>
<!--Superuser-->
<string name="su_request_title">Superuser request</string>
<string name="touch_filtered_warning">Because an app is obscuring a Superuser request, Magisk can\'t verify your response.</string>
<string name="deny">Deny</string>
<string name="prompt">Prompt</string>
<string name="restrict">Restrict</string>
<string name="grant">Grant</string>
<string name="superuser_grant">Grant Superuser</string>
<string name="su_warning">Grants full access to your device.\nDeny if you\'re not sure!</string>
<string name="forever">Forever</string>
<string name="once">Once</string>
<string name="tenmin">10 mins</string>
<string name="twentymin">20 mins</string>
<string name="thirtymin">30 mins</string>
<string name="sixtymin">60 mins</string>
<string name="su_allow_toast">%1$s was granted Superuser rights</string>
<string name="su_deny_toast">%1$s was denied Superuser rights</string>
<string name="su_snack_grant">Superuser rights of %1$s are granted</string>
@@ -170,20 +160,10 @@
<string name="settings_su_app">Apps only</string>
<string name="settings_su_adb">ADB only</string>
<string name="settings_su_disable">Disabled</string>
<string name="settings_su_request_10">10 seconds</string>
<string name="settings_su_request_15">15 seconds</string>
<string name="settings_su_request_20">20 seconds</string>
<string name="settings_su_request_30">30 seconds</string>
<string name="settings_su_request_45">45 seconds</string>
<string name="settings_su_request_60">60 seconds</string>
<string name="superuser_access">Superuser access</string>
<string name="auto_response">Automatic response</string>
<string name="request_timeout">Request timeout</string>
<string name="superuser_notification">Superuser notification</string>
<string name="settings_su_reauth_title">Reauthenticate after upgrade</string>
<string name="settings_su_reauth_summary">Ask for Superuser permissions again after upgrading apps</string>
<string name="settings_su_tapjack_title">Tapjacking protection</string>
<string name="settings_su_tapjack_summary">The Superuser prompt dialog won\'t respond to input while obscured by any other window or overlay</string>
<string name="settings_su_auth_title">User authentication</string>
<string name="settings_su_auth_summary">Ask for user authentication during Superuser requests</string>
<string name="settings_su_auth_insecure">No authentication method is configured on the device</string>
+1 -1
View File
@@ -30,5 +30,5 @@ kapt.use.k2=true
android.injected.testOnly=false
# Magisk
magisk.stubVersion=40
magisk.stubVersion=41
magisk.versionCode=31000
@@ -206,27 +206,7 @@ public class DynLoad {
{
var src = stub.activities;
var dest = app.activities;
final ActivityInfo sa;
final ActivityInfo da;
final ActivityInfo sb;
final ActivityInfo db;
if (src[0].exported) {
sa = src[0];
sb = src[1];
} else {
sa = src[1];
sb = src[0];
}
if (dest[0].exported) {
da = dest[0];
db = dest[1];
} else {
da = dest[1];
db = dest[0];
}
mapping.put(sa.name, da.name);
mapping.put(sb.name, db.name);
mapping.put(src[0].name, dest[0].name);
}
{