OpenDelta: Allow opting out of sleep detection
This commit is contained in:
parent
3b769805cd
commit
b6a15fc567
|
@ -107,6 +107,8 @@
|
||||||
<string name="scheduler_weekly">Weekly</string>
|
<string name="scheduler_weekly">Weekly</string>
|
||||||
<string name="scheduler_daily_time">Time</string>
|
<string name="scheduler_daily_time">Time</string>
|
||||||
<string name="scheduler_week_day">Day</string>
|
<string name="scheduler_week_day">Day</string>
|
||||||
|
<string name="scheduler_sleep_enabled_title">Sleep detection</string>
|
||||||
|
<string name="scheduler_sleep_enabled_summary">Attempt to check for updates when the screen is off for 5 hours straight</string>
|
||||||
<string name="metered_networks_title">Metered networks</string>
|
<string name="metered_networks_title">Metered networks</string>
|
||||||
<string name="metered_networks_message">Allow auto downloading on metered networks</string>
|
<string name="metered_networks_message">Allow auto downloading on metered networks</string>
|
||||||
<string name="category_flashing">Flashing</string>
|
<string name="category_flashing">Flashing</string>
|
||||||
|
|
|
@ -47,6 +47,11 @@
|
||||||
android:entryValues="@array/scheduler_mode_values"
|
android:entryValues="@array/scheduler_mode_values"
|
||||||
android:key="scheduler_mode"
|
android:key="scheduler_mode"
|
||||||
android:title="@string/scheduler_mode_title" />
|
android:title="@string/scheduler_mode_title" />
|
||||||
|
<SwitchPreference
|
||||||
|
android:defaultValue="true"
|
||||||
|
android:key="scheduler_sleep_enabled"
|
||||||
|
android:summary="@string/scheduler_sleep_enabled_summary"
|
||||||
|
android:title="@string/scheduler_sleep_enabled_title" />
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
android:key="scheduler_daily_time"
|
android:key="scheduler_daily_time"
|
||||||
|
|
|
@ -206,6 +206,14 @@ public class Config {
|
||||||
prefs.edit().putBoolean(PREF_SHOW_INFO_NAME, enable).commit();
|
prefs.edit().putBoolean(PREF_SHOW_INFO_NAME, enable).commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean getSchedulerSleepEnabled() {
|
||||||
|
return prefs.getBoolean(SettingsActivity.PREF_SCHEDULER_SLEEP, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSchedulerSleepEnabled(boolean enable) {
|
||||||
|
prefs.edit().putBoolean(SettingsActivity.PREF_SCHEDULER_SLEEP, enable).commit();
|
||||||
|
}
|
||||||
|
|
||||||
public List<String> getFlashAfterUpdateZIPs() {
|
public List<String> getFlashAfterUpdateZIPs() {
|
||||||
List<String> extras = new ArrayList<>();
|
List<String> extras = new ArrayList<>();
|
||||||
|
|
||||||
|
|
|
@ -156,12 +156,16 @@ public class Scheduler extends Service implements OnScreenStateListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
// smart mode
|
// smart mode
|
||||||
mScreenState.start(this, this);
|
|
||||||
final long time = getMaxTime(ALARM_INTERVAL);
|
final long time = getMaxTime(ALARM_INTERVAL);
|
||||||
Logger.i("Setting a repeating alarm (inexact) for %s", mSdf.format(new Date(time)));
|
Logger.i("Setting a repeating alarm (inexact) for %s", mSdf.format(new Date(time)));
|
||||||
mAlarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME,
|
mAlarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME,
|
||||||
time, ALARM_INTERVAL, mAlarmInterval);
|
time, ALARM_INTERVAL, mAlarmInterval);
|
||||||
setSecondaryWakeAlarm();
|
setSecondaryWakeAlarm();
|
||||||
|
if (!Config.getInstance(this).getSchedulerSleepEnabled()) {
|
||||||
|
mScreenState.stop();
|
||||||
|
return START_NOT_STICKY;
|
||||||
|
}
|
||||||
|
mScreenState.start(this, this);
|
||||||
return START_REDELIVER_INTENT;
|
return START_REDELIVER_INTENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -304,7 +308,11 @@ public class Scheduler extends Service implements OnScreenStateListener {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onScreenState(boolean state) {
|
public void onScreenState(boolean state) {
|
||||||
if (mIsStopped || mIsCustomAlarm) return;
|
final boolean enabled = Config.getInstance(this).getSchedulerSleepEnabled();
|
||||||
|
if (!enabled)
|
||||||
|
mScreenState.stop();
|
||||||
|
if (mIsStopped || mIsCustomAlarm || !enabled)
|
||||||
|
return;
|
||||||
Logger.d("onScreenState = " + state);
|
Logger.d("onScreenState = " + state);
|
||||||
if (!state) {
|
if (!state) {
|
||||||
setDetectSleepAlarm();
|
setDetectSleepAlarm();
|
||||||
|
|
|
@ -37,6 +37,7 @@ public class SettingsActivity extends CollapsingToolbarBaseActivity {
|
||||||
|
|
||||||
public static final String PREF_SCHEDULER_DAILY_TIME = "scheduler_daily_time";
|
public static final String PREF_SCHEDULER_DAILY_TIME = "scheduler_daily_time";
|
||||||
public static final String PREF_SCHEDULER_WEEK_DAY = "scheduler_week_day";
|
public static final String PREF_SCHEDULER_WEEK_DAY = "scheduler_week_day";
|
||||||
|
public static final String PREF_SCHEDULER_SLEEP = "scheduler_sleep_enabled";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
|
@ -63,6 +63,7 @@ public class SettingsFragment extends PreferenceFragment implements
|
||||||
private Config mConfig;
|
private Config mConfig;
|
||||||
private PreferenceCategory mAutoDownloadCategory;
|
private PreferenceCategory mAutoDownloadCategory;
|
||||||
private ListPreference mSchedulerMode;
|
private ListPreference mSchedulerMode;
|
||||||
|
private SwitchPreference mSchedulerSleep;
|
||||||
private Preference mSchedulerDailyTime;
|
private Preference mSchedulerDailyTime;
|
||||||
private Preference mCleanFiles;
|
private Preference mCleanFiles;
|
||||||
private ListPreference mScheduleWeekDay;
|
private ListPreference mScheduleWeekDay;
|
||||||
|
@ -70,17 +71,16 @@ public class SettingsFragment extends PreferenceFragment implements
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
||||||
SharedPreferences prefs = PreferenceManager
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||||
.getDefaultSharedPreferences(getContext());
|
|
||||||
mConfig = Config.getInstance(getContext());
|
mConfig = Config.getInstance(getContext());
|
||||||
|
|
||||||
addPreferencesFromResource(R.xml.settings);
|
addPreferencesFromResource(R.xml.settings);
|
||||||
mNetworksConfig = findPreference(KEY_NETWORKS);
|
mNetworksConfig = findPreference(KEY_NETWORKS);
|
||||||
mNetworksConfig.setChecked(prefs.getBoolean(UpdateService.PREF_AUTO_UPDATE_METERED_NETWORKS, false));
|
mNetworksConfig.setChecked(prefs.getBoolean(UpdateService.PREF_AUTO_UPDATE_METERED_NETWORKS, false));
|
||||||
|
|
||||||
String autoDownload = prefs.getString(SettingsActivity.PREF_AUTO_DOWNLOAD,
|
final String autoDownload = prefs.getString(SettingsActivity.PREF_AUTO_DOWNLOAD,
|
||||||
Integer.toString(UpdateService.PREF_AUTO_DOWNLOAD_CHECK));
|
Integer.toString(UpdateService.PREF_AUTO_DOWNLOAD_CHECK));
|
||||||
int autoDownloadValue = Integer.parseInt(autoDownload);
|
final int autoDownloadValue = Integer.parseInt(autoDownload);
|
||||||
mAutoDownload = findPreference(SettingsActivity.PREF_AUTO_DOWNLOAD);
|
mAutoDownload = findPreference(SettingsActivity.PREF_AUTO_DOWNLOAD);
|
||||||
mAutoDownload.setOnPreferenceChangeListener(this);
|
mAutoDownload.setOnPreferenceChangeListener(this);
|
||||||
mAutoDownload.setValue(autoDownload);
|
mAutoDownload.setValue(autoDownload);
|
||||||
|
@ -111,21 +111,28 @@ public class SettingsFragment extends PreferenceFragment implements
|
||||||
}
|
}
|
||||||
|
|
||||||
mAutoDownloadCategory = findPreference(KEY_CATEGORY_DOWNLOAD);
|
mAutoDownloadCategory = findPreference(KEY_CATEGORY_DOWNLOAD);
|
||||||
mAutoDownloadCategory
|
mAutoDownloadCategory.setEnabled(
|
||||||
.setEnabled(autoDownloadValue > UpdateService.PREF_AUTO_DOWNLOAD_CHECK);
|
autoDownloadValue > UpdateService.PREF_AUTO_DOWNLOAD_CHECK);
|
||||||
|
|
||||||
|
final boolean schedulerEnabled = autoDownloadValue > UpdateService.PREF_AUTO_DOWNLOAD_DISABLED;
|
||||||
mSchedulerMode = findPreference(SettingsActivity.PREF_SCHEDULER_MODE);
|
mSchedulerMode = findPreference(SettingsActivity.PREF_SCHEDULER_MODE);
|
||||||
mSchedulerMode.setOnPreferenceChangeListener(this);
|
mSchedulerMode.setOnPreferenceChangeListener(this);
|
||||||
mSchedulerMode.setSummary(mSchedulerMode.getEntry());
|
mSchedulerMode.setSummary(mSchedulerMode.getEntry());
|
||||||
mSchedulerMode
|
mSchedulerMode.setEnabled(schedulerEnabled);
|
||||||
.setEnabled(autoDownloadValue > UpdateService.PREF_AUTO_DOWNLOAD_DISABLED);
|
|
||||||
|
|
||||||
String schedulerMode = prefs.getString(SettingsActivity.PREF_SCHEDULER_MODE,
|
final String schedulerMode = prefs.getString(SettingsActivity.PREF_SCHEDULER_MODE,
|
||||||
SettingsActivity.PREF_SCHEDULER_MODE_SMART);
|
SettingsActivity.PREF_SCHEDULER_MODE_SMART);
|
||||||
mSchedulerDailyTime = findPreference(SettingsActivity.PREF_SCHEDULER_DAILY_TIME);
|
mSchedulerDailyTime = findPreference(SettingsActivity.PREF_SCHEDULER_DAILY_TIME);
|
||||||
mSchedulerDailyTime.setEnabled(!schedulerMode.equals(SettingsActivity.PREF_SCHEDULER_MODE_SMART));
|
mSchedulerDailyTime.setEnabled(!schedulerMode.equals(SettingsActivity.PREF_SCHEDULER_MODE_SMART));
|
||||||
mSchedulerDailyTime.setSummary(prefs.getString(
|
mSchedulerDailyTime.setSummary(prefs.getString(
|
||||||
SettingsActivity.PREF_SCHEDULER_DAILY_TIME, "00:00"));
|
SettingsActivity.PREF_SCHEDULER_DAILY_TIME, "00:00"));
|
||||||
|
|
||||||
|
final boolean sleepEnabled = prefs.getBoolean(SettingsActivity.PREF_SCHEDULER_SLEEP, true);
|
||||||
|
mSchedulerSleep = findPreference(SettingsActivity.PREF_SCHEDULER_SLEEP);
|
||||||
|
mSchedulerSleep.setChecked(sleepEnabled);
|
||||||
|
mSchedulerSleep.setOnPreferenceChangeListener(this);
|
||||||
|
mSchedulerSleep.setEnabled(schedulerEnabled &&
|
||||||
|
schedulerMode.equals(SettingsActivity.PREF_SCHEDULER_MODE_SMART));
|
||||||
|
|
||||||
mCleanFiles = findPreference(PREF_CLEAN_FILES);
|
mCleanFiles = findPreference(PREF_CLEAN_FILES);
|
||||||
|
|
||||||
|
@ -171,10 +178,11 @@ public class SettingsFragment extends PreferenceFragment implements
|
||||||
mAutoDownload.setSummary(mAutoDownload.getEntries()[idx]);
|
mAutoDownload.setSummary(mAutoDownload.getEntries()[idx]);
|
||||||
mAutoDownload.setValueIndex(idx);
|
mAutoDownload.setValueIndex(idx);
|
||||||
int autoDownloadValue = Integer.parseInt(value);
|
int autoDownloadValue = Integer.parseInt(value);
|
||||||
mAutoDownloadCategory
|
mAutoDownloadCategory.setEnabled(
|
||||||
.setEnabled(autoDownloadValue > UpdateService.PREF_AUTO_DOWNLOAD_CHECK);
|
autoDownloadValue > UpdateService.PREF_AUTO_DOWNLOAD_CHECK);
|
||||||
mSchedulerMode
|
mSchedulerMode.setEnabled(
|
||||||
.setEnabled(autoDownloadValue > UpdateService.PREF_AUTO_DOWNLOAD_DISABLED);
|
autoDownloadValue > UpdateService.PREF_AUTO_DOWNLOAD_DISABLED);
|
||||||
|
updateSleepEnablement();
|
||||||
return true;
|
return true;
|
||||||
} else if (preference == mBatteryLevel) {
|
} else if (preference == mBatteryLevel) {
|
||||||
String value = (String) newValue;
|
String value = (String) newValue;
|
||||||
|
@ -189,6 +197,10 @@ public class SettingsFragment extends PreferenceFragment implements
|
||||||
mSchedulerMode.setValueIndex(idx);
|
mSchedulerMode.setValueIndex(idx);
|
||||||
mSchedulerDailyTime.setEnabled(!value.equals(SettingsActivity.PREF_SCHEDULER_MODE_SMART));
|
mSchedulerDailyTime.setEnabled(!value.equals(SettingsActivity.PREF_SCHEDULER_MODE_SMART));
|
||||||
mScheduleWeekDay.setEnabled(value.equals(SettingsActivity.PREF_SCHEDULER_MODE_WEEKLY));
|
mScheduleWeekDay.setEnabled(value.equals(SettingsActivity.PREF_SCHEDULER_MODE_WEEKLY));
|
||||||
|
updateSleepEnablement();
|
||||||
|
return true;
|
||||||
|
} else if (preference == mSchedulerSleep) {
|
||||||
|
mConfig.setSchedulerSleepEnabled((boolean) newValue);
|
||||||
return true;
|
return true;
|
||||||
} else if (preference == mScheduleWeekDay) {
|
} else if (preference == mScheduleWeekDay) {
|
||||||
int idx = mScheduleWeekDay.findIndexOfValue((String) newValue);
|
int idx = mScheduleWeekDay.findIndexOfValue((String) newValue);
|
||||||
|
@ -219,14 +231,25 @@ public class SettingsFragment extends PreferenceFragment implements
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
|
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
|
||||||
SharedPreferences prefs = PreferenceManager
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||||
.getDefaultSharedPreferences(getContext());
|
|
||||||
String prefValue = String.format(Locale.ENGLISH, "%02d:%02d",
|
String prefValue = String.format(Locale.ENGLISH, "%02d:%02d",
|
||||||
hourOfDay, minute);
|
hourOfDay, minute);
|
||||||
prefs.edit().putString(SettingsActivity.PREF_SCHEDULER_DAILY_TIME, prefValue).apply();
|
prefs.edit().putString(SettingsActivity.PREF_SCHEDULER_DAILY_TIME, prefValue).apply();
|
||||||
mSchedulerDailyTime.setSummary(prefValue);
|
mSchedulerDailyTime.setSummary(prefValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateSleepEnablement() {
|
||||||
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||||
|
final String autoDownload = prefs.getString(SettingsActivity.PREF_AUTO_DOWNLOAD,
|
||||||
|
Integer.toString(UpdateService.PREF_AUTO_DOWNLOAD_CHECK));
|
||||||
|
final int autoDownloadValue = Integer.parseInt(autoDownload);
|
||||||
|
final String schedulerMode = prefs.getString(SettingsActivity.PREF_SCHEDULER_MODE,
|
||||||
|
SettingsActivity.PREF_SCHEDULER_MODE_SMART);
|
||||||
|
mSchedulerSleep.setEnabled(
|
||||||
|
autoDownloadValue > UpdateService.PREF_AUTO_DOWNLOAD_DISABLED &&
|
||||||
|
schedulerMode.equals(SettingsActivity.PREF_SCHEDULER_MODE_SMART));
|
||||||
|
}
|
||||||
|
|
||||||
private void showTimePicker() {
|
private void showTimePicker() {
|
||||||
final Calendar c = Calendar.getInstance();
|
final Calendar c = Calendar.getInstance();
|
||||||
final int hour = c.get(Calendar.HOUR_OF_DAY);
|
final int hour = c.get(Calendar.HOUR_OF_DAY);
|
||||||
|
|
Loading…
Reference in New Issue