Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forward notifications to applications using UnifiedPush library #115

Merged
merged 1 commit into from
Dec 28, 2020
Merged

Conversation

p1gp1g
Copy link
Contributor

@p1gp1g p1gp1g commented May 31, 2020

… to theses apps

The app will only need to add these files to the project and enable a service. Then it is possible to register to gotify to receive notifications. Every time gotify receive a notification for a registered app, it will forward it (and pop the notification in the client app context)
Here is an example of a client app

@jmattheis
Copy link
Member

Hey there, thanks for your contribution.

As this is a pretty big feature, that may create a long lasting API. We first have to thoroughly discuss how this feature should be implemented and what it should support. Could you introduce the changes you made in terms of security, functionality, etc. That it is easier for us to understand the change and its possible drawbacks? The discussion may be done inside #29

@p1gp1g
Copy link
Contributor Author

p1gp1g commented Jun 1, 2020

OK, well on gotify side :
It adds one service and two classes :

  • the service is used for other apps to register, it creates a new app on the server if it needs to. Once an app is registered it saved the service to bind to notify, the app name and the sender uid (At this moment, the app token is registered, but it shouldn't, the same for the server, I will soon do a commit for this version of the app and an issue for the server). After this moment, only app with this uid will be considered as this one.
  • one database class, to register/unregister the apps
  • one class to bind to the registered service when a notification append

There is only one change in the original code, at "onMessage", it cheks if the appId is registered and if it is it sends the notification to the registered app instead of popping it.

On the client apps side:
There is a service to receive the notifications and pop it, and an activity to register.
During the registration, the uid of gotify is saved and only app with this uid will be trust as gotify. It also receive the url and the token (if some app want to send the notification directly, would be nice)

If you have a specifique question (and you probably will ^^), I'd be glad to answer

@jmattheis
Copy link
Member

Alright, thanks. I'll have a look at this later, this may take a little time to understand this as a whole (:.

@p1gp1g
Copy link
Contributor Author

p1gp1g commented Jun 1, 2020

Yes no problem. You should also have a look on "gotification tester" mention before. Tell me if you want to talk via irc/riot/other for some details

@jmattheis
Copy link
Member

Yeah, I may come back to this offer later, first I want to grasp the current implementation (:.

Copy link
Member

@jmattheis jmattheis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there, sorry that it took so long, but I'm currently pretty busy with my day job (:. Anyway, I added some questions in subcomments.

Currently, the "gotify-lib" and "gotifytester" repos are licenced with GPL-3, would it be possible to use MIT instead? (I don't want having different licences in Gotify). And, would you be ok, if both the repos would be migrated to the gotify organization?

app/src/main/java/com/github/gotify/service/Constants.kt Outdated Show resolved Hide resolved
// The app is registered with the same uid : we re-register it
// the client may need to create a new app in the server
if (db.strictIsRegistered(clientPackageName, clientUid)) {
Log.i("$clientPackageName already registered : unregistering to register again")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The user of the gotify-android app should manually grant permissions to other applications to receive these messages. Otherwise, this looks like any app can just intercept gotify messages, without the user knowing it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any app can register but not intercept messages. But it is a really good idea to grant permissions manually. We can do it with a notification maybe

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh yeah, thought you could subscribe to existing apps. A notification like. XX likes to receive applications from gotify. Allow, Deny sounds great.

// we only trust unregistered demands from the uid who registered the app
if (db.strictIsRegistered(clientPackageName, clientUid)) {
Log.i("Unregistering $clientPackageName uid: $clientUid")
deleteApp(clientPackageName)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should ever delete an application, maybe there is some important stuff in it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know, these apps aren't created manually but automatically. Maybe we should make it optionnal

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can ask the user for this too, something like: "App XX unregistered, delete the application with all its messages?"

@p1gp1g
Copy link
Contributor Author

p1gp1g commented Jun 21, 2020

Currently, the "gotify-lib" and "gotifytester" repos are licenced with GPL-3, would it be possible to use MIT instead? (I don't want having different licences in Gotify). And, would you be ok, if both the repos would be migrated to the gotify organization?

I'm OK for both. Maybe we should migrate before any further change?

@jmattheis
Copy link
Member

I've created https://github.com/gotify/android-connector and https://github.com/gotify/android-connector-template you could open pull requests to these repos. I'm not 100% sure about the names, but I think connector fits.

The android-connector should be an android library which we later can publish a maven central / something else that it can be included as dependency without copying too much code.

@p1gp1g
Copy link
Contributor Author

p1gp1g commented Jun 21, 2020

It will be a good idea to do a recursive git for the template in the same time. I was thinking of a name referring to gotify because it will be used in other apps and it can be the android lib name too (which is a good idea).
I'll change the app name in the same time. I used gotifycationtester as a ref to the app to test GCM push notification.

@jmattheis
Copy link
Member

What do you mean with

It will be a good idea to do a recursive git for the template in the same time

yeah, the lib itself can have gotify in its name, but on github this is already described by the organization f.ex gotify/android, I like to follow this pattern for the connector as well.

@p1gp1g
Copy link
Contributor Author

p1gp1g commented Jun 21, 2020

Ok, I understand :)
I meant to have a git clone in the git of the template
Should we rename GotifyMessengerService to GotifyRegisterService (which is more explicit I guess)?

@jmattheis
Copy link
Member

I think ConnectorService would be enough, with package it is then com.github.gotify.sevice.ConnectorService. Maybe we can also move all stuff related to the connector in a separate package named connector.

app/build.gradle Outdated
@@ -2,6 +2,8 @@ plugins {
id "com.diffplug.gradle.spotless" version "3.26.1"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you want to proceed with this PR, as there are still some todo comments inside the code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right about the TODO comments, they were there as a reminder for possible improvement.
To resume :

  • A function to force to unregister an app: I don't think I have even needed it during my tests. There is still a workaround if it is really needed: wiping app data.
  • As discussed, a notification to let the user to chose :
    • If we accept an app registration
    • If we delete the app on unregistration
  • Automatic notification deletion (like issue Feature Request: Automatically Delete Old Messages #138)
  • Implementing a special notification on URL change. As it happens very rarely, re-register an app is a good way to deal with it for the moment.

Should I delete the comments and we will write an issue as a feature request for these ? Implementing the notification for user acknowledge, and write a feature request for the others ? Something else ?

I'm committing the deletion of these lines for the moment

@sparchatus
Copy link

Hello there @p1gp1g
This looks like a cool addition and could possibly in the future serve as a push alternative to gcm by deploying it as a priv-app?

When looking at Firebase messaging they seem to prefer using broadcasts to services for sending messages to the application but I am not sure why they chose it. Are there particular reasons you chose service binding over broadcasts for message delivery? To make sure that only gotify can deliver messages one could also have the gotify app define a custom permission and the receiving app requiring said permission on the service/receiver.

@p1gp1g
Copy link
Contributor Author

p1gp1g commented Dec 18, 2020

This looks like a cool addition and could possibly in the future serve as a push alternative to gcm by deploying it as a priv-app?

That's exactly the idea :)

When looking at Firebase messaging they seem to prefer using broadcasts to services for sending messages to the application but I am not sure why they chose it. Are there particular reasons you chose service binding over broadcasts for message delivery? To make sure that only gotify can deliver messages one could also have the gotify app define a custom permission and the receiving app requiring said permission on the service/receiver.

I know, I am not sure why they did that. Activities do very well the job, that's why I used this :)

This still need a few things before being merged (notification control before allowing to register or delete an app, a page to see apps registered etc.). And help is welcome :)

I am also working on a system to get push notifications without push provider. It would be nice if we could use one lib for both system (then we need to change 2 things on the connector here: the registered service should not be hardcoded and the message received by registered apps should not be gotify specific). If that lib is generic enough, any new way to get push notifications will be able to use it.

PS: I've sent you a request on matrix

@p1gp1g p1gp1g changed the title Service to permit other app to register and forward the notifications… Forward notifications to applications using UnifiedPush library Dec 28, 2020
@p1gp1g p1gp1g changed the base branch from master to unifiedpush December 28, 2020 14:46
@jmattheis jmattheis merged commit 253ce0e into gotify:unifiedpush Dec 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants