Refactor ActivityRecord#finish* methods

Updated ActivityRecord#finish* methods and to separate their purposes
and use better suited names.

ActivityRecord#finishIfPossible - start of activity finishing. In
most cases will first pause activity and wait for it to report back.

ActivityRecord#completeFinishing - second stage of the process, when
activity is no longer resumed. Usually will be called from 'paused'
callback on the server. If the next activity that should be shown in
place of the current one is not visible yet - it will defer the
finishing process and add the current activity to stopping list. If
next is already visible - will finish immediately.

ActivityRecord#destroyIfPossible - called when activity is ready to
be destroyed, or when the caller does not want to wait. Will initiate
the client destruction immediately, unless it's the last activity on
display.

Bug: 137329632
Test: atest CtsWindowManagerDeviceTestCases:android.server.wm.lifecycle
Test: atest WmTests:ActivityRecordTests
Change-Id: Id6e6dae306e2af91e9e00d9e66c416b13810ad93
diff --git a/services/core/java/com/android/server/wm/ActivityTaskManagerService.java b/services/core/java/com/android/server/wm/ActivityTaskManagerService.java
index 7283ca5..04dab40 100644
--- a/services/core/java/com/android/server/wm/ActivityTaskManagerService.java
+++ b/services/core/java/com/android/server/wm/ActivityTaskManagerService.java
@@ -86,6 +86,7 @@
 import static com.android.server.wm.ActivityStack.REMOVE_TASK_MODE_DESTROYING;
 import static com.android.server.wm.ActivityStackSupervisor.DEFER_RESUME;
 import static com.android.server.wm.ActivityStackSupervisor.ON_TOP;
+import static com.android.server.wm.ActivityStackSupervisor.PAUSE_IMMEDIATELY;
 import static com.android.server.wm.ActivityStackSupervisor.PRESERVE_WINDOWS;
 import static com.android.server.wm.ActivityStackSupervisor.REMOVE_FROM_RECENTS;
 import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_ALL;
@@ -1614,8 +1615,8 @@
                     // Explicitly dismissing the activity so reset its relaunch flag.
                     r.mRelaunchReason = RELAUNCH_REASON_NONE;
                 } else {
-                    r.finishActivityLocked(resultCode, resultData, "app-request",
-                            true /* oomAdj */);
+                    r.finishIfPossible(resultCode, resultData, "app-request",
+                            true /* oomAdj */, !PAUSE_IMMEDIATELY);
                     res = r.finishing;
                     if (!res) {
                         Slog.i(TAG, "Failed to finish by app-request");