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
@@ -263,7 +263,6 @@ class MainActivity : ComponentActivity(), SplashScreenHost {
}
}
@SuppressLint("InlinedApi")
override fun showInvalidStateMessage() {
showInvalidState.value = true
}
@@ -12,7 +12,7 @@ import android.content.pm.PackageManager.MATCH_DISABLED_COMPONENTS
import android.content.pm.PackageManager.MATCH_UNINSTALLED_PACKAGES
import android.content.pm.ServiceInfo
import android.graphics.drawable.Drawable
import androidx.core.os.ProcessCompat
import android.os.Process
import com.topjohnwu.magisk.core.ktx.getLabel
import java.util.Locale
import java.util.TreeSet
@@ -58,7 +58,7 @@ class AppProcessInfo(
fun isSystemApp() = info.flags and ApplicationInfo.FLAG_SYSTEM != 0
fun isApp() = packageName == WEBVIEW_ZYGOTE_MAGIC || ProcessCompat.isApplicationUid(info.uid)
fun isApp() = packageName == WEBVIEW_ZYGOTE_MAGIC || Process.isApplicationUid(info.uid)
private fun createProcess(name: String, pkg: String = info.packageName) =
ProcessInfo(name, pkg, denyList.any { it.process == name && it.packageName == pkg })
@@ -1,6 +1,5 @@
package com.topjohnwu.magisk.ui.deny
import android.annotation.SuppressLint
import android.content.pm.PackageManager.MATCH_UNINSTALLED_PACKAGES
import androidx.lifecycle.viewModelScope
import com.topjohnwu.magisk.arch.AsyncLoadViewModel
@@ -179,7 +178,6 @@ class DenyListViewModel : AsyncLoadViewModel() {
}
}
@SuppressLint("InlinedApi")
override suspend fun doLoadWork() {
_loading.value = true
val apps = withContext(Dispatchers.Default) {
@@ -1,10 +1,9 @@
package com.topjohnwu.magisk.ui.superuser
import android.annotation.SuppressLint
import android.content.pm.ApplicationInfo
import android.content.pm.PackageManager.MATCH_UNINSTALLED_PACKAGES
import android.graphics.drawable.Drawable
import androidx.core.os.ProcessCompat
import android.os.Process
import androidx.lifecycle.viewModelScope
import com.topjohnwu.magisk.arch.AsyncLoadViewModel
import com.topjohnwu.magisk.core.AppContext
@@ -186,7 +185,6 @@ class SuperuserGrantViewModel(
}
}
@SuppressLint("InlinedApi")
override suspend fun doLoadWork() {
if (_allApps.value.isNotEmpty()) return
_loading.value = true
@@ -234,7 +232,7 @@ class SuperuserGrantViewModel(
val label = appInfo.getLabel(pm)
val icon = runCatching { appInfo.loadIcon(pm) }.getOrDefault(pm.defaultActivityIcon)
val isSystemApp = (appInfo.flags and ApplicationInfo.FLAG_SYSTEM) != 0
val isApp = ProcessCompat.isApplicationUid(appInfo.uid)
val isApp = Process.isApplicationUid(appInfo.uid)
val suAppInfo = SuGrantAppInfo(
label = label,
packageName = appInfo.packageName,
@@ -1,6 +1,5 @@
package com.topjohnwu.magisk.ui.superuser
import android.annotation.SuppressLint
import android.content.pm.PackageManager
import android.content.pm.PackageManager.MATCH_UNINSTALLED_PACKAGES
import android.graphics.drawable.Drawable
@@ -63,7 +62,6 @@ class SuperuserViewModel(
private val _uiState = MutableStateFlow(UiState())
val uiState: StateFlow<UiState> = _uiState.asStateFlow()
@SuppressLint("InlinedApi")
override suspend fun doLoadWork() {
if (!Info.showSuperUser) {
_uiState.update { it.copy(loading = false) }
+1 -2
View File
@@ -52,7 +52,7 @@ fun Project.setupCommon() {
ndkVersion = "30.0.15729638"
defaultConfig.apply {
minSdk = 23
minSdk = 24
}
compileOptions.apply {
@@ -280,7 +280,6 @@ fun Project.setupMainApk() {
defaultConfig {
applicationId = "com.topjohnwu.magisk"
vectorDrawables.useSupportLibrary = true
versionName = Config.version
versionCode = Config.versionCode
ndk {
@@ -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 {
@@ -26,14 +26,8 @@ public class StubApk {
private static File getDynDir(ApplicationInfo info) {
if (dynDir == null) {
final String dataDir;
if (SDK_INT >= Build.VERSION_CODES.N) {
// Use device protected path to allow directBootAware
dataDir = info.deviceProtectedDataDir;
} else {
dataDir = info.dataDir;
}
dynDir = new File(dataDir, "dyn");
// Use device protected path to allow directBootAware
dynDir = new File(info.deviceProtectedDataDir, "dyn");
dynDir.mkdirs();
}
return dynDir;
@@ -31,7 +31,6 @@ import java.io.IOException;
import java.io.OutputStream;
import java.util.zip.InflaterInputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipOutputStream;
import javax.crypto.Cipher;
@@ -158,11 +157,7 @@ public class DownloadActivity extends Activity {
} else {
File apk = new File(getCodeCacheDir(), "res.apk");
try (var out = new ZipOutputStream(new FileOutputStream(apk))) {
// AndroidManifest.xml is required on Android 6-, and directory support is broken on Android 9-10
out.putNextEntry(new ZipEntry("AndroidManifest.xml"));
try (var stubApk = new ZipFile(getPackageCodePath())) {
APKInstall.transfer(stubApk.getInputStream(stubApk.getEntry("AndroidManifest.xml")), out);
}
// Directory support is broken on Android 9-10
out.putNextEntry(new ZipEntry("resources.arsc"));
decryptResources(out);
}
@@ -118,7 +118,6 @@ public class DynLoad {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q)
replaceClassLoader(context);
// noinspection InlinedApi
int flags = PackageManager.GET_ACTIVITIES | PackageManager.GET_SERVICES
| PackageManager.GET_PROVIDERS | PackageManager.GET_RECEIVERS
| PackageManager.MATCH_DIRECT_BOOT_AWARE | PackageManager.MATCH_DISABLED_COMPONENTS
@@ -196,7 +195,7 @@ public class DynLoad {
mcl.set(loadedApk, new DelegateClassLoader());
} catch (Exception e) {
// Actually impossible as this method is only called on API < 29,
// and API 23 - 28 do not restrict access to these fields.
// and API 24 - 28 do not restrict access to these fields.
Log.e(DynLoad.class.getSimpleName(), "", e);
}
}