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

Commit b99f5c84 authored by Winson Chung's avatar Winson Chung
Browse files

Prevent other organizer lifecycle events if taskAppeared fails

- In the unlikely scenario that onTaskAppeared() fails, we should not
  send any other organizer events otherwise it violates the expected
  lifecycle of tasks in ShellTaskOrganizer

Bug: 404475663
Flag: EXEMPT bugfix
Test: atest WindowOrganizerTests

Change-Id: I8495d0c296a141b1866c021b6501fbd1242dd33d
parent 0219d4b6
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -68,6 +68,8 @@ import java.util.WeakHashMap;
/**
 * Stores the TaskOrganizers associated with a given windowing mode and
 * their associated state.
 *
 * Current tests can be found in WindowOrganizerTests.
 */
class TaskOrganizerController extends ITaskOrganizerController.Stub {
    private static final String TAG = "TaskOrganizerController";
@@ -121,6 +123,11 @@ class TaskOrganizerController extends ITaskOrganizerController.Stub {
                mTaskOrganizer.onTaskAppeared(taskInfo, leash);
            } catch (RemoteException e) {
                Slog.e(TAG, "Exception sending onTaskAppeared callback", e);

                // In the rare case that onTaskAppeared() fails to notify, then we should prevent
                // subsequent lifecycle calls to shell to prevent it from getting an inconsistent
                // set of calls
                task.mTaskAppearedSent = false;
            } finally {
                leash.release();
            }
+32 −1
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ import static android.window.DisplayAreaOrganizer.FEATURE_VENDOR_FIRST;

import static com.android.dx.mockito.inline.extended.ExtendedMockito.doNothing;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doThrow;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.mockitoSession;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.never;
@@ -1363,7 +1364,8 @@ public class WindowOrganizerTests extends WindowTestsBase {
        @Override
        public void copySplashScreenView(int taskId) { }
        @Override
        public void onTaskAppeared(RunningTaskInfo info, SurfaceControl leash) {
        public void onTaskAppeared(RunningTaskInfo info, SurfaceControl leash)
                throws RemoteException {
            mInfo = info;
        }
        @Override
@@ -1784,6 +1786,35 @@ public class WindowOrganizerTests extends WindowTestsBase {
                pendingEvents.get(0).mTask.getTaskInfo().taskDescription.getLabel());
    }

    @Test
    public void testAppearFailed_ignoreOtherLifecycleCalls() throws RemoteException {
        // Set up a task organizer that throws from onTaskAppeared
        final ITaskOrganizer organizer = createMockOrganizer();
        doThrow(new RemoteException()).when(organizer).onTaskAppeared(any(), any());
        mWm.mAtmService.mTaskOrganizerController.registerTaskOrganizer(organizer);

        // Create a task and notify the organizer
        final Task rootTask = createRootTask();
        final Task task = createTask(rootTask);
        task.setTaskOrganizer(organizer);
        final ActivityRecord activity = createActivityRecord(rootTask.mDisplayContent, task);
        mAtm.mTaskOrganizerController.dispatchPendingEvents();

        // Ensure that the exception resulted in the task appeared state to be reset and future
        // updates are not sent to it
        assertThat(task.mTaskAppearedSent).isFalse();

        // Ignore subsequent task info changes
        activity.setTaskDescription(new ActivityManager.TaskDescription("TestDescription"));
        mAtm.mTaskOrganizerController.dispatchPendingEvents();
        verify(organizer, never()).onTaskInfoChanged(any());

        // Ignore subsequent vanished calls
        rootTask.removeImmediately();
        mAtm.mTaskOrganizerController.dispatchPendingEvents();
        verify(organizer, never()).onTaskVanished(any());
    }

    @Test
    public void testReorderWithParents() {
        /*