-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExecEvent
149 lines (132 loc) · 4.07 KB
/
ExecEvent
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package com.hpe.exec;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.ArrayList;
import java.util.List;
/**
* @author syl 2017/04/19 14:00
*/
public class ExecEvent {
static String TAG = ExecEvent.class.getSimpleName();
private static List<ActionEvent> mActionEvents = new ArrayList<ActionEvent>();
private static List<ActionEvent> mActionEvents1 = new ArrayList<ActionEvent>();
final static StringBuffer inputbf = new StringBuffer("input:");
final static StringBuffer errorbf = new StringBuffer("error:");
static List<String> eventinfo = new ArrayList<String>();
public static List<String> getEventinfo() {
return eventinfo;
}
public static void setEventinfo(List<String> eventinfo) {
ExecEvent.eventinfo = eventinfo;
}
public static StringBuffer getInputbf() {
return inputbf;
}
public static StringBuffer getErrorbf() {
return errorbf;
}
public static void main(String[] args) throws IOException,
InterruptedException {
String cmd = "adb shell getevent -l";
execADBInput(cmd);
execADBError(cmd);
// new ActionUtils(mActionEvents).resolveAction();
// new Thread(new Runnable() {
//
// @Override
// public void run() {
// System.out.println("gospel:::" + getInputbf());
// }
// });
}
public static String execADBInput(String cmd) throws IOException,
InterruptedException {
System.out.println("**my getevent, cmd:" + cmd);
final Process process = Runtime.getRuntime().exec(cmd);
printMessageInput(process.getInputStream());
/*
* the exit value of the process. By convention, <code>0</code>
* indicates normal termination.
*/
int value = process.waitFor();
System.out.println("**my adb return" + value);
// return printMessageInput(process.getInputStream());
return inputbf.toString();
}
public static String execADBError(String cmd) throws IOException,
InterruptedException {
final Process process = Runtime.getRuntime().exec(cmd);
printMessageError(process.getErrorStream());
/*
* the exit value of the process. By convention, <code>0</code>
* indicates normal termination.
*/
int value = process.waitFor();
System.out.println("**my adb return" + value);
return errorbf.toString();
}
private static void printMessageInput(final InputStream input)
throws IOException, InterruptedException {
new Thread(new Runnable() {
public void run() {
Reader reader = new InputStreamReader(input);
BufferedReader bf = new BufferedReader(reader);
String line = null;
try {
int i = 0;
while ((line = bf.readLine()) != null) {
i++;
// System.out.println("Input" + i + "-" + line);
inputbf.append("\n" + i + "- " + line);
// eventinfo.add(line);
ActionEvent event = ActionUtils.parseFromString(line,
System.currentTimeMillis());
if (event != null) {
// Logger.i(TAG, "event:" + event);
System.out.println(TAG + ": event:"
+ event.getStr());
mActionEvents.add(event);
// create script
new ActionUtils(mActionEvents).resolveAction();
}
if (event != null
&& event.getActionType().equals(
ActionType.PRESS_UP)) {
// Message msg = MessageHelper
// .createActionEventListMessage(mActionEvents);
// Server.getInstance().getSender()
// .sendCommandAsyn(msg);
mActionEvents.clear();
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();
// return inputbf.toString();
}
private static void printMessageError(final InputStream input)
throws IOException, InterruptedException {
new Thread(new Runnable() {
public void run() {
Reader reader = new InputStreamReader(input);
BufferedReader bf = new BufferedReader(reader);
String line = null;
try {
int i = 0;
while ((line = bf.readLine()) != null) {
i++;
System.out.println("Error" + line);
errorbf.append("\n" + i + "-" + line);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();
}
}