Android红外功能模拟触摸鼠标事件唤醒屏幕

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 index a384f38fea…f982ae8117 100755 — a/frameworks/base/services/core/java/com/android/server/power/PowerManagerService.java +++ b/frameworks/base/services/core/java/com/android/server/power/PowerManagerService.java @@ -93,12 +93,17 @@ import static android.os.PowerManagerInternal.WAKEFULNESS_ASLEEP; import static android.os.PowerManagerInternal.WAKEFULNESS_AWAKE; import static android.os.PowerManagerInternal.WAKEFULNESS_DOZING; import static android.os.PowerManagerInternal.WAKEFULNESS_DREAMING; +import com.android.jws.JwsIntents;

//FOR CEC import android.hardware.hdmi.*; import android.os.ServiceManager; import android.hardware.JawestCtrlManager; +import android.os.SystemProperties; +import android.os.TransactionTooLargeException;

/**

    The power manager service is responsible for coordinating power management @@ -525,6 +530,8 @@ public final class PowerManagerService extends SystemService private int mPerformanceMode = PowerManager.PERFORMANCE_MODE_NORMAL;
    private final static String ACTION_IR_STATE = “android.intent.action.IRDET_PLUGGED”; private native void nativeInit(); private static native void nativeAcquireSuspendBlocker(String name); @@ -665,6 +672,10 @@ public final class PowerManagerService extends SystemService mContext.registerReceiver(mUpdateReceiver, filter); // end filter = new IntentFilter(); filter.addAction(ACTION_IR_STATE); mContext.registerReceiver(IRReceiver, filter); // Register for settings changes. final ContentResolver resolver = mContext.getContentResolver(); resolver.registerContentObserver(Settings.Secure.getUriFor(

@@ -1335,6 +1346,12 @@ public final class PowerManagerService extends SystemService break; case PowerManager.GO_TO_SLEEP_REASON_TIMEOUT: Slog.i(TAG, “Going to sleep due to screen timeout (uid " + uid +”)…");

    boolean aBoolean1 = SystemProperties.getBoolean("persist.test.one", false); if (aBoolean1) { TransactionTooLargeException transactionTooLargeException = new TransactionTooLargeException(); transactionTooLargeException.fillInStackTrace(); transactionTooLargeException.printStackTrace(); } break; case PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH: Slog.i(TAG, "Going to sleep due to lid switch (uid " + uid +")...");

@@ -1442,7 +1459,7 @@ public final class PowerManagerService extends SystemService long lastSendTime = 0; private void setWakefulnessLocked(int wakefulness, int reason) { long currentTime = System.currentTimeMillis();

    Slog.d(TAG, “come in here screen reason:”+reason +" wakefulness:"+wakefulness ); Slog.d(TAG, "come in here screen timeout current time = " + currentTime + " settingTime " + mScreenOffTimeoutSetting); Slog.d(TAG, "come in here screen "+(currentTime - lastSendTime));

@@ -1504,6 +1521,13 @@ public final class PowerManagerService extends SystemService if (!Thread.holdsLock(mLock)) { Slog.wtf(TAG, “Power manager lock was not held when calling updatePowerStateLocked”); } +

    boolean aBoolean1 = SystemProperties.getBoolean("persist.test.two", false); if (aBoolean1) { TransactionTooLargeException transactionTooLargeException = new TransactionTooLargeException(); transactionTooLargeException.fillInStackTrace(); transactionTooLargeException.printStackTrace(); } Trace.traceBegin(Trace.TRACE_TAG_POWER, "updatePowerState"); try {

@@ -1664,6 +1688,11 @@ public final class PowerManagerService extends SystemService } } }

/**
  * Updates the value of mWakeLockSummary to summarize the state of all active wake locks.

@@ -1797,11 +1826,15 @@ public final class PowerManagerService extends SystemService final int screenOffTimeout = getScreenOffTimeoutLocked(sleepTimeout); final int screenDimDuration = getScreenDimDurationLocked(screenOffTimeout); final boolean userInactiveOverride = mUserInactiveOverrideFromWindowManager;

+Log.v(TAG,“screenOffTimeout:”+screenOffTimeout); mUserActivitySummary = 0; if (mLastUserActivityTime >= mLastWakeTime) { nextTimeout = mLastUserActivityTime + screenOffTimeout - screenDimDuration;

    Log.v(TAG,"mLastUserActivityTime:"+mLastUserActivityTime); Log.v(TAG,"now:"+now); Log.v(TAG,"screenDimDuration:"+screenDimDuration+"screenOffTimeout:"+screenOffTimeout + "nextTimeout:"+nextTimeout); if (now < nextTimeout) { mUserActivitySummary = USER_ACTIVITY_SCREEN_BRIGHT; } else {

@@ -1811,9 +1844,11 @@ public final class PowerManagerService extends SystemService } } }

    Log.v(TAG,"mUserActivitySummary:"+mUserActivitySummary); if (mUserActivitySummary == 0 && mLastUserActivityTimeNoChangeLights >= mLastWakeTime) { nextTimeout = mLastUserActivityTimeNoChangeLights + screenOffTimeout; Log.v(TAG,"mLastUserActivityTimeNoChangeLights::::"); if (now < nextTimeout) { if (mDisplayPowerRequest.policy == DisplayPowerRequest.POLICY_BRIGHT) { mUserActivitySummary = USER_ACTIVITY_SCREEN_BRIGHT;

@@ -1828,12 +1863,14 @@ public final class PowerManagerService extends SystemService final long anyUserActivity = Math.max(mLastUserActivityTime, mLastUserActivityTimeNoChangeLights); if (anyUserActivity >= mLastWakeTime) {

    Log.v(TAG,"anyUserActivity::::"); nextTimeout = anyUserActivity + sleepTimeout; if (now < nextTimeout) { mUserActivitySummary = USER_ACTIVITY_SCREEN_DREAM; } } } else { Log.v(TAG,"USER_ACTIVITY_SCREEN_DREAM::::"); mUserActivitySummary = USER_ACTIVITY_SCREEN_DREAM; nextTimeout = -1; }

@@ -1848,6 +1885,7 @@ public final class PowerManagerService extends SystemService mOverriddenTimeout = nextTimeout; } }

    Log.v(TAG,"USER_ACTIVITY_SCREEN_DREAM:"); mUserActivitySummary = USER_ACTIVITY_SCREEN_DREAM; nextTimeout = -1; }

@@ -1861,7 +1899,7 @@ public final class PowerManagerService extends SystemService mUserActivitySummary = 0; }

    if (DEBUG_SPEW) {
    if (true) { Slog.d(TAG, "updateUserActivitySummaryLocked: mWakefulness=" + PowerManagerInternal.wakefulnessToString(mWakefulness) + ", mUserActivitySummary=0x" + Integer.toHexString(mUserActivitySummary)

@@ -1899,9 +1937,11 @@ public final class PowerManagerService extends SystemService

private int getScreenOffTimeoutLocked(int sleepTimeout) {
     int timeout = mScreenOffTimeoutSetting;
    Log.v(TAG,"isMaximumScreenOffTimeoutFromDeviceAdminEnforcedLocked:"+isMaximumScreenOffTimeoutFromDeviceAdminEnforcedLocked()); if (isMaximumScreenOffTimeoutFromDeviceAdminEnforcedLocked()) { timeout = Math.min(timeout, mMaximumScreenOffTimeoutFromDeviceAdmin); } Log.v(TAG,"mUserActivityTimeoutOverrideFromWindowManager:"+mUserActivityTimeoutOverrideFromWindowManager); if (mUserActivityTimeoutOverrideFromWindowManager >= 0) { timeout = (int)Math.min(timeout, mUserActivityTimeoutOverrideFromWindowManager); }

@@ -1927,6 +1967,9 @@ public final class PowerManagerService extends SystemService */ private boolean updateWakefulnessLocked(int dirty) { boolean changed = false;

    // mStayOn:false mProximityPositive:false mWakeLockSummary:1 WAKE_LOCK_STAY_AWAKE:32 // WAKE_LOCK_STAY_AWAKE::::::0 USER_ACTIVITY_SCREEN_BRIGHT:1 mUserActivitySummary:4 // USER_ACTIVITY_SCREEN_DIM:2 USER_ACTIVITY_SCREEN_DIM:::::0 mScreenBrightnessBoostInProgress:false if ((dirty & (DIRTY_WAKE_LOCKS | DIRTY_USER_ACTIVITY | DIRTY_BOOT_COMPLETED | DIRTY_WAKEFULNESS | DIRTY_STAY_ON | DIRTY_PROXIMITY_POSITIVE | DIRTY_DOCK_STATE)) != 0) { @@ -1951,6 +1994,8 @@ public final class PowerManagerService extends SystemService activity timeout has expired and it’s bedtime. */ private boolean shouldNapAtBedTimeLocked() { Log.v(TAG,"mDreamsActivateOnSleepSetting:"+mDreamsActivateOnSleepSetting+" mDreamsActivateOnDockSetting:"+mDreamsActivateOnDockSetting +"EXTRA_DOCK_STATE_UNDOCKED: "+(mDockState != Intent.EXTRA_DOCK_STATE_UNDOCKED)); return mDreamsActivateOnSleepSetting || (mDreamsActivateOnDockSetting && mDockState != Intent.EXTRA_DOCK_STATE_UNDOCKED);

@@ -1973,7 +2018,20 @@ public final class PowerManagerService extends SystemService * will go to sleep or dream which is independent of whether it will be allowed * to suspend. */

    // mStayOn:false --ok mProximityPositive:false--ok mWakeLockSummary:1==WAKEFULNESS_AWAKE WAKE_LOCK_STAY_AWAKE:32 // WAKE_LOCK_STAY_AWAKE::::::0–ok USER_ACTIVITY_SCREEN_BRIGHT:1 mUserActivitySummary:4 // USER_ACTIVITY_SCREEN_DIM:2 USER_ACTIVITY_SCREEN_DIM:::::0 mScreenBrightnessBoostInProgress:false private boolean isBeingKeptAwakeLocked() { Log.v(TAG,"mStayOn:"+mStayOn +" mProximityPositive:"+mProximityPositive +" mWakeLockSummary:"+mWakeLockSummary +" WAKE_LOCK_STAY_AWAKE:"+WAKE_LOCK_STAY_AWAKE +" WAKE_LOCK_STAY_AWAKE::::::"+(mWakeLockSummary & WAKE_LOCK_STAY_AWAKE) +" USER_ACTIVITY_SCREEN_BRIGHT:"+USER_ACTIVITY_SCREEN_BRIGHT +" mUserActivitySummary:"+mUserActivitySummary +" USER_ACTIVITY_SCREEN_DIM:"+USER_ACTIVITY_SCREEN_DIM +" USER_ACTIVITY_SCREEN_DIM:::::"+(mUserActivitySummary & (USER_ACTIVITY_SCREEN_BRIGHT | USER_ACTIVITY_SCREEN_DIM)) +" mScreenBrightnessBoostInProgress:"+mScreenBrightnessBoostInProgress); return mStayOn || mProximityPositive || (mWakeLockSummary & WAKE_LOCK_STAY_AWAKE) != 0

@@ -2829,6 +2887,7 @@ public final class PowerManagerService extends SystemService

private void setUserActivityTimeoutOverrideFromWindowManagerInternal(long timeoutMillis) {
     synchronized (mLock) {
    Log.v(TAG,"setUserActivityTimeoutOverrideFromWindowManagerInternal:"+timeoutMillis); if (mUserActivityTimeoutOverrideFromWindowManager != timeoutMillis) { mUserActivityTimeoutOverrideFromWindowManager = timeoutMillis; mDirty |= DIRTY_SETTINGS;

@@ -3442,6 +3501,59 @@ public final class PowerManagerService extends SystemService } }

    private BroadcastReceiver IRReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if(intent.getAction().equals(ACTION_IR_STATE)) { Slog.d(TAG, "IRReceiver: ir status: " + intent.getBooleanExtra("state", false)); if(!(intent.getBooleanExtra("state", false)) && (mJawestCtrlManager != null ) && (0 == mJawestCtrlManager.GetPanelBacklightStatus())) { Slog.d(TAG, "SetPanelBacklight 1 reason ir "); mJawestCtrlManager.SetPanelBacklight(1); long time = SystemClock.uptimeMillis(); //模拟鼠标事件唤醒背光 userActivityFromNative(time, PowerManager.USER_ACTIVITY_EVENT_TOUCH, 0); // PowerManager.USER_ACTIVITY_EVENT_TOUCH //userActivityFromNative(long eventTime, int event, int flags); //PowerManager mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE); //long time = SystemClock.uptimeMillis(); //模拟鼠标事件唤醒背光 //mPowerManager.userActivity(time, true /*noChangeLights*/); // cancelTimer(); // TestTimer(); } } } }; //++ add by ouzh 2018-7-24 private AlertDialog mUpateAlertDlg = null; private AlertDialog mUUIDUpdateDlg = null; @@ -4039,6 +4151,7 @@ public final class PowerManagerService extends SystemService @Override public void setUserActivityTimeoutOverrideFromWindowManager(long timeoutMillis) { Log.v(TAG,"setUserActivityTimeoutOverrideFromWindowManager:"+timeoutMillis); setUserActivityTimeoutOverrideFromWindowManagerInternal(timeoutMillis); }
经验分享 程序员 微信小程序 职场和发展