Skip to content

Add a banner to ask the user to disable battery optimization when Event cannot be resolved from Push#4845

Merged
bmarty merged 10 commits intodevelopfrom
feature/bma/batteryOptimization
Jun 16, 2025
Merged

Add a banner to ask the user to disable battery optimization when Event cannot be resolved from Push#4845
bmarty merged 10 commits intodevelopfrom
feature/bma/batteryOptimization

Conversation

@bmarty
Copy link
Copy Markdown
Member

@bmarty bmarty commented Jun 9, 2025

Content

When an Event cannot be resolved from Push, let the application render a banner in the room list to propose the user to disable battery optimization.

When battery optimization is disabled, it should help to resolve more events when a Push is received. The cost is a higher battery consumption. User always has the ability to revert the change by navigating to the system settings.

Draft as we're waiting for product decision and the wording of the banner may be updated (and must be added to Localazy).

Motivation and context

Improve Notification resolution and limit the risk of not shown notification because not resolve. In a separate PR we will ensure that a notification is always displayed when a not resolved Push is happening.

Closes #4611

Screenshots / GIFs

BatteryOptimization_0.mp4
BatteryOptimization_1.mp4

Tests

  • Have an unresolved event
  • Open the app
  • See the banner
  • Option 1: Close the banner: it should not be displayed again. From the application, clear the cache to be able to test it again
  • Option 2: click on "Yes, disable"
  • A system dialog is displayed (can depend on OS / device)
  • Option 1: click on "Deny"
  • The system dialog is gone and the banner is gone until the application is started again
  • Option 2: click on "Accept"
  • The system dialog is gone and the banner is gone until the battery optimization setting remains unchanged.

Tested devices

  • Physical
  • 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 bmarty requested a review from a team as a code owner June 9, 2025 13:26
@bmarty bmarty requested review from jmartinesp and removed request for a team June 9, 2025 13:26
@bmarty bmarty marked this pull request as draft June 9, 2025 13:28
Result.success(
requests.associateWith { Result.failure(ResolvingException("Unable to resolve event")) }
)
},
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The existing test was not really testing the notification resolver failure (the type is a Result of a Map of Result, so it's a bit confusing), but this change fixes it.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jun 9, 2025

📱 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/s24gUj

@codecov
Copy link
Copy Markdown

codecov bot commented Jun 9, 2025

Codecov Report

Attention: Patch coverage is 79.79798% with 20 lines in your changes missing coverage. Please review.

Project coverage is 80.30%. Comparing base (11c2467) to head (751f7e7).
Report is 60 commits behind head on develop.

Files with missing lines Patch % Lines
.../libraries/push/impl/store/DefaultPushDataStore.kt 0.00% 9 Missing ⚠️
.../push/impl/push/MutableBatteryOptimizationStore.kt 0.00% 4 Missing ⚠️
...libraries/push/impl/battery/BatteryOptimization.kt 88.23% 0 Missing and 2 partials ⚠️
.../push/impl/battery/BatteryOptimizationPresenter.kt 91.66% 0 Missing and 2 partials ⚠️
...ces/impl/notifications/NotificationSettingsView.kt 0.00% 1 Missing ⚠️
...mlist/impl/components/BatteryOptimizationBanner.kt 90.00% 0 Missing and 1 partial ⚠️
...ement/android/libraries/push/impl/di/PushModule.kt 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #4845   +/-   ##
========================================
  Coverage    80.29%   80.30%           
========================================
  Files         2140     2148    +8     
  Lines        56902    56986   +84     
  Branches      7158     7172   +14     
========================================
+ Hits         45688    45761   +73     
- Misses        8781     8787    +6     
- Partials      2433     2438    +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

Copy link
Copy Markdown
Member

@jmartinesp jmartinesp left a comment

Choose a reason for hiding this comment

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

Thanks for the changes! I added a few quick review comments.

@bmarty bmarty added the PR-Misc For other changes label Jun 10, 2025
@mxandreas
Copy link
Copy Markdown
Contributor

A couple of suggestions on the wording:

Notification tip

Notifications not arriving?

To be sure to receive all the notifications, it can help to disable the battery optimization for this application.

Disable battery optimization for this app, to make sure all notifications are received.

Yes, disable

Disable Optimization

Am I right that we do not directly check if the battery optimization is enabled, we derive this from the fact that there was an unresolved event? So in theory it could be that the battery optimization actually is already disabled and there was another reason why the event was unresolved?

@bmarty
Copy link
Copy Markdown
Member Author

bmarty commented Jun 12, 2025

Hello, @mxandreas , thanks for the feedback.

Am I right that we do not directly check if the battery optimization is enabled, we derive this from the fact that there was an unresolved event? So in theory it could be that the battery optimization actually is already disabled and there was another reason why the event was unresolved?

No, Element X also checks if the battery optimisation is already disabled. If battery optimization is already disabled, we do not show the banner. (code)

@bmarty bmarty added the Record-Screenshots Runs the 'Record Screenshots' CI job and adds a commit with any new screenshots found. label Jun 12, 2025
@github-actions github-actions bot removed the Record-Screenshots Runs the 'Record Screenshots' CI job and adds a commit with any new screenshots found. label Jun 12, 2025
@bmarty bmarty marked this pull request as ready for review June 12, 2025 16:21
@bmarty bmarty requested review from a team and jmartinesp and removed request for a team June 13, 2025 14:02
Copy link
Copy Markdown
Member

@jmartinesp jmartinesp left a comment

Choose a reason for hiding this comment

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

LGTM, thanks. Just a question about naming.


sealed interface BatteryOptimizationEvents {
data object Dismiss : BatteryOptimizationEvents
data object DoAction : BatteryOptimizationEvents
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

DoAction sounds way too generic IMO 😅 . Why not just DisableOptimizations? Even if we end up opening the app settings as a fallback for this I think it's fine.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ah yes, renamed to RequestDisableOptimizations. I wanted to use a common Event interface for the other banner, but I changed my mind and forgot to rename the data object.

@bmarty bmarty enabled auto-merge June 16, 2025 09:01
@sonarqubecloud
Copy link
Copy Markdown

@bmarty bmarty merged commit 8f94b4c into develop Jun 16, 2025
28 of 29 checks passed
@bmarty bmarty deleted the feature/bma/batteryOptimization branch June 16, 2025 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR-Misc For other changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add check/info to disable battery optimization to F-Droid-build's notification settings/troubleshooter

5 participants