Can one Android application control another application through UI Automator?

I am trying to write an Android application / service that can be deployed to a target device. The application can be used as a hook for remote control of the target device. Starting with the Jelly Bean version, there is a UI Automator implementation that provides similar functionality. However, it seems that UI Automator can only be used through the ADB interface. An application running on a device cannot use UI Automator directly (???). I am trying to find a solution that can work without ADB help. For example, a hook can listen on a socket as a protobuf server. The client can send a command to the hook for remote control and the device. I looked at the source code of the Andorid SDK. It seems like the only way is to use the Android APIs. I am wondering if there is a better way?

+8
android accessibility uiautomator
source share
3 answers

You can run UiAutomator from the application, you just need to have a test jar on the device and provide permissions for your application.

In your application, you can simply call:

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

And your device will do everything that your UiAutomatorTestCase will do.

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"); 
+8
source share

You need an ADB connection (via WIFI or cable) to run the UiAutomator test cases if you do not have su permissions. With su permission, you can run uiautomator from the device itself.

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

+4
source share

You can remotely execute your code.

If your device is embedded, you can first connect your device to the machine and use adb tcpip 5555. This will redirect the listening port to 5555, and then you can execute your script on your computer, which will work on the device. just use adb -s shell

+1
source share

All Articles