Bump minSdk to 24 and drop API 23 workarounds

- Bump minSdk to 24 in Setup.kt, APP_PLATFORM to android-24 in
  Application.mk, and update CI AVD matrices and scripts.
- Unify SePatchStrategy::Legacy with SePatchStrategy::SelinuxFs in
  magiskinit to use MOCK_ENFORCE FIFO blocking and remove MOCK_REQPROT.
- Make APP_DATA_DIR a compile-time "/data/user_de" constant and remove
  pre-API 24 /data/user and /data/adb fallbacks.
- Remove Android 6.0 Samsung forkAndSpecialize JNI hook signature.
- Remove pre-API 24 device-protected storage wrappers, Api23Impl in
  LocaleSetting, AndroidManifest.xml stub resource workaround, and
  ServiceCompat/ProcessCompat/InlinedApi workarounds in the app.

Assisted-by: Gemini 4 Argon
This commit is contained in:
topjohnwu
2026-10-22 14:06:48 -07:00
committed by John Wu
parent af8c2566b0
commit b43a08fdde
35 changed files with 78 additions and 245 deletions
@@ -7,7 +7,6 @@ import android.content.ComponentCallbacks2
import android.content.Context
import android.content.ContextWrapper
import android.content.res.Configuration
import android.os.Build
import android.os.Build.VERSION.SDK_INT
import android.os.Bundle
import android.system.Os
@@ -115,14 +114,6 @@ object AppContext : ContextWrapper(null),
}
}
override fun createDeviceProtectedStorageContext(): Context {
return if (SDK_INT >= Build.VERSION_CODES.N) {
super.createDeviceProtectedStorageContext()
} else {
this
}
}
override fun onActivityCreated(activity: Activity, bundle: Bundle?) {}
override fun onActivityStopped(activity: Activity) {}
override fun onActivitySaveInstanceState(activity: Activity, bundle: Bundle) {}
@@ -1,6 +1,5 @@
package com.topjohnwu.magisk.core
import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import androidx.core.content.IntentCompat
@@ -18,7 +17,6 @@ open class Receiver : BaseReceiver() {
private val policyDB get() = ServiceLocator.policyDB
@SuppressLint("InlinedApi")
private fun getPkg(intent: Intent): String? {
val pkg = intent.getStringExtra(Intent.EXTRA_PACKAGE_NAME)
return pkg ?: intent.data?.schemeSpecificPart
@@ -3,7 +3,6 @@ package com.topjohnwu.magisk.core
import android.app.Notification
import android.content.Intent
import android.os.Build
import androidx.core.app.ServiceCompat
import androidx.core.content.IntentCompat
import com.topjohnwu.magisk.core.base.BaseService
import com.topjohnwu.magisk.core.download.DownloadEngine
@@ -34,6 +33,6 @@ class Service : BaseService(), DownloadSession {
}
override fun onDownloadComplete() {
ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE)
stopForeground(STOP_FOREGROUND_REMOVE)
}
}
@@ -10,7 +10,6 @@ import com.topjohnwu.magisk.core.data.SuLogDatabase
import com.topjohnwu.magisk.core.data.magiskdb.PolicyDao
import com.topjohnwu.magisk.core.data.magiskdb.SettingsDao
import com.topjohnwu.magisk.core.data.magiskdb.StringDao
import com.topjohnwu.magisk.core.ktx.deviceProtectedContext
import com.topjohnwu.magisk.core.repository.FirmwareCrawler
import com.topjohnwu.magisk.core.repository.LogRepository
import com.topjohnwu.magisk.core.repository.NetworkService
@@ -20,7 +19,7 @@ import io.noties.markwon.utils.NoCopySpannableFactory
@SuppressLint("StaticFieldLeak")
object ServiceLocator {
val deContext by lazy { AppContext.deviceProtectedContext }
val deContext by lazy { AppContext.createDeviceProtectedStorageContext() }
// Database
val policyDB = PolicyDao()
@@ -48,7 +48,7 @@ import java.io.InputStream
* the session to make sure all download operations can be completed without the operating system
* killing the session.
*
* For API 23 - 33, we use a foreground service as a session.
* For API 24 - 33, we use a foreground service as a session.
* For API 34 and higher, we use user-initiated job services as a session.
*/
class DownloadEngine(session: DownloadSession) : DownloadSession by session, DownloadNotifier {
@@ -46,11 +46,6 @@ fun Context.getBitmap(id: Int): Bitmap {
return bitmap
}
val Context.deviceProtectedContext: Context get() =
if (SDK_INT >= Build.VERSION_CODES.N) {
createDeviceProtectedStorageContext()
} else { this }
fun Context.cachedFile(name: String) = File(cacheDir, name)
fun ApplicationInfo.getLabel(pm: PackageManager): String {
@@ -29,38 +29,6 @@ interface LocaleSetting {
fun setLocale(tag: String)
fun updateResource(res: Resources)
private class Api23Impl : LocaleSetting {
private val systemLocale: Locale = Locale.getDefault()
override var appLocale: Locale? = null
override var currentLocale: Locale = systemLocale
init {
setLocale(Config.locale)
}
override fun setLocale(tag: String) {
val locale = when {
tag.isEmpty() -> null
else -> Locale.forLanguageTag(tag)
}
currentLocale = locale ?: systemLocale
appLocale = locale
Locale.setDefault(currentLocale)
updateResource(AppContext.resources)
AppContext.foregroundActivity?.relaunch()
}
@Suppress("DEPRECATION")
override fun updateResource(res: Resources) {
val config = res.configuration
config.setLocale(currentLocale)
res.updateConfiguration(config, null)
}
}
@RequiresApi(24)
private class Api24Impl : LocaleSetting {
private val systemLocaleList = LocaleList.getDefault()
@@ -185,8 +153,6 @@ interface LocaleSetting {
available
if (useLocaleManager) {
Api33Impl()
} else if (Build.VERSION.SDK_INT <= 23) {
Api23Impl()
} else {
Api24Impl()
}
@@ -6,7 +6,6 @@ import com.topjohnwu.magisk.core.Const
import com.topjohnwu.magisk.core.Info
import com.topjohnwu.magisk.core.isRunningAsStub
import com.topjohnwu.magisk.core.ktx.cachedFile
import com.topjohnwu.magisk.core.ktx.deviceProtectedContext
import com.topjohnwu.magisk.core.ktx.writeTo
import com.topjohnwu.superuser.Shell
import kotlinx.coroutines.Dispatchers
@@ -30,7 +29,7 @@ class ShellInit : Shell.Initializer() {
return true
val jar = JarFile(StubApk.current(context))
val bb = jar.getJarEntry("lib/${Const.CPU_ABI}/libbusybox.so")
localBB = context.deviceProtectedContext.cachedFile("busybox")
localBB = context.createDeviceProtectedStorageContext().cachedFile("busybox")
localBB.delete()
runBlocking {
jar.getInputStream(bb).writeTo(localBB, dispatcher = Dispatchers.Unconfined)
@@ -1,6 +1,5 @@
package com.topjohnwu.magisk.test
import android.os.Build
import android.os.ParcelFileDescriptor.AutoCloseInputStream
import androidx.annotation.Keep
import androidx.test.ext.junit.runners.AndroidJUnit4
@@ -43,13 +42,7 @@ class SmokeTest : TestCommon {
}
// Try to call su from ADB shell
val cmd = if (Build.VERSION.SDK_INT < 24) {
// API 23 runs executeShellCommand as root
"/system/xbin/su 2000 su -c id"
} else {
"su -c id"
}
val pfd = uiAutomation.executeShellCommand(cmd)
val pfd = uiAutomation.executeShellCommand("su -c id")
// Check that root access is granted
AutoCloseInputStream(pfd).reader().use {