Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 67bb207b authored by Yichi Chen's avatar Yichi Chen
Browse files

Query the display status from DisplayInfo

During the resolution changes, the display status in DisplayMetrics is
obsolete during the resolution changes. To get the accurate display
status, we query the status from DisplayInfo, instead of DisplayMetrics.

Bug: 233698163
Test: Switch resolution with customized density
Change-Id: I360aeecab0feaa5d21cc7a5679ff50e735ed8043
parent 75d2de30
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.util.DisplayMetrics;
import android.util.Log;
import android.util.MathUtils;
import android.view.Display;
import android.view.DisplayInfo;
import android.view.IWindowManager;
import android.view.WindowManagerGlobal;

@@ -87,14 +88,14 @@ public class DisplayDensityUtils {
        }

        final Resources res = context.getResources();
        final DisplayMetrics metrics = new DisplayMetrics();
        context.getDisplayNoVerify().getRealMetrics(metrics);
        DisplayInfo info = new DisplayInfo();
        context.getDisplayNoVerify().getDisplayInfo(info);

        final int currentDensity = metrics.densityDpi;
        final int currentDensity = info.logicalDensityDpi;
        int currentDensityIndex = -1;

        // Compute number of "larger" and "smaller" scales for this display.
        final int minDimensionPx = Math.min(metrics.widthPixels, metrics.heightPixels);
        final int minDimensionPx = Math.min(info.logicalWidth, info.logicalHeight);
        final int maxDensity = DisplayMetrics.DENSITY_MEDIUM * minDimensionPx / MIN_DIMENSION_DP;
        final float maxScaleDimen = context.getResources().getFraction(
                R.fraction.display_density_max_scale, 1, 1);