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

Commit 0cca3db9 authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

Fix issue #11278906: Some wm commands fail on shell users

Binder.clearCallingIdentity makes everything better.

Change-Id: I31cd9478c857553b3cf1ea54d5b4987571788796
parent ce39e8ce
Loading
Loading
Loading
Loading
+64 −38
Original line number Diff line number Diff line
@@ -7636,6 +7636,8 @@ public class WindowManagerService extends IWindowManager.Stub
        if (displayId != Display.DEFAULT_DISPLAY) {
            throw new IllegalArgumentException("Can only set the default display");
        }
        final long ident = Binder.clearCallingIdentity();
        try {
            synchronized(mWindowMap) {
                // Set some sort of reasonable bounds on the size of the display that we
                // will try to emulate.
@@ -7653,6 +7655,9 @@ public class WindowManagerService extends IWindowManager.Stub
                            Settings.Global.DISPLAY_SIZE_FORCED, width + "," + height);
                }
            }
        } finally {
            Binder.restoreCallingIdentity(ident);
        }
    }

    private void readForcedDisplaySizeAndDensityLocked(final DisplayContent displayContent) {
@@ -7722,6 +7727,8 @@ public class WindowManagerService extends IWindowManager.Stub
        if (displayId != Display.DEFAULT_DISPLAY) {
            throw new IllegalArgumentException("Can only set the default display");
        }
        final long ident = Binder.clearCallingIdentity();
        try {
            synchronized(mWindowMap) {
                final DisplayContent displayContent = getDisplayContentLocked(displayId);
                if (displayContent != null) {
@@ -7731,6 +7738,9 @@ public class WindowManagerService extends IWindowManager.Stub
                            Settings.Global.DISPLAY_SIZE_FORCED, "");
                }
            }
        } finally {
            Binder.restoreCallingIdentity(ident);
        }
    }

    @Override
@@ -7770,6 +7780,8 @@ public class WindowManagerService extends IWindowManager.Stub
        if (displayId != Display.DEFAULT_DISPLAY) {
            throw new IllegalArgumentException("Can only set the default display");
        }
        final long ident = Binder.clearCallingIdentity();
        try {
            synchronized(mWindowMap) {
                final DisplayContent displayContent = getDisplayContentLocked(displayId);
                if (displayContent != null) {
@@ -7778,6 +7790,9 @@ public class WindowManagerService extends IWindowManager.Stub
                            Settings.Global.DISPLAY_DENSITY_FORCED, Integer.toString(density));
                }
            }
        } finally {
            Binder.restoreCallingIdentity(ident);
        }
    }

    // displayContent must not be null
@@ -7801,14 +7816,20 @@ public class WindowManagerService extends IWindowManager.Stub
        if (displayId != Display.DEFAULT_DISPLAY) {
            throw new IllegalArgumentException("Can only set the default display");
        }
        final long ident = Binder.clearCallingIdentity();
        try {
            synchronized(mWindowMap) {
                final DisplayContent displayContent = getDisplayContentLocked(displayId);
                if (displayContent != null) {
                setForcedDisplayDensityLocked(displayContent, displayContent.mInitialDisplayDensity);
                    setForcedDisplayDensityLocked(displayContent,
                            displayContent.mInitialDisplayDensity);
                    Settings.Global.putString(mContext.getContentResolver(),
                            Settings.Global.DISPLAY_DENSITY_FORCED, "");
                }
            }
        } finally {
            Binder.restoreCallingIdentity(ident);
        }
    }

    // displayContent must not be null
@@ -7855,12 +7876,17 @@ public class WindowManagerService extends IWindowManager.Stub
            throw new SecurityException("Must hold permission " +
                    android.Manifest.permission.WRITE_SECURE_SETTINGS);
        }
        final long ident = Binder.clearCallingIdentity();
        try {
            synchronized(mWindowMap) {
                DisplayContent displayContent = getDisplayContentLocked(displayId);
                if (displayContent != null) {
                    setOverscanLocked(displayContent, left, top, right, bottom);
                }
            }
        } finally {
            Binder.restoreCallingIdentity(ident);
        }
    }

    private void setOverscanLocked(DisplayContent displayContent,