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

Commit f1b37ca1 authored by Biswarup Pal's avatar Biswarup Pal Committed by Android (Google) Code Review
Browse files

Merge "Notify stability calculator on failed text insertion." into main

parents e9cf7306 64fc5a83
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -388,6 +388,7 @@ final class ComputerControlSessionImpl extends IComputerControlSession.Stub
            notifyNonContinuousInputToStabilityCalculator();
        } else {
            Slog.e(TAG, "Invalid action code for performAction: " + actionCode);
            notifyInteractionFailedToStabilityCalculator();
        }
    }

@@ -421,6 +422,7 @@ final class ComputerControlSessionImpl extends IComputerControlSession.Stub
                    mVirtualDisplayId);
            if (ic == null) {
                Slog.e(TAG, "Unable to insert text: No input connection found!");
                notifyInteractionFailedToStabilityCalculator();
                return;
            }
            // TODO(b/422134565): Implement client invoker logic to pass the correct session id when
@@ -637,6 +639,15 @@ final class ComputerControlSessionImpl extends IComputerControlSession.Stub
        }
    }

    // TODO(b/428957982): Remove once we implement actual stability signals from the framework.
    private void notifyInteractionFailedToStabilityCalculator() {
        synchronized (mStabilityCalculatorLock) {
            if (mStabilityCalculator != null) {
                mStabilityCalculator.onInteractionFailed();
            }
        }
    }

    private class ComputerControlActivityListener extends IVirtualDeviceActivityListener.Stub {
        @Override
        public void onTopActivityChanged(int displayId, ComponentName topActivity,
+19 −5
Original line number Diff line number Diff line
@@ -58,6 +58,10 @@ final class StabilityCalculator {
        notifyListenerAfter(APPLICATION_LAUNCH_STABILITY_TIMEOUT_MS);
    }

    void onInteractionFailed() {
        notifyListenerImmediately();
    }

    void close() {
        cancelExistingStabilityNotification();
    }
@@ -66,11 +70,7 @@ final class StabilityCalculator {
        cancelExistingStabilityNotification();

        ScheduledFuture<?> future = mScheduler.schedule(() -> {
            try {
                mListener.onSessionStable();
            } catch (RemoteException e) {
                Slog.w(TAG, "Failed to notify about ComputerControlSession stability");
            }
            sendStableNotification();
        }, timeoutMs, TimeUnit.MILLISECONDS);

        synchronized (this) {
@@ -78,10 +78,24 @@ final class StabilityCalculator {
        }
    }

    private void notifyListenerImmediately() {
        cancelExistingStabilityNotification();
        sendStableNotification();
    }

    private void sendStableNotification() {
        try {
            mListener.onSessionStable();
        } catch (RemoteException e) {
            Slog.w(TAG, "Failed to notify about ComputerControlSession stability");
        }
    }

    private void cancelExistingStabilityNotification() {
        synchronized (this) {
            if (mStabilityFuture != null) {
                mStabilityFuture.cancel(true);
                mStabilityFuture = null;
            }
        }
    }
+35 −0
Original line number Diff line number Diff line
@@ -489,8 +489,32 @@ public class ComputerControlSessionTest {
    }

    @Test
    public void performAction_withInvalidCode_notifiesStabilityListener() throws Exception {
        createComputerControlSession(mDefaultParams);
        mSession.setStabilityListener(mStabilityListener);

        mSession.performAction(-1);

        verify(mStabilityListener).onSessionStable();
    }

    @Test
    @DisableFlags(Flags.FLAG_COMPUTER_CONTROL_TYPING)
    public void insertTextLegacy_notifiesStabilityListener() throws Exception {
        createComputerControlSession(mDefaultParams);
        mSession.setStabilityListener(mStabilityListener);

        mSession.insertText("hello", false /* replaceExisting */, true /* commit */);

        verify(mStabilityListener, timeout(STABILITY_TIMEOUT_MS)).onSessionStable();
    }

    @Test
    @EnableFlags(Flags.FLAG_COMPUTER_CONTROL_TYPING)
    public void insertText_notifiesStabilityListener() throws Exception {
        createComputerControlSession(mDefaultParams);
        when(mInjector.getInputConnection(VIRTUAL_DISPLAY_ID)).thenReturn(
                mRemoteComputerControlInputConnection);
        mSession.setStabilityListener(mStabilityListener);

        mSession.insertText("hello", false /* replaceExisting */, true /* commit */);
@@ -498,6 +522,17 @@ public class ComputerControlSessionTest {
        verify(mStabilityListener, timeout(STABILITY_TIMEOUT_MS)).onSessionStable();
    }

    @Test
    @EnableFlags(Flags.FLAG_COMPUTER_CONTROL_TYPING)
    public void insertText_withNoInputConnection_notifiesStabilityListener() throws Exception {
        createComputerControlSession(mDefaultParams);
        mSession.setStabilityListener(mStabilityListener);

        mSession.insertText("hello", false /* replaceExisting */, true /* commit */);

        verify(mStabilityListener).onSessionStable();
    }

    @Test
    public void swipe_notifiesStabilityListener() throws Exception {
        createComputerControlSession(mDefaultParams);