This isn't possible.
UiAutomator 2.0 relies on Instrumentation which is only available when you run your test using am instrument .... Regular (non-test) apps don't have access to Instrumentation.
Shell-based UiAutomator is similar. You execute tests using adb shell uiautomator runtest ... and UiAutomatorTestRunner takes advantage of the fact that it is running as the shell user to do things that normal apps don't have permission to do.
If you use Runtime#exec(..) to call either am instrument or uiautomator runtest, the command won't run as the shell user (it will use your application's uid), and will fail because it doesn't have the necessary permissions.
|