Loading core/java/android/provider/Settings.java +20 −2 Original line number Original line Diff line number Diff line Loading @@ -2001,7 +2001,10 @@ public final class Settings { public static final String DIM_SCREEN = "dim_screen"; public static final String DIM_SCREEN = "dim_screen"; /** /** * The timeout before the screen turns off. * The amount of time in milliseconds before the device goes to sleep or begins * to dream after a period of inactivity. This value is also known as the * user activity timeout period since the screen isn't necessarily turned off * when it expires. */ */ public static final String SCREEN_OFF_TIMEOUT = "screen_off_timeout"; public static final String SCREEN_OFF_TIMEOUT = "screen_off_timeout"; Loading Loading @@ -4816,6 +4819,20 @@ public final class Settings { public static final String USB_AUDIO_AUTOMATIC_ROUTING_DISABLED = public static final String USB_AUDIO_AUTOMATIC_ROUTING_DISABLED = "usb_audio_automatic_routing_disabled"; "usb_audio_automatic_routing_disabled"; /** * The timeout in milliseconds before the device fully goes to sleep after * a period of inactivity. This value sets an upper bound on how long the device * will stay awake or dreaming without user activity. It should generally * be longer than {@link #SCREEN_OFF_TIMEOUT} as otherwise the device * will sleep before it ever has a chance to dream. * <p> * Use -1 to disable this timeout. * </p> * * @hide */ public static final String SLEEP_TIMEOUT = "sleep_timeout"; /** /** * This are the settings to be backed up. * This are the settings to be backed up. * * Loading Loading @@ -4865,7 +4882,8 @@ public final class Settings { MOUNT_UMS_AUTOSTART, MOUNT_UMS_AUTOSTART, MOUNT_UMS_PROMPT, MOUNT_UMS_PROMPT, MOUNT_UMS_NOTIFY_ENABLED, MOUNT_UMS_NOTIFY_ENABLED, UI_NIGHT_MODE UI_NIGHT_MODE, SLEEP_TIMEOUT }; }; /** /** Loading packages/SettingsProvider/res/values/defaults.xml +1 −0 Original line number Original line Diff line number Diff line Loading @@ -19,6 +19,7 @@ <resources> <resources> <bool name="def_dim_screen">true</bool> <bool name="def_dim_screen">true</bool> <integer name="def_screen_off_timeout">60000</integer> <integer name="def_screen_off_timeout">60000</integer> <integer name="def_sleep_timeout">-1</integer> <bool name="def_airplane_mode_on">false</bool> <bool name="def_airplane_mode_on">false</bool> <!-- Comma-separated list of bluetooth, wifi, and cell. --> <!-- Comma-separated list of bluetooth, wifi, and cell. --> <string name="def_airplane_mode_radios" translatable="false">cell,bluetooth,wifi,nfc,wimax</string> <string name="def_airplane_mode_radios" translatable="false">cell,bluetooth,wifi,nfc,wimax</string> Loading packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java +19 −1 Original line number Original line Diff line number Diff line Loading @@ -70,7 +70,7 @@ public class DatabaseHelper extends SQLiteOpenHelper { // database gets upgraded properly. At a minimum, please confirm that 'upgradeVersion' // database gets upgraded properly. At a minimum, please confirm that 'upgradeVersion' // is properly propagated through your change. Not doing so will result in a loss of user // is properly propagated through your change. Not doing so will result in a loss of user // settings. // settings. private static final int DATABASE_VERSION = 112; private static final int DATABASE_VERSION = 113; private Context mContext; private Context mContext; private int mUserHandle; private int mUserHandle; Loading Loading @@ -1811,6 +1811,22 @@ public class DatabaseHelper extends SQLiteOpenHelper { upgradeVersion = 112; upgradeVersion = 112; } } if (upgradeVersion < 113) { db.beginTransaction(); SQLiteStatement stmt = null; try { stmt = db.compileStatement("INSERT OR IGNORE INTO secure(name,value)" + " VALUES(?,?);"); loadIntegerSetting(stmt, Settings.Secure.SLEEP_TIMEOUT, R.integer.def_sleep_timeout); db.setTransactionSuccessful(); } finally { db.endTransaction(); if (stmt != null) stmt.close(); } upgradeVersion = 113; } // *** Remember to update DATABASE_VERSION above! // *** Remember to update DATABASE_VERSION above! if (upgradeVersion != currentVersion) { if (upgradeVersion != currentVersion) { Loading Loading @@ -2382,6 +2398,8 @@ public class DatabaseHelper extends SQLiteOpenHelper { loadBooleanSetting(stmt, Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, loadBooleanSetting(stmt, Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, R.bool.def_lock_screen_allow_private_notifications); R.bool.def_lock_screen_allow_private_notifications); loadIntegerSetting(stmt, Settings.Secure.SLEEP_TIMEOUT, R.integer.def_sleep_timeout); } finally { } finally { if (stmt != null) stmt.close(); if (stmt != null) stmt.close(); } } Loading services/core/java/com/android/server/power/PowerManagerService.java +57 −10 Original line number Original line Diff line number Diff line Loading @@ -142,10 +142,12 @@ public final class PowerManagerService extends SystemService // Summarizes the user activity state. // Summarizes the user activity state. private static final int USER_ACTIVITY_SCREEN_BRIGHT = 1 << 0; private static final int USER_ACTIVITY_SCREEN_BRIGHT = 1 << 0; private static final int USER_ACTIVITY_SCREEN_DIM = 1 << 1; private static final int USER_ACTIVITY_SCREEN_DIM = 1 << 1; private static final int USER_ACTIVITY_SCREEN_DREAM = 1 << 2; // Default timeout in milliseconds. This is only used until the settings // Default timeout in milliseconds. This is only used until the settings // provider populates the actual default value (R.integer.def_screen_off_timeout). // provider populates the actual default value (R.integer.def_screen_off_timeout). private static final int DEFAULT_SCREEN_OFF_TIMEOUT = 15 * 1000; private static final int DEFAULT_SCREEN_OFF_TIMEOUT = 15 * 1000; private static final int DEFAULT_SLEEP_TIMEOUT = -1; // Power hints defined in hardware/libhardware/include/hardware/power.h. // Power hints defined in hardware/libhardware/include/hardware/power.h. private static final int POWER_HINT_INTERACTION = 2; private static final int POWER_HINT_INTERACTION = 2; Loading Loading @@ -214,7 +216,6 @@ public final class PowerManagerService extends SystemService private long mLastInteractivePowerHintTime; private long mLastInteractivePowerHintTime; // A bitfield that summarizes the effect of the user activity timer. // A bitfield that summarizes the effect of the user activity timer. // A zero value indicates that the user activity timer has expired. private int mUserActivitySummary; private int mUserActivitySummary; // The desired display power state. The actual state may lag behind the // The desired display power state. The actual state may lag behind the Loading Loading @@ -340,6 +341,9 @@ public final class PowerManagerService extends SystemService // The screen off timeout setting value in milliseconds. // The screen off timeout setting value in milliseconds. private int mScreenOffTimeoutSetting; private int mScreenOffTimeoutSetting; // The sleep timeout setting value in milliseconds. private int mSleepTimeoutSetting; // The maximum allowable screen off timeout according to the device // The maximum allowable screen off timeout according to the device // administration policy. Overrides other settings. // administration policy. Overrides other settings. private int mMaximumScreenOffTimeoutFromDeviceAdmin = Integer.MAX_VALUE; private int mMaximumScreenOffTimeoutFromDeviceAdmin = Integer.MAX_VALUE; Loading Loading @@ -543,6 +547,9 @@ public final class PowerManagerService extends SystemService resolver.registerContentObserver(Settings.System.getUriFor( resolver.registerContentObserver(Settings.System.getUriFor( Settings.System.SCREEN_OFF_TIMEOUT), Settings.System.SCREEN_OFF_TIMEOUT), false, mSettingsObserver, UserHandle.USER_ALL); false, mSettingsObserver, UserHandle.USER_ALL); resolver.registerContentObserver(Settings.Secure.getUriFor( Settings.Secure.SLEEP_TIMEOUT), false, mSettingsObserver, UserHandle.USER_ALL); resolver.registerContentObserver(Settings.Global.getUriFor( resolver.registerContentObserver(Settings.Global.getUriFor( Settings.Global.STAY_ON_WHILE_PLUGGED_IN), Settings.Global.STAY_ON_WHILE_PLUGGED_IN), false, mSettingsObserver, UserHandle.USER_ALL); false, mSettingsObserver, UserHandle.USER_ALL); Loading Loading @@ -624,6 +631,9 @@ public final class PowerManagerService extends SystemService mScreenOffTimeoutSetting = Settings.System.getIntForUser(resolver, mScreenOffTimeoutSetting = Settings.System.getIntForUser(resolver, Settings.System.SCREEN_OFF_TIMEOUT, DEFAULT_SCREEN_OFF_TIMEOUT, Settings.System.SCREEN_OFF_TIMEOUT, DEFAULT_SCREEN_OFF_TIMEOUT, UserHandle.USER_CURRENT); UserHandle.USER_CURRENT); mSleepTimeoutSetting = Settings.Secure.getIntForUser(resolver, Settings.Secure.SLEEP_TIMEOUT, DEFAULT_SLEEP_TIMEOUT, UserHandle.USER_CURRENT); mStayOnWhilePluggedInSetting = Settings.Global.getInt(resolver, mStayOnWhilePluggedInSetting = Settings.Global.getInt(resolver, Settings.Global.STAY_ON_WHILE_PLUGGED_IN, BatteryManager.BATTERY_PLUGGED_AC); Settings.Global.STAY_ON_WHILE_PLUGGED_IN, BatteryManager.BATTERY_PLUGGED_AC); Loading Loading @@ -1431,7 +1441,8 @@ public final class PowerManagerService extends SystemService if (mWakefulness == WAKEFULNESS_AWAKE if (mWakefulness == WAKEFULNESS_AWAKE || mWakefulness == WAKEFULNESS_DREAMING || mWakefulness == WAKEFULNESS_DREAMING || mWakefulness == WAKEFULNESS_DOZING) { || mWakefulness == WAKEFULNESS_DOZING) { final int screenOffTimeout = getScreenOffTimeoutLocked(); final int sleepTimeout = getSleepTimeoutLocked(); final int screenOffTimeout = getScreenOffTimeoutLocked(sleepTimeout); final int screenDimDuration = getScreenDimDurationLocked(screenOffTimeout); final int screenDimDuration = getScreenDimDurationLocked(screenOffTimeout); mUserActivitySummary = 0; mUserActivitySummary = 0; Loading @@ -1439,11 +1450,11 @@ public final class PowerManagerService extends SystemService nextTimeout = mLastUserActivityTime nextTimeout = mLastUserActivityTime + screenOffTimeout - screenDimDuration; + screenOffTimeout - screenDimDuration; if (now < nextTimeout) { if (now < nextTimeout) { mUserActivitySummary |= USER_ACTIVITY_SCREEN_BRIGHT; mUserActivitySummary = USER_ACTIVITY_SCREEN_BRIGHT; } else { } else { nextTimeout = mLastUserActivityTime + screenOffTimeout; nextTimeout = mLastUserActivityTime + screenOffTimeout; if (now < nextTimeout) { if (now < nextTimeout) { mUserActivitySummary |= USER_ACTIVITY_SCREEN_DIM; mUserActivitySummary = USER_ACTIVITY_SCREEN_DIM; } } } } } } Loading @@ -1458,7 +1469,22 @@ public final class PowerManagerService extends SystemService } } } } } } if (mUserActivitySummary != 0) { if (mUserActivitySummary == 0) { if (sleepTimeout >= 0) { final long anyUserActivity = Math.max(mLastUserActivityTime, mLastUserActivityTimeNoChangeLights); if (anyUserActivity >= mLastWakeTime) { nextTimeout = anyUserActivity + sleepTimeout; if (now < nextTimeout) { mUserActivitySummary = USER_ACTIVITY_SCREEN_DREAM; } } } else { mUserActivitySummary = USER_ACTIVITY_SCREEN_DREAM; nextTimeout = -1; } } if (mUserActivitySummary != 0 && nextTimeout >= 0) { Message msg = mHandler.obtainMessage(MSG_USER_ACTIVITY_TIMEOUT); Message msg = mHandler.obtainMessage(MSG_USER_ACTIVITY_TIMEOUT); msg.setAsynchronous(true); msg.setAsynchronous(true); mHandler.sendMessageAtTime(msg, nextTimeout); mHandler.sendMessageAtTime(msg, nextTimeout); Loading Loading @@ -1495,7 +1521,15 @@ public final class PowerManagerService extends SystemService } } } } private int getScreenOffTimeoutLocked() { private int getSleepTimeoutLocked() { int timeout = mSleepTimeoutSetting; if (timeout <= 0) { return -1; } return Math.max(timeout, mMinimumScreenOffTimeoutConfig); } private int getScreenOffTimeoutLocked(int sleepTimeout) { int timeout = mScreenOffTimeoutSetting; int timeout = mScreenOffTimeoutSetting; if (isMaximumScreenOffTimeoutFromDeviceAdminEnforcedLocked()) { if (isMaximumScreenOffTimeoutFromDeviceAdminEnforcedLocked()) { timeout = Math.min(timeout, mMaximumScreenOffTimeoutFromDeviceAdmin); timeout = Math.min(timeout, mMaximumScreenOffTimeoutFromDeviceAdmin); Loading @@ -1503,6 +1537,9 @@ public final class PowerManagerService extends SystemService if (mUserActivityTimeoutOverrideFromWindowManager >= 0) { if (mUserActivityTimeoutOverrideFromWindowManager >= 0) { timeout = (int)Math.min(timeout, mUserActivityTimeoutOverrideFromWindowManager); timeout = (int)Math.min(timeout, mUserActivityTimeoutOverrideFromWindowManager); } } if (sleepTimeout >= 0) { timeout = Math.min(timeout, sleepTimeout); } return Math.max(timeout, mMinimumScreenOffTimeoutConfig); return Math.max(timeout, mMinimumScreenOffTimeoutConfig); } } Loading Loading @@ -1619,8 +1656,7 @@ public final class PowerManagerService extends SystemService mSandmanScheduled = false; mSandmanScheduled = false; wakefulness = mWakefulness; wakefulness = mWakefulness; if (mSandmanSummoned && mDisplayReady) { if (mSandmanSummoned && mDisplayReady) { startDreaming = ((wakefulness == WAKEFULNESS_DREAMING && canDreamLocked()) startDreaming = canDreamLocked() || canDozeLocked(); || wakefulness == WAKEFULNESS_DOZING); mSandmanSummoned = false; mSandmanSummoned = false; } else { } else { startDreaming = false; startDreaming = false; Loading Loading @@ -1708,13 +1744,14 @@ public final class PowerManagerService extends SystemService /** /** * Returns true if the device is allowed to dream in its current state. * Returns true if the device is allowed to dream in its current state. * This function is not called when dozing. */ */ private boolean canDreamLocked() { private boolean canDreamLocked() { if (mWakefulness != WAKEFULNESS_DREAMING if (mWakefulness != WAKEFULNESS_DREAMING || !mDreamsSupportedConfig || !mDreamsSupportedConfig || !mDreamsEnabledSetting || !mDreamsEnabledSetting || !mDisplayPowerRequest.isBrightOrDim() || !mDisplayPowerRequest.isBrightOrDim() || (mUserActivitySummary & (USER_ACTIVITY_SCREEN_BRIGHT | USER_ACTIVITY_SCREEN_DIM | USER_ACTIVITY_SCREEN_DREAM)) == 0 || !mBootCompleted) { || !mBootCompleted) { return false; return false; } } Loading @@ -1736,6 +1773,13 @@ public final class PowerManagerService extends SystemService return true; return true; } } /** * Returns true if the device is allowed to doze in its current state. */ private boolean canDozeLocked() { return mWakefulness == WAKEFULNESS_DOZING; } /** /** * Updates the display power state asynchronously. * Updates the display power state asynchronously. * When the update is finished, mDisplayReady will be set to true. The display * When the update is finished, mDisplayReady will be set to true. The display Loading Loading @@ -2343,6 +2387,7 @@ public final class PowerManagerService extends SystemService pw.println(" mMaximumScreenDimDurationConfig=" + mMaximumScreenDimDurationConfig); pw.println(" mMaximumScreenDimDurationConfig=" + mMaximumScreenDimDurationConfig); pw.println(" mMaximumScreenDimRatioConfig=" + mMaximumScreenDimRatioConfig); pw.println(" mMaximumScreenDimRatioConfig=" + mMaximumScreenDimRatioConfig); pw.println(" mScreenOffTimeoutSetting=" + mScreenOffTimeoutSetting); pw.println(" mScreenOffTimeoutSetting=" + mScreenOffTimeoutSetting); pw.println(" mSleepTimeoutSetting=" + mSleepTimeoutSetting); pw.println(" mMaximumScreenOffTimeoutFromDeviceAdmin=" pw.println(" mMaximumScreenOffTimeoutFromDeviceAdmin=" + mMaximumScreenOffTimeoutFromDeviceAdmin + " (enforced=" + mMaximumScreenOffTimeoutFromDeviceAdmin + " (enforced=" + isMaximumScreenOffTimeoutFromDeviceAdminEnforcedLocked() + ")"); + isMaximumScreenOffTimeoutFromDeviceAdminEnforcedLocked() + ")"); Loading @@ -2367,9 +2412,11 @@ public final class PowerManagerService extends SystemService pw.println(" mScreenBrightnessSettingMaximum=" + mScreenBrightnessSettingMaximum); pw.println(" mScreenBrightnessSettingMaximum=" + mScreenBrightnessSettingMaximum); pw.println(" mScreenBrightnessSettingDefault=" + mScreenBrightnessSettingDefault); pw.println(" mScreenBrightnessSettingDefault=" + mScreenBrightnessSettingDefault); final int screenOffTimeout = getScreenOffTimeoutLocked(); final int sleepTimeout = getSleepTimeoutLocked(); final int screenOffTimeout = getScreenOffTimeoutLocked(sleepTimeout); final int screenDimDuration = getScreenDimDurationLocked(screenOffTimeout); final int screenDimDuration = getScreenDimDurationLocked(screenOffTimeout); pw.println(); pw.println(); pw.println("Sleep timeout: " + sleepTimeout + " ms"); pw.println("Screen off timeout: " + screenOffTimeout + " ms"); pw.println("Screen off timeout: " + screenOffTimeout + " ms"); pw.println("Screen dim duration: " + screenDimDuration + " ms"); pw.println("Screen dim duration: " + screenDimDuration + " ms"); Loading Loading
core/java/android/provider/Settings.java +20 −2 Original line number Original line Diff line number Diff line Loading @@ -2001,7 +2001,10 @@ public final class Settings { public static final String DIM_SCREEN = "dim_screen"; public static final String DIM_SCREEN = "dim_screen"; /** /** * The timeout before the screen turns off. * The amount of time in milliseconds before the device goes to sleep or begins * to dream after a period of inactivity. This value is also known as the * user activity timeout period since the screen isn't necessarily turned off * when it expires. */ */ public static final String SCREEN_OFF_TIMEOUT = "screen_off_timeout"; public static final String SCREEN_OFF_TIMEOUT = "screen_off_timeout"; Loading Loading @@ -4816,6 +4819,20 @@ public final class Settings { public static final String USB_AUDIO_AUTOMATIC_ROUTING_DISABLED = public static final String USB_AUDIO_AUTOMATIC_ROUTING_DISABLED = "usb_audio_automatic_routing_disabled"; "usb_audio_automatic_routing_disabled"; /** * The timeout in milliseconds before the device fully goes to sleep after * a period of inactivity. This value sets an upper bound on how long the device * will stay awake or dreaming without user activity. It should generally * be longer than {@link #SCREEN_OFF_TIMEOUT} as otherwise the device * will sleep before it ever has a chance to dream. * <p> * Use -1 to disable this timeout. * </p> * * @hide */ public static final String SLEEP_TIMEOUT = "sleep_timeout"; /** /** * This are the settings to be backed up. * This are the settings to be backed up. * * Loading Loading @@ -4865,7 +4882,8 @@ public final class Settings { MOUNT_UMS_AUTOSTART, MOUNT_UMS_AUTOSTART, MOUNT_UMS_PROMPT, MOUNT_UMS_PROMPT, MOUNT_UMS_NOTIFY_ENABLED, MOUNT_UMS_NOTIFY_ENABLED, UI_NIGHT_MODE UI_NIGHT_MODE, SLEEP_TIMEOUT }; }; /** /** Loading
packages/SettingsProvider/res/values/defaults.xml +1 −0 Original line number Original line Diff line number Diff line Loading @@ -19,6 +19,7 @@ <resources> <resources> <bool name="def_dim_screen">true</bool> <bool name="def_dim_screen">true</bool> <integer name="def_screen_off_timeout">60000</integer> <integer name="def_screen_off_timeout">60000</integer> <integer name="def_sleep_timeout">-1</integer> <bool name="def_airplane_mode_on">false</bool> <bool name="def_airplane_mode_on">false</bool> <!-- Comma-separated list of bluetooth, wifi, and cell. --> <!-- Comma-separated list of bluetooth, wifi, and cell. --> <string name="def_airplane_mode_radios" translatable="false">cell,bluetooth,wifi,nfc,wimax</string> <string name="def_airplane_mode_radios" translatable="false">cell,bluetooth,wifi,nfc,wimax</string> Loading
packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java +19 −1 Original line number Original line Diff line number Diff line Loading @@ -70,7 +70,7 @@ public class DatabaseHelper extends SQLiteOpenHelper { // database gets upgraded properly. At a minimum, please confirm that 'upgradeVersion' // database gets upgraded properly. At a minimum, please confirm that 'upgradeVersion' // is properly propagated through your change. Not doing so will result in a loss of user // is properly propagated through your change. Not doing so will result in a loss of user // settings. // settings. private static final int DATABASE_VERSION = 112; private static final int DATABASE_VERSION = 113; private Context mContext; private Context mContext; private int mUserHandle; private int mUserHandle; Loading Loading @@ -1811,6 +1811,22 @@ public class DatabaseHelper extends SQLiteOpenHelper { upgradeVersion = 112; upgradeVersion = 112; } } if (upgradeVersion < 113) { db.beginTransaction(); SQLiteStatement stmt = null; try { stmt = db.compileStatement("INSERT OR IGNORE INTO secure(name,value)" + " VALUES(?,?);"); loadIntegerSetting(stmt, Settings.Secure.SLEEP_TIMEOUT, R.integer.def_sleep_timeout); db.setTransactionSuccessful(); } finally { db.endTransaction(); if (stmt != null) stmt.close(); } upgradeVersion = 113; } // *** Remember to update DATABASE_VERSION above! // *** Remember to update DATABASE_VERSION above! if (upgradeVersion != currentVersion) { if (upgradeVersion != currentVersion) { Loading Loading @@ -2382,6 +2398,8 @@ public class DatabaseHelper extends SQLiteOpenHelper { loadBooleanSetting(stmt, Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, loadBooleanSetting(stmt, Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, R.bool.def_lock_screen_allow_private_notifications); R.bool.def_lock_screen_allow_private_notifications); loadIntegerSetting(stmt, Settings.Secure.SLEEP_TIMEOUT, R.integer.def_sleep_timeout); } finally { } finally { if (stmt != null) stmt.close(); if (stmt != null) stmt.close(); } } Loading
services/core/java/com/android/server/power/PowerManagerService.java +57 −10 Original line number Original line Diff line number Diff line Loading @@ -142,10 +142,12 @@ public final class PowerManagerService extends SystemService // Summarizes the user activity state. // Summarizes the user activity state. private static final int USER_ACTIVITY_SCREEN_BRIGHT = 1 << 0; private static final int USER_ACTIVITY_SCREEN_BRIGHT = 1 << 0; private static final int USER_ACTIVITY_SCREEN_DIM = 1 << 1; private static final int USER_ACTIVITY_SCREEN_DIM = 1 << 1; private static final int USER_ACTIVITY_SCREEN_DREAM = 1 << 2; // Default timeout in milliseconds. This is only used until the settings // Default timeout in milliseconds. This is only used until the settings // provider populates the actual default value (R.integer.def_screen_off_timeout). // provider populates the actual default value (R.integer.def_screen_off_timeout). private static final int DEFAULT_SCREEN_OFF_TIMEOUT = 15 * 1000; private static final int DEFAULT_SCREEN_OFF_TIMEOUT = 15 * 1000; private static final int DEFAULT_SLEEP_TIMEOUT = -1; // Power hints defined in hardware/libhardware/include/hardware/power.h. // Power hints defined in hardware/libhardware/include/hardware/power.h. private static final int POWER_HINT_INTERACTION = 2; private static final int POWER_HINT_INTERACTION = 2; Loading Loading @@ -214,7 +216,6 @@ public final class PowerManagerService extends SystemService private long mLastInteractivePowerHintTime; private long mLastInteractivePowerHintTime; // A bitfield that summarizes the effect of the user activity timer. // A bitfield that summarizes the effect of the user activity timer. // A zero value indicates that the user activity timer has expired. private int mUserActivitySummary; private int mUserActivitySummary; // The desired display power state. The actual state may lag behind the // The desired display power state. The actual state may lag behind the Loading Loading @@ -340,6 +341,9 @@ public final class PowerManagerService extends SystemService // The screen off timeout setting value in milliseconds. // The screen off timeout setting value in milliseconds. private int mScreenOffTimeoutSetting; private int mScreenOffTimeoutSetting; // The sleep timeout setting value in milliseconds. private int mSleepTimeoutSetting; // The maximum allowable screen off timeout according to the device // The maximum allowable screen off timeout according to the device // administration policy. Overrides other settings. // administration policy. Overrides other settings. private int mMaximumScreenOffTimeoutFromDeviceAdmin = Integer.MAX_VALUE; private int mMaximumScreenOffTimeoutFromDeviceAdmin = Integer.MAX_VALUE; Loading Loading @@ -543,6 +547,9 @@ public final class PowerManagerService extends SystemService resolver.registerContentObserver(Settings.System.getUriFor( resolver.registerContentObserver(Settings.System.getUriFor( Settings.System.SCREEN_OFF_TIMEOUT), Settings.System.SCREEN_OFF_TIMEOUT), false, mSettingsObserver, UserHandle.USER_ALL); false, mSettingsObserver, UserHandle.USER_ALL); resolver.registerContentObserver(Settings.Secure.getUriFor( Settings.Secure.SLEEP_TIMEOUT), false, mSettingsObserver, UserHandle.USER_ALL); resolver.registerContentObserver(Settings.Global.getUriFor( resolver.registerContentObserver(Settings.Global.getUriFor( Settings.Global.STAY_ON_WHILE_PLUGGED_IN), Settings.Global.STAY_ON_WHILE_PLUGGED_IN), false, mSettingsObserver, UserHandle.USER_ALL); false, mSettingsObserver, UserHandle.USER_ALL); Loading Loading @@ -624,6 +631,9 @@ public final class PowerManagerService extends SystemService mScreenOffTimeoutSetting = Settings.System.getIntForUser(resolver, mScreenOffTimeoutSetting = Settings.System.getIntForUser(resolver, Settings.System.SCREEN_OFF_TIMEOUT, DEFAULT_SCREEN_OFF_TIMEOUT, Settings.System.SCREEN_OFF_TIMEOUT, DEFAULT_SCREEN_OFF_TIMEOUT, UserHandle.USER_CURRENT); UserHandle.USER_CURRENT); mSleepTimeoutSetting = Settings.Secure.getIntForUser(resolver, Settings.Secure.SLEEP_TIMEOUT, DEFAULT_SLEEP_TIMEOUT, UserHandle.USER_CURRENT); mStayOnWhilePluggedInSetting = Settings.Global.getInt(resolver, mStayOnWhilePluggedInSetting = Settings.Global.getInt(resolver, Settings.Global.STAY_ON_WHILE_PLUGGED_IN, BatteryManager.BATTERY_PLUGGED_AC); Settings.Global.STAY_ON_WHILE_PLUGGED_IN, BatteryManager.BATTERY_PLUGGED_AC); Loading Loading @@ -1431,7 +1441,8 @@ public final class PowerManagerService extends SystemService if (mWakefulness == WAKEFULNESS_AWAKE if (mWakefulness == WAKEFULNESS_AWAKE || mWakefulness == WAKEFULNESS_DREAMING || mWakefulness == WAKEFULNESS_DREAMING || mWakefulness == WAKEFULNESS_DOZING) { || mWakefulness == WAKEFULNESS_DOZING) { final int screenOffTimeout = getScreenOffTimeoutLocked(); final int sleepTimeout = getSleepTimeoutLocked(); final int screenOffTimeout = getScreenOffTimeoutLocked(sleepTimeout); final int screenDimDuration = getScreenDimDurationLocked(screenOffTimeout); final int screenDimDuration = getScreenDimDurationLocked(screenOffTimeout); mUserActivitySummary = 0; mUserActivitySummary = 0; Loading @@ -1439,11 +1450,11 @@ public final class PowerManagerService extends SystemService nextTimeout = mLastUserActivityTime nextTimeout = mLastUserActivityTime + screenOffTimeout - screenDimDuration; + screenOffTimeout - screenDimDuration; if (now < nextTimeout) { if (now < nextTimeout) { mUserActivitySummary |= USER_ACTIVITY_SCREEN_BRIGHT; mUserActivitySummary = USER_ACTIVITY_SCREEN_BRIGHT; } else { } else { nextTimeout = mLastUserActivityTime + screenOffTimeout; nextTimeout = mLastUserActivityTime + screenOffTimeout; if (now < nextTimeout) { if (now < nextTimeout) { mUserActivitySummary |= USER_ACTIVITY_SCREEN_DIM; mUserActivitySummary = USER_ACTIVITY_SCREEN_DIM; } } } } } } Loading @@ -1458,7 +1469,22 @@ public final class PowerManagerService extends SystemService } } } } } } if (mUserActivitySummary != 0) { if (mUserActivitySummary == 0) { if (sleepTimeout >= 0) { final long anyUserActivity = Math.max(mLastUserActivityTime, mLastUserActivityTimeNoChangeLights); if (anyUserActivity >= mLastWakeTime) { nextTimeout = anyUserActivity + sleepTimeout; if (now < nextTimeout) { mUserActivitySummary = USER_ACTIVITY_SCREEN_DREAM; } } } else { mUserActivitySummary = USER_ACTIVITY_SCREEN_DREAM; nextTimeout = -1; } } if (mUserActivitySummary != 0 && nextTimeout >= 0) { Message msg = mHandler.obtainMessage(MSG_USER_ACTIVITY_TIMEOUT); Message msg = mHandler.obtainMessage(MSG_USER_ACTIVITY_TIMEOUT); msg.setAsynchronous(true); msg.setAsynchronous(true); mHandler.sendMessageAtTime(msg, nextTimeout); mHandler.sendMessageAtTime(msg, nextTimeout); Loading Loading @@ -1495,7 +1521,15 @@ public final class PowerManagerService extends SystemService } } } } private int getScreenOffTimeoutLocked() { private int getSleepTimeoutLocked() { int timeout = mSleepTimeoutSetting; if (timeout <= 0) { return -1; } return Math.max(timeout, mMinimumScreenOffTimeoutConfig); } private int getScreenOffTimeoutLocked(int sleepTimeout) { int timeout = mScreenOffTimeoutSetting; int timeout = mScreenOffTimeoutSetting; if (isMaximumScreenOffTimeoutFromDeviceAdminEnforcedLocked()) { if (isMaximumScreenOffTimeoutFromDeviceAdminEnforcedLocked()) { timeout = Math.min(timeout, mMaximumScreenOffTimeoutFromDeviceAdmin); timeout = Math.min(timeout, mMaximumScreenOffTimeoutFromDeviceAdmin); Loading @@ -1503,6 +1537,9 @@ public final class PowerManagerService extends SystemService if (mUserActivityTimeoutOverrideFromWindowManager >= 0) { if (mUserActivityTimeoutOverrideFromWindowManager >= 0) { timeout = (int)Math.min(timeout, mUserActivityTimeoutOverrideFromWindowManager); timeout = (int)Math.min(timeout, mUserActivityTimeoutOverrideFromWindowManager); } } if (sleepTimeout >= 0) { timeout = Math.min(timeout, sleepTimeout); } return Math.max(timeout, mMinimumScreenOffTimeoutConfig); return Math.max(timeout, mMinimumScreenOffTimeoutConfig); } } Loading Loading @@ -1619,8 +1656,7 @@ public final class PowerManagerService extends SystemService mSandmanScheduled = false; mSandmanScheduled = false; wakefulness = mWakefulness; wakefulness = mWakefulness; if (mSandmanSummoned && mDisplayReady) { if (mSandmanSummoned && mDisplayReady) { startDreaming = ((wakefulness == WAKEFULNESS_DREAMING && canDreamLocked()) startDreaming = canDreamLocked() || canDozeLocked(); || wakefulness == WAKEFULNESS_DOZING); mSandmanSummoned = false; mSandmanSummoned = false; } else { } else { startDreaming = false; startDreaming = false; Loading Loading @@ -1708,13 +1744,14 @@ public final class PowerManagerService extends SystemService /** /** * Returns true if the device is allowed to dream in its current state. * Returns true if the device is allowed to dream in its current state. * This function is not called when dozing. */ */ private boolean canDreamLocked() { private boolean canDreamLocked() { if (mWakefulness != WAKEFULNESS_DREAMING if (mWakefulness != WAKEFULNESS_DREAMING || !mDreamsSupportedConfig || !mDreamsSupportedConfig || !mDreamsEnabledSetting || !mDreamsEnabledSetting || !mDisplayPowerRequest.isBrightOrDim() || !mDisplayPowerRequest.isBrightOrDim() || (mUserActivitySummary & (USER_ACTIVITY_SCREEN_BRIGHT | USER_ACTIVITY_SCREEN_DIM | USER_ACTIVITY_SCREEN_DREAM)) == 0 || !mBootCompleted) { || !mBootCompleted) { return false; return false; } } Loading @@ -1736,6 +1773,13 @@ public final class PowerManagerService extends SystemService return true; return true; } } /** * Returns true if the device is allowed to doze in its current state. */ private boolean canDozeLocked() { return mWakefulness == WAKEFULNESS_DOZING; } /** /** * Updates the display power state asynchronously. * Updates the display power state asynchronously. * When the update is finished, mDisplayReady will be set to true. The display * When the update is finished, mDisplayReady will be set to true. The display Loading Loading @@ -2343,6 +2387,7 @@ public final class PowerManagerService extends SystemService pw.println(" mMaximumScreenDimDurationConfig=" + mMaximumScreenDimDurationConfig); pw.println(" mMaximumScreenDimDurationConfig=" + mMaximumScreenDimDurationConfig); pw.println(" mMaximumScreenDimRatioConfig=" + mMaximumScreenDimRatioConfig); pw.println(" mMaximumScreenDimRatioConfig=" + mMaximumScreenDimRatioConfig); pw.println(" mScreenOffTimeoutSetting=" + mScreenOffTimeoutSetting); pw.println(" mScreenOffTimeoutSetting=" + mScreenOffTimeoutSetting); pw.println(" mSleepTimeoutSetting=" + mSleepTimeoutSetting); pw.println(" mMaximumScreenOffTimeoutFromDeviceAdmin=" pw.println(" mMaximumScreenOffTimeoutFromDeviceAdmin=" + mMaximumScreenOffTimeoutFromDeviceAdmin + " (enforced=" + mMaximumScreenOffTimeoutFromDeviceAdmin + " (enforced=" + isMaximumScreenOffTimeoutFromDeviceAdminEnforcedLocked() + ")"); + isMaximumScreenOffTimeoutFromDeviceAdminEnforcedLocked() + ")"); Loading @@ -2367,9 +2412,11 @@ public final class PowerManagerService extends SystemService pw.println(" mScreenBrightnessSettingMaximum=" + mScreenBrightnessSettingMaximum); pw.println(" mScreenBrightnessSettingMaximum=" + mScreenBrightnessSettingMaximum); pw.println(" mScreenBrightnessSettingDefault=" + mScreenBrightnessSettingDefault); pw.println(" mScreenBrightnessSettingDefault=" + mScreenBrightnessSettingDefault); final int screenOffTimeout = getScreenOffTimeoutLocked(); final int sleepTimeout = getSleepTimeoutLocked(); final int screenOffTimeout = getScreenOffTimeoutLocked(sleepTimeout); final int screenDimDuration = getScreenDimDurationLocked(screenOffTimeout); final int screenDimDuration = getScreenDimDurationLocked(screenOffTimeout); pw.println(); pw.println(); pw.println("Sleep timeout: " + sleepTimeout + " ms"); pw.println("Screen off timeout: " + screenOffTimeout + " ms"); pw.println("Screen off timeout: " + screenOffTimeout + " ms"); pw.println("Screen dim duration: " + screenDimDuration + " ms"); pw.println("Screen dim duration: " + screenDimDuration + " ms"); Loading