GNSS Batching - Default Implementation

Connections from .hal layer, through to
Location Manager System APIs

Bug: 31974439
Test: builds, boots, ordinary GNSS & new GNSS batching
      basic functional checks on Marlin
Change-Id: If75118c27b5ed34cfc16c9f817b60a3be5485095
This commit is contained in:
Wyatt Riley
2017-01-12 13:57:38 -08:00
parent 85adc21488
commit cf879db366
11 changed files with 777 additions and 61 deletions

View File

@@ -18,6 +18,7 @@ package android.location;
import com.android.internal.location.ProviderProperties;
import android.Manifest;
import android.annotation.RequiresPermission;
import android.annotation.SystemApi;
import android.annotation.TestApi;
@@ -59,13 +60,15 @@ import static android.Manifest.permission.ACCESS_FINE_LOCATION;
* return location results, but the update rate will be throttled and the exact
* location will be obfuscated to a coarse level of accuracy.
*/
public class LocationManager {
public class LocationManager
{
private static final String TAG = "LocationManager";
private final Context mContext;
private final ILocationManager mService;
private final GnssMeasurementCallbackTransport mGnssMeasurementCallbackTransport;
private final GnssNavigationMessageCallbackTransport mGnssNavigationMessageCallbackTransport;
private final BatchedLocationCallbackTransport mBatchedLocationCallbackTransport;
private final HashMap<GpsStatus.Listener, GnssStatusListenerTransport> mGpsStatusListeners =
new HashMap<>();
private final HashMap<GpsStatus.NmeaListener, GnssStatusListenerTransport> mGpsNmeaListeners =
@@ -321,9 +324,13 @@ public class LocationManager {
public LocationManager(Context context, ILocationManager service) {
mService = service;
mContext = context;
mGnssMeasurementCallbackTransport = new GnssMeasurementCallbackTransport(mContext, mService);
mGnssMeasurementCallbackTransport =
new GnssMeasurementCallbackTransport(mContext, mService);
mGnssNavigationMessageCallbackTransport =
new GnssNavigationMessageCallbackTransport(mContext, mService);
mBatchedLocationCallbackTransport =
new BatchedLocationCallbackTransport(mContext, mService);
}
private LocationProvider createProvider(String name, ProviderProperties properties) {
@@ -1878,7 +1885,8 @@ public class LocationManager {
* No-op method to keep backward-compatibility.
* Don't use it. Use {@link #unregisterGnssNavigationMessageCallback} instead.
* @hide
* @deprecated use {@link #unregisterGnssNavigationMessageCallback(GnssMeasurements.Callback)}
* @deprecated use
* {@link #unregisterGnssNavigationMessageCallback(GnssNavigationMessage.Callback)}
* instead
*/
@Deprecated
@@ -1959,6 +1967,96 @@ public class LocationManager {
}
}
/**
* Returns the batch size (in number of Location objects) that are supported by the batching
* interface.
*
* @return Maximum number of location objects that can be returned
* @hide
*/
@SystemApi
@RequiresPermission(Manifest.permission.LOCATION_HARDWARE)
public int getGnssBatchSize() {
try {
return mService.getGnssBatchSize(mContext.getPackageName());
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Start hardware-batching of GNSS locations. This API is primarily used when the AP is
* asleep and the device can batch GNSS locations in the hardware.
*
* Note this is designed (as was the fused location interface before it) for a single user
* SystemApi - requests are not consolidated. Care should be taken when the System switches
* users that may have different batching requests, to stop hardware batching for one user, and
* restart it for the next.
*
* @param periodNanos Time interval, in nanoseconds, that the GNSS locations are requested
* within the batch
* @param wakeOnFifoFull True if the hardware batching should flush the locations in a
* a callback to the listener, when it's internal buffer is full. If
* set to false, the oldest location information is, instead,
* dropped when the buffer is full.
* @param callback The listener on which to return the batched locations
* @param handler The handler on which to process the callback
*
* @return True if batching was successfully started
* @hide
*/
@SystemApi
@RequiresPermission(Manifest.permission.LOCATION_HARDWARE)
public boolean registerGnssBatchedLocationCallback(long periodNanos, boolean wakeOnFifoFull,
BatchedLocationCallback callback, Handler handler) {
mBatchedLocationCallbackTransport.add(callback, handler);
try {
return mService.startGnssBatch(periodNanos, wakeOnFifoFull, mContext.getPackageName());
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Flush the batched GNSS locations.
* All GNSS locations currently ready in the batch are returned via the callback sent in
* startGnssBatch(), and the buffer containing the batched locations is cleared.
*
* @hide
*/
@SystemApi
@RequiresPermission(Manifest.permission.LOCATION_HARDWARE)
public void flushGnssBatch() {
try {
mService.flushGnssBatch(mContext.getPackageName());
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Stop batching locations. This API is primarily used when the AP is
* asleep and the device can batch locations in the hardware.
*
* @param callback the specific callback class to remove from the transport layer
*
* @return True if batching was successfully started
* @hide
*/
@SystemApi
@RequiresPermission(Manifest.permission.LOCATION_HARDWARE)
public boolean unregisterGnssBatchedLocationCallback(BatchedLocationCallback callback) {
mBatchedLocationCallbackTransport.remove(callback);
try {
return mService.stopGnssBatch();
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Sends additional commands to a location provider.
* Can be used to support provider specific extensions to the Location Manager API