Unable to capture Android phone (USB)

This is for discussing general topics about how to use VirtualBox.
Post Reply
HulkySulky
Posts: 29
Joined: 28. Jan 2020, 06:24

Unable to capture Android phone (USB)

Post by HulkySulky »

When I capture an Android phone (USB), the phone shows the question "Allow access to phone data ?". If I answer yes, the capture is lost, and the USB phone returns to the host.

I tried to setup a filter, but then it just goes into a loop, with the same steps :
- USB phone is captured by the VM
- phone asks me to allow
- I allow, and the VM loses the USB connection
- and a second later the cycle repeats : USB is captured, phone asks me to allow, I allow, USB capture is lost

Virtualbox 6.1.36
Host & guest : Debian 11
Phone : Samsung Galaxy S20FE
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: Unable to capture Android phone (USB)

Post by mpack »

Complex phones usually appear as composite devices, so don't define the USB filter too narrowly.

Can I ask why you need to connect a phone directly to your PC using USB? I have a Samsung phone (S10), which I access quite easily over home WiFi. E.g. installing the "Sweech" app on the phone gives me pretty much full access.
HulkySulky
Posts: 29
Joined: 28. Jan 2020, 06:24

Re: Unable to capture Android phone (USB)

Post by HulkySulky »

mpack wrote: I have a Samsung phone (S10), which I access quite easily over home WiFi. E.g. installing the "Sweech" app on the phone gives me pretty much full access.
Thanks, never heard of "Sweech", I'll try it.
mpack wrote: Can I ask why you need to connect a phone directly to your PC using USB?
It was more of a theoretical question, it's not a "need" per se, I can do without. I just noticed that I was unable to capture it from within a VM, and was wondering why.
mpack wrote:Complex phones usually appear as composite devices, so don't define the USB filter too narrowly.
I just removed everything from the filter, except Samsung's vendor ID (04e8). Same behavior (loop).
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: Unable to capture Android phone (USB)

Post by mpack »

Frankly, I'm of the opinion that managing any kind of physical interface from a virtual machine may be asking for trouble. That's why I almost never do it. I rely on networking APIs instead.
HulkySulky
Posts: 29
Joined: 28. Jan 2020, 06:24

Re: Unable to capture Android phone (USB)

Post by HulkySulky »

mpack wrote:Frankly, I'm of the opinion that managing any kind of physical interface from a virtual machine may be asking for trouble. That's why I almost never do it. I rely on networking APIs instead.
I agree, at least for smartphones, their many connection modes makes it tricky. But it's usually OK for printers, usb sticks and hard disk drives (although I prefer AirPrint for printers now, it works fine from within VMs).

Anyway, thanks for Sweech, a really nice software I've never heard of before.
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: Unable to capture Android phone (USB)

Post by mpack »

HulkySulky wrote:But it's usually OK for printers, usb sticks and hard disk drives
I have no way to know that those things are "usually OK". People only post here about the problem cases.

But in many of those cases a direct connection is neither necessary nor wise:
  • Printer sharing is a standard feature of modern OS's, there is simply no reason or benefit to connect the printer to one VM using a physical API - depriving the host plus every other VM of access.
  • USB sticks: can be accessed more reliably as shared folders, regardless the level of guest support for USB.
  • Hard disk drives: you can't directly access hard disk drives anyway. Shared folders is the only option here. If you meant "raw disk access" then again that is not direct access, you are still using a virtual controller, it's just that the drive is accessed at sector level instead of at file level. Raw disks will be slower than normal disks since they bypass caches, so again it is rarely beneficial to use them. The only valid scenarios I know about is when the disk is formatted using a filesystem the host OS doesn't support, or you intend to format the drive from inside the guest. In both scenarios the performance loss will be secondary.
HulkySulky
Posts: 29
Joined: 28. Jan 2020, 06:24

Re: Unable to capture Android phone (USB)

Post by HulkySulky »

Interesting thoughts,which prompted me to do some tests, and I have to say that I disagree on some points. Performance wise, capturing a USB HDD or USB stick is much better than using a shared folder.
mpack wrote: Hard disk drives: you can't directly access hard disk drives anyway.
Sorry, I meant USB HDD

So, I plugged a USB HDD, and did 3 tests : copy from HDD to host, copy from HDD to guest through a shared folder, and copy from HDD to guest through a USB capture.

I believe all tests have been done in similar conditions (I emptied RAM cache on both host and guest before each test).
Dataset is a folder of 34.000 files, totaling 13 Gib.
Hardware is a Dell XPS 13 with 3.2 USB, but HDD is a rather old USB 3.0 disk.
Both host and guest are Debian 11 with Gnome. Copy operations have been done with Nautilus, Gnome's file manager.

Test results :
  • Copy from USB HDD to host : 2'58"
  • Copy from USB HDD to guest through a shared folder : 5'12"
  • Copy from USB HDD to guest through a USB capture : 3'04"
So, capturing the USB HDD is way faster than using a shared folder. Performance is near the host's performance.
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: Unable to capture Android phone (USB)

Post by mpack »

I you review my comment on shared folders you should note that I said "more reliably", not "faster". Performance isn't a very important factor for me because I copy files so infrequently. I need it to work, but I don't always need it to work fast.

