Question

I am working on a tool to identify widgets within an android app, and display their properties when clicked upon. I have created a standalone tool that can successfully do this, but I am having issues in converting the standalone tool into an eclipse plugin, which will be necessary to package into our final product.

The way that the tool operates is that first, a transparent overlay application is run on the emulator. This application gathers the coordinate of a screen press by the user and writes it to the Android log. Then, the application to be tested is started on the emulator.

Adb logcat is piped as standard input into a monkeyrunner script which handles the widget identification. In real time, the monkeyrunner script parses the logcat input for the coordinate press information. The monkeyrunner script uses AndroidViewClient (https://github.com/dtmilano/AndroidViewClient ), a tool which can list all of the View objects on a screen and their properties. Using the coordinate press information, the View from the list of Views which has the correct coordinate properties is singled out, and its properties are printed out.

The issue(s) that I am having stem from attempting to handle the piping of logcat output to the monkeyrunner script within the context of eclipse/java. If I run adb logcat and monkeyrunner in separate, concurrent processes, and transfer logcat's InputStream to monkeyrunner's OutputStream, there seems to be some locking issue, as monkeyrunner never receives the coordinate information as input. I tried putting the stream handlers in separate threads as well, but this had no effect.

Since concurrent processes can sometimes be a source of problems, I thought to read from logcat directly within monkeyrunner, thereby only having one main process. Within monkeyrunner, once a connection is established with the emulator, it is possible to open an adb shell on it (https://developer.android.com/tools/help/MonkeyDevice.html#shell). Logcat is a pretty common adb command, but when I run device.shell("logcat"), it fails with

    [main] [com.android.chimpchat.adb.AdbChimpDevice] Error executing command: logcat

and

    [main] [com.android.chimpchat.adb.AdbChimpDevice]com.android.ddmlib.ShellCommandUnrespo‌​nsiveException – 

Unfortunately, my google skills have not been able to find me a solution to this problem.

Was it helpful?

Solution

Well, I guess this is what you are looking for:

#! /usr/bin/env monkeyrunner
import time
import subprocess

# Imports the monkeyrunner modules
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice, MonkeyImage

# Connects to the current device, returning a MonkeyDevice object
device = MonkeyRunner.waitForConnection()

p = subprocess.Popen([ "adb", "logcat", "TEST:V", "*:S" ], shell=False,
        stdout=subprocess.PIPE)
i = 0
while True:
    device.shell("log -t TEST This is line %d" % i)
    i += 1
    print p.stdout.readline()
    time.sleep(1)

a monkeyrunner script that connects to the device, writes and also reads the logcat.

BTW, I'm glad to hear you found AndroidViewClient useful.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top