element-x-android icon indicating copy to clipboard operation
element-x-android copied to clipboard

Update UnifiedPush library

Open bmarty opened this issue 1 year ago • 18 comments

Content

Update UnifiedPush library

Motivation and context

Be up to date and let Renovate handle this in the future.

We will also benefit from improvement from the library, in particular the support for RAISE_TO_FOREGROUND added in https://github.com/UnifiedPush/android-connector/commit/7438c52c3f0ef2edba4c908c2cf796297aeb888c .

Screenshots / GIFs

Tests

  • Ensure that UnifiedPush notification are still working (still under test on my side)

Tested devices

  • [ ] Physical
  • [x] Emulator
  • OS version(s):

Checklist

  • [ ] Changes have been tested on an Android device or Android emulator with API 24
  • [ ] UI change has been tested on both light and dark themes
  • [ ] Accessibility has been taken into account. See https://github.com/element-hq/element-x-android/blob/develop/CONTRIBUTING.md#accessibility
  • [ ] Pull request is based on the develop branch
  • [ ] Pull request title will be used in the release note, it clearly define what will change for the user
  • [ ] Pull request includes screenshots or videos if containing UI changes
  • [ ] You've made a self review of your PR

bmarty avatar Mar 04 '25 17:03 bmarty

:iphone: Scan the QR code below to install the build (arm64 only) for this PR. QR code If you can't scan the QR code you can install the build via this link: https://i.diawi.com/3qTYjg

github-actions[bot] avatar Mar 04 '25 18:03 github-actions[bot]

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 80.40%. Comparing base (b926f5f) to head (beb7297). Report is 4 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #4358      +/-   ##
===========================================
- Coverage    80.40%   80.40%   -0.01%     
===========================================
  Files         2142     2142              
  Lines        56642    56642              
  Branches      7081     7081              
===========================================
- Hits         45545    45544       -1     
  Misses        8679     8679              
- Partials      2418     2419       +1     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

codecov[bot] avatar Mar 04 '25 21:03 codecov[bot]

I am testing that the upgrade do not break anything, and sadly I do not receive anymore push from ntfy, even when not using a matrix.org account.

The troubleshoot fails at the "Test push loopback":

image

Logs:

POST https://ntfy.sh/_matrix/push/v1/notify 
{"notification":{"event_id":"$THIS_IS_A_FAKE_EVENT_ID","room_id":"!room:domain","devices":[{"app_id":"im.vector.app.android","pushkey":"https://ntfy.sh/upMQ1D9W3MlzAD?up=1"}]}}
<-- 507 https://ntfy.sh/_matrix/push/v1/notify
{"code":50701,"http":507,"error":"cannot publish to UnifiedPush topic without previously active subscriber"}

Seems related: https://github.com/binwiederhier/ntfy/issues/649

bmarty avatar Mar 12 '25 16:03 bmarty

This may be because your ntfy didn't have any registration when it has received elemen-x request. And ntfy is a bit buggy during this state. This would be fixed with https://github.com/binwiederhier/ntfy-android/pull/97

You can try Sunup, it will use the default gateway (matrix.gateway.unifiedpush.org) or create a first registration on ntfy before doing the tests

p1gp1g avatar Mar 12 '25 17:03 p1gp1g

Testing again this morning, now the troubleshoot tests are OK, but I still do not receive push from the homeserver. When switching to Firebase it's working.

bmarty avatar Mar 13 '25 08:03 bmarty

MSC4173 would probably help here. The server may have rejected the push key due to the previous 507 error

You can try:

  • to remove the registration from ntfy (be sure to give it unrestricted background use, because of the bug quoted above) and try again
  • or try sunup

p1gp1g avatar Mar 13 '25 09:03 p1gp1g

I selfhost both ntfy and synapse

I built ntfy-android with https://github.com/binwiederhier/ntfy-android/pull/97 and https://github.com/binwiederhier/ntfy-android/pull/98 I built Element X with this patch based on the latest tag

  1. Upon installing I ran the the troubleshooting with my existing setup and it passed without issues as before
  2. Closed both apps from the foreground and sent a message, received instantly.
  3. Force closed Element X and cleared it's cache
  4. Sent another message, got the notification instantly too.
  5. Killed Element X and removed the topic from the ntfy android app
  6. Tried sending another message and obviously got nothing, but synapse logs still claimed to be trying to sending them to ntfy server (I guess this is a synapse/nfty server issue who are not communicating deletions and out of scope here)
  7. Opened Element X again and it automatically registered a new topic without any input.
  8. Run a troubleshoot without errores.
  9. Killed Element X again
  10. Sent another message, received without issues.

Eskuero avatar Mar 13 '25 14:03 Eskuero

Is there anything else missing or that I can test ? Been running the patch for a month without issues on notification receipts so on my clueless knowledge it seems ready to go.

Eskuero avatar Apr 09 '25 13:04 Eskuero

The current changes don't seem to work reliably on my end, sadly (element.io account).

  1. I switched Firebase to NTFY, it didn't seem to take effect until I restarted the app.
  2. Once restarted, I sent a few messages again from another account and I got one quite fast and the rest either were delayed a long time or didn't arrive at all.
  3. After a while no new notifications were received.

This device is charging and with the screen on, so Doze should not apply. The server is ntfy.sh, maybe I should change that.

The logs display a couple of timeouts, but otherwise just something like:

[https://ntfy.sh/xxxxxxl] Connection is active (failed=false, callCanceled=false, jobActive=true, serviceStarted=true

When a timeout happens, the service reconnects but no new notifications arrive. I might try with the changes proposed by @Eskuero above.

jmartinesp avatar Apr 10 '25 09:04 jmartinesp

The current changes don't seem to work reliably on my end, sadly (element.io account).

Can you try with Sunup, or with another ntfy server (eg. https://ntfy.adminforge.de/), and double check that you have allowed background usage without restrictions for ntfy

p1gp1g avatar Apr 10 '25 09:04 p1gp1g

With Sunup the notifications arrive, but they're severely delayed (30s) and for some reason they appear twice in the list of notifications 😓 .

With NTFY + the alternative server, I had the same problemas as before: some notifications being delayed, most not arriving at all. I also couldn't build a custom version of NTFY with the patches mentioned above, the versions are quite outdated and every time I fix a problem another one appears...

jmartinesp avatar Apr 10 '25 10:04 jmartinesp

I have the app already built with the patches in my fdroid repo https://repo.fromshado.ws/repo/ https://repo.fromshado.ws/repo/ntfy-android-fdroidrelease-fdroid.apk

If you would rather give another try at building the clean patchfile to apply is also here: https://github.com/Eskuero/nino_samples/tree/master/ntfy-android

And also is true that probably the ntfy.sh instance is putting some ratelimits which might harm testing. If you want I can give you access to my ntfy instance. Ping me at @eskuero:matrix.fromshado.ws

Eskuero avatar Apr 10 '25 10:04 Eskuero

With Sunup the notifications arrive, but they're severely delayed (30s) and for some reason they appear twice in the list of notifications 😓 .

This is probably not the best place to debug setups. There are a lot of reasons why a notification could be delayed (depending on the load on the server, if the client have history to fetch, if it can get the decryption keys, etc.). It also depends on your OS configuration, if it is in doze mode etc. When doing tests, you may figure out that sometimes the web client get its notification after the android client, sometimes the opposite. You 'd see the same thing with FCM too

p1gp1g avatar Apr 10 '25 11:04 p1gp1g

Can you try with version 3.0.9 ?

p1gp1g avatar Apr 24 '25 15:04 p1gp1g

Can you try with version 3.0.9 ?

Sure. Is there any bug fixed on the new version that may help with the encountered problem?

bmarty avatar May 02 '25 11:05 bmarty

Can you try with version 3.0.9 ?

Sure. Is there any bug fixed on the new version that may help with the encountered problem?

There was a bug that doesn't apply here, sorry for the ping. For the details, PushService can be used to replace the MessagingReceiver, but isn't used here and it didn't work correctly with SDK<33

p1gp1g avatar May 02 '25 11:05 p1gp1g

By the way, what is the encountered problem ? Is it the 507 response ?

p1gp1g avatar May 08 '25 06:05 p1gp1g

It may be better to use a resolutionStrategy than to exclude the transient dependency.

something like

configurations.all {
    resolutionStrategy {
        force(libs.tink)
        dependencySubstitution {
            substitute module('com.google.crypto.tink:tink-android') using module(libs.tink)
        }
    }
}

p1gp1g avatar May 20 '25 09:05 p1gp1g

Just for the record, I was able to get reliable push notifications working in NTFY by doing:

  1. Deleting every single topic in ntfy.
  2. Changing the push server to ntfy.adminforge.de.
  3. Switching to firebase, then back to ntfy in the notification settings.
  4. Checking the new server is used in ntfy (a new topic is created with the server name being part of it).

I have battery optimizations disabled on EXA, btw. With it enabled, notifications sometimes take some time to arrive.

jmartinesp avatar May 23 '25 14:05 jmartinesp

Thanks for the commit @jmartinesp !

We have decided to merge this PR and let users play with the nightly (that can be joined at https://appdistribution.firebase.dev/i/7de2dbc61e7fb2a6) and report any issue with UnifiedPush / ntfy.

If we got issues, we will revert this PR before the next release.

bmarty avatar May 26 '25 07:05 bmarty

Warnings
:warning:

gradle/libs.versions.toml#L23 - A newer version of androidx.compose:compose-bom than 2025.04.00 is available: 2025.05.01

:warning:

gradle/libs.versions.toml#L40 - A newer version of io.coil-kt.coil3:coil-test than 3.1.0 is available: 3.2.0

:warning:

gradle/libs.versions.toml#L42 - A newer version of com.bumble.appyx:testing-junit4 than 1.7.0 is available: 1.7.1

:warning:

gradle/libs.versions.toml#L43 - A newer version of app.cash.sqldelight:sqlite-driver than 2.0.2 is available: 2.1.0

:warning:

gradle/libs.versions.toml#L45 - A newer version of me.saket.telephoto:zoomable-image-coil than 0.15.1 is available: 0.16.0

:warning:

gradle/libs.versions.toml#L189 - The native library arm64-v8a/libopuscodec.so (from io.element.android:opusencoder:1.1.0) is not 16 KB aligned

:warning:

gradle/libs.versions.toml#L210 - A newer version of io.element.android:element-call-embedded than 0.9.0 is available: 0.11.1

Generated by :no_entry_sign: dangerJS against beb7297721797bc97470396aac26036d12d37c5b

ElementBot avatar May 26 '25 07:05 ElementBot