Remove unused code

This commit is contained in:
topjohnwu
2026-04-09 23:09:39 -07:00
committed by John Wu
parent 81413b0f10
commit 7d5942a3bc
11 changed files with 3 additions and 167 deletions

View File

@@ -1,6 +1,5 @@
package com.topjohnwu.magisk.arch
import android.os.Bundle
import android.widget.Toast
import androidx.annotation.StringRes
import androidx.lifecycle.ViewModel
@@ -15,9 +14,6 @@ abstract class BaseViewModel : ViewModel() {
private val _navEvents = MutableSharedFlow<Route>(extraBufferCapacity = 1)
val navEvents: SharedFlow<Route> = _navEvents
open fun onSaveState(state: Bundle) {}
open fun onRestoreState(state: Bundle) {}
fun showSnackbar(@StringRes resId: Int) {
AppContext.toast(resId, Toast.LENGTH_SHORT)
}

View File

@@ -237,7 +237,6 @@ class TerminalEmulator(
cursorRow = cursor[1]
}
fun setCursorStyle() {
cursorStyle = DEFAULT_TERMINAL_CURSOR_STYLE
}
@@ -1509,12 +1508,10 @@ class TerminalEmulator(
mAboutToAutoWrap = false
}
fun clearScrollCounter() {
scrollCounter = 0
}
fun toggleAutoScrollDisabled() {
isAutoScrollDisabled = !isAutoScrollDisabled
}
@@ -1566,7 +1563,6 @@ class TerminalEmulator(
fun getSelectedText(x1: Int, y1: Int, x2: Int, y2: Int): String =
screen.getSelectedText(x1, y1, x2, y2)
private fun setTitle(newTitle: String?) {
title = newTitle
}

View File

@@ -130,5 +130,4 @@ data class ProcessInfo(
var isEnabled: Boolean
) {
val isIsolated = packageName == ISOLATED_MAGIC
val isAppZygote = name.endsWith("_zygote")
}

View File

@@ -26,9 +26,7 @@ import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Check
import androidx.compose.material.icons.filled.Close
import androidx.compose.material.icons.filled.Delete
import androidx.compose.material.icons.filled.Layers
import androidx.compose.material.icons.filled.PowerSettingsNew
import androidx.compose.material.icons.filled.PushPin
import androidx.compose.material.icons.filled.Visibility
import androidx.compose.material.icons.filled.VisibilityOff
import androidx.compose.material3.AlertDialog
@@ -65,8 +63,6 @@ import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.rotate
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
@@ -98,7 +94,6 @@ import com.topjohnwu.magisk.ui.install.InstallViewModel
import kotlinx.coroutines.launch
import com.topjohnwu.magisk.core.R as CoreR
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun HomeScreen(viewModel: HomeViewModel, installVm: InstallViewModel) {
@@ -1050,7 +1045,6 @@ private fun EnvFixComposableDialog(
@Composable
private fun HideAppDialog(onDismiss: () -> Unit, onConfirm: (String) -> Unit) {
val showState = rememberSaveable { mutableStateOf(true) }
val defaultName = stringResource(CoreR.string.settings)
var appName by rememberSaveable { mutableStateOf(defaultName) }
val isError = appName.length > AppMigration.MAX_LABEL_LENGTH || appName.isBlank()
@@ -1087,8 +1081,6 @@ private fun HideAppDialog(onDismiss: () -> Unit, onConfirm: (String) -> Unit) {
@Composable
private fun RestoreAppDialog(onDismiss: () -> Unit, onConfirm: () -> Unit) {
val showState = rememberSaveable { mutableStateOf(true) }
AlertDialog(
onDismissRequest = onDismiss,
title = { Text(stringResource(CoreR.string.settings_restore_app_title)) },

View File

@@ -9,8 +9,6 @@ import com.topjohnwu.magisk.core.AppContext
import com.topjohnwu.magisk.core.BuildConfig
import com.topjohnwu.magisk.core.Config
import com.topjohnwu.magisk.core.Info
import com.topjohnwu.magisk.core.download.Subject
import com.topjohnwu.magisk.core.download.Subject.App
import com.topjohnwu.magisk.core.ktx.await
import com.topjohnwu.magisk.core.ktx.toast
import com.topjohnwu.magisk.core.repository.NetworkService
@@ -19,7 +17,6 @@ import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update
import kotlin.math.roundToInt
import com.topjohnwu.magisk.core.R as CoreR
class HomeViewModel(
@@ -95,15 +92,6 @@ class HomeViewModel(
Info.isConnected.removeObserver(networkObserver)
}
fun onProgressUpdate(progress: Float, subject: Subject) {
if (subject is App)
_uiState.update { it.copy(managerProgress = progress.times(100f).roundToInt()) }
}
fun resetProgress() {
_uiState.update { it.copy(managerProgress = 0) }
}
fun onLinkPressed(link: String) {
val intent = Intent(Intent.ACTION_VIEW, link.toUri())
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)

View File

@@ -113,15 +113,4 @@ class InstallViewModel(svc: NetworkService) : BaseViewModel() {
else -> error("Unknown method")
}
}
val canInstall: Boolean
get() {
val state = _uiState.value
return when (state.method) {
Method.PATCH -> state.patchUri != null
Method.DIRECT, Method.INACTIVE_SLOT -> true
Method.NONE -> false
}
}
}

View File

@@ -1,6 +1,5 @@
package com.topjohnwu.magisk.ui.module
import android.net.Uri
import android.provider.OpenableColumns
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
@@ -25,11 +24,11 @@ import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.Undo
import androidx.compose.material.icons.filled.Add
import androidx.compose.material.icons.filled.CloudUpload
import androidx.compose.material.icons.filled.Delete
import androidx.compose.material.icons.filled.PlayArrow
import androidx.compose.material.icons.automirrored.filled.Undo
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
@@ -86,8 +85,6 @@ fun ModuleScreen(viewModel: ModuleViewModel) {
val scope = rememberCoroutineScope()
val activity = context as MainActivity
var pendingZipUri by remember { mutableStateOf<Uri?>(null) }
var pendingZipName by remember { mutableStateOf("") }
val localInstallDialog = rememberConfirmDialog()
val confirmInstallTitle = stringResource(CoreR.string.confirm_install_title)
@@ -100,8 +97,6 @@ fun ModuleScreen(viewModel: ModuleViewModel) {
val idx = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME)
if (cursor.moveToFirst() && idx >= 0) cursor.getString(idx) else null
} ?: uri.lastPathSegment ?: "module.zip"
pendingZipUri = uri
pendingZipName = displayName
scope.launch {
val result = localInstallDialog.awaitConfirm(
title = confirmInstallTitle,
@@ -110,7 +105,6 @@ fun ModuleScreen(viewModel: ModuleViewModel) {
if (result == ConfirmResult.Confirmed) {
viewModel.confirmLocalInstall(uri)
}
pendingZipUri = null
}
}
}

View File

@@ -16,36 +16,12 @@ class Navigator(initialKey: NavKey) {
backStack.add(key)
}
fun replace(key: NavKey) {
if (backStack.isNotEmpty()) {
backStack[backStack.lastIndex] = key
} else {
backStack.add(key)
}
}
fun replaceAll(keys: List<NavKey>) {
if (keys.isEmpty()) return
if (backStack.isNotEmpty()) {
backStack.clear()
backStack.addAll(keys)
}
}
fun pop() {
backStack.removeLastOrNull()
}
fun popUntil(predicate: (NavKey) -> Boolean) {
while (backStack.isNotEmpty() && !predicate(backStack.last())) {
backStack.removeAt(backStack.lastIndex)
}
}
fun current(): NavKey? = backStack.lastOrNull()
fun backStackSize(): Int = backStack.size
companion object {
val Saver: Saver<Navigator, Any> = listSaver(
save = { navigator -> navigator.backStack.toList() },

View File

@@ -12,7 +12,6 @@ import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Card
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
@@ -33,12 +32,10 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.core.content.pm.ShortcutManagerCompat
import com.topjohnwu.magisk.core.BuildConfig
import com.topjohnwu.magisk.core.Config
import com.topjohnwu.magisk.core.Const
import com.topjohnwu.magisk.core.Info
import com.topjohnwu.magisk.core.isRunningAsStub
import com.topjohnwu.magisk.core.tasks.AppMigration
import com.topjohnwu.magisk.core.utils.LocaleSetting
import com.topjohnwu.magisk.core.utils.MediaStoreUtils
import com.topjohnwu.magisk.ui.ThemeState
@@ -71,7 +68,7 @@ fun SettingsScreen(viewModel: SettingsViewModel) {
) {
CustomizationSection(viewModel)
Spacer(Modifier.height(12.dp))
AppSettingsSection(viewModel)
AppSettingsSection()
if (Info.env.isActive) {
Spacer(Modifier.height(12.dp))
MagiskSection(viewModel)
@@ -149,10 +146,9 @@ private fun CustomizationSection(viewModel: SettingsViewModel) {
// --- App Settings ---
@Composable
private fun AppSettingsSection(viewModel: SettingsViewModel) {
private fun AppSettingsSection() {
val context = LocalContext.current
val resources = context.resources
val hidden = context.packageName != BuildConfig.APP_PACKAGE_NAME
SmallTitle(text = stringResource(CoreR.string.home_app_title))
Card(modifier = Modifier.fillMaxWidth()) {
@@ -241,7 +237,6 @@ private fun AppSettingsSection(viewModel: SettingsViewModel) {
Config.randName = it
}
)
}
}
@@ -540,68 +535,3 @@ private fun DownloadPathDialog(show: Boolean, onDismiss: () -> Unit) {
)
}
}
@Composable
private fun HideAppDialog(show: Boolean, onDismiss: () -> Unit, onConfirm: (String) -> Unit) {
val showState = rememberSaveable { mutableStateOf(show) }
showState.value = show
val defaultName = stringResource(CoreR.string.settings)
var appName by rememberSaveable { mutableStateOf(defaultName) }
val isError = appName.length > AppMigration.MAX_LABEL_LENGTH || appName.isBlank()
if (showState.value) {
AlertDialog(
onDismissRequest = onDismiss,
title = { Text(stringResource(CoreR.string.settings_hide_app_title)) },
text = {
OutlinedTextField(
value = appName,
onValueChange = { appName = it },
modifier = Modifier.fillMaxWidth(),
label = { Text(stringResource(CoreR.string.settings_app_name_hint)) }
)
},
confirmButton = {
TextButton(
onClick = { if (!isError) onConfirm(appName) }
) {
Text(stringResource(android.R.string.ok))
}
},
dismissButton = {
TextButton(onClick = onDismiss) {
Text(stringResource(android.R.string.cancel))
}
}
)
}
}
@Composable
private fun RestoreDialog(show: Boolean, onDismiss: () -> Unit, onConfirm: () -> Unit) {
val showState = rememberSaveable { mutableStateOf(show) }
showState.value = show
if (showState.value) {
AlertDialog(
onDismissRequest = onDismiss,
title = { Text(stringResource(CoreR.string.settings_restore_app_title)) },
text = {
Text(
text = stringResource(CoreR.string.restore_app_confirmation),
color = MaterialTheme.colorScheme.onSurface,
)
},
confirmButton = {
TextButton(onClick = onConfirm) {
Text(stringResource(android.R.string.ok))
}
},
dismissButton = {
TextButton(onClick = onDismiss) {
Text(stringResource(android.R.string.cancel))
}
}
)
}
}

View File

@@ -1,6 +1,5 @@
package com.topjohnwu.magisk.ui.settings
import android.content.Context
import android.widget.Toast
import androidx.lifecycle.viewModelScope
import com.topjohnwu.magisk.arch.BaseViewModel
@@ -9,17 +8,14 @@ import com.topjohnwu.magisk.core.Config
import com.topjohnwu.magisk.core.Info
import com.topjohnwu.magisk.core.R
import com.topjohnwu.magisk.core.ktx.toast
import com.topjohnwu.magisk.core.tasks.AppMigration
import com.topjohnwu.magisk.core.utils.RootUtils
import com.topjohnwu.magisk.ui.navigation.Route
import com.topjohnwu.magisk.view.Shortcuts
import com.topjohnwu.superuser.Shell
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
class SettingsViewModel : BaseViewModel() {
@@ -38,24 +34,6 @@ class SettingsViewModel : BaseViewModel() {
Shortcuts.addHomeIcon(AppContext)
}
suspend fun hideApp(context: Context, name: String): Boolean {
val success = withContext(Dispatchers.IO) {
AppMigration.patchAndHide(context, name)
}
if (!success) {
context.toast(R.string.failure, Toast.LENGTH_LONG)
}
return success
}
suspend fun restoreApp(context: Context): Boolean {
val success = AppMigration.restoreApp(context)
if (!success) {
context.toast(R.string.failure, Toast.LENGTH_LONG)
}
return success
}
fun createHosts() {
viewModelScope.launch {
RootUtils.addSystemlessHosts()

View File

@@ -37,9 +37,7 @@ class PolicyItem(
val appName: String,
) {
val title get() = appName
val showSlider = Config.suRestrict || policy.policy == SuPolicy.RESTRICT
var isExpanded by mutableStateOf(false)
var policyValue by mutableIntStateOf(policy.policy)
var notification by mutableStateOf(policy.notification)
var logging by mutableStateOf(policy.logging)