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

Commit 5bbc3013 authored by Qasid Sadiq's avatar Qasid Sadiq
Browse files

Make sure keys get flushed when connection falls apart.

This is for the event that a key has been intercepted, sent to the app,
and the app hasn't handled it yet. If the connection dies, the key is
lost. So flush all pending keys.

Test: Unit test (this would have caught me introducing this bug in the
first place).

Bug:74593001
Change-Id: I5a94aafe5c58f18a3e9ca46f7cd5a9cb71d38aaa
parent cf0aa64b
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -258,6 +258,7 @@ class AccessibilityServiceConnection extends AbstractAccessibilityServiceConnect
                return;
            }
            mWasConnectedAndDied = true;
            mSystemSupport.getKeyEventDispatcher().flush(this);
            UserState userState = mUserStateWeakReference.get();
            if (userState != null) {
                userState.serviceDisconnectedLocked(this);
+11 −0
Original line number Diff line number Diff line
@@ -141,4 +141,15 @@ public class AccessibilityServiceConnectionTest {
        when(mMockUserState.getBindingServicesLocked())
                .thenReturn(new HashSet<>(Arrays.asList(componentName)));
    }

    @Test
    public void binderDied_keysGetFlushed() {
        IBinder mockBinder = mock(IBinder.class);
        setServiceBinding(COMPONENT_NAME);
        mConnection.bindLocked();
        mConnection.onServiceConnected(COMPONENT_NAME, mockBinder);
        mConnection.binderDied();
        assertTrue(mConnection.getServiceInfo().crashed);
        verify(mMockKeyEventDispatcher).flush(mConnection);
    }
}