Skip to content

Commit aef1c48

Browse files
authored
Merge pull request simpligility#784 from dukescript/ForwardJDWP-Ps-Af
Use ps -Af when needed to locate the right process
2 parents 23d4eb3 + d849fc2 commit aef1c48

File tree

1 file changed

+31
-20
lines changed
  • src/main/java/com/simpligility/maven/plugins/android/standalonemojos

1 file changed

+31
-20
lines changed

src/main/java/com/simpligility/maven/plugins/android/standalonemojos/RunMojo.java

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -332,28 +332,11 @@ public void doWithDevice( IDevice device ) throws MojoExecutionException, MojoFa
332332
}
333333
if ( debugPort > 0 )
334334
{
335-
CollectingOutputReceiver processOutput = new CollectingOutputReceiver();
336-
device.executeShellCommand( "ps", processOutput );
337-
BufferedReader r = new BufferedReader( new StringReader( processOutput.getOutput() ) );
338-
int pid = -1;
339-
for ( ;; )
335+
int pid = findPid( device, "ps" );
336+
if ( pid == -1 )
340337
{
341-
String line = r.readLine();
342-
if ( line == null )
343-
{
344-
break;
345-
}
346-
if ( line.endsWith( info.packageName ) )
347-
{
348-
String[] values = line.split( " +" );
349-
if ( values.length > 2 )
350-
{
351-
pid = Integer.valueOf( values[1] );
352-
break;
353-
}
354-
}
338+
pid = findPid( device, "ps -Af" );
355339
}
356-
r.close();
357340
if ( pid == -1 )
358341
{
359342
throw new MojoFailureException( "Cannot find stated process " + info.packageName );
@@ -394,6 +377,34 @@ public void doWithDevice( IDevice device ) throws MojoExecutionException, MojoFa
394377
throw new MojoFailureException( deviceLogLinePrefix + "Unresponsive command", ex );
395378
}
396379
}
380+
381+
private int findPid( IDevice device, final String cmd )
382+
throws IOException, TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException
383+
{
384+
CollectingOutputReceiver processOutput = new CollectingOutputReceiver();
385+
device.executeShellCommand( cmd, processOutput );
386+
BufferedReader r = new BufferedReader( new StringReader( processOutput.getOutput() ) );
387+
int pid = -1;
388+
for ( ;; )
389+
{
390+
String line = r.readLine();
391+
if ( line == null )
392+
{
393+
break;
394+
}
395+
if ( line.endsWith( info.packageName ) )
396+
{
397+
String[] values = line.split( " +" );
398+
if ( values.length > 2 )
399+
{
400+
pid = Integer.valueOf( values[1] );
401+
break;
402+
}
403+
}
404+
}
405+
r.close();
406+
return pid;
407+
}
397408
} );
398409
}
399410

0 commit comments

Comments
 (0)