modify wait mechanism so that it checks whether activity has already finished or not first

squashed commit of the following:

commit e2c2d1c09475ce2e319b935fb5627c82a7693a9b
Author: Guang Zhu <guangzhu@google.com>
Date:   Mon Apr 20 13:33:08 2009 -0700

    modify wait mechanism so that it checks whether activity has already finished or not first

    This reverts commit deb6e8792dd563916724bbc127a6fe16ffe81647.

commit deb6e8792dd563916724bbc127a6fe16ffe81647
Author: Guang Zhu <guangzhu@google.com>
Date:   Mon Apr 20 10:58:52 2009 -0700

    changed callback mechanism in TestShellActivity to use condition
diff --git a/tests/DumpRenderTree/src/com/android/dumprendertree/LayoutTestsAutoTest.java b/tests/DumpRenderTree/src/com/android/dumprendertree/LayoutTestsAutoTest.java
index 39eae02..910cb8d 100644
--- a/tests/DumpRenderTree/src/com/android/dumprendertree/LayoutTestsAutoTest.java
+++ b/tests/DumpRenderTree/src/com/android/dumprendertree/LayoutTestsAutoTest.java
@@ -16,24 +16,11 @@
 
 package com.android.dumprendertree;
 
-import android.app.Activity;
 import android.app.Instrumentation;
-import android.app.Instrumentation.ActivityMonitor;
-import android.content.ContentResolver;
-import android.content.ContentValues;
 import android.content.Intent;
-
-import android.util.Log;
-import android.view.KeyEvent;
-import android.webkit.WebSettings;
-
 import android.os.Bundle;
-import android.os.Message;
 import android.test.ActivityInstrumentationTestCase2;
-import android.test.AndroidTestCase;
-import android.test.suitebuilder.annotation.LargeTest;
-
-import com.android.dumprendertree.TestShellActivity;
+import android.util.Log;
 
 import java.io.BufferedOutputStream;
 import java.io.BufferedReader;
@@ -141,6 +128,7 @@
     private Vector<String> mTestList;
     private boolean mRebaselineResults;
     private String mTestPathPrefix;
+    private boolean mFinished;
     
     public LayoutTestsAutoTest() {
       super("com.android.dumprendertree", TestShellActivity.class);
@@ -290,6 +278,7 @@
         activity.setCallback(new TestShellCallback() {
             public void finished() {
                 synchronized (LayoutTestsAutoTest.this) {
+                    mFinished = true;
                     LayoutTestsAutoTest.this.notifyAll();
                 }
             }         
@@ -306,6 +295,7 @@
             resultFile = getAndroidExpectedResultFile(expectedResultFile);
         }
         
+        mFinished = false;
         Intent intent = new Intent(Intent.ACTION_VIEW);
         intent.setClass(activity, TestShellActivity.class);
         intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
@@ -316,9 +306,11 @@
       
         // Wait until done.
         synchronized (this) {
-            try {
-                this.wait();
-            } catch (InterruptedException e) { }
+            while(!mFinished){
+                try {
+                    this.wait();
+                } catch (InterruptedException e) { }
+            }
         }
         
         if (!mRebaselineResults) {
diff --git a/tests/DumpRenderTree/src/com/android/dumprendertree/LoadTestsAutoTest.java b/tests/DumpRenderTree/src/com/android/dumprendertree/LoadTestsAutoTest.java
index 9e1e9ed..e793ed4 100644
--- a/tests/DumpRenderTree/src/com/android/dumprendertree/LoadTestsAutoTest.java
+++ b/tests/DumpRenderTree/src/com/android/dumprendertree/LoadTestsAutoTest.java
@@ -37,6 +37,7 @@
 
     private final static String LOGTAG = "LoadTest";
     private final static String LOAD_TEST_RESULT = "/sdcard/load_test_result.txt";
+    private boolean mFinished;
 
     public LoadTestsAutoTest() {
         super("com.android.dumprendertree", TestShellActivity.class);
@@ -124,11 +125,13 @@
         activity.setCallback(new TestShellCallback() {
             public void finished() {
                 synchronized (LoadTestsAutoTest.this) {
+                    mFinished = true;
                     LoadTestsAutoTest.this.notifyAll();
                 }
             }
         });
 
+        mFinished = false;
         Intent intent = new Intent(Intent.ACTION_VIEW);
         intent.setClass(activity, TestShellActivity.class);
         intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
@@ -139,9 +142,11 @@
 
         // Wait until done.
         synchronized (this) {
-            try {
-                this.wait();
-            } catch (InterruptedException e) { }
+            while(!mFinished) {
+                try {
+                    this.wait();
+                } catch (InterruptedException e) { }
+            }
         }
     }
 }