From 97039af9d7ed1fe4d5f3a6d69f8813759f41fae3 Mon Sep 17 00:00:00 2001 From: AsyJAIZ <2007andrylavr@gmail.com> Date: Sun, 1 Oct 2023 04:26:08 +0200 Subject: [PATCH] Android 14 support --- app/build.gradle | 6 +- .../java/com/asyjaiz/A12blur/Replace.java | 145 ++++++++++++------ 2 files changed, 99 insertions(+), 52 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 505ebf7..c310232 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,17 +9,17 @@ android { applicationId "com.asyjaiz.A12blur" minSdk 31 targetSdk 31 - versionCode 4 - versionName "1.31N" + versionCode 5 + versionName "1.4N" archivesBaseName = "NST" - //testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + signingConfig signingConfigs.debug } } compileOptions { diff --git a/app/src/main/java/com/asyjaiz/A12blur/Replace.java b/app/src/main/java/com/asyjaiz/A12blur/Replace.java index 8c790cf..862ed6c 100644 --- a/app/src/main/java/com/asyjaiz/A12blur/Replace.java +++ b/app/src/main/java/com/asyjaiz/A12blur/Replace.java @@ -1,6 +1,6 @@ package com.asyjaiz.A12blur; -import static de.robv.android.xposed.XposedHelpers.findAndHookConstructor; +import static de.robv.android.xposed.XposedHelpers.findConstructorExact; import static de.robv.android.xposed.XposedHelpers.setFloatField; import android.content.res.XModuleResources; @@ -9,6 +9,7 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; +import java.lang.reflect.Constructor; import de.robv.android.xposed.IXposedHookInitPackageResources; import de.robv.android.xposed.IXposedHookLoadPackage; @@ -19,6 +20,8 @@ import de.robv.android.xposed.callbacks.XC_LoadPackage; public class Replace implements IXposedHookLoadPackage, IXposedHookInitPackageResources { + + String rootPackage = "com.android.systemui"; private String rootPackagePath; boolean supportsBlur; @@ -27,8 +30,6 @@ public class Replace implements IXposedHookLoadPackage, IXposedHookInitPackageRe boolean lowRam; boolean disableBlur; - Object[] parameterTypesAndCallback; - public static Boolean read(String propName) { Process process = null; BufferedReader bufferedReader = null; @@ -92,6 +93,97 @@ public static Boolean read(String propName) { } else return defaultA; } */ + private Constructor findConstructor(boolean forceOld13Constructor, Class hookClass) throws Throwable { + Object[] parameterTypesAndCallback = new Object[0]; + if (Build.VERSION.SDK_INT >= 33) { + if (Build.TIME > 1678278441000L && !forceOld13Constructor) { + if (BuildConfig.DEBUG) { + XposedBridge.log("Your device is using a build of the new type."); + } + parameterTypesAndCallback = new Object [] { + rootPackage + ".statusbar.phone.LightBarController", + rootPackage + ".statusbar.phone.DozeParameters", + "android.app.AlarmManager", + rootPackage + ".statusbar.policy.KeyguardStateController", + rootPackage + ".util.wakelock.DelayedWakeLock.Builder", + "android.os.Handler", + "com.android.keyguard.KeyguardUpdateMonitor", + rootPackage + ".dock.DockManager", + rootPackage + ".statusbar.policy.ConfigurationController", + "java.util.concurrent.Executor", + rootPackage + ".statusbar.phone.ScreenOffAnimationController", + rootPackage + ".keyguard.KeyguardUnlockAnimationController", + rootPackage + ".statusbar.phone.StatusBarKeyguardViewManager", + rootPackage + ".keyguard.ui.viewmodel.PrimaryBouncerToGoneTransitionViewModel", + rootPackage + ".keyguard.domain.interactor.KeyguardTransitionInteractor", + "kotlinx.coroutines.CoroutineDispatcher", + rootPackage + ".shade.transition.LargeScreenShadeInterpolator", + rootPackage + ".flags.FeatureFlags" + }; + try { + return findConstructorExact(hookClass, parameterTypesAndCallback); + } catch (Throwable t) { + if (BuildConfig.DEBUG) { + XposedBridge.log("Problem with finding corresponding constructor, retrying with an old scheme"); + } + return findConstructor(true, hookClass); + } + } else { + parameterTypesAndCallback = new Object [] { + rootPackage + ".statusbar.phone.LightBarController", + rootPackage + ".statusbar.phone.DozeParameters", + "android.app.AlarmManager", + rootPackage + ".statusbar.policy.KeyguardStateController", + rootPackage + ".util.wakelock.DelayedWakeLock.Builder", + "android.os.Handler", + "com.android.keyguard.KeyguardUpdateMonitor", + rootPackage + ".dock.DockManager", + rootPackage + ".statusbar.policy.ConfigurationController", + "java.util.concurrent.Executor", + rootPackage + ".statusbar.phone.ScreenOffAnimationController", + rootPackage + ".keyguard.KeyguardUnlockAnimationController", + rootPackage + ".statusbar.phone.StatusBarKeyguardViewManager", + }; + } + } + else if (Build.VERSION.SDK_INT == 32) { + parameterTypesAndCallback = new Object [] { + rootPackage + ".statusbar.phone.LightBarController", + rootPackage + ".statusbar.phone.DozeParameters", + "android.app.AlarmManager", + rootPackage + ".statusbar.policy.KeyguardStateController", + rootPackage + ".util.wakelock.DelayedWakeLock.Builder", + "android.os.Handler", + "com.android.keyguard.KeyguardUpdateMonitor", + rootPackage + ".dock.DockManager", + rootPackage + ".statusbar.policy.ConfigurationController", + "java.util.concurrent.Executor", + rootPackage + ".statusbar.phone.UnlockedScreenOffAnimationController", + rootPackage + ".statusbar.phone.panelstate.PanelExpansionStateManager" + }; + } + else if (Build.VERSION.SDK_INT == 31) { + parameterTypesAndCallback = new Object [] { + rootPackage + ".statusbar.phone.LightBarController", + rootPackage + ".statusbar.phone.DozeParameters", + "android.app.AlarmManager", + rootPackage + ".statusbar.policy.KeyguardStateController", + rootPackage + ".util.wakelock.DelayedWakeLock.Builder", + "android.os.Handler", + "com.android.keyguard.KeyguardUpdateMonitor", + rootPackage + ".dock.DockManager", + rootPackage + ".statusbar.policy.ConfigurationController", + "java.util.concurrent.Executor", + rootPackage + ".statusbar.phone.UnlockedScreenOffAnimationController" + }; + } + return findConstructorExact(hookClass, parameterTypesAndCallback); + } + + private Constructor findConstructor(Class hookClass) throws Throwable { + return findConstructor(false, hookClass); + } + @Override public void handleInitPackageResources(XC_InitPackageResources.InitPackageResourcesParam resParam) throws Throwable { XModuleResources modRes = XModuleResources.createInstance(rootPackagePath, null); @@ -99,7 +191,6 @@ public void handleInitPackageResources(XC_InitPackageResources.InitPackageResour } public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpParam) throws Throwable { - String rootPackage = "com.android.systemui"; if (!lpParam.packageName.equals(rootPackage)) return; @@ -120,7 +211,6 @@ public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpParam) throws Th float alpha = capable ? 0.54f : 0.85f; final Class ScrimController = XposedHelpers.findClass(rootPackage + ".statusbar.phone.ScrimController", lpParam.classLoader); - XC_MethodHook xcMethodHook = new XC_MethodHook() { @Override protected void afterHookedMethod(MethodHookParam param) throws Throwable { @@ -128,51 +218,8 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable { } }; - if (Build.VERSION.SDK_INT >= 33) { parameterTypesAndCallback = new Object [] { - rootPackage + ".statusbar.phone.LightBarController", - rootPackage + ".statusbar.phone.DozeParameters", - "android.app.AlarmManager", - rootPackage + ".statusbar.policy.KeyguardStateController", - rootPackage + ".util.wakelock.DelayedWakeLock.Builder", - "android.os.Handler", - "com.android.keyguard.KeyguardUpdateMonitor", - rootPackage + ".dock.DockManager", - rootPackage + ".statusbar.policy.ConfigurationController", - "java.util.concurrent.Executor", - rootPackage + ".statusbar.phone.ScreenOffAnimationController", - rootPackage + ".keyguard.KeyguardUnlockAnimationController", - rootPackage + ".statusbar.phone.StatusBarKeyguardViewManager", - xcMethodHook};} - else if (Build.VERSION.SDK_INT == 32) { parameterTypesAndCallback = new Object [] { - rootPackage + ".statusbar.phone.LightBarController", - rootPackage + ".statusbar.phone.DozeParameters", - "android.app.AlarmManager", - rootPackage + ".statusbar.policy.KeyguardStateController", - rootPackage + ".util.wakelock.DelayedWakeLock.Builder", - "android.os.Handler", - "com.android.keyguard.KeyguardUpdateMonitor", - rootPackage + ".dock.DockManager", - rootPackage + ".statusbar.policy.ConfigurationController", - "java.util.concurrent.Executor", - rootPackage + ".statusbar.phone.UnlockedScreenOffAnimationController", - rootPackage + ".statusbar.phone.panelstate.PanelExpansionStateManager", - xcMethodHook};} - else if (Build.VERSION.SDK_INT == 31) { parameterTypesAndCallback = new Object [] { - rootPackage + ".statusbar.phone.LightBarController", - rootPackage + ".statusbar.phone.DozeParameters", - "android.app.AlarmManager", - rootPackage + ".statusbar.policy.KeyguardStateController", - rootPackage + ".util.wakelock.DelayedWakeLock.Builder", - "android.os.Handler", - "com.android.keyguard.KeyguardUpdateMonitor", - rootPackage + ".dock.DockManager", - rootPackage + ".statusbar.policy.ConfigurationController", - "java.util.concurrent.Executor", - rootPackage + ".statusbar.phone.UnlockedScreenOffAnimationController", - xcMethodHook};} - if (BuildConfig.DEBUG) XposedBridge.log("Trying to hook a ScrimController constructor."); - findAndHookConstructor(ScrimController, parameterTypesAndCallback); + XposedBridge.hookMethod(findConstructor(ScrimController), xcMethodHook); } }