android模拟器
开发环境搭建注意:
- 先以win环境为例
- 最好将adb加入环境变量参考链接:adb环境变量配置
- 在模拟器中打开开发者模式及usb调试
adb连接droid4x
droid4x不能在adb devices
命令中直接显示,需要先进行连接:
adb connect 127.0.0.1:53001
之后可以用adb命令对其进行操作
adb模拟对设备的简单操作
截屏
保存到SDCard:
adb shell /system/bin/screencap -p /sdcard/screenshot.png
保存到电脑
不能直接保存到电脑,可以将sd卡中的截屏pull到电脑上来
adb pull /sdcard/screenshot.png d:/screenshot.png
模拟输入
使用 adb shell input
命令,参考adb shell input
文中 adb 版本可能较老,我在自己电脑上运行时得到的目前的 adb shell input
命令的使用方法为:
usage: input ...
input text <string>
input keyevent <key code number or name>
input [touchscreen|touchpad] tap <x> <y>
input [touchscreen|touchpad] swipe <x1> <y1> <x2> <y2>
input trackball press
input trackball roll <dx> <dy>
adb对设备的复杂操作
多点触控
多点触控并不能通过简单的 input 命令进行模拟,目前的思路是通过 解析输入设备事件,得到输入事件规则,通过发送模拟事件的方式模拟。
具体参考两篇文章:
用adb shell cat /proc/bus/input/devices 命令得到输入设备:
我的droid4x得到的可输入设备有:
C:\Users\zhouy>adb shell cat /proc/bus/input/devices
I: Bus=0019 Vendor=0000 Product=0001 Version=0000
N: Name=”Power Button”
P: Phys=LNXPWRBN/button/input0
S: Sysfs=/devices/LNXSYSTM:00/LNXPWRBN:00/input/input0
U: Uniq=
H: Handlers=kbd event0
B: PROP=0
B: EV=3
B: KEY=100000 0 0 0
I: Bus=0019 Vendor=0000 Product=0003 Version=0000
N: Name=”Sleep Button”
P: Phys=LNXSLPBN/button/input0
S: Sysfs=/devices/LNXSYSTM:00/LNXSLPBN:00/input/input1
U: Uniq=
H: Handlers=kbd event1
B: PROP=0
B: EV=3
B: KEY=4000 0 0 0 0
I: Bus=0011 Vendor=0001 Product=0001 Version=ab41
N: Name=”AT Translated Set 2 keyboard”
P: Phys=isa0060/serio0/input0
S: Sysfs=/devices/platform/i8042/serio0/input/input2
U: Uniq=
H: Handlers=sysrq kbd event2
B: PROP=0
B: EV=120013
B: KEY=4 2000000 3803078 f800d001 feffffdf ffefffff ffffffff fffffffe
B: MSC=10
B: LED=7
I: Bus=0011 Vendor=0002 Product=0006 Version=0000
N: Name=”ImExPS/2 Generic Explorer Mouse”
P: Phys=isa0060/serio1/input0
S: Sysfs=/devices/platform/i8042/serio1/input/input3
U: Uniq=
H: Handlers=mouse0 event3
B: PROP=0
B: EV=7
B: KEY=1f0000 0 0 0 0 0 0 0 0
B: REL=143
I: Bus=0003 Vendor=80ee Product=0021 Version=0110
N: Name=”VirtualBox USB Tablet”
P: Phys=usb-0000:00:06.0-1/input0
S: Sysfs=/devices/pci0000:00/0000:00:06.0/usb1/1-1/1-1:1.0/input/input4
U: Uniq=
H: Handlers=mouse1 event4
B: PROP=0
B: EV=1f
B: KEY=1f0000 0 0 0 0 0 0 0 0
B: REL=140
B: ABS=3
B: MSC=10
I: Bus=0001 Vendor=80ee Product=cafe Version=0402
N: Name=”VirtualBox mouse integration”
P: Phys=
S: Sysfs=/devices/pci0000:00/0000:00:04.0/input/input5
U: Uniq=
H: Handlers=event5
B: PROP=0
B: EV=b
B: KEY=10000 0 0 0 0 0 0 0 0
B: ABS=3
I: Bus=0000 Vendor=6666 Product=0001 Version=0001
N: Name=”Droid4x Virtual PassThrough Input”
P: Phys=
S: Sysfs=/devices/virtual/input/input6
U: Uniq=
H: Handlers=sysrq rfkill kbd mouse2 event6
B: PROP=0
B: EV=f
B: KEY=420 0 30000 ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe
B: REL=140
B: ABS=4600000 0
其中:
- Power Button,关机
- Sleep Button,锁屏
- AT Translated Set 2 keyboard,键盘
- VirtualBox USB Tablet,vbox的usb共享接口(推测)
- VirtualBox mouse integration,vbox的鼠标自动捕获接口
- ImExPS/2 Generic Explorer Mouse,鼠标输入接口
- Droid4x Virtual PassThrough Input,droid4x的自定义接口
但在之后的实验中发现,在对droid4x进行getevent监听时,只有一个event再触发,那就是 Droid4x Virtual PassThrough Input 的event6,如图:
所以我推测,可能droid4x将所有的事件都封装在 Droid4x Virtual PassThrough Input里,如果是这样的话,具体的动作解析变得相当困难。
其他,关于修改deviceID,IMEI
查找了一些资料,修改deviceID和IMEI可以有手动更改文件的方式:
参考手动更改
也可以由程序更改:
参考程序更改中的第二个答案
另外,我还有个想法是可以采取拦截软件的 get 方法的方式,来模拟deviceID,IMEI以及版本号,具体实现方法还要在搜寻资料。
面临的问题
- droid4x模拟器兼容性和稳定性很好,但是很有可能对用户的event事件进行了封装处理,如果要模拟高级操作,event得解析将会有不少麻烦。
- IMEI和deviceID以及版本号模拟的处理方式还要进行深入的了解
- 目前还有其他不错的模拟器,还没有实验,如 Bluestacks,Visual Studio Emulator for Android,需要时间进行比较