19

I often plug my Android device into the USB drive simply for charging purposes with no intention to use the filesystem (and with the screen off or with the USB settings in "charging only" mode, either of which prevent the phone from allowing a data connection to be made). When I do this, though, I often get a very large number of annoying pop-ups that look like the popup shown in the image below:

enter image description here

Ideally, there would be some way to configure the window manager to not display these pop-ups in the first place (without disabling automounting, so that I can still -- on occassion -- use the device as a filesystem without needing to mount manually, i.e. when the phone's USB setting is in "MTP" mode and the screen is unlocked). Failing that, it would be ideal if there were a simple command that I can use to kill all instances of this popup (without killing the rest of the window manager at the same time). Failing that, solutions to disable automounting of this specific device (without disabling all automounting) would be an acceptable solution.

Any suggestions on how to either prevent this popup from happening in the first place or to kill multiple instances of the popup in a single command?

For more context, I am using Ubuntu 14.04 LTS; I am not sure whether Gnome or Nemo is responsible for this error (I know that my "Home" directory shortcut icon invokes "nemo", but I am pretty sure that there are also Gnome-based apps on the system, there is a ~/.gnome and ~/.gnome2 directory, etc. so it could be Gnome).

5
  • Try this: Ignore the popup, then pull down the notification bar (which says it's "Connected as a media device") - if you have one, tap on "Ongoing" connection and switch from "MTP mode" to "PTP mode":
    – harrymc
    Commented Jan 20, 2017 at 18:59
  • 1
    The solution to your answer is here on the ubuntu stack exchange Commented Jan 20, 2017 at 19:01
  • 2
    Try also the solution in this thread. Also try sudo apt-get install mtp-tools mtpfs.
    – harrymc
    Commented Jan 20, 2017 at 19:07
  • These solutions do not work / address a different issue. Commented Jan 20, 2017 at 21:15
  • @MichaelAaronSafyan "These solutions do not work / address a different issue". With kde when I installed mtp-tools mtpfs it solved a similar issue... I didn't understand if you have tried the Harry's suggestion and it didn't work or if you just discarded it...a feedback can be useful to other users too...
    – Hastur
    Commented Jan 24, 2017 at 17:24

8 Answers 8

15
+100

So you have this:

Unable to mount Pixel

The file manager is presenting those error messages, which come from GVfs, which is relaying information from libmtp.

Preventing File Manager Error Popups

Unfortunately, I have not yet discovered a way to suppress error popups in the GNOME/MATE/Cinnamon file manager. Maybe someday, I'll look into the source code to see where the error can be turned off or intercepted.

Since I don't have an answer for this, let's move on to your next-best acceptable option, which is…

Closing File Manager Popups by Command

Here is a script that can be used to clear the popups on GNOME, MATE, and Cinnamon:

#!/bin/bash

function list_empty_windows() {
  wmctrl -lp | awk "{if(\$5==\"\"){print\$3,\$1}}"
}

function list_wm_pids() {
  ps aux | grep cinnamon | perl -pe 's/.*\+\s+(\d+)\s+.*/\1/'
  pidof nautilus | tr ' ' '\n'
  pidof caja | tr ' ' '\n'
  pidof nemo | tr ' ' '\n'
}

function list_popup_windows() {
  local empty_window_file=$(mktemp)
  local window_manager_pid_file=$(mktemp)
  list_empty_windows > "$empty_window_file"
  list_wm_pids | sort > "$window_manager_pid_file"
  join "$empty_window_file" "$window_manager_pid_file"
}

function main() {
  list_popup_windows | cut -d ' ' -f 2 | xargs -n1 -P100 wmctrl -ic
}

main

If you want an easy command to remember, these will close all the windows in your file manager and cause your desktop to restart your file manager:

  • GNOME: killall nautilus
  • MATE: killall caja
  • Cinnamon: killall nemo

Disabling Automounting of Google Pixel

There doesn't seem to be a way to remember to ignore only Google Pixel.

I don't recommend this, and I haven't tested this myself, but to single out Google Pixel, you might have to comment out vendor 18d1 product 4ee1 (Google Pixel) and vendor 18d1 product 4ee2 (Google Pixel debug) in the udev rules and hwdb.

You can find the records with this command:

grep -ri '18d1.*4ee[12]' /lib/udev

After commenting out the udev records of Google Pixel, you may need to restart your desktop environment, reboot, and/or run some combination of the following commands:

sudo udevadm hwdb --update
sudo udevadm control --reload-rules
sudo udevadm trigger

Again, this is untested, and I don't recommend this especially because in order to mount Google Pixel again, you'd have to undo the manual udev changes.


Explanation

According to /var/log/syslog, GNOME is making the error show up because the USB device disappeared on the second attempt to initialize it:

Jan 24 01:32:41 node51 kernel: [613604.065259] usb 3-2: new SuperSpeed USB device number 96 using xhci_hcd
Jan 24 01:32:41 node51 kernel: [613604.082734] usb 3-2: New USB device found, idVendor=18d1, idProduct=4ee1
Jan 24 01:32:41 node51 kernel: [613604.082739] usb 3-2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
Jan 24 01:32:41 node51 kernel: [613604.082741] usb 3-2: Product: Pixel
Jan 24 01:32:41 node51 kernel: [613604.082743] usb 3-2: Manufacturer: Google
Jan 24 01:32:41 node51 kernel: [613604.082745] usb 3-2: SerialNumber: XXXXXXXXXXXX
Jan 24 01:32:41 node51 kernel: [613604.083855] usb 3-2: Enable of device-initiated U1 failed.
Jan 24 01:32:41 node51 kernel: [613604.084154] usb 3-2: Enable of device-initiated U2 failed.
Jan 24 01:32:42 node51 org.gtk.vfs.Daemon[4988]: Device 0 (VID=18d1 and PID=4ee1) is a Google Inc (for LG Electronics/Samsung) Nexus 4/5/7/10 (MTP).
Jan 24 01:32:43 node51 org.gtk.vfs.GPhoto2VolumeMonitor[4988]: (process:5256): GVFS-GPhoto2-WARNING **: device (null) has no BUSNUM property, ignoring
Jan 24 01:33:34 node51 org.gtk.vfs.Daemon[4988]: PTP_ERROR_IO: failed to open session, trying again after resetting USB interface
Jan 24 01:33:34 node51 org.gtk.vfs.Daemon[4988]: LIBMTP libusb: Attempt to reset device
Jan 24 01:33:34 node51 org.gtk.vfs.Daemon[4988]: inep: usb_get_endpoint_status(): No such device
Jan 24 01:33:34 node51 org.gtk.vfs.Daemon[4988]: outep: usb_get_endpoint_status(): No such device
Jan 24 01:33:34 node51 org.gtk.vfs.Daemon[4988]: libusb_open() failed!: No such device
Jan 24 01:33:34 node51 org.gtk.vfs.Daemon[4988]: LIBMTP PANIC: Could not init USB on second attempt
Jan 24 01:33:34 node51 org.gtk.vfs.Daemon[4988]: ** (gvfsd:5151): WARNING **: dbus_mount_reply: Error from org.gtk.vfs.Mountable.mount(): Unable to open MTP device '[usb:003,096]'

In the sample above, GVfs through libmtp identified USB bus 003 device 096 as the Google Pixel device, but the Google Pixel device had already disconnected itself. The next time Google Pixel reconnects, Linux will have assigned a new device ID.

libmtp errors out because it's still trying to work with the device that disappeared. GVfs picks up the error and forwards it to GNOME Files or some other GNOME-based file manager.

Who's At Fault?

Based on what I've discovered, these have room for improvement:

libmtp

libmtp is probably the most responsible in causing this problem.

It should improve error handling when an MTP device is connected and suddenly disconnected. The error should only be passed if the device still exists. If the USB device doesn't exist, it's pointless to try resetting it.

Report issues to libmtp

Android

Android could improve its MTP implementation so that it doesn't disconnect immediately upon connecting to a computer.

Report issues to Android

Nautilus / Caja / Nemo

It would be nice if these software offered a preference to suppress error messages or display them in a less popup-y fashion.

Report issues to GNOME
Report issues to MATE Caja
Report issues to Linux Mint Nemo

4
  • 1
    This answer is very, very close (thanks for the suggestion concerning wmctrl). However, it turns out that the PID from the empty windows is one associated with none of the above but rather with the command "/usr/lib/x86_64-linux-gnu/cinnamon-settings-daemon/cinnamon-settings-daemon". However, what you gave me is enough to create a script that clears all the popup windows. Commented Jan 25, 2017 at 14:59
  • FYI, I've updated / edited your answer to replace your one-liner with a script that successfully closes the popup windows. Commented Jan 25, 2017 at 15:19
  • Here is relevant issue for libmtp
    – gmk57
    Commented Feb 3, 2021 at 10:57
  • You can also take a look at this workaround, but in my particular case it didn't help.
    – gmk57
    Commented Feb 3, 2021 at 11:11
9

I have a workaround for this on Nemo:

Go to Edit > Preferences > Behavior and on Media Handling uncheck "Automatically mount removeable media when inserted and on startup".

When you finish charging your phone you can reenable the option to resume the default behavior.

2
  • 2
    Thanks for this. With caja (Ubuntu MATE) you can do: Edit -> Preferences -> Media -> uncheck "Browse media when inserted" Commented Jan 2, 2019 at 3:47
  • And what if this auto-mount setting is already disabled in Caja?
    – basic6
    Commented Sep 17, 2022 at 18:18
1
sudo apt-get install mtp-tools mtpfs

Executing this command will install the necessary tools and the error won't appear. A complete reboot might be needed.

2
  • How is this supposed to help if the device is intentionally not in a mode that allows usage with MTP? [I'm not trying to use the device with MTP; rather, I'm trying to disable annoying notices/popups that appear whenever I simply want to plug-in the phone in order to charge] Commented Jan 22, 2017 at 5:28
  • 3
    @Logan: If you had read the comments on the post, you would have seen that this advice was already offered and did not help. To avoid such mistakes, it's a good idea to always read all existing answers and comments before answering.
    – harrymc
    Commented Jan 22, 2017 at 15:23
1

How to disable the pop-ups without disabling automounting

Ideally, there would be some way to configure the window manager to not display these pop-ups in the first place (without disabling automounting, so that I can still -- on occassion -- use the device as a filesystem without needing to mount manually, i.e. when the phone's USB setting is in "MTP" mode and the screen is unlocked).

Any suggestions on how to prevent this popup from happening in the first place

This specific popup, which can be very annoying for people like me who have flaky USB ports, is created by this code in GNOME-based DEs. It can be suppressed without modifying any automounting behavior by patching the source code of the file manager. Here are patches for nautilus:

diff --git a/src/nautilus-file-operations.c b/src/nautilus-file-operations.c
index cf88198a8..dbd7af71e 100644
--- a/src/nautilus-file-operations.c
+++ b/src/nautilus-file-operations.c
@@ -2605,22 +2605,22 @@ volume_mount_cb (GObject      *source_object,
     error = NULL;
     if (!g_volume_mount_finish (G_VOLUME (source_object), res, &error))
     {
-        if (error->code != G_IO_ERROR_FAILED_HANDLED &&
-            error->code != G_IO_ERROR_ALREADY_MOUNTED)
-        {
-            GtkWindow *parent;
-
-            parent = gtk_mount_operation_get_parent (GTK_MOUNT_OPERATION (mount_op));
-            name = g_volume_get_name (G_VOLUME (source_object));
-            primary = g_strdup_printf (_("Unable to access “%s”"), name);
-            g_free (name);
-            success = FALSE;
-            show_dialog (primary,
-                         error->message,
-                         parent,
-                         GTK_MESSAGE_ERROR);
-            g_free (primary);
-        }
+        // if (error->code != G_IO_ERROR_FAILED_HANDLED &&
+        //     error->code != G_IO_ERROR_ALREADY_MOUNTED)
+        // {
+        //     GtkWindow *parent;
+
+        //     parent = gtk_mount_operation_get_parent (GTK_MOUNT_OPERATION (mount_op));
+        //     name = g_volume_get_name (G_VOLUME (source_object));
+        //     primary = g_strdup_printf (_("Unable to access “%s”"), name);
+        //     g_free (name);
+        //     success = FALSE;
+        //     show_dialog (primary,
+        //                  error->message,
+        //                  parent,
+        //                  GTK_MESSAGE_ERROR);
+        //     g_free (primary);
+        // }
         g_error_free (error);
     }
 

caja:

diff --git a/libcaja-private/caja-file-operations.c b/libcaja-private/caja-file-operations.c
index 8676800e..bc203e20 100644
--- a/libcaja-private/caja-file-operations.c
+++ b/libcaja-private/caja-file-operations.c
@@ -2441,18 +2441,18 @@ volume_mount_cb (GObject *source_object,
    error = NULL;
    caja_allow_autorun_for_volume_finish (G_VOLUME (source_object));
    if (!g_volume_mount_finish (G_VOLUME (source_object), res, &error)) {
-       if (error->code != G_IO_ERROR_FAILED_HANDLED) {
-           char *name;
-           char *primary;
-
-           name = g_volume_get_name (G_VOLUME (source_object));
-           primary = g_strdup_printf (_("Unable to mount %s"), name);
-           g_free (name);
-           eel_show_error_dialog (primary,
-                         error->message,
-                         NULL);
-           g_free (primary);
-       }
+       // if (error->code != G_IO_ERROR_FAILED_HANDLED) {
+       //  char *name;
+       //  char *primary;
+
+       //  name = g_volume_get_name (G_VOLUME (source_object));
+       //  primary = g_strdup_printf (_("Unable to mount %s"), name);
+       //  g_free (name);
+       //  eel_show_error_dialog (primary,
+       //                error->message,
+       //                NULL);
+       //  g_free (primary);
+       // }
        g_error_free (error);
    }
 

and nemo:

diff --git a/libnemo-private/nemo-file-operations.c b/libnemo-private/nemo-file-operations.c
index 8b107db..dd7b5e9 100644
--- a/libnemo-private/nemo-file-operations.c
+++ b/libnemo-private/nemo-file-operations.c
@@ -2688,17 +2688,17 @@ volume_mount_cb (GObject *source_object,
    success = TRUE;
    error = NULL;
    if (!g_volume_mount_finish (G_VOLUME (source_object), res, &error)) {
-       if (error->code != G_IO_ERROR_FAILED_HANDLED &&
-                    error->code != G_IO_ERROR_ALREADY_MOUNTED) {
-           name = g_volume_get_name (G_VOLUME (source_object));
-           primary = g_strdup_printf (_("Unable to mount %s"), name);
-           g_free (name);
-           success = FALSE;
-           eel_show_error_dialog (primary,
-                          error->message,
-                          NULL);
-           g_free (primary);
-       }
+       // if (error->code != G_IO_ERROR_FAILED_HANDLED &&
+        //             error->code != G_IO_ERROR_ALREADY_MOUNTED) {
+       //  name = g_volume_get_name (G_VOLUME (source_object));
+       //  primary = g_strdup_printf (_("Unable to mount %s"), name);
+       //  g_free (name);
+       //  success = FALSE;
+       //  eel_show_error_dialog (primary,
+       //                 error->message,
+       //                 NULL);
+       //  g_free (primary);
+       // }
        g_error_free (error);
    }
 

These patches can be installed persistently on source-based distros like Gentoo. In my case, I disabled the pop-up in caja:

sudo su
mkdir -p /etc/portage/patches/mate-base/caja/
cd /etc/portage/patches/mate-base/caja/
vim disable-MTP-error-popup.patch # paste the patch for caja into an editor
emerge mate-base/caja

The pop-up can also be disabled on Ubuntu 22.04, but Ubuntu isn't a source-based distro in the same sense as Gentoo, so the patch would have to be reapplied after every upgrade:

sudo apt install build-essential fakeroot devscripts
sudo apt build-dep nautilus # requires deb-src entries in sources.list
apt source nautilus
cd nautilus-42.6/debian/patches/
vim disable-MTP-error-popup.patch # paste the patch for nautilus into an editor
echo disable-MTP-error-popup.patch >> series
cd ../..
DEB_BUILD_OPTIONS=nocheck debuild -b -uc -us # test suite of this package failed before any patching
sudo apt install ../nautilus_42.6-0ubuntu1_amd64.deb

After installing the patched package, to apply the changes, log out and log in again or kill the file manager's process, then open it again. This was sufficient for me:

pkill caja
0

One thing you can try is to change how Android handles the USB port on the device. Starting with Marshmallow (Android 6.0) the default setting for the USB port was for charging only and to change that you'd have to tap on the notification bar and then the notification to change it for other uses.
First thing you'll have to do is to enable Developer Mode.
To do this open Settings - About Phone, then scroll down until you see Build Number, then just tap that 7 times to enable Developer Mode.
You'll see a little message saying that you are now a developer once you've completed the steps in the right order.

Now with developer mode enabled you'll see a new menu item in the settings menu called 'Developer Options', tap on that then scroll down until you see USB Configuration, then tap on that.
You'll then be presented with a window where you can specify the default behavior of the USB port when you connect a cable to it. You'll have the choices of Charge, MTP, PTP, and any other protocols that your device supports.

0

a simpler fix for this is to set your phone to present to the computer as a midi device instead of mtp , ptp or anything else.

You might need android 8 , i can do this on my oneplus3t

This then stops nautilus getting involved at all but is quickly undone when you do want the file sharing.

0

FWIW on my phone (Galaxy S6) Dev' options is at: Settings; System; Advanced; Developer options and the default USB behavoiur is not shown but is accessible to change (to File transfer) under ‘Default USB configuration’. This then results in Nemo opening: ‘mtp://%5Busb%3A003,111%5D/’ ==>> smiles.

0

My bad I am noob for now and I can only account this for one specific environment. Other answers have covered good enough about different environments. Here is how you can disable this in LXDE desktop environment running on Lightdm desktop manager. This has been tested by me. I suffered the same problem when using Moto G5 Plus.

  1. Open up the File Manager (PCMan FM).
  2. Go to "Edit" -> "Preferences" in menu bar at the top.
  3. Go to "Volume Management".
  4. Uncheck,"Mount removable media automatically when they are inserted" and "Show available options for removable media when they are inserted".

You should not see that annoying useless dialog box again.

I think you get the idea where to go for to disable that dialog box in other GUI desktop environments :)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .