Fixed flaky proximity alert tests.

Fixed b/10667162. It's a regression in JB-MR2.
This is caused by race conditions in multiple threads and processes.
Because addProximityAlert returns before geofences are being monitored,
it's possible that the mock location inside the geofence can't be received by
GeofenceManager if it's sent immediately after addProximityAlert.

Change-Id: I7208bb288efe6bdf840a54b7e1544ebf96a45f2f
diff --git a/tests/tests/location/src/android/location/cts/LocationManagerTest.java b/tests/tests/location/src/android/location/cts/LocationManagerTest.java
index 5e823bc..2a2274c 100644
--- a/tests/tests/location/src/android/location/cts/LocationManagerTest.java
+++ b/tests/tests/location/src/android/location/cts/LocationManagerTest.java
@@ -660,6 +660,13 @@
         // update location to outside proximity range
         updateLocationAndWait(FUSED_PROVIDER_NAME, 30, 30);
         registerProximityListener(0, 0, 1000, expiration);
+
+        // Adding geofences is asynchronous, the return of LocationManager.addProximityAlert
+        // doesn't mean that geofences are already being monitored. Wait for a few milliseconds
+        // so that GeofenceManager is actively monitoring locations before we send the mock
+        // location to avoid flaky tests.
+        Thread.sleep(500);
+
         updateLocationAndWait(FUSED_PROVIDER_NAME, 0, 0);
         waitForReceiveBroadcast();
         assertProximityType(true);