Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TouchUtils with Android Emulator

Has anyone been able to successfully perform unit testing on the Android Emulator using methods offered by the TouchUtils class?
I'm able to get the test(s) to pass on my device but when I run the exact same test(s) (and test suite) on an emulator, any test using a TouchUtils methods always throws the following exception:

java.lang.SecurityException: Injecting to another application requires INJECT_EVENTS permission
at android.os.Parcel.readException(Parcel.java:1327)
at android.os.Parcel.readException(Parcel.java:1281)
at android.view.IWindowManager$Stub$Proxy.injectPointerEvent(IWindowManager.java:1196)
at android.app.Instrumentation.sendPointerSync(Instrumentation.java:902)
at android.test.TouchUtils.drag(TouchUtils.java:786)
at android.test.TouchUtils.dragViewTo(TouchUtils.java:633)
...

I've unlocked the keyguard and even ran other (non TouchUtils) test cases which have passed.
I do not have the @UiThreadTest applied nor am I running anything that requires code to run on the UI thread.
When I comment out the line that employs TouchUtils.dragViewTo(...) and put in a simple assert(true), the test runs and passes.

Any ideas?

like image 378
kwi wi Avatar asked Jan 13 '12 01:01

kwi wi


1 Answers

It happens if your phone is locked or there is some other Activity on the HomeScreen.

like image 74
Rajdeep Dua Avatar answered Oct 02 '22 03:10

Rajdeep Dua