AI 144452: More Location Manager cleanup:
Remove 1 Hz "heartbeat" polling of location providers from LocationManagerService.
Now location providers report their location to LocationManagerService via
LocationManager.setLocation() rather than waiting to be polled.
This reduces GPS fix latency by up to one second.
Remove LocationProvderImpl.getLocation().
Since we are no longer polling, this method is no longer necessary.
BUG=1729031
Automated import of CL 144452
diff --git a/test-runner/android/test/TestLocationProvider.java b/test-runner/android/test/TestLocationProvider.java
index 00c1ce8..69747d2 100644
--- a/test-runner/android/test/TestLocationProvider.java
+++ b/test-runner/android/test/TestLocationProvider.java
@@ -18,6 +18,7 @@
import android.location.Criteria;
+import android.location.ILocationManager;
import android.location.Location;
import android.location.LocationProviderImpl;
import android.os.Bundle;
@@ -36,14 +37,45 @@
public static final float SPEED = 10;
public static final float BEARING = 1;
public static final int STATUS = AVAILABLE;
+ private static final long LOCATION_INTERVAL = 1000;
private Location mLocation;
private boolean mEnabled;
+ private TestLocationProviderThread mThread;
- public TestLocationProvider() {
- super(PROVIDER_NAME);
+ private class TestLocationProviderThread extends Thread {
+
+ private boolean mDone = false;
+
+ public TestLocationProviderThread() {
+ super("TestLocationProviderThread");
+ }
+
+ public void run() {
+ // thread exits after disable() is called
+ synchronized (this) {
+ while (!mDone) {
+ try {
+ wait(LOCATION_INTERVAL);
+ } catch (InterruptedException e) {
+ }
+
+ if (!mDone) {
+ TestLocationProvider.this.updateLocation();
+ }
+ }
+ }
+ }
+
+ synchronized void setDone() {
+ mDone = true;
+ notify();
+ }
+ }
+
+ public TestLocationProvider(ILocationManager locationManager) {
+ super(PROVIDER_NAME, locationManager);
mLocation = new Location(PROVIDER_NAME);
- updateLocation();
}
//LocationProvider methods
@@ -95,13 +127,23 @@
//LocationProviderImpl methods
@Override
- public void disable() {
+ public synchronized void disable() {
mEnabled = false;
+ if (mThread != null) {
+ mThread.setDone();
+ try {
+ mThread.join();
+ } catch (InterruptedException e) {
+ }
+ mThread = null;
+ }
}
@Override
- public void enable() {
- mEnabled = true;
+ public synchronized void enable() {
+ mEnabled = true;
+ mThread = new TestLocationProviderThread();
+ mThread.start();
}
@Override
@@ -110,13 +152,6 @@
}
@Override
- public boolean getLocation(Location l) {
- updateLocation();
- l.set(mLocation);
- return true;
- }
-
- @Override
public int getStatus(Bundle extras) {
return STATUS;
}
@@ -134,6 +169,7 @@
extras.putInt("extraTest", 24);
mLocation.setExtras(extras);
mLocation.setTime(time);
+ reportLocationChanged(mLocation);
}
}