summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinux Build Service Account <lnxbuild@localhost>2021-01-02 02:13:24 -0800
committerLinux Build Service Account <lnxbuild@localhost>2021-01-02 02:13:24 -0800
commit67346ca8894725ddd8d5e2f80d702ce05f30d655 (patch)
treea78b8a2fdd938c21c9391b65795c9831ec32b704
parent5e2a377d0357c14c88345d84d3c309e6351b7f74 (diff)
parent555935f14fe316db3cdbda4c0ba953a539cfad78 (diff)
Merge 555935f14fe316db3cdbda4c0ba953a539cfad78 on remote branch
Change-Id: I5724b20bf35bfc63c4bac87a7a7ed6572b8ea407
-rw-r--r--location/LocationAPI.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/location/LocationAPI.cpp b/location/LocationAPI.cpp
index dea0cad..3659b1c 100644
--- a/location/LocationAPI.cpp
+++ b/location/LocationAPI.cpp
@@ -39,6 +39,8 @@
typedef const GnssInterface* (getGnssInterface)();
typedef const GeofenceInterface* (getGeofenceInterface)();
typedef const BatchingInterface* (getBatchingInterface)();
+typedef void (createOSFramework)();
+typedef void (destroyOSFramework)();
typedef struct {
// bit mask of the adpaters that we need to wait for the removeClientCompleteCallback
@@ -68,6 +70,7 @@ static pthread_mutex_t gDataMutex = PTHREAD_MUTEX_INITIALIZER;
static bool gGnssLoadFailed = false;
static bool gBatchingLoadFailed = false;
static bool gGeofenceLoadFailed = false;
+static uint32_t gOSFrameworkRefCount = 0;
template <typename T1, typename T2>
static const T1* loadLocationInterface(const char* library, const char* name) {
@@ -80,6 +83,28 @@ static const T1* loadLocationInterface(const char* library, const char* name) {
}
}
+static void createOSFrameworkInstance() {
+ void* libHandle = nullptr;
+ createOSFramework* getter = (createOSFramework*)dlGetSymFromLib(libHandle,
+ "liblocationservice_glue.so", "createOSFramework");
+ if (getter != nullptr) {
+ (*getter)();
+ } else {
+ LOC_LOGe("dlGetSymFromLib failed for liblocationservice_glue.so");
+ }
+}
+
+static void destroyOSFrameworkInstance() {
+ void* libHandle = nullptr;
+ destroyOSFramework* getter = (destroyOSFramework*)dlGetSymFromLib(libHandle,
+ "liblocationservice_glue.so", "destroyOSFramework");
+ if (getter != nullptr) {
+ (*getter)();
+ } else {
+ LOC_LOGe("dlGetSymFromLib failed for liblocationservice_glue.so");
+ }
+}
+
static bool needsGnssTrackingInfo(LocationCallbacks& locationCallbacks)
{
return (locationCallbacks.gnssLocationInfoCb != nullptr ||
@@ -171,6 +196,11 @@ LocationAPI::createInstance (LocationCallbacks& locationCallbacks)
pthread_mutex_lock(&gDataMutex);
+ gOSFrameworkRefCount++;
+ if (1 == gOSFrameworkRefCount) {
+ createOSFrameworkInstance();
+ }
+
if (isGnssClient(locationCallbacks)) {
if (NULL == gData.gnssInterface && !gGnssLoadFailed) {
gData.gnssInterface =
@@ -296,6 +326,11 @@ LocationAPI::destroy(locationApiDestroyCompleteCallback destroyCompleteCb)
__func__, __LINE__, this);
}
+ if (1 == gOSFrameworkRefCount) {
+ destroyOSFrameworkInstance();
+ }
+ gOSFrameworkRefCount--;
+
pthread_mutex_unlock(&gDataMutex);
if (invokeDestroyCb) {
if (!destroyCompleteCb) {