Merge change 25360 into eclair

* changes:
  Fix issue #2121993: com.android.unit_tests.os.HandlerThreadTest:testHandlerThread is failing
This commit is contained in:
Android (Google) Code Review
2009-09-16 19:20:52 -04:00

View File

@ -36,8 +36,11 @@ public class HandlerThreadTest extends TestCase {
public void testHandlerThread() throws Exception { public void testHandlerThread() throws Exception {
HandlerThread th1 = new HandlerThread("HandlerThreadTest") { HandlerThread th1 = new HandlerThread("HandlerThreadTest") {
protected void onLooperPrepared() { protected void onLooperPrepared() {
mDidSetup = true; synchronized (HandlerThreadTest.this) {
mLooperTid = Process.myTid(); mDidSetup = true;
mLooperTid = Process.myTid();
HandlerThreadTest.this.notify();
}
} }
}; };
@ -49,14 +52,23 @@ public class HandlerThreadTest extends TestCase {
assertTrue(th1.isAlive()); assertTrue(th1.isAlive());
assertNotNull(th1.getLooper()); assertNotNull(th1.getLooper());
/* // The call to getLooper() internally blocks until the looper is
* Since getLooper() will block until the HandlerThread is setup, we are guaranteed // available, but will call onLooperPrepared() after that. So we
* that mDidSetup and mLooperTid will have been initalized. If they have not, then // need to block here to wait for our onLooperPrepared() to complete
* this test should fail // and fill in the values we expect.
*/ synchronized (this) {
while (!mDidSetup) {
try {
wait();
} catch (InterruptedException e) {
}
}
}
// Make sure that the process was set.
assertNotSame(-1, mLooperTid);
// Make sure that the onLooperPrepared() was called on a different thread. // Make sure that the onLooperPrepared() was called on a different thread.
assertNotSame(Process.myTid(), mLooperTid); assertNotSame(Process.myTid(), mLooperTid);
assertTrue(mDidSetup);
final Handler h1 = new Handler(th1.getLooper()) { final Handler h1 = new Handler(th1.getLooper()) {
public void handleMessage(Message msg) { public void handleMessage(Message msg) {