Fix crash when trying to dismiss dialog

Calling Dialog.dismiss() requires a safe condition, including that
dialog is shown,and activity is neither finishing nor destroying, so we
should add a precondition check here to avoid crash.

Bug: 248562161
Test: manual and atest
Change-Id: I87de2cd05680815d4bb4e80ac1e0d6e2e4a685f7
1 file changed