Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can one Android application control another application via UI Automator?

I am trying to write an Android application/service which can be deployed on the target device. The app can be used as a hook to remotely control a target device. Starting from Jelly Bean release, there is the UI Automator implementation available, which provides similar functionality. However, it seems that UI Automator can only be used via ADB interface. Application running on the device cannot use UI Automator directly(???). I am trying to find a solution that can work without the help of the ADB. For example, the hook can listen on a socket as a protobuf server. The client can send command to the hook to remotely control and device. I looked into the Andorid SDK source code. It looks like the only way is to use android accessibility APIs. I am wondering if there is any better way?

like image 785
Zhichao Avatar asked Jun 06 '13 04:06

Zhichao


Video Answer


2 Answers

It is possible to run UiAutomator from an application, you just need to have your Test jar on the device and give your application su permissions.

From your application you can then just call:

uiautomator runtest Test.jar -c com.package.name.ClassName -e key value

And your device will perform whatever your UiAutomatorTestCase would perform.

Quick example:

Process rt = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(rt.getOutputStream());

os.writeBytes("uiautomator runtest Testing.jar -c com.hey.rich.CalculatorDemo" + "\n");
os.flush();
os.writeBytes("exit\n");
like image 121
tophernuts Avatar answered Oct 15 '22 05:10

tophernuts


You need ADB connection (over WIFI or Cable) to run UiAutomator test cases unless you have su permissions. With su permission you can run uiautomator from the device itself.

In UiAutomator test cases, you can implement socket, webSocket and some other communication protocols, so your test case will expose communication connection to the outside world and other devices can connect to it. In this case, you need ADB connection only once to run the test case, then you can disconnect it.

like image 29
Amir Avatar answered Oct 15 '22 06:10

Amir