Ensure proper mail account removal
Description
Resolves a bug where apps like the mail client failed to receive account removal events while stopped, leading to stale data.
Technical details
Mail applications rely on account-related events (e.g., account removal) to keep their internal state synchronized with the system. Previously, the Account Manager used a custom broadcast to send account lifecycle events. This custom broadcast included the Intent.FLAG_INCLUDE_STOPPED_PACKAGES
flag, ensuring that applications would receive these events even when they were in a stopped state.
A later change removed this custom broadcast, and the mail app was updated to listen for standard system events instead. However, these standard broadcasts do not include the FLAG_INCLUDE_STOPPED_PACKAGES
flag. As a result, if the mail app is in a stopped state when an account is removed via system settings, it does not receive the event. This causes a desynchronized state where the app continues to display data for an account that no longer exists.
This fix reintroduces explicit broadcasts for account lifecycle events, including the necessary flag to ensure delivery to stopped packages.
Tests
manual:
- add an sso account from settings and turn on mail sync
- open mail app and verify you see your email from newly added account
- force-stop the mail app
- remove the sso account from settings
- verify the account is remove from mail app as well
(in build without this patch account will not be removed if the app is not running 'at-least in background')
Issues
see mail#3657
10 commandments of code review
Summary by CodeRabbit
-
New Features
- Account removal now triggers protected app-wide notifications so linked services and sync processes can react and clean up.
-
Chores
- Added and declared a signature-level permission to secure broadcasts for account event notifications, ensuring only authorized receivers get these messages.