Do not always destroy activity when cleaning up.

There are some invocations of ActivityStack#cleanUpActivityLocked
where the activity is not removed from history. In this case, we
want to keep the ActivityRecord around, but clear the process.
Previously, we were also setting the state to destroy. This is
inconsistent with the client side state, which is still in the
stopped state. With recent changes, this state change now causes
the server side record to be destroyed, removing it from history
and causing it to not return on back traversal.

This changelist separates clearing the app process from setting the
activity state, allowing for the record to remain when appropriate.

Bug: 71506345
Test: atest CtsActivityManagerDeviceTestCases:ActivityLifecycleTests#testRestoreFromKill
Test: atest FrameworksServicesTests:com.android.server.am.ActivityRecordTests#testFinishingAfterDestroying
Test: atest FrameworksServicesTests:com.android.server.am.ActivityRecordTests#testFinishingAfterDestroyed
Change-Id: I98366a1b51d8d4d002536683c6335ee57c22129c
3 files changed