mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-27 09:01:38 +01:00
TimeChangeReceiver: Ensure the alarm is set
Ensure TimeChangeReceiver alarm is scheduled when enabling datetime_synconconnect and registering TimeChangeReceiver broadcast receiver. It is important to re-schedule the alarm after registering broadcast receiver, because: 1. if broadcast receiver was unregistered while previous alarm arrived, there is no alarm scheduled; 2. re-scheduling the alarm resets the periodic time sync timer when first device is connected (which is desired). It is important to re-schedule the alarm when datetime_synconconnect gets enabled, because there might be no alarm scheduled. Call onSetTime() when enabling datetime_synconconnect.
This commit is contained in:
parent
31fc266f94
commit
cc5078332b
@ -246,7 +246,6 @@ public class GBApplication extends Application {
|
|||||||
loadAppsPebbleBlackList();
|
loadAppsPebbleBlackList();
|
||||||
|
|
||||||
PeriodicExporter.enablePeriodicExport(context);
|
PeriodicExporter.enablePeriodicExport(context);
|
||||||
TimeChangeReceiver.scheduleNextDstChangeOrPeriodicSync(context);
|
|
||||||
|
|
||||||
if (isRunningMarshmallowOrLater()) {
|
if (isRunningMarshmallowOrLater()) {
|
||||||
notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
|
@ -71,6 +71,7 @@ import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandPreferencesActi
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.devices.pebble.PebbleSettingsActivity;
|
import nodomain.freeyourgadget.gadgetbridge.devices.pebble.PebbleSettingsActivity;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.qhybrid.ConfigActivity;
|
import nodomain.freeyourgadget.gadgetbridge.devices.qhybrid.ConfigActivity;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.zetime.ZeTimePreferenceActivity;
|
import nodomain.freeyourgadget.gadgetbridge.devices.zetime.ZeTimePreferenceActivity;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.externalevents.TimeChangeReceiver;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.Weather;
|
import nodomain.freeyourgadget.gadgetbridge.model.Weather;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.AndroidUtils;
|
import nodomain.freeyourgadget.gadgetbridge.util.AndroidUtils;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.FileUtils;
|
import nodomain.freeyourgadget.gadgetbridge.util.FileUtils;
|
||||||
@ -173,6 +174,17 @@ public class SettingsActivity extends AbstractSettingsActivityV2 {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pref = findPreference("datetime_synconconnect");
|
||||||
|
if (pref != null) {
|
||||||
|
pref.setOnPreferenceChangeListener((preference, newVal) -> {
|
||||||
|
if (Boolean.TRUE.equals(newVal)) {
|
||||||
|
TimeChangeReceiver.scheduleNextDstChangeOrPeriodicSync(requireContext());
|
||||||
|
GBApplication.deviceService().onSetTime();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
pref = findPreference("log_to_file");
|
pref = findPreference("log_to_file");
|
||||||
if (pref != null) {
|
if (pref != null) {
|
||||||
pref.setOnPreferenceChangeListener((preference, newVal) -> {
|
pref.setOnPreferenceChangeListener((preference, newVal) -> {
|
||||||
|
@ -143,6 +143,12 @@ public class TimeChangeReceiver extends BroadcastReceiver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void ifEnabledScheduleNextDstChangeOrPeriodicSync(final Context context) {
|
||||||
|
if (GBApplication.getPrefs().getBoolean("datetime_synconconnect", true)) {
|
||||||
|
scheduleNextDstChangeOrPeriodicSync(context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static boolean canScheduleExactAlarms(final Context context, final AlarmManager am) {
|
private static boolean canScheduleExactAlarms(final Context context, final AlarmManager am) {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||||
return am.canScheduleExactAlarms();
|
return am.canScheduleExactAlarms();
|
||||||
|
@ -1181,6 +1181,9 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
|
|||||||
filter.addAction("android.intent.action.TIMEZONE_CHANGED");
|
filter.addAction("android.intent.action.TIMEZONE_CHANGED");
|
||||||
filter.addAction(TimeChangeReceiver.ACTION_DST_CHANGED_OR_PERIODIC_SYNC);
|
filter.addAction(TimeChangeReceiver.ACTION_DST_CHANGED_OR_PERIODIC_SYNC);
|
||||||
registerReceiver(mTimeChangeReceiver, filter);
|
registerReceiver(mTimeChangeReceiver, filter);
|
||||||
|
// Ensure alarm is scheduled after registering broadcast receiver
|
||||||
|
// (this is important in case receiver was unregistered when the previous alarm arrived).
|
||||||
|
TimeChangeReceiver.ifEnabledScheduleNextDstChangeOrPeriodicSync(this);
|
||||||
}
|
}
|
||||||
if (mBlueToothPairingRequestReceiver == null) {
|
if (mBlueToothPairingRequestReceiver == null) {
|
||||||
mBlueToothPairingRequestReceiver = new BluetoothPairingRequestReceiver(this);
|
mBlueToothPairingRequestReceiver = new BluetoothPairingRequestReceiver(this);
|
||||||
|
Loading…
Reference in New Issue
Block a user