Skip to content

Commit 4af5b29

Browse files
authored
add AntiBrightnessChange modulet (#2)
This adds a new modulet which removes the ability of an app to overwrite the screen brightness. Works limited to an app, and also to every app, if android is selected as target package.
2 parents 09404f2 + 398903e commit 4af5b29

File tree

10 files changed

+105
-0
lines changed

10 files changed

+105
-0
lines changed

AntiBrightnessChange/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# AntiBrightnessChange
2+
3+
This module prevents selected apps from overwriting the screen brightness.
4+
5+
If applied to System Framework (`android`)
6+
it will prevent every app from changing the screen brightness.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
plugins {
2+
id("com.android.application")
3+
}
4+
5+
android {
6+
val packageName = "com.programminghoch10.AntiBrightnessChange"
7+
namespace = packageName
8+
9+
defaultConfig {
10+
applicationId = packageName
11+
minSdk = 33
12+
targetSdk = 33
13+
compileSdk = 33
14+
versionCode = 1
15+
versionName = "1.0"
16+
}
17+
}
18+
19+
dependencies {}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
xmlns:tools="http://schemas.android.com/tools"
5+
>
6+
7+
<application
8+
android:label="AntiBrightnessChange"
9+
tools:ignore="MissingApplicationIcon"
10+
>
11+
<meta-data
12+
android:name="xposedmodule"
13+
android:value="true"
14+
/>
15+
<meta-data
16+
android:name="xposeddescription"
17+
android:value="Prevent apps from changing display brightness."
18+
/>
19+
<meta-data
20+
android:name="xposedminversion"
21+
android:value="82"
22+
/>
23+
<meta-data
24+
android:name="xposedscope"
25+
android:resource="@array/scope"
26+
/>
27+
</application>
28+
29+
</manifest>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
com.programminghoch10.AntiBrightnessChange.Hook
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.programminghoch10.AntiBrightnessChange;
2+
3+
import static android.view.WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE;
4+
5+
import android.view.WindowManager;
6+
7+
import androidx.annotation.Keep;
8+
9+
import de.robv.android.xposed.IXposedHookLoadPackage;
10+
import de.robv.android.xposed.XC_MethodHook;
11+
import de.robv.android.xposed.XposedHelpers;
12+
import de.robv.android.xposed.callbacks.XC_LoadPackage;
13+
14+
@Keep
15+
public class Hook implements IXposedHookLoadPackage {
16+
@Override
17+
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) {
18+
if (lpparam.packageName.equals("android")) {
19+
XposedHelpers.findAndHookMethod("com.android.server.wm.RootWindowContainer", lpparam.classLoader, "handleNotObscuredLocked",
20+
"com.android.server.wm.WindowState", boolean.class, boolean.class, new XC_MethodHook() {
21+
@Override
22+
protected void afterHookedMethod(MethodHookParam param) {
23+
XposedHelpers.setFloatField(param.thisObject, "mScreenBrightnessOverride", Float.NaN);
24+
}
25+
});
26+
return;
27+
}
28+
29+
XposedHelpers.findAndHookMethod(WindowManager.LayoutParams.class, "copyFrom", WindowManager.LayoutParams.class, new XC_MethodHook() {
30+
@Override
31+
protected void beforeHookedMethod(MethodHookParam param) {
32+
WindowManager.LayoutParams layoutParams = (WindowManager.LayoutParams) param.args[0];
33+
layoutParams.screenBrightness = BRIGHTNESS_OVERRIDE_NONE;
34+
layoutParams.buttonBrightness = BRIGHTNESS_OVERRIDE_NONE;
35+
}
36+
});
37+
}
38+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<string-array name="scope">
4+
</string-array>
5+
</resources>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
This module prevents selected apps from overwriting the screen brightness.
2+
3+
If applied to System Framework (`android`)
4+
it will prevent every app from changing the screen brightness.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Prevents selected apps from overwriting the screen brightness.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Anti Brightness Change

settings.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ dependencyResolutionManagement {
1818
}
1919

2020
rootProject.name = "XposedModulets"
21+
include(":AntiBrightnessChange")
2122
include(":AutomaticAdvancedSettingsExpander")
2223
include(":BetterVerboseWiFiLogging")
2324
include(":BetterBluetoothDeviceSort")

0 commit comments

Comments
 (0)