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

Commit 2b5c5b64 authored by Svetoslav Ganov's avatar Svetoslav Ganov Committed by Android Git Automerger
Browse files

am 0bb4d078: Merge "Screen magnifier should handle window rebuilds correctly." into jb-mr1-dev

* commit '0bb4d078':
  Screen magnifier should handle window rebuilds correctly.
parents 8a2cf2ca 0bb4d078
Loading
Loading
Loading
Loading
+27 −5
Original line number Diff line number Diff line
@@ -45,13 +45,15 @@ public class WindowInfo implements Parcelable {

    public final Rect touchableRegion = new Rect();

    public int type;
    public int type = UNDEFINED;

    public float compatibilityScale;
    public float compatibilityScale = UNDEFINED;

    public boolean visible;

    public int displayId;
    public int displayId = UNDEFINED;

    public int layer = UNDEFINED;

    private WindowInfo() {
        /* do nothing - reduce visibility */
@@ -71,6 +73,7 @@ public class WindowInfo implements Parcelable {
        parcel.writeFloat(compatibilityScale);
        parcel.writeInt(visible ? 1 : 0);
        parcel.writeInt(displayId);
        parcel.writeInt(layer);
        recycle();
    }

@@ -82,6 +85,7 @@ public class WindowInfo implements Parcelable {
        compatibilityScale = parcel.readFloat();
        visible = (parcel.readInt() == 1);
        displayId = parcel.readInt();
        layer = parcel.readInt();
    }

    public static WindowInfo obtain(WindowInfo other) {
@@ -90,9 +94,10 @@ public class WindowInfo implements Parcelable {
        info.frame.set(other.frame);
        info.touchableRegion.set(other.touchableRegion);
        info.type = other.type;
        info.displayId = other.displayId;
        info.compatibilityScale = other.compatibilityScale;
        info.visible = other.visible;
        info.displayId = other.displayId;
        info.layer = other.layer;
        return info;
    }

@@ -131,8 +136,25 @@ public class WindowInfo implements Parcelable {
        frame.setEmpty();
        touchableRegion.setEmpty();
        type = UNDEFINED;
        displayId = UNDEFINED;
        compatibilityScale = UNDEFINED;
        visible = false;
        displayId = UNDEFINED;
        layer = UNDEFINED;
    }

    @Override
    public String toString() {
        StringBuilder builder = new StringBuilder();
        builder.append("Window [token:").append((token != null) ? token.hashCode() : null);
        builder.append(", displayId:").append(displayId);
        builder.append(", type:").append(type);
        builder.append(", visible:").append(visible);
        builder.append(", layer:").append(layer);
        builder.append(", compatibilityScale:").append(compatibilityScale);
        builder.append(", frame:").append(frame);
        builder.append(", touchableRegion:").append(touchableRegion);
        builder.append("]");
        return builder.toString();
    }

    /**
+71 −13
Original line number Diff line number Diff line
@@ -67,6 +67,8 @@ import com.android.internal.R;
import com.android.internal.os.SomeArgs;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

/**
 * This class handles the screen magnification when accessibility is enabled.
@@ -1020,7 +1022,9 @@ public final class ScreenMagnifier implements EventStreamTransformation {
                }
                if (info.type == WindowManager.LayoutParams.TYPE_NAVIGATION_BAR
                        || info.type == WindowManager.LayoutParams.TYPE_INPUT_METHOD
                        || info.type == WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG) {
                        || info.type == WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG
                        || info.type == WindowManager.LayoutParams.TYPE_KEYGUARD
                        || info.type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG) {
                    switch (transition) {
                        case WindowManagerPolicy.TRANSIT_ENTER:
                        case WindowManagerPolicy.TRANSIT_SHOW:
@@ -1473,7 +1477,9 @@ public final class ScreenMagnifier implements EventStreamTransformation {

        private final ArrayList<WindowInfo> mTempWindowInfoList = new ArrayList<WindowInfo>();

        private final Rect mTempRect = new Rect();
        private final Rect mTempRect1 = new Rect();
        private final Rect mTempRect2 = new Rect();
        private final Rect mTempRect3 = new Rect();

        private final IWindowManager mWindowManagerService;
        private final DisplayProvider mDisplayProvider;
@@ -1542,31 +1548,83 @@ public final class ScreenMagnifier implements EventStreamTransformation {
            recomputeBounds(false);
        }

        private final Comparator<WindowInfo> mWindowInfoInverseComparator =
                new Comparator<WindowInfo>() {
            @Override
            public int compare(WindowInfo lhs, WindowInfo rhs) {
                if (lhs.layer != rhs.layer) {
                    return rhs.layer - lhs.layer;
                }
                if (lhs.touchableRegion.top != rhs.touchableRegion.top) {
                    return rhs.touchableRegion.top - lhs.touchableRegion.top;
                }
                if (lhs.touchableRegion.left != rhs.touchableRegion.left) {
                    return rhs.touchableRegion.left - lhs.touchableRegion.left;
                }
                if (lhs.touchableRegion.right != rhs.touchableRegion.right) {
                    return rhs.touchableRegion.right - lhs.touchableRegion.right;
                }
                if (lhs.touchableRegion.bottom != rhs.touchableRegion.bottom) {
                    return rhs.touchableRegion.bottom - lhs.touchableRegion.bottom;
                }
                return 0;
            }
        };

        public void recomputeBounds(boolean animate) {
            Rect frame = mTempRect;
            frame.set(0, 0, mDisplayProvider.getDisplayInfo().logicalWidth,
                    mDisplayProvider.getDisplayInfo().logicalHeight);
            Rect magnifiedFrame = mTempRect1;
            magnifiedFrame.set(0, 0, 0, 0);

            Rect notMagnifiedFrame = mTempRect2;
            notMagnifiedFrame.set(0, 0, 0, 0);

            ArrayList<WindowInfo> infos = mTempWindowInfoList;
            infos.clear();
            int windowCount = 0;
            try {
                mWindowManagerService.getVisibleWindowsForDisplay(
                        mDisplayProvider.getDisplay().getDisplayId(), infos);
                final int windowCount = infos.size();
                Collections.sort(infos, mWindowInfoInverseComparator);
                windowCount = infos.size();
                for (int i = 0; i < windowCount; i++) {
                    WindowInfo info = infos.get(i);
                    if (info.type == WindowManager.LayoutParams.TYPE_NAVIGATION_BAR
                            || info.type == WindowManager.LayoutParams.TYPE_INPUT_METHOD
                            || info.type == WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG) {
                        subtract(frame, info.touchableRegion);
                    if (info.type == WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY) {
                        continue;
                    }
                    if (isWindowMagnified(info.type)) {
                        Rect clippedFrame = mTempRect3;
                        clippedFrame.set(info.touchableRegion);
                        subtract(clippedFrame, notMagnifiedFrame);
                        magnifiedFrame.union(clippedFrame);
                    } else {
                        Rect clippedFrame = mTempRect3;
                        clippedFrame.set(info.touchableRegion);
                        subtract(clippedFrame, magnifiedFrame);
                        notMagnifiedFrame.union(clippedFrame);
                    }
                    if (magnifiedFrame.bottom >= notMagnifiedFrame.top) {
                        break;
                    }
                    info.recycle();
                }
            } catch (RemoteException re) {
                /* ignore */
            } finally {
                infos.clear();
                for (int i = windowCount - 1; i >= 0; i--) {
                    infos.remove(i).recycle();
                }
            }

            final int displayWidth = mDisplayProvider.getDisplayInfo().logicalWidth;
            final int displayHeight = mDisplayProvider.getDisplayInfo().logicalHeight;
            magnifiedFrame.intersect(0, 0, displayWidth, displayHeight);

            resize(magnifiedFrame, animate);
        }
            resize(frame, animate);

        private boolean isWindowMagnified(int type) {
            return (type != WindowManager.LayoutParams.TYPE_NAVIGATION_BAR
                    && type != WindowManager.LayoutParams.TYPE_INPUT_METHOD
                    && type != WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG);
        }

        public void rotationChanged() {
+1 −0
Original line number Diff line number Diff line
@@ -3153,6 +3153,7 @@ public class WindowManagerService extends IWindowManager.Stub
        info.compatibilityScale = window.mGlobalScale;
        info.visible = window.isVisibleLw()
                || info.type == WindowManager.LayoutParams.TYPE_UNIVERSE_BACKGROUND;
        info.layer = window.mLayer;
        window.getTouchableRegion(mTempRegion);
        mTempRegion.getBounds(info.touchableRegion);
        return info;