Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions AntiWakeLock/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# AntiWakeLock

Disable WAKE_LOCK and FLAG_KEEP_SCREEN_ON.

Applies to selected apps only.
17 changes: 17 additions & 0 deletions AntiWakeLock/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
plugins {
alias(libs.plugins.buildlogic.android.application)
alias(libs.plugins.buildlogic.kotlin.android)
}

android {
namespace = "com.programminghoch10.AntiWakeLock"

defaultConfig {
minSdk = 1
targetSdk = 36
}
}

dependencies {
implementation(project(":logger"))
}
20 changes: 20 additions & 0 deletions AntiWakeLock/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android">

<application android:label="AntiWakeLock">
<meta-data
android:name="xposedmodule"
android:value="true"
/>
<meta-data
android:name="xposeddescription"
android:value="Disable WAKE_LOCK"
/>
<meta-data
android:name="xposedminversion"
android:value="93"
/>
</application>

</manifest>
2 changes: 2 additions & 0 deletions AntiWakeLock/src/main/assets/xposed_init
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
com.programminghoch10.AntiWakeLock.PowerManagerHook
com.programminghoch10.AntiWakeLock.WindowHook
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.programminghoch10.AntiWakeLock

import java.util.concurrent.*
import android.os.Build
import android.os.PowerManager
import android.os.WorkSource
import de.robv.android.xposed.IXposedHookLoadPackage
import de.robv.android.xposed.XC_MethodReplacement.DO_NOTHING
import de.robv.android.xposed.XC_MethodReplacement.returnConstant
import de.robv.android.xposed.XposedHelpers
import de.robv.android.xposed.callbacks.XC_LoadPackage

class PowerManagerHook : IXposedHookLoadPackage {
override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam) {
XposedHelpers.findAndHookMethod(PowerManager::class.java, "acquire", DO_NOTHING)
XposedHelpers.findAndHookMethod(PowerManager::class.java, "acquire", Int::class.java, DO_NOTHING)

// optional hooks for completeness
XposedHelpers.findAndHookMethod(PowerManager::class.java, "isHeld", returnConstant(false))
XposedHelpers.findAndHookMethod(PowerManager::class.java, "release", DO_NOTHING)
XposedHelpers.findAndHookMethod(PowerManager::class.java, "release", Int::class.java, DO_NOTHING)
XposedHelpers.findAndHookMethod(PowerManager::class.java, "setReferenceCounted", Boolean::class.java, DO_NOTHING)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) XposedHelpers.findAndHookMethod(
PowerManager::class.java,
"setStateListener",
Executor::class.java,
PowerManager.WakeLockStateListener::class.java,
DO_NOTHING,
)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) XposedHelpers.findAndHookMethod(
PowerManager::class.java,
"setWorkSource",
WorkSource::class.java,
DO_NOTHING,
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package com.programminghoch10.AntiWakeLock

import android.os.Build
import android.view.SurfaceView
import android.view.View
import android.view.Window
import android.view.WindowManager
import de.binarynoise.logger.Logger.log
import de.robv.android.xposed.IXposedHookLoadPackage
import de.robv.android.xposed.XC_MethodHook
import de.robv.android.xposed.XC_MethodReplacement.DO_NOTHING
import de.robv.android.xposed.XposedHelpers
import de.robv.android.xposed.callbacks.XC_LoadPackage

class WindowHook : IXposedHookLoadPackage {
fun filterKeepScreenOnFlag(flags: Int): Int {
return flags and WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON.inv()
}

override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam) {
XposedHelpers.findAndHookMethod(
Window::class.java,
"addFlags",
Int::class.java,
object : XC_MethodHook() {
override fun beforeHookedMethod(param: MethodHookParam) {
log("removing FLAG_KEEP_SCREEN_ON from addFlags")
param.args[0] = filterKeepScreenOnFlag(param.args[0] as Int)
}
},
)
XposedHelpers.findAndHookMethod(
Window::class.java,
"setFlags", Int::class.java, Int::class.java,
object : XC_MethodHook() {
override fun beforeHookedMethod(param: MethodHookParam) {
log("removing FLAG_KEEP_SCREEN_ON from setFlags")
param.args[0] = filterKeepScreenOnFlag(param.args[0] as Int)
param.args[1] = filterKeepScreenOnFlag(param.args[1] as Int)
}
},
)

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
try {
val AttachInfoClass = Class.forName(View::class.java.name + "\$AttachInfo", false, lpparam.classLoader)
XposedHelpers.findAndHookMethod(
SurfaceView::class.java,
"performCollectViewAttributes",
AttachInfoClass,
Int::class.java,
object : XC_MethodHook() {
override fun afterHookedMethod(param: MethodHookParam) {
val attachInfo = param.args[0]
XposedHelpers.setBooleanField(attachInfo, "mKeepScreenOn", false)
}
},
)
} catch (e: Throwable) {
log("failed to hook SurfaceView.performCollectViewAttributes", e)
}
}

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
try {
val ViewRootImplClass = Class.forName("android.view.ViewRootImpl", false, lpparam.classLoader)
XposedHelpers.findAndHookMethod(
ViewRootImplClass,
"applyKeepScreenOnFlag",
WindowManager.LayoutParams::class.java,
DO_NOTHING,
)
} catch (e: Throwable) {
log("failed to hook ViewRootImpl.applyKeepScreenOnFlag", e)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Disable WAKE_LOCK and FLAG_KEEP_SCREEN_ON.

Applies to selected apps only.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Disable WAKE_LOCK and FLAG_KEEP_SCREEN_ON.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
AntiWakeLock
1 change: 1 addition & 0 deletions modules.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
include(":AlwaysAllowChargingFeedback")
include(":AnimationScaleMod")
include(":AntiBrightnessChange")
include(":AntiWakeLock")
include(":AutomaticAdvancedSettingsExpander")
include(":BetterBluetoothDeviceSort")
include(":BetterVerboseWiFiLogging")
Expand Down
Loading