ostrya / PresencePublisher

An Android MQTT client that regularly publishes messages to notify about the device's presence
MIT License
83 stars 13 forks source link

Mininum period increased to 15 mins #13

Closed gpbenton closed 4 years ago

gpbenton commented 4 years ago

I upgraded to version 1.6.4 and discovered that the minimum period between transmissions was 15 minutes. This isn't much use to me as a presence detector so I have reverted back to 1.6.1. Is this change intentional?

ostrya commented 4 years ago

The minimum period of 15 minutes was introduced in 1.6.0 because of limitations of Android. Before, I used a continuously running ForegroundService with an internal scheduler, but I noticed that the ForegroundService is paused when the device enters doze. So I moved the trigger logic to the Android AlarmManager. But even when I request to suppress battery optimization, Android will not allow more than one alarm every 15 Minutes while the device is in Standby. See https://developer.android.com/reference/android/app/AlarmManager.html#setExactAndAllowWhileIdle(int,%20long,%20android.app.PendingIntent) .

I can allow entering lower values again, but at least during standby, the period will grow to 15 minutes due to Android battery saving policy. Would that help you?

gpbenton commented 4 years ago

It may be different on different versions of android. I am running android 5.1 and pp version 1.5.2 (I got that wrong last night) and sending a message every minute works perfectly. I really would not have any use for pp if it only sent a message every 15 minutes.

ostrya commented 4 years ago

Ah, I see. Ok, I will re-enable lower rates for android < 7.0.

gpbenton commented 4 years ago

Perfect. Thanks very much :1st_place_medal: