public final class GeofenceHardwareImpl {
private static final String TAG = "GeofenceHardwareImpl";
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
+ private static final int FIRST_VERSION_WITH_CAPABILITIES = 2;
private final Context mContext;
private static GeofenceHardwareImpl sInstance;
private IFusedGeofenceHardware mFusedService;
private IGpsGeofenceHardware mGpsService;
private int mCapabilities;
+ private int mVersion = 1;
private int[] mSupportedMonitorTypes = new int[GeofenceHardware.NUM_MONITORS];
private void updateFusedHardwareAvailability() {
boolean fusedSupported;
try {
+ final boolean hasGnnsCapabilities = (mVersion < FIRST_VERSION_WITH_CAPABILITIES)
+ || (mCapabilities & CAPABILITY_GNSS) != 0;
fusedSupported = (mFusedService != null
- ? mFusedService.isSupported() && (mCapabilities & CAPABILITY_GNSS) != 0
+ ? mFusedService.isSupported() && hasGnnsCapabilities
: false);
} catch (RemoteException e) {
Log.e(TAG, "RemoteException calling LocationManagerService");
updateFusedHardwareAvailability();
}
+ public void setVersion(int version) {
+ mVersion = version;
+ updateFusedHardwareAvailability();
+ }
+
public void setFusedGeofenceHardware(IFusedGeofenceHardware service) {
if(mFusedService == null) {
mFusedService = service;
* of the locations returned in this call.
*/
void flushBatchedLocations() = 11;
+
+ /**
+ * Returns the version of this FLP HAL implementation.
+ */
+ int getVersion() = 12;
}
}
}
+
+ /**
+ * Returns the version of the FLP HAL.
+ *
+ * <p>Version 1 is the initial release.
+ * <p>Version 2 adds the ability to use {@link #flushBatchedLocations},
+ * {@link FusedLocationHardwareSink#onCapabilities}, and
+ * {@link FusedLocationHardwareSink#onStatusChanged}.
+ *
+ * <p>This method is only available on API 23 or later. Older APIs have version 1.
+ */
+ public int getVersion() {
+ try {
+ return mLocationHardware.getVersion();
+ } catch(RemoteException e) {
+ Log.e(TAG, "RemoteException at getVersion");
+ }
+ return 1;
+ }
+
/*
* Helper methods and classes
*/
/**
* Called when the status changes in the underlying FLP HAL
* implementation (the ability to compute location). This
- * callback will only be made on API 23 or later.
+ * callback will only be made on version 2 or later
+ * (see {@link FusedLocationHardware#getVersion()}).
*
* @param status One of FLP_STATUS_LOCATION_AVAILABLE or
* FLP_STATUS_LOCATION_UNAVAILABLE as defined in
* {@hide}
*/
public class FlpHardwareProvider {
+ private static final int FIRST_VERSION_WITH_FLUSH_LOCATIONS = 2;
private GeofenceHardwareImpl mGeofenceHardwareSink = null;
private IFusedLocationHardwareSink mLocationSink = null;
// Capabilities provided by FlpCallbacks
private boolean mHaveBatchingCapabilities;
private int mBatchingCapabilities;
+ private int mVersion;
private static FlpHardwareProvider sSingletonInstance = null;
}
}
+ private void setVersion(int version) {
+ mVersion = version;
+ getGeofenceHardwareSink().setVersion(version);
+ }
+
private void maybeSendCapabilities() {
IFusedLocationHardwareSink sink;
boolean haveBatchingCapabilities;
@Override
public void flushBatchedLocations() {
- nativeFlushBatchedLocations();
+ if (mVersion >= FIRST_VERSION_WITH_FLUSH_LOCATIONS) {
+ nativeFlushBatchedLocations();
+ } else {
+ Log.wtf(TAG,
+ "Tried to call flushBatchedLocations on an unsupported implementation");
+ }
}
@Override
public void injectDeviceContext(int deviceEnabledContext) {
nativeInjectDeviceContext(deviceEnabledContext);
}
+
+ @Override
+ public int getVersion() {
+ return mVersion;
+ }
};
private final IFusedGeofenceHardware mGeofenceHardwareService =
checkPermissions();
mLocationHardware.flushBatchedLocations();
}
+
+ @Override
+ public int getVersion() throws RemoteException {
+ checkPermissions();
+ return mLocationHardware.getVersion();
+ }
}
static JNIEnv *sCallbackEnv = NULL;
static hw_device_t* sHardwareDevice = NULL;
+static jmethodID sSetVersion = NULL;
static jmethodID sOnLocationReport = NULL;
static jmethodID sOnDataReport = NULL;
static jmethodID sOnBatchingCapabilities = NULL;
}
ALOGV("Callback thread attached: %p", sCallbackEnv);
+
+ // Send the version to the upper layer.
+ sCallbackEnv->CallVoidMethod(
+ sCallbacksObj,
+ sSetVersion,
+ sFlpInterface->size == sizeof(FlpLocationInterface) ? 2 : 1
+ );
+ CheckExceptions(sCallbackEnv, __FUNCTION__);
break;
}
case DISASSOCIATE_JVM:
sFlpInterface = NULL;
// get references to the Java provider methods
+ sSetVersion = env->GetMethodID(
+ clazz,
+ "setVersion",
+ "(I)V");
sOnLocationReport = env->GetMethodID(
clazz,
"onLocationReport",