Merge "Treble GNSS - Removing FlpHardwareProvider"
diff --git a/services/core/java/com/android/server/location/FlpHardwareProvider.java b/services/core/java/com/android/server/location/FlpHardwareProvider.java
index 6d08c36..5c9b0ea 100644
--- a/services/core/java/com/android/server/location/FlpHardwareProvider.java
+++ b/services/core/java/com/android/server/location/FlpHardwareProvider.java
@@ -17,523 +17,58 @@
package com.android.server.location;
import android.content.Context;
-import android.hardware.location.GeofenceHardware;
-import android.hardware.location.GeofenceHardwareImpl;
-import android.hardware.location.GeofenceHardwareRequestParcelable;
import android.hardware.location.IFusedLocationHardware;
-import android.hardware.location.IFusedLocationHardwareSink;
-import android.location.FusedBatchOptions;
import android.location.IFusedGeofenceHardware;
-import android.location.Location;
-import android.location.LocationListener;
-import android.location.LocationManager;
-import android.location.LocationRequest;
-import android.os.Bundle;
-import android.os.Looper;
-import android.os.RemoteException;
-import android.os.SystemClock;
import android.util.Log;
/**
- * This class is an interop layer for JVM types and the JNI code that interacts
+ * This class was an interop layer for JVM types and the JNI code that interacted
* with the FLP HAL implementation.
*
+ * Now, after Treble FLP & GNSS HAL simplification, it is a thin shell that acts like the
+ * pre-existing cases where there was no FLP Hardware support, to keep legacy users of this
+ * class operating.
+ *
* {@hide}
+ * {@Deprecated}
*/
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 = 1;
-
private static FlpHardwareProvider sSingletonInstance = null;
private final static String TAG = "FlpHardwareProvider";
- private final Context mContext;
- private final Object mLocationSinkLock = new Object();
- // FlpHal result codes, they must be equal to the ones in fused_location.h
- private static final int FLP_RESULT_SUCCESS = 0;
- private static final int FLP_RESULT_ERROR = -1;
- private static final int FLP_RESULT_INSUFFICIENT_MEMORY = -2;
- private static final int FLP_RESULT_TOO_MANY_GEOFENCES = -3;
- private static final int FLP_RESULT_ID_EXISTS = -4;
- private static final int FLP_RESULT_ID_UNKNOWN = -5;
- private static final int FLP_RESULT_INVALID_GEOFENCE_TRANSITION = -6;
-
- // FlpHal monitor status codes, they must be equal to the ones in fused_location.h
- private static final int FLP_GEOFENCE_MONITOR_STATUS_UNAVAILABLE = 1<<0;
- private static final int FLP_GEOFENCE_MONITOR_STATUS_AVAILABLE = 1<<1;
+ private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
public static FlpHardwareProvider getInstance(Context context) {
if (sSingletonInstance == null) {
- sSingletonInstance = new FlpHardwareProvider(context);
- sSingletonInstance.nativeInit();
+ sSingletonInstance = new FlpHardwareProvider();
+ if (DEBUG) Log.d(TAG, "getInstance() created empty provider");
}
-
return sSingletonInstance;
}
- private FlpHardwareProvider(Context context) {
- mContext = context;
-
- // register for listening for passive provider data
- LocationManager manager = (LocationManager) mContext.getSystemService(
- Context.LOCATION_SERVICE);
- final long minTime = 0;
- final float minDistance = 0;
- final boolean oneShot = false;
- LocationRequest request = LocationRequest.createFromDeprecatedProvider(
- LocationManager.PASSIVE_PROVIDER,
- minTime,
- minDistance,
- oneShot);
- // Don't keep track of this request since it's done on behalf of other clients
- // (which are kept track of separately).
- request.setHideFromAppOps(true);
- manager.requestLocationUpdates(
- request,
- new NetworkLocationListener(),
- Looper.myLooper());
+ private FlpHardwareProvider() {
}
public static boolean isSupported() {
- return nativeIsSupported();
+ if (DEBUG) Log.d(TAG, "isSupported() returning false");
+ return false;
}
/**
- * Private callback functions used by FLP HAL.
- */
- // FlpCallbacks members
- private void onLocationReport(Location[] locations) {
- for (Location location : locations) {
- location.setProvider(LocationManager.FUSED_PROVIDER);
- // set the elapsed time-stamp just as GPS provider does
- location.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos());
- }
-
- IFusedLocationHardwareSink sink;
- synchronized (mLocationSinkLock) {
- sink = mLocationSink;
- }
- try {
- if (sink != null) {
- sink.onLocationAvailable(locations);
- }
- } catch (RemoteException e) {
- Log.e(TAG, "RemoteException calling onLocationAvailable");
- }
- }
-
- private void onBatchingCapabilities(int capabilities) {
- synchronized (mLocationSinkLock) {
- mHaveBatchingCapabilities = true;
- mBatchingCapabilities = capabilities;
- }
-
- maybeSendCapabilities();
-
- if (mGeofenceHardwareSink != null) {
- mGeofenceHardwareSink.setVersion(getVersion());
- }
- }
-
- private void onBatchingStatus(int status) {
- IFusedLocationHardwareSink sink;
- synchronized (mLocationSinkLock) {
- sink = mLocationSink;
- }
- try {
- if (sink != null) {
- sink.onStatusChanged(status);
- }
- } catch (RemoteException e) {
- Log.e(TAG, "RemoteException calling onBatchingStatus");
- }
- }
-
- // Returns the current version of the FLP HAL. This depends both on the version of the
- // structure returned by the hardware layer, and whether or not we've received the
- // capabilities callback on initialization. Assume original version until we get
- // the new initialization callback.
- private int getVersion() {
- synchronized (mLocationSinkLock) {
- if (mHaveBatchingCapabilities) {
- return mVersion;
- }
- }
- return 1;
- }
-
- private void setVersion(int version) {
- mVersion = version;
- if (mGeofenceHardwareSink != null) {
- mGeofenceHardwareSink.setVersion(getVersion());
- }
- }
-
- private void maybeSendCapabilities() {
- IFusedLocationHardwareSink sink;
- boolean haveBatchingCapabilities;
- int batchingCapabilities;
- synchronized (mLocationSinkLock) {
- sink = mLocationSink;
- haveBatchingCapabilities = mHaveBatchingCapabilities;
- batchingCapabilities = mBatchingCapabilities;
- }
- try {
- if (sink != null && haveBatchingCapabilities) {
- sink.onCapabilities(batchingCapabilities);
- }
- } catch (RemoteException e) {
- Log.e(TAG, "RemoteException calling onLocationAvailable");
- }
- }
-
- // FlpDiagnosticCallbacks members
- private void onDataReport(String data) {
- IFusedLocationHardwareSink sink;
- synchronized (mLocationSinkLock) {
- sink = mLocationSink;
- }
- try {
- if (mLocationSink != null) {
- sink.onDiagnosticDataAvailable(data);
- }
- } catch (RemoteException e) {
- Log.e(TAG, "RemoteException calling onDiagnosticDataAvailable");
- }
- }
-
- // FlpGeofenceCallbacks members
- private void onGeofenceTransition(
- int geofenceId,
- Location location,
- int transition,
- long timestamp,
- int sourcesUsed) {
- // the transition Id does not require translation because the values in fused_location.h
- // and GeofenceHardware are in sync
- getGeofenceHardwareSink().reportGeofenceTransition(
- geofenceId,
- updateLocationInformation(location),
- transition,
- timestamp,
- GeofenceHardware.MONITORING_TYPE_FUSED_HARDWARE,
- sourcesUsed);
- }
-
- private void onGeofenceMonitorStatus(int status, int source, Location location) {
- // allow the location to be optional in this event
- Location updatedLocation = null;
- if(location != null) {
- updatedLocation = updateLocationInformation(location);
- }
-
- int monitorStatus;
- switch (status) {
- case FLP_GEOFENCE_MONITOR_STATUS_UNAVAILABLE:
- monitorStatus = GeofenceHardware.MONITOR_CURRENTLY_UNAVAILABLE;
- break;
- case FLP_GEOFENCE_MONITOR_STATUS_AVAILABLE:
- monitorStatus = GeofenceHardware.MONITOR_CURRENTLY_AVAILABLE;
- break;
- default:
- Log.e(TAG, "Invalid FlpHal Geofence monitor status: " + status);
- monitorStatus = GeofenceHardware.MONITOR_CURRENTLY_UNAVAILABLE;
- break;
- }
-
- getGeofenceHardwareSink().reportGeofenceMonitorStatus(
- GeofenceHardware.MONITORING_TYPE_FUSED_HARDWARE,
- monitorStatus,
- updatedLocation,
- source);
- }
-
- private void onGeofenceAdd(int geofenceId, int result) {
- getGeofenceHardwareSink().reportGeofenceAddStatus(
- geofenceId,
- translateToGeofenceHardwareStatus(result));
- }
-
- private void onGeofenceRemove(int geofenceId, int result) {
- getGeofenceHardwareSink().reportGeofenceRemoveStatus(
- geofenceId,
- translateToGeofenceHardwareStatus(result));
- }
-
- private void onGeofencePause(int geofenceId, int result) {
- getGeofenceHardwareSink().reportGeofencePauseStatus(
- geofenceId,
- translateToGeofenceHardwareStatus(result));
- }
-
- private void onGeofenceResume(int geofenceId, int result) {
- getGeofenceHardwareSink().reportGeofenceResumeStatus(
- geofenceId,
- translateToGeofenceHardwareStatus(result));
- }
-
- private void onGeofencingCapabilities(int capabilities) {
- getGeofenceHardwareSink().onCapabilities(capabilities);
- }
-
- /**
- * Private native methods accessing FLP HAL.
- */
- static { nativeClassInit(); }
-
- // Core members
- private static native void nativeClassInit();
- private static native boolean nativeIsSupported();
-
- // FlpLocationInterface members
- private native void nativeInit();
- private native int nativeGetBatchSize();
- private native void nativeStartBatching(int requestId, FusedBatchOptions options);
- private native void nativeUpdateBatchingOptions(int requestId, FusedBatchOptions optionsObject);
- private native void nativeStopBatching(int id);
- private native void nativeRequestBatchedLocation(int lastNLocations);
- private native void nativeFlushBatchedLocations();
- private native void nativeInjectLocation(Location location);
- private native void nativeCleanup();
-
- // FlpDiagnosticsInterface members
- private native boolean nativeIsDiagnosticSupported();
- private native void nativeInjectDiagnosticData(String data);
-
- // FlpDeviceContextInterface members
- private native boolean nativeIsDeviceContextSupported();
- private native void nativeInjectDeviceContext(int deviceEnabledContext);
-
- // FlpGeofencingInterface members
- private native boolean nativeIsGeofencingSupported();
- private native void nativeAddGeofences(
- GeofenceHardwareRequestParcelable[] geofenceRequestsArray);
- private native void nativePauseGeofence(int geofenceId);
- private native void nativeResumeGeofence(int geofenceId, int monitorTransitions);
- private native void nativeModifyGeofenceOption(
- int geofenceId,
- int lastTransition,
- int monitorTransitions,
- int notificationResponsiveness,
- int unknownTimer,
- int sourcesToUse);
- private native void nativeRemoveGeofences(int[] geofenceIdsArray);
-
- /**
* Interface implementations for services built on top of this functionality.
*/
public static final String LOCATION = "Location";
- public static final String GEOFENCING = "Geofencing";
public IFusedLocationHardware getLocationHardware() {
- return mLocationHardware;
+ return null;
}
public IFusedGeofenceHardware getGeofenceHardware() {
- return mGeofenceHardwareService;
+ return null;
}
public void cleanup() {
- Log.i(TAG, "Calling nativeCleanup()");
- nativeCleanup();
- }
-
- private final IFusedLocationHardware mLocationHardware = new IFusedLocationHardware.Stub() {
- @Override
- public void registerSink(IFusedLocationHardwareSink eventSink) {
- synchronized (mLocationSinkLock) {
- // only one sink is allowed at the moment
- if (mLocationSink != null) {
- Log.e(TAG, "Replacing an existing IFusedLocationHardware sink");
- }
-
- mLocationSink = eventSink;
- }
- maybeSendCapabilities();
- }
-
- @Override
- public void unregisterSink(IFusedLocationHardwareSink eventSink) {
- synchronized (mLocationSinkLock) {
- // don't throw if the sink is not registered, simply make it a no-op
- if (mLocationSink == eventSink) {
- mLocationSink = null;
- }
- }
- }
-
- @Override
- public int getSupportedBatchSize() {
- return nativeGetBatchSize();
- }
-
- @Override
- public void startBatching(int requestId, FusedBatchOptions options) {
- nativeStartBatching(requestId, options);
- }
-
- @Override
- public void stopBatching(int requestId) {
- nativeStopBatching(requestId);
- }
-
- @Override
- public void updateBatchingOptions(int requestId, FusedBatchOptions options) {
- nativeUpdateBatchingOptions(requestId, options);
- }
-
- @Override
- public void requestBatchOfLocations(int batchSizeRequested) {
- nativeRequestBatchedLocation(batchSizeRequested);
- }
-
- @Override
- public void flushBatchedLocations() {
- if (getVersion() >= FIRST_VERSION_WITH_FLUSH_LOCATIONS) {
- nativeFlushBatchedLocations();
- } else {
- Log.wtf(TAG,
- "Tried to call flushBatchedLocations on an unsupported implementation");
- }
- }
-
- @Override
- public boolean supportsDiagnosticDataInjection() {
- return nativeIsDiagnosticSupported();
- }
-
- @Override
- public void injectDiagnosticData(String data) {
- nativeInjectDiagnosticData(data);
- }
-
- @Override
- public boolean supportsDeviceContextInjection() {
- return nativeIsDeviceContextSupported();
- }
-
- @Override
- public void injectDeviceContext(int deviceEnabledContext) {
- nativeInjectDeviceContext(deviceEnabledContext);
- }
-
- @Override
- public int getVersion() {
- return FlpHardwareProvider.this.getVersion();
- }
- };
-
- private final IFusedGeofenceHardware mGeofenceHardwareService =
- new IFusedGeofenceHardware.Stub() {
- @Override
- public boolean isSupported() {
- return nativeIsGeofencingSupported();
- }
-
- @Override
- public void addGeofences(GeofenceHardwareRequestParcelable[] geofenceRequestsArray) {
- nativeAddGeofences(geofenceRequestsArray);
- }
-
- @Override
- public void removeGeofences(int[] geofenceIds) {
- nativeRemoveGeofences(geofenceIds);
- }
-
- @Override
- public void pauseMonitoringGeofence(int geofenceId) {
- nativePauseGeofence(geofenceId);
- }
-
- @Override
- public void resumeMonitoringGeofence(int geofenceId, int monitorTransitions) {
- nativeResumeGeofence(geofenceId, monitorTransitions);
- }
-
- @Override
- public void modifyGeofenceOptions(int geofenceId,
- int lastTransition,
- int monitorTransitions,
- int notificationResponsiveness,
- int unknownTimer,
- int sourcesToUse) {
- nativeModifyGeofenceOption(
- geofenceId,
- lastTransition,
- monitorTransitions,
- notificationResponsiveness,
- unknownTimer,
- sourcesToUse);
- }
- };
-
- /**
- * Internal classes and functions used by the provider.
- */
- private final class NetworkLocationListener implements LocationListener {
- @Override
- public void onLocationChanged(Location location) {
- if (
- !LocationManager.NETWORK_PROVIDER.equals(location.getProvider()) ||
- !location.hasAccuracy()
- ) {
- return;
- }
-
- nativeInjectLocation(location);
- }
-
- @Override
- public void onStatusChanged(String provider, int status, Bundle extras) { }
-
- @Override
- public void onProviderEnabled(String provider) { }
-
- @Override
- public void onProviderDisabled(String provider) { }
- }
-
- private GeofenceHardwareImpl getGeofenceHardwareSink() {
- if (mGeofenceHardwareSink == null) {
- mGeofenceHardwareSink = GeofenceHardwareImpl.getInstance(mContext);
- mGeofenceHardwareSink.setVersion(getVersion());
- }
-
- return mGeofenceHardwareSink;
- }
-
- private static int translateToGeofenceHardwareStatus(int flpHalResult) {
- switch(flpHalResult) {
- case FLP_RESULT_SUCCESS:
- return GeofenceHardware.GEOFENCE_SUCCESS;
- case FLP_RESULT_ERROR:
- return GeofenceHardware.GEOFENCE_FAILURE;
- case FLP_RESULT_INSUFFICIENT_MEMORY:
- return GeofenceHardware.GEOFENCE_ERROR_INSUFFICIENT_MEMORY;
- case FLP_RESULT_TOO_MANY_GEOFENCES:
- return GeofenceHardware.GEOFENCE_ERROR_TOO_MANY_GEOFENCES;
- case FLP_RESULT_ID_EXISTS:
- return GeofenceHardware.GEOFENCE_ERROR_ID_EXISTS;
- case FLP_RESULT_ID_UNKNOWN:
- return GeofenceHardware.GEOFENCE_ERROR_ID_UNKNOWN;
- case FLP_RESULT_INVALID_GEOFENCE_TRANSITION:
- return GeofenceHardware.GEOFENCE_ERROR_INVALID_TRANSITION;
- default:
- Log.e(TAG, String.format("Invalid FlpHal result code: %d", flpHalResult));
- return GeofenceHardware.GEOFENCE_FAILURE;
- }
- }
-
- private Location updateLocationInformation(Location location) {
- location.setProvider(LocationManager.FUSED_PROVIDER);
- // set the elapsed time-stamp just as GPS provider does
- location.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos());
- return location;
+ if (DEBUG) Log.d(TAG, "empty cleanup()");
}
}
diff --git a/services/core/java/com/android/server/location/GnssLocationProvider.java b/services/core/java/com/android/server/location/GnssLocationProvider.java
index fb2b961..24b2041 100644
--- a/services/core/java/com/android/server/location/GnssLocationProvider.java
+++ b/services/core/java/com/android/server/location/GnssLocationProvider.java
@@ -2069,7 +2069,10 @@
// note that this assumes the message will not be removed from the queue before
// it is handled (otherwise the wake lock would be leaked).
mWakeLock.acquire();
- Log.i(TAG, "WakeLock acquired by sendMessage(" + message + ", " + arg + ", " + obj + ")");
+ if (Log.isLoggable(TAG, Log.INFO)) {
+ Log.i(TAG, "WakeLock acquired by sendMessage(" + messageIdAsString(message) + ", " + arg
+ + ", " + obj + ")");
+ }
mHandler.obtainMessage(message, arg, 1, obj).sendToTarget();
}
@@ -2127,8 +2130,10 @@
if (msg.arg2 == 1) {
// wakelock was taken for this message, release it
mWakeLock.release();
- Log.i(TAG, "WakeLock released by handleMessage(" + message + ", " + msg.arg1 + ", "
- + msg.obj + ")");
+ if (Log.isLoggable(TAG, Log.INFO)) {
+ Log.i(TAG, "WakeLock released by handleMessage(" + messageIdAsString(message)
+ + ", " + msg.arg1 + ", " + msg.obj + ")");
+ }
}
}
@@ -2376,6 +2381,40 @@
}
}
+ /**
+ * @return A string representing the given message ID.
+ */
+ private String messageIdAsString(int message) {
+ switch (message) {
+ case ENABLE:
+ return "ENABLE";
+ case SET_REQUEST:
+ return "SET_REQUEST";
+ case UPDATE_NETWORK_STATE:
+ return "UPDATE_NETWORK_STATE";
+ case REQUEST_SUPL_CONNECTION:
+ return "REQUEST_SUPL_CONNECTION";
+ case RELEASE_SUPL_CONNECTION:
+ return "RELEASE_SUPL_CONNECTION";
+ case INJECT_NTP_TIME:
+ return "INJECT_NTP_TIME";
+ case DOWNLOAD_XTRA_DATA:
+ return "DOWNLOAD_XTRA_DATA";
+ case INJECT_NTP_TIME_FINISHED:
+ return "INJECT_NTP_TIME_FINISHED";
+ case DOWNLOAD_XTRA_DATA_FINISHED:
+ return "DOWNLOAD_XTRA_DATA_FINISHED";
+ case UPDATE_LOCATION:
+ return "UPDATE_LOCATION";
+ case SUBSCRIPTION_OR_SIM_CHANGED:
+ return "SUBSCRIPTION_OR_SIM_CHANGED";
+ case INITIALIZE_HANDLER:
+ return "INITIALIZE_HANDLER";
+ default:
+ return "<Unknown>";
+ }
+ }
+
@Override
public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
StringBuilder s = new StringBuilder();
@@ -2439,7 +2478,13 @@
// preallocated to avoid memory allocation in reportNmea()
private byte[] mNmeaBuffer = new byte[120];
- static { class_init_native(); }
+ static {
+ class_init_native();
+ if (Log.isLoggable(TAG, Log.DEBUG)) {
+ Log.d(TAG, "class_init_native()");
+ }
+ }
+
private static native void class_init_native();
private static native boolean native_is_supported();
private static native boolean native_is_agps_ril_supported();
diff --git a/services/core/jni/Android.mk b/services/core/jni/Android.mk
index d238215..eab5d8a 100644
--- a/services/core/jni/Android.mk
+++ b/services/core/jni/Android.mk
@@ -17,7 +17,6 @@
$(LOCAL_REL_DIR)/com_android_server_lights_LightsService.cpp \
$(LOCAL_REL_DIR)/com_android_server_location_ContextHubService.cpp \
$(LOCAL_REL_DIR)/com_android_server_location_GnssLocationProvider.cpp \
- $(LOCAL_REL_DIR)/com_android_server_location_FlpHardwareProvider.cpp \
$(LOCAL_REL_DIR)/com_android_server_power_PowerManagerService.cpp \
$(LOCAL_REL_DIR)/com_android_server_SerialService.cpp \
$(LOCAL_REL_DIR)/com_android_server_storage_AppFuseBridge.cpp \
diff --git a/services/core/jni/com_android_server_location_FlpHardwareProvider.cpp b/services/core/jni/com_android_server_location_FlpHardwareProvider.cpp
deleted file mode 100644
index 06d2031..0000000
--- a/services/core/jni/com_android_server_location_FlpHardwareProvider.cpp
+++ /dev/null
@@ -1,1101 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the license at
- *
- * http://www.apache.org/license/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the license.
- */
-
-#define LOG_TAG "FlpHardwareProvider"
-#define LOG_NDEBUG 0
-
-#define WAKE_LOCK_NAME "FLP"
-#define LOCATION_CLASS_NAME "android/location/Location"
-
-#include "jni.h"
-#include "JNIHelp.h"
-#include "android_runtime/AndroidRuntime.h"
-#include "android_runtime/Log.h"
-#include "hardware/fused_location.h"
-#include "hardware_legacy/power.h"
-
-static jobject sCallbacksObj = NULL;
-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;
-static jmethodID sOnBatchingStatus = NULL;
-static jmethodID sOnGeofenceTransition = NULL;
-static jmethodID sOnGeofenceMonitorStatus = NULL;
-static jmethodID sOnGeofenceAdd = NULL;
-static jmethodID sOnGeofenceRemove = NULL;
-static jmethodID sOnGeofencePause = NULL;
-static jmethodID sOnGeofenceResume = NULL;
-static jmethodID sOnGeofencingCapabilities = NULL;
-
-static const FlpLocationInterface* sFlpInterface = NULL;
-static const FlpDiagnosticInterface* sFlpDiagnosticInterface = NULL;
-static const FlpGeofencingInterface* sFlpGeofencingInterface = NULL;
-static const FlpDeviceContextInterface* sFlpDeviceContextInterface = NULL;
-
-namespace android {
-
-static inline void CheckExceptions(JNIEnv* env, const char* methodName) {
- if(!env->ExceptionCheck()) {
- return;
- }
-
- ALOGE("An exception was thrown by '%s'.", methodName);
- LOGE_EX(env);
- env->ExceptionClear();
-}
-
-static inline void ThrowOnError(
- JNIEnv* env,
- int resultCode,
- const char* methodName) {
- if(resultCode == FLP_RESULT_SUCCESS) {
- return;
- }
-
- ALOGE("Error %d in '%s'", resultCode, methodName);
- // TODO: this layer needs to be refactored to return error codes to Java
- // raising a FatalError is harsh, and because FLP Hardware Provider is loaded inside the system
- // service, it can cause the device to reboot, or remain in a reboot loop
- // a simple exception is still dumped to logcat, but it is handled more gracefully
- jclass exceptionClass = env->FindClass("java/lang/RuntimeException");
- env->ThrowNew(exceptionClass, methodName);
-}
-
-static bool IsValidCallbackThreadEnvOnly() {
- JNIEnv* env = AndroidRuntime::getJNIEnv();
-
- if(sCallbackEnv == NULL || sCallbackEnv != env) {
- ALOGE("CallbackThread check fail: env=%p, expected=%p", env, sCallbackEnv);
- return false;
- }
-
- return true;
-}
-
-static bool IsValidCallbackThread() {
- // sCallbacksObject is created when FlpHardwareProvider on Java side is
- // initialized. Sometimes the hardware may call a function before the Java
- // side is ready. In order to prevent a system crash, check whether
- // sCallbacksObj has been created. If not, simply ignore this event from
- // hardware.
- if (sCallbacksObj == NULL) {
- ALOGE("Attempt to use FlpHardwareProvider blocked, because it hasn't been initialized.");
- return false;
- }
-
- return IsValidCallbackThreadEnvOnly();
-}
-
-static void BatchingCapabilitiesCallback(int32_t capabilities) {
- if(!IsValidCallbackThread()) {
- return;
- }
-
- sCallbackEnv->CallVoidMethod(
- sCallbacksObj,
- sOnBatchingCapabilities,
- capabilities
- );
- CheckExceptions(sCallbackEnv, __FUNCTION__);
-}
-
-static void BatchingStatusCallback(int32_t status) {
- if(!IsValidCallbackThread()) {
- return;
- }
-
- sCallbackEnv->CallVoidMethod(
- sCallbacksObj,
- sOnBatchingStatus,
- status
- );
- CheckExceptions(sCallbackEnv, __FUNCTION__);
-}
-
-static int SetThreadEvent(ThreadEvent event) {
- JavaVM* javaVm = AndroidRuntime::getJavaVM();
-
- switch(event) {
- case ASSOCIATE_JVM:
- {
- if(sCallbackEnv != NULL) {
- ALOGE(
- "Attempted to associate callback in '%s'. Callback already associated.",
- __FUNCTION__
- );
- return FLP_RESULT_ERROR;
- }
-
- JavaVMAttachArgs args = {
- JNI_VERSION_1_6,
- "FLP Service Callback Thread",
- /* group */ NULL
- };
-
- jint attachResult = javaVm->AttachCurrentThread(&sCallbackEnv, &args);
- if (attachResult != 0) {
- ALOGE("Callback thread attachment error: %d", attachResult);
- return FLP_RESULT_ERROR;
- }
-
- 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:
- {
- if (!IsValidCallbackThreadEnvOnly()) {
- ALOGE(
- "Attempted to dissasociate an unnownk callback thread : '%s'.",
- __FUNCTION__
- );
- return FLP_RESULT_ERROR;
- }
-
- if (javaVm->DetachCurrentThread() != 0) {
- return FLP_RESULT_ERROR;
- }
-
- sCallbackEnv = NULL;
- break;
- }
- default:
- ALOGE("Invalid ThreadEvent request %d", event);
- return FLP_RESULT_ERROR;
- }
-
- return FLP_RESULT_SUCCESS;
-}
-
-/*
- * Initializes the FlpHardwareProvider class from the native side by opening
- * the HW module and obtaining the proper interfaces.
- */
-static void ClassInit(JNIEnv* env, jclass clazz) {
- sFlpInterface = NULL;
-
- // get references to the Java provider methods
- sSetVersion = env->GetMethodID(
- clazz,
- "setVersion",
- "(I)V");
- sOnLocationReport = env->GetMethodID(
- clazz,
- "onLocationReport",
- "([Landroid/location/Location;)V");
- sOnDataReport = env->GetMethodID(
- clazz,
- "onDataReport",
- "(Ljava/lang/String;)V"
- );
- sOnBatchingCapabilities = env->GetMethodID(
- clazz,
- "onBatchingCapabilities",
- "(I)V");
- sOnBatchingStatus = env->GetMethodID(
- clazz,
- "onBatchingStatus",
- "(I)V");
- sOnGeofencingCapabilities = env->GetMethodID(
- clazz,
- "onGeofencingCapabilities",
- "(I)V");
- sOnGeofenceTransition = env->GetMethodID(
- clazz,
- "onGeofenceTransition",
- "(ILandroid/location/Location;IJI)V"
- );
- sOnGeofenceMonitorStatus = env->GetMethodID(
- clazz,
- "onGeofenceMonitorStatus",
- "(IILandroid/location/Location;)V"
- );
- sOnGeofenceAdd = env->GetMethodID(clazz, "onGeofenceAdd", "(II)V");
- sOnGeofenceRemove = env->GetMethodID(clazz, "onGeofenceRemove", "(II)V");
- sOnGeofencePause = env->GetMethodID(clazz, "onGeofencePause", "(II)V");
- sOnGeofenceResume = env->GetMethodID(clazz, "onGeofenceResume", "(II)V");
-
- // open the hardware module
- const hw_module_t* module = NULL;
- int err = hw_get_module(FUSED_LOCATION_HARDWARE_MODULE_ID, &module);
- if (err != 0) {
- ALOGE("Error hw_get_module '%s': %d", FUSED_LOCATION_HARDWARE_MODULE_ID, err);
- return;
- }
-
- err = module->methods->open(
- module,
- FUSED_LOCATION_HARDWARE_MODULE_ID,
- &sHardwareDevice);
- if (err != 0) {
- ALOGE("Error opening device '%s': %d", FUSED_LOCATION_HARDWARE_MODULE_ID, err);
- return;
- }
-
- // acquire the interfaces pointers
- flp_device_t* flp_device = reinterpret_cast<flp_device_t*>(sHardwareDevice);
- sFlpInterface = flp_device->get_flp_interface(flp_device);
-
- if (sFlpInterface != NULL) {
- sFlpDiagnosticInterface = reinterpret_cast<const FlpDiagnosticInterface*>(
- sFlpInterface->get_extension(FLP_DIAGNOSTIC_INTERFACE));
-
- sFlpGeofencingInterface = reinterpret_cast<const FlpGeofencingInterface*>(
- sFlpInterface->get_extension(FLP_GEOFENCING_INTERFACE));
-
- sFlpDeviceContextInterface = reinterpret_cast<const FlpDeviceContextInterface*>(
- sFlpInterface->get_extension(FLP_DEVICE_CONTEXT_INTERFACE));
- }
-}
-
-/*
- * Helper function to unwrap a java object back into a FlpLocation structure.
- */
-static void TranslateFromObject(
- JNIEnv* env,
- jobject locationObject,
- FlpLocation& location) {
- location.size = sizeof(FlpLocation);
- location.flags = 0;
-
- jclass locationClass = env->GetObjectClass(locationObject);
-
- jmethodID getLatitude = env->GetMethodID(locationClass, "getLatitude", "()D");
- location.latitude = env->CallDoubleMethod(locationObject, getLatitude);
- jmethodID getLongitude = env->GetMethodID(locationClass, "getLongitude", "()D");
- location.longitude = env->CallDoubleMethod(locationObject, getLongitude);
- jmethodID getTime = env->GetMethodID(locationClass, "getTime", "()J");
- location.timestamp = env->CallLongMethod(locationObject, getTime);
- location.flags |= FLP_LOCATION_HAS_LAT_LONG;
-
- jmethodID hasAltitude = env->GetMethodID(locationClass, "hasAltitude", "()Z");
- if (env->CallBooleanMethod(locationObject, hasAltitude)) {
- jmethodID getAltitude = env->GetMethodID(locationClass, "getAltitude", "()D");
- location.altitude = env->CallDoubleMethod(locationObject, getAltitude);
- location.flags |= FLP_LOCATION_HAS_ALTITUDE;
- }
-
- jmethodID hasSpeed = env->GetMethodID(locationClass, "hasSpeed", "()Z");
- if (env->CallBooleanMethod(locationObject, hasSpeed)) {
- jmethodID getSpeed = env->GetMethodID(locationClass, "getSpeed", "()F");
- location.speed = env->CallFloatMethod(locationObject, getSpeed);
- location.flags |= FLP_LOCATION_HAS_SPEED;
- }
-
- jmethodID hasBearing = env->GetMethodID(locationClass, "hasBearing", "()Z");
- if (env->CallBooleanMethod(locationObject, hasBearing)) {
- jmethodID getBearing = env->GetMethodID(locationClass, "getBearing", "()F");
- location.bearing = env->CallFloatMethod(locationObject, getBearing);
- location.flags |= FLP_LOCATION_HAS_BEARING;
- }
-
- jmethodID hasAccuracy = env->GetMethodID(locationClass, "hasAccuracy", "()Z");
- if (env->CallBooleanMethod(locationObject, hasAccuracy)) {
- jmethodID getAccuracy = env->GetMethodID(
- locationClass,
- "getAccuracy",
- "()F"
- );
- location.accuracy = env->CallFloatMethod(locationObject, getAccuracy);
- location.flags |= FLP_LOCATION_HAS_ACCURACY;
- }
-
- // TODO: wire sources_used if Location class exposes them
-
- env->DeleteLocalRef(locationClass);
-}
-
-/*
- * Helper function to unwrap FlpBatchOptions from the Java Runtime calls.
- */
-static void TranslateFromObject(
- JNIEnv* env,
- jobject batchOptionsObject,
- FlpBatchOptions& batchOptions) {
- jclass batchOptionsClass = env->GetObjectClass(batchOptionsObject);
-
- jmethodID getMaxPower = env->GetMethodID(
- batchOptionsClass,
- "getMaxPowerAllocationInMW",
- "()D"
- );
- batchOptions.max_power_allocation_mW = env->CallDoubleMethod(
- batchOptionsObject,
- getMaxPower
- );
-
- jmethodID getPeriod = env->GetMethodID(
- batchOptionsClass,
- "getPeriodInNS",
- "()J"
- );
- batchOptions.period_ns = env->CallLongMethod(batchOptionsObject, getPeriod);
-
- jmethodID getSourcesToUse = env->GetMethodID(
- batchOptionsClass,
- "getSourcesToUse",
- "()I"
- );
- batchOptions.sources_to_use = env->CallIntMethod(
- batchOptionsObject,
- getSourcesToUse
- );
-
- jmethodID getSmallestDisplacementMeters = env->GetMethodID(
- batchOptionsClass,
- "getSmallestDisplacementMeters",
- "()F"
- );
- batchOptions.smallest_displacement_meters
- = env->CallFloatMethod(batchOptionsObject, getSmallestDisplacementMeters);
-
- jmethodID getFlags = env->GetMethodID(batchOptionsClass, "getFlags", "()I");
- batchOptions.flags = env->CallIntMethod(batchOptionsObject, getFlags);
-
- env->DeleteLocalRef(batchOptionsClass);
-}
-
-/*
- * Helper function to unwrap Geofence structures from the Java Runtime calls.
- */
-static void TranslateGeofenceFromGeofenceHardwareRequestParcelable(
- JNIEnv* env,
- jobject geofenceRequestObject,
- Geofence& geofence) {
- jclass geofenceRequestClass = env->GetObjectClass(geofenceRequestObject);
-
- jmethodID getId = env->GetMethodID(geofenceRequestClass, "getId", "()I");
- geofence.geofence_id = env->CallIntMethod(geofenceRequestObject, getId);
-
- jmethodID getType = env->GetMethodID(geofenceRequestClass, "getType", "()I");
- // this works because GeofenceHardwareRequest.java and fused_location.h have
- // the same notion of geofence types
- GeofenceType type = (GeofenceType)env->CallIntMethod(geofenceRequestObject, getType);
- if(type != TYPE_CIRCLE) {
- ThrowOnError(env, FLP_RESULT_ERROR, __FUNCTION__);
- }
- geofence.data->type = type;
- GeofenceCircle& circle = geofence.data->geofence.circle;
-
- jmethodID getLatitude = env->GetMethodID(
- geofenceRequestClass,
- "getLatitude",
- "()D");
- circle.latitude = env->CallDoubleMethod(geofenceRequestObject, getLatitude);
-
- jmethodID getLongitude = env->GetMethodID(
- geofenceRequestClass,
- "getLongitude",
- "()D");
- circle.longitude = env->CallDoubleMethod(geofenceRequestObject, getLongitude);
-
- jmethodID getRadius = env->GetMethodID(geofenceRequestClass, "getRadius", "()D");
- circle.radius_m = env->CallDoubleMethod(geofenceRequestObject, getRadius);
-
- GeofenceOptions* options = geofence.options;
- jmethodID getMonitorTransitions = env->GetMethodID(
- geofenceRequestClass,
- "getMonitorTransitions",
- "()I");
- options->monitor_transitions = env->CallIntMethod(
- geofenceRequestObject,
- getMonitorTransitions);
-
- jmethodID getUnknownTimer = env->GetMethodID(
- geofenceRequestClass,
- "getUnknownTimer",
- "()I");
- options->unknown_timer_ms = env->CallIntMethod(geofenceRequestObject, getUnknownTimer);
-
- jmethodID getNotificationResponsiveness = env->GetMethodID(
- geofenceRequestClass,
- "getNotificationResponsiveness",
- "()I");
- options->notification_responsivenes_ms = env->CallIntMethod(
- geofenceRequestObject,
- getNotificationResponsiveness);
-
- jmethodID getLastTransition = env->GetMethodID(
- geofenceRequestClass,
- "getLastTransition",
- "()I");
- options->last_transition = env->CallIntMethod(geofenceRequestObject, getLastTransition);
-
- jmethodID getSourceTechnologies =
- env->GetMethodID(geofenceRequestClass, "getSourceTechnologies", "()I");
- options->sources_to_use = env->CallIntMethod(geofenceRequestObject, getSourceTechnologies);
-
- env->DeleteLocalRef(geofenceRequestClass);
-}
-
-/*
- * Helper function to transform FlpLocation into a java object.
- */
-static void TranslateToObject(const FlpLocation* location, jobject& locationObject) {
- jclass locationClass = sCallbackEnv->FindClass(LOCATION_CLASS_NAME);
- jmethodID locationCtor = sCallbackEnv->GetMethodID(
- locationClass,
- "<init>",
- "(Ljava/lang/String;)V"
- );
-
- // the provider is set in the upper JVM layer
- locationObject = sCallbackEnv->NewObject(locationClass, locationCtor, NULL);
- jint flags = location->flags;
-
- // set the valid information in the object
- if (flags & FLP_LOCATION_HAS_LAT_LONG) {
- jmethodID setLatitude = sCallbackEnv->GetMethodID(
- locationClass,
- "setLatitude",
- "(D)V"
- );
- sCallbackEnv->CallVoidMethod(locationObject, setLatitude, location->latitude);
-
- jmethodID setLongitude = sCallbackEnv->GetMethodID(
- locationClass,
- "setLongitude",
- "(D)V"
- );
- sCallbackEnv->CallVoidMethod(
- locationObject,
- setLongitude,
- location->longitude
- );
-
- jmethodID setTime = sCallbackEnv->GetMethodID(
- locationClass,
- "setTime",
- "(J)V"
- );
- sCallbackEnv->CallVoidMethod(locationObject, setTime, location->timestamp);
- }
-
- if (flags & FLP_LOCATION_HAS_ALTITUDE) {
- jmethodID setAltitude = sCallbackEnv->GetMethodID(
- locationClass,
- "setAltitude",
- "(D)V"
- );
- sCallbackEnv->CallVoidMethod(locationObject, setAltitude, location->altitude);
- }
-
- if (flags & FLP_LOCATION_HAS_SPEED) {
- jmethodID setSpeed = sCallbackEnv->GetMethodID(
- locationClass,
- "setSpeed",
- "(F)V"
- );
- sCallbackEnv->CallVoidMethod(locationObject, setSpeed, location->speed);
- }
-
- if (flags & FLP_LOCATION_HAS_BEARING) {
- jmethodID setBearing = sCallbackEnv->GetMethodID(
- locationClass,
- "setBearing",
- "(F)V"
- );
- sCallbackEnv->CallVoidMethod(locationObject, setBearing, location->bearing);
- }
-
- if (flags & FLP_LOCATION_HAS_ACCURACY) {
- jmethodID setAccuracy = sCallbackEnv->GetMethodID(
- locationClass,
- "setAccuracy",
- "(F)V"
- );
- sCallbackEnv->CallVoidMethod(locationObject, setAccuracy, location->accuracy);
- }
-
- // TODO: wire FlpLocation::sources_used when needed
-
- sCallbackEnv->DeleteLocalRef(locationClass);
-}
-
-/*
- * Helper function to serialize FlpLocation structures.
- */
-static void TranslateToObjectArray(
- int32_t locationsCount,
- FlpLocation** locations,
- jobjectArray& locationsArray) {
- jclass locationClass = sCallbackEnv->FindClass(LOCATION_CLASS_NAME);
- locationsArray = sCallbackEnv->NewObjectArray(
- locationsCount,
- locationClass,
- /* initialElement */ NULL
- );
-
- for (int i = 0; i < locationsCount; ++i) {
- jobject locationObject = NULL;
- TranslateToObject(locations[i], locationObject);
- sCallbackEnv->SetObjectArrayElement(locationsArray, i, locationObject);
- sCallbackEnv->DeleteLocalRef(locationObject);
- }
-
- sCallbackEnv->DeleteLocalRef(locationClass);
-}
-
-static void LocationCallback(int32_t locationsCount, FlpLocation** locations) {
- if(!IsValidCallbackThread()) {
- return;
- }
-
- if(locationsCount == 0 || locations == NULL) {
- ALOGE(
- "Invalid LocationCallback. Count: %d, Locations: %p",
- locationsCount,
- locations
- );
- return;
- }
-
- jobjectArray locationsArray = NULL;
- TranslateToObjectArray(locationsCount, locations, locationsArray);
-
- sCallbackEnv->CallVoidMethod(
- sCallbacksObj,
- sOnLocationReport,
- locationsArray
- );
- CheckExceptions(sCallbackEnv, __FUNCTION__);
-
- if(locationsArray != NULL) {
- sCallbackEnv->DeleteLocalRef(locationsArray);
- }
-}
-
-static void AcquireWakelock() {
- acquire_wake_lock(PARTIAL_WAKE_LOCK, WAKE_LOCK_NAME);
-}
-
-static void ReleaseWakelock() {
- release_wake_lock(WAKE_LOCK_NAME);
-}
-
-FlpCallbacks sFlpCallbacks = {
- sizeof(FlpCallbacks),
- LocationCallback,
- AcquireWakelock,
- ReleaseWakelock,
- SetThreadEvent,
- BatchingCapabilitiesCallback,
- BatchingStatusCallback
-};
-
-static void ReportData(char* data, int length) {
- jstring stringData = NULL;
-
- if(length != 0 && data != NULL) {
- stringData = sCallbackEnv->NewString(reinterpret_cast<jchar*>(data), length);
- } else {
- ALOGE("Invalid ReportData callback. Length: %d, Data: %p", length, data);
- return;
- }
-
- sCallbackEnv->CallVoidMethod(sCallbacksObj, sOnDataReport, stringData);
- CheckExceptions(sCallbackEnv, __FUNCTION__);
-}
-
-FlpDiagnosticCallbacks sFlpDiagnosticCallbacks = {
- sizeof(FlpDiagnosticCallbacks),
- SetThreadEvent,
- ReportData
-};
-
-static void GeofenceTransitionCallback(
- int32_t geofenceId,
- FlpLocation* location,
- int32_t transition,
- FlpUtcTime timestamp,
- uint32_t sourcesUsed
- ) {
- if(!IsValidCallbackThread()) {
- return;
- }
-
- if(location == NULL) {
- ALOGE("GeofenceTransition received with invalid location: %p", location);
- return;
- }
-
- jobject locationObject = NULL;
- TranslateToObject(location, locationObject);
-
- sCallbackEnv->CallVoidMethod(
- sCallbacksObj,
- sOnGeofenceTransition,
- geofenceId,
- locationObject,
- transition,
- timestamp,
- sourcesUsed
- );
- CheckExceptions(sCallbackEnv, __FUNCTION__);
-
- if(locationObject != NULL) {
- sCallbackEnv->DeleteLocalRef(locationObject);
- }
-}
-
-static void GeofenceMonitorStatusCallback(
- int32_t status,
- uint32_t source,
- FlpLocation* lastLocation) {
- if(!IsValidCallbackThread()) {
- return;
- }
-
- jobject locationObject = NULL;
- if(lastLocation != NULL) {
- TranslateToObject(lastLocation, locationObject);
- }
-
- sCallbackEnv->CallVoidMethod(
- sCallbacksObj,
- sOnGeofenceMonitorStatus,
- status,
- source,
- locationObject
- );
- CheckExceptions(sCallbackEnv, __FUNCTION__);
-
- if(locationObject != NULL) {
- sCallbackEnv->DeleteLocalRef(locationObject);
- }
-}
-
-static void GeofenceAddCallback(int32_t geofenceId, int32_t result) {
- if(!IsValidCallbackThread()) {
- return;
- }
-
- sCallbackEnv->CallVoidMethod(sCallbacksObj, sOnGeofenceAdd, geofenceId, result);
- CheckExceptions(sCallbackEnv, __FUNCTION__);
-}
-
-static void GeofenceRemoveCallback(int32_t geofenceId, int32_t result) {
- if(!IsValidCallbackThread()) {
- return;
- }
-
- sCallbackEnv->CallVoidMethod(
- sCallbacksObj,
- sOnGeofenceRemove,
- geofenceId,
- result
- );
- CheckExceptions(sCallbackEnv, __FUNCTION__);
-}
-
-static void GeofencePauseCallback(int32_t geofenceId, int32_t result) {
- if(!IsValidCallbackThread()) {
- return;
- }
-
- sCallbackEnv->CallVoidMethod(
- sCallbacksObj,
- sOnGeofencePause,
- geofenceId,
- result
- );
- CheckExceptions(sCallbackEnv, __FUNCTION__);
-}
-
-static void GeofenceResumeCallback(int32_t geofenceId, int32_t result) {
- if(!IsValidCallbackThread()) {
- return;
- }
-
- sCallbackEnv->CallVoidMethod(
- sCallbacksObj,
- sOnGeofenceResume,
- geofenceId,
- result
- );
- CheckExceptions(sCallbackEnv, __FUNCTION__);
-}
-
-static void GeofencingCapabilitiesCallback(int32_t capabilities) {
- if(!IsValidCallbackThread()) {
- return;
- }
-
- sCallbackEnv->CallVoidMethod(
- sCallbacksObj,
- sOnGeofencingCapabilities,
- capabilities
- );
- CheckExceptions(sCallbackEnv, __FUNCTION__);
-}
-
-FlpGeofenceCallbacks sFlpGeofenceCallbacks = {
- sizeof(FlpGeofenceCallbacks),
- GeofenceTransitionCallback,
- GeofenceMonitorStatusCallback,
- GeofenceAddCallback,
- GeofenceRemoveCallback,
- GeofencePauseCallback,
- GeofenceResumeCallback,
- SetThreadEvent,
- GeofencingCapabilitiesCallback
-};
-
-/*
- * Initializes the Fused Location Provider in the native side. It ensures that
- * the Flp interfaces are initialized properly.
- */
-static void Init(JNIEnv* env, jobject obj) {
- if(sCallbacksObj == NULL) {
- sCallbacksObj = env->NewGlobalRef(obj);
- }
-
- // initialize the Flp interfaces
- if(sFlpInterface == NULL || sFlpInterface->init(&sFlpCallbacks) != 0) {
- ThrowOnError(env, FLP_RESULT_ERROR, __FUNCTION__);
- }
-
- if(sFlpDiagnosticInterface != NULL) {
- sFlpDiagnosticInterface->init(&sFlpDiagnosticCallbacks);
- }
-
- if(sFlpGeofencingInterface != NULL) {
- sFlpGeofencingInterface->init(&sFlpGeofenceCallbacks);
- }
-
- // TODO: inject any device context if when needed
-}
-
-static jboolean IsSupported(JNIEnv* /* env */, jclass /* clazz */) {
- if (sFlpInterface == NULL) {
- return JNI_FALSE;
- }
- return JNI_TRUE;
-}
-
-static jint GetBatchSize(JNIEnv* env, jobject /* object */) {
- if(sFlpInterface == NULL) {
- ThrowOnError(env, FLP_RESULT_ERROR, __FUNCTION__);
- }
-
- return sFlpInterface->get_batch_size();
-}
-
-static void StartBatching(
- JNIEnv* env,
- jobject /* object */,
- jint id,
- jobject optionsObject) {
- if(sFlpInterface == NULL || optionsObject == NULL) {
- ThrowOnError(env, FLP_RESULT_ERROR, __FUNCTION__);
- }
-
- FlpBatchOptions options;
- TranslateFromObject(env, optionsObject, options);
- int result = sFlpInterface->start_batching(id, &options);
- ThrowOnError(env, result, __FUNCTION__);
-}
-
-static void UpdateBatchingOptions(
- JNIEnv* env,
- jobject /* object */,
- jint id,
- jobject optionsObject) {
- if(sFlpInterface == NULL || optionsObject == NULL) {
- ThrowOnError(env, FLP_RESULT_ERROR, __FUNCTION__);
- }
-
- FlpBatchOptions options;
- TranslateFromObject(env, optionsObject, options);
- int result = sFlpInterface->update_batching_options(id, &options);
- ThrowOnError(env, result, __FUNCTION__);
-}
-
-static void StopBatching(JNIEnv* env, jobject /* object */, jint id) {
- if(sFlpInterface == NULL) {
- ThrowOnError(env, FLP_RESULT_ERROR, __FUNCTION__);
- }
-
- sFlpInterface->stop_batching(id);
-}
-
-static void Cleanup(JNIEnv* env, jobject /* object */) {
- if(sFlpInterface == NULL) {
- ThrowOnError(env, FLP_RESULT_ERROR, __FUNCTION__);
- }
-
- sFlpInterface->cleanup();
-
- if(sCallbacksObj != NULL) {
- env->DeleteGlobalRef(sCallbacksObj);
- sCallbacksObj = NULL;
- }
-}
-
-static void GetBatchedLocation(JNIEnv* env, jobject /* object */, jint lastNLocations) {
- if(sFlpInterface == NULL) {
- ThrowOnError(env, FLP_RESULT_ERROR, __FUNCTION__);
- }
-
- sFlpInterface->get_batched_location(lastNLocations);
-}
-
-static void FlushBatchedLocations(JNIEnv* env, jobject /* object */) {
- if(sFlpInterface == NULL) {
- ThrowOnError(env, FLP_RESULT_ERROR, __FUNCTION__);
- }
-
- sFlpInterface->flush_batched_locations();
-}
-
-static void InjectLocation(JNIEnv* env, jobject /* object */, jobject locationObject) {
- if(locationObject == NULL) {
- ALOGE("Invalid location for injection: %p", locationObject);
- ThrowOnError(env, FLP_RESULT_ERROR, __FUNCTION__);
- }
-
- if(sFlpInterface == NULL) {
- // there is no listener, bail
- return;
- }
-
- FlpLocation location;
- TranslateFromObject(env, locationObject, location);
- int result = sFlpInterface->inject_location(&location);
- if (result != FLP_RESULT_SUCCESS) {
- // do not throw but log, this operation should be fire and forget
- ALOGE("Error %d in '%s'", result, __FUNCTION__);
- }
-}
-
-static jboolean IsDiagnosticSupported() {
- return sFlpDiagnosticInterface != NULL;
-}
-
-static void InjectDiagnosticData(JNIEnv* env, jobject /* object */, jstring stringData) {
- if(stringData == NULL) {
- ALOGE("Invalid diagnostic data for injection: %p", stringData);
- ThrowOnError(env, FLP_RESULT_ERROR, __FUNCTION__);
- }
-
- if(sFlpDiagnosticInterface == NULL) {
- ThrowOnError(env, FLP_RESULT_ERROR, __FUNCTION__);
- }
-
- int length = env->GetStringLength(stringData);
- const jchar* data = env->GetStringChars(stringData, /* isCopy */ NULL);
- if(data == NULL) {
- ThrowOnError(env, FLP_RESULT_ERROR, __FUNCTION__);
- }
-
- int result = sFlpDiagnosticInterface->inject_data((char*) data, length);
- ThrowOnError(env, result, __FUNCTION__);
-}
-
-static jboolean IsDeviceContextSupported() {
- return sFlpDeviceContextInterface != NULL;
-}
-
-static void InjectDeviceContext(JNIEnv* env, jobject /* object */, jint enabledMask) {
- if(sFlpDeviceContextInterface == NULL) {
- ThrowOnError(env, FLP_RESULT_ERROR, __FUNCTION__);
- }
-
- int result = sFlpDeviceContextInterface->inject_device_context(enabledMask);
- ThrowOnError(env, result, __FUNCTION__);
-}
-
-static jboolean IsGeofencingSupported() {
- return sFlpGeofencingInterface != NULL;
-}
-
-static void AddGeofences(
- JNIEnv* env,
- jobject /* object */,
- jobjectArray geofenceRequestsArray) {
- if(geofenceRequestsArray == NULL) {
- ALOGE("Invalid Geofences to add: %p", geofenceRequestsArray);
- ThrowOnError(env, FLP_RESULT_ERROR, __FUNCTION__);
- }
-
- if (sFlpGeofencingInterface == NULL) {
- ThrowOnError(env, FLP_RESULT_ERROR, __FUNCTION__);
- }
-
- jint geofenceRequestsCount = env->GetArrayLength(geofenceRequestsArray);
- if(geofenceRequestsCount == 0) {
- return;
- }
-
- Geofence* geofences = new Geofence[geofenceRequestsCount];
- if (geofences == NULL) {
- ThrowOnError(env, FLP_RESULT_INSUFFICIENT_MEMORY, __FUNCTION__);
- }
-
- for (int i = 0; i < geofenceRequestsCount; ++i) {
- geofences[i].data = new GeofenceData();
- geofences[i].options = new GeofenceOptions();
- jobject geofenceObject = env->GetObjectArrayElement(geofenceRequestsArray, i);
-
- TranslateGeofenceFromGeofenceHardwareRequestParcelable(env, geofenceObject, geofences[i]);
- env->DeleteLocalRef(geofenceObject);
- }
-
- sFlpGeofencingInterface->add_geofences(geofenceRequestsCount, &geofences);
- if (geofences != NULL) {
- for(int i = 0; i < geofenceRequestsCount; ++i) {
- delete geofences[i].data;
- delete geofences[i].options;
- }
- delete[] geofences;
- }
-}
-
-static void PauseGeofence(JNIEnv* env, jobject /* object */, jint geofenceId) {
- if(sFlpGeofencingInterface == NULL) {
- ThrowOnError(env, FLP_RESULT_ERROR, __FUNCTION__);
- }
-
- sFlpGeofencingInterface->pause_geofence(geofenceId);
-}
-
-static void ResumeGeofence(
- JNIEnv* env,
- jobject /* object */,
- jint geofenceId,
- jint monitorTransitions) {
- if(sFlpGeofencingInterface == NULL) {
- ThrowOnError(env, FLP_RESULT_ERROR, __FUNCTION__);
- }
-
- sFlpGeofencingInterface->resume_geofence(geofenceId, monitorTransitions);
-}
-
-static void ModifyGeofenceOption(
- JNIEnv* env,
- jobject /* object */,
- jint geofenceId,
- jint lastTransition,
- jint monitorTransitions,
- jint notificationResponsiveness,
- jint unknownTimer,
- jint sourcesToUse) {
- if(sFlpGeofencingInterface == NULL) {
- ThrowOnError(env, FLP_RESULT_ERROR, __FUNCTION__);
- }
-
- GeofenceOptions options = {
- lastTransition,
- monitorTransitions,
- notificationResponsiveness,
- unknownTimer,
- (uint32_t)sourcesToUse
- };
-
- sFlpGeofencingInterface->modify_geofence_option(geofenceId, &options);
-}
-
-static void RemoveGeofences(
- JNIEnv* env,
- jobject /* object */,
- jintArray geofenceIdsArray) {
- if(sFlpGeofencingInterface == NULL) {
- ThrowOnError(env, FLP_RESULT_ERROR, __FUNCTION__);
- }
-
- jsize geofenceIdsCount = env->GetArrayLength(geofenceIdsArray);
- jint* geofenceIds = env->GetIntArrayElements(geofenceIdsArray, /* isCopy */ NULL);
- if(geofenceIds == NULL) {
- ThrowOnError(env, FLP_RESULT_ERROR, __FUNCTION__);
- }
-
- sFlpGeofencingInterface->remove_geofences(geofenceIdsCount, geofenceIds);
- env->ReleaseIntArrayElements(geofenceIdsArray, geofenceIds, 0 /*mode*/);
-}
-
-static const JNINativeMethod sMethods[] = {
- //{"name", "signature", functionPointer }
- {"nativeClassInit", "()V", reinterpret_cast<void*>(ClassInit)},
- {"nativeInit", "()V", reinterpret_cast<void*>(Init)},
- {"nativeCleanup", "()V", reinterpret_cast<void*>(Cleanup)},
- {"nativeIsSupported", "()Z", reinterpret_cast<void*>(IsSupported)},
- {"nativeGetBatchSize", "()I", reinterpret_cast<void*>(GetBatchSize)},
- {"nativeStartBatching",
- "(ILandroid/location/FusedBatchOptions;)V",
- reinterpret_cast<void*>(StartBatching)},
- {"nativeUpdateBatchingOptions",
- "(ILandroid/location/FusedBatchOptions;)V",
- reinterpret_cast<void*>(UpdateBatchingOptions)},
- {"nativeStopBatching", "(I)V", reinterpret_cast<void*>(StopBatching)},
- {"nativeRequestBatchedLocation",
- "(I)V",
- reinterpret_cast<void*>(GetBatchedLocation)},
- {"nativeFlushBatchedLocations",
- "()V",
- reinterpret_cast<void*>(FlushBatchedLocations)},
- {"nativeInjectLocation",
- "(Landroid/location/Location;)V",
- reinterpret_cast<void*>(InjectLocation)},
- {"nativeIsDiagnosticSupported",
- "()Z",
- reinterpret_cast<void*>(IsDiagnosticSupported)},
- {"nativeInjectDiagnosticData",
- "(Ljava/lang/String;)V",
- reinterpret_cast<void*>(InjectDiagnosticData)},
- {"nativeIsDeviceContextSupported",
- "()Z",
- reinterpret_cast<void*>(IsDeviceContextSupported)},
- {"nativeInjectDeviceContext",
- "(I)V",
- reinterpret_cast<void*>(InjectDeviceContext)},
- {"nativeIsGeofencingSupported",
- "()Z",
- reinterpret_cast<void*>(IsGeofencingSupported)},
- {"nativeAddGeofences",
- "([Landroid/hardware/location/GeofenceHardwareRequestParcelable;)V",
- reinterpret_cast<void*>(AddGeofences)},
- {"nativePauseGeofence", "(I)V", reinterpret_cast<void*>(PauseGeofence)},
- {"nativeResumeGeofence", "(II)V", reinterpret_cast<void*>(ResumeGeofence)},
- {"nativeModifyGeofenceOption",
- "(IIIIII)V",
- reinterpret_cast<void*>(ModifyGeofenceOption)},
- {"nativeRemoveGeofences", "([I)V", reinterpret_cast<void*>(RemoveGeofences)}
-};
-
-/*
- * Registration method invoked on JNI Load.
- */
-int register_android_server_location_FlpHardwareProvider(JNIEnv* env) {
- return jniRegisterNativeMethods(
- env,
- "com/android/server/location/FlpHardwareProvider",
- sMethods,
- NELEM(sMethods)
- );
-}
-
-} /* name-space Android */
diff --git a/services/core/jni/onload.cpp b/services/core/jni/onload.cpp
index 9758678..6f505d5 100644
--- a/services/core/jni/onload.cpp
+++ b/services/core/jni/onload.cpp
@@ -38,7 +38,6 @@
int register_android_server_VibratorService(JNIEnv* env);
int register_android_server_location_ContextHubService(JNIEnv* env);
int register_android_server_location_GnssLocationProvider(JNIEnv* env);
-int register_android_server_location_FlpHardwareProvider(JNIEnv* env);
int register_android_server_connectivity_Vpn(JNIEnv* env);
int register_android_server_hdmi_HdmiCecController(JNIEnv* env);
int register_android_server_tv_TvUinputBridge(JNIEnv* env);
@@ -76,7 +75,6 @@
register_android_server_SystemServer(env);
register_android_server_location_ContextHubService(env);
register_android_server_location_GnssLocationProvider(env);
- register_android_server_location_FlpHardwareProvider(env);
register_android_server_connectivity_Vpn(env);
register_android_server_ConsumerIrService(env);
register_android_server_BatteryStatsService(env);