@@ -33,11 +33,11 @@ public class JsDebugger
33
33
private static native void processDebugMessages ();
34
34
35
35
private static native void enable ();
36
-
36
+
37
37
private static native void disable ();
38
-
38
+
39
39
private static native void debugBreak ();
40
-
40
+
41
41
private static native void sendCommand (byte [] command , int length );
42
42
43
43
private final Context context ;
@@ -51,9 +51,9 @@ public class JsDebugger
51
51
private static final String portEnvOutputFile = "envDebug.out" ;
52
52
53
53
private static int currentPort = INVALID_PORT ;
54
-
54
+
55
55
private static LinkedBlockingQueue <String > dbgMessages = new LinkedBlockingQueue <String >();
56
-
56
+
57
57
private static void enqueueMessage (String message )
58
58
{
59
59
dbgMessages .add (message );
@@ -63,24 +63,24 @@ public JsDebugger(Context context)
63
63
{
64
64
this .context = context ;
65
65
}
66
-
66
+
67
67
private static ServerSocket serverSocket ;
68
68
private static ServerThread serverThread = null ;
69
69
private static Thread javaServerThread = null ;
70
-
70
+
71
71
private static class ServerThread implements Runnable
72
72
{
73
73
private volatile boolean running ;
74
74
private final int port ;
75
75
private ResponseWorker responseWorker ;
76
76
private ListenerWorker commThread ;
77
-
77
+
78
78
public ServerThread (int port )
79
79
{
80
80
this .port = port ;
81
81
this .running = false ;
82
82
}
83
-
83
+
84
84
public void stop ()
85
85
{
86
86
this .running = false ;
@@ -94,7 +94,7 @@ public void stop()
94
94
e .printStackTrace ();
95
95
}
96
96
}
97
-
97
+
98
98
public void run ()
99
99
{
100
100
try
@@ -113,10 +113,10 @@ public void run()
113
113
try
114
114
{
115
115
Socket socket = serverSocket .accept ();
116
-
116
+
117
117
this .responseWorker = new ResponseWorker (socket );
118
118
new Thread (this .responseWorker ).start ();
119
-
119
+
120
120
commThread = new ListenerWorker (socket .getInputStream ());
121
121
new Thread (commThread ).start ();
122
122
}
@@ -127,13 +127,12 @@ public void run()
127
127
}
128
128
}
129
129
}
130
-
130
+
131
131
private static class ListenerWorker implements Runnable
132
132
{
133
133
private enum State
134
134
{
135
- Header ,
136
- Message
135
+ Header , Message
137
136
}
138
137
139
138
private BufferedReader input ;
@@ -142,20 +141,20 @@ public ListenerWorker(InputStream inputStream)
142
141
{
143
142
this .input = new BufferedReader (new InputStreamReader (inputStream ));
144
143
}
145
-
144
+
146
145
private volatile boolean running = true ;
147
-
146
+
148
147
public void run ()
149
148
{
150
149
Scanner scanner = new Scanner (this .input );
151
150
scanner .useDelimiter ("\r \n " );
152
-
151
+
153
152
ArrayList <String > headers = new ArrayList <String >();
154
153
String line ;
155
154
State state = State .Header ;
156
155
int messageLength = -1 ;
157
156
String leftOver = null ;
158
-
157
+
159
158
Runnable dispatchProcessDebugMessages = new Runnable ()
160
159
{
161
160
@ Override
@@ -196,7 +195,7 @@ public void run()
196
195
leftOver = line .substring (messageLength );
197
196
state = State .Header ;
198
197
headers .clear ();
199
-
198
+
200
199
try
201
200
{
202
201
byte [] cmdBytes = msg .getBytes ("UTF-16LE" );
@@ -237,32 +236,32 @@ public void run()
237
236
}
238
237
}
239
238
}
240
-
239
+
241
240
private static class ResponseWorker implements Runnable
242
241
{
243
242
private Socket socket ;
244
-
243
+
245
244
private final static String END_MSG = "#end#" ;
246
-
245
+
247
246
private OutputStream output ;
248
-
247
+
249
248
public ResponseWorker (Socket clientSocket ) throws IOException
250
249
{
251
250
this .socket = clientSocket ;
252
251
this .output = this .socket .getOutputStream ();
253
252
}
254
-
253
+
255
254
public void stop ()
256
255
{
257
256
dbgMessages .add (END_MSG );
258
257
}
259
-
258
+
260
259
@ Override
261
260
public void run ()
262
261
{
263
262
byte [] LINE_END_BYTES = new byte [2 ];
264
- LINE_END_BYTES [0 ] = (byte )'\r' ;
265
- LINE_END_BYTES [1 ] = (byte )'\n' ;
263
+ LINE_END_BYTES [0 ] = (byte ) '\r' ;
264
+ LINE_END_BYTES [1 ] = (byte ) '\n' ;
266
265
while (true )
267
266
{
268
267
try
@@ -271,7 +270,7 @@ public void run()
271
270
272
271
if (msg .equals (END_MSG ))
273
272
break ;
274
-
273
+
275
274
byte [] utf8 ;
276
275
try
277
276
{
@@ -282,7 +281,7 @@ public void run()
282
281
utf8 = null ;
283
282
e1 .printStackTrace ();
284
283
}
285
-
284
+
286
285
if (utf8 != null )
287
286
{
288
287
try
@@ -310,7 +309,6 @@ public void run()
310
309
}
311
310
}
312
311
313
-
314
312
int getDebuggerPortFromEnvironment ()
315
313
{
316
314
int port = INVALID_PORT ;
@@ -345,7 +343,7 @@ int getDebuggerPortFromEnvironment()
345
343
}
346
344
w = null ;
347
345
}
348
-
346
+
349
347
try
350
348
{
351
349
Thread .sleep (3 * 1000 );
@@ -354,7 +352,7 @@ int getDebuggerPortFromEnvironment()
354
352
{
355
353
e1 .printStackTrace ();
356
354
}
357
-
355
+
358
356
File envInFile = new File (baseDir , portEnvInputFile );
359
357
if (envInFile .exists ())
360
358
{
@@ -372,7 +370,7 @@ int getDebuggerPortFromEnvironment()
372
370
{
373
371
requestedPort = INVALID_PORT ;
374
372
}
375
-
373
+
376
374
w = new OutputStreamWriter (new FileOutputStream (envOutFile , true ));
377
375
int localPort = (requestedPort != INVALID_PORT ) ? requestedPort : getAvailablePort ();
378
376
String strLocalPort = "PORT=" + localPort + "\n " ;
@@ -449,7 +447,7 @@ private static int getAvailablePort()
449
447
return port ;
450
448
}
451
449
452
- static void enableAgent (String packageName , int port , boolean waitForConnection )
450
+ private static void enableAgent (String packageName , int port , boolean waitForConnection )
453
451
{
454
452
enable ();
455
453
if (serverThread == null )
@@ -460,7 +458,7 @@ static void enableAgent(String packageName, int port, boolean waitForConnection)
460
458
javaServerThread .start ();
461
459
}
462
460
463
- static void disableAgent ()
461
+ private static void disableAgent ()
464
462
{
465
463
disable ();
466
464
if (serverThread != null )
0 commit comments