Cleanup configs

This commit is contained in:
topjohnwu 2024-07-01 17:23:48 -07:00
parent c92204c724
commit 966c6314f8
7 changed files with 41 additions and 59 deletions

View File

@ -7,7 +7,6 @@ import com.topjohnwu.magisk.BuildConfig
import com.topjohnwu.magisk.core.di.AppContext import com.topjohnwu.magisk.core.di.AppContext
import com.topjohnwu.magisk.core.di.ServiceLocator import com.topjohnwu.magisk.core.di.ServiceLocator
import com.topjohnwu.magisk.core.ktx.writeTo import com.topjohnwu.magisk.core.ktx.writeTo
import com.topjohnwu.magisk.core.repository.BoolDBPropertyNoWrite
import com.topjohnwu.magisk.core.repository.DBConfig import com.topjohnwu.magisk.core.repository.DBConfig
import com.topjohnwu.magisk.core.repository.PreferenceConfig import com.topjohnwu.magisk.core.repository.PreferenceConfig
import com.topjohnwu.magisk.core.utils.refreshLocale import com.topjohnwu.magisk.core.utils.refreshLocale
@ -41,7 +40,6 @@ object Config : PreferenceConfig, DBConfig {
const val SU_BIOMETRIC = "su_biometric" const val SU_BIOMETRIC = "su_biometric"
const val ZYGISK = "zygisk" const val ZYGISK = "zygisk"
const val BOOTLOOP = "bootloop" const val BOOTLOOP = "bootloop"
const val DENYLIST = "denylist"
const val SU_MANAGER = "requester" const val SU_MANAGER = "requester"
const val KEYSTORE = "keystore" const val KEYSTORE = "keystore"
@ -56,12 +54,9 @@ object Config : PreferenceConfig, DBConfig {
const val CUSTOM_CHANNEL = "custom_channel" const val CUSTOM_CHANNEL = "custom_channel"
const val LOCALE = "locale" const val LOCALE = "locale"
const val DARK_THEME = "dark_theme_extended" const val DARK_THEME = "dark_theme_extended"
const val REPO_ORDER = "repo_order"
const val SHOW_SYSTEM_APP = "show_system"
const val DOWNLOAD_DIR = "download_dir" const val DOWNLOAD_DIR = "download_dir"
const val SAFETY = "safety_notice" const val SAFETY = "safety_notice"
const val THEME_ORDINAL = "theme_ordinal" const val THEME_ORDINAL = "theme_ordinal"
const val BOOT_ID = "boot_id"
const val ASKED_HOME = "asked_home" const val ASKED_HOME = "asked_home"
const val DOH = "doh" const val DOH = "doh"
} }
@ -102,10 +97,6 @@ object Config : PreferenceConfig, DBConfig {
// su timeout // su timeout
val TIMEOUT_LIST = intArrayOf(0, -1, 10, 20, 30, 60) val TIMEOUT_LIST = intArrayOf(0, -1, 10, 20, 30, 60)
// repo order
const val ORDER_NAME = 0
const val ORDER_DATE = 1
} }
private val defaultChannel = private val defaultChannel =
@ -119,24 +110,21 @@ object Config : PreferenceConfig, DBConfig {
@JvmField var keepVerity = false @JvmField var keepVerity = false
@JvmField var keepEnc = false @JvmField var keepEnc = false
@JvmField var recovery = false @JvmField var recovery = false
var denyList = false
var bootId by preference(Key.BOOT_ID, "")
var askedHome by preference(Key.ASKED_HOME, false) var askedHome by preference(Key.ASKED_HOME, false)
var bootloop by dbSettings(Key.BOOTLOOP, 0)
var downloadDir by preference(Key.DOWNLOAD_DIR, "")
var repoOrder by preference(Key.REPO_ORDER, Value.ORDER_DATE)
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 updateChannel by preferenceStrInt(Key.UPDATE_CHANNEL, defaultChannel)
var safetyNotice by preference(Key.SAFETY, true) var safetyNotice by preference(Key.SAFETY, true)
var darkTheme by preference(Key.DARK_THEME, AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM) var darkTheme by preference(Key.DARK_THEME, AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
var themeOrdinal by preference(Key.THEME_ORDINAL, Theme.Piplup.ordinal) var themeOrdinal by preference(Key.THEME_ORDINAL, Theme.Piplup.ordinal)
var suReAuth by preference(Key.SU_REAUTH, false)
var suTapjack by preference(Key.SU_TAPJACK, true)
private var checkUpdatePrefs by preference(Key.CHECK_UPDATES, true) private var checkUpdatePrefs by preference(Key.CHECK_UPDATES, true)
private var localePrefs by preference(Key.LOCALE, "")
var doh by preference(Key.DOH, false)
var updateChannel by preferenceStrInt(Key.UPDATE_CHANNEL, defaultChannel)
var customChannelUrl by preference(Key.CUSTOM_CHANNEL, "")
var downloadDir by preference(Key.DOWNLOAD_DIR, "")
var checkUpdate var checkUpdate
get() = checkUpdatePrefs get() = checkUpdatePrefs
set(value) { set(value) {
@ -145,11 +133,6 @@ object Config : PreferenceConfig, DBConfig {
JobService.schedule(AppContext) JobService.schedule(AppContext)
} }
} }
var doh by preference(Key.DOH, false)
var showSystemApp by preference(Key.SHOW_SYSTEM_APP, false)
var customChannelUrl by preference(Key.CUSTOM_CHANNEL, "")
private var localePrefs by preference(Key.LOCALE, "")
var locale var locale
get() = localePrefs get() = localePrefs
set(value) { set(value) {
@ -157,20 +140,24 @@ object Config : PreferenceConfig, DBConfig {
refreshLocale() refreshLocale()
} }
var zygisk by dbSettings(Key.ZYGISK, false)
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 rootMode by dbSettings(Key.ROOT_ACCESS, Value.ROOT_ACCESS_APPS_AND_ADB)
var suMntNamespaceMode by dbSettings(Key.SU_MNT_NS, Value.NAMESPACE_MODE_REQUESTER) var suMntNamespaceMode by dbSettings(Key.SU_MNT_NS, Value.NAMESPACE_MODE_REQUESTER)
var suMultiuserMode by dbSettings(Key.SU_MULTIUSER_MODE, Value.MULTIUSER_MODE_OWNER_ONLY) var suMultiuserMode by dbSettings(Key.SU_MULTIUSER_MODE, Value.MULTIUSER_MODE_OWNER_ONLY)
private var suBiometric by dbSettings(Key.SU_BIOMETRIC, false) private var suBiometric by dbSettings(Key.SU_BIOMETRIC, false)
var userAuth var suAuth
get() = Info.isDeviceSecure && suBiometric get() = Info.isDeviceSecure && suBiometric
set(value) { set(value) {
suBiometric = value suBiometric = value
} }
var zygisk by dbSettings(Key.ZYGISK, false) var suReAuth by preference(Key.SU_REAUTH, false)
var bootloop by dbSettings(Key.BOOTLOOP, 0) var suTapjack by preference(Key.SU_TAPJACK, true)
var denyList by BoolDBPropertyNoWrite(Key.DENYLIST, false)
var suManager by dbStrings(Key.SU_MANAGER, "", true)
var keyStoreRaw by dbStrings(Key.KEYSTORE, "", true)
private const val SU_FINGERPRINT = "su_fingerprint" private const val SU_FINGERPRINT = "su_fingerprint"

View File

@ -7,6 +7,7 @@ import com.topjohnwu.magisk.core.di.AppContext
import com.topjohnwu.magisk.core.ktx.getProperty import com.topjohnwu.magisk.core.ktx.getProperty
import com.topjohnwu.magisk.core.model.UpdateInfo import com.topjohnwu.magisk.core.model.UpdateInfo
import com.topjohnwu.magisk.core.repository.NetworkService import com.topjohnwu.magisk.core.repository.NetworkService
import com.topjohnwu.superuser.Shell
import com.topjohnwu.superuser.ShellUtils.fastCmd import com.topjohnwu.superuser.ShellUtils.fastCmd
val isRunningAsStub get() = Info.stub != null val isRunningAsStub get() = Info.stub != null
@ -24,7 +25,8 @@ object Info {
} }
// Device state // Device state
@JvmStatic val env by lazy { loadState() } @JvmStatic var env = Env()
private set
@JvmField var isSAR = false @JvmField var isSAR = false
var legacySAR = false var legacySAR = false
var isAB = false var isAB = false
@ -36,8 +38,8 @@ object Info {
var noDataExec = false var noDataExec = false
var isRooted = false var isRooted = false
@JvmField var hasGMS = true var hasGMS = true
@JvmField val isEmulator = val isEmulator =
getProperty("ro.kernel.qemu", "0") == "1" || getProperty("ro.kernel.qemu", "0") == "1" ||
getProperty("ro.boot.qemu", "0") == "1" getProperty("ro.boot.qemu", "0") == "1"
@ -51,14 +53,6 @@ object Info {
val isDeviceSecure get() = val isDeviceSecure get() =
AppContext.getSystemService(KeyguardManager::class.java).isDeviceSecure AppContext.getSystemService(KeyguardManager::class.java).isDeviceSecure
private fun loadState(): Env {
val v = fastCmd("magisk -v").split(":".toRegex())
return Env(
v[0], v.size >= 3 && v[2] == "D",
runCatching { fastCmd("magisk -V").toInt() }.getOrDefault(-1)
)
}
class Env( class Env(
val versionString: String = "", val versionString: String = "",
val isDebug: Boolean = false, val isDebug: Boolean = false,
@ -66,10 +60,21 @@ object Info {
) { ) {
val versionCode = when { val versionCode = when {
code < Const.Version.MIN_VERCODE -> -1 code < Const.Version.MIN_VERCODE -> -1
isRooted -> code isRooted -> code
else -> -1 else -> -1
} }
val isUnsupported = code > 0 && code < Const.Version.MIN_VERCODE val isUnsupported = code > 0 && code < Const.Version.MIN_VERCODE
val isActive = versionCode > 0 val isActive = versionCode > 0
} }
fun init(shell: Shell) {
if (shell.isRoot) {
isRooted = true
val v = fastCmd(shell, "magisk -v").split(":".toRegex())
env = Env(
v[0], v.size >= 3 && v[2] == "D",
runCatching { fastCmd("magisk -V").toInt() }.getOrDefault(-1)
)
}
}
} }

View File

@ -69,17 +69,6 @@ open class BoolDBProperty(
base.setValue(thisRef, property, if (value) 1 else 0) base.setValue(thisRef, property, if (value) 1 else 0)
} }
class BoolDBPropertyNoWrite(
name: String,
default: Boolean
) : BoolDBProperty(name, default) {
override fun setValue(thisRef: DBConfig, property: KProperty<*>, value: Boolean) {
synchronized(base) {
base.value = if (value) 1 else 0
}
}
}
class StringDBProperty( class StringDBProperty(
private val name: String, private val name: String,
private val default: String, private val default: String,

View File

@ -20,8 +20,8 @@ import java.util.jar.JarFile
class ShellInit : Shell.Initializer() { class ShellInit : Shell.Initializer() {
override fun onInit(context: Context, shell: Shell): Boolean { override fun onInit(context: Context, shell: Shell): Boolean {
Info.init(shell)
if (shell.isRoot) { if (shell.isRoot) {
Info.isRooted = true
RootUtils.bindTask?.let { shell.execTask(it) } RootUtils.bindTask?.let { shell.execTask(it) }
RootUtils.bindTask = null RootUtils.bindTask = null
} }
@ -88,6 +88,7 @@ class ShellInit : Shell.Initializer() {
Config.recovery = getBool("RECOVERYMODE") Config.recovery = getBool("RECOVERYMODE")
Config.keepVerity = getBool("KEEPVERITY") Config.keepVerity = getBool("KEEPVERITY")
Config.keepEnc = getBool("KEEPFORCEENCRYPT") Config.keepEnc = getBool("KEEPFORCEENCRYPT")
Config.denyList = shell.newJob().add("magisk --denylist status").exec().isSuccess
return true return true
} }

View File

@ -267,7 +267,7 @@ object Tapjack : BaseSettingsItem.Toggle() {
object Authentication : BaseSettingsItem.Toggle() { object Authentication : BaseSettingsItem.Toggle() {
override val title = R.string.settings_su_auth_title.asText() override val title = R.string.settings_su_auth_title.asText()
override var description = R.string.settings_su_auth_summary.asText() override var description = R.string.settings_su_auth_summary.asText()
override var value by Config::userAuth override var value by Config::suAuth
override fun refresh() { override fun refresh() {
isEnabled = Info.isDeviceSecure isEnabled = Info.isDeviceSecure

View File

@ -117,7 +117,7 @@ class SuperuserViewModel(
} }
} }
if (Config.userAuth) { if (Config.suAuth) {
AuthEvent { updateState() }.publish() AuthEvent { updateState() }.publish()
} else { } else {
SuperuserRevokeDialog(item.title) { updateState() }.show() SuperuserRevokeDialog(item.title) { updateState() }.show()
@ -170,7 +170,7 @@ class SuperuserViewModel(
} }
} }
if (Config.userAuth) { if (Config.suAuth) {
AuthEvent { updateState() }.publish() AuthEvent { updateState() }.publish()
} else { } else {
updateState() updateState()

View File

@ -76,7 +76,7 @@ class SuRequestViewModel(
fun grantPressed() { fun grantPressed() {
cancelTimer() cancelTimer()
if (Config.userAuth) { if (Config.suAuth) {
AuthEvent { respond(ALLOW) }.publish() AuthEvent { respond(ALLOW) }.publish()
} else { } else {
respond(ALLOW) respond(ALLOW)