BlackyHawky / Clock

Privacy-conscious open-source clock, based on AOSP Clock
Apache License 2.0
178 stars 11 forks source link

The next alarm is displayed at a random time even if no alarm is configured (only a few devices are affected) #61

Closed woj-tek closed 3 months ago

woj-tek commented 3 months ago

Describe the bug There is an icon and time stating next alarm clock even though there is none configured.

To Reproduce It's just there...

Expected behavior No alarm clock time should be displayed in widget if no alarm clock set

Screenshots

App version 2.4 / f-droid

Device (please complete the following information):

Additional context So right now it shows alarm for tomorrow's (sábado = Saturday) at 9am even though I don't have any alarm set in the application. When I open Clock and add alarm for today at 17:50 and go back to home screen it shows that alarm. Disabling 17:50 alarm and widget again shows 9:00am alarm...

I though that maybe other apps with alarm clock could influence it but no other app have (active) alarm clock for tomorrow for 9am... well, non have alarm for that time, even disabled (tbh I don't have any alarm clock set in any app - I usually set it when going to bed)

BlackyHawky commented 3 months ago

I've only seen this bug on one phone (Xiaomi Redmi Note 5) and I'm very surprised to see that it also happens on a Samsung phone.

Can you tell me if you see this "phantom" alarm in the Clock tab?

Unfortunately, I'm unable to find the source of this problem. 😬

Can you please tell me if this bug appears with the LineageOS application?

DeskClock-LineageOS-release.zip

woj-tek commented 3 months ago

Can you tell me if you see this "phantom" alarm in the Clock tab?

Actually yes :D

Can you please tell me if this bug appears with the LineageOS application?

Yes :-)

(btw it's compiled from https://github.com/LineageOS/android_packages_apps_DeskClock?)

BlackyHawky commented 3 months ago

That's what I thought. Is it the same with version 1.2? Normally yes...

woj-tek commented 3 months ago

Is it the same with version 1.2? Normally yes...

I have no idea. Given that the new version uses same app-id it's not possible to have both versions installe at the same time and given that the new version has most of the improvements then I took the leap and finally upgraded :-)

BlackyHawky commented 3 months ago

I did the test and the bug also appears with version 1.2. I'm really disappointed that this bug appears on several phone models.

I believe it's caused by this piece of code in Utils.java file:

    /**
     * @return The next alarm from {@link AlarmManager}
     */
    public static String getNextAlarm(Context context) {
        final AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        final AlarmClockInfo info = getNextAlarmClock(am);
        if (info != null) {
            final long triggerTime = info.getTriggerTime();
            final Calendar alarmTime = Calendar.getInstance();
            alarmTime.setTimeInMillis(triggerTime);
            return AlarmUtils.getFormattedTime(context, alarmTime);
        }

        return null;
    }

In any case, I'm sorry not to be able to solve this bug.

woj-tek commented 3 months ago

No worries though looking at the snippet - it looks like it's getting that info form system service so probably is scheduling it.

Could you log value of AlarmClockInfo info? Maybe it would hold info which app is responsible?

(own solution would be an option to hide alarm info but that would further complicate settings and we have to stop doing that at one point :D)

BlackyHawky commented 3 months ago

I finally found a workaround.

You need to follow this procedure to determine which application displays the phantom alarm. From what I've read, it's not possible to do this in the code.

I tested it on the phone mentioned above (Xiaomi Redmi Note 5) and the phantom alarm was caused by the original Calendar application. After uninstalling this application, everything went back to normal.

To resolve this bug completely, instead of using AlarmManager, which takes into account all the alarms registered in the Android system, the alarms created should be saved in SharedPreferences.

However, I don't know how to do that. 😬

woj-tek commented 3 months ago

OK... so after digging in it pointed to some calendar and indeed at the next alarm (-1h, timezones I guess?) I had an even in calendar... Now - I'm using https://github.com/quarck/calendarnotification app because it's the only way to have persistent notifications, even across reboots and in the "Misc settings" it has option: "Use setAlarmClock for reminders" (for increase accuracy and indeed it mentions that it would result in this random alamr being displayed) :D