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

Commit 239677da authored by Phil Weaver's avatar Phil Weaver
Browse files

Notify system when uiAutomation terminates

When the binder died, the system wasn't finding out,
so it got into an inconsistent state and told client
apps that accessibility wasn't enabled when it actually
was.

Also fixing dumping of uiautomation, which was failing
with an NPE.

Fixes: 70338333
Fixes: 70227110
Test: Repro case in 70227110 no longer fails.
Ran a11y and UiAutomation CTS.
Ran a11y system server unit tests, and added one to verify
the new behavior.
Change-Id: I4fa6067f8316114a925de86d3fac611e6196da3e
parent 175b0092
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -749,7 +749,6 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
    public void unregisterUiTestAutomationService(IAccessibilityServiceClient serviceClient) {
        synchronized (mLock) {
            mUiAutomationManager.unregisterUiTestAutomationServiceLocked(serviceClient);
            onUserStateChangedLocked(getCurrentUserStateLocked());
        }
    }

+16 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.os.RemoteException;
import android.util.Slog;
import android.view.accessibility.AccessibilityEvent;

import com.android.internal.util.DumpUtils;
import com.android.server.wm.WindowManagerInternal;

import java.io.FileDescriptor;
@@ -45,6 +46,8 @@ class UiAutomationManager {

    private AccessibilityServiceInfo mUiAutomationServiceInfo;

    private AccessibilityClientConnection.SystemSupport mSystemSupport;

    private int mUiAutomationFlags;

    private IBinder mUiAutomationServiceOwner;
@@ -92,6 +95,7 @@ class UiAutomationManager {
            return;
        }

        mSystemSupport = systemSupport;
        mUiAutomationService = new UiAutomationService(context, accessibilityServiceInfo, id,
                mainHandler, lock, securityPolicy, systemSupport, windowManagerInternal,
                globalActionPerfomer);
@@ -169,6 +173,7 @@ class UiAutomationManager {
            mUiAutomationServiceOwner.unlinkToDeath(mUiAutomationServiceOwnerDeathRecipient, 0);
            mUiAutomationServiceOwner = null;
        }
        mSystemSupport.onClientChange(false);
    }

    private class UiAutomationService extends AccessibilityClientConnection {
@@ -224,6 +229,17 @@ class UiAutomationManager {
            return true;
        }

        @Override
        public void dump(FileDescriptor fd, final PrintWriter pw, String[] args) {
            if (!DumpUtils.checkDumpPermission(mContext, LOG_TAG, pw)) return;
            synchronized (mLock) {
                pw.append("Ui Automation[eventTypes="
                        + AccessibilityEvent.eventTypeToString(mEventTypes));
                pw.append(", notificationTimeout=" + mNotificationTimeout);
                pw.append("]");
            }
        }

        // Since this isn't really an accessibility service, several methods are just stubbed here.
        @Override
        public boolean setSoftKeyboardShowMode(int mode) {
+2 −1
Original line number Diff line number Diff line
@@ -153,13 +153,14 @@ public class UiAutomationManagerTest {
    }

    @Test
    public void uiAutomationBinderDiesBeforeConnecting_shouldNotCrash() throws Exception {
    public void uiAutomationBinderDiesBeforeConnecting_notifiesSystem() throws Exception {
        register(0);
        ArgumentCaptor<IBinder.DeathRecipient> captor = ArgumentCaptor.forClass(
                IBinder.DeathRecipient.class);
        verify(mMockOwner).linkToDeath(captor.capture(), anyInt());
        captor.getValue().binderDied();
        mMessageCapturingHandler.sendAllMessages();
        verify(mMockSystemSupport).onClientChange(false);
    }

    private void register(int flags) {