Finish DreamActivity on creation if it is obsolete

DreamService keeps a reference to its DreamActivity, and finishes it
when the dream stops. This reference is set when the DreamActivity
receives its onCreate lifecycle callback.

If a dream is stopped shortly after it started, before its DreamActivity
was created, the DreamActivity can be created after the dream is
supposed to be finished, and finish isn't called on the activity.
If another dream starts another DreamActivity, the reference to the old
DreamActivity is overwritten and lost, so that DreamService can no
longer finish the old DreamActivity.

This change tracks the DreamToken, unique to each dream, that an
activity was started for. If an activity is created for a dream that is
already finished, the activity is finished immediately.

Bug: 229561570
Test: manual, with adding delay before startDreamActivity to ease
      reproduction
Change-Id: I0fca226855ee4e2317ac807a4c87c8656c72169b
2 files changed