Fix focused stack adjustment when finishing top activity

Since commit f2835df035, a stack won't be visible if it doesn't
contain running activity. So when checking if the stack order
needs to be adjusted after the top activity is set as finishing,
the adjustment will be skipped by invisible stack. It is resolved
by checking before the activity becomes finishing.

Also remove the activity focus adjustment in stopActivityLocked
because the original condition should be never satisfied: only
adjust for resumed activity in top focused stack. That doesn't
seem to be the condition for an activity that can be stopped.
So the adjustment logic becomes simpler to be inlined.

Bug: 138519583
Test: atest ActivityRecordTests#testFinishActivityIfPossible_adjustStackOrder

Change-Id: I0a0edc3f28acc4eb435dbbf2c71ab6119b155c39
3 files changed