-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
JNI Android Support on Unrooted devices #1164
base: master
Are you sure you want to change the base?
JNI Android Support on Unrooted devices #1164
Conversation
Integrated Android support for device relisting xloem#3 |
I'm happy to have this replace #874 or merge and rebase it too, whatever works better for maintainers and contributors. |
@xloem I'm not sure but one option could be to force push this onto #874 then the conversation history is maintained while adding a cleaner set of commits? I would be happy to have this replace that pull also. Primarily its amazing work you have made and it needs to get merged as has significant value. Also, I would very much be in a position to aid/maintain for testing purposes. Current identified issues(s):
|
For people who are interested in better Android support, please come here and post your review or success/fail testing results. Thanks. |
780b024
to
77321cc
Compare
77321cc
to
e6d0202
Compare
NOTE: |
Thanks for the rebasing work! For information, the maintainers typically rebase any PR locally when merging, regardless of Signed-Commits or not, so just ignore the GitHub warning about this (dunno how to turn it off). However, before this PR can be merged it should ideally be worked down to the smallest number of commits that makes sense, so e.g. without fixups commits. If there are multiple authors it can be correct to have their commits separated for credit attribution, but minor fixups of other people's commit can be amended in-place and commented in the commit message. |
- Fix `op_set_option()` Fix applying options to all new contexts
e6d0202
to
4c17b61
Compare
Now that we have libusb_init_context() in git master, it would be a good time to rebase this. The NO_DEVICE_DISCOVERY option should be set in the libusb_init_context() call. |
int linux_netlink_start_event_monitor(void); | ||
int linux_netlink_stop_event_monitor(void); | ||
void linux_netlink_hotplug_poll(void); | ||
#elif defined(__ANDROID__) | ||
void android_jni_hotplug_poll(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have an error here with NDK 25.2.9519653.
error: this function declaration is not a prototype
void android_jni_hotplug_poll();
^
void
Should here be added 'void' inside brackets?
void android_jni_hotplug_poll(); | |
void android_jni_hotplug_poll(void); |
#elif !defined(__ANDROID__) | ||
int linux_netlink_start_event_monitor(void); | ||
int linux_netlink_stop_event_monitor(void); | ||
void linux_netlink_hotplug_poll(void); | ||
#elif defined(__ANDROID__) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These function prototypes inside the header file are wrapped in a conditional. Should the functions itself in the 'libusb/os/linux_netlink.c' file be wrapped out to the same conditional?
I have these errors if build with NDK 25.2.9519653.
libusb/os/linux_netlink.c:94:5: error: no previous prototype for function 'linux_netlink_start_event_monitor'
int linux_netlink_start_event_monitor(void)
libusb/os/linux_netlink.c:155:5 error: no previous prototype for function 'linux_netlink_stop_event_monitor'
int linux_netlink_stop_event_monitor(void)
libusb/os/linux_netlink.c:397:6 error: no previous prototype for function 'linux_netlink_hotplug_poll'
void linux_netlink_hotplug_poll(void)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might consider removing the netlink file from the build entirely on line 37 of android/jni/libusb.mk, given android is an uncommon build target. I do not know netlink's potential role on rooted devices but it looks disabled as of now. Adding the proposed guards or changing build flags such that the condition is not an error would both also work.
Its unclear to me whats preventing this from merging. Can someone summarize the action items needed ? |
Need more reviews and tests. Another thing, as of now this PR has conflicts with the git repo which needs to be fixed. |
hello,I'm new here. Is there any Android demo using this branch? @CraigHutchinson @xloem |
Not entirely sure what sort of demo you mean. But the Libusb should work as per any other example as long as you provide the JNI for the context configurable iirc. |
@CraigHutchinson Thank you for your answer. I'm new to jni and I think need a sample program like this, where the author gets the file descriptor through usbmanager and passes it to jni, which works. Then I found your branch, and I was very interested in what you said about "to do the sdk calls within libusb itself." r = libusb_init(NULL); cnt = libusb_get_device_list(NULL, &devs); print_devs(devs); libusb_exit(NULL);
|
I only rebased @xloem work but yes that is looking nearly there. Check the original PR for details which is linked on this rebase key bit is this (which I hope you gathered)
I'm not at a PC nor working in this area for last year. As far as I recall the PR adds context options for setting these. It's upto your android code to choose where/how you get them but pass them in. |
@CraigHutchinson Thank you so much for your answer, I have read this today#874, hard for me to fully understand by now. But finally I found out that @xloem has added an example to his libusb-android codehere, the guy I mentioned last time also wrote ademo program for this example, just I didn't find and understand it yesterday. |
Rebase of work on #874:
This code implements connection and device listing on unrooted android devices, without requiring any user-provided java.
This PR is usable now 🎉
The java native interface library is used, which is always available when building on android, to do the sdk calls within libusb itself. The approach is modularised to aid expanding if new features are needed.
📓 Dispatching this request involves setting an action string on the intent for permission that the application can optionally subscribe to. The permission intent I dispatch has action string libusb.android.USB_PERMISSION.
The code only takes effect if the user provides their JNIEnv* or JavaVM* pointer via a new libusb option.