Johboh / hassalarm

Android app for integration with Hass.io as a sensor for the next scheduled alarm on the device
MIT License
62 stars 6 forks source link

FR: Store app (intent) which triggered a certain alarm update #30

Open nitobuendia opened 1 year ago

nitobuendia commented 1 year ago

I've been facing the issue as in #19. Ignored apps is a good fix. My challenge is to know which app to block. At the moment, the only way to do this is by acting on the moment it's been set up as "next alarm" to ignore it. However, I might not have a chance to check at that moment. I would love to understand for all the history of publishes, which app triggered which.

In short, the request here would be to store and show the app source of the alarm on the "Publish history".

For example, instead of: @23-03-25 10:48:17 alarm @: 23-03-26 09:30

Show something like: @23-03-25 10:48:17 alarm @: 23-03-26 09:30 by "com.sec.android.app.clockpackage"

Alternatively, this information could be shown on click, similar to the popup information when you click on errors.

At the moment, this would be only for information, so we can diagnose the source of the problematic apps to ignore. In the future, we could also change it so you could have a one click to add that app to the Ignore apps list.

Johboh commented 1 year ago

I will look into it!

Johboh commented 1 year ago

@nitobuendia I pushed a version that includes the package name now in the history view. It will take some hours for it to propagate. Please give it a go once you receive the update (1.22).

Johboh commented 1 year ago

Forgot to hit publish in Google Play Console! Now the new version is actually published (or rather, sent for review). Will take some hours for it to propagate.

nitobuendia commented 1 year ago

Thanks a lot, @Johboh, for woking on this and the quick turnaround.

I was waiting for it to be deployed to test it out and I've just tried the new version.

At the moment, when I go to "Publish History", it shows empty and immediately redirects back to the home view. If I leave it be for some seconds, it automatically closes. The app also crashed a couple of times when accessing Publish History, but I am unable to reproduce consistently. Most times, it simply closes without an error.

I have sent the logs via the Android built-in system:

Could it be that creatorPackage is null because historically it was not collected and it's making the system crash when calling return new AutoValue_NextAlarmUpdaterJob_Request(call, triggerTimestamp, creatorPackage);? I assume supporting @Nullable or adding some default value (unknown?) when it's null could do the trick to avoid breaking history backwards.

Johboh commented 1 year ago

😢 It was supposed to handle null creatorPackage. I will look into it (also, I should migrate to kotlin)

Johboh commented 1 year ago

@nitobuendia I pushed a new version now (1.23).

nitobuendia commented 1 year ago

@Johboh Thank you! Still crashing but different error. I've tried with a Pixel 5 and a Samsung A53.

Error: Exception while computing database live data from RoomOpenHelper. I couldn't see the lines since the Preview is quite limited, but it seems the data structures expected and received are different. I've sent the log data via the system.

Johboh commented 1 year ago

That is odd, as I added a migration strategy for the database. I will investigate.

Johboh commented 1 year ago

@nitobuendia Is this for 1.23 btw? I cannot seams to find any for that version, only the NPE you saw earlier for 1.22.

nitobuendia commented 1 year ago

Yes, 1.23, @Johboh - I've sent another report.

nitobuendia commented 1 year ago

Updated to 1.24. The app is no longer crashing, but there's also no history shown. I'll report what I see tomorrow. Thanks!

Johboh commented 1 year ago

Yes I have to sacrifice the history in favor for not crashing. Lessons learned to next time I change the Room database structure 😊.

nitobuendia commented 1 year ago

I've just checked in the morning and the history data is flowing in again, but I still cannot see the app source. Here's a screenshot in horizontal since I had text wrap issues before. Clicking also does not seem to open a pop up or alike.

Screenshot_20230327-093812

Johboh commented 1 year ago

The app source is only shown if the alarm manager is reporting one. Can you verify by trying to set an alarm in the stock Google clock? I will also investigate this from the API side of things.

Johboh commented 1 year ago

Looks like I broke something while converting to kotlin. Will investigate after work today. Sorry for the inconvenience!

Johboh commented 1 year ago

It turns out that starting with Android 13, there is no creator package name in the pending intent provided by the AlarmClockInfo. It works on Android 12L. I will investigate further.

Johboh commented 1 year ago

@nitobuendia So it looks like starting with Android 13 / API 33, the creator package is no longer set in the Pending Intent for the alarm clock. Other similar apps have the same issue: https://community.openhab.org/t/alarm-clock-andorid-sends-undef/133718 I couldn't find any mention of this in the Android API 33 change log, so unsure if this is a bug or an intentional change. This also mean that the Ignore App function in the Hassalarm app is no longer functioning. I'm still trying to find a workaround for this, but no luck so far.

Johboh commented 1 year ago

I created a ticket: https://issuetracker.google.com/issues/275678087