title: How to send key events to a headless emulator in an instrumentation test?
body: <p>We are currently working on an instrumentation test suite which runs on our build server, but while the tests pass on a dev machine using a normal Android emulator, the builds fail on the build server since there we only run a headless emulator with the <code>-no-window</code> flag.</p>
  
  <p>The failure occurs when trying to invoke the <code>InstrumentationTestCase.sendKeys()</code> method to programmatically open the options menu. The error is:</p>
  
  <blockquote>
    <p>Permission denied: injecting key event from pid 646 uid 10026 to window Window{43d55100  paused=false} owned by uid 1000</p>
  </blockquote>
  
  <p>We then found out that there's a <code>INJECT_EVENTS</code> permission, but setting it in the manifest had no effect. In fact in the log we saw this output:</p>
  
  <blockquote>
    <p>Not granting permission android.permission.INJECT_EVENTS to package com.qype.radar (protectionLevel=2 flags=0x6644)  </p>
  </blockquote>
  
  <p>Does that mean this permission is useless?</p>
  
  <p>We also tried to let the instrumentation test app and the app under test share the same Linux user ID using <code>android:sharedUserId</code> and run in the same process (<code>android:process</code> -- we weren't sure if that was already the case), but still no luck.</p>
  
  <p>Does this mean it's currently impossible to run instrumentations which contain key events on a headless emulator, or are we missing something?</p>