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

Commit 239a1228 authored by Jacky Kao's avatar Jacky Kao
Browse files

Deleting the codes related the embedded displays

This CL is to delete all codes related the embedded displays in the
A11y framework due to the ActivityView is removed.

Bug: 189793002
Test: a11y CTS & unit tests
Test: manual testing Talkback
Change-Id: I964f601c3b98da4d637eeab017b60eb5a818fe91
parent fb2a9fe9
Loading
Loading
Loading
Loading
+4 −29
Original line number Original line Diff line number Diff line
@@ -143,12 +143,8 @@ public class AccessibilityWindowManager {


        /**
        /**
         * Starts tracking windows changes from window manager by registering callback.
         * Starts tracking windows changes from window manager by registering callback.
         *
         * @return true if callback registers successful.
         */
         */
        boolean startTrackingWindowsLocked() {
        void startTrackingWindowsLocked() {
            boolean result = true;

            if (!mTrackingWindows) {
            if (!mTrackingWindows) {
                // Turns on the flag before setup the callback.
                // Turns on the flag before setup the callback.
                // In some cases, onWindowsForAccessibilityChanged will be called immediately in
                // In some cases, onWindowsForAccessibilityChanged will be called immediately in
@@ -158,16 +154,10 @@ public class AccessibilityWindowManager {
                    logTraceWM("setWindowsForAccessibilityCallback",
                    logTraceWM("setWindowsForAccessibilityCallback",
                            "displayId=" + mDisplayId + ";callback=" + this);
                            "displayId=" + mDisplayId + ";callback=" + this);
                }
                }
                result = mWindowManagerInternal.setWindowsForAccessibilityCallback(
                mWindowManagerInternal.setWindowsForAccessibilityCallback(
                        mDisplayId, this);
                        mDisplayId, this);
                if (!result) {
                    mTrackingWindows = false;
                    Slog.w(LOG_TAG, "set windowsObserver callbacks fail, displayId:"
                            + mDisplayId);
            }
            }
        }
        }
            return result;
        }


        /**
        /**
         * Stops tracking windows changes from window manager, and clear all windows info.
         * Stops tracking windows changes from window manager, and clear all windows info.
@@ -384,20 +374,6 @@ public class AccessibilityWindowManager {
            }
            }
        }
        }


        /**
         * Called when the display is reparented and becomes an embedded
         * display.
         *
         * @param embeddedDisplayId The embedded display Id.
         */
        @Override
        public void onDisplayReparented(int embeddedDisplayId) {
            // Removes the un-used window observer for the embedded display.
            synchronized (mLock) {
                mDisplayWindowsObservers.remove(embeddedDisplayId);
            }
        }

        private boolean shouldUpdateWindowsLocked(boolean forceSend,
        private boolean shouldUpdateWindowsLocked(boolean forceSend,
                @NonNull List<WindowInfo> windows) {
                @NonNull List<WindowInfo> windows) {
            if (forceSend) {
            if (forceSend) {
@@ -900,11 +876,10 @@ public class AccessibilityWindowManager {
            if (observer.isTrackingWindowsLocked()) {
            if (observer.isTrackingWindowsLocked()) {
                return;
                return;
            }
            }
            if (observer.startTrackingWindowsLocked()) {
            observer.startTrackingWindowsLocked();
            mDisplayWindowsObservers.put(displayId, observer);
            mDisplayWindowsObservers.put(displayId, observer);
        }
        }
    }
    }
    }


    /**
    /**
     * Stops tracking windows changes from window manager, and clear all windows info for specified
     * Stops tracking windows changes from window manager, and clear all windows info for specified
+4 −124
Original line number Original line Diff line number Diff line
@@ -74,7 +74,6 @@ import android.os.Message;
import android.os.Process;
import android.os.Process;
import android.os.SystemClock;
import android.os.SystemClock;
import android.util.ArraySet;
import android.util.ArraySet;
import android.util.IntArray;
import android.util.Slog;
import android.util.Slog;
import android.util.SparseArray;
import android.util.SparseArray;
import android.util.TypedValue;
import android.util.TypedValue;
@@ -94,7 +93,6 @@ import android.view.animation.Interpolator;
import com.android.internal.R;
import com.android.internal.R;
import com.android.internal.os.SomeArgs;
import com.android.internal.os.SomeArgs;
import com.android.internal.util.TraceBuffer;
import com.android.internal.util.TraceBuffer;
import com.android.internal.util.function.pooled.PooledLambda;
import com.android.server.LocalServices;
import com.android.server.LocalServices;
import com.android.server.policy.WindowManagerPolicy;
import com.android.server.policy.WindowManagerPolicy;
import com.android.server.wm.WindowManagerInternal.AccessibilityControllerInternal;
import com.android.server.wm.WindowManagerInternal.AccessibilityControllerInternal;
@@ -177,17 +175,12 @@ final class AccessibilityController {


    /**
    /**
     * Sets a callback for observing which windows are touchable for the purposes
     * Sets a callback for observing which windows are touchable for the purposes
     * of accessibility on specified display. When a display is reparented and becomes
     * of accessibility on specified display.
     * an embedded one, the {@link WindowsForAccessibilityCallback#onDisplayReparented(int)}
     * will notify the accessibility framework to remove the un-used window observer of
     * this embedded display.
     *
     *
     * @param displayId The logical display id.
     * @param displayId The logical display id.
     * @param callback The callback.
     * @param callback The callback.
     * @return {@code false} if display id is not valid or an embedded display when the callback
     * isn't null.
     */
     */
    boolean setWindowsForAccessibilityCallback(int displayId,
    void setWindowsForAccessibilityCallback(int displayId,
            WindowsForAccessibilityCallback callback) {
            WindowsForAccessibilityCallback callback) {
        if (mAccessibilityTracing.isTracingEnabled(FLAGS_WINDOWS_FOR_ACCESSIBILITY_CALLBACK)) {
        if (mAccessibilityTracing.isTracingEnabled(FLAGS_WINDOWS_FOR_ACCESSIBILITY_CALLBACK)) {
            mAccessibilityTracing.logTrace(
            mAccessibilityTracing.logTrace(
@@ -197,30 +190,15 @@ final class AccessibilityController {
        }
        }


        if (callback != null) {
        if (callback != null) {
            final DisplayContent dc = mService.mRoot.getDisplayContentOrCreate(displayId);
            if (dc == null) {
                return false;
            }

            WindowsForAccessibilityObserver observer =
            WindowsForAccessibilityObserver observer =
                    mWindowsForAccessibilityObserver.get(displayId);
                    mWindowsForAccessibilityObserver.get(displayId);
            if (isEmbeddedDisplay(dc)) {
            if (observer != null) {
                // If this display is an embedded one, its window observer should have been set from
                // window manager after setting its parent window. But if its window observer is
                // empty, that means this mapping didn't be set, and needs to do this again.
                // This happened when accessibility window observer is disabled and enabled again.
                if (observer == null) {
                    handleWindowObserverOfEmbeddedDisplay(displayId, dc.getParentWindow());
                }
                return false;
            } else if (observer != null) {
                final String errorMessage = "Windows for accessibility callback of display "
                final String errorMessage = "Windows for accessibility callback of display "
                        + displayId + " already set!";
                        + displayId + " already set!";
                Slog.e(TAG, errorMessage);
                Slog.e(TAG, errorMessage);
                if (Build.IS_DEBUGGABLE) {
                if (Build.IS_DEBUGGABLE) {
                    throw new IllegalStateException(errorMessage);
                    throw new IllegalStateException(errorMessage);
                }
                }
                removeObserversForEmbeddedChildDisplays(observer);
                mWindowsForAccessibilityObserver.remove(displayId);
                mWindowsForAccessibilityObserver.remove(displayId);
            }
            }
            observer = new WindowsForAccessibilityObserver(mService, displayId, callback);
            observer = new WindowsForAccessibilityObserver(mService, displayId, callback);
@@ -237,10 +215,8 @@ final class AccessibilityController {
                    throw new IllegalStateException(errorMessage);
                    throw new IllegalStateException(errorMessage);
                }
                }
            }
            }
            removeObserversForEmbeddedChildDisplays(windowsForA11yObserver);
            mWindowsForAccessibilityObserver.remove(displayId);
            mWindowsForAccessibilityObserver.remove(displayId);
        }
        }
        return true;
    }
    }


    void performComputeChangedWindowsNot(int displayId, boolean forceSend) {
    void performComputeChangedWindowsNot(int displayId, boolean forceSend) {
@@ -507,54 +483,6 @@ final class AccessibilityController {
        }
        }
    }
    }


    void handleWindowObserverOfEmbeddedDisplay(int embeddedDisplayId,
            WindowState parentWindow) {
        handleWindowObserverOfEmbeddedDisplay(
                embeddedDisplayId, parentWindow, Binder.getCallingUid());
    }

    void handleWindowObserverOfEmbeddedDisplay(
            int embeddedDisplayId, WindowState parentWindow, int callingUid) {
        if (mAccessibilityTracing.isTracingEnabled(FLAGS_WINDOWS_FOR_ACCESSIBILITY_CALLBACK)) {
            mAccessibilityTracing.logTrace(TAG + ".handleWindowObserverOfEmbeddedDisplay",
                    FLAGS_WINDOWS_FOR_ACCESSIBILITY_CALLBACK,
                    "embeddedDisplayId=" + embeddedDisplayId + "; parentWindowState={"
                    + parentWindow + "}", "".getBytes(), callingUid);
        }
        if (embeddedDisplayId == Display.DEFAULT_DISPLAY || parentWindow == null) {
            return;
        }
        mService.mH.sendMessage(PooledLambda.obtainMessage(
                AccessibilityController::updateWindowObserverOfEmbeddedDisplay,
                this, embeddedDisplayId, parentWindow));
    }

    private void updateWindowObserverOfEmbeddedDisplay(int embeddedDisplayId,
            WindowState parentWindow) {
        final WindowsForAccessibilityObserver windowsForA11yObserver;

        synchronized (mService.mGlobalLock) {
            // Finds the parent display of this embedded display
            WindowState candidate = parentWindow;
            while (candidate != null) {
                parentWindow = candidate;
                candidate = parentWindow.getDisplayContent().getParentWindow();
            }
            final int parentDisplayId = parentWindow.getDisplayId();
            // Uses the observer of parent display
            windowsForA11yObserver = mWindowsForAccessibilityObserver.get(parentDisplayId);
        }

        if (windowsForA11yObserver != null) {
            windowsForA11yObserver.notifyDisplayReparented(embeddedDisplayId);
            windowsForA11yObserver.addEmbeddedDisplay(embeddedDisplayId);
            synchronized (mService.mGlobalLock) {
                // Replaces the observer of embedded display to the one of parent display
                mWindowsForAccessibilityObserver.put(embeddedDisplayId, windowsForA11yObserver);
            }
        }
    }

    void onImeSurfaceShownChanged(WindowState windowState, boolean shown) {
    void onImeSurfaceShownChanged(WindowState windowState, boolean shown) {
        if (mAccessibilityTracing.isTracingEnabled(FLAGS_MAGNIFICATION_CALLBACK)) {
        if (mAccessibilityTracing.isTracingEnabled(FLAGS_MAGNIFICATION_CALLBACK)) {
            mAccessibilityTracing.logTrace(TAG + ".onImeSurfaceShownChanged",
            mAccessibilityTracing.logTrace(TAG + ".onImeSurfaceShownChanged",
@@ -584,23 +512,6 @@ final class AccessibilityController {
                + "mWindowsForAccessibilityObserver=" + mWindowsForAccessibilityObserver);
                + "mWindowsForAccessibilityObserver=" + mWindowsForAccessibilityObserver);
    }
    }


    private void removeObserversForEmbeddedChildDisplays(WindowsForAccessibilityObserver
            observerOfParentDisplay) {
        final IntArray embeddedDisplayIdList =
                observerOfParentDisplay.getAndClearEmbeddedDisplayIdList();

        for (int index = 0; index < embeddedDisplayIdList.size(); index++) {
            final int embeddedDisplayId = embeddedDisplayIdList.get(index);
            mWindowsForAccessibilityObserver.remove(embeddedDisplayId);
        }
    }

    private static boolean isEmbeddedDisplay(DisplayContent dc) {
        final Display display = dc.getDisplay();

        return display.getType() == Display.TYPE_VIRTUAL && dc.getParentWindow() != null;
    }

    /**
    /**
     * This class encapsulates the functionality related to display magnification.
     * This class encapsulates the functionality related to display magnification.
     */
     */
@@ -1534,8 +1445,6 @@ final class AccessibilityController {


        private final long mRecurringAccessibilityEventsIntervalMillis;
        private final long mRecurringAccessibilityEventsIntervalMillis;


        private final IntArray mEmbeddedDisplayIdList = new IntArray(0);

        // Set to true if initializing window population complete.
        // Set to true if initializing window population complete.
        private boolean mInitialized;
        private boolean mInitialized;


@@ -1573,28 +1482,6 @@ final class AccessibilityController {
            }
            }
        }
        }


        IntArray getAndClearEmbeddedDisplayIdList() {
            final IntArray returnedArray = new IntArray(mEmbeddedDisplayIdList.size());
            returnedArray.addAll(mEmbeddedDisplayIdList);
            mEmbeddedDisplayIdList.clear();

            return returnedArray;
        }

        void addEmbeddedDisplay(int displayId) {
            if (displayId == mDisplayId) {
                return;
            }
            mEmbeddedDisplayIdList.add(displayId);
        }

        void notifyDisplayReparented(int embeddedDisplayId) {
            // Notifies the A11y framework the display is reparented and
            // becomes an embedded display for removing the un-used
            // displayWindowObserver of this embedded one.
            mCallback.onDisplayReparented(embeddedDisplayId);
        }

        boolean shellRootIsAbove(WindowState windowState, ShellRoot shellRoot) {
        boolean shellRootIsAbove(WindowState windowState, ShellRoot shellRoot) {
            int wsLayer = mService.mPolicy.getWindowLayerLw(windowState);
            int wsLayer = mService.mPolicy.getWindowLayerLw(windowState);
            int shellLayer = mService.mPolicy.getWindowLayerFromTypeLw(shellRoot.getWindowType(),
            int shellLayer = mService.mPolicy.getWindowLayerFromTypeLw(shellRoot.getWindowType(),
@@ -1761,12 +1648,7 @@ final class AccessibilityController {
                addedWindows.clear();
                addedWindows.clear();


                // Gets the top focused display Id and window token for supporting multi-display.
                // Gets the top focused display Id and window token for supporting multi-display.
                // If this top focused display is an embedded one, using its parent display as the
                topFocusedDisplayId = mService.mRoot.getTopFocusedDisplayContent().getDisplayId();
                // top focused display.
                final DisplayContent topFocusedDisplayContent =
                        mService.mRoot.getTopFocusedDisplayContent();
                topFocusedDisplayId = isEmbeddedDisplay(topFocusedDisplayContent) ? mDisplayId
                        : topFocusedDisplayContent.getDisplayId();
                topFocusedWindowToken = topFocusedWindowState.mClient.asBinder();
                topFocusedWindowToken = topFocusedWindowState.mClient.asBinder();
            }
            }
            mCallback.onWindowsForAccessibilityChanged(forceSend, topFocusedDisplayId,
            mCallback.onWindowsForAccessibilityChanged(forceSend, topFocusedDisplayId,
@@ -1970,8 +1852,6 @@ final class AccessibilityController {
        public String toString() {
        public String toString() {
            return "WindowsForAccessibilityObserver{"
            return "WindowsForAccessibilityObserver{"
                    + "mDisplayId=" + mDisplayId
                    + "mDisplayId=" + mDisplayId
                    + ", mEmbeddedDisplayIdList="
                    + Arrays.toString(mEmbeddedDisplayIdList.toArray())
                    + ", mInitialized=" + mInitialized
                    + ", mInitialized=" + mInitialized
                    + '}';
                    + '}';
        }
        }
+1 −12
Original line number Original line Diff line number Diff line
@@ -122,16 +122,6 @@ public abstract class WindowManagerInternal {
         */
         */
        void onWindowsForAccessibilityChanged(boolean forceSend, int topFocusedDisplayId,
        void onWindowsForAccessibilityChanged(boolean forceSend, int topFocusedDisplayId,
                IBinder topFocusedWindowToken, @NonNull List<WindowInfo> windows);
                IBinder topFocusedWindowToken, @NonNull List<WindowInfo> windows);

        /**
         * Called when the display is reparented and becomes an embedded
         * display. The {@link WindowsForAccessibilityCallback} with the given embedded
         * display will be replaced by the {@link WindowsForAccessibilityCallback}
         * associated with its parent display at the same time.
         *
         * @param embeddedDisplayId The embedded display Id.
         */
        void onDisplayReparented(int embeddedDisplayId);
    }
    }


    /**
    /**
@@ -375,9 +365,8 @@ public abstract class WindowManagerInternal {
     *
     *
     * @param displayId The logical display id.
     * @param displayId The logical display id.
     * @param callback The callback.
     * @param callback The callback.
     * @return {@code false} if display id is not valid.
     */
     */
    public abstract boolean setWindowsForAccessibilityCallback(int displayId,
    public abstract void setWindowsForAccessibilityCallback(int displayId,
            WindowsForAccessibilityCallback callback);
            WindowsForAccessibilityCallback callback);


    /**
    /**
+2 −4
Original line number Original line Diff line number Diff line
@@ -7453,20 +7453,18 @@ public class WindowManagerService extends IWindowManager.Stub
        }
        }


        @Override
        @Override
        public boolean setWindowsForAccessibilityCallback(int displayId,
        public void setWindowsForAccessibilityCallback(int displayId,
                WindowsForAccessibilityCallback callback) {
                WindowsForAccessibilityCallback callback) {
            synchronized (mGlobalLock) {
            synchronized (mGlobalLock) {
                if (mAccessibilityController == null) {
                if (mAccessibilityController == null) {
                    mAccessibilityController = new AccessibilityController(
                    mAccessibilityController = new AccessibilityController(
                            WindowManagerService.this);
                            WindowManagerService.this);
                }
                }
                final boolean result =
                mAccessibilityController.setWindowsForAccessibilityCallback(
                mAccessibilityController.setWindowsForAccessibilityCallback(
                        displayId, callback);
                        displayId, callback);
                if (!mAccessibilityController.hasCallbacks()) {
                if (!mAccessibilityController.hasCallbacks()) {
                    mAccessibilityController = null;
                    mAccessibilityController = null;
                }
                }
                return result;
            }
            }
        }
        }


+0 −16
Original line number Original line Diff line number Diff line
@@ -30,7 +30,6 @@ import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.eq;
@@ -836,19 +835,6 @@ public class AccessibilityWindowManagerTest {
        assertNull(token);
        assertNull(token);
    }
    }


    @Test
    public void onDisplayReparented_shouldRemoveObserver() throws RemoteException {
        // Starts tracking window of second display.
        startTrackingPerDisplay(SECONDARY_DISPLAY_ID);
        assertTrue(mA11yWindowManager.isTrackingWindowsLocked(SECONDARY_DISPLAY_ID));
        // Notifies the second display is an embedded one of the default display.
        final WindowsForAccessibilityCallback callbacks =
                mCallbackOfWindows.get(Display.DEFAULT_DISPLAY);
        callbacks.onDisplayReparented(SECONDARY_DISPLAY_ID);
        // Makes sure the observer of the second display is removed.
        assertFalse(mA11yWindowManager.isTrackingWindowsLocked(SECONDARY_DISPLAY_ID));
    }

    private void registerLeashedTokenAndWindowId() {
    private void registerLeashedTokenAndWindowId() {
        mA11yWindowManager.registerIdLocked(mMockHostToken, HOST_WINDOW_ID);
        mA11yWindowManager.registerIdLocked(mMockHostToken, HOST_WINDOW_ID);
        mA11yWindowManager.registerIdLocked(mMockEmbeddedToken, EMBEDDED_WINDOW_ID);
        mA11yWindowManager.registerIdLocked(mMockEmbeddedToken, EMBEDDED_WINDOW_ID);
@@ -878,8 +864,6 @@ public class AccessibilityWindowManagerTest {
            windowInfosForDisplay.get(DEFAULT_FOCUSED_INDEX).focused = true;
            windowInfosForDisplay.get(DEFAULT_FOCUSED_INDEX).focused = true;
        }
        }
        // Turns on windows tracking, and update window info.
        // Turns on windows tracking, and update window info.
        when(mMockWindowManagerInternal.setWindowsForAccessibilityCallback(eq(displayId), any()))
                .thenReturn(true);
        mA11yWindowManager.startTrackingWindows(displayId);
        mA11yWindowManager.startTrackingWindows(displayId);
        // Puts window lists into array.
        // Puts window lists into array.
        mWindowInfos.put(displayId, windowInfosForDisplay);
        mWindowInfos.put(displayId, windowInfosForDisplay);