Connect your phone and run this code.
Press the power button and see what changes are occurring.
Unlock your phone and see what changes have occurred.
Experiment. Have some fun.
import re import subprocess import time states = { 'no_cached_wake_locks': '', 'mDirty': '', 'mWakefulness': '', 'mWakefulnessChanging': '', 'mIsPowered': '', 'mPlugType': '', 'mBatteryLevel': '', 'mBatteryLevelCriticalLow': '', 'mLastBatteryLevelCriticalLowTime': '', 'mBatteryLevelWhenDreamStarted': '', 'mDockState': '', 'mStayOn': '', 'mProximityPositive': '', 'mBootCompleted': '', 'mSystemReady': '', 'mHalAutoSuspendModeEnabled': '', 'mHalInteractiveModeEnabled': '', 'mWakeLockSummary': '', 'mUserActivitySummary': '', 'mRequestWaitForNegativeProximity': '', 'mSandmanScheduled': '', 'mSandmanSummoned': '', 'mLowPowerModeEnabled': '', 'mBatteryLevelLow': '', 'mLightDeviceIdleMode': '', 'mDeviceIdleMode': '', 'mScreenBrightnessBoostInProgress': '', 'mDisplayReady': '', 'mHoldingWakeLockSuspendBlocker': '', 'mHoldingDisplaySuspendBlocker': '', } def checkit(): cmd = ['adb', 'shell', 'dumpsys', 'power'] proc = subprocess.Popen(cmd, bufsize=0, universal_newlines=True, stdin=None, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) changes = 0 for line2 in proc.stdout.readlines(): line = line2.strip() for state, value in states.items(): m = re.search(r'{}=(.*)'.format(state), line) if m: if value != m.group(1): changes += 1 print("changed: state={} old={} new={}".format(state, value, m.group(1))) states[state] = m.group(1) if changes > 0: print("---- {} changes".format(changes)) while True: checkit() time.sleep(0.5)
For example, these are the changes that occur after locking the phone and the black screen:
changed: state=mWakefulness old=Awake new=Asleep changed: state=mHalAutoSuspendModeEnabled old=false new=true changed: state=mHalInteractiveModeEnabled old=true new=false changed: state=mUserActivitySummary old=0x4 new=0x0 changed: state=mHoldingDisplaySuspendBlocker old=true new=false ---- 5 changes changed: state=mWakeLockSummary old=0x1 new=0x0 changed: state=mHoldingWakeLockSuspendBlocker old=true new=false ---- 2 changes changed: state=mWakeLockSummary old=0x0 new=0x1 changed: state=mHoldingWakeLockSuspendBlocker old=false new=true ---- 2 changes changed: state=mWakeLockSummary old=0x1 new=0x0 changed: state=mHoldingWakeLockSuspendBlocker old=true new=false ---- 2 changes