编程连接和断开连接Android设备 [英] Programmatically Connect and Disconnect Android Device
问题描述
我需要找到一种方法,(使用的是Android应用程序)编程连接和从主机断开连接Android设备。
I need to find a way to (using an Android application) programmatically connect and disconnect an Android device from a host.
我使用的是Galaxy Nexus的。我的目标是把一切都尽可能接近股票的可能,尽管我已经启用的内核,为了查看这些详细的调试信息已经启用了手机root权限访问的/ proc / kmsg
(和shell命令的dmesg
)。
I am using a Galaxy Nexus. My goal is to keep everything as close to stock as possible, though I have already enabled verbose debug messages in the kernel and in order to view them have enabled root access on the phone to access /proc/kmsg
(and the shell command dmesg
).
我相信,有一种方法利用root访问权限做什么,我需要做的,但我所有的尝试都导致尼克斯。
I am certain that there is a way to leverage root access to do what I need to do, but all of my attempts have lead to nix.
- 惹
的/ proc /巴士/ USB
- 惹
的/ dev /巴士/ USB
- MTP / PTP之间切换(不能做编程)
- 制作了Android的USB小工具驱动到模块< - ???
- Mess with
/proc/bus/usb
- Mess with
/dev/bus/usb
- Change between MTP/PTP (unable to do programatically)
- Making the Android USB gadget driver into a module <- ???
我要揣摩如何做的名单上的最后一个对象,那么我将能够 rmmod的
和 insmod的
生成的 *阁
在我的应用程序,这会连接和断开手机。我不能确定这个方案虽然可行的。
I am going to try to figure out how to do the last object on the list, as then I would be able to rmmod
and insmod
the resulting *.ko
in my application and that would connect and disconnect the phone. I am unsure of the feasibility of this option though.
推荐答案
解决方案接近最后期限时,来了,所以我几乎可以肯定它不是做事情的最好方法,但它满足了我的要求。
Solution came when close to a deadline, so I am almost sure it is not the best way of doing things, but it met my requirements.
构建改装成内核(允许特定功能的挂钩)
Build Modded kernel (to allow hooking of particular function)
- 修改内核配置,以支持Kprobes的(设置为CONFIG_KPROBES Y)
- 删除从静态关键字的 android_setup()定义(驱动器/ USB /小工具/ android.c)
- 在构建一个内核
- Modify kernel config to support Kprobes (set CONFIG_KPROBES to Y)
- Remove "static" keyword from android_setup() definition (driver/usb/gadget/android.c)
- Build that kernel
编译内核模块(这给连接和断开的实际功能)
- 使用Kallsyms动态拉android_setup的绝对地址()
- 使用Kprobes的,勾android_setup()
- 设置了两个定时器来执行每一次android_setup()被调用
- 在第一定时器设置2秒钟从现在开始,第二套为2.005秒从现在
- 在两个定时器需要一个指向结构usb_gadget作为数据
- 在各自的回调函数,调用usb_gadget_connect()和usb_gadget_disconnect(),这迫使物理断开然后重新连接上,三星Galaxy Nexus的
构建应用程序
- 总得有一个根深蒂固的设备
- 在简单地做一个shell调用与SU特权 - insmod的MODULE_NAME。直到你调用rmmod的,该模块将强制器件进入枚举周期,断开并重新连接不断。
如果你有兴趣在重复这些结果,在这里阅读文件公布,并随时给我任何问题。
If you are interested in repeating these results, read the document posted here and feel free to send me any questions.
的https://docs.google.com/uc?export=download&id=0B9WchRkSOWwJbi10MGhLWUljT2s
这篇关于编程连接和断开连接Android设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!