title: Android 10 injecting inputs to External Display / Virtual Display
body: <p><strong>Concept:</strong></p>
  <p>I have an Android application written in Kotlin that simply launches an Android application on an external display. The display could be a AirServer, Miracast, Microsoft Connect, USB-OTG HDMI, USB-C HDMI, or a Simulated Secondary Display (see screenshot).</p>
  <p>Here's the except of the code that does the &quot;heavy lifting&quot;:</p>
  <pre><code>        val intent = packageManager.getLaunchIntentForPackage(info.id)
          val dm = recyclerView.context.getSystemService(Service.DISPLAY_SERVICE) as DisplayManager
          val displays = dm.getDisplays(DisplayManager.DISPLAY_CATEGORY_PRESENTATION)
  
          for (display in displays) {
              val options = ActivityOptions.makeBasic()
              options.launchDisplayId = display.displayId
              recyclerView.context.startActivity(intent, options.toBundle())
              break
          }
  </code></pre>
  <p>The applications start fine. See the screenshot, where I used it to launch Minecraft Pocket Edition to a Simulated Secondary Display (as if an external HDMI monitor was connected). The issue is that <strong>I cannot send touch or cursor inputs</strong> to the virtual displays.</p>
  <p><strong>What Works:</strong></p>
  <ul>
  <li><code>adb shell input -d &lt;display-id&gt; tap &lt;x&gt; &lt;y&gt;</code></li>
  <li>Wireless Controllers</li>
  <li>Wireless Keyboards</li>
  </ul>
  <p><strong>What Doesn't Work:</strong></p>
  <ul>
  <li>Wireless / Wired Mice (cursor hits the edges of the phone screen, never enters the Virtual Display / External Display screen)</li>
  <li>Touch (see screenshot)</li>
  </ul>
  <p><strong>What I've Tried:</strong></p>
  <p>The output of <code>dumpsys display</code> reveals that the Virtual Displays all lack the <code>touch VIRTUAL</code> parameter that the internal display has. I'm not sure if this means that the display itself doesn't support touchscreen input, or if it's simply not enabled.</p>
  <p>I tried forcing the application into the foreground, which made the apps detect keyboard and controller inputs, but the cursor was still locked to the internal display window.</p>
  <p>It's worth noting that the Android 10 Desktop Mode Developer Setting <strong>DOES</strong> put the cursor into the external display instead of the internal display. This is what I'm trying to accomplish.</p>
  <p>There appears to be a hidden Java API within Androids SDK:</p>
  <p><a href="https://github.com/aosp-mirror/platform_frameworks_base/blob/a4ddee215e41ea232340c14ef92d6e9f290e5174/services/core/jni/com_android_server_input_InputManagerService.cpp#L825" rel="noreferrer">https://github.com/aosp-mirror/platform_frameworks_base/blob/a4ddee215e41ea232340c14ef92d6e9f290e5174/services/core/jni/com_android_server_input_InputManagerService.cpp#L825</a></p>
  <p>I attempted to access this class via reflection and call setFocusedDisplay, but I kept getting ClassNotFound exceptions, even with the private API blacklist secure settings changed.</p>
  <p>Any help would be appreciated here. The only other related threat to this one is here, and it was never solved:</p>
  <p><a href="https://stackoverflow.com/questions/59125717/android-q-virtualdisplay-touch-input-events">Android Q VirtualDisplay touch input events</a></p>
  <p><a href="https://i.stack.imgur.com/dcCmD.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/dcCmD.jpg" alt="Example Virtual Display Usage" /></a></p>