Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 06683b53 authored by Ricardo Cerqueira's avatar Ricardo Cerqueira
Browse files

GlobalActions: Fix possible race condition when showing dialog.

Depending on the presence of a previous dialog, the newly generated one
gets either immediately displayed (no old dialog) or shortly delayed
(after dismissal of the existing one).
If a new show event happens (by rapid fire of the power key, for instance,
using a keyboard with fast-repeating events) during that delay, a new
dialog will be immediately displayed, and when the delayed show triggers
it'll conflict with it (and bring everything down).

This moves the creation of the new Dialog object to _before_ showing
it (delayed or not), instead of the show method itself, to ensure the
object isn't clobbered by competing/sequential calls to handleShow()

Change-Id: Ie4d9a8507ebaf59da31869c38b98c3c98a74468e
parent 4607ac5a
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -173,9 +173,11 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
            }
            mDialog.dismiss();
            mDialog = null;
            mDialog = createDialog();
            // Show delayed, so that the dismiss of the previous dialog completes
            mHandler.sendEmptyMessage(MESSAGE_SHOW);
        } else {
            mDialog = createDialog();
            handleShow();
        }
    }
@@ -194,7 +196,6 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac

    private void handleShow() {
        awakenIfNecessary();
        mDialog = createDialog();
        prepareDialog();

        WindowManager.LayoutParams attrs = mDialog.getWindow().getAttributes();