Add option to enable notifications during Doze

Closes #341
pull/384/head
Alex Baker 10 years ago
parent 271eded3e7
commit 06375cb0b7

@ -367,10 +367,18 @@ public class AndroidUtilities {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN; return Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN;
} }
public static boolean atLeastKitKat() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
}
public static boolean atLeastLollipop() { public static boolean atLeastLollipop() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP; return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
} }
public static boolean atLeastMarshmallow() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M;
}
/** /**
* Sort files by date so the newest file is on top * Sort files by date so the newest file is on top
*/ */

@ -27,6 +27,7 @@ import org.tasks.ui.TimePreference;
import javax.inject.Inject; import javax.inject.Inject;
import static com.todoroo.andlib.utility.AndroidUtilities.atLeastMarshmallow;
import static com.todoroo.andlib.utility.AndroidUtilities.preJellybean; import static com.todoroo.andlib.utility.AndroidUtilities.preJellybean;
public class ReminderPreferences extends InjectingPreferenceActivity { public class ReminderPreferences extends InjectingPreferenceActivity {
@ -38,6 +39,7 @@ public class ReminderPreferences extends InjectingPreferenceActivity {
public static String RESET_GEOFENCES = "reset_geofences"; public static String RESET_GEOFENCES = "reset_geofences";
public static String TOGGLE_GEOFENCES = "toggle_geofences"; public static String TOGGLE_GEOFENCES = "toggle_geofences";
public static String RESCHEDULE_ALARMS = "reschedule_alarms";
private Bundle result; private Bundle result;
@Inject DeviceInfo deviceInfo; @Inject DeviceInfo deviceInfo;
@ -59,6 +61,11 @@ public class ReminderPreferences extends InjectingPreferenceActivity {
preferenceScreen.removePreference(findPreference(getString(R.string.p_rmd_notif_actions_enabled))); preferenceScreen.removePreference(findPreference(getString(R.string.p_rmd_notif_actions_enabled)));
preferenceScreen.removePreference(findPreference(getString(R.string.p_notification_priority))); preferenceScreen.removePreference(findPreference(getString(R.string.p_notification_priority)));
} }
if (atLeastMarshmallow()) {
setExtraOnChange(R.string.p_doze_notifications, RESCHEDULE_ALARMS);
} else {
preferenceScreen.removePreference(findPreference(getString(R.string.p_doze_notifications)));
}
if (deviceInfo.supportsLocationServices()) { if (deviceInfo.supportsLocationServices()) {
setExtraOnChange(R.string.p_geofence_radius, RESET_GEOFENCES); setExtraOnChange(R.string.p_geofence_radius, RESET_GEOFENCES);

@ -29,6 +29,7 @@ import timber.log.Timber;
import static android.content.SharedPreferences.Editor; import static android.content.SharedPreferences.Editor;
import static com.todoroo.andlib.utility.AndroidUtilities.atLeastJellybean; import static com.todoroo.andlib.utility.AndroidUtilities.atLeastJellybean;
import static com.todoroo.andlib.utility.AndroidUtilities.atLeastMarshmallow;
public class Preferences { public class Preferences {
@ -99,6 +100,10 @@ public class Preferences {
return getStringValue(R.string.gcal_p_default); return getStringValue(R.string.gcal_p_default);
} }
public boolean isDozeNotificationEnabled() {
return atLeastMarshmallow() && getBoolean(R.string.p_doze_notifications, false);
}
public boolean geofencesEnabled() { public boolean geofencesEnabled() {
return deviceInfo.supportsLocationServices() && getBoolean(R.string.p_geofence_reminders_enabled, true); return deviceInfo.supportsLocationServices() && getBoolean(R.string.p_geofence_reminders_enabled, true);
} }

@ -3,16 +3,22 @@ package org.tasks.scheduling;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.content.Context; import android.content.Context;
import org.tasks.R;
import org.tasks.injection.ForApplication; import org.tasks.injection.ForApplication;
import org.tasks.preferences.Preferences;
import javax.inject.Inject; import javax.inject.Inject;
import static com.todoroo.andlib.utility.AndroidUtilities.atLeastKitKat;
public class AlarmManager { public class AlarmManager {
private final android.app.AlarmManager alarmManager; private final android.app.AlarmManager alarmManager;
private final Preferences preferences;
@Inject @Inject
public AlarmManager(@ForApplication Context context) { public AlarmManager(@ForApplication Context context, Preferences preferences) {
this.preferences = preferences;
alarmManager = (android.app.AlarmManager) context.getSystemService(Context.ALARM_SERVICE); alarmManager = (android.app.AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
} }
@ -21,11 +27,23 @@ public class AlarmManager {
} }
public void wakeup(long time, PendingIntent pendingIntent) { public void wakeup(long time, PendingIntent pendingIntent) {
alarmManager.set(android.app.AlarmManager.RTC_WAKEUP, time, pendingIntent); if (preferences.isDozeNotificationEnabled()) {
alarmManager.setExactAndAllowWhileIdle(android.app.AlarmManager.RTC_WAKEUP, time, pendingIntent);
} else if (atLeastKitKat()) {
alarmManager.setExact(android.app.AlarmManager.RTC_WAKEUP, time, pendingIntent);
} else {
alarmManager.set(android.app.AlarmManager.RTC_WAKEUP, time, pendingIntent);
}
} }
public void noWakeup(long time, PendingIntent pendingIntent) { public void noWakeup(long time, PendingIntent pendingIntent) {
alarmManager.set(android.app.AlarmManager.RTC, time, pendingIntent); if (preferences.isDozeNotificationEnabled()) {
alarmManager.setExactAndAllowWhileIdle(android.app.AlarmManager.RTC, time, pendingIntent);
} else if (atLeastKitKat()) {
alarmManager.setExact(android.app.AlarmManager.RTC, time, pendingIntent);
} else {
alarmManager.set(android.app.AlarmManager.RTC, time, pendingIntent);
}
} }
public void setInexactRepeating(long interval, PendingIntent pendingIntent) { public void setInexactRepeating(long interval, PendingIntent pendingIntent) {

@ -32,6 +32,7 @@ import org.tasks.injection.InjectingFragment;
import org.tasks.location.GeofenceService; import org.tasks.location.GeofenceService;
import org.tasks.preferences.AppearancePreferences; import org.tasks.preferences.AppearancePreferences;
import org.tasks.preferences.Preferences; import org.tasks.preferences.Preferences;
import org.tasks.scheduling.AlarmSchedulingIntentService;
import javax.inject.Inject; import javax.inject.Inject;
@ -96,6 +97,9 @@ public class NavigationDrawerFragment extends InjectingFragment {
} }
} else if (data.getBooleanExtra(ReminderPreferences.RESET_GEOFENCES, false)) { } else if (data.getBooleanExtra(ReminderPreferences.RESET_GEOFENCES, false)) {
geofenceService.setupGeofences(); geofenceService.setupGeofences();
} else if (data.getBooleanExtra(ReminderPreferences.RESCHEDULE_ALARMS, false)) {
Context context = getContext();
context.startService(new Intent(context, AlarmSchedulingIntentService.class));
} }
if (data.getBooleanExtra(AppearancePreferences.FILTERS_CHANGED, false)) { if (data.getBooleanExtra(AppearancePreferences.FILTERS_CHANGED, false)) {

@ -244,6 +244,7 @@
<string name="p_manual_sort">manual_sort</string> <string name="p_manual_sort">manual_sort</string>
<string name="p_notification_priority">notification_priority</string> <string name="p_notification_priority">notification_priority</string>
<string name="p_disable_notification_light">disable_notification_light</string> <string name="p_disable_notification_light">disable_notification_light</string>
<string name="p_doze_notifications">doze_notifications</string>
<string-array name="TEA_control_sets_prefs"> <string-array name="TEA_control_sets_prefs">
<item>@string/TEA_ctrl_when_pref</item> <item>@string/TEA_ctrl_when_pref</item>

@ -138,6 +138,9 @@
<string name="opt_out">Opt-out</string> <string name="opt_out">Opt-out</string>
<string name="tag_already_exists">Tag already exists</string> <string name="tag_already_exists">Tag already exists</string>
<string name="disable_notification_light">Disable notification light</string> <string name="disable_notification_light">Disable notification light</string>
<string name="doze_notifications">Interrupt Doze mode for notifications</string>
<string name="doze_notifications_off">Android will significantly delay notifications while device is in Doze mode</string>
<string name="doze_notifications_on">Android will allow limited interruptions while device is in Doze mode</string>
<string-array name="sync_SPr_interval_entries"> <string-array name="sync_SPr_interval_entries">
<!-- sync_SPr_interval_entries: Synchronization Intervals --> <!-- sync_SPr_interval_entries: Synchronization Intervals -->

@ -44,6 +44,13 @@
android:key="@string/p_rmd_persistent" android:key="@string/p_rmd_persistent"
android:summary="@string/persistent_notifications_description" android:summary="@string/persistent_notifications_description"
android:title="@string/persistent_notifications" /> android:title="@string/persistent_notifications" />
<com.todoroo.astrid.ui.MultilineCheckboxPreference
android:defaultValue="false"
android:dependency="@string/p_rmd_enabled"
android:key="@string/p_doze_notifications"
android:summaryOff="@string/doze_notifications_off"
android:summaryOn="@string/doze_notifications_on"
android:title="@string/doze_notifications" />
<CheckBoxPreference <CheckBoxPreference
android:defaultValue="false" android:defaultValue="false"
android:dependency="@string/p_rmd_enabled" android:dependency="@string/p_rmd_enabled"

Loading…
Cancel
Save