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

Commit d46747a1 authored by Jeff Brown's avatar Jeff Brown
Browse files

Add support for disabling display scaling for development.

Added two new options to the wm command.

1. Set the screen size based on dips rather than pixels using the
current screen density.

eg. adb shell wm size 320dpx320dp

2. Disable automatic scaling of the contents of the display.
When combined with the previous command, this is useful for seeing
how the UI would behave if the screen remained at its current density
but changed physical size.

eg. adb shell wm scaling off

Bug: 19899223
Change-Id: I545f893ba4861494e995cf0457ebeba1050d28dc
parent 10acf6d3
Loading
Loading
Loading
Loading
+42 −4
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.graphics.Rect;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.util.AndroidException;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.IWindowManager;
import com.android.internal.os.BaseCommand;
@@ -45,21 +46,27 @@ public class Wm extends BaseCommand {
        (new Wm()).run(args);
    }

    @Override
    public void onShowUsage(PrintStream out) {
        out.println(
                "usage: wm [subcommand] [options]\n" +
                "       wm size [reset|WxH]\n" +
                "       wm size [reset|WxH|WdpxHdp]\n" +
                "       wm density [reset|DENSITY]\n" +
                "       wm overscan [reset|LEFT,TOP,RIGHT,BOTTOM]\n" +
                "       wm scaling [off|auto]\n" +
                "\n" +
                "wm size: return or override display size.\n" +
                "         width and height in pixels unless suffixed with 'dp'.\n" +
                "\n" +
                "wm density: override display density.\n" +
                "\n" +
                "wm overscan: set overscan area for display.\n"
                "wm overscan: set overscan area for display.\n" +
                "\n" +
                "wm scaling: set display scaling mode.\n"
                );
    }

    @Override
    public void onRun() throws Exception {
        mWm = IWindowManager.Stub.asInterface(ServiceManager.checkService(
                        Context.WINDOW_SERVICE));
@@ -76,6 +83,8 @@ public class Wm extends BaseCommand {
            runDisplayDensity();
        } else if (op.equals("overscan")) {
            runDisplayOverscan();
        } else if (op.equals("scaling")) {
            runDisplayScaling();
        } else {
            showError("Error: unknown command '" + op + "'");
            return;
@@ -85,6 +94,7 @@ public class Wm extends BaseCommand {
    private void runDisplaySize() throws Exception {
        String size = nextArg();
        int w, h;
        boolean scale = true;
        if (size == null) {
            Point initialSize = new Point();
            Point baseSize = new Point();
@@ -109,8 +119,8 @@ public class Wm extends BaseCommand {
            String wstr = size.substring(0, div);
            String hstr = size.substring(div+1);
            try {
                w = Integer.parseInt(wstr);
                h = Integer.parseInt(hstr);
                w = parseDimension(wstr);
                h = parseDimension(hstr);
            } catch (NumberFormatException e) {
                System.err.println("Error: bad number " + e);
                return;
@@ -193,4 +203,32 @@ public class Wm extends BaseCommand {
        } catch (RemoteException e) {
        }
    }

    private void runDisplayScaling() throws Exception {
        String scalingStr = nextArgRequired();
        if ("auto".equals(scalingStr)) {
            mWm.setForcedDisplayScalingMode(Display.DEFAULT_DISPLAY, 0);
        } else if ("off".equals(scalingStr)) {
            mWm.setForcedDisplayScalingMode(Display.DEFAULT_DISPLAY, 1);
        } else {
            System.err.println("Error: scaling must be 'auto' or 'off'");
        }
    }

    private int parseDimension(String s) throws NumberFormatException {
        if (s.endsWith("px")) {
            return Integer.parseInt(s.substring(0, s.length() - 2));
        }
        if (s.endsWith("dp")) {
            int density;
            try {
                density = mWm.getBaseDisplayDensity(Display.DEFAULT_DISPLAY);
            } catch (RemoteException e) {
                density = DisplayMetrics.DENSITY_DEFAULT;
            }
            return Integer.parseInt(s.substring(0, s.length() - 2)) * density /
                    DisplayMetrics.DENSITY_DEFAULT;
        }
        return Integer.parseInt(s);
    }
}
+7 −0
Original line number Diff line number Diff line
@@ -6035,6 +6035,13 @@ public final class Settings {
        */
       public static final String DISPLAY_SIZE_FORCED = "display_size_forced";

       /**
        * The saved value for WindowManagerService.setForcedDisplayScalingMode().
        * 0 or unset if scaling is automatic, 1 if scaling is disabled.
        * @hide
        */
       public static final String DISPLAY_SCALING_FORCE = "display_scaling_force";

       /**
        * The maximum size, in bytes, of a download that the download manager will transfer over
        * a non-wifi connection.
+9 −0
Original line number Diff line number Diff line
@@ -169,6 +169,15 @@ public final class Display {
     */
    public static final int FLAG_PRESENTATION = 1 << 3;

    /**
     * Display flag: Indicates that the contents of the display should not be scaled
     * to fit the physical screen dimensions.  Used for development only to emulate
     * devices with smaller physicals screens while preserving density.
     *
     * @hide
     */
    public static final int FLAG_SCALING_DISABLED = 1 << 30;

    /**
     * Display type: Unknown display type.
     * @hide
+3 −0
Original line number Diff line number Diff line
@@ -538,6 +538,9 @@ public final class DisplayInfo implements Parcelable {
        if ((flags & Display.FLAG_PRESENTATION) != 0) {
            result.append(", FLAG_PRESENTATION");
        }
        if ((flags & Display.FLAG_SCALING_DISABLED) != 0) {
            result.append(", FLAG_SCALING_DISABLED");
        }
        return result.toString();
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -70,6 +70,7 @@ interface IWindowManager
    int getBaseDisplayDensity(int displayId);
    void setForcedDisplayDensity(int displayId, int density);
    void clearForcedDisplayDensity(int displayId);
    void setForcedDisplayScalingMode(int displayId, int mode); // 0 = auto, 1 = disable

    void setOverscan(int displayId, int left, int top, int right, int bottom);

Loading