Adb devices not detecting device from within a toolbox

Hi,

I have a toolbox with Android toolchain available to it, since my host has Android Studio installed. I can execute adb from within the toolbox, but no matter what I’ve tried, it does not detect my connected phone when I run adb devices (it just shows “List of devices attached” and then no devices after that).

In the developer setting of my phone, I’ve tried revoking USB debugging and re-plugging and along with changing the default USB configuration from “No data transfer” to “PTP”, which does result in the host showing a notification, but no change to the toolbox’s ability to see the device.

Can anyone make suggestions on how to get this working?

Thanks

Sounds like some kind of sandbox issue. Can you expose USB access from within your Flatpak environment?

Toolbox is a second Fedora installation running in a container, sharing the kernel of the host system, with network and home directory access. It is running as normal user, so access to devices is limited. After installing “lsusb”, you do get the list of usb devices, but mounting an usb storage device is (fortunately) not possible.

“toolbox” launches “podman” with a huge number of options. With podman you can “mount” an existing directory from the host system into the container, but whether you can do this via the toolbox program, I do not know. May be it’s better to start with a minimal Fedora virtual machine, adding enough software to run adb. With a VM (virt-manager), you can pass USB devices from host to VM.

Edit: Tested on a normal workstation, not immutable:

/mnt, /media and /run/user are passed from host to toolbox, so if you mount the phone before into the main system, the Android filesystem should be available. If adb does tricks with direct access to USB ports, I’m afraid you have no chance.

Edit2: looked into adb and found as Ubuntu example: “sudo adb devices”

“sudo” gives you the right to do what you want within the toolbox, but outside of the container, you’re not root, so access on hardware level to the USB device is prohibited.

Thanks for the response. One important thing I forgot to mention is that this all worked when I was running Silverblue (also immutable). Not sure if it’s a KDE thing, a Kinoite thing, or some other misconfiguration on my part.

Also I did think to try sudo after I posted, and sudo adb devices still shows nothing from within the toolbox.

Something I didn’t think of until now was trying within Android Studio, although I’m not sure how instructive that really would be given that Android Studio is a Flatpak. Anyway, it also doesn’t see the device.

I will continue playing with this when I get a chance, but if you have any further thoughts please let me know.

I found other posts like this one and when I followed the recommended approach, it worked like a charm!

The only mystery to me is how this worked for me on Silverblue considering I don’t recall doing any such setup (and my entire setup is formalized as scripts, so it’s even less likely I did anything special because I’d have captured it in my scripts). Anyway, I’m just super happy that this is working!

For reference, here is the script I added to my setup:

#!/bin/bash
set -euo pipefail

cat <<EOF | sudo tee /etc/udev/rules.d/51-android.rules > /dev/null
# Skip if not connected via USB
SUBSYSTEM!="usb", GOTO="android_usb_rules_end"

LABEL="android_usb_rules_begin"

# 18d1 is the vendor code for Google. See the output of lsusb with phone plugged in.
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ENV{adb_user}="yes"

# Enable device as a user device if found
ENV{adb_user}=="yes", MODE="0660", GROUP="adbusers", TAG+="uaccess"

LABEL="android_usb_rules_end"
EOF

sudo groupadd adbusers
sudo usermod -a -G adbusers $(whoami)