Concept:
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).
Here's the except of the code that does the "heavy lifting":
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
}
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 I cannot send touch or cursor inputs to the virtual displays.
What Works:
adb shell input -d <display-id> tap <x> <y>
- Wireless Controllers
- Wireless Keyboards
What Doesn't Work:
- Wireless / Wired Mice (cursor hits the edges of the phone screen, never enters the Virtual Display / External Display screen)
- Touch (see screenshot)
What I've Tried:
The output of dumpsys display
reveals that the Virtual Displays all lack the touch VIRTUAL
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.
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.
It's worth noting that the Android 10 Desktop Mode Developer Setting DOES put the cursor into the external display instead of the internal display. This is what I'm trying to accomplish.
There appears to be a hidden Java API within Androids SDK:
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.
Any help would be appreciated here. The only other related threat to this one is here, and it was never solved: