Skip to content
Gianluca Boiano edited this page Jan 2, 2022 · 1 revision

Welcome to the android-udev-rules wiki

51-android.rules is a text file needed to detect and allow the usage of Android device on GNU/Linux distros.

This text file follows very basic commands.

For example "==" means, compare the left_value with the right value, if it is equal, then do the next thing to the right, if it is not equal, then go to the next line down.

Example

Let's show an example and have a look to the different fields:

# Nokia-3310 my super phone
ATTR{idVendor}=="13fe", ATTR{idProduct}=="6300", ENV{adb_user}="yes"

Basically a flow like this is processed:

  1. Is idVendor the same as 13fe? yes continue right, no go down
  2. Is idProduct the same as 6300? yes continue right, no go down. you can keep asking more with "=="
  3. You see only "=" which means save the value of "yes" in this location "adb_user".

Originally, back in 2011, the rules were simple, we only needed to say yes, we found it. Today, android devices are more complicated. Some have the basic features like in 2011, plus other features like fast boot, access the the internal directories, and more.

Why different ENV variables?

What happened then is other developers started adding more features to 51-android-rules Some added features went beyond what was expected of the original 51-android-rules, like

SYMLINK+="libmtp-%k", ENV{ID_MTP_DEVICE}="1", ENV{ID_MEDIA_PLAYER}="1"

To help reduce the confusion, an attempt some cleanup was made, some of it as best guess since we don't have all these phones to test with, and other developers have moved on and are no longer watching.

"adb_adb" tries to keep to the same as 2011, which is to add SYMLINK+=android_adb".

Some users want FAST too, so, "adb_fast" will do the same as "adb_adb" and also set "SYMLINK+=android_fast"

There is room for future expansion, since you can see some users added some very interesting additions, and some users wanted to help but did not really understand what was needed so they copied other code, so it may have errors. If you see errors, it is worth correcting it, since the more eyes that look at the code, the better chance of fixing errors. For example, I accidently included some test code "midi_user" for the fairphone because I read some information that the fairphone has midi too. I did not add the midi_user stuff at the bottom of the 51-android-rules file since I was not able to test the midi code. I do not have an android phone with midi, but if you have a phone with midi - we can try that - we just need to add some extra code at the bottom.

If some of the idVendor are confusing, just remember companies are bought and sold, and so they may have more than one idVendor. Also they may hire other companies to help. Looking at your example, it looks like Nokia has idVendor of 13fe, or 0421, or 2e04 which seems confusing.

Not just smart phones. Android rules can also apply to smart Android tablets, book readers (example amazon kindle), GPS devices (example Archos), hand-held payment devices (example castles), and car radios or smart panels if you know how/where to plug it in (example Audi), and other android devices.

For you to keep it simple, start with the basics. Read through, and follow the steps shown in JoesCat Documentation and focus on just adding "adb_adb" If the device you are looking at has fastboot, then you can use "adb_fast" which will add both "adb_adb" and "adb_fastboot". "adb_user" was something added because some contributions we are not sure of if it is normal adb, or fastboot, or if it is usable at all.

The "adb_user" was added later, and it adds a nice feature for users with more than one Android device - this will come in handy for midi_user since midi can sometimes be more than one device. If you have more than one Android device added you will see "dev/android[1,2,3,4,5....] for multiple devices and the last device plugged in as "/dev/android":

ls -l /dev/android*
lrwxrwxrwx 1 root root 15 Sep 12 11:04 /dev/android -> bus/usb/001/004
lrwxrwxrwx 1 root root 15 Sep 12 11:04 /dev/android7 -> bus/usb/001/004
lrwxrwxrwx 1 root root 15 Sep 12 10:34 /dev/android8 -> bus/usb/001/002

This is the important thing to know with using "adb_adb" and "adb_adbfast"... When your android device is enabled with DEBUG/DEVELOPER mode ON and then you plug in the device, you should see your device show up when you type:

ls -l /dev/android*
lrwxrwxrwx 1 root root 15 Sep 12 11:04 /dev/android_adb -> bus/usb/001/004

The "android_adb" is the important SYMLINK.

MTP

Another thing to keep in mind is you are sharing USB with another project that has many, many, more users (there are many more ordinary users than there are developers), that simply want to plug in their phone and fetch/save information to the phone - you will see those other rules in the same directory generally named 69-libmtp.rules. Please have a look to this project to try and keep your rules compatible with this project too.

Clone this wiki locally