Dialog not dismissed when tearing down dialog fragment.
Dialog not dismissed when tearing down dialog fragment.

1. The dismiss implementaton in Dialog was posting a message
   on the main thread to perform the real dismiss work. The
   goal of this was to allow calling dismiss() from multiple
   threads. The side effect of this is that when dialog fragment
   is dismissed the dialog is not dimissed until the current
   loop on the main thread is completed. However, during rotation
   of the screen the current activity has to be restarted, hence
   all fragments whould be removed. In the destruction process
   the dialog grament requests from the dialog to dismiss but
   since this is asynchromous, the code in
   ActivityThread#handleDestroyActivity detects a leaking window
   since the dialog window is still not removed and removes that
   window. Now when the dialog removal message is processed on
   the next loop we get an exception that the window has already
   been removed. Now if Dialog#dismiss() is called from the
   main thread the call goes right though otherwise a message is
   posted.

bug:5911682

Change-Id: I449d6dd75a84c0ff29ea13dac7d163219cc38341

xorware/android_frameworks_base,xorware/android_frameworks_base,xorware/android_frameworks_base,xorware/android_frameworks_base,xorware/android_frameworks_base,xorware/android_frameworks_base