在 logcat 中我发现了以下几行:
06-12 13:22:09.250 2484-2510/system_process I/Terry-FB: strSuspendImgFileName = /storage/sdcard1/suspend_others.jpg
06-12 13:22:09.250 2484-2510/system_process I/Terry-FB: strEPubFolder + "/" + strDefaultImgFileName = /data/data/de.telekom.epub/files//suspend_others.jpg
06-12 13:22:09.250 2484-2510/system_process I/Terry-FB: strLocaleImgFolder + "/" + strDefaultImgFileName = /system/usr/sleep/drawable-de-nodpi/suspend_others.jpg
06-12 13:22:09.250 2484-2510/system_process I/Terry-FB: strEPubFolder + "/" + strChargeImgFileName = /data/data/de.telekom.epub/files//suspend_charging_others.jpg
06-12 13:22:09.250 2484-2510/system_process I/Terry-FB: strLocaleImgFolder + "/" + strChargeImgFileName = /system/usr/sleep/drawable-de-nodpi/suspend_charging_others.jpg
06-12 13:22:09.250 2484-2510/system_process I/Terry-FB: strLocaleImgFolder + "/" + strFullImgFileName = /system/usr/sleep/drawable-de-nodpi/suspend_batteryfull_others.jpg
显然这是它加载睡眠期间显示的图像的地方。使用 grep 我在 /system/framework/android.policy.jar 中找到了代码。
所以我使用 JADX 反编译了这个文件,并在 ShowSleepScreenEx() 中找到了屏幕被清除和覆盖的行。由于重新编译使用 JADX 反编译的代码相当麻烦,我使用 apktool 将 jar 反编译为 smali 代码,并删除了对 ShowSleepScreenEx() 的调用。使用“apktool build”我重新创建了 jar 文件并将其推回设备。瞧:设备进入睡眠状态时不再清除屏幕。
我没有找到以编程方式关闭屏幕的方法,所以我只是简单地将屏幕超时设置为一个较低的值
adb shell settings put system screen_off_timeout 1000
(好吧,事实证明最小值是 10 秒,但我仍然固执地设置为 1 秒 :-))
使用 ALarmManager 我每分钟都会醒来以更新时间。
由于某种原因,打开屏幕的常用方法(SCREEN_DIM_WAKE_LOCK、WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON)在此设备上不起作用,所以我找到了一个不同的方法:
我交叉编译了libevdev 和evemu 并模拟按下电源按钮:
public class AlarmWorker extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
try {
Process proc = Runtime.getRuntime().exec(new String[]{"/system/bin/evemu-event",
"--sync", "/dev/input/event0", "--type", "EV_KEY", "--code", "KEY_POWER", "--value", "1"});
proc.waitFor();
SystemClock.sleep(50);
proc = Runtime.getRuntime().exec(new String[]{ "/system/bin/evemu-event",
"--sync", "/dev/input/event0", "--type", "EV_KEY", "--code", "KEY_POWER", "--value", "0" });
proc.waitFor();
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
}
}
电池现在一次充电可持续使用 5 天,而不是 2 天。