Fix incomplete removal of nested task

For example:
T0 - T1 - A1 <- iterator
     T2 - A2
After calling A1.finishIfPossible(), the order may change to
T0 - T2 - A2
     T1 - A1 <- iterator
So A1 is finished twice (no-op) and T0 can not be removed because
A2 is still alive. This part is solved by using a list to collect
first. And change the cleanup order to from bottom to top, which
avoid some unnecessary focus adjusting.

Another problem is that when removing last task of a parent task,
it only checks !mCreatedByOrganizer, so the removal request is
ignored. This is fixed by checking shouldRemoveSelfOnLastChildRemoval.

Fixes: 222722020
Test: atest TaskTests#testRemoveContainer_multipleNestedTasks
Change-Id: I3a5cb17be57fae758f57e2d2c669cc3727346ff8
3 files changed