Dialog denies access automatically when disappear (new test is added)

Originally, dialog does not deny access on “return home” and “lock screen” until timeout passes because nothing triggers a decline in log access action in onStop(). Therefore, onStop() is overridden in this change, which calls cancel() in Dialog. As a result, every time the dialog disappears, onDismiss() is guaranteed to be called and will trigger declineLogAccess() immediately. This also fixes the case where users lock the screen without clicking any button on the dialog.

Additionally, a new test for LogAccessDialogActivity is created and added to SystemUI/tests. LogAccessDialogActivityTest.java is an instrumented test which verifies the behavior of the activity when:
	1. the state moves to onStop (whenever dialog disappears)
	2. onClick() is called and view.getId() == R.id.log_access_dialog_allow_button
	3. onClick() is called and view.getId() == R.id.log_access_dialog_deny_button

Some other small changes for improvement:

	1. Original onClick() calls finish() at the end of every case, which is unnecessary. It’s better to not call finish() manually since it will be called whenever a dialog is in onDismiss() and the original onClick() will result in finish() being called unnecessarily repeatedly. Thus, mAlert.dismiss() is added into a “FINALLY” block in onClick().
	2. Add “mAlert = null” in setOnDismissListener and delete some redundant settings of “mAlert = null” in other places.
	3. onDestroy() is not needed anymore because it has mostly the same logic as onStop(). In addition, because mAlert is set to NULL whenever it enters into onDismiss(), it’s almost impossible to enter into the if statement block in the original onDestroy()

Test: atest SystemUITests:LogAccessDialogTest
Bug: 244005521
Change-Id: I62b7f0e5ebeb29d5a4f09b4cf42b1a7e0a235a62
3 files changed