automount: handle devices mounted twice (Android/MTP phones) instead of "Unable to open a folder"

Problem

Plugging in an Android phone over MTP makes unity-fallback-mount-helper show "Unable to open a folder for SAMSUNG Android — Object does not exist at path /org/gtk/vfs/mount/1".

Original error dialog (French locale)

gvfs first mounts the phone with no storage while the phone asks the user to allow access to its data. Once access is allowed, gvfs replaces that mount with a new one under the same mtp:// URI. The folder requested for the first mount no longer exists, so gtk_show_uri() fails (G_DBUS_ERROR_UNKNOWN_OBJECT). The original GMount object is still listed by the volume monitor, so checking for the mount alone does not detect it.

Launchpad bug: LP: #2175476

Changes

  • gsd-automount-manager.c
    • When opening the folder fails with a stale-mount error (G_DBUS_ERROR_UNKNOWN_OBJECT/METHOD/INTERFACE, G_IO_ERROR_NOT_FOUND/NOT_MOUNTED/CLOSED) on a non-native mount, or the mount went away, poll the URI (asynchronous enumeration, 1 s interval) for up to 10 s.
    • If the URI has content again, this is the "mounted twice" case: open the folder, and show a short explanation with Don't ask again / No / Yes. Otherwise, the existing "Unable to open a folder" dialog is shown, unchanged.
    • Registered devices (Yes): do not open immediately; wait until the URI has content (up to 60 s, silent on timeout), then open it once. Only one wait per URI, kept for 10 s after opening, because both mounts trigger an autorun.
  • gsd-automount-devices.[ch] (new): per-device choices stored by mount URI in $XDG_CONFIG_HOME/unity-settings-daemon/automount-devices.conf (Mode=wait|never-ask).
  • unity-automount-devices.c + .desktop (new): small "Delayed Device Opening" window listing the registered devices, to change the mode or remove a device.
  • Build: Makefile.am, po/POTFILES.in, debian/unity-settings-daemon.install (usr/share/applications).
  • po/fr.po: French translation of the new strings (can be dropped if translations only go through Launchpad).

Testing

  • Ubuntu 22.04, unity-settings-daemon 15.04.1+21.10.20220207-0ubuntu1 rebuilt with this patch, Samsung Galaxy Note20 (Android 13):
    1. Plug in, allow access after ~10 s: explanation shown (instead of the error), Yes saved, folder opened.
    2. Plug in again: no dialog, the folder opens once ~1 s after allowing access (second mount ignored).
    3. "Delayed Device Opening" lists the phone with "Wait for its content".
  • On ubuntu/devel: the patch applies cleanly and the changed files pass gcc -fsyntax-only -Werror=incompatible-pointer-types -Werror=implicit-function-declaration -Werror=int-conversion. A full build and run on the development release was not done.

Notes

  • debian/changelog is left to the maintainer/sponsor. Suggested entry: * automount: handle devices mounted twice (MTP phones) instead of showing "Unable to open a folder"; add a per-device choice and a "Delayed Device Opening" window (LP: #2175476)

🤖 Generated with Claude Code

Merge request reports

Loading
Loading