Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4e50b78b authored by Mike Lockwood's avatar Mike Lockwood Committed by The Android Open Source Project
Browse files

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
parent e84de8d7
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -54,6 +54,9 @@ interface ILocationManager

    Location getLastKnownLocation(String provider);
    
    /* used by location providers to tell the location manager when it has a new location */
    void setLocation(in Location location);

    String getFromLocation(double latitude, double longitude, int maxResults,
        String language, String country, String variant, String appName, out List<Address> addrs);
    String getFromLocationName(String locationName,
+14 −12
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import java.util.HashMap;
import java.util.List;

import android.os.Bundle;
import android.os.RemoteException;
import android.util.Config;
import android.util.Log;

@@ -46,11 +47,13 @@ public abstract class LocationProviderImpl extends LocationProvider {
    private static HashMap<String, LocationProviderImpl> sProvidersByName
        = new HashMap<String, LocationProviderImpl>();

    private final ILocationManager mLocationManager;
    private boolean mLocationTracking = false;
    private long mMinTime = 0;

    protected LocationProviderImpl(String name) {
    protected LocationProviderImpl(String name, ILocationManager locationManager) {
        super(name);
        mLocationManager = locationManager;
    }

    public static void addProvider(LocationProviderImpl provider) {
@@ -114,16 +117,24 @@ public abstract class LocationProviderImpl extends LocationProvider {
        return null;
    }

    public void reportLocationChanged(Location location) {
        try {
            mLocationManager.setLocation(location);
        } catch (RemoteException e) {
            Log.e(TAG, "RemoteException calling ILocationManager.onLocationChanged");
        }
    }
    
    /**
     * Enables this provider.  When enabled, calls to {@link #getStatus()}
     * and {@link #getLocation} must be handled.  Hardware may be started up
     * must be handled.  Hardware may be started up
     * when the provider is enabled.
     */
    public abstract void enable();

    /**
     * Disables this provider.  When disabled, calls to {@link #getStatus()}
     * and {@link #getLocation} need not be handled.  Hardware may be shut
     * need not be handled.  Hardware may be shut
     * down while the provider is disabled.
     */
    public abstract void disable();
@@ -174,15 +185,6 @@ public abstract class LocationProviderImpl extends LocationProvider {
        return 0;
    }

    /**
     * Sets a Location object with the information gathered
     * during the most recent fix.
     *
     * @param l location object to set
     * @return true if a location fix is available
     */
    public abstract boolean getLocation(Location l);

    /**
     * Notifies the location provider that clients are listening for locations.
     * Called with enable set to true when the first client is added and
+7 −17
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.location.Criteria;
import android.location.IGpsStatusListener;
import android.location.ILocationManager;
import android.location.Location;
import android.location.LocationManager;
import android.location.LocationProvider;
@@ -209,8 +210,8 @@ public class GpsLocationProvider extends LocationProviderImpl {
        return native_is_supported();
    }

    public GpsLocationProvider(Context context) {
        super(LocationManager.GPS_PROVIDER);
    public GpsLocationProvider(Context context, ILocationManager locationManager) {
        super(LocationManager.GPS_PROVIDER, locationManager);
        mContext = context;

        TelephonyBroadcastReceiver receiver = new TelephonyBroadcastReceiver();
@@ -355,7 +356,7 @@ public class GpsLocationProvider extends LocationProviderImpl {

    /**
     * Enables this provider.  When enabled, calls to getStatus()
     * and getLocation() must be handled.  Hardware may be started up
     * must be handled.  Hardware may be started up
     * when the provider is enabled.
     */
    @Override
@@ -385,7 +386,7 @@ public class GpsLocationProvider extends LocationProviderImpl {

    /**
     * Disables this provider.  When disabled, calls to getStatus()
     * and getLocation() need not be handled.  Hardware may be shut
     * need not be handled.  Hardware may be shut
     * down while the provider is disabled.
     */
    @Override
@@ -448,19 +449,6 @@ public class GpsLocationProvider extends LocationProviderImpl {
        return mStatusUpdateTime;
    }

    @Override
    public boolean getLocation(Location l) {
        synchronized (mLocation) {
            // don't report locations without latitude and longitude
            if ((mLocationFlags & LOCATION_HAS_LAT_LONG) == 0) {
                return false;
            }
            l.set(mLocation);
            l.setExtras(mLocationExtras);
            return true;
        }
    }

    @Override
    public void enableLocationTracking(boolean enable) {
        if (mLocationTracking == enable) {
@@ -685,6 +673,8 @@ public class GpsLocationProvider extends LocationProviderImpl {
                mLocation.removeAccuracy();
            }

            reportLocationChanged(mLocation);

            // Send to collector
            if ((flags & LOCATION_HAS_LAT_LONG) == LOCATION_HAS_LAT_LONG
                    && mCollector != null) {
+0 −5
Original line number Diff line number Diff line
@@ -20,12 +20,7 @@ import android.location.Address;
import android.location.Location;
import android.net.wifi.ScanResult;

import com.google.common.io.protocol.ProtoBuf;

import java.io.IOException;
import java.util.Collection;
import java.util.List;
import java.util.Locale;

/**
 * Interface for network location provider
+11 −34
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.internal.location;

import android.location.ILocationManager;
import android.location.Location;
import android.location.LocationProviderImpl;
import android.os.Bundle;
@@ -46,10 +47,11 @@ public class MockProvider extends LocationProviderImpl {
    private boolean mHasStatus;
    private boolean mEnabled;

    public MockProvider(String name,  boolean requiresNetwork, boolean requiresSatellite,
    public MockProvider(String name,  ILocationManager locationManager,
        boolean requiresNetwork, boolean requiresSatellite,
        boolean requiresCell, boolean hasMonetaryCost, boolean supportsAltitude,
        boolean supportsSpeed, boolean supportsBearing, int powerRequirement, int accuracy) {
        super(name);
        super(name, locationManager);

        mRequiresNetwork = requiresNetwork;
        mRequiresSatellite = requiresSatellite;
@@ -73,15 +75,6 @@ public class MockProvider extends LocationProviderImpl {
        mEnabled = true;
    }

    @Override
    public boolean getLocation(Location l) {
        if (mHasLocation) {
            l.set(mLocation);
            return true;
        }
        return false;
    }

    @Override
    public int getStatus(Bundle extras) {
        if (mHasStatus) {
@@ -93,6 +86,11 @@ public class MockProvider extends LocationProviderImpl {
        }
    }

    @Override
    public long getStatusUpdateTime() {
        return mStatusUpdateTime;
    }

    @Override
    public boolean isEnabled() {
        return mEnabled;
@@ -146,6 +144,7 @@ public class MockProvider extends LocationProviderImpl {
    public void setLocation(Location l) {
        mLocation.set(l);
        mHasLocation = true;
        reportLocationChanged(mLocation);
    }

    public void clearLocation() {
@@ -164,29 +163,7 @@ public class MockProvider extends LocationProviderImpl {

    public void clearStatus() {
        mHasStatus = false;
    }

    public int overrideStatus(int status) {
        if (mHasStatus) {
            return mStatus;
        } else {
            return status;
        }
    }

    public long overrideStatusUpdateTime(long statusUpdateTime) {
        if (mHasStatus) {
            return mStatusUpdateTime;
        } else {
            return statusUpdateTime;
        }
    }

    public void overrideExtras(Bundle extras) {
        if (mHasStatus) {
            extras.clear();
            extras.putAll(mExtras);
        }
        mStatusUpdateTime = 0;
    }

    public void dump(PrintWriter pw, String prefix) {
Loading