commit 10a64bcc659442daf9eaa9f442761081cec7da99
Author: maizhitao maizhitao@sztouchtec.cn
Date: Fri Jan 13 10:37:08 2023 +0800
使用开关背光接口实现framework层假休眠,锁屏界面除外(锁屏界面不灭屏)
打开背光:鼠标事件(移动,左右键,滚轮),点击触摸屏,按power键
关闭背光:设置休眠时间到,单击物理power键
modified: frameworks/base/core/java/com/android/internal/policy/PhoneWindow.java
modified: frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationShadeWindowViewController.java
modified: frameworks/base/services/core/java/com/android/server/power/PowerManagerService.java
diff --git a/frameworks/base/core/java/com/android/internal/policy/PhoneWindow.java b/frameworks/base/core/java/com/android/internal/policy/PhoneWindow.java
old mode 100644
new mode 100755
index bfc57b403a…8ce86015ec
— a/frameworks/base/core/java/com/android/internal/policy/PhoneWindow.java
+++ b/frameworks/base/core/java/com/android/internal/policy/PhoneWindow.java
@@ -125,7 +125,10 @@ import com.android.internal.widget.DecorContentParent;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;
+/* fake sleep start*/
+import android.hardware.JawestCtrlManager;
+/* fake sleep end*/
+import android.os.SystemProperties;
/**
- Android-specific Window.
-
@@ -240,6 +243,10 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
*/
PanelFeatureState mPreparedPanel;
-
/* fake sleep start*/
-
private JawestCtrlManager mJawestCtrlManager = new JawestCtrlManager();
-
/* fake sleep end*/
-
private int mCount = 0;
/**- The keycode that is currently held down (as a modifier) for chording. If
- this is 0, there is no key held down.
@@ -1877,6 +1884,34 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
@Override
public boolean superDispatchKeyEvent(KeyEvent event) { -
/* fake sleep start*/
-
Log.i(TAG, "superDispatchKeyEvent event.getAction() = " + event.getAction() + ",getKeyCode() = " + event.getKeyCode());
-
if(event.getAction() == KeyEvent.ACTION_DOWN){
-
mCount++;
-
}
-
if(event.getAction() == KeyEvent.ACTION_UP) {
-
if ((mJawestCtrlManager != null) && (event.getKeyCode() == KeyEvent.KEYCODE_POWER && mCount < 2)) {
-
if (0 == mJawestCtrlManager.GetPanelBacklightStatus()) {
-
Log.i(TAG, "SetBacklight lcd to on ");
-
mJawestCtrlManager.SetPanelBacklight(1);
-
} else {
-
Log.i(TAG, "SetBacklight lcd to off ");
-
mJawestCtrlManager.SetPanelBacklight(0);
-
}
-
if (0 == mJawestCtrlManager.GetHDMIStatus()) {
-
Log.i(TAG, "SetBacklight hdmi to on ");
-
mJawestCtrlManager.setHDMIOnOff(1);
-
}else{
-
Log.i(TAG, "SetBacklight hdmi to off ");
-
mJawestCtrlManager.setHDMIOnOff(0);
-
}
-
}
-
mCount = 0;
-
}
-
/* fake sleep end*/ return mDecor.superDispatchKeyEvent(event);
}
@@ -1887,6 +1922,19 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
@Override
public boolean superDispatchTouchEvent(MotionEvent event) {
-
/* fake sleep start*/
-
int action = event.getAction();
-
if((mJawestCtrlManager != null ) && (action == MotionEvent.ACTION_DOWN)){
-
if(0 == mJawestCtrlManager.GetPanelBacklightStatus()) {
-
Log.d(TAG, "SetBacklight lcd to on ");
-
mJawestCtrlManager.SetPanelBacklight(1);
-
}
-
if(0 == mJawestCtrlManager.GetHDMIStatus()) {
-
Log.d(TAG, "SetBacklight hdmi to on ");
-
mJawestCtrlManager.setHDMIOnOff(1);
-
}
-
}
-
}/* fake sleep end*/ return mDecor.superDispatchTouchEvent(event);
diff --git a/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationShadeWindowViewController.java b/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationShadeWindowViewController.java
old mode 100644
new mode 100755
index 55f14500f8…d67d48cef6
— a/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationShadeWindowViewController.java
+++ b/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationShadeWindowViewController.java
@@ -17,13 +17,17 @@
package com.android.systemui.statusbar.phone;
import static android.app.StatusBarManager.WINDOW_STATE_SHOWING;
+import static android.content.Context.KEYGUARD_SERVICE;
+import android.app.KeyguardManager;
import android.app.StatusBarManager;
import android.graphics.RectF;
+import android.hardware.JawestCtrlManager;
import android.hardware.display.AmbientDisplayConfiguration;
import android.media.AudioManager;
import android.media.session.MediaSessionLegacyHelper;
import android.os.SystemClock;
+import android.os.SystemProperties;
import android.os.UserHandle;
import android.provider.Settings;
import android.util.Log;
@@ -114,6 +118,9 @@ public class NotificationShadeWindowViewController {
private int[] mTempLocation = new int[2];
private RectF mTempRect = new RectF();
private boolean mIsTrackingBarGesture = false;
-
/* fake sleep start*/
-
private int mCount = 0;
-
/* fake sleep end*/
@Inject
public NotificationShadeWindowViewController(
@@ -431,6 +438,38 @@ public class NotificationShadeWindowViewController {
return true;
}
break; -
/* fake sleep start*/
-
case KeyEvent.KEYCODE_POWER:
-
KeyguardManager keyguardManager = (KeyguardManager) mView.getContext().getSystemService(KEYGUARD_SERVICE);
-
if (!keyguardManager.inKeyguardRestrictedInputMode()) {
-
JawestCtrlManager jawestCtrlManager = new JawestCtrlManager();
-
if (event.getAction() == KeyEvent.ACTION_DOWN) {
-
mCount++;
-
}
-
if (event.getAction() == KeyEvent.ACTION_UP) {
-
if ((jawestCtrlManager != null) && (mCount < 2)) {
-
if (0 == jawestCtrlManager.GetPanelBacklightStatus()) {
-
Log.i(TAG, "dispatchKeyEvent SetBacklight lcd to on ");
-
jawestCtrlManager.SetPanelBacklight(1);
-
} else {
-
Log.i(TAG, "dispatchKeyEvent SetBacklight lcd to off ");
-
jawestCtrlManager.SetPanelBacklight(0);
-
}
-
if (0 == jawestCtrlManager.GetHDMIStatus()) {
-
Log.i(TAG, "dispatchKeyEvent SetBacklight hdmi to on ");
-
jawestCtrlManager.setHDMIOnOff(1);
-
} else {
-
Log.i(TAG, "dispatchKeyEvent SetBacklight hdmi to off ");
-
jawestCtrlManager.setHDMIOnOff(0);
-
}
-
}
-
mCount = 0;
-
}
-
jawestCtrlManager = null;
-
}
-
break;
-
/* fake sleep end*/ } return false; }
diff --git a/frameworks/base/services/core/java/com/android/server/power/PowerManagerService.java b/frameworks/base/services/core/java/com/android/server/power/PowerManagerService.java
old mode 100644
new mode 100755
index 8c7d257d27…72b6d25a68
— a/frameworks/base/services/core/java/com/android/server/power/PowerManagerService.java
+++ b/frameworks/base/services/core/java/com/android/server/power/PowerManagerService.java
@@ -16,6 +16,7 @@
package com.android.server.power;
+import static android.content.Context.KEYGUARD_SERVICE;
import static android.hardware.display.DisplayManagerInternal.DisplayPowerRequest.policyToString;
import static android.os.IServiceManager.DUMP_FLAG_PRIORITY_CRITICAL;
import static android.os.IServiceManager.DUMP_FLAG_PRIORITY_DEFAULT;
@@ -38,8 +39,10 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.UserIdInt;
import android.app.ActivityManager;
+import android.app.KeyguardManager;
import android.app.SynchronousUserSwitchObserver;
import android.content.BroadcastReceiver;
+import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
@@ -54,6 +57,7 @@ import android.hardware.display.DisplayManagerInternal;
import android.hardware.display.DisplayManagerInternal.DisplayPowerRequest;
import android.hardware.power.Boost;
import android.hardware.power.Mode;
+import android.media.AudioManager;
import android.net.Uri;
import android.os.BatteryManager;
import android.os.BatteryManagerInternal;
@@ -134,7 +138,7 @@ import java.util.Arrays;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Objects;
+import android.hardware.JawestCtrlManager;
/**
- The power manager service is responsible for coordinating power management
- functions on the device.
@@ -624,6 +628,11 @@ public final class PowerManagerService extends SystemService
// True if double tap to wake is enabled
private boolean mDoubleTapWakeEnabled;
- /* fake sleep start*/
- private static JawestCtrlManager mJawestCtrlManager = null;
- private long lastSendTime = 0;
- /* fake sleep end*/
- // True if we are currently in VR Mode.
private boolean mIsVrModeEnabled;
@@ -1163,6 +1172,9 @@ public final class PowerManagerService extends SystemService
mLightsManager = getLocalService(LightsManager.class);
mAttentionLight = mLightsManager.getLight(LightsManager.LIGHT_ID_ATTENTION);
-
/* fake sleep start*/
-
mJawestCtrlManager = new JawestCtrlManager();
-
/* fake sleep end*/ // Initialize display power management. mDisplayManagerInternal.initPowerManagement( mDisplayPowerCallbacks, mHandler, sensorManager);
@@ -1738,6 +1750,22 @@ public final class PowerManagerService extends SystemService
+ “, flags=0x” + Integer.toHexString(flags) + “, uid=” + uid);
}
-
/*fake sleep start*/
-
KeyguardManager keyguardManager = (KeyguardManager) mContext.getSystemService(KEYGUARD_SERVICE);
-
if (!keyguardManager.inKeyguardRestrictedInputMode()) {
-
if (event == 0 && mJawestCtrlManager != null) {
-
if (0 == mJawestCtrlManager.GetPanelBacklightStatus()) {
-
Slog.i(TAG, "userActivityNoUpdateLocked SetBacklight lcd to on ");
-
mJawestCtrlManager.SetPanelBacklight(1);
-
}
-
if (0 == mJawestCtrlManager.GetHDMIStatus()) {
-
//Slog.i(TAG, "userActivityNoUpdateLocked SetBacklight hdmi to on ");
-
mJawestCtrlManager.setHDMIOnOff(1);
-
}
-
}
-
}
-
/*fake sleep end*/
-
if (eventTime < mLastSleepTime || eventTime < mLastWakeTime || !mSystemReady) { return false; }
@@ -1898,8 +1926,12 @@ public final class PowerManagerService extends SystemService
+ ", uid= " + uid + “)…”);
mDisplayGroupPowerStateMapper.setSandmanSummoned(groupId, true);
-
setWakefulnessLocked(groupId, WAKEFULNESS_DOZING, eventTime, uid, reason,
+/* fake sleep start*/
+// setWakefulnessLocked(groupId, WAKEFULNESS_DOZING, eventTime, uid, reason,
+// /* opUid= / 0, / opPackageName= / null, / details= */ null);
-
setWakefulnessLocked(groupId, WAKEFULNESS_AWAKE, eventTime, uid, reason, /* opUid= */ 0, /* opPackageName= */ null, /* details= */ null);
+/* fake sleep end*/
if ((flags & PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE) != 0) {
reallySleepDisplayGroupNoUpdateLocked(groupId, eventTime, uid);
}
@@ -1935,7 +1967,6 @@ public final class PowerManagerService extends SystemService
mDisplayGroupPowerStateMapper.setSandmanSummoned(groupId, true);
setWakefulnessLocked(groupId, WAKEFULNESS_DREAMING, eventTime, uid, /* reason= /
0, / opUid= / 0, / opPackageName= / null, / details= */ null);
} finally {
Trace.traceEnd(Trace.TRACE_TAG_POWER);
}
@@ -1958,10 +1989,14 @@ public final class PowerManagerService extends SystemService
Trace.traceBegin(Trace.TRACE_TAG_POWER, “reallySleepDisplayGroup”);
try {
Slog.i(TAG, “Sleeping display group (groupId=” + groupId + “, uid=” + uid + “)…”);
-
setWakefulnessLocked(groupId, WAKEFULNESS_ASLEEP, eventTime, uid,
+/* fake sleep start*/
+// setWakefulnessLocked(groupId, WAKEFULNESS_ASLEEP, eventTime, uid,
+// PowerManager.GO_TO_SLEEP_REASON_TIMEOUT, /* opUid= / 0,
+// / opPackageName= / null, / details= */ null);
-
setWakefulnessLocked(groupId, WAKEFULNESS_AWAKE, eventTime, uid, PowerManager.GO_TO_SLEEP_REASON_TIMEOUT, /* opUid= */ 0, /* opPackageName= */ null, /* details= */ null);
+/* fake sleep end*/
} finally {
Trace.traceEnd(Trace.TRACE_TAG_POWER);
}
@@ -1971,6 +2006,31 @@ public final class PowerManagerService extends SystemService
@VisibleForTesting
void setWakefulnessLocked(int groupId, int wakefulness, long eventTime, int uid, int reason,
int opUid, String opPackageName, String details) {
-
/* fake sleep start*/
-
long currentTime = System.currentTimeMillis();
-
Slog.i(TAG, "setWakefulnessLocked come in here screen reason = " + reason);
-
KeyguardManager keyguardManager = (KeyguardManager) mContext.getSystemService(KEYGUARD_SERVICE);
-
Slog.i(TAG, "setWakefulnessLocked inKeyguardRestrictedInputMode() = " + keyguardManager.inKeyguardRestrictedInputMode());
-
if (keyguardManager.inKeyguardRestrictedInputMode()) {
-
return;
-
}
-
if((lastSendTime == 0 || currentTime >= (lastSendTime + mScreenOffTimeoutSetting)) && mScreenOffTimeoutSetting != 0x7fffffff/*2147483647*/
-
&& reason != PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON ) {
-
lastSendTime = currentTime;
-
if(mJawestCtrlManager != null ){
-
if(mJawestCtrlManager.GetPanelBacklightStatus() != 0) {
-
Slog.i(TAG, "SetBacklight lcd to off ");
-
mJawestCtrlManager.SetPanelBacklight(0);
-
}
-
if(mJawestCtrlManager.GetHDMIStatus() != 0) {
-
Slog.i(TAG, "SetBacklight hdmi to off ");
-
mJawestCtrlManager.setHDMIOnOff(0);
-
}
-
}
-
}
-
/* fake sleep end*/ if (mDisplayGroupPowerStateMapper.setWakefulnessLocked(groupId, wakefulness)) { mDirty |= DIRTY_DISPLAY_GROUP_WAKEFULNESS; setGlobalWakefulnessLocked(mDisplayGroupPowerStateMapper.getGlobalWakefulnessLocked(),
@@ -2513,6 +2573,27 @@ public final class PowerManagerService extends SystemService
}
}
- private boolean isVideoPlaying(Context context){
-
AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
-
if(audioManager != null && !"com.android.music".equals(getCurrPackageName(context))){
-
return audioManager.isMusicActive();
-
}
-
return false;
- }
- public static String getCurrPackageName(Context context){
-
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
-
if(am != null) {
-
List<ActivityManager.RunningTaskInfo> list = am.getRunningTasks(1);
-
if (list != null && list.size() > 0) {
-
ComponentName cn = list.get(0).topActivity;
-
if(cn != null) {
-
return cn.getPackageName();
-
}
-
}
-
}
-
return null;
- }
/**- Updates the value of mUserActivitySummary to summarize the user requested
- state of the system such as whether the screen should be bright or dim.
@@ -2630,6 +2711,22 @@ public final class PowerManagerService extends SystemService
groupUserActivitySummary)
+ “, nextTimeout=” + TimeUtils.formatUptime(groupNextTimeout));
}
+/* fake sleep start*/
-
KeyguardManager keyguardManager = (KeyguardManager) mContext.getSystemService(KEYGUARD_SERVICE);
-
if (!keyguardManager.inKeyguardRestrictedInputMode()) {
-
if (groupNextTimeout == -1 && mJawestCtrlManager != null && !isVideoPlaying(mContext)) {
-
Slog.i(TAG, "updateUserActivitySummaryLocked mJawestCtrlManager.GetPanelBacklightStatus() = " + mJawestCtrlManager.GetPanelBacklightStatus());
-
if (0 != mJawestCtrlManager.GetPanelBacklightStatus()) {
-
Slog.i(TAG, "updateUserActivitySummaryLocked SetBacklight lcd to off ");
-
mJawestCtrlManager.SetPanelBacklight(0);
-
}
-
if (0 != mJawestCtrlManager.GetHDMIStatus()) {
-
Slog.i(TAG, "updateUserActivitySummaryLocked SetBacklight hdmi to off ");
-
mJawestCtrlManager.setHDMIOnOff(0);
-
}
-
}
-
}
+/* fake sleep end*/
}
final long nextProfileTimeout = getNextProfileTimeoutLocked(now);