Bangle.js: Intents - extending functionality #2769

Merged
vanous merged 1 commit from Ganblejs/Gadgetbridge:Intents into master 2022-08-17 19:37:24 +00:00
Contributor

The additions in this PR has been developed together with @gfwilliams in this forum post and this closed PR to his Gadgetbridge-fork. I have also gotten input from José Rebelo, vanous and Sylvia in the Gadgetbridge matrix chat. Thank you to everyone!

Gadgetbridge with a Bangle.js now supports starting activities in addition to sending broadcasts. Targeting services is yet to be implemented.

action, category, mimetype, data, extra, package, class and target information can now be supplied to intents (these are also the corresponding keys to use when programming intent messages to send to gadgetbridge). Values to pass to target are "", "broadcastreceiver", "activity", "service" or target can be left out.

Template for initiating an intent through javascript-code from a Bangle.js app that sends message to Gadgetbridge:

Bluetooth.println(JSON.stringify({t:"intent", action:"", category:"", mimetype:"", data:"", package:"", class:"", target:"", extra:{someKey:"someValueOrString"}}));

Key/value-pairs in the template above can be omitted if not applicable in the specific case.

Things to consider:

  • If/when this PR gets merged, the documentation here should be updated regarding intents as well. However, the changes don't break the functionality as it is currently described in the espruino documentation. They only extend it. It's also been mentioned a Gadgetbridge wiki page might be a good idea.
  • I will probably try to add support for targeting services. But that can be a separate PR.
  • I have tested the changes and now it seems to work well. I am not experienced with testing new code. But @gfwilliams have kindly pointed out potential (read guaranteed) bugs so most bases should be covered.
  • Maybe there should be more descriptive comments.
  • I haven't really done java and android programming before, so I could be doing mistakes without realizing it.

