Reapply "Finish BrightnessDialog when shade is opened."

This reverts commit b1dbb465b03d26e071aa38a9f85ae233bf92e882.
The test flakiness observed with the original commit is fixed by using
Flow to track the state of the activity instead of a boolean.

Test: BrightnessDialogTest#testFinishOnQSExpanded --rerun-until-failure 20
Flag: None
Fixes: 243630115
Change-Id: I7574a0ec1bf09e589049fc1c659b2279a4a42336
2 files changed