Skip to content

Commit

Permalink
NOW we rollin'!
Browse files Browse the repository at this point in the history
  • Loading branch information
AsyJAIZ committed Oct 16, 2024
1 parent 1c1391c commit b67ae16
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 24 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

**Compatible with Android 12+**

![Android 15](notifshade15d.png "Screenshot of module working on Android 15, dark theme")![Android 15](notifshade15l.png "Screenshot of module working on Android 15, light theme")
![Dark theme preview](notifshade15d.png "Screenshot of the module working on Android 15, dark theme")![Light theme preview](notifshade15l.png "Screenshot of the module working on Android 15, light theme")

### License
This project is licensed under the Apache License, Version 2.0 (the "License"). See [LICENSE](LICENSE) for details.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ android {
minSdk 31
targetSdk 35
versionCode 6
versionName "1.5N"
versionName "1.5G"

archivesBaseName = "NST"
}
Expand Down
97 changes: 75 additions & 22 deletions app/src/main/java/com/asyjaiz/A12blur/Replace.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package com.asyjaiz.A12blur;

import static de.robv.android.xposed.XposedBridge.hookMethod;
import static de.robv.android.xposed.XposedBridge.log;
import static de.robv.android.xposed.XposedHelpers.callMethod;
import static de.robv.android.xposed.XposedHelpers.findAndHookMethod;
import static de.robv.android.xposed.XposedHelpers.findClass;
import static de.robv.android.xposed.XposedHelpers.findField;
import static de.robv.android.xposed.XposedHelpers.findMethodBestMatch;
import static de.robv.android.xposed.XposedHelpers.getFloatField;
import static de.robv.android.xposed.XposedHelpers.setFloatField;

import android.content.res.XModuleResources;
Expand All @@ -11,7 +16,9 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Arrays;

