private void updateLockAfterPreferenceSummary() { // Update summary message with current value long currentTimeout = Settings.Secure.getLong( getContentResolver(), Settings.Secure.LOCK_SCREEN_LOCK_AFTER_TIMEOUT, 5000); final CharSequence[] entries = mLockAfter.getEntries(); final CharSequence[] values = mLockAfter.getEntryValues(); int best = 0; for (int i = 0; i < values.length; i++) { long timeout = Long.valueOf(values[i].toString()); if (currentTimeout >= timeout) { best = i; } } mLockAfter.setSummary(getString(R.string.lock_after_timeout_summary, entries[best])); }
private void setupLockAfterPreference() { // Compatible with pre-Froyo long currentTimeout = Settings.Secure.getLong( getContentResolver(), Settings.Secure.LOCK_SCREEN_LOCK_AFTER_TIMEOUT, 5000); mLockAfter.setValue(String.valueOf(currentTimeout)); mLockAfter.setOnPreferenceChangeListener(this); final long adminTimeout = (mDPM != null ? mDPM.getMaximumTimeToLock(null) : 0); final long displayTimeout = Math.max(0, Settings.System.getInt(getContentResolver(), SCREEN_OFF_TIMEOUT, 0)); if (adminTimeout > 0) { // This setting is a slave to display timeout when a device policy is enforced. // As such, maxLockTimeout = adminTimeout - displayTimeout. // If there isn't enough time, shows "immediately" setting. disableUnusableTimeouts(Math.max(0, adminTimeout - displayTimeout)); } }
void checkReboot(boolean fromAlarm) { int rebootInterval = mReqRebootInterval >= 0 ? mReqRebootInterval : Settings.Secure.getInt( mResolver, Settings.Secure.REBOOT_INTERVAL, REBOOT_DEFAULT_INTERVAL); mRebootInterval = rebootInterval; if (rebootInterval <= 0) { // No reboot interval requested. if (localLOGV) Slog.v(TAG, "No need to schedule a reboot alarm!"); mAlarm.remove(mRebootIntent); return; } long rebootStartTime = mReqRebootStartTime >= 0 ? mReqRebootStartTime : Settings.Secure.getLong( mResolver, Settings.Secure.REBOOT_START_TIME, REBOOT_DEFAULT_START_TIME); long rebootWindowMillis = (mReqRebootWindow >= 0 ? mReqRebootWindow : Settings.Secure.getLong( mResolver, Settings.Secure.REBOOT_WINDOW, REBOOT_DEFAULT_WINDOW)) * 1000; long recheckInterval = (mReqRecheckInterval >= 0 ? mReqRecheckInterval : Settings.Secure.getLong( mResolver, Settings.Secure.MEMCHECK_RECHECK_INTERVAL, MEMCHECK_DEFAULT_RECHECK_INTERVAL)) * 1000; retrieveBrutalityAmount(); long realStartTime; long now; synchronized (this) { now = System.currentTimeMillis(); realStartTime = computeCalendarTime(mCalendar, now, rebootStartTime); long rebootIntervalMillis = rebootInterval * 24 * 60 * 60 * 1000; if (DB || mReqRebootNoWait || (now - mBootTime) >= (rebootIntervalMillis - rebootWindowMillis)) { if (fromAlarm && rebootWindowMillis <= 0) { // No reboot window -- just immediately reboot. EventLog.writeEvent( EventLogTags.WATCHDOG_SCHEDULED_REBOOT, now, (int) rebootIntervalMillis, (int) rebootStartTime * 1000, (int) rebootWindowMillis, ""); rebootSystem("Checkin scheduled forced"); return; } // Are we within the reboot window? if (now < realStartTime) { // Schedule alarm for next check interval. realStartTime = computeCalendarTime(mCalendar, now, rebootStartTime); } else if (now < (realStartTime + rebootWindowMillis)) { String doit = shouldWeBeBrutalLocked(now); EventLog.writeEvent( EventLogTags.WATCHDOG_SCHEDULED_REBOOT, now, (int) rebootInterval, (int) rebootStartTime * 1000, (int) rebootWindowMillis, doit != null ? doit : ""); if (doit == null) { rebootSystem("Checked scheduled range"); return; } // Schedule next alarm either within the window or in the // next interval. if ((now + recheckInterval) >= (realStartTime + rebootWindowMillis)) { realStartTime = computeCalendarTime(mCalendar, now + rebootIntervalMillis, rebootStartTime); } else { realStartTime = now + recheckInterval; } } else { // Schedule alarm for next check interval. realStartTime = computeCalendarTime(mCalendar, now + rebootIntervalMillis, rebootStartTime); } } } if (localLOGV) Slog.v( TAG, "Scheduling next reboot alarm for " + ((realStartTime - now) / 1000 / 60) + "m from now"); mAlarm.remove(mRebootIntent); mAlarm.set(AlarmManager.RTC_WAKEUP, realStartTime, mRebootIntent); }
private long getLong(String secureSettingKey, long def) { return android.provider.Settings.Secure.getLong(mContentResolver, secureSettingKey, def); }