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

Commit bbb9c302 authored by Jeff Chang's avatar Jeff Chang
Browse files

Support to set the density with uniqueId from WM command

Update the wm command to set density with uniqueId for emulator to
develop the multi display environment.

Bug: 186124236
Test: adb shell wm density 500 -u local:0
Change-Id: Ibe867a4b4de46923979e1cf8fb433fa459296bcc
parent 306cae8d
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -114,6 +114,7 @@ interface IWindowManager
    @UnsupportedAppUsage
    int getInitialDisplayDensity(int displayId);
    int getBaseDisplayDensity(int displayId);
    int getDisplayIdByUniqueId(String uniqueId);
    void setForcedDisplayDensityForUser(int displayId, int density, int userId);
    void clearForcedDisplayDensityForUser(int displayId, int userId);
    void setForcedDisplayScalingMode(int displayId, int mode); // 0 = auto, 1 = disable
+15 −0
Original line number Diff line number Diff line
@@ -5820,6 +5820,21 @@ public class WindowManagerService extends IWindowManager.Stub
        return -1;
    }

    /**
     * Return the display Id that has the given uniqueId. Unique ID is defined in
     * {@link DisplayInfo#uniqueId}.
     */
    @Override
    public int getDisplayIdByUniqueId(String uniqueId) {
        synchronized (mGlobalLock) {
            final DisplayContent displayContent = mRoot.getDisplayContent(uniqueId);
            if (displayContent != null && displayContent.hasAccess(Binder.getCallingUid())) {
                return displayContent.mDisplayId;
            }
        }
        return -1;
    }

    @Override
    public void setForcedDisplayDensityForUser(int displayId, int density, int userId) {
        if (mContext.checkCallingOrSelfPermission(WRITE_SECURE_SETTINGS)
+17 −2
Original line number Diff line number Diff line
@@ -276,8 +276,23 @@ public class WindowManagerShellCommand extends ShellCommand {

    private int runDisplayDensity(PrintWriter pw) throws RemoteException {
        String densityStr = getNextArg();
        String option = getNextOption();
        String arg = getNextArg();
        int density;
        final int displayId = getDisplayId(densityStr);
        int displayId = Display.DEFAULT_DISPLAY;
        if ("-d".equals(option) && arg != null) {
            try {
                displayId = Integer.parseInt(arg);
            } catch (NumberFormatException e) {
                getErrPrintWriter().println("Error: bad number " + e);
            }
        } else if ("-u".equals(option) && arg != null) {
            displayId = mInterface.getDisplayIdByUniqueId(arg);
            if (displayId == Display.INVALID_DISPLAY) {
                getErrPrintWriter().println("Error: the uniqueId is invalid ");
                return -1;
            }
        }

        if (densityStr == null) {
            printInitialDisplayDensity(pw, displayId);
@@ -1324,7 +1339,7 @@ public class WindowManagerShellCommand extends ShellCommand {
        pw.println("  size [reset|WxH|WdpxHdp] [-d DISPLAY_ID]");
        pw.println("    Return or override display size.");
        pw.println("    width and height in pixels unless suffixed with 'dp'.");
        pw.println("  density [reset|DENSITY] [-d DISPLAY_ID]");
        pw.println("  density [reset|DENSITY] [-d DISPLAY_ID] [-u UNIQUE_ID]");
        pw.println("    Return or override display density.");
        pw.println("  folded-area [reset|LEFT,TOP,RIGHT,BOTTOM]");
        pw.println("    Return or override folded area.");