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

Commit 6970c31b authored by Svetoslav Ganov's avatar Svetoslav Ganov Committed by Android (Google) Code Review
Browse files

Merge "AccessibilityNodeInfo bounds in screen incorrect if application scale not one V2.0."

parents 99d8fae5 fd8d9c4c
Loading
Loading
Loading
Loading
+41 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package android.view;

import static android.view.accessibility.AccessibilityNodeInfo.INCLUDE_NOT_IMPORTANT_VIEWS;

import android.graphics.Rect;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
@@ -64,6 +65,8 @@ final class AccessibilityInteractionController {

    private final ArrayList<View> mTempArrayList = new ArrayList<View>();

    private final Rect mTempRect = new Rect();

    public AccessibilityInteractionController(ViewRootImpl viewRootImpl) {
        Looper looper =  viewRootImpl.mHandler.getLooper();
        mMyLooperThreadId = looper.getThread().getId();
@@ -207,6 +210,7 @@ final class AccessibilityInteractionController {
        } finally {
            try {
                mViewRootImpl.mAttachInfo.mIncludeNotImportantViews = false;
                applyApplicationScaleIfNeeded(infos);
                callback.setFindAccessibilityNodeInfosResult(infos, interactionId);
                infos.clear();
            } catch (RemoteException re) {
@@ -287,6 +291,7 @@ final class AccessibilityInteractionController {
        } finally {
            try {
                mViewRootImpl.mAttachInfo.mIncludeNotImportantViews = false;
                applyApplicationScaleIfNeeded(info);
                callback.setFindAccessibilityNodeInfoResult(info, interactionId);
            } catch (RemoteException re) {
                /* ignore - the other side will time out */
@@ -396,6 +401,7 @@ final class AccessibilityInteractionController {
        } finally {
            try {
                mViewRootImpl.mAttachInfo.mIncludeNotImportantViews = false;
                applyApplicationScaleIfNeeded(infos);
                callback.setFindAccessibilityNodeInfosResult(infos, interactionId);
            } catch (RemoteException re) {
                /* ignore - the other side will time out */
@@ -502,6 +508,7 @@ final class AccessibilityInteractionController {
        } finally {
            try {
                mViewRootImpl.mAttachInfo.mIncludeNotImportantViews = false;
                applyApplicationScaleIfNeeded(focused);
                callback.setFindAccessibilityNodeInfoResult(focused, interactionId);
            } catch (RemoteException re) {
                /* ignore - the other side will time out */
@@ -582,6 +589,7 @@ final class AccessibilityInteractionController {
        } finally {
            try {
                mViewRootImpl.mAttachInfo.mIncludeNotImportantViews = false;
                applyApplicationScaleIfNeeded(next);
                callback.setFindAccessibilityNodeInfoResult(next, interactionId);
            } catch (RemoteException re) {
                /* ignore - the other side will time out */
@@ -677,6 +685,39 @@ final class AccessibilityInteractionController {
        return foundView;
    }

    private void applyApplicationScaleIfNeeded(List<AccessibilityNodeInfo> infos) {
        if (infos == null) {
            return;
        }
        final float applicationScale = mViewRootImpl.mAttachInfo.mApplicationScale;
        if (applicationScale != 1.0f) {
            final int infoCount = infos.size();
            for (int i = 0; i < infoCount; i++) {
                AccessibilityNodeInfo info = infos.get(i);
                applyApplicationScaleIfNeeded(info);
            }
        }
    }

    private void applyApplicationScaleIfNeeded(AccessibilityNodeInfo info) {
        if (info == null) {
            return;
        }
        final float applicationScale = mViewRootImpl.mAttachInfo.mApplicationScale;
        if (applicationScale != 1.0f) {
            Rect bounds = mTempRect;

            info.getBoundsInParent(bounds);
            bounds.scale(applicationScale);
            info.setBoundsInParent(bounds);

            info.getBoundsInScreen(bounds);
            bounds.scale(applicationScale);
            info.setBoundsInScreen(bounds);
        }
    }


    /**
     * This class encapsulates a prefetching strategy for the accessibility APIs for
     * querying window content. It is responsible to prefetch a batch of
+0 −3
Original line number Diff line number Diff line
@@ -4697,14 +4697,11 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
     */
    void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
        Rect bounds = mAttachInfo.mTmpInvalRect;
        final float applicationScale = mAttachInfo.mApplicationScale;
        getDrawingRect(bounds);
        bounds.scale(applicationScale);
        info.setBoundsInParent(bounds);
        getBoundsOnScreen(bounds);
        bounds.scale(applicationScale);
        info.setBoundsInScreen(bounds);
        ViewParent parent = getParentForAccessibility();