Skip to content

Commit eb82103

Browse files
committed
Updated CRT state detection to respond to changes without reboot;
changed variable for orientation detection; resolves #7 and #14
1 parent 43f6e3f commit eb82103

2 files changed

Lines changed: 26 additions & 27 deletions

File tree

0 Bytes
Binary file not shown.

XposedTweakbox/src/de/robv/android/xposed/mods/tweakbox/XposedTweakbox.java

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package de.robv.android.xposed.mods.tweakbox;
22

3-
import static de.robv.android.xposed.XposedHelpers.getIntField;
43
import static de.robv.android.xposed.XposedHelpers.getSurroundingThis;
54
import static de.robv.android.xposed.XposedHelpers.setFloatField;
65
import static de.robv.android.xposed.XposedHelpers.setIntField;
@@ -10,7 +9,6 @@
109
import java.lang.reflect.Field;
1110
import java.lang.reflect.Method;
1211
import java.util.Locale;
13-
import java.util.Observable;
1412

1513
import android.app.AndroidAppHelper;
1614
import android.content.Context;
@@ -55,20 +53,21 @@ public void initZygote(StartupParam startupParam) {
5553
try {
5654
// this is not really necessary if no effects are wanted, but it speeds up turning off the screen
5755
XResources.setSystemWideReplacement("android", "bool", "config_animateScreenLights", false);
58-
Class<?> classSettingsObserver = Class.forName("com.android.server.PowerManagerService$SettingsObserver");
59-
Method methodUpdate = classSettingsObserver.getDeclaredMethod("update", Observable.class, Object.class);
60-
XposedBridge.hookMethod(methodUpdate, new XC_MethodHook() {
61-
@Override
62-
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
63-
Object powerManagerService = getSurroundingThis(param.thisObject);
64-
int mAnimationSetting = getIntField(powerManagerService, "mAnimationSetting");
65-
if (mAnimationSetting != 0) {
66-
mAnimationSetting = (pref.getBoolean("crt_off_effect", false)) ? ANIM_SETTING_OFF : 0;
67-
mAnimationSetting |= (pref.getBoolean("crt_on_effect", false)) ? ANIM_SETTING_ON : 0;
68-
setIntField(powerManagerService, "mAnimationSetting", mAnimationSetting);
69-
}
70-
}
71-
});
56+
// hook for CRT effects
57+
Class<?> classBrightnessState = Class.forName("com.android.server.PowerManagerService$BrightnessState");
58+
Method methodRun = classBrightnessState.getDeclaredMethod("run");
59+
XposedBridge.hookMethod(methodRun, new XC_MethodHook() {
60+
@Override
61+
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
62+
// About to turn off screen
63+
AndroidAppHelper.reloadSharedPreferencesIfNeeded(pref);
64+
Object powerManagerService = getSurroundingThis(param.thisObject);
65+
int animationSetting;
66+
animationSetting = (pref.getBoolean("crt_off_effect", false)) ? ANIM_SETTING_OFF : 0;
67+
animationSetting |= (pref.getBoolean("crt_on_effect", false)) ? ANIM_SETTING_ON : 0;
68+
setIntField(powerManagerService, "mAnimationSetting", animationSetting);
69+
}
70+
});
7271
} catch (Exception e) { XposedBridge.log(e); }
7372

7473
try {
@@ -276,18 +275,18 @@ protected Object replaceHookedMethod(MethodHookParam param) throws Throwable {
276275
});
277276
} catch (Exception e) { XposedBridge.log(e); }
278277
} else if (lpparam.packageName.equals("android")) {
279-
if (pref.getBoolean("crt_off_effect", false) || pref.getBoolean("crt_on_effect", false)) {
280-
try {
281-
Class<?> classMOL = Class.forName("com.android.internal.policy.impl.PhoneWindowManager$MyOrientationListener", false, lpparam.classLoader);
282-
XposedBridge.hookMethod(classMOL.getDeclaredMethod("onProposedRotationChanged", int.class), new XC_MethodHook() {
283-
@Override
284-
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
285-
int rotation = (Integer) param.args[0];
286-
SystemProperties.set("hw.crt.landscape", String.valueOf(rotation % 2));
278+
try {
279+
Class<?> classMOL = Class.forName("com.android.internal.policy.impl.PhoneWindowManager$MyOrientationListener", false, lpparam.classLoader);
280+
XposedBridge.hookMethod(classMOL.getDeclaredMethod("onProposedRotationChanged", int.class), new XC_MethodHook() {
281+
@Override
282+
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
283+
int rotation = (Integer) param.args[0];
284+
if (rotation >= 0) {
285+
SystemProperties.set("runtime.xposed.orientation", String.valueOf(rotation));
287286
}
288-
});
289-
} catch (Throwable t) { XposedBridge.log(t); }
290-
}
287+
}
288+
});
289+
} catch (Throwable t) { XposedBridge.log(t); }
291290
} else if (lpparam.packageName.equals("com.android.phone")) {
292291
try {
293292
Method displaySSInfo = Class.forName("com.android.phone.PhoneUtils", false, lpparam.classLoader).getDeclaredMethod("displaySSInfo",

0 commit comments

Comments
 (0)