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

Commit bce17f97 authored by ryanlwlin's avatar ryanlwlin
Browse files

Fix strictMode violation in Accesibility Service

From Android R, using the WindowManager from non-ui context
violates the vm policy. It may cause incorrect window bounds
with the given floating window. AccessibilityService provides
Accesibility overlay usage that needs to set window token to
the windowManager. However, Setting it when the service is bounded
violates the policy.
To fixt it, we set the window token when developers get WindowManager
first time.

Bug: 175785781
Test: atest AccessibilityOverlayTest, use the test apk to check if
the warning message is shown in the log
      manual test to see if SelectToSpeak works well
Change-Id: Ia873488626aa4da111499282d1971f836cf111cd

Change-Id: Ia87df60c393bb0e40d85ced4184c78a09d7b427b
parent 5c990f82
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -2074,6 +2074,10 @@ public abstract class AccessibilityService extends Service {
        if (WINDOW_SERVICE.equals(name)) {
            if (mWindowManager == null) {
                mWindowManager = (WindowManager) getBaseContext().getSystemService(name);
                final WindowManagerImpl wm = (WindowManagerImpl) mWindowManager;
                // Set e default token obtained from the connection to ensure client could use
                // accessibility overlay.
                wm.setDefaultToken(mWindowToken);
            }
            return mWindowManager;
        }
@@ -2182,8 +2186,10 @@ public abstract class AccessibilityService extends Service {

                // The client may have already obtained the window manager, so
                // update the default token on whatever manager we gave them.
                final WindowManagerImpl wm = (WindowManagerImpl) getSystemService(WINDOW_SERVICE);
                wm.setDefaultToken(windowToken);
                if (mWindowManager != null) {
                    final WindowManagerImpl wm = (WindowManagerImpl) mWindowManager;
                    wm.setDefaultToken(mWindowToken);
                }
            }

            @Override