0

I'm making an app that contains a feature with an alarm clock. For that purpose I'm testing with AlarmManager setExactAndAllowWhileIdle() with RTC_WAKEUP and a BoadcastReceiver and also with setAlarmClock in order to work in Doze. Everything works fine in Android Pie but when I tested in Marshmallow I got random delays and sometimes doesn't work, I think.

Today during my tests I notice a strange behaviour in marshmallow(ZTE), if I use the word "clock" in package name suddently everthing works. Is that a known behaviour? Someone can reproduce that behaviour? There is another way to use setAlarmClock () without having to use the word "clock" in the package?

I've been looking on the internet and the only thing similar I found was :

Also I remember that some chinese phones would not kill apps that had the word "alarm" in the package name :-).

Edit:

Correction, is not when I use the word "clock" in package but in applicationId, I was considering that both were the same thing.

Darm0ka
  • 192
  • 1
  • 14
  • is it failing to work properly always of just when dozing? and if its the second one, how often are you triggering alarms cause documentation says they will be limited to once every 15min – quealegriamasalegre Mar 14 '20 at 03:58
  • it also says the following: Note that the OS will allow itself more flexibility for scheduling these alarms than regular exact alarms, since the application has opted into this behavior. When the device is idle it may take even more liberties with scheduling in order to optimize for battery life. https://developer.android.com/reference/android/app/AlarmManager#setExactAndAllowWhileIdle(int,%20long,%20android.app.PendingIntent) – quealegriamasalegre Mar 14 '20 at 04:01
  • have you tried disabling battery saver for your app https://stackoverflow.com/a/47043450/10637400 – quealegriamasalegre Mar 14 '20 at 04:09
  • It always fails even if I use android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS and battery saver disabled, but again if I use the word "clock" in package name works fine. – Darm0ka Mar 14 '20 at 07:30
  • In the following test, I create an app with name com.example.testaudio, don't work(work with random delays) when I use RTC_WAKEUP, or if I use setAlarmClock(), then I rename th package to com.example.testaudioclock and start working fine, then rename again to com.example.testaudio and stop working again – Darm0ka Mar 14 '20 at 07:38
  • Even if the app is in foreground fails – Darm0ka Mar 14 '20 at 07:43
  • I bet for that device there is a whitelisting policy in place that includes %clock% – quealegriamasalegre Mar 14 '20 at 08:34
  • 1
    maybe this will help https://source.android.com/devices/tech/config/perms-whitelist – quealegriamasalegre Mar 14 '20 at 08:45

1 Answers1

0

maybe add permission

<uses-permission `enter code here`android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>

and request it from the user when he first installs the app in case he is using android M or higher

quealegriamasalegre
  • 2,887
  • 1
  • 13
  • 35