Merge "Wait until any background events are processed." into stage-aosp-master