Fix race condition in checkPattern and verifyPattern. am: 9475460e66
am: ce2cef46b3

Change-Id: I7777ce413f30d99d4712bd9aa4a2b4f5f371403f