title: Espresso - Perform action fails on fullscreen activity - InjectEventSecurityException
body: <p>I wasted two days trying to perform click action on a fullscreen activity.</p>
  
  <h1>Steps to reproduce</h1>
  
  <ol>
  <li>Create a new project in android studio using fullscreen activity code template  </li>
  <li><p>Write an espresso test for the activity to perform click</p>
  
  <pre><code>public class FullscreenActivityTest 
                extends ActivityInstrumentationTestCase2&lt;FullscreenActivity&gt; {
  public FullscreenActivityTest() {
      super(FullscreenActivity.class);
  }
  
  @Override
  protected void setUp() throws Exception {
      super.setUp();
      getActivity();
  }
  
  public void testClickingOnLayout() {
      onView(withId(R.id.fullscreen_content)).perform(click());
  }
  </code></pre>
  
  <p>}</p></li>
  <li>Run this test on emulator (any android version from ginger bread to lollipop).</li>
  </ol>
  
  <h1>Failure</h1>
  
  <pre><code>android.support.test.espresso.PerformException: 
  Error performing 'click' on view 'with id: com.example.espressodefect:id/fullscreen_content'
  ...
  Caused by: android.support.test.espresso.PerformException: 
  Error performing 'Send down montion event' on view 'unknown'.
  ...
  Caused by: android.support.test.espresso.InjectEventSecurityException: java.lang.SecurityException: 
  Injecting to another application requires INJECT_EVENTS permission
  </code></pre>
  
  <p>Full stack is <a href="https://gist.github.com/rpattabi/c8bff2e6556bbbeb65ad#file-espresso_fullscreen_click_error" rel="noreferrer">here</a>.</p>
  
  <h1>Tried</h1>
  
  <p>I have tried the following with no luck:</p>
  
  <ul>
  <li>No lock screen on the emulator. (also updated activity using <code>WindowManager.LayoutParams.FLAG_FULLSCREEN |               WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD)</code></li>
  <li>All animations turned off</li>
  <li>No on-screen keyboard, or anything overlayed on top of the app.</li>
  <li>Also followed instructions <a href="https://developer.android.com/tools/testing-support-library/index.html" rel="noreferrer">here</a> at developer.android.com</li>
  <li>JUnit3 and JUnit4 styles (AndroidJUnitRunner)</li>
  <li><code>&lt;uses-permission&gt;</code> for INJECT_EVENTS</li>
  </ul>
  
  <h1>TL;DR</h1>
  
  <p>In espresso test, performing actions work fine if I use non-fullscreen activity like the one created with blank activity. Same action on full screen fails.</p>
  
  <p>I am using Espresso 2.0 and support libraries.</p>
  
  <p>What am I doing wrong here?</p>
  
  <h1>Update</h1>
  
  <p>Espresso dev confirmed this as defect. Please see <a href="https://code.google.com/p/android-test-kit/issues/detail?id=140" rel="noreferrer">issue 140</a>.</p>