Skip to content

Commit

Permalink
Android 14 support
Browse files Browse the repository at this point in the history
  • Loading branch information
AsyJAIZ committed Oct 1, 2023
1 parent 0de84c6 commit 97039af
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 52 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
145 changes: 96 additions & 49 deletions app/src/main/java/com/asyjaiz/A12blur/Replace.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -92,14 +93,104 @@ 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);
avoidAccel1 = modRes.getBoolean(modRes.getIdentifier("config_avoidGfxAccel", "bool", "android"));
}

public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpParam) throws Throwable {
String rootPackage = "com.android.systemui";
if (!lpParam.packageName.equals(rootPackage))
return;

Expand All @@ -120,59 +211,15 @@ 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 {
setFloatField(param.thisObject, "mDefaultScrimAlpha", alpha);
}
};

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);
}
}

0 comments on commit 97039af

Please sign in to comment.