import de.robv.android.xposed.IXposedHookInitPackageResources;
import de.robv.android.xposed.IXposedHookLoadPackage;
Expand Down Expand Up @@ -40,13 +47,9 @@ public static Boolean read(String propName) {
process = new ProcessBuilder().command("/system/bin/getprop", propName).start();
bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line = bufferedReader.readLine();
boolean contains = line.contains("true") || line.contains("1");
if (BuildConfig.DEBUG) XposedBridge.log("Check for " + propName + " returned " +
line +
(contains ? " and contains a success value" : " and doesn't contain a success value"));
return contains;
return line.contains("true") || line.contains("1");
} catch (Exception e) {
XposedBridge.log("Something went wrong: " + e + "\nMake a new issue on a Github page.");
log("Something went wrong: " + e + "\nMake a new issue on a Github page.");
return false;
} finally {
if (bufferedReader != null){
Expand Down Expand Up @@ -75,31 +78,51 @@ public void handleInitPackageResources(XC_InitPackageResources.InitPackageResour
avoidAccel1 = modRes.getBoolean(modRes.getIdentifier("config_avoidGfxAccel", "bool", "android"));
}

static float GAR = 0.54f;
public static void quickCheck(float value) {
if (GAR > value) log("You may want to set value " + value + "to " + GAR + "or higher for better text visibility");
}

public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpParam) throws Throwable {
if (!lpParam.packageName.equals(rootPackage))
return;

if (BuildConfig.DEBUG) {
XposedBridge.log("Debug and diagnostics.");
log("Debug and diagnostics.");
}


XSharedPreferences prefs = new XSharedPreferences(BuildConfig.APPLICATION_ID, "set");
if (BuildConfig.DEBUG)
XposedBridge.log("Can read preferences? " + prefs.getFile().canRead());
log("Can read preferences? " + prefs.getFile().canRead());

float notifAlpha;
if (prefs.getBoolean("auto", true)) {
boolean auto = prefs.getBoolean("auto", true);
if (auto) {
supportsBlur = read("ro.surface_flinger.supports_background_blur");
avoidAccel2 = read("ro.config.avoid_gfx_accel");
lowRam = read("ro.config.low_ram");
disableBlur = read("persist.sysui.disableBlur");
boolean capable = supportsBlur && !avoidAccel1 && !avoidAccel2 && !lowRam && !disableBlur; // yes, sadly we can't just call BlurUtils check for this, so we should do this on our own
if (BuildConfig.DEBUG) XposedBridge.log(capable ?
if (BuildConfig.DEBUG) log(capable ?
"Your device is capable of handling blur. Using a corresponding alpha value" :
"Your device is not capable of handling blur. Using a default alpha value");
notifAlpha = capable ? 0.54f : 0.85f;
if (!capable && BuildConfig.DEBUG) {
StringBuilder builder = new StringBuilder("Possible culprits:\n");
if (!supportsBlur)
builder.append(" Your SurfaceFlinger may have blur disabled\n");
if (avoidAccel1 || avoidAccel2)
builder.append(" System avoids graphical acceleration\n");
if (lowRam)
builder.append(" Device reports to be a low ram device\n");
if (disableBlur)
builder.append(" Blur is disabled in SystemUI by a property");
log(builder.toString());
}
notifAlpha = capable ? GAR : 0.85f;
} else {
notifAlpha = prefs.getFloat("notif_alpha", 1.0f);
quickCheck(notifAlpha);
}

String base = ".statusbar.phone.";
Expand All @@ -111,10 +134,13 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
}
};

if (BuildConfig.DEBUG) XposedBridge.log("Trying to hook a ScrimController constructor.");
XposedBridge.hookMethod(findConstructor(ScrimController), xcMethodHook);
if (BuildConfig.DEBUG) log("Trying to hook a ScrimController constructor.");
hookMethod(findConstructor(ScrimController), xcMethodHook);

if (BuildConfig.DEBUG) XposedBridge.log("Hooking ScrimState");
if (auto) return;
float alpha = prefs.getFloat("behind_alpha", 1f);
quickCheck(alpha);
/*if (BuildConfig.DEBUG) log("Hooking ScrimState");
final Class<?> ScrimState = findClass(rootPackage + base + "ScrimState", lpParam.classLoader);
final Class<?> ScrimView = findClass(rootPackage + ".scrim.ScrimView", lpParam.classLoader);
Method updateScrimColor;
Expand All @@ -133,33 +159,60 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
}
final boolean finalStripped = stripped;
float alpha = prefs.getFloat("behind_alpha", 1f);
XC_MethodHook hook = new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
if (BuildConfig.DEBUG) XposedBridge.log("beforeHook");
Object mScrimBehind = XposedHelpers.findField(ScrimState, "mScrimBehind").get(param.thisObject);
Object mScrimBehind = findField(ScrimState, "mScrimBehind").get(param.thisObject);
if (!mScrimBehind.equals(param.args[0]))
return;
if (!finalStripped)
if ((Float) param.args[1] == 1f)
if ((Float) param.args[1] == 1f) {
param.args[1] = alpha;
//log("Alpha is " + param.args[1]);
}
}
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
super.afterHookedMethod(param);
if (BuildConfig.DEBUG) XposedBridge.log("afterHook");

Object mScrimBehind = XposedHelpers.findField(ScrimState, "mScrimBehind").get(param.thisObject);
Object mScrimBehind = findField(ScrimState, "mScrimBehind").get(param.thisObject);
if (finalStripped) {
callMethod(mScrimBehind, "setViewAlpha", alpha);
//log("Alpha is " + (Float) callMethod(mScrimBehind, "getViewAlpha"));
}
}
};
XposedBridge.hookMethod(updateScrimColor, hook);
if (BuildConfig.DEBUG) log("Hooking updateScrimColor");
hookMethod(updateScrimColor, hook);*/

if (BuildConfig.DEBUG) log("Hooking applyState in ScrimController");
Method applyState;
try {
applyState = findMethodBestMatch(ScrimController, "applyState");
} catch (NoSuchMethodError e) {
try {
applyState = findMethodBestMatch(ScrimController, "applyState$1");
} catch (NoSuchMethodError ex) {
try {
applyState = findMethodBestMatch(ScrimController, "applyState$1$1");
} catch (NoSuchMethodError exc) {
log("applyState function was not found. Please open a new GitHub issue and provide next info:\n1. OS version\n2. Error log\n3. SystemUI folder copy");
throw new RuntimeException(exc);
}
}
}
hookMethod(applyState, new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
super.afterHookedMethod(param);
Field mBehindAlpha = findField(ScrimController, "mBehindAlpha");
if (mBehindAlpha.getFloat(param.thisObject) == 1f) {
mBehindAlpha.setFloat(param.thisObject, alpha);
}
}
});
}
}

0 comments on commit b67ae16

Please sign in to comment.