Bug 57933 - 5" KitKat XXHDPI Phone emulator returns wrong / incorrect density
Summary: 5" KitKat XXHDPI Phone emulator returns wrong / incorrect density
Status: RESOLVED ANSWERED
Alias: None
Product: Android
Classification: Xamarin
Component: General ()
Version: 7.3 (15.2)
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Jonathan Pryor
URL:
Depends on:
Blocks:
 
Reported: 2017-07-05 06:16 UTC by Ales Suchac
Modified: 2017-07-07 05:01 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Testing app to demostrate the DPI problem (20.23 KB, application/x-zip-compressed)
2017-07-05 23:59 UTC, Ales Suchac
Details
Screenshot 1 showing the emulator is not AVD but Xamarin (112.28 KB, image/png)
2017-07-06 00:00 UTC, Ales Suchac
Details
Screenshot 2 showing my current list of AVDs (45.63 KB, image/png)
2017-07-06 00:00 UTC, Ales Suchac
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED ANSWERED

Description Ales Suchac 2017-07-05 06:16:50 UTC
I have Xamarin.Android 7.3.1.2. When testing my Android app, the '5" KitKat (4.4) XXHDPI Phone' emulator returns the density as 72 dpi. I guess it should be 480 dpi, if it claims to be XXHDPI.

The relevant code:

Activity currentActivity = this;     // This code is called inside Activity object
Display d = currentActivity.WindowManager.DefaultDisplay;
Android.Util.DisplayMetrics m = new Android.Util.DisplayMetrics();
d.GetMetrics( m );

Check the value of:

m.Xdpi
m.Ydpi

This problem may be in other emulators as well, I didn't have time to test them.
Comment 1 Jon Douglas [MSFT] 2017-07-05 16:09:35 UTC
Hi Ales,

To help pin down this issue, can you please provide a step-by-step reproduction of this issue so we can investigate further? The reason why we need a step-by-step is that we need to know what exactly is being added to your AVD. The AVD can be tricky because there are many things that might affect DPI such as the SKIN you pick, and if you select the "SCALE DISPLAY TO REAL SIZE" before booting.

The real test is to ensure your physical device works first. Once you ensure that's correct, then start playing around with your AVD to ensure the settings mimic a real world device instead of being shrunk. Thus I am marking this bug as NEEDINFO for the time being.
Comment 2 Ales Suchac 2017-07-05 23:59:13 UTC
Created attachment 23315 [details]
Testing app to demostrate the DPI problem
Comment 3 Ales Suchac 2017-07-06 00:00:20 UTC
Created attachment 23316 [details]
Screenshot 1 showing the emulator is not AVD but Xamarin
Comment 4 Ales Suchac 2017-07-06 00:00:59 UTC
Created attachment 23317 [details]
Screenshot 2 showing my current list of AVDs
Comment 5 Ales Suchac 2017-07-06 00:03:50 UTC
I have added a testing app and screenshots.
The device I am referring to is not a standard AVD device but Xamarin's own emulator so when I launch it it doesn't ask for 'Scale display to real size'.
My physical devices display correct DPI.
Comment 6 Jon Douglas [MSFT] 2017-07-06 17:18:12 UTC
(In reply to Ales Suchac from comment #5)
> I have added a testing app and screenshots.
> The device I am referring to is not a standard AVD device but Xamarin's own
> emulator so when I launch it it doesn't ask for 'Scale display to real size'.
> My physical devices display correct DPI.

What do you mean Xamarin's own emulator? This is Microsoft's Emulator for Android. I don't believe it's readily available in newer versions of Visual Studio 2017(As they moved it to be an optional workload)

For example if you are using the AVDs from Google, you will be able to see the resolution of a device such as:

Google Pixel XL - 1440 x 2560; 560 dpi

When running the sample app on this emulator, I get the expected 560 dpi.

Now if I change this emulator to the regular Google Pixel, I would see the following:

Google Pixel - 1080 x 1920; xxhdpi

Running the sample app, I would see 480 dpi (Which is the threshold for xxdpi)

So I believe the issue might be with the emulator you are using. It looks like you're using the Visual Studio Emulator for Android, which unfortunately does not publish any new emulator images for Android updates. It is thus recommended to move to the Android Emulators that Google provides.

https://developer.android.com/studio/run/managing-avds.html

I highly recommend updating your Xamarin versions and installing Android Studio for an easier AVD Manager for the time being(As Google released avdmanager recently). I am thus marking this bug as RESOLVED ANSWERED as this behavior should work just fine on these emulators.
Comment 7 Ales Suchac 2017-07-07 05:01:34 UTC
You are right that AVD emulators solve the problem, which I never disputed. 

I just thought that the Microsoft's Visual Studio emulator is in fact a Xamarin's product so you might be able to fix it.

OK I agree we have the solution. Thank you.