Bug 473881 - False detection of "background activity" for many Flatpak apps
Summary: False detection of "background activity" for many Flatpak apps
Status: RESOLVED FIXED
Alias: None
Product: xdg-desktop-portal-kde
Classification: Plasma
Component: general (show other bugs)
Version: 5.27.7
Platform: Fedora RPMs Linux
: HI normal
Target Milestone: ---
Assignee: Plasma Bugs List
URL:
Keywords: usability
Depends on:
Blocks:
 
Reported: 2023-08-29 06:31 UTC by Yevhen Popok
Modified: 2023-11-11 04:18 UTC (History)
5 users (show)

See Also:
Latest Commit:
Version Fixed In: 6.0
Sentry Crash Report:


Attachments
Screencast showing auto-close of Flatpak apps on Wayland and X11 sessions (2.97 MB, video/webm)
2023-08-29 06:31 UTC, Yevhen Popok
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Yevhen Popok 2023-08-29 06:31:13 UTC
Created attachment 161254 [details]
Screencast showing auto-close of Flatpak apps on Wayland and X11 sessions

SUMMARY
On Wayland session xdg-desktop-portal-kde  mistakenly detects that Flatpak app as running in the background. Then it shows "special" notification. With many popular Flatpak apps (e.g. org.libreoffice.LibreOffice, org.mozilla.firefox, com.google.Chrome) dialog appears right after program launch.
Notification has "Find out more" button. if the user clicks on it, a dialog will appear that will inform that app is running in the background so user need to either "Allow" it or "Force quit". If user simple closes this dialog, action "Force quit" will be chosen automatically and application will automatically close as well. 
After subsequent launches, the program will close automatically in a few second.
As  a workaround user needs to override "background" permission with some GUI (like "Flatseal") or command
flatpak permission-set background background org.mozilla.firefox yes
 

STEPS TO REPRODUCE (also attached screencast)
1. Login into Wayland session (easier to reproduce)
2. Install some application from Flathub
flatpak install flathub org.mozilla.firefox
3. Launch installed app
flatpak run org.mozilla.firefox
4. Few seconds after launch notice notification about "Background activity"
5. Click "Find out more" button
6. See dialog with a question about "Background activity" and buttons "Allow", "Force quit".
7. Close this dialog (application will be closed automatically)
8. Relaunch Flatpak application


OBSERVED RESULT
Application silently closes


EXPECTED RESULT
KDE Portal should not detect "Background activity for visible applications.
KDE Portal should not set "Background" permission if the user closes the dialog and does not select any action,

SOFTWARE/OS VERSIONS
Linux: Fedora 38 Kinoite
KDE Plasma Version: 5.27.7
KDE Frameworks Version: 5.109.0
Qt Version: 5.15.10

ADDITIONAL INFORMATION
As you can see from the screencast, on X11 session KDE Portal have far less false detects of "Background activity".
However if permission "Background" is set as denied, apps on X11 session will auto-close as well.

Related bugs:
https://bugs.kde.org/show_bug.cgi?id=466325
https://bugs.kde.org/show_bug.cgi?id=468805
https://github.com/flathub/org.libreoffice.LibreOffice/issues/249
Comment 1 David Edmundson 2023-10-10 10:07:24 UTC
I just re-installed a bunch of applications and the user experience is pretty bad. Gimp is throwing up warnings whilst it clearly has windows open because the IDs don't match.

I don't see why we should be inhibiting apps from running in the background on the desktop in the first place.  We don't have to do stuff just because Gnome pushes it. I would fully support removing this until a time where the situation works better.
Comment 2 Nate Graham 2023-10-10 14:28:38 UTC
Agreed. UX parity with non-flatpak apps is more important here IMO.
Comment 3 laubblaeser 2023-11-07 11:36:49 UTC
(In reply to David Edmundson from comment #1)
> I don't see why we should be inhibiting apps from running in the background
> on the desktop in the first place.  We don't have to do stuff just because
> Gnome pushes it. I would fully support removing this until a time where the
> situation works better.

I would be all in favour of this. The background activity popups are a reoccurring annoyance that I could absolutely do without, if possible. :)
Comment 4 Bug Janitor Service 2023-11-09 17:12:43 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/xdg-desktop-portal-kde/-/merge_requests/246
Comment 5 David Edmundson 2023-11-10 16:41:03 UTC
Git commit dbe20a183509465bb7b230cb1b7d31d1aed9fbe9 by David Edmundson.
Committed on 10/11/2023 at 17:40.
Pushed by davidedmundson into branch 'master'.

Default to allowing background applications without prompts

Flatpak tends to have a lot of applications with window IDs that do not
match the containment, particularly with X11 applications.

There is also the UX question of why we shouldn't an app run in the
background, KDE has support for systemtrays with both X11, and the FD.O
standard which most apps running in the background would populate.

This patch always returns "Allow once" when prompted by the daemon.

Whilst this might seem like a lazy solution, from what I can tell from a
lot of DBus montioring on Gnome, this is what they do too.

We can't just disable the portal implementation as disabling by the
config file doesn't work, but even if did we still want enableAutostart
to work.

I left the original code behind a configuration option in case we want
it for mobile.

M  +31   -26   src/background.cpp

https://invent.kde.org/plasma/xdg-desktop-portal-kde/-/commit/dbe20a183509465bb7b230cb1b7d31d1aed9fbe9