fix CFI issues
Change-Id: I5b94804c381f1d26196ddf6dee97adbee36dc128 CRs-Fixed: 2353650
This commit is contained in:
parent
a6c61bde6a
commit
313284b9dd
7 changed files with 60 additions and 65 deletions
|
@ -27,7 +27,7 @@
|
|||
#include "Gnss.h"
|
||||
#include <LocationUtil.h>
|
||||
|
||||
typedef void* (getLocationInterface)();
|
||||
typedef const GnssInterface* (getLocationInterface)();
|
||||
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
|
@ -84,7 +84,7 @@ GnssAPIClient* Gnss::getApi() {
|
|||
return mApi;
|
||||
}
|
||||
|
||||
GnssInterface* Gnss::getGnssInterface() {
|
||||
const GnssInterface* Gnss::getGnssInterface() {
|
||||
static bool getGnssInterfaceFailed = false;
|
||||
if (nullptr == mGnssInterface && !getGnssInterfaceFailed) {
|
||||
LOC_LOGD("%s]: loading libgnss.so::getGnssInterface ...", __func__);
|
||||
|
@ -105,7 +105,7 @@ GnssInterface* Gnss::getGnssInterface() {
|
|||
if (NULL == getter) {
|
||||
getGnssInterfaceFailed = true;
|
||||
} else {
|
||||
mGnssInterface = (GnssInterface*)(*getter)();
|
||||
mGnssInterface = (const GnssInterface*)(*getter)();
|
||||
}
|
||||
}
|
||||
return mGnssInterface;
|
||||
|
@ -238,7 +238,7 @@ Return<bool> Gnss::injectLocation(double latitudeDegrees,
|
|||
double longitudeDegrees,
|
||||
float accuracyMeters) {
|
||||
ENTRY_LOG_CALLFLOW();
|
||||
GnssInterface* gnssInterface = getGnssInterface();
|
||||
const GnssInterface* gnssInterface = getGnssInterface();
|
||||
if (nullptr != gnssInterface) {
|
||||
gnssInterface->injectLocation(latitudeDegrees, longitudeDegrees, accuracyMeters);
|
||||
return true;
|
||||
|
@ -250,7 +250,7 @@ Return<bool> Gnss::injectLocation(double latitudeDegrees,
|
|||
Return<bool> Gnss::injectTime(int64_t timeMs, int64_t timeReferenceMs,
|
||||
int32_t uncertaintyMs) {
|
||||
ENTRY_LOG_CALLFLOW();
|
||||
GnssInterface* gnssInterface = getGnssInterface();
|
||||
const GnssInterface* gnssInterface = getGnssInterface();
|
||||
if (nullptr != gnssInterface) {
|
||||
gnssInterface->injectTime(timeMs, timeReferenceMs, uncertaintyMs);
|
||||
return true;
|
||||
|
|
|
@ -99,7 +99,7 @@ struct Gnss : public IGnss {
|
|||
GnssAPIClient* getApi();
|
||||
Return<bool> setGnssNiCb(const sp<IGnssNiCallback>& niCb);
|
||||
Return<bool> updateConfiguration(GnssConfig& gnssConfig);
|
||||
GnssInterface* getGnssInterface();
|
||||
const GnssInterface* getGnssInterface();
|
||||
|
||||
// Callback for ODCPI request
|
||||
void odcpiRequestCb(const OdcpiRequestInfo& request);
|
||||
|
@ -129,7 +129,7 @@ struct Gnss : public IGnss {
|
|||
sp<V1_0::IGnssCallback> mGnssCbIface = nullptr;
|
||||
sp<V1_0::IGnssNiCallback> mGnssNiCbIface = nullptr;
|
||||
GnssConfig mPendingConfig;
|
||||
GnssInterface* mGnssInterface = nullptr;
|
||||
const GnssInterface* mGnssInterface = nullptr;
|
||||
};
|
||||
|
||||
extern "C" IGnss* HIDL_FETCH_IGnss(const char* name);
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
#include "Gnss.h"
|
||||
#include <LocationUtil.h>
|
||||
|
||||
typedef void* (getLocationInterface)();
|
||||
typedef const GnssInterface* (getLocationInterface)();
|
||||
|
||||
#define IMAGES_INFO_FILE "/sys/devices/soc0/images"
|
||||
#define DELIMITER ";"
|
||||
|
@ -124,7 +124,7 @@ GnssAPIClient* Gnss::getApi() {
|
|||
return mApi;
|
||||
}
|
||||
|
||||
GnssInterface* Gnss::getGnssInterface() {
|
||||
const GnssInterface* Gnss::getGnssInterface() {
|
||||
static bool getGnssInterfaceFailed = false;
|
||||
if (nullptr == mGnssInterface && !getGnssInterfaceFailed) {
|
||||
LOC_LOGD("%s]: loading libgnss.so::getGnssInterface ...", __func__);
|
||||
|
@ -145,7 +145,7 @@ GnssInterface* Gnss::getGnssInterface() {
|
|||
if (NULL == getter) {
|
||||
getGnssInterfaceFailed = true;
|
||||
} else {
|
||||
mGnssInterface = (GnssInterface*)(*getter)();
|
||||
mGnssInterface = (const GnssInterface*)(*getter)();
|
||||
}
|
||||
}
|
||||
return mGnssInterface;
|
||||
|
@ -278,7 +278,7 @@ Return<bool> Gnss::injectLocation(double latitudeDegrees,
|
|||
double longitudeDegrees,
|
||||
float accuracyMeters) {
|
||||
ENTRY_LOG_CALLFLOW();
|
||||
GnssInterface* gnssInterface = getGnssInterface();
|
||||
const GnssInterface* gnssInterface = getGnssInterface();
|
||||
if (nullptr != gnssInterface) {
|
||||
gnssInterface->injectLocation(latitudeDegrees, longitudeDegrees, accuracyMeters);
|
||||
return true;
|
||||
|
@ -290,7 +290,7 @@ Return<bool> Gnss::injectLocation(double latitudeDegrees,
|
|||
Return<bool> Gnss::injectTime(int64_t timeMs, int64_t timeReferenceMs,
|
||||
int32_t uncertaintyMs) {
|
||||
ENTRY_LOG_CALLFLOW();
|
||||
GnssInterface* gnssInterface = getGnssInterface();
|
||||
const GnssInterface* gnssInterface = getGnssInterface();
|
||||
if (nullptr != gnssInterface) {
|
||||
gnssInterface->injectTime(timeMs, timeReferenceMs, uncertaintyMs);
|
||||
return true;
|
||||
|
@ -375,7 +375,7 @@ Return<bool> Gnss::setCallback_1_1(const sp<V1_1::IGnssCallback>& callback) {
|
|||
ENTRY_LOG_CALLFLOW();
|
||||
callback->gnssNameCb(getVersionString());
|
||||
mGnssCbIface_1_1 = callback;
|
||||
GnssInterface* gnssInterface = getGnssInterface();
|
||||
const GnssInterface* gnssInterface = getGnssInterface();
|
||||
if (nullptr != gnssInterface) {
|
||||
OdcpiRequestCallback cb = [this](const OdcpiRequestInfo& odcpiRequest) {
|
||||
odcpiRequestCb(odcpiRequest);
|
||||
|
@ -419,7 +419,7 @@ Return<sp<V1_1::IGnssConfiguration>> Gnss::getExtensionGnssConfiguration_1_1() {
|
|||
|
||||
Return<bool> Gnss::injectBestLocation(const GnssLocation& gnssLocation) {
|
||||
ENTRY_LOG_CALLFLOW();
|
||||
GnssInterface* gnssInterface = getGnssInterface();
|
||||
const GnssInterface* gnssInterface = getGnssInterface();
|
||||
if (nullptr != gnssInterface) {
|
||||
Location location = {};
|
||||
convertGnssLocation(gnssLocation, location);
|
||||
|
@ -446,9 +446,9 @@ void Gnss::odcpiRequestCb(const OdcpiRequestInfo& request) {
|
|||
}
|
||||
}
|
||||
|
||||
IGnss* HIDL_FETCH_IGnss(const char* hal) {
|
||||
V1_0::IGnss* HIDL_FETCH_IGnss(const char* hal) {
|
||||
ENTRY_LOG_CALLFLOW();
|
||||
IGnss* iface = nullptr;
|
||||
V1_0::IGnss* iface = nullptr;
|
||||
iface = new Gnss();
|
||||
if (iface == nullptr) {
|
||||
LOC_LOGE("%s]: failed to get %s", __FUNCTION__, hal);
|
||||
|
|
|
@ -109,7 +109,7 @@ struct Gnss : public IGnss {
|
|||
GnssAPIClient* getApi();
|
||||
Return<bool> setGnssNiCb(const sp<IGnssNiCallback>& niCb);
|
||||
Return<bool> updateConfiguration(GnssConfig& gnssConfig);
|
||||
GnssInterface* getGnssInterface();
|
||||
const GnssInterface* getGnssInterface();
|
||||
|
||||
// Callback for ODCPI request
|
||||
void odcpiRequestCb(const OdcpiRequestInfo& request);
|
||||
|
@ -140,10 +140,10 @@ struct Gnss : public IGnss {
|
|||
sp<V1_1::IGnssCallback> mGnssCbIface_1_1 = nullptr;
|
||||
sp<V1_0::IGnssNiCallback> mGnssNiCbIface = nullptr;
|
||||
GnssConfig mPendingConfig;
|
||||
GnssInterface* mGnssInterface = nullptr;
|
||||
const GnssInterface* mGnssInterface = nullptr;
|
||||
};
|
||||
|
||||
extern "C" IGnss* HIDL_FETCH_IGnss(const char* name);
|
||||
extern "C" V1_0::IGnss* HIDL_FETCH_IGnss(const char* name);
|
||||
|
||||
} // namespace implementation
|
||||
} // namespace V1_1
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
#include "Gnss.h"
|
||||
#include "LocationUtil.h"
|
||||
|
||||
typedef void* (getLocationInterface)();
|
||||
typedef const GnssInterface* (getLocationInterface)();
|
||||
|
||||
#define IMAGES_INFO_FILE "/sys/devices/soc0/images"
|
||||
#define DELIMITER ";"
|
||||
|
@ -125,7 +125,7 @@ GnssAPIClient* Gnss::getApi() {
|
|||
return mApi;
|
||||
}
|
||||
|
||||
GnssInterface* Gnss::getGnssInterface() {
|
||||
const GnssInterface* Gnss::getGnssInterface() {
|
||||
static bool getGnssInterfaceFailed = false;
|
||||
if (nullptr == mGnssInterface && !getGnssInterfaceFailed) {
|
||||
LOC_LOGD("%s]: loading libgnss.so::getGnssInterface ...", __func__);
|
||||
|
@ -146,7 +146,7 @@ GnssInterface* Gnss::getGnssInterface() {
|
|||
if (NULL == getter) {
|
||||
getGnssInterfaceFailed = true;
|
||||
} else {
|
||||
mGnssInterface = (GnssInterface*)(*getter)();
|
||||
mGnssInterface = (const GnssInterface*)(*getter)();
|
||||
}
|
||||
}
|
||||
return mGnssInterface;
|
||||
|
@ -283,7 +283,7 @@ Return<bool> Gnss::injectLocation(double latitudeDegrees,
|
|||
double longitudeDegrees,
|
||||
float accuracyMeters) {
|
||||
ENTRY_LOG_CALLFLOW();
|
||||
GnssInterface* gnssInterface = getGnssInterface();
|
||||
const GnssInterface* gnssInterface = getGnssInterface();
|
||||
if (nullptr != gnssInterface) {
|
||||
gnssInterface->injectLocation(latitudeDegrees, longitudeDegrees, accuracyMeters);
|
||||
return true;
|
||||
|
@ -295,7 +295,7 @@ Return<bool> Gnss::injectLocation(double latitudeDegrees,
|
|||
Return<bool> Gnss::injectTime(int64_t timeMs, int64_t timeReferenceMs,
|
||||
int32_t uncertaintyMs) {
|
||||
ENTRY_LOG_CALLFLOW();
|
||||
GnssInterface* gnssInterface = getGnssInterface();
|
||||
const GnssInterface* gnssInterface = getGnssInterface();
|
||||
if (nullptr != gnssInterface) {
|
||||
gnssInterface->injectTime(timeMs, timeReferenceMs, uncertaintyMs);
|
||||
return true;
|
||||
|
@ -383,7 +383,7 @@ Return<bool> Gnss::setCallback_1_1(const sp<V1_1::IGnssCallback>& callback) {
|
|||
ENTRY_LOG_CALLFLOW();
|
||||
callback->gnssNameCb(getVersionString());
|
||||
mGnssCbIface_1_1 = callback;
|
||||
GnssInterface* gnssInterface = getGnssInterface();
|
||||
const GnssInterface* gnssInterface = getGnssInterface();
|
||||
if (nullptr != gnssInterface) {
|
||||
OdcpiRequestCallback cb = [this](const OdcpiRequestInfo& odcpiRequest) {
|
||||
odcpiRequestCb(odcpiRequest);
|
||||
|
@ -431,7 +431,7 @@ Return<sp<V1_1::IGnssConfiguration>> Gnss::getExtensionGnssConfiguration_1_1() {
|
|||
|
||||
Return<bool> Gnss::injectBestLocation(const GnssLocation& gnssLocation) {
|
||||
ENTRY_LOG_CALLFLOW();
|
||||
GnssInterface* gnssInterface = getGnssInterface();
|
||||
const GnssInterface* gnssInterface = getGnssInterface();
|
||||
if (nullptr != gnssInterface) {
|
||||
Location location = {};
|
||||
convertGnssLocation(gnssLocation, location);
|
||||
|
@ -521,9 +521,9 @@ Return<sp<V2_0::IGnssDebug>> Gnss::getExtensionGnssDebug_2_0() {
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
IGnss* HIDL_FETCH_IGnss(const char* hal) {
|
||||
V1_0::IGnss* HIDL_FETCH_IGnss(const char* hal) {
|
||||
ENTRY_LOG_CALLFLOW();
|
||||
IGnss* iface = nullptr;
|
||||
V1_0::IGnss* iface = nullptr;
|
||||
iface = new Gnss();
|
||||
if (iface == nullptr) {
|
||||
LOC_LOGE("%s]: failed to get %s", __FUNCTION__, hal);
|
||||
|
|
|
@ -138,7 +138,7 @@ struct Gnss : public IGnss {
|
|||
GnssAPIClient* getApi();
|
||||
Return<bool> setGnssNiCb(const sp<IGnssNiCallback>& niCb);
|
||||
Return<bool> updateConfiguration(GnssConfig& gnssConfig);
|
||||
GnssInterface* getGnssInterface();
|
||||
const GnssInterface* getGnssInterface();
|
||||
|
||||
// Callback for ODCPI request
|
||||
void odcpiRequestCb(const OdcpiRequestInfo& request);
|
||||
|
@ -171,10 +171,10 @@ struct Gnss : public IGnss {
|
|||
|
||||
GnssAPIClient* mApi = nullptr;
|
||||
GnssConfig mPendingConfig;
|
||||
GnssInterface* mGnssInterface = nullptr;
|
||||
const GnssInterface* mGnssInterface = nullptr;
|
||||
};
|
||||
|
||||
extern "C" IGnss* HIDL_FETCH_IGnss(const char* name);
|
||||
extern "C" V1_0::IGnss* HIDL_FETCH_IGnss(const char* name);
|
||||
|
||||
} // namespace implementation
|
||||
} // namespace V2_0
|
||||
|
|
|
@ -34,8 +34,11 @@
|
|||
#include <log_util.h>
|
||||
#include <pthread.h>
|
||||
#include <map>
|
||||
#include <loc_misc_utils.h>
|
||||
|
||||
typedef void* (getLocationInterface)();
|
||||
typedef const GnssInterface* (getGnssInterface)();
|
||||
typedef const GeofenceInterface* (getGeofenceInterface)();
|
||||
typedef const BatchingInterface* (getBatchingInterface)();
|
||||
|
||||
typedef struct {
|
||||
// bit mask of the adpaters that we need to wait for the removeClientCompleteCallback
|
||||
|
@ -66,6 +69,17 @@ static bool gGnssLoadFailed = false;
|
|||
static bool gBatchingLoadFailed = false;
|
||||
static bool gGeofenceLoadFailed = false;
|
||||
|
||||
template <typename T1, typename T2>
|
||||
static const T1* loadLocationInterface(const char* library, const char* name) {
|
||||
void* libhandle = nullptr;
|
||||
T2* getter = (T2*)dlGetSymFromLib(libhandle, library, name);
|
||||
if (nullptr == getter) {
|
||||
return (const T1*) getter;
|
||||
}else {
|
||||
return (*getter)();
|
||||
}
|
||||
}
|
||||
|
||||
static bool isGnssClient(LocationCallbacks& locationCallbacks)
|
||||
{
|
||||
return (locationCallbacks.gnssNiCb != nullptr ||
|
||||
|
@ -85,32 +99,6 @@ static bool isGeofenceClient(LocationCallbacks& locationCallbacks)
|
|||
locationCallbacks.geofenceStatusCb != nullptr);
|
||||
}
|
||||
|
||||
static void* loadLocationInterface(const char* library, const char* name)
|
||||
{
|
||||
LOC_LOGD("%s]: loading %s::%s ...", __func__, library, name);
|
||||
if (NULL == library || NULL == name) {
|
||||
return NULL;
|
||||
}
|
||||
getLocationInterface* getter = NULL;
|
||||
const char *error = NULL;
|
||||
dlerror();
|
||||
void *handle = dlopen(library, RTLD_NOW);
|
||||
if (NULL == handle || (error = dlerror()) != NULL) {
|
||||
LOC_LOGW("dlopen for %s failed, error = %s", library, error);
|
||||
} else {
|
||||
getter = (getLocationInterface*)dlsym(handle, name);
|
||||
if ((error = dlerror()) != NULL) {
|
||||
LOC_LOGW("dlsym for %s::%s failed, error = %s", library, name, error);
|
||||
getter = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (NULL == getter) {
|
||||
return (void*)getter;
|
||||
} else {
|
||||
return (*getter)();
|
||||
}
|
||||
}
|
||||
|
||||
void LocationAPI::onRemoveClientCompleteCb (LocationAdapterTypeMask adapterType)
|
||||
{
|
||||
|
@ -170,7 +158,8 @@ LocationAPI::createInstance(LocationCallbacks& locationCallbacks)
|
|||
if (isGnssClient(locationCallbacks)) {
|
||||
if (NULL == gData.gnssInterface && !gGnssLoadFailed) {
|
||||
gData.gnssInterface =
|
||||
(GnssInterface*)loadLocationInterface("libgnss.so", "getGnssInterface");
|
||||
(GnssInterface*)loadLocationInterface<GnssInterface,
|
||||
getGnssInterface>("libgnss.so", "getGnssInterface");
|
||||
if (NULL == gData.gnssInterface) {
|
||||
gGnssLoadFailed = true;
|
||||
LOC_LOGW("%s:%d]: No gnss interface available", __func__, __LINE__);
|
||||
|
@ -190,7 +179,8 @@ LocationAPI::createInstance(LocationCallbacks& locationCallbacks)
|
|||
if (isBatchingClient(locationCallbacks)) {
|
||||
if (NULL == gData.batchingInterface && !gBatchingLoadFailed) {
|
||||
gData.batchingInterface =
|
||||
(BatchingInterface*)loadLocationInterface("libbatching.so", "getBatchingInterface");
|
||||
(BatchingInterface*)loadLocationInterface<BatchingInterface,
|
||||
getBatchingInterface>("libbatching.so", "getBatchingInterface");
|
||||
if (NULL == gData.batchingInterface) {
|
||||
gBatchingLoadFailed = true;
|
||||
LOC_LOGW("%s:%d]: No batching interface available", __func__, __LINE__);
|
||||
|
@ -210,7 +200,8 @@ LocationAPI::createInstance(LocationCallbacks& locationCallbacks)
|
|||
if (isGeofenceClient(locationCallbacks)) {
|
||||
if (NULL == gData.geofenceInterface && !gGeofenceLoadFailed) {
|
||||
gData.geofenceInterface =
|
||||
(GeofenceInterface*)loadLocationInterface("libgeofencing.so", "getGeofenceInterface");
|
||||
(GeofenceInterface*)loadLocationInterface<GeofenceInterface,
|
||||
getGeofenceInterface>("libgeofencing.so", "getGeofenceInterface");
|
||||
if (NULL == gData.geofenceInterface) {
|
||||
gGeofenceLoadFailed = true;
|
||||
LOC_LOGW("%s:%d]: No geofence interface available", __func__, __LINE__);
|
||||
|
@ -324,7 +315,8 @@ LocationAPI::updateCallbacks(LocationCallbacks& locationCallbacks)
|
|||
if (isGnssClient(locationCallbacks)) {
|
||||
if (NULL == gData.gnssInterface && !gGnssLoadFailed) {
|
||||
gData.gnssInterface =
|
||||
(GnssInterface*)loadLocationInterface("libgnss.so", "getGnssInterface");
|
||||
(GnssInterface*)loadLocationInterface<GnssInterface,
|
||||
getGnssInterface>("libgnss.so", "getGnssInterface");
|
||||
if (NULL == gData.gnssInterface) {
|
||||
gGnssLoadFailed = true;
|
||||
LOC_LOGW("%s:%d]: No gnss interface available", __func__, __LINE__);
|
||||
|
@ -341,7 +333,8 @@ LocationAPI::updateCallbacks(LocationCallbacks& locationCallbacks)
|
|||
if (isBatchingClient(locationCallbacks)) {
|
||||
if (NULL == gData.batchingInterface && !gBatchingLoadFailed) {
|
||||
gData.batchingInterface =
|
||||
(BatchingInterface*)loadLocationInterface("libbatching.so", "getBatchingInterface");
|
||||
(BatchingInterface*)loadLocationInterface<BatchingInterface,
|
||||
getBatchingInterface>("libbatching.so", "getBatchingInterface");
|
||||
if (NULL == gData.batchingInterface) {
|
||||
gBatchingLoadFailed = true;
|
||||
LOC_LOGW("%s:%d]: No batching interface available", __func__, __LINE__);
|
||||
|
@ -358,7 +351,8 @@ LocationAPI::updateCallbacks(LocationCallbacks& locationCallbacks)
|
|||
if (isGeofenceClient(locationCallbacks)) {
|
||||
if (NULL == gData.geofenceInterface && !gGeofenceLoadFailed) {
|
||||
gData.geofenceInterface =
|
||||
(GeofenceInterface*)loadLocationInterface("libgeofencing.so", "getGeofenceInterface");
|
||||
(GeofenceInterface*)loadLocationInterface<GeofenceInterface,
|
||||
getGeofenceInterface>("libgeofencing.so", "getGeofenceInterface");
|
||||
if (NULL == gData.geofenceInterface) {
|
||||
gGeofenceLoadFailed = true;
|
||||
LOC_LOGW("%s:%d]: No geofence interface available", __func__, __LINE__);
|
||||
|
@ -606,7 +600,8 @@ LocationControlAPI::createInstance(LocationControlCallbacks& locationControlCall
|
|||
if (nullptr != locationControlCallbacks.responseCb && NULL == gData.controlAPI) {
|
||||
if (NULL == gData.gnssInterface && !gGnssLoadFailed) {
|
||||
gData.gnssInterface =
|
||||
(GnssInterface*)loadLocationInterface("libgnss.so", "getGnssInterface");
|
||||
(GnssInterface*)loadLocationInterface<GnssInterface,
|
||||
getGnssInterface>("libgnss.so", "getGnssInterface");
|
||||
if (NULL == gData.gnssInterface) {
|
||||
gGnssLoadFailed = true;
|
||||
LOC_LOGW("%s:%d]: No gnss interface available", __func__, __LINE__);
|
||||
|
|
Loading…
Reference in a new issue