Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENV{adb_user} or ENV{adb_adb} or other? #215

Closed
AKotov-dev opened this issue Sep 7, 2021 · 9 comments
Closed

ENV{adb_user} or ENV{adb_adb} or other? #215

AKotov-dev opened this issue Sep 7, 2021 · 9 comments

Comments

@AKotov-dev
Copy link

Hello, M0Rf30 (Gianluca Boiano). Thank you and the team for your useful and necessary work. Rules 51-android.rules work well, including with new smartphones.

I apologize in advance for my poor English, I write through an online translator. :)

I don't have a message about adding rules or an error, I only need your advice if you don't mind. For myself and other users inexperienced in udev, I studied the drawing (style) of the code in which you write rules and made an automatic rule editor for your 51-android.rules: https://github.com/AKotov-dev/areditor

This can be useful for emergency insertion of the necessary rule, if it is missing, since packages with distribution updates are not released as often as we would like.

It searches for and shows in the list of rules a device that is connected to USB. If the device is not found, it offers to insert a ready-made rule with a comment like:

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

The editor analyzes 3 main fragments of the rules:

  • Minimalistic (idVendor and ENV):
    ATTR{idVendor}==idVendor, ENV{adb_user}="yes"
  • Advanced (idVendor and idProduct):
    ATTR{idVendor}==idVendor, ATTR{idProduct}==idProduct, ...
  • Complex (idVendor!= block, then searches for idProduct inside it):
    ATTR{idVendor}!=idVendor ...
    ATTR{idProduct}==idProduct ...

I noticed that outside the GOTO/LABEL blocks you use ENV{adb_user}= "yes", and inside the GOTO/LABEL blocks - ENV{adb_adb}="yes" and some other combinations (ENV{adb_adbfast}="yes", SYMLINK+="android_adb").

Question: which ENV{adb_user}="yes" or ENV{adb_adb}="yes" (or something else ENV{???}) is it better to use it for automatic addition to the list of rules so that the smartphone/device is guaranteed to work/recognized?

For example: ATTR{idVendor}=="13fe", ATTR{idProduct}=="6300", ENV{?right here?}="yes"

Thank you in advance.

Sincerely,
Alex

@AKotov-dev
Copy link
Author

Hello, M0Rf30. In general, I have not yet found anything better than to select an environment variable from the list:

ENV{adb_adb}="yes"
ENV{adb_user}="yes"
ENV{adb_adbfast}="yes"
ENV{adb_user}="yes", SYMLINK+="android_adb"
ENV{adb_user}="yes", SYMLINK+="android_fastboot"

I don't know how much this is correct for various situations, but I'll leave it like this for now. Still, I would like to stick something universal in ENV{}.

I wish you and the team a successful development of your project android-udev-rules.

Sincerely,
Alex

@M0Rf30
Copy link
Owner

M0Rf30 commented Sep 9, 2021

Hi @AKotov-dev and thanks for your considerations.
This needs to be deep dived. So I've reopened the issue as a reminder to clean and refactor some working mechanisms. It's always the right time to put things in discussion.
Regards

@M0Rf30 M0Rf30 reopened this Sep 9, 2021
@AKotov-dev
Copy link
Author

OK, thanks. :)

@JoesCat
Copy link
Collaborator

JoesCat commented Sep 12, 2021

Hi @AKotov-dev,
@M0Rf30 version of 51-android rules is a much more up to date version of this:
http://www.joescat.com/linux/android_rules.html (created in 2011).

Basically 51-android rules is a text file. 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.

If we read your example above, what it means is:

# Nokia-3310 my super phone
ATTR{idVendor}=="13fe", ATTR{idProduct}=="6300", ENV{adb_user}="yes"
  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.

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.

To answer your question, you need to look at the bottom of 51-android rules.
"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.

@AKotov-dev
Copy link
Author

Hello @JoesCat,
Many thanks for the detailed explanation of the rules 51-android.rules.

No, no, no... The Nokia 13fe:6300 smartphone does not exist. I have given it solely to demonstrate the form of writing the rule, which is created by my editor. Moreover, I don't have a smartphone myself, because it's not safe to have a smartphone in Russia. For experiments, I take a smartphone from friends. :)

I think it will not be possible to take into account all the features of the devices in the editor, so I am only interested in adb/fastboot for now. An ordinary user is unlikely to enter the rules manually to use the additional features of the device.

Does your explanation mean that in the new 51-android.rules format from @M0Rf30, I need to focus exclusively on variables like ENV{adb_adb} and ENV{adb_fast}, and ENV{adb_fast} overlaps the functionality of ENV{adb_adb} (+fast), which means it is more preferable?

However...

# Symlink shortcuts to reduce code in tests above
ENV{adb_adbfast}=="yes", ENV{adb_adb}="yes", ENV{adb_fast}="yes"

May be ENV{adb_adbfast}=="yes" - is this what I need to use adb/fastboot with any devices? Or do we still assume that there are three main variables: ENV{adb_adb}, ENV{adb_adbfast} and ENV{adb_user} and they need to be separated and specified individually for each device, depending on the functionality of these devices? And then what about ENV{adb_user}?

p.s. I apologize for the large number of questions. I'm just trying to choose one of the many options... :)

@JoesCat
Copy link
Collaborator

JoesCat commented Sep 12, 2021

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 http://www.joescat.com/linux/android_rules.html
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.

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. I think it is this project: https://sourceforge.net/projects/libmtp/ so you need to try and keep your rules compatible with their project too.

@JoesCat
Copy link
Collaborator

JoesCat commented Sep 12, 2021

When DEBUG/DEVELOPER mode is "OFF", your android device should work with https://sourceforge.net/projects/libmtp/ and if not, it is a good idea to share information with them too so their project works better too. We all want our devices to work with libmtp too.

@AKotov-dev
Copy link
Author

Hi, @JoesCat.
Thank you for the comprehensive explanation. http://www.joescat.com/linux/android_rules.html - very good material to study.

In general, I left in my editor for the user to choose from the list:

  • Selecting an environment variable
    ENV{adb_adb}="yes" (as default)
    ENV{adb_fast}="yes" (as adb + fastboot)
    ENV{adb_user}="yes" (for other functions)

I think that's enough for him to start with. As the functionality of 51-android.rules expands, something else can be added. :)

About MTP... I am not familiar with this connection protocol in detail, but I have previously read several articles and reviews about it on various forums. The reviews are not too good, for example here (Russian): https://www.linux.org.ru/forum/desktop/13867008
Quote/translation:

How do you work with android devices that connect via the MTP protocol?  
In Kubuntu 16.04, the device data is detected and the data can be copied. But copying  
is extremely unstable. Then it ends with a copy error, then it hangs at all and does not  
output a list of files. And how do you work with this wonderful technology?

MTP pulls too many dependencies:
libmtp9
fuse
gvfs
gvfs-fuse
gvfs-backends

I don't want to say that this technology is somehow worse or better than others, but I just decided not to get involved. :)

To transfer files, I made myself an adbmanager: https://github.com/AKotov-dev/adbmanager . Among other things, it also has work with the SD-Card. Maybe it will also be useful to someone for experiments.

With respect,
Alex

@M0Rf30 M0Rf30 pinned this issue Jan 2, 2022
@M0Rf30
Copy link
Owner

M0Rf30 commented Jan 2, 2022

I reported these details here

Many thanks. I'm closing this. Happy New Year's Eve

@M0Rf30 M0Rf30 closed this as completed Jan 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants