Goal
I want to run an Android app (third-party), but not show it on the physical screen.
Conditions
- Have the complete system source code (AOSP)
- Have root permission
Attempts
- Try to create a virtual screen, and request the app to display on the virtual screen (the following code runs with
android.uid.system
.)
public static android.hardware.display.VirtualDisplay createDisplay(
Context context,
Surface surface,
String name,
int height,
int width,
int dpi
) {
DisplayManager displayManager = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
android.hardware.display.VirtualDisplay display = displayManager.createVirtualDisplay(
name, width, height, dpi, surface,
DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC |
DisplayManager.VIRTUAL_DISPLAY_FLAG_SECURE |
DisplayManager.VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY |
DisplayManager.VIRTUAL_DISPLAY_FLAG_PRESENTATION |
DisplayManager.VIRTUAL_DISPLAY_FLAG_ROTATES_WITH_CONTENT |
DisplayManager.VIRTUAL_DISPLAY_FLAG_TRUSTED |
DisplayManager.VIRTUAL_DISPLAY_FLAG_SUPPORTS_TOUCH |
/*DisplayManager. VIRTUAL_DISPLAY_FLAG_OWN_FOCUS*/ 1 << 14,
);
return display;
}
public static void startApplication(Context context, Display display, String packageName) {
Intent intent = context.getPackageManager().getLaunchIntentForPackage(packageName)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
ActivityOptions options = ActivityOptions.makeBasic()
.setLaunchDisplayId(display.getDisplayId());
context.startActivity(intent, options.toBundle());
}
But the app will show on the real screen.
Did I miss something?
What should I do to make the specified application only appear on the virtual display, not on the physical screen?
It's easy, to remove your app's surface from the Output layer.