Changing primary display resolution programmatically

881 views Asked by At

I'm trying to change the display resolution of my primary display on Android 8.1. I get an event from the kernel (based on EDID) that tells me I need to change mode.

I then basically do:

sp<IBinder> display(SurfaceComposerClient::getBuiltInDisplay(ISurfaceComposer::eDisplayIdMain));
status_t res = SurfaceComposerClient::setActiveConfig(display, new_mode);

This updates surfaceflinger, the display hal and the kernel correctly, but windowmanager/display does not change resolution until I run:

wm size 1920x1080
wm density 240

But wm calls these function, which seem a bit too harsh, and also store the size/density in persistent setting:

public void setForcedDisplaySize(int displayId, int width, int height);
public void setForcedDisplayDensityForUser(int displayId, int density, int userId);

I've been looking at code in windowmanager/display without finding an API that I should use for this.

Is there a way to notify windowmanager/display about the change in surfaceflinger, or an API I've missed that I can use?

Am I going about this the wrong way? Is there a proper way you're meant to change resolution/mode of the primary display, that I haven't found?

0

There are 0 answers