How to prevent "Unable to open MTP device" popups from opening?

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).


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


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.