BimmerGestalt / AAIdrive

Implementations of some Android Auto features as unofficial IDrive apps
MIT License
541 stars 90 forks source link

Reimplement Calendar car app #279

Closed hufman closed 2 years ago

hufman commented 3 years ago

With Connected being replaced with MyBMW, the Calendar app and the ability to navigate to upcoming appointments is going away. This ability is provided by Android Auto, and so it would fit in the purview of Android Auto Idrive.

wnrussell commented 3 years ago

Walter, I just installed Calendar car app in my 2019 430ix Gran Coupe w/ iDrive 6 (I think). Calendar app still not showing yet. Any way you can help troubleshoot? Thx...

wnrussell

hufman commented 3 years ago

What Calendar app did you install? AAI has not implemented anything for this functionality yet.

wnrussell commented 3 years ago

androidautoidrive-1.3-nomap-nonalytics-release.apk

Just saying the screenshot in the README file shows MINI Calendar. I'll be happy to do some testing when Beta is ready.

Thank you for your fast response, Walter

wnrussell

hufman commented 3 years ago

Oh ha, that's the original BMW/MINI Connected calendar, from before it shut down this year :)

wnrussell commented 3 years ago

Then did I install the wrong APK or it doesn't matter? Has anyone outlined next steps for this project and how can I help?

hufman commented 3 years ago

You didn't install the wrong AAI APK, because none of them have this feature yet. To get that pictured Calendar app, you'd need to install the earlier BMW/MINI Connected app, use the Android Settings to manually grant Calendar access to the app (since the app won't make it past the login screen to request the permissions), and hope it connects to the car. You might run into issues if you have both the new MyBMW/MINI app and the older Connected app, I've encountered issues where both of them try to talk to the car. Since running both BMW Connected and MyBMW simultaneously is not recommended, this task is to reimplement the Calendar feature in AAI. (Unless, of course, BMW brings it back to MyBMW ;) The rough roadmap is outlined here: https://github.com/hufman/AndroidAutoIdrive/milestones

hufman commented 2 years ago

In early version is available in the calendar branch, and here's a test build to try out before I merge to the main branch!

berseker commented 2 years ago

In early version is available in the calendar branch, and here's a test build to try out before I merge to the main branch!

I tried today this test build, I can confirm that (check the comment & the screenshot organized this way)

1 | 2 3 | 4

1) the app shows up (BMW Calendario, so it takes the Italian Language app name

2) scrolling between dates works flawlessly it highlights also the holidays with an "halo" under the day number (as instance, December 8Th is an Catholic Holiday)

3 & 4) it is not connected to the Google Calendar (but maybe it is not supposed to, at least at this stage ;), I quickly tried to add an appointment \ reminder for my Mum birthday to try just for curiosity

image

in any case, excellent job as always :)

hufman commented 2 years ago

Hmmm! That's disappointing, it works very well for me and my Samsung Calendar (which Google Calendar sees the same events). The fact that it sees the holidays means that it has the READ_CALENDAR permission, so it's not that... Do you have several calendars in Google Calendar, and do some of them at least show up? I wonder what the pattern is, since your Holiday calendar shows up.

berseker commented 2 years ago

I checked and the app I'm using is MIUI Calendar 12.5.1-data, so maybe It works weird as all the MIUI apps do :) i confirm i gave the permissions. The app Is linked to my Google Calendar(s) more than One account. Actually if you see the screenshot, December 5 have Also the "halo" thing as It has inside something but After clicking on It, nothing shows up.. i'll do more tests and let you know.

jezikk82 commented 2 years ago

Hi, I tested it as well and it works fine for me. Just 2 notes to what @berseker said:

  1. Google calendar work fine (I see all the calendars I have created and have shared by others).
  2. I also own MIUI and their calendar app use the own calendar as default and what's created in it it not seen in default android calendar. That's why I had to left behind some miui alternatives. Sad but you can find a lot of information about it in google.

Questions:

  1. Would it be possible to mark from which calendar even came from ?
  2. Would it be possible to present events on the side panel in months view ? (e.g. for the highlighted day or starting from today going couple days in future ?).

Issue:

p.s. I just saw in release note from Google Play what MyBMW also got the Calendar reimplemented - curious if no interference there will be. I'll try to test it.

Marc2480 commented 2 years ago

I don't seem to get any entries in the calendar, using Samsung email (1 exchange and 1 imap account) on a S20 ... Any specific setting needed apart from granting access to AAI ? (running build 1.3.1.24 Calendar)