Future work for another PR:

  • Implement targeting services.
  • Allow gadgetbridge to wake the device to trigger intents. (If there's a better way please tell. Maybe something something services?)

Follow up PR: #2826

The additions in this PR has been developed together with @gfwilliams in [this forum post](http://forum.espruino.com/conversations/377692/#comment16604862) and [this closed PR to his Gadgetbridge-fork](https://codeberg.org/gfwilliams/Gadgetbridge/pulls/1). I have also gotten input from José Rebelo, vanous and Sylvia in the Gadgetbridge matrix chat. Thank you to everyone! Gadgetbridge with a Bangle.js now supports starting activities in addition to sending broadcasts. Targeting services is yet to be implemented. action, category, mimetype, data, extra, package, class and target information can now be supplied to intents (these are also the corresponding keys to use when programming intent messages to send to gadgetbridge). Values to pass to target are "", "broadcastreceiver", "activity", "service" or target can be left out. Template for initiating an intent through javascript-code from a Bangle.js app that sends message to Gadgetbridge: `Bluetooth.println(JSON.stringify({t:"intent", action:"", category:"", mimetype:"", data:"", package:"", class:"", target:"", extra:{someKey:"someValueOrString"}}));` Key/value-pairs in the template above can be omitted if not applicable in the specific case. Things to consider: - If/when this PR gets merged, the documentation [here](https://github.com/espruino/EspruinoDocs/blob/master/info/Gadgetbridge.md) should be updated regarding intents as well. However, the changes don't break the functionality as it is currently described in the espruino documentation. They only extend it. It's also been mentioned a Gadgetbridge wiki page might be a good idea. - I will probably try to add support for targeting services. But that can be a separate PR. - I have tested the changes and now it seems to work well. I am not experienced with testing new code. But @gfwilliams have kindly pointed out potential (read guaranteed) bugs so most bases should be covered. - Maybe there should be more descriptive comments. - I haven't really done java and android programming before, so I could be doing mistakes without realizing it. Future work for another PR: - Implement targeting services. - Allow gadgetbridge to wake the device to trigger intents. (If there's a better way please tell. Maybe something something services?) Follow up PR: #2826
Ganblejs changed title from WIP: Intents to Intents 2022-07-19 14:46:48 +00:00
Ganblejs changed title from Intents to Bangle.js : Intents - extending functionality 2022-07-19 15:08:52 +00:00
Ganblejs changed title from Bangle.js : Intents - extending functionality to Bangle.js: Intents - extending functionality 2022-07-19 15:09:32 +00:00
Author
Contributor

Should permission "Display over other apps" also be introduced for the main build variant, since intents for Bangle.js is present there as well?

Should permission "Display over other apps" also be introduced for the main build variant, since intents for Bangle.js is present there as well?
Owner

Thank you, we will look at it.

Thank you, we will look at it.
Ganblejs reviewed 2022-07-20 09:55:43 +00:00
@ -287,2 +287,4 @@
}
if (BuildConfig.FLAVOR.equals("banglejs") &&
ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.SYSTEM_ALERT_WINDOW) == PackageManager.PERMISSION_DENIED) {
Author
Contributor

I've now noticed this doesn't behave as for other permissions and like I want/expect it to. When launching "Bangle.js Gadgetbridge" the associated pop-up to this permission will always show, even if the the setting is enabled.

I've now noticed this doesn't behave as for other permissions and like I want/expect it to. When launching "Bangle.js Gadgetbridge" the associated pop-up to this permission will always show, even if the the setting is enabled.
Owner

@Ganblejs, how would I go about trying this? Can you please give some example of how I could test it (besides looking at the code)?

Thank you.

@Ganblejs, how would I go about trying this? Can you please give some example of how I could test it (besides looking at the code)? Thank you.
Author
Contributor

@Ganblejs, how would I go about trying this? Can you please give some example of how I could test it (besides looking at the code)?

Thank you.

Do you mean specifically what I mentioned in my last comment:

I've now noticed this doesn't behave as for other permissions and....

Or the PR in general?

In case of the former I reproduce the bug on my end by:

  1. giving all permissions when Bangle.js Gadgetbridge asks for them.
  2. Closing Bangle.js Gadgetbridge and clearing it from recents.
  3. starting Bangle.js Gadgetbridge again.
  4. Bangle.js Gadgetbridge asks for permission to display over other apps even though it has already been granted that permission and the setting is still enabled on "app info" settings section -> advanced -> Display over other apps.

In case of the latter, do you have a Bangle.js to test with yourself?

EDIT:

How it works:

  1. The bangle sends a message to Gadgetbridge e.g. to start a track on spotify, coded in javascript:
    Bluetooth.println(JSON.stringify({t:"intent", action:"android.intent.action.VIEW", category:"android.intent.category.DEFAULT", package:"com.spotify.music", data:"spotify:track:5QEFFJ5tAeRlVquCUNpAJY:play", target:"activity" }));
  2. Gadgetbridge receives it (GB Log):

22:59:12.705 [Binder:3650_8] INFO n.f.g.s.d.b.BangleJSDeviceSupport - UART RX LINE: {"t":"intent","action":"android.intent.action.VIEW","category":"android.intent.category.DEFAULT","package":"com.spotify.music","data":"spotify:track:5QEFFJ5tAeRlVquCUNpAJY:play","target":"activity"}

  1. Gadgetbridge bakes and sends the intent (GB Log):

22:59:12.707 [Binder:3650_8] INFO n.f.g.s.d.b.BangleJSDeviceSupport - Sending intent: Intent { act=android.intent.action.VIEW cat=[android.intent.category.DEFAULT] dat=spotify:track:5QEFFJ5tAeRlVquCUNpAJY:play pkg=com.spotify.music }

  1. Spotify opens and it plays the track supplied as value to the "data"-key in (1.).

If it's possible to emulate the Bangle.js Gadgetbridge receiving the message in (2.) I think maybe you could test the code just as well without a Bangle.js. I've been browsing the GB code to try and understand how I could achieve this. I've come across the "ADD TEST DEVICE MANUALLY" debug option in the app - can that be used in some way?

> @Ganblejs, how would I go about trying this? Can you please give some example of how I could test it (besides looking at the code)? > > Thank you. Do you mean specifically what I mentioned in my last comment: >I've now noticed this doesn't behave as for other permissions and.... Or the PR in general? In case of the former I reproduce the bug on my end by: 1. giving all permissions when Bangle.js Gadgetbridge asks for them. 2. Closing Bangle.js Gadgetbridge and clearing it from recents. 3. starting Bangle.js Gadgetbridge again. 4. Bangle.js Gadgetbridge asks for permission to display over other apps even though it has already been granted that permission and the setting is still enabled on "app info" settings section -> advanced -> Display over other apps. In case of the latter, do you have a Bangle.js to test with yourself? EDIT: How it works: 1. The bangle sends a message to Gadgetbridge e.g. to start a track on spotify, coded in javascript: `Bluetooth.println(JSON.stringify({t:"intent", action:"android.intent.action.VIEW", category:"android.intent.category.DEFAULT", package:"com.spotify.music", data:"spotify:track:5QEFFJ5tAeRlVquCUNpAJY:play", target:"activity" }));` 2. Gadgetbridge receives it (GB Log): > 22:59:12.705 [Binder:3650_8] INFO n.f.g.s.d.b.BangleJSDeviceSupport - UART RX LINE: {"t":"intent","action":"android.intent.action.VIEW","category":"android.intent.category.DEFAULT","package":"com.spotify.music","data":"spotify:track:5QEFFJ5tAeRlVquCUNpAJY:play","target":"activity"} 3. Gadgetbridge bakes and sends the intent (GB Log): > 22:59:12.707 [Binder:3650_8] INFO n.f.g.s.d.b.BangleJSDeviceSupport - Sending intent: Intent { act=android.intent.action.VIEW cat=[android.intent.category.DEFAULT] dat=spotify:track:5QEFFJ5tAeRlVquCUNpAJY:play pkg=com.spotify.music } 4. Spotify opens and it plays the track supplied as value to the "data"-key in (1.). If it's possible to emulate the Bangle.js Gadgetbridge receiving the message in (2.) I think maybe you could test the code just as well without a Bangle.js. I've been browsing the GB code to try and understand how I could achieve this. I've come across the "ADD TEST DEVICE MANUALLY" debug option in the app - can that be used in some way?
Author
Contributor

I've written a Bangle.js app for testing some intents, mainly for spotify-actions for now. Other intent-messages can be implemented if it's needed. I've tested it on my Bangle.js 2 but I think it should work on a Bangle.js 1 as well.

It can be loaded to the watch here.

The code for the app can be reviewed here.

I've written a Bangle.js app for testing some intents, mainly for spotify-actions for now. Other intent-messages can be implemented if it's needed. I've tested it on my Bangle.js 2 but I think it should work on a Bangle.js 1 as well. It can be loaded to the watch [here](https://thyttan.github.io/BangleApps/?q=testintents). The code for the app can be reviewed [here](https://github.com/thyttan/BangleApps/blob/intents_test_app/apps/testintents/app.js).
Author
Contributor

Ping! @vanous. Just in case you weren't alerted to/didn't notice my latest comments. Fully understand if you're occupied with other things.

Ping! @vanous. Just in case you weren't alerted to/didn't notice my latest comments. Fully understand if you're occupied with other things.
Owner

Ping! @vanous. Just in case you weren't alerted to/didn't notice my latest comments. Fully understand if you're occupied with other things.

Hi, yes, i am aware but unfortunatelly i do not have either bangle nor spotify...

> Ping! @vanous. Just in case you weren't alerted to/didn't notice my latest comments. Fully understand if you're occupied with other things. Hi, yes, i am aware but unfortunatelly i do not have either bangle nor spotify...
Owner

I've written a Bangle.js app for testing some intents, mainly for spotify-actions for now. Other intent-messages can be implemented if it's needed. I've tested it on my Bangle.js 2 but I think it should work on a Bangle.js 1 as well.

It can be loaded to the watch here.

The code for the app can be reviewed here.

These examples are helpful. Can you please rebase this branch? Thank you.

> I've written a Bangle.js app for testing some intents, mainly for spotify-actions for now. Other intent-messages can be implemented if it's needed. I've tested it on my Bangle.js 2 but I think it should work on a Bangle.js 1 as well. > > It can be loaded to the watch [here](https://thyttan.github.io/BangleApps/?q=testintents). > > The code for the app can be reviewed [here](https://github.com/thyttan/BangleApps/blob/intents_test_app/apps/testintents/app.js). These examples are helpful. Can you please rebase this branch? Thank you.
Ganblejs force-pushed Intents from a653c18844 to f8102767e4 2022-08-07 23:15:08 +00:00 Compare
joserebelo reviewed 2022-08-07 23:19:35 +00:00
@ -2,6 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
Member

I think we should add this + the permission check on the default flavor, since there are for sure people using the F-Droid build with a Bangle.js

I think we should add this + the permission check on the default flavor, since there are for sure people using the F-Droid build with a Bangle.js
Author
Contributor

Makes sense.

I've however noticed that the permission check doesn't seem to work for this permission.

As stated before I rebased the PR re this:
I've now noticed this doesn't behave as for other permissions and like I want/expect it to. When launching "Bangle.js Gadgetbridge" the associated pop-up to this permission will always show, even if the the setting is enabled.

Makes sense. I've however noticed that the permission check doesn't seem to work for this permission. As stated before I rebased the PR re this: I've now noticed this doesn't behave as for other permissions and like I want/expect it to. When launching "Bangle.js Gadgetbridge" the associated pop-up to this permission will always show, even if the the setting is enabled.
Author
Contributor

I've moved it to the main AndroidManifest.xml now.

I've moved it to the main AndroidManifest.xml now.
Author
Contributor

Permission check is now working and present in the default flavor.

Permission check is now working and present in the default flavor.
@ -295,2 +295,2 @@
<string name="pref_summary_device_intents">Allow Bangle.js watch apps to send Android Intents, and allow other apps on Android (like Tasker) to send data to Bangle.js with the com.banglejs.uart.tx Intent.</string>
<string name="pref_summary_sync_calendar">Enables calendar alerts, even when disconnected</string>
<string name="pref_summary_device_intents">Allow Bangle.js watch apps to send Android Intents, and allow other apps on Android (like Tasker) to send data to Bangle.js with the com.banglejs.uart.tx Intent. Needs permission to display over other apps to work in the background.</string>
<string name="pref_summary_sync_calendar">Enables calendar alerts, even when disconnected</string>
Member

(nitpick) thre's an extra tab at the end of this line

(nitpick) thre's an extra tab at the end of this line
Author
Contributor

I've removed it now.

I've removed it now.
Ganblejs marked this conversation as resolved
Ganblejs reviewed 2022-08-07 23:39:54 +00:00
Ganblejs left a comment
Author
Contributor

As stated before rebasing:

I've now noticed this doesn't behave as for other permissions and like I want/expect it to. When launching "Bangle.js Gadgetbridge" the associated pop-up to this permission will always show, even if the the setting is enabled.

As stated before rebasing: I've now noticed this doesn't behave as for other permissions and like I want/expect it to. When launching "Bangle.js Gadgetbridge" the associated pop-up to this permission will always show, even if the the setting is enabled.
Ganblejs changed title from Bangle.js: Intents - extending functionality to WIP: Bangle.js: Intents - extending functionality 2022-08-08 00:20:13 +00:00
Author
Contributor

Added WIP tag since the I have to sort out the permission check for displaying over other apps. Or possibly rethink and do without it.

Could we instead have a boolean stored for checking if the user has clicked 'ok' to go to the settings-page before, maybe?

Added WIP tag since the I have to sort out the permission check for displaying over other apps. Or possibly rethink and do without it. Could we instead have a boolean stored for checking if the user has clicked 'ok' to go to the settings-page before, maybe?
Ganblejs closed this pull request 2022-08-08 00:35:39 +00:00
Ganblejs reopened this pull request 2022-08-08 00:35:54 +00:00
Ganblejs changed title from WIP: Bangle.js: Intents - extending functionality to Bangle.js: Intents - extending functionality 2022-08-14 19:54:28 +00:00
Author
Contributor

@vanous @joserebelo

I just removed the WIP tag and think the PR is ready to be merged or at least reviewed again. Getting permissions for displaying over other apps works as expected now.

@vanous @joserebelo I just removed the WIP tag and think the PR is ready to be merged or at least reviewed again. Getting permissions for displaying over other apps works as expected now.
Owner

Cool, i will look at it during the week. Can you please squash the commits and rebase on top of the master? I can also do it via the webinterface I believe...

Cool, i will look at it during the week. Can you please squash the commits and rebase on top of the master? I can also do it via the webinterface I believe...
Ganblejs force-pushed Intents from 0879e3d613 to 9c1b9d1e03 2022-08-14 20:53:10 +00:00 Compare
Author
Contributor

Squashed and rebased! Hopefully I did it correctly.

Squashed and rebased! Hopefully I did it correctly.
Ganblejs force-pushed Intents from 9c1b9d1e03 to 2ad14b9442 2022-08-16 12:30:29 +00:00 Compare
Ganblejs force-pushed Intents from 2ad14b9442 to 60c7f79366 2022-08-16 22:41:52 +00:00 Compare
Owner

OK, seems alright. The message to paint over other apps will be new for people and unexpected, but the message is clear, mentions Bangle and if people do not want that, it can be dismissed. I am merging it in now. 🤞

OK, seems alright. The message to paint over other apps will be new for people and unexpected, but the message is clear, mentions Bangle and if people do not want that, it can be dismissed. I am merging it in now. 🤞
vanous merged commit 60c7f79366 into master 2022-08-17 19:37:24 +00:00
Owner

And of course thank you @Ganblejs for all the work and testing!

And of course thank you @Ganblejs for all the work and testing!
Author
Contributor

Thank you and everyone else for helping out as well!

Thank you and everyone else for helping out as well!
Author
Contributor

Follow up PR: #2826

Follow up PR: #2826
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
3 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#2769
No description provided.