3

We are using UIAutomator for automation.

To run UIAutomator test scripts we used to compile the scripts from command prompt by using either USB or Wifi adb and it will run on the android device.

UiAutomator scripts will come in jar format after compilation. We will push the jar in the device and we have trigger the test scripts. The command to start the test script in “adb shell uiautomator runtest TestPackage.jar”.

It is working with normal adb connection.

But in our case we have to initiate the test scripts without any adb connection.

So we tried by passing the commands programmatically in the device using this java code

        try {

        StringBuffer output = new StringBuffer();
        Process p = Runtime.getRuntime().exec(params[0]);
        BufferedReader reader = new BufferedReader(new InputStreamReader(
                p.getInputStream()));
        String line = "";
        while ((line = reader.readLine()) != null) {
            output.append(line + "\n");
            p.waitFor();
        }
    } catch (IOException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

After the execution we are getting the following exception:

java.lang.securityException : longMsg = You do not have android.permission.RETRIEVE_WINDOW_CONTENT required to call registerUITestAutomationService

If we run scripts from command prompt with adb connection it is working. But if we tried the command programmatically we are getting this exception.

We came to know that the above mentioned issue can be overcome in a rooted android device by enabling the RETRIEVE_WINDOW_CONTENT permission. But we want this scripts to run on a non-rooted setup.

Can anyone help me in explaining this security permission issue?

How can I resolve it?

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • I think that type of permission is only granted for system applications. Check this http://stackoverflow.com/a/13802178 some times you will get help . – Sree Jul 14 '15 at 11:28
  • I want to know that how come it s running with adb connection normally?? – Anbarasan Paulraj Jul 15 '15 at 19:14
  • 1
    Because different permissions are assigned if you run from `adb`. On the other hand, imagine what could happen if any app on the device could start UiAutomator tests. – Diego Torres Milano Jul 21 '15 at 22:14

0 Answers0