thanks, Marc

jezikk82 commented 2 years ago

On first usage you should be prompt to give access to android calendar default app. Check if you have in default calendar entries from Samsung email app.

e.g. I have exchange app in Workspace (email&calendar) and this calendar evens are not seen, as this spaces are independent.

hufman commented 2 years ago

Thank you all so much for testing! I'm not sure what options there are for supporting Mi Calendar... I do see that it has its own Content Provider to provide access to its events, but the API contract is undocumented and very different from the native Android Calendar Content Provider, and unlikely to be guaranteed between versions. Is there a setting in Mi Calendar to synchronize their calendar with other apps? The original BMW Connected Calendar would not support it either, it only has code to query the system calendar.

I'm also not sure how Samsung email will integrate with it; as long as it's pushing the events to the system calendar so that they are visible in Google Calendar on the phone, it should work fine. My Samsung S9 uses the native Google Account Sync to fill things in the system calendar, which then shows up in Samsung Calendar. I did not add any filtering options in AAIdrive for now, so all events that are viewable should show up. The Work Profile calendar is indeed entirely separate and can't be seen from the main apps.

If AAIdrive Calendar doesn't have permission, it'll show a button in the phone UI to grant it and it'll show a one-time popup in the car app to request access. You'll probably have already granted this, which should be all you need to do.

The app name is hardcoded into the BMW app resources, so I'm delighted that it has a translated name! I don't think any other car app has a translated name like that! I don't know of a way to show the day view in the sidebar while in the month view: that screen is entirely managed by the car, and all I do is provide a list of highlighted days for the month that the car says it is showing. I'd like to hear more about the bug about the selected day being different when going back to the month view, I tried to support this feature. In fact, it seems very sticky for me, so that it goes back to the last selected day even when exiting the app and going back into it. Please also tell me more about the month view showing an event on December 5th but no event showing in the day view. The code to find events for the Day view purposely looks a day ahead and behind to catch events that cross midnight (technically it won't show events in the Day view if you click into the middle of a week-long event, which aren't going to be super relevant to navigation but still fixable if that's preferred). The Day view might support adding an icon or something; the BMW Calendar code says that there's a field for an ID of an image from the icon pack, which didn't work for either attempt I tried, but I haven't yet tried sending an actual image in this field which does work in other lists in the car. I planned to explore this after merging this branch to the main branch.

berseker commented 2 years ago

about "Please also tell me more about the month view showing an event on December 5th but no event showing in the day view. " i noticed that the halo is simply the one always present in the "selected" day :/
today I tried both only Miui Calendar & even Google Calendar but suddenly completely stopped working for me (the calendar worked but neither the holidays were shown today).. I surely manager to broke something, I'll try again some testings in the next days and give you some reports

hufman commented 2 years ago

How do you like the wording on this note, if the Mi Calendar is installed on the phone? image

jezikk82 commented 2 years ago

Maybe it would be better something like this:

_Events from Vendor Specific calendar apps (e.g. Mi Calendar) or from Work Profile that are not sync with default Android Calendar may not show up in the car.

The car will show the events that are visible in Google Calendar only (including shared calendars)._

hufman commented 2 years ago

How about this? The description at the top always shows up, indicating that Google Calendar will be the definitive view, and the Mi Calendar notice only shows up if Mi Calendar is installed. image

jezikk82 commented 2 years ago

Quick question, is it possible to present only calendars where I see details ? In Gcalc I have some read-only calendars where I only see free/busy and no detail and on daily bases it's not needed to present in the car.

So would be nice to have option to show only selected calendars from Gcalc or if not possible to present only the event that have title/details. Thanks.

hufman commented 2 years ago

In my test (and peeking in some Android code) it should hide events from calendars that aren't selected to display in Google Calendar. I can also add an option to hide events without details or location easily enough! Thanks for the suggestion!

hufman commented 2 years ago

image

jezikk82 commented 2 years ago

In my test (and peeking in some Android code) it should hide events from calendars that aren't selected to display in Google Calendar. I can also add an option to hide events without details or location easily enough! Thanks for the suggestion!

In my case not showing calendars that are unselected works fine. Adding the toggle to hide events without details would be nice and would solve the problem. Not sure about hidding events without location, as sometime I create tasks in calendar without location.

hufman commented 2 years ago

I implemented this toggle to hide any events that have neither a description or a location, so if one of those fields is provided it will still show the event.

jezikk82 commented 2 years ago

Great, will test it over the weekend

jezikk82 commented 2 years ago

I tested the latest commits but unfortunately for me the calendar doesn't work any more. No matter the toggle to hide event without location/details is on or off. App shows the calendar permission granted but in car no events.

Previously it was working almost fine.

Still there is a situation that when I enter details at that day and press back button on idrive controller, the selected day is usually 1st day of the month or first Sunday of the month.

Request:

jezikk82 commented 2 years ago

https://youtu.be/aubJHFo2vgE

hufman commented 2 years ago

I just now implemented that Day View header to click through to the next day, thanks for the idea! I didn't even realize that field was clickable. The weird date behavior is very very weird, I can't reproduce it on my end. I'm very intrigued that the selected day is changing to a different day, the only code I have to set the selected date is within the click handler. The value that is being sent from the car is parsed and sent back to the Day View, which does look to be displaying the proper date on top. I had changed (in 7f099d3) the Day View to query the entire month's events and filter to just the selected day, instead of querying just a single day, to display events that span multiple days. Please try a build from before and after that commit to confirm if that commit is causing the problem of missing data in the Day View. I just pushed a possible tweak to the Month view, but it wouldn't help if the underlying problem is that the calendar query is failing to search the entire month. Did you ever see the highlighted halo in the Month view, as shown in the pictures from berseker?

jezikk82 commented 2 years ago

Did you ever see the highlighted halo in the Month view, as shown in the pictures from berseker?

No i haven't seen.

I'll check tomorrow both versions and let you know.

jezikk82 commented 2 years ago

I checked version with roll-backed commit 7f099d3 works fine. Below are 2 movies showing the working calendar with and without hiding empty events. Unfortunately, no halo even on Christmas Days (24-26 Dec).

https://youtu.be/XRAtZnOEtog https://youtu.be/KzOwn9GU9vw

Version with that commit fails

berseker commented 2 years ago

Did you ever see the highlighted halo in the Month view, as shown in the pictures from berseker?

actually also myself after that first "quick test" i did not manage to see the "holidays" again . not sure which is the reason

hufman commented 2 years ago

@jezikk82 thank you for the test! Can you clarify which commit shows the working Day view and which one does not show any events in the Day view? The option to hide empty events came after that 7f099d3 Day View change, so that's promising...

Please try out cloning the repo down again and remove the Ignore line from this test file and uncomment some of the debugging from the query module and try out running the CalendarTest from your IDE. You can edit the CalendarTest to query with a null day parameter to simulate the month view. Perhaps add an extra logging line above the splitEventIntoDays loop to see if it's finding events there and they're somehow making it into the loop for some reason. It should add lines to your Logcat tab (filterable by the word Calendar) with what events it found.

Thank you for your patience in helping with the project!

jezikk82 commented 2 years ago

I only rolled back single commit no 7f099d3. So in 2 files mentioned there i have old content.

Will try tomorrow CalendarTest and let you know.

hufman commented 2 years ago

I encountered a crash, and it seems that sometimes the phone's CalendarProvider can unexpectedly return null strings for the title, description, or location strings. I just added a guard for that behavior, and perhaps it might fix the problem you were seeing.

jezikk82 commented 2 years ago

I'm extremely busy now and didn't have time to test what you stated. Today I made a quick test of what you committed and I don't work for me. I see only full day event, no other. Doesn't matter if the toggle to hide is on or off. Will share some pics later showing the problem. bmw-calendar

Brown and Blue are my personal calendars within Google Calendar, Orange (full day event in pic) is from predefined GCalenders I'm subscribed to.

p.s. I haven't experienced the jumping to previous dates when going back from day to month view.

hufman commented 2 years ago

I appreciate the time you spend helping test this project! That looks like progress, since you hadn't seen the Highlighted Days halos before! Do I understand you are running the tip of the main branch but with 7f099d3 reverted in your build? That commit is meant to make sure that, if a day is highlighted in the month view (such as your Dec 17), then it will show up in the day view. Of course, those short events you demonstrate should show up anyways, so there's still something behaving wrong there. The toggle will affect whether an empty event is shown in the Month view too, not just the Day view, they should always match. Does the "p.s." mean that I fixed that bug you were encountering?

jezikk82 commented 2 years ago

Today's testes I performed on clean version from github. No, previously I havent seen Highlighted Days halos, now it's present on days that have all day events. Yes, you fixed the but I demonstrated on previous video when going back from day view highlighted was not the right day.

As soon as I get some free time will try to check with 7f099d3 reverted and let you know.

jezikk82 commented 2 years ago

By chance I think I found root cause of the problem, actually two problems.

  1. In Google calendar I have couple of different calendars, not only from Google but from others apps as well. What I did is to mark all of them as visible in GCalendar and made an event in all of them one by one. That way I discovered that only events from subscribed GCalendar Holiday events and week numbers are presented and from alphabetically first calendar on the list. In my case of it's a calendar from some app I dont use so much. Checked it twice and adding events from GCalendar and choosing that calendar make event visible in the car. Not sure how You were taking events before, but It was working for me before the 7f099d3. I showed that in this video: https://www.youtube.com/watch?v=KzOwn9GU9vw

Two link that may be useful: https://stackoverflow.com/questions/14423189/how-to-get-calendar-event-by-date-range-or-month-in-android/15331996#15331996 https://stackoverflow.com/questions/61012807/android-calendar-provider-does-not-return-latest-data

  1. Toggle to hide events without details is not working as expected as well. On Dec 17 I have some events, I edited them to use the calendar I stated before as I see them in the car.
    • Browns event are synced from read only calendar and Title is "BUSY" no details. However in car they are presented without title (see video above) - toggle remove that entries.
    • Blue are mine, some of them have Teams meeting details, other have addresses in it and some have only title and times This last set it also hidden when toggle is on.
jezikk82 commented 2 years ago

Any progress ?

I looked at https://developer.android.com/guide/topics/providers/calendar-provider#kotlin but can't find in AAID where to modify to ask for all subscribed calendars.

hufman commented 2 years ago

I haven't been able to think of anything. I recently added a change to require a title to be considered detailed enough to show in the car, which you may have seen.

The single line in AAIdrive that asks for calendar events is here. It uses an official helper function to query all events from the Instances table. This function automatically adds a query parameter of visible=1, which I believe would properly show all events for visible calendars and not include unchecked calendars. You could try copying this helper function and modifying it to not add this visible parameter, and maybe it will help find more events from your phone.

The change in 7f099d3 is to, when viewing the day view, to query the entire month and then filter for any events that have the correct day, as opposed to previously querying for events specifically by day, to handle the case where events span across the day. Because the same query is now being queried for both month and day view, any highlighted days in the month view should have events in the day view.

Have you checked in ADB Logcat to see if your phone is logging any crashes? Technically, when trying to set an icon for an event in the day view, I'm sending an RHMIResourceIdentifier while the official BMW Connected Calendar used to just send an integer, and perhaps your car is returning an exception and mine is just ignoring it? I just pushed up a change to remove this code and match the original Calendar app's behavior, just in case.

drm87 commented 2 years ago

It this intended to be running on iDrive4, too? Currently, it seems broken (at least in my car/setup), no further interaction is possible:

2048-966-max

hufman commented 2 years ago

This screenshot shows that the app has queried your calendar and then sent a list to the car to highlight all of the days in the month view. It's strange that it doesn't show a selected date cursor nor does it show a label for the current month name.

I'm technically using the ID5 version of the calendar resources, but the ID4 version looked similar enough to not matter. If you'd like to try the ID4 version, change this line in buildtools/external.gradle, clear the app/assets/carapplications directory, and build again:

-"calendar/rhmi/ui_description_ID5.xml": "calendar/rhmi/ui_description.xml",
+"calendar/rhmi/ui_description_ID4PP.xml": "calendar/rhmi/ui_description.xml",

Do you see any messages in adb logcat about the calendar?

drm87 commented 2 years ago

Had the chance to test it with the ID4 XML file, but still the same situation. I will try to get the log output next time.

drm87 commented 2 years ago

Here are all logcat messages for the calendar app I could see:

[01-03 13:31:38.525 29314:9201 I/MainService]
Starting calendar app

[01-03 13:31:38.564 29314:29314 I/MainService]
Successful null connection to ComponentInfo{me.hufman.androidautoidrive/me.hufman.androidautoidrive.carapp.calendar.CalendarAppService} module

[01-03 13:31:41.254 29314:9201 I/CarThread]
Successfully finished runnable for thread CalendarAppService, starting Handler loop

[01-03 13:31:43.272 29314:9155 W/CalendarApp]
Received rhmi_onActionEvent: handle=21 ident=me.hufman.androidautoidrive.calendar actionId=52 args={43=725}

[01-03 13:31:43.311 29314:9198 W/CalendarApp]
Received rhmi_onHmiEvent: handle=21 ident=me.hufman.androidautoidrive.calendar componentId=6 eventId=11 args={23=true}

[01-03 13:31:43.313 29314:9197 W/CalendarApp]
Received rhmi_onHmiEvent: handle=21 ident=me.hufman.androidautoidrive.calendar componentId=6 eventId=1 args={4=true}

[01-03 13:31:48.350 29314:9187 W/CalendarApp]
Received rhmi_onHmiEvent: handle=21 ident=me.hufman.androidautoidrive.calendar componentId=6 eventId=1 args={4=false}

[01-03 13:31:49.671 29314:9197 W/CalendarApp]
Received rhmi_onHmiEvent: handle=21 ident=me.hufman.androidautoidrive.calendar componentId=6 eventId=1 args={4=true}

[01-03 13:31:57.268 29314:9201 I/CarThread]
Successfully finished tasks for thread CalendarAppService

Otherwise, I have not been able to see anything unusual in the logs.

hufman commented 2 years ago

Very interesting! Thank you for the log snippet! Would you be able to swap out MyBMW for BMW Connected 6.4, manually grant it the Calendar permission through the Android settings, and see how the official BMW Connected Calendar behaves? I deciphered the Calendar app protocol by reading the decompiled code from BMW Connected, but I didn't see any special handling for ID4 in there and I wonder what I'm missing...

drm87 commented 2 years ago

Alright, I will test it. Anything in particular I should do, like saving logcat messages again?

Side note: From my previous experiences, neither the BMW calendar apps from the Connected and Classic versions of the app were perfect, but the one from the BMW Connected Classic app worked better. It showed all my calendars from my phone (and even let me select/deselect every calender via the options menu in iDrive). The one from the newer Connected app only showed my Google calendar. Both had in common that the left side-menu was a bit broken, the bottom menu entry (used for scrolling I think) was not visible but selectable.

hufman commented 2 years ago

Capturing logcat messages isn't necessary for testing BMW Calendar, it has its logs muted. If you have a rooted phone, an advanced technique would be to install and run tcpdump -i lo to capture the car traffic, but probably not necessary. That's curious that Classic's Calendar was more functional! I'll peek in that codebase to see if it has any clues! I'd be most interested to see if the new BMW Connected Calendar works properly in your ID4, and I'd appreciate an overview (perhaps a video?) of how BMW Classic Calendar works. Thank you so much for your patience and assistance!

drm87 commented 2 years ago

Here is a video showing the behavior of the original calendar app from the BMW Connected app:

https://user-images.githubusercontent.com/1875852/148662915-aeeb4ddb-3eb3-4964-b219-c50bed61223c.mp4

And here is a demo of the Connected Classic's calendar app:

https://user-images.githubusercontent.com/1875852/148662858-e08f22c3-88b2-430d-bcf1-8d9487bf486a.mp4

hufman commented 2 years ago

I just added a phone interface section to show what calendars and events the app can see, hopefully it helps debug the calendar visibility problems!

jezikk82 commented 2 years ago

Hi, I just tested new release and it confirm what I manage to find earlier. It only takes one "default???" calendar (now it's xiaomi default) not the GCal and other subscribed calendars. All the calendars except Contact are marked as visible in GCalendar app.

That's interesting as well, as I don't have a Xiaomi Calendar app on my phone installed. It as removed with xiaomi debloater just after I bought the phone. Previously the "default??" calendar was from some project management app I tested, but after complete removal and clean-up with ADB it changed to xiaomi calendar DB (previously removed). Strange behaviour.

Maybe the best way would be to mark which calendars include in the car as you already have most of the ui for it. (same swipe behaviour as with music apps)

Screenshot_2022-01-14-11-34-46-606_me hufman androidautoidrive

hufman commented 2 years ago

That's fascinating! I just pushed up a branch that adds a debug row showing what sync provider each calendar comes from, check it out! Please feel free to experiment with this code and explore the data further. I'm reluctant to add a separate customization of what calendars to view: This adds several extra user interaction steps and a complicated data storage model, which is tricky to keep in sync with the default data, in order to make its behavior diverge from the phone's native view of the data. I'd much rather have it work automatically, by figuring out the weird incompatibility with your (or perhaps, any?) Huawei phone.