openhab / openhab-android

openHAB client for Android
https://play.google.com/store/apps/details?id=org.openhab.habdroid
Eclipse Public License 2.0
606 stars 314 forks source link

Phone sends false alarms to the server #2890

Closed felixschndr closed 2 years ago

felixschndr commented 2 years ago

Actual behaviour

I bought a Samsung Galaxy S22 Ultra which regularly sends false times for upcoming alarms. I cannot figure out a pattern that triggers this. I checked out the logs of the app:

04-26 06:15:01.910 10062 10062 D BackgroundTasksManager: onReceive() with intent android.app.action.NEXT_ALARM_CLOCK_CHANGED
04-26 06:15:01.910 10062 10062 D BackgroundTasksManager: Alarm clock changed
04-26 06:15:01.914 10062 10062 D BackgroundTasksManager: Alarm sent by null
04-26 06:15:01.915 10062 10062 D BackgroundTasksManager: Got value 'ValueWithInfo(value=1650953622334, mappedValue=null, type=Timestamp)' for alarmClock
04-26 06:15:01.917 10062 10062 D BackgroundTasksManager: Scheduling work for tag alarmClock

As you can see in line 3 that the $sender is null. I suggest checking for null and returning in this case

Environment data

Client

Logs

App log (Also you can see some file not found exceptions)

felixschndr commented 2 years ago

Might be related to https://github.com/openhab/openhab-android/issues/2548

mueller-ma commented 2 years ago

I opened #2891. This might block some valid alarm times for other people, so it might be reverted. But let's see.

felixschndr commented 2 years ago

👍🏻 Can you tell me when there is a new build available? I will test the new version

mueller-ma commented 2 years ago

mobile-foss-beta-debug.zip

felixschndr commented 2 years ago

Installed it. I will test it a few days and keep you up-to-date

felixschndr commented 2 years ago

Found this in the app log

05-03 10:21:38.294  7665  7665 D BackgroundTasksManager: Alarm sent by null
05-03 10:21:38.294  7665  7665 D BackgroundTasksManager: Got value 'ValueWithInfo(value=UNDEF, mappedValue=null, type=Timestamp)' for alarmClock
05-03 10:21:38.297  7665  7665 I BackgroundTasksManager: Don't send update for item Wecker_Android with value ValueWithInfo(value=UNDEF, mappedValue=null, type=Timestamp)
05-03 10:21:38.313  7665  7665 D BackgroundTasksManager: Got value 'ValueWithInfo(value=IDLE, mappedValue=null, type=Raw)' for phoneState
05-03 10:21:38.313  7665  7665 I BackgroundTasksManager: Don't send update for item Android_Anrufstatus with value ValueWithInfo(value=IDLE, mappedValue=null, type=Raw)

Looks good but I have to check the server logs too and will come back to you

felixschndr commented 2 years ago

I checked the server logs. Here's what I found out

1. The null check helps a lot! From about 10 false alarms a day to nearly zero 👍🏻

2. > nearly zero

Not zero. There are still some false alarms:

   9811: 11:04:57 (30. 04.)    Item 'Wecker_Android' received command 2022-04-30T11:00:00.000+0000
  11382: 01:15:43 (01. 05.)    Item 'Wecker_Android' received command 2022-05-01T03:00:00.000+0000
  12211: 19:03:59 (01. 05.)    Item 'Wecker_Android' received command 2022-05-01T22:00:00.000+0000
  12764: 03:59:44 (02. 05.)    Item 'Wecker_Android' received command 2022-05-02T03:00:00.000+0000
  12852: 05:00:15 (02. 05.)    Item 'Wecker_Android' received command 2022-05-02T04:00:00.000+0000
  12902: 06:00:05 (02. 05.)    Item 'Wecker_Android' received command 2022-05-02T05:15:00.000+0000
  13027: 07:15:07 (02. 05.)    Item 'Wecker_Android' received command 2022-05-02T05:45:00.000+0000
  13923: 17:29:57 (02. 05.)    Item 'Wecker_Android' received command 2022-05-02T22:00:00.000+0000
  14717: 02:31:31 (03. 05.)    Item 'Wecker_Android' received command 2022-05-03T03:00:00.000+0000
  14883: 06:00:06 (03. 05.)    Item 'Wecker_Android' received command 2022-05-03T04:15:00.000+0000
  15668: 21:47:34 (03. 05.)    Item 'Wecker_Android' received command 2022-05-03T22:00:00.000+0000

For example check out line 14883 where an alarm was set for 04:15 at 06:00 (so 1:45h om the past). Sadly the log of the app clears itself so often that I am not able to detect what app triggered this alarm.

However I think this is the same problem as in https://github.com/openhab/openhab-android/issues/2548 where an unwanted app sends an alarm.

I think we can clone this issue by merging https://github.com/openhab/openhab-android/pull/2891

mueller-ma commented 2 years ago

Sadly the log of the app clears itself so often that I am not able to detect what app triggered this alarm.

You can search in the developer settings for a size restriction of app logs. I see that debugging this issue isn't easy, so I opened https://github.com/openhab/openhab-android/issues/2852.

felixschndr commented 2 years ago

You can search in the developer settings for a size restriction of app logs.

Thanks. I set the Größe pro Protokollpuffer from 4 Mio. to 8 MB (the maximum). Lets see if this helps

felixschndr commented 2 years ago

With the search function I can see this:

An Alarm is today The package com.sec.android.app.clockpackage sends the valid alarm

If I delete this alarm now the package com.android.providers.calendar sends an null alarm. --> The app interprets this as no alarm set. Even tough there are many alarms set for the next days

felixschndr commented 2 years ago

I found the issue!

When a calendar event is upcoming which reminds the user com.android.providers.calendar sees this as an alarm and sends null:

Example: calendar event at 16:30, reminder 10 minutes early (16:20) set an alarm at 16:19: works set an alarm at 16:20 (or later): doesn't work since com.android.providers.calendar sends its 'alarm' with no time first

So the issue is upcoming calendar events and their reminders


Alarms by the calendar are ignored by Code

However the app just sends UNDEF instead of returning

image image

mueller-ma commented 2 years ago

However the app just sends UNDEF instead of returning

That's because the app doesn't know if the real alarm on the next day was cancelled or not.

felixschndr commented 2 years ago

So the problem is that the OS just sends the calendar 'alarm' as the next alarm? The app cannot get only alarms by some package (e.g. only com.sec.android.app.clockpackage)?

https://developer.android.com/reference/kotlin/android/provider/AlarmClock

mueller-ma commented 2 years ago

No, that's not possible. I recently added a note to the docs: https://next.openhab.org/docs/apps/android.html#alarm-clock

https://developer.android.com/reference/kotlin/android/provider/AlarmClock

This API seems to have no action to get an alarm clock.

felixschndr commented 2 years ago

Got it. So there is nothing we can do.


However https://github.com/openhab/openhab-android/pull/2891 helps a lot with the null alarms. Ready to merge?