This question is related to: OnePlus 6T Android Emulator Screen Configuration Hardware Profile, in which I was able to match emulator's screen to the actual device via trial and error. Now, I'm trying to find a formula to accomplish the same for other devices.
i'm looking at the data Configuration and DisplayMetrics as returned respectively by the following:
activity.getResources().getConfiguration().toString();
...
DisplayMetrics displayMetrics = new DisplayMetrics();
activity.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
displayMetrics.toString();
For the phone in question, OnePlust 6T, the screen specs are: 6.41 in, 2340 x 1080 pixels and the outputs from the above are (Device):
Configuration{1.0 0 452mcc4mnc [en_US,pl_PL] ldltr sw411dp w411dp h812dp 420dpi nrml long hdr widecg port night force dark=0 finger -keyb/v/h -nav/h winConfig={ mBounds=Rect(0, 0 - 1080, 2340) mAppBounds=Rect(0, 80 - 1080, 2214) mWindowingMode=fullscreen mDisplayWindowingMode=fullscreen mActivityType=standard mAlwaysOnTop=undefined mRotation=ROTATION_0} s.1}
DisplayMetrics{density=2.625, width=1080, height=2134, scaledDensity=2.625, xdpi=403.411, ydpi=409.903}
When emulator is configured to the same specs as the device, the outputs are (EmuDev):
Configuration{1.0 310mcc260mnc [en_US] ldltr sw360dp w360dp h708dp 480dpi nrml long port finger qwerty/v/v -nav/h winConfig={ mBounds=Rect(0, 0 - 1080, 2196) mAppBounds=Rect(0, 0 - 1080, 2196) mWindowingMode=fullscreen mActivityType=standard} s.6}
DisplayMetrics{density=3.0, width=1080, height=2196, scaledDensity=3.0, xdpi=480.0, ydpi=480.0}}
Finally, the output for my modified emulator, set to 6.41 in and 2643 x 1220 is (EmuMod):
Configuration{1.0 310mcc260mnc [en_US] ldltr sw406dp w406dp h809dp 480dpi nrml long port finger qwerty/v/v -nav/h winConfig={ mBounds=Rect(0, 0 - 1220, 2499) mAppBounds=Rect(0, 0 - 1220, 2499) mWindowingMode=fullscreen mActivityType=standard} s.6}
DisplayMetrics{density=3.0, width=1220, height=2499, scaledDensity=3.0, xdpi=480.0, ydpi=480.0}
My first guess was that to match emulator's screen to the device's, I have to match their dp width and height from Configuration (see in bold above) and came up with the following formula:
EmuDev Density / Device Density * Spec Pixels = EmuMod Pixels
Plugging the actual numbers seemed to confirm this:
3.0 / 2.625 * 2340 = 2674 ( ~ 2643 )
3.0 / 2.625 * 1080 = 1234 ( ~ 1220 )
However, applying this formula to other devices didn't work as the emulator's screen didn't mirror the device's. Any ideas on how to tweak it? What other metrics to look for?
For completeness, below are the outputs for the device it didn't work, Galaxy A9 with specs 6.3 in, 1080 x 2220 pixels:
Device:
Configuration{1.1 452mcc1mnc [vi_VN] ldltr sw360dp w360dp h668dp 480dpi nrml long port night finger -keyb/v/h -nav/h winConfig:{ mBounds:Rect(0, 0 - 1080, 2220) mAppBounds:Rect(0, 0 - 1080, 2076) mWindowingMode:fullscreen mDisplayWindowingMode:fullscreen mActivityType:standard mAlwaysOnTop:undefined mRotation:ROTATION_0} s.1 bts:0 ff:0 bf:0 themeSeq:0}
DisplayMetrics{density:3.0, width:1080, height:2076, scaledDensity:3.0, xdpi:409.432, ydpi:408.608}
EmuDev:
Configuration{1.0 310mcc260mnc [en_US] ldltr sw540dp w540dp h1038dp 320dpi lrg long port finger qwerty/v/v -nav/h winConfig={ mBounds=Rect(0, 0 - 1080, 2220) mAppBounds=Rect(0, 0 - 1080, 2124) mWindowingMode=fullscreen mDisplayWindowingMode=fullscreen mActivityType=standard mAlwaysOnTop=undefined mRotation=ROTATION_0} s.1}
DisplayMetrics{density=2.0, width=1080, height=2124, scaledDensity=2.0, xdpi=320.0, ydpi=320.0}
and EmuMod (with modified specs 720 x 1480):
Configuration{1.0 310mcc260mnc [en_US] ldltr sw480dp w480dp h914dp 240dpi lrg long port finger qwerty/v/v -nav/h winConfig={ mBounds=Rect(0, 0 - 720, 1480) mAppBounds=Rect(0, 0 - 720, 1408) mWindowingMode=fullscreen mDisplayWindowingMode=fullscreen mActivityType=standard mAlwaysOnTop=undefined mRotation=ROTATION_0} s.1}
DisplayMetrics{density=1.5, width=720, height=1408, scaledDensity=1.5, xdpi=240.0, ydpi=240.0}