Also, I assume you refer to Guest Additions Shared folders (as indeed did I). But if I cared about performance I wouldnt be using that since that too is designed for infrequent convenience, not performance. Instead I would configure a true network share.
HulkySulky
Posts: 29
Joined: 28. Jan 2020, 06:24

Re: Unable to capture Android phone (USB)

Post by HulkySulky »

mpack wrote:Instead I would configure a true network share.
I set up a NFS share between the USB disk and the guest. Results are catastrophic : 9'00".
Now, there's maybe some fine tuning that could be done to get better performances, or maybe SMB/CIFS would perform better (I don't want to install Samba just for that test), but those methods are rather cumbersome to conveniently and quickly transfer files between a USB disk and a VB guest.

I did some additional tests, with 1 big 16 GiB file. It's interesting to note that all methods result in the same performance (e.g. guest additions shared folder, NFS shared folder, and USB capture), almost the same performance as natively on the host
mpack wrote:I you review my comment on shared folders you should note that I said "more reliably", not "faster".
What exactly makes you say that USB capture is not reliable ? I am using it to transfer files for over a decade now, and I never experienced any problem with it

For me, USB capture remains the "best" way to transfer data from a USB drive to a guest. By "best" I mean that it's very easy and convenient to set up, very fast in all circumstances, including with a bunch of small files, and, as far as I know, perfectly reliable. And unless I have some proof or some experience that it can be unreliable, I have no reason not to stick to it for data transfer.
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: Unable to capture Android phone (USB)

Post by mpack »

I don't really want to rehash USB discussions that I've had a zillion times before. Try Googling for "busy previous request site:forums.virtualbox.org", for coverage of just one common USB problem.
HulkySulky
Posts: 29
Joined: 28. Jan 2020, 06:24

Re: Unable to capture Android phone (USB)

Post by HulkySulky »

Interesting...

Like I said, transferring data through USB captured disks never caused me any trouble, and it's something I do quite often, and for many years now, so I'll just stick with it until I have a good reason not to.

I noticed that in all the links of your Google search (I opened the 10 first ones), the host OS is always Windows. Maybe a Linux host (which I use) is more reliable when it comes to USB captured disks.

Anyway, thanks for your time, it was an interesting read and I learned a few things along the way
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: Unable to capture Android phone (USB)

Post by mpack »

HulkySulky wrote: I noticed that in all the links of your Google search (I opened the 10 first ones), the host OS is always Windows.
MacOS users get it a lot too, perhaps more so than Windows users in recent years. I don't specifically recall it being a problem on Linux hosts, I'm not sure (*): but fundamentally it's a fact that USB does not allow sharing, therefore host and guest can't be using the same device at the same time using USB directly, and if you try then you'll get some kind of error response even if not worded per the above.

(*) Actually I do recall people trying to use USB-LPT adapters to talk to printers, and having problems because the host kernel started a printer queuing service. It's been a while though, since in 2022 a printer would have to be VERY old to offer an LPT port.
HulkySulky
Posts: 29
Joined: 28. Jan 2020, 06:24

Re: Unable to capture Android phone (USB)

Post by HulkySulky »

mpack wrote:therefore host and guest can't be using the same device at the same time using USB directly, and if you try then you'll get some kind of error response
Of course ! I am surprised you even mention that possibility to use the same device at the same time on both host and guest ! I was always talking about capturing a USB disk exclusively in the guest.

I never tried otherwise, and don't even see how this could be done. In Linux once the disk is captured by the guest it's automatically unmounted in the host (it still appears in lsusb results, but the device /dev/sdX is removed, thus the disk cannot be mounted in the host anymore). And it is automatically mounted in the guest once captured.

I have very few experience with other OSes, but I doubt that a USB disk can be mounted in both the host and guest at the same time.
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: Unable to capture Android phone (USB)

Post by mpack »

HulkySulky wrote:but I doubt that a USB disk can be mounted in both the host and guest at the same time.
I already said that it can't. But people often expect otherwise.

You seem to be keen to debate the ills of USB, but what I asked you to consider was: what is the upside of restricting access to a device one VM when that isn't necessary?

In the end, I have offered opinions based on my experience but you are of course entitled to manage your PC in your own way.
HulkySulky
Posts: 29
Joined: 28. Jan 2020, 06:24

Re: Unable to capture Android phone (USB)

Post by HulkySulky »

mpack wrote:what is the upside of restricting access to a device one VM when that isn't necessary?
I guess it depends on your workflow. My need is to plug a USB disk in order to transfer some data between that disk and a VM, and I have no need to access that same disk from another VM or from the host. So in that case, capturing the USB port has the following upsides :
  • It's convenient, quick and easy to do (no network or VB shares to configure)
  • And, per my tests, it's faster than through a share (at least with small files)
The only downside would be reliability issues, but as long as I never experienced that I can say that, in my setup at least, there's no downside to it.

Again, the use case here is that I don't need to access that particular USB disk from the host or from another VM. The reasoning would of course be different if I wanted to share the USB disk between several VMs and/or the host, in which case a shared folder would be the chosen solution.
Post Reply