//屏保设置界面
./packages/apps/Settings/src/com/android/settings/dream/DreamSettings.java
//和PowerManagerService 建立联系
./frameworks/base/packages/SettingsLib/src/com/android/settingslib/dream/DreamBackend.java
//系统时钟屏保 继承了DreamService
./packages/apps/DeskClock/src/com/android/deskclock/Screensaver.java
./packages/apps/DeskClock/src/com/android/deskclock/ScreensaverActivity.java
public static final String SCREENSAVER_ENABLED = "screensaver_enabled";
adb shell settings get secure screensaver_enabled
0 false(never)
如何替换activityt退出(finish)的动画
private void textFinish() {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
//finish();
finishAndRemoveTask();//使用这个
}
}, 0);
}
//复写finishAndRemoveTask
@Override
public void finishAndRemoveTask() {
super.finishAndRemoveTask();
overridePendingTransition(0, R.anim.dream_activity_close_exit);
}
//R.anim.dream_activity_close_exit
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:fromAlpha="1.0"
android:toAlpha="0.0"
android:duration="100" />
android 屏保 (PowerManager & DreamService)
android 系统休眠过程四个状态,分别是SCREEN_BRIGHT,SCREEN_DIM,SCREEN_DREAM,SLEEP
思路1:不让系统进入后面两个状态,保持在SCREEN_DREAM,然后发送广播,操作屏幕背光--->我把它叫做假休眠(fake_sleep_mode)
(或者保持在SCREEN_DREAM后,拉起一个服务,在界面上添加一个的window,window上面布局随意,点击之后移除)
+++ b/frameworks/base/services/core/java/com/android/server/power/PowerManagerService.java
@@ -140,6 +140,8 @@ public final class PowerManagerService extends SystemService
private static final int MSG_CHECK_FOR_LONG_WAKELOCKS = 4;
// Message: Sent when an attentive timeout occurs to update the power state.
private static final int MSG_ATTENTIVE_TIMEOUT = 5;
+ // Message: enter fake sleep mode
+ private static final int MSG_FAKE_SLEEP_MODE = 6;//add text
// Dirty bit: mWakeLocks changed
private static final int DIRTY_WAKE_LOCKS = 1 << 0;
@@ -1722,6 +1724,9 @@ public final class PowerManagerService extends SystemService
}
}
+ //fake sleep mode flag
+ private int fake_sleep_init = 0;//add text
+
private void updateUserActivitySummaryLocked(long now, int dirty) {
...
if (Integer.MAX_VALUE == screenOffTimeout) {
mUserActivitySummary = USER_ACTIVITY_SCREEN_BRIGHT;
//Slog.d(TAG, "set mUserActivitySummary USER_ACTIVITY_SCREEN_BRIGHT never sleep " + nextTimeout);
}
if (mUserActivitySummary != 0 && nextTimeout >= 0) {
scheduleUserInactivityTimeout(nextTimeout);
}
} else {
mUserActivitySummary = 0;
}
//add text
if(mUserActivitySummary == 1 && fake_sleep_init > 0){
fake_sleep_init = 0;
Slog.d(TAG, "fake_sleep_init: reset");
}
//add text
...
}
@SuppressWarnings("deprecation")
private boolean goToSleepNoUpdateLocked(long eventTime, int reason, int flags, int uid) {
if (DEBUG_SPEW) {
Slog.d(TAG, "goToSleepNoUpdateLocked: eventTime=" + eventTime
+ ", reason=" + reason + ", flags=" + flags + ", uid=" + uid);
}
//add text
int fake_sleep_mode = SystemProperties.getInt("persist.sys.fake_sleep_enable", 0);
if (fake_sleep_mode == 0) {
if (fake_sleep_init == 0) {
Message fake_msg = mHandler.obtainMessage(MSG_FAKE_SLEEP_MODE);
fake_msg.setAsynchronous(true);
mHandler.sendMessage(fake_msg);
fake_sleep_init++;
}
return false;
}
//add text
if (eventTime < mLastWakeTime
|| getWakefulnessLocked() == WAKEFULNESS_ASLEEP
|| getWakefulnessLocked() == WAKEFULNESS_DOZING
|| !mSystemReady
|| !mBootCompleted) {
return false;
}
Trace.traceBegin(Trace.TRACE_TAG_POWER, "goToSleep");
try {
reason = Math.min(PowerManager.GO_TO_SLEEP_REASON_MAX,
Math.max(reason, PowerManager.GO_TO_SLEEP_REASON_MIN));
Slog.i(TAG, "Going to sleep due to " + PowerManager.sleepReasonToString(reason)
+ " (uid " + uid + ")...");
mLastSleepTime = eventTime;
mLastSleepReason = reason;
mSandmanSummoned = true;
mDozeStartInProgress = true;
setWakefulnessLocked(WAKEFULNESS_DOZING, reason, eventTime);
...
}
private final class PowerManagerHandlerCallback implements Handler.Callback {
@Override
public boolean handleMessage(Message msg) {
switch (msg.what) {
case MSG_USER_ACTIVITY_TIMEOUT:
handleUserActivityTimeout();
break;
...
//add text
case MSG_FAKE_SLEEP_MODE:
//发送广播去关闭背光
Slog.d(TAG, "Fake sleep mode , entering clock screen...");
Intent intent = new Intent("sys.android.fake.sleep.action");
intent.setPackage("com.android.settings");
mContext.sendBroadcastAsUser(intent,UserHandle.ALL);
break;
//add text
Android 系统全局监听touch事件,在背光关闭的情况下.
./frameworks/base/core/java/android/view/WindowManagerPolicyConstants.java
// TODO: move this to a more appropriate place.
interface PointerEventListener {
/**
* 1. onPointerEvent will be called on the service.UiThread.
* 2. motionEvent will be recycled after onPointerEvent returns so if it is needed later a
* copy() must be made and the copy must be recycled.
**/
void onPointerEvent(MotionEvent motionEvent);
}
+++ b/frameworks/base/services/core/java/com/android/server/wm/WindowManagerService.java
@@ -1149,7 +1149,7 @@ public class WindowManagerService extends IWindowManager.Stub
String[] args, ShellCallback callback, ResultReceiver result) {
new WindowManagerShellCommand(this).exec(this, in, out, err, args, callback, result);
}
-
+ private static Context t_context;
private WindowManagerService(Context context, InputManagerService inputManager,
boolean showBootMsgs, boolean onlyCore, WindowManagerPolicy policy,
ActivityTaskManagerService atm, Supplier<SurfaceControl.Transaction> transactionFactory,
@@ -1159,6 +1159,7 @@ public class WindowManagerService extends IWindowManager.Stub
mGlobalLock = atm.getGlobalLock();
mAtmService = atm;
mContext = context;
+ t_context = context;
mIsPc = mContext.getPackageManager().hasSystemFeature(FEATURE_PC);
mAllowBootMessages = showBootMsgs;
mOnlyCore = onlyCore;
@@ -6805,6 +6806,8 @@ public class WindowManagerService extends IWindowManager.Stub
MousePositionTracker mMousePositionTracker = new MousePositionTracker();
+ private static int x_init = 0;
private static class MousePositionTracker implements PointerEventListener {
private boolean mLatestEventWasMouse;
private float mLatestMouseX;
@@ -6825,6 +6827,13 @@ public class WindowManagerService extends IWindowManager.Stub
} else {
synchronized (this) {
mLatestEventWasMouse = false;
+ //add text
+ if (motionEvent.getAction() == MotionEvent.ACTION_DOWN && x_init == 0){
+ android.util.Log.d("tag","motionEvent---ACTION_DOWN.");
+ mContext.sendBroadcast(new Intent("sys.android.fake.sleep.awake.action"));//发送广播点亮背光
+ x_init++;
+ }
+ //add text
}
}
}
./frameworks/base/services/core/java/com/android/server/wm/SystemGesturesPointerEventListener.java:39:
class SystemGesturesPointerEventListener implements PointerEventListener {
./frameworks/base/services/core/java/com/android/server/wm/WindowManagerService.java:6808:
private static class MousePositionTracker implements PointerEventListener {
./frameworks/base/services/core/java/com/android/server/wm/TaskTapPointerEventListener.java:37:
public class TaskTapPointerEventListener implements PointerEventListener {