From 28770b9a3232788f11759fa9a7414c203fa2d047 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Thu, 26 Oct 2023 15:56:42 -0700 Subject: [PATCH] Support baseline profiles --- app/build.gradle.kts | 2 +- app/src/main/AndroidManifest.xml | 8 ++++++-- app/src/main/java/com/topjohnwu/magisk/core/App.kt | 9 +++++++++ buildSrc/src/main/java/Setup.kt | 2 -- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index b361cf209d67..894809b78d7a 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -65,7 +65,6 @@ setupApp() configurations.all { exclude("org.jetbrains.kotlin", "kotlin-stdlib-jdk7") exclude("org.jetbrains.kotlin", "kotlin-stdlib-jdk8") - exclude("androidx.profileinstaller", "profileinstaller") } dependencies { @@ -117,5 +116,6 @@ dependencies { implementation("androidx.transition:transition:1.4.1") implementation("androidx.core:core-ktx:1.12.0") implementation("androidx.core:core-splashscreen:1.0.1") + implementation("androidx.profileinstaller:profileinstaller:1.3.1") implementation("com.google.android.material:material:1.10.0") } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 68f548a48979..6b1aac312e66 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -82,11 +82,15 @@ android:name="androidx.room.MultiInstanceInvalidationService" tools:node="remove" /> - + + + + diff --git a/app/src/main/java/com/topjohnwu/magisk/core/App.kt b/app/src/main/java/com/topjohnwu/magisk/core/App.kt index f524b8a6a554..949b513534dc 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/App.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/App.kt @@ -5,6 +5,8 @@ import android.app.Application import android.content.Context import android.content.res.Configuration import android.os.Bundle +import androidx.profileinstaller.ProfileInstaller +import com.topjohnwu.magisk.BuildConfig import com.topjohnwu.magisk.StubApk import com.topjohnwu.magisk.core.di.ServiceLocator import com.topjohnwu.magisk.core.utils.DispatcherExecutor @@ -20,6 +22,8 @@ import com.topjohnwu.superuser.Shell import com.topjohnwu.superuser.internal.UiThreadHandler import com.topjohnwu.superuser.ipc.RootService import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.launch import timber.log.Timber import java.lang.ref.WeakReference import kotlin.system.exitProcess @@ -84,6 +88,11 @@ open class App() : Application() { super.onCreate() ProcessLifecycle.init(this) NetworkObserver.init(this) + if (!BuildConfig.DEBUG && !isRunningAsStub) { + GlobalScope.launch(Dispatchers.IO) { + ProfileInstaller.writeProfile(this@App) + } + } } override fun onConfigurationChanged(newConfig: Configuration) { diff --git a/buildSrc/src/main/java/Setup.kt b/buildSrc/src/main/java/Setup.kt index 4381ea3a73c5..709df72a2d3b 100644 --- a/buildSrc/src/main/java/Setup.kt +++ b/buildSrc/src/main/java/Setup.kt @@ -144,8 +144,6 @@ abstract class AddCommentTask: DefaultTask() { it.eocdComment = comment.get().toByteArray() it.get(IncrementalPackager.APP_METADATA_ENTRY_PATH)?.delete() it.get(JarFile.MANIFEST_NAME)?.delete() - it.get("assets/dexopt/baseline.prof")?.delete() - it.get("assets/dexopt/baseline.profm")?.delete() } outFile