Watchdog race condition when sending message out of synchronized

A race condition leading to false positive detections might occur
when the monitoring thread executes very fast and terminates before
the sending thread entered the synchronized section.

Change-Id: I6fe686f8f12393e11fa18326508af5b73738f9d7
Author: Jean-Christophe PINCE <jean-christophe.pince@intel.com>
Signed-off-by: Jean-Christophe PINCE <jean-christophe.pince@intel.com>
Signed-off-by: Shuo Gao <shuo.gao@intel.com>
Signed-off-by: Bruce Beare <bruce.j.beare@intel.com>
Signed-off-by: Jack Ren <jack.ren@intel.com>
Author-tracking-BZ: 81644
diff --git a/services/java/com/android/server/Watchdog.java b/services/java/com/android/server/Watchdog.java
index 167e7af..de941f2 100644
--- a/services/java/com/android/server/Watchdog.java
+++ b/services/java/com/android/server/Watchdog.java
@@ -386,13 +386,11 @@
     public void run() {
         boolean waitedHalf = false;
         while (true) {
-            mCompleted = false;
-            mHandler.sendEmptyMessage(MONITOR);
-
-
             final String name;
             synchronized (this) {
                 long timeout = TIME_TO_WAIT;
+                mCompleted = false;
+                mHandler.sendEmptyMessage(MONITOR);
 
                 // NOTE: We use uptimeMillis() here because we do not want to increment the time we
                 // wait while asleep. If the device is asleep then the thing that we are waiting