We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 4016

Summary: SDL 2.0.7 wrong screen size detection on android
Product: SDL Reporter: tibiz <sasha.faryna1234>
Component: videoAssignee: Sam Lantinga <slouken>
Status: NEW --- QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: sylvain.becker
Version: 2.0.7   
Hardware: ARM   
OS: Android (All)   

Description tibiz 2017-12-29 23:41:27 UTC
I dont know if it's a pure SDL bug or not,but it's pretty weird.In my app I have a java method to determine the screen resolution of the device.The method is called in the onCreate() method of SDLActivity.I use a Samsung Galaxy A5(2017)(SM-A520F)(1920x1080) for testing,and when i have sdl 2.0.7 it tells 1440x810,and when building project with SDL 2.0.4 it tells 1920x1080.Maybe this but is due to the recent changes in the android subsystem.
Comment 1 tibiz 2017-12-29 23:42:18 UTC
Forgot to tell,but this bug doesn't appear on emulators
Comment 2 Sylvain 2018-01-02 14:47:42 UTC
what is your java method ?
maybe this is a change is you targetSdkVersion API ?
Comment 3 tibiz 2018-01-03 10:53:05 UTC
This is the function to determine the screen size:

private String[] getScreenDimension(){
        DisplayMetrics dm = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getRealMetrics(dm);

        int width = dm.widthPixels;
        int height = dm.heightPixels;
        int dens = dm.densityDpi;
        double wi = (double)width / (double)dens;
        double hi = (double)height / (double)dens;
        double x = Math.pow(wi, 2);
        double y = Math.pow(hi, 2);
        double screenInches = Math.sqrt(x+y);

        String[] screenInformation = new String[3];
        screenInformation[0] = String.valueOf(width) + " px";
        screenInformation[1] = String.valueOf(height) + " px" ;
        screenInformation[2] = String.format("%.2f", screenInches) + " inches" ;

        return screenInformation;
    }

getScrenDimension()[0] and getScrenDimension()[1] give me the wrong width and height.

This is my API version:
 minSdkVersion 19
 targetSdkVersion 26
Comment 4 Sylvain 2018-01-03 15:54:43 UTC
If you build with SDL 2.0.4 and use the same API version as in your 2.0.7, eg
 minSdkVersion 19
 targetSdkVersion 26

what happens ?
Comment 5 tibiz 2018-01-03 20:04:20 UTC
If I use this:
 minSdkVersion 19
 targetSdkVersion 26
in SDL 2.0.4 it gives me a correct width and height.Also I have noticed, when logcating with SDL 2.0.7 I get this message "D/SurfaceView: Relayout returned: oldFrame=[0,72][1440,810] newFrame=[0,72][1440,810] result=0x1 surface={Surface(name=null)/@0x87f7d7d isValid=true 542053654016}"

and when using SDL 2.0.4 I get "D/SurfaceView: Relayout returned: oldFrame=[0,72][1920,1080] newFrame=[0,72][1920,1080] result=0x1 surface={Surface(name=null)/@0x87f7d7d isValid=true 542053654016}"
Comment 6 Sylvain 2018-01-03 20:19:42 UTC
And, why if you use 
DisplayMetrics dm = getContext().getResources().getDisplayMetrics(); 
?
Comment 7 tibiz 2018-01-03 20:32:53 UTC
If i use this ,I get an error:
java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference at org.libsdl.app.SDLActivity.getScreenDimension(SDLActivity.java:170)
Comment 8 Sylvain 2018-01-03 20:37:35 UTC
strange ... you need to call at a good place, not to early maybe.


- Also, you can try something in AndroidManifest.xml: android:configChanges="..."
see if "screenLayout|fontScale|uiMode|screenSize" matters.

- or to comment out the setSystemUiVisibility() in SDLActivity.java


- in your logcat, you should also have a line : 
  SDL : Window size: 1080x1920


Otherwise, I don't have much idea ...
Comment 9 tibiz 2018-01-03 20:47:05 UTC
This is what I get in logcat: SDL : Window size: 1440x810.
Anyway,thanks