More Location Manager cleanup:

Move LocationCollector support out of GpsLocationProvider.
Don't disable GPS when screen is off.

Signed-off-by: Mike Lockwood <lockwood@android.com>
diff --git a/location/java/com/android/internal/location/GpsLocationProvider.java b/location/java/com/android/internal/location/GpsLocationProvider.java
index f133b4f..c825724 100644
--- a/location/java/com/android/internal/location/GpsLocationProvider.java
+++ b/location/java/com/android/internal/location/GpsLocationProvider.java
@@ -22,7 +22,6 @@
 import android.content.IntentFilter;
 import android.location.Criteria;
 import android.location.IGpsStatusListener;
-import android.location.ILocationCollector;
 import android.location.ILocationManager;
 import android.location.Location;
 import android.location.LocationManager;
@@ -207,8 +206,6 @@
     // current setting - 5 minutes
     private static final long RETRY_INTERVAL = 5*60*1000; 
 
-    private ILocationCollector mCollector;
-
     private class TelephonyBroadcastReceiver extends BroadcastReceiver {
         @Override public void onReceive(Context context, Intent intent) {
             String action = intent.getAction();
@@ -272,10 +269,6 @@
         }
     }
 
-    public void setLocationCollector(ILocationCollector collector) {
-        mCollector = collector;
-    }
-
     /**
      * Returns true if the provider requires access to a
      * data network (e.g., the Internet), false otherwise.
@@ -729,16 +722,6 @@
             }
 
             reportLocationChanged(mLocation);
-
-            // Send to collector
-            if ((flags & LOCATION_HAS_LAT_LONG) == LOCATION_HAS_LAT_LONG
-                    && mCollector != null) {
-                try {
-                    mCollector.updateLocation(mLocation);
-                } catch (RemoteException e) {
-                    Log.w(TAG, "mCollector.updateLocation failed");
-                }
-            }
         }
 
         if (mStarted && mStatus != AVAILABLE) {
diff --git a/services/java/com/android/server/LocationManagerService.java b/services/java/com/android/server/LocationManagerService.java
index c91e21c..c60e4ea 100644
--- a/services/java/com/android/server/LocationManagerService.java
+++ b/services/java/com/android/server/LocationManagerService.java
@@ -126,7 +126,6 @@
 
     private final Context mContext;
     private GpsLocationProvider mGpsLocationProvider;
-    private boolean mGpsNavigating;
     private LocationProviderProxy mNetworkLocationProvider;
     private IGeocodeProvider mGeocodeProvider;
     private LocationWorkerHandler mLocationHandler;
@@ -600,12 +599,7 @@
                 "Installing location collectors outside of the system is not supported");
         }
 
-        synchronized (mLock) {
-            mCollector = collector;
-            if (mGpsLocationProvider != null) {
-                mGpsLocationProvider.setLocationCollector(mCollector);
-            }
-        }
+        mCollector = collector;
     }
 
     public void setGeocodeProvider(IGeocodeProvider provider) {
@@ -805,9 +799,6 @@
             }
         } else {
             p.enableLocationTracking(false);
-            if (p == mGpsLocationProvider) {
-                mGpsNavigating = false;
-            }
             p.disable();
             updateWakelockStatusLocked(mScreenOn);
         }
@@ -1612,6 +1603,16 @@
 
                     synchronized (mLock) {
                         Location location = (Location) msg.obj;
+
+                        if (mCollector != null && 
+                                LocationManager.GPS_PROVIDER.equals(location.getProvider())) {
+                            try {
+                                mCollector.updateLocation(location);
+                            } catch (RemoteException e) {
+                                Log.w(TAG, "mCollector.updateLocation failed");
+                            }
+                        }
+
                         String provider = location.getProvider();
                         if (!isAllowedBySettingsLocked(provider)) {
                             return;
@@ -1767,10 +1768,7 @@
                     false);
 
                 synchronized (mLock) {
-                    if (enabled) {
-                        mGpsNavigating = true;
-                    } else {
-                        mGpsNavigating = false;
+                    if (!enabled) {
                         // When GPS is disabled, we are OK to release wake-lock
                         mWakeLockGpsReceived = true;
                     }
@@ -1798,12 +1796,6 @@
         if (mGpsLocationProvider != null && mGpsLocationProvider.isLocationTracking()) {
             needsLock = true;
             minTime = Math.min(mGpsLocationProvider.getMinTime(), minTime);
-            if (screenOn) {
-                startGpsLocked();
-            } else if (mScreenOn && !screenOn) {
-                // We just turned the screen off so stop navigating
-                stopGpsLocked();
-            }
         }
 
         mScreenOn = screenOn;
@@ -1869,9 +1861,6 @@
         mWakeLockAcquireTime = SystemClock.elapsedRealtime();
         log("Acquired wakelock");
 
-        // Start the gps provider
-        startGpsLocked();
-
         // Acquire cell lock
         if (mCellWakeLockAcquired) {
             // Lock is already acquired
@@ -1902,22 +1891,6 @@
         }
     }
 
-    private void startGpsLocked() {
-        boolean gpsActive = (mGpsLocationProvider != null)
-                    && mGpsLocationProvider.isLocationTracking();
-        if (gpsActive) {
-            mGpsLocationProvider.startNavigating();
-        }
-    }
-
-    private void stopGpsLocked() {
-        boolean gpsActive = mGpsLocationProvider != null
-                    && mGpsLocationProvider.isLocationTracking();
-        if (gpsActive) {
-            mGpsLocationProvider.stopNavigating();
-        }
-    }
-
     private void releaseWakeLockLocked() {
         try {
             releaseWakeLockXLocked();
@@ -1938,11 +1911,6 @@
             }
         }
 
-        if (!mScreenOn) {
-            // Stop the gps
-            stopGpsLocked();
-        }
-
         // Release cell lock
         if (mCellWakeLockAcquired) {
             mTelephonyManager.disableLocationUpdates();
@@ -2140,7 +2108,6 @@
             pw.println("Current Location Manager state:");
             pw.println("  sProvidersLoaded=" + sProvidersLoaded);
             pw.println("  mGpsLocationProvider=" + mGpsLocationProvider);
-            pw.println("  mGpsNavigating=" + mGpsNavigating);
             pw.println("  mNetworkLocationProvider=" + mNetworkLocationProvider);
             pw.println("  mCollector=" + mCollector);
             pw.println("  mAlarmInterval=" + mAlarmInterval