The best way to achieve this will be to install a server application on your own device, and have a client-based application on other devices. Then upon connection, detect the devices and connect to them using server-client channel that you will hold in the network.
This is the safest way, and the simplest way, otherwise USB won't allow much of permissions, such as executing any command (write commands are way too strict).
By inspecting the Android sources to find which module is generating the message (if the message is not prefixed with the module name). Once the module is known check if it provides some kind of notification that can be used.
The above code seems to be executed when activating and deactivating the host mode and calls the msm_otg_host_notify function when enabled by build configuration. So it might be useful to inspect this function.
But please understand that I don't have the time and interest to dig into this further (especially because it would also require to get the sources first).
I pointed you to directions that might help to solve the problem. But I'm not going to do the research for you.
Yes I tried but it only work when I plug in otg cable with usb device attached to it and enable manually otg inside app and enter app that detects it.Without usb device on otg cable it won't detect it!!!I used ACTION_USB_DEVICE_ATTACED with this app: How to Monitor USB Events on Android[^]
How to find modules that send messages inside kernel source?
I have found file called host_notifier.c inside /drivers/usb/otg/ inside kernel source!
There is also file called Kconfig which contains this:
# USB Host notify configuration
boolean "USB Host notify Driver"
depends on USB
Android framework needs uevents for usb host operation.
Host notify Driver serves uevent format
that is used by usb host or otg.
boolean "USB detailed log for debugging"
depends on USB
Add detailed log for debugging.