Wiqaytna-app / wiqaytna_android

GNU General Public License v3.0
161 stars 65 forks source link

Inconsistency in scheduling events between APIs before and after Marshmallow #17

Closed hichamboushaba closed 4 years ago

hichamboushaba commented 4 years ago

Salam Alaykum, I want to thank you first for your work on the app, and hopefully it will be of help to our country.

I want to just to put a note on a possible inconsistency in the way events are scheduled in the app using AlarmManager, here: https://github.com/Wiqaytna-app/wiqaytna_android/blob/fecb6622e836658f96842e4b4e889a9ebd54497b/app/src/main/java/covid/trace/morocco/scheduler/Scheduler.kt#L29-L40 So before Marshmallow you use the method set which is inexact, but after Marshmallow you use the method setExactAndAllowWhileIdle which is exact, and more it awakes device if it's in Doze mode. So either you should use setExact on the APIs before if you really need the exactitude, or keep using the set method for all APIs.

Another question please, did you test the app against Doze, and against the task killers that Chinese OEMs (Huawei, Xiaomi, Oppo...) use on their devices? I'm asking because from what I understand from the BluetoothMonitoringService's code, the app will use CommandHandler to reschedule scanning at different period of times, but if the device is sleeping, or in Doze mode, the events won't be fired I think.

Abdelwahad commented 4 years ago

Thanks a lot for your help.

as quoted in the android documentation:

Applications whose targetSdkVersion is earlier than API 19 will continue to see the previous behavior in which all alarms are delivered exactly when requested.

Moreover, setExact is available only after API 19

https://developer.android.com/reference/android/app/AlarmManager#setExact(int,%20long,%20android.app.PendingIntent)

hichamboushaba commented 4 years ago

@Abdelwahad I really don't understand your comment, the application is targeting API 28, so what you said doesn't apply here, set method will be non exact, you should be calling setExact.

And the app is not even compatible with devices running API 19 and earlier, so you don't have to worry about the existence of the API, as setExact will be there always.

Abdelwahad commented 4 years ago

You are absolutely right, we will try to add this on a future version after testing

majhamza commented 4 years ago

@hichamboushaba Please create a pull request, after all it's your contribution

majhamza commented 4 years ago

@hichamboushaba The change you suggested was included in the version 1.1.0, thanks for your contribution

hichamboushaba commented 4 years ago

Thanks @majhamza.