Scrape Navigation info from Google Maps notifications, and add Navigation handling to Bangle.js #3136

Merged
joserebelo merged 1 commits from gfwilliams/Gadgetbridge:navigation-google-maps-notify into master 2023-06-09 08:01:52 +00:00

It looks like navigation code based on #2387 has just gone into the master branch, so it'd be great to get this working with Google Maps too.

  • Allow Local Notifications from Google Maps to be parsed into NavigationInfoSpec by GoogleMapsNotificationHandler
  • Add Navigation handling to Bangle.js
  • Add extra 'ETA' field to NavigationInfoSpec

I've been using this for the last few days and it seems pretty stable - we have to figure out the actions by matching the image Google Maps displays on the notification, but I do a 'fuzzy' match - it's pretty quick and should put up with a few device-specific differences.

It looks like navigation code based on https://codeberg.org/Freeyourgadget/Gadgetbridge/issues/2387 has just gone into the master branch, so it'd be great to get this working with Google Maps too. * Allow Local Notifications from Google Maps to be parsed into NavigationInfoSpec by GoogleMapsNotificationHandler * Add Navigation handling to Bangle.js * Add extra 'ETA' field to NavigationInfoSpec I've been using this for the last few days and it seems pretty stable - we have to figure out the actions by matching the image Google Maps displays on the notification, but I do a 'fuzzy' match - it's pretty quick and should put up with a few device-specific differences.
joserebelo reviewed 2023-05-22 12:41:02 +00:00
@ -276,2 +279,4 @@
if (mediaIgnoresAppList && handleMediaSessionNotification(sbn)) return;
/* Check for navigation notifications and ignore if we're handling them */
if (googleMapsNotificationHandler.handle(getApplicationContext(), sbn)) return;
Collaborator

I think this should be toggleable - either by being after the shouldIgnoreSource so it can be whitelisted/blacklisted, or by using the toggle from #3135, which wasn't merged yet. If this is merged before #3135 I can update this logic to use the toggle.

I think this should be toggleable - either by being after the `shouldIgnoreSource` so it can be whitelisted/blacklisted, or by using the toggle from #3135, which wasn't merged yet. If this is merged before #3135 I can update this logic to use the toggle.

Yes, good point. I've just moved it after the shouldIgnoreSource check - that's nice and easy and makes sense that you should be able to use the existing app ignore list to stop notifications being parsed.

But yes, when #3135 gets merged we could make the call dependent on that too.

Yes, good point. I've just moved it after the shouldIgnoreSource check - that's nice and easy and makes sense that you should be able to use the existing app ignore list to stop notifications being parsed. But yes, when #3135 gets merged we could make the call dependent on that too.
joserebelo marked this conversation as resolved
joserebelo reviewed 2023-05-22 12:43:06 +00:00
@ -0,0 +313,4 @@
}
public boolean handle(Context context, StatusBarNotification sbn) {
if (sbn.getPackageName().equals("com.google.android.apps.maps")) {
Collaborator

Small nitpick (non-blocker): can we flip this if to reduce the nesting?

if (!sbn.getPackageName().equals("com.google.android.apps.maps")) {
    return false;
}

// everything else after
Small nitpick (non-blocker): can we flip this if to reduce the nesting? ```java if (!sbn.getPackageName().equals("com.google.android.apps.maps")) { return false; } // everything else after ```
Collaborator

I think I've also seen getPackageName being null in the past, so maybe flip it to `"com.google.android.apps.maps".equals(sbn.getPackageName())

EDIT: Nevermind - this is not the notificationspec :)

~~I think I've also seen getPackageName being null in the past, so maybe flip it to `"com.google.android.apps.maps".equals(sbn.getPackageName())~~ EDIT: Nevermind - this is not the notificationspec :)
joserebelo marked this conversation as resolved

Just updated this - it's been live in the play store for a week or two now and it appears to be working pretty well now. It can easily be disabled by disabling the Google Maps notifications in the normal way in Gadgetbridge.

Just updated this - it's been live in the play store for a week or two now and it appears to be working pretty well now. It can easily be disabled by disabling the Google Maps notifications in the normal way in Gadgetbridge.
Collaborator

I gave this a quick test, here's a couple of things I noticed:

  1. The distance seems to often be an empty string. In my case, it quickly alternates every other call:
MapsNotificationHandler  I  Navigation: Silver Canoe Way toward Meditation Lane,,23 hr 33 min,110 km,15:07 ETA
MapsNotificationHandler  I  Navigation: Silver Canoe Way toward Meditation Lane,0 m,23 hr 33 min,110 km,15:07 ETA
MapsNotificationHandler  I  Navigation: Silver Canoe Way toward Meditation Lane,0 m,23 hr 33 min,110 km,15:07 ETA
MapsNotificationHandler  I  Navigation: Silver Canoe Way toward Meditation Lane,,23 hr 33 min,110 km,15:07 ETA
MapsNotificationHandler  I  Navigation: Silver Canoe Way toward Meditation Lane,,23 hr 33 min,110 km,15:08 ETA
MapsNotificationHandler  I  Navigation: Silver Canoe Way toward Meditation Lane,0 m,23 hr 33 min,110 km,15:08 ETA
MapsNotificationHandler  I  Navigation: Silver Canoe Way toward Meditation Lane,,23 hr 33 min,110 km,15:08 ETA
MapsNotificationHandler  I  Navigation: Silver Canoe Way toward Meditation Lane,0 m,23 hr 33 min,110 km,15:08 ETA
MapsNotificationHandler  I  Navigation: Silver Canoe Way toward Meditation Lane,,23 hr 33 min,110 km,15:08 ETA
MapsNotificationHandler  I  Navigation: Silver Canoe Way toward Meditation Lane,0 m,23 hr 33 min,110 km,15:08 ETA
MapsNotificationHandler  I  Navigation: Silver Canoe Way toward Meditation Lane,0 m,23 hr 33 min,110 km,15:13 ETA

We could probably fallback to navLines in case the title is empty / fails to be parsed, since it seems to contain the distance on the 2nd item: ["23 hr 33 min", "110 km", "15:15 ETA"]

  1. The call to update the navigation is made quite often - probably every time Google Maps updates the notification. Is this not a problem for the Bangle? I'm not sure about the Pinetime, but in my hacky implementation to send instructions as notifications, it's resulting in the watch constantly vibrating :) might be something I want to handle on the Zepp OS implementation though, since I'm trying to use notifications.
I gave this a quick test, here's a couple of things I noticed: 1. The distance seems to often be an empty string. In my case, it quickly alternates every other call: ``` MapsNotificationHandler I Navigation: Silver Canoe Way toward Meditation Lane,,23 hr 33 min,110 km,15:07 ETA MapsNotificationHandler I Navigation: Silver Canoe Way toward Meditation Lane,0 m,23 hr 33 min,110 km,15:07 ETA MapsNotificationHandler I Navigation: Silver Canoe Way toward Meditation Lane,0 m,23 hr 33 min,110 km,15:07 ETA MapsNotificationHandler I Navigation: Silver Canoe Way toward Meditation Lane,,23 hr 33 min,110 km,15:07 ETA MapsNotificationHandler I Navigation: Silver Canoe Way toward Meditation Lane,,23 hr 33 min,110 km,15:08 ETA MapsNotificationHandler I Navigation: Silver Canoe Way toward Meditation Lane,0 m,23 hr 33 min,110 km,15:08 ETA MapsNotificationHandler I Navigation: Silver Canoe Way toward Meditation Lane,,23 hr 33 min,110 km,15:08 ETA MapsNotificationHandler I Navigation: Silver Canoe Way toward Meditation Lane,0 m,23 hr 33 min,110 km,15:08 ETA MapsNotificationHandler I Navigation: Silver Canoe Way toward Meditation Lane,,23 hr 33 min,110 km,15:08 ETA MapsNotificationHandler I Navigation: Silver Canoe Way toward Meditation Lane,0 m,23 hr 33 min,110 km,15:08 ETA MapsNotificationHandler I Navigation: Silver Canoe Way toward Meditation Lane,0 m,23 hr 33 min,110 km,15:13 ETA ``` We could probably fallback to navLines in case the title is empty / fails to be parsed, since it seems to contain the distance on the 2nd item: `["23 hr 33 min", "110 km", "15:15 ETA"]` 2. The call to update the navigation is made quite often - probably every time Google Maps updates the notification. Is this not a problem for the Bangle? I'm not sure about the Pinetime, but in my hacky implementation to send instructions as notifications, it's resulting in the watch constantly vibrating :) might be something I want to handle on the Zepp OS implementation though, since I'm trying to use notifications.

Ahh, interesting - I think the 2nd item is the total distance, whereas what we were hoping to report in NavigationSpec was the distance to the next turning?
It seems you were likey right at the point where it wanted you to make a turn, so it wouldn't have given you a number.

When you start and the phone GPS location is still getting more accurate, the values do move around a bit, but I found that in practice you only got updates when the value changes. When driving around it was about once a second, but honestly if you're driving and looking at the countdown of distance to the turning, that's kind of what you want.

On Bangle.js we treat the nav updates slightly different to notifications - but they don't buzz. I don't know if that's something you can tweak - I did have the idea originally you could have a 'onNotificationModified' event that wouldn't buzz but would just silently update the data

Ahh, interesting - I think the 2nd item is the total distance, whereas what we were hoping to report in NavigationSpec was the distance to the next turning? It seems you were likey right at the point where it wanted you to make a turn, so it wouldn't have given you a number. When you start and the phone GPS location is still getting more accurate, the values do move around a bit, but I found that in practice you only got updates when the value changes. When driving around it was about once a second, but honestly if you're driving and looking at the countdown of distance to the turning, that's kind of what you want. On Bangle.js we treat the nav updates slightly different to notifications - but they don't buzz. I don't know if that's something you can tweak - I did have the idea originally you could have a 'onNotificationModified' event that wouldn't buzz but would just silently update the data
Collaborator

Ah - I think you're right, I got the total distance and distance to the next turn mixed up.

This looks good to me. Regarding the frequent updates, I'll check if I can handle them on my side to get this working with Zepp OS devices.

Ah - I think you're right, I got the total distance and distance to the next turn mixed up. This looks good to me. Regarding the frequent updates, I'll check if I can handle them on my side to get this working with Zepp OS devices.
Collaborator

@gfwilliams can you rebase this branch? Looks like there are some conflicts:

Merge Failed: There was a conflict whilst rebasing commit: be77d8e18e4783c5f218a34ef737afa83e72d90e. Hint: Try a different strategy
Error Message
Rebasing (1/4) error: could not apply be77d8e18e... Add Navigation handling to Bangle.js
Resolve all conflicts manually, mark them as resolved with
"git add/rm <conflicted_files>", then run "git rebase --continue".
You can instead skip this commit: run "git rebase --skip".
To abort and get back to the state before "git rebase", run "git rebase --abort".
Could not apply be77d8e18e... Add Navigation handling to Bangle.js Add extra 'ETA' field to NavigationInfoSpec Allow Local Notifications from Google Maps to be parsed into NavigationInfoSpec by GoogleMapsNotificationHandler

Auto-merging app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/banglejs/BangleJSDeviceSupport.java
Auto-merging app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/NotificationListener.java
CONFLICT (content): Merge conflict in app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/NotificationListener.java
@gfwilliams can you rebase this branch? Looks like there are some conflicts: ``` Merge Failed: There was a conflict whilst rebasing commit: be77d8e18e4783c5f218a34ef737afa83e72d90e. Hint: Try a different strategy Error Message Rebasing (1/4) error: could not apply be77d8e18e... Add Navigation handling to Bangle.js Resolve all conflicts manually, mark them as resolved with "git add/rm <conflicted_files>", then run "git rebase --continue". You can instead skip this commit: run "git rebase --skip". To abort and get back to the state before "git rebase", run "git rebase --abort". Could not apply be77d8e18e... Add Navigation handling to Bangle.js Add extra 'ETA' field to NavigationInfoSpec Allow Local Notifications from Google Maps to be parsed into NavigationInfoSpec by GoogleMapsNotificationHandler Auto-merging app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/banglejs/BangleJSDeviceSupport.java Auto-merging app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/NotificationListener.java CONFLICT (content): Merge conflict in app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/NotificationListener.java ```
joserebelo added the
Bangle.js
label 2023-06-08 21:23:33 +00:00
gfwilliams force-pushed navigation-google-maps-notify from 79590fc946 to 735f27d5bf 2023-06-09 07:51:57 +00:00 Compare

No problem - just rebased and squashed commits - hopefully that sorts it :)

No problem - just rebased and squashed commits - hopefully that sorts it :)
joserebelo merged commit 735f27d5bf into master 2023-06-09 08:01:52 +00:00

Excellent - thanks! I've been using this a lot recently and it's really handy having navigation on your wrist, especially when cycling or walking

Excellent - thanks! I've been using this a lot recently and it's really handy having navigation on your wrist, especially when cycling or walking
gfwilliams deleted branch navigation-google-maps-notify 2023-06-09 08:12:39 +00:00
Sign in to join this conversation.
No reviewers
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: Freeyourgadget/Gadgetbridge#3136
There is no content yet.