1.adb shell getevent -t > camera.sh
2.操作Device 录入event,ctrl + V 结束
3.将camera.sh 转换成device 支持的脚本语言(java 代码 如下)
编写执行 camera.sh 的脚本 stress.sh
# stress.sh shell
#!/system/bin/sh
# Test Result
echo "***************start camera activity ***************"
#am start -e FactoryTest true -e camera-id 0 -a android.media.action.IMAGE_CAPTURE
am start -n com.android.camera/com.android.camera.Camera
sleep 6
TIMES=2
mtime=1
while true
do
echo "********************This is the $mtime camera switch stress*************"
. /data/bin/camera.sh
sleep 8
mtime=$(($mtime+1))
done
echo "result is $TEST_RESULT"
//Java 转换代码
package com.event;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
public class Event{
public static void parseEvent(String inFile,String outFile){
BufferedReader reader = null;
FileWriter fw = null;
BufferedWriter bw = null;
try {
System.out.println("start:" + inFile);
reader = new BufferedReader(new FileReader(inFile));
fw = new FileWriter(outFile);
bw = new BufferedWriter(fw);
String tempString = null;
int line = 1;
String separator = " ";
// 一次读入一行,直到读入null为文件结束
while ((tempString = reader.readLine()) != null) {
if (tempString.isEmpty() || tempString.contains("add")
|| tempString.contains("name:"))
continue;
String newLine = "sendevent";
String arrs[] = tempString.split(separator);
for (int i = 1;i < arrs.length;i++){
if (arrs[i].endsWith(":")){
newLine += separator;
newLine += arrs[i].substring(0, arrs[i].length()-1);
}else{
String hex = arrs[i];
//int vaule = Long.parseLong(hex, 16);
newLine += separator;
newLine += Long.toString(Long.parseLong(hex, 16));
}
}
// 显示行号
//System.out.println("line " + line + ": " + newLine);
line++;
bw.write(newLine);
bw.newLine();
bw.flush();
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (reader != null)
reader.close();
if (fw != null)
fw.close();
if (bw != null)
bw.close();
} catch (IOException e1) {
}
}
}
public static void main(String [] args){
String fileInArr[] = {
"E:/temp_data/shell/camera.sh",
};
String fileOutArr[] = {
"E:/temp_data/shell/out/camera.sh",
};
for (int i = 0;i<fileInArr.length;i++){
parseEvent(fileInArr[i],fileOutArr[i]);
}
}
}