sm8250-common: import location from LA.UM.9.12.r1-13500.01-SMxx50.QSSI12.0

Change-Id: If93ba9b50dc3bb07a4ba81694187e99f58dd172c
This commit is contained in:
SGCMarkus 2022-03-23 21:42:45 +01:00
parent 72410cf795
commit 64ab05b033
103 changed files with 92521 additions and 0 deletions

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,200 @@
/* Copyright (c) 2018-2020, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation, nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef LOCHAL_CLIENT_HANDLER_H
#define LOCHAL_CLIENT_HANDLER_H
#include <queue>
#include <mutex>
#include <log_util.h>
#include <loc_pla.h>
#ifdef NO_UNORDERED_SET_OR_MAP
#include <map>
#else
#include <unordered_map>
#endif
#include <LocationAPI.h>
#include <LocIpc.h>
#include <LocationApiPbMsgConv.h>
using namespace loc_util;
// forward declaration
class LocationApiService;
/******************************************************************************
LocHalDaemonClientHandler
******************************************************************************/
class LocHalDaemonClientHandler
{
public:
inline LocHalDaemonClientHandler(LocationApiService* service, const std::string& clientname,
ClientType clientType) :
mService(service),
mName(clientname),
mClientType(clientType),
mCapabilityMask(0),
mTracking(false),
mBatching(false),
mSessionId(0),
mBatchingId(0),
mBatchingMode(BATCHING_MODE_NO_AUTO_REPORT),
mLocationApi(nullptr),
mCallbacks{},
mPendingMessages(),
mGfPendingMessages(),
mSubscriptionMask(0),
mEngineInfoRequestMask(0),
mGeofenceIds(nullptr),
mIpcSender(createSender(clientname.c_str())) {
if (mClientType == LOCATION_CLIENT_API) {
updateSubscription(E_LOC_CB_GNSS_LOCATION_INFO_BIT);
// client has not yet subscribed to anything yet
mSubscriptionMask = 0;
mLocationApi = LocationAPI::createInstance(mCallbacks);
}
}
static shared_ptr<LocIpcSender> createSender(const string socket);
void cleanup();
// public APIs
void updateSubscription(uint32_t mask);
// when client stops the location session, then all callbacks
// related to location session need to be unsubscribed
void unsubscribeLocationSessionCb();
uint32_t startTracking();
uint32_t startTracking(LocationOptions & locOptions);
void stopTracking();
void updateTrackingOptions(LocationOptions & locOptions);
void onGnssEnergyConsumedInfoAvailable(LocAPIGnssEnergyConsumedIndMsg &msg);
void onControlResponseCb(LocationError err, ELocMsgID msgId);
void onGnssConfigCb(ELocMsgID configMsgId, const GnssConfig & gnssConfig);
bool hasPendingEngineInfoRequest(uint32_t mask);
void addEngineInfoRequst(uint32_t mask);
uint32_t startBatching(uint32_t minInterval, uint32_t minDistance, BatchingMode batchMode);
void stopBatching();
void updateBatchingOptions(uint32_t minInterval, uint32_t minDistance, BatchingMode batchMode);
uint32_t* addGeofences(size_t count, GeofenceOption*, GeofenceInfo*);
void removeGeofences(size_t count, uint32_t* ids);
void modifyGeofences(size_t count, uint32_t* ids, GeofenceOption* options);
void pauseGeofences(size_t count, uint32_t* ids);
void resumeGeofences(size_t count, uint32_t* ids);
//other API
void setGeofenceIds(size_t count, uint32_t* clientIds, uint32_t* sessionIds);
void eraseGeofenceIds(size_t count, uint32_t* clientIds);
uint32_t* getSessionIds(size_t count, uint32_t* clientIds);
uint32_t* getClientIds(size_t count, uint32_t* sessionIds);
// send terrestrial fix to the requesting LCA client
void sendTerrestrialFix(LocationError error, const Location& location);
inline shared_ptr<LocIpcSender> getIpcSender () {return mIpcSender;};
void pingTest();
bool mTracking;
bool mBatching;
BatchingMode mBatchingMode;
std::queue<ELocMsgID> mPendingMessages;
std::queue<ELocMsgID> mGfPendingMessages;
private:
inline ~LocHalDaemonClientHandler() {}
// Location API callback functions
void onCapabilitiesCallback(LocationCapabilitiesMask capabilitiesMask);
void onResponseCb(LocationError err, uint32_t id);
void onCollectiveResponseCallback(size_t count, LocationError *errs, uint32_t *ids);
void onTrackingCb(Location location);
void onBatchingCb(size_t count, Location* location, BatchingOptions batchOptions);
void onBatchingStatusCb(BatchingStatusInfo batchingStatus,
std::list<uint32_t>& listOfCompletedTrips);
void onGnssLocationInfoCb(GnssLocationInfoNotification gnssLocationInfoNotification);
void onGeofenceBreachCb(GeofenceBreachNotification geofenceBreachNotification);
void onEngLocationsInfoCb(uint32_t count,
GnssLocationInfoNotification* engLocationsInfoNotification);
void onGnssNiCb(uint32_t id, GnssNiNotification gnssNiNotification);
void onGnssSvCb(GnssSvNotification gnssSvNotification);
void onGnssNmeaCb(GnssNmeaNotification);
void onGnssDataCb(GnssDataNotification gnssDataNotification);
void onGnssMeasurementsCb(GnssMeasurementsNotification gnssMeasurementsNotification);
void onLocationSystemInfoCb(LocationSystemInfo);
void onLocationApiDestroyCompleteCb();
// send ipc message to this client for serialized payload
bool sendMessage(const char* msg, size_t msglen, ELocMsgID msg_id) {
bool retVal= LocIpc::send(*mIpcSender, reinterpret_cast<const uint8_t*>(msg), msglen);
if (retVal == false) {
struct timespec ts;
clock_gettime(CLOCK_BOOTTIME, &ts);
LOC_LOGe("failed: client %s, msg id: %d, msg size %d, err %s, "
"boot timestamp %" PRIu64" msec",
mName.c_str(), msg_id, msglen, strerror(errno),
(ts.tv_sec * 1000ULL + ts.tv_nsec/1000000));
}
return retVal;
}
uint32_t getSupportedTbf (uint32_t tbfMsec);
// pointer to parent service
LocationApiService* mService;
// name of this client
const std::string mName;
ClientType mClientType;
// LocationAPI interface
LocationCapabilitiesMask mCapabilityMask;
uint32_t mSessionId;
uint32_t mBatchingId;
LocationAPI* mLocationApi;
LocationCallbacks mCallbacks;
TrackingOptions mOptions;
BatchingOptions mBatchOptions;
// bitmask to hold this client's subscription
uint32_t mSubscriptionMask;
// bitmask to hold this client's request to engine info related subscription
uint32_t mEngineInfoRequestMask;
uint32_t* mGeofenceIds;
shared_ptr<LocIpcSender> mIpcSender;
std::unordered_map<uint32_t, uint32_t> mGfIdsMap; //geofence ID map, clientId-->session
};
#endif //LOCHAL_CLIENT_HANDLER_H

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,317 @@
/* Copyright (c) 2018-2020 The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation, nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef LOCATIONAPISERVICE_H
#define LOCATIONAPISERVICE_H
#include <string>
#include <mutex>
#include <MsgTask.h>
#include <loc_cfg.h>
#include <LocIpc.h>
#include <LocTimer.h>
#ifdef POWERMANAGER_ENABLED
#include <PowerEvtHandler.h>
#endif
#include <location_interface.h>
#include <LocationAPI.h>
#include <LocationApiMsg.h>
#include <LocHalDaemonClientHandler.h>
#ifdef NO_UNORDERED_SET_OR_MAP
#include <map>
#else
#include <unordered_map>
#endif
#undef LOG_TAG
#define LOG_TAG "LocSvc_HalDaemon"
typedef struct {
uint32_t autoStartGnss;
uint32_t gnssSessionTbfMs;
uint32_t deleteAllBeforeAutoStart;
uint32_t posEngineMask;
uint32_t positionMode;
} configParamToRead;
/******************************************************************************
LocationApiService
******************************************************************************/
typedef struct {
// this stores the client name and the command type that client requests
// the info will be used to send back command response
std::string clientName;
ELocMsgID configMsgId;
} ConfigReqClientData;
// periodic timer to perform maintenance work, e.g.: resource cleanup
// for location hal daemon
typedef std::unordered_map<std::string, shared_ptr<LocIpcSender>> ClientNameIpcSenderMap;
class MaintTimer : public LocTimer {
public:
MaintTimer(LocationApiService* locationApiService) :
mLocationApiService(locationApiService) {
};
~MaintTimer() = default;
public:
void timeOutCallback() override;
private:
LocationApiService* mLocationApiService;
};
class SingleTerrestrialFixTimer : public LocTimer {
public:
SingleTerrestrialFixTimer(LocationApiService* locationApiService,
std::string& clientName) :
mLocationApiService(locationApiService),
mClientName(clientName) {
}
~SingleTerrestrialFixTimer() {
}
public:
void timeOutCallback() override;
private:
LocationApiService* mLocationApiService;
const std::string mClientName;
};
// This keeps track of the client that requests single fix terrestrial position
// and the timer that will fire when the timeout value has reached
typedef std::unordered_map<std::string, SingleTerrestrialFixTimer>
SingleTerrestrialFixClientMap;
class LocationApiService
{
public:
// singleton instance
LocationApiService(const LocationApiService&) = delete;
LocationApiService& operator = (const LocationApiService&) = delete;
static LocationApiService* getInstance(
const configParamToRead & configParamRead) {
if (nullptr == mInstance) {
mInstance = new LocationApiService(configParamRead);
}
return mInstance;
}
static void destroy() {
if (nullptr != mInstance) {
delete mInstance;
mInstance = nullptr;
}
}
// APIs can be invoked by IPC
void processClientMsg(const char* data, uint32_t length);
// from IPC receiver
void onListenerReady(bool externalApIpc);
#ifdef POWERMANAGER_ENABLED
void onPowerEvent(PowerStateType powerState);
#endif
// other APIs
void deleteClientbyName(const std::string name);
// protobuf conversion util class
LocationApiPbMsgConv mPbufMsgConv;
static std::mutex mMutex;
// Utility routine used by maintenance timer
void performMaintenance();
// Utility routine used by gtp fix timeout timer
void gtpFixRequestTimeout(const std::string& clientName);
inline const MsgTask& getMsgTask() const {return mMsgTask;};
private:
// APIs can be invoked to process client's IPC messgage
void newClient(LocAPIClientRegisterReqMsg*);
void deleteClient(LocAPIClientDeregisterReqMsg*);
void startTracking(LocAPIStartTrackingReqMsg*);
void stopTracking(LocAPIStopTrackingReqMsg*);
void suspendAllTrackingSessions();
void resumeAllTrackingSessions();
void updateSubscription(LocAPIUpdateCallbacksReqMsg*);
void updateTrackingOptions(LocAPIUpdateTrackingOptionsReqMsg*);
void updateNetworkAvailability(bool availability);
void getGnssEnergyConsumed(const char* clientSocketName);
void getSingleTerrestrialPos(LocAPIGetSingleTerrestrialPosReqMsg*);
void startBatching(LocAPIStartBatchingReqMsg*);
void stopBatching(LocAPIStopBatchingReqMsg*);
void updateBatchingOptions(LocAPIUpdateBatchingOptionsReqMsg*);
void addGeofences(LocAPIAddGeofencesReqMsg*);
void removeGeofences(LocAPIRemoveGeofencesReqMsg*);
void modifyGeofences(LocAPIModifyGeofencesReqMsg*);
void pauseGeofences(LocAPIPauseGeofencesReqMsg*);
void resumeGeofences(LocAPIResumeGeofencesReqMsg*);
void pingTest(LocAPIPingTestReqMsg*);
inline uint32_t gnssUpdateConfig(const GnssConfig& config) {
uint32_t* sessionIds = mLocationControlApi->gnssUpdateConfig(config);
// in our usage, we only configure one setting at a time,
// so we have only one sessionId
uint32_t sessionId = 0;
if (sessionIds) {
sessionId = *sessionIds;
delete [] sessionIds;
}
return sessionId;
}
// Location control API callback
void onControlResponseCallback(LocationError err, uint32_t id);
void onControlCollectiveResponseCallback(size_t count, LocationError *errs, uint32_t *ids);
void onGnssConfigCallback(uint32_t sessionId, const GnssConfig& config);
void onGnssEnergyConsumedCb(uint64_t totalEnergyConsumedSinceFirstBoot);
// Callbacks for location api used service GTP WWAN fix request
void onCapabilitiesCallback(LocationCapabilitiesMask mask);
void onResponseCb(LocationError err, uint32_t id);
void onCollectiveResponseCallback(size_t count, LocationError *errs, uint32_t *ids);
void onGtpWwanTrackingCallback(Location location);
// Location configuration API requests
void configConstrainedTunc(
const LocConfigConstrainedTuncReqMsg* pMsg);
void configPositionAssistedClockEstimator(
const LocConfigPositionAssistedClockEstimatorReqMsg* pMsg);
void configConstellations(
const LocConfigSvConstellationReqMsg* pMsg);
void configConstellationSecondaryBand(
const LocConfigConstellationSecondaryBandReqMsg* pMsg);
void configAidingDataDeletion(
LocConfigAidingDataDeletionReqMsg* pMsg);
void configLeverArm(const LocConfigLeverArmReqMsg* pMsg);
void configRobustLocation(const LocConfigRobustLocationReqMsg* pMsg);
void configMinGpsWeek(const LocConfigMinGpsWeekReqMsg* pMsg);
void configDeadReckoningEngineParams(const LocConfigDrEngineParamsReqMsg* pMsg);
void configMinSvElevation(const LocConfigMinSvElevationReqMsg* pMsg);
void configEngineRunState(const LocConfigEngineRunStateReqMsg* pMsg);
void configUserConsentTerrestrialPositioning(
LocConfigUserConsentTerrestrialPositioningReqMsg* pMsg);
// Location configuration API get/read requests
void getGnssConfig(const LocAPIMsgHeader* pReqMsg,
GnssConfigFlagsBits configFlag);
void getConstellationSecondaryBandConfig(
const LocConfigGetConstellationSecondaryBandConfigReqMsg* pReqMsg);
// Location configuration API util routines
void addConfigRequestToMap(uint32_t sessionId,
const LocAPIMsgHeader* pMsg);
LocationApiService(const configParamToRead & configParamRead);
virtual ~LocationApiService();
// private utilities
inline LocHalDaemonClientHandler* getClient(const std::string& clientname) {
// find client from property db
auto client = mClients.find(clientname);
if (client == std::end(mClients)) {
LOC_LOGe("Failed to find client %s", clientname.c_str());
return nullptr;
}
return client->second;
}
inline LocHalDaemonClientHandler* getClient(const char* socketName) {
std::string clientname(socketName);
return getClient(clientname);
}
GnssInterface* getGnssInterface();
#ifdef POWERMANAGER_ENABLED
// power event observer
PowerEvtHandler* mPowerEventObserver;
#endif
// singleton instance
static LocationApiService *mInstance;
// IPC interface
LocIpc mIpc;
unique_ptr<LocIpcRecver> mBlockingRecver;
// Client propery database
std::unordered_map<std::string, LocHalDaemonClientHandler*> mClients;
std::unordered_map<uint32_t, ConfigReqClientData> mConfigReqs;
// Location Control API interface
uint32_t mLocationControlId;
LocationControlCallbacks mControlCallabcks;
LocationControlAPI *mLocationControlApi;
// Configration
const uint32_t mAutoStartGnss;
GnssSuplMode mPositionMode;
PowerStateType mPowerState;
// maintenance timer
MaintTimer mMaintTimer;
// msg task used by timers
const MsgTask mMsgTask;
// Terrestrial service related APIs
// Location api interface for single short wwan fix
LocationAPI* mGtpWwanSsLocationApi;
LocationCallbacks mGtpWwanSsLocationApiCallbacks;
trackingCallback mGtpWwanPosCallback;
// -1: not set, 0: user not opt-in, 1: user opt in
int mOptInTerrestrialService;
SingleTerrestrialFixClientMap mTerrestrialFixReqs;
};
#endif //LOCATIONAPISERVICE_H

View file

@ -0,0 +1,67 @@
AM_CFLAGS = \
-DDEBUG \
-I./ \
$(LOCCORE_CFLAGS) \
$(GPSUTILS_CFLAGS) \
$(LOCAPIMSGPROTO_CFLAGS) \
-std=c++11
if USE_SYSTEMD
AM_CFLAGS += -DINIT_SYSTEM_SYSTEMD
else
AM_CFLAGS += -DINIT_SYSTEM_SYSV
endif
if USE_FEATURE_AUTOMOTIVE
AM_CFLAGS += -DFEATURE_AUTOMOTIVE
endif
requiredlibs = \
$(LOCATIONAPI_LIBS) \
$(GPSUTILS_LIBS) \
$(LOCAPIMSGPROTO_LIBS) \
-lprotobuf
h_sources = \
LocHalDaemonClientHandler.h \
LocationApiService.h
c_sources = \
LocHalDaemonClientHandler.cpp \
LocationApiService.cpp \
main.cpp
if POWERMANAGER_ENABLED
AM_CFLAGS += $(PM_CFLAGS) -DPOWERMANAGER_ENABLED
c_sources += PowerEvtHandler.cpp
requiredlibs += $(PM_LIBS)
endif
location_hal_daemon_SOURCES = \
$(c_sources) $(h_sources)
######################
# Build location_hal_daemon
######################
if USE_GLIB
location_hal_daemon_CFLAGS = -DUSE_GLIB $(AM_CFLAGS) @GLIB_CFLAGS@
location_hal_daemon_LDFLAGS = -lstdc++ -g -Wl,-z,defs -lpthread @GLIB_LIBS@ -shared
location_hal_daemon_CPPFLAGS = -DUSE_GLIB $(AM_CFLAGS) $(AM_CPPFLAGS) @GLIB_CFLAGS@
else
location_hal_daemon_CFLAGS = $(AM_CFLAGS)
location_hal_daemon_LDFLAGS = -Wl,-z,defs -lpthread -shared
location_hal_daemon_CPPFLAGS = $(AM_CFLAGS) $(AM_CPPFLAGS)
endif
location_hal_daemon_LDADD = $(requiredlibs) -lcutils -ldl
bin_PROGRAMS = location_hal_daemon
library_include_HEADERS = $(h_sources)
library_includedir = $(pkgincludedir)
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = location-hal-daemon.pc
EXTRA_DIST = $(pkgconfig_DATA)

View file

@ -0,0 +1,87 @@
/* Copyright (c) 2018, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation, nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <unistd.h>
#include <PowerEvtHandler.h>
#include <LocationApiService.h>
#include <log_util.h>
#include <syslog.h>
#define ACK_TIMEOUT_US 300000 // 300 msec
LocationApiService* PowerEvtHandler::mLocationApiService = nullptr;
PowerEvtHandler* PowerEvtHandler::getPwrEvtHandler(LocationApiService* locServiceApiObj) {
mLocationApiService = locServiceApiObj;
static PowerEvtHandler instance;
return &instance;
}
PowerEvtHandler::PowerEvtHandler() {
int ret = pwr_state_notification_register(PowerEvtHandler::pwrStateCb);
syslog(LOG_INFO, "PowerEvtHandler: register api returned: %d", ret);
}
PowerEvtHandler::~PowerEvtHandler() {
}
int PowerEvtHandler::pwrStateCb(power_state_t pwr_state) {
client_ack_t client_ack;
client_ack.ack = ERR;
PowerStateType powerState = POWER_STATE_UNKNOWN;
syslog(LOG_INFO, "PowerEvtHandler: pwrStateCb: %d", pwr_state.sys_state);
switch (pwr_state.sys_state) {
case SYS_SUSPEND:
client_ack.ack = SUSPEND_ACK;
powerState = POWER_STATE_SUSPEND;
break;
case SYS_RESUME:
client_ack.ack = RESUME_ACK;
powerState = POWER_STATE_RESUME;
break;
case SYS_SHUTDOWN:
client_ack.ack = SHUTDOWN_ACK;
powerState = POWER_STATE_SHUTDOWN;
break;
}
if (powerState != POWER_STATE_UNKNOWN) {
if (mLocationApiService) {
mLocationApiService->onPowerEvent(powerState);
}
}
//Allow some time to stop the session and write calibration data NVM.
usleep(ACK_TIMEOUT_US);
syslog(LOG_INFO, "PowerEvtHandler: pwrStateCb sending ack");
send_acknowledgement(client_ack);
return 0;
}

View file

@ -0,0 +1,49 @@
/* Copyright (c) 2018, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation, nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _POWER_EVENT_HANDLER_H_
#define _POWER_EVENT_HANDLER_H_
#include <power_state.h>
class LocationApiService;
class PowerEvtHandler
{
public:
static PowerEvtHandler* getPwrEvtHandler(LocationApiService*);
~PowerEvtHandler();
static int pwrStateCb(power_state_t pwr_state);
private:
PowerEvtHandler();
static LocationApiService* mLocationApiService;
};
#endif //_POWER_EVENT_HANDLER_H_

View file

@ -0,0 +1,115 @@
# configure.ac -- Autoconf script for gps location-hal-daemon
#
# Process this file with autoconf to produce a configure script
# Requires autoconf tool later than 2.61
AC_PREREQ(2.61)
# Initialize the location-hal-daemon package version 1.0.0
AC_INIT([location-hal-daemon],1.0.0)
# Does not strictly follow GNU Coding standards
AM_INIT_AUTOMAKE([foreign subdir-objects])
# Disables auto rebuilding of configure, Makefile.ins
AM_MAINTAINER_MODE
# Verifies the --srcdir is correct by checking for the path
AC_CONFIG_SRCDIR([Makefile.am])
# defines some macros variable to be included by source
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_MACRO_DIR([m4])
# Checks for programs.
AC_PROG_LIBTOOL
AC_PROG_CXX
AC_PROG_CC
AM_PROG_CC_C_O
AC_PROG_AWK
AC_PROG_CPP
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_MAKE_SET
PKG_PROG_PKG_CONFIG
# Checks for libraries.
PKG_CHECK_MODULES([LOCCORE], [loc-core])
AC_SUBST([LOCCORE_CFLAGS])
AC_SUBST([LOCCORE_LIBS])
PKG_CHECK_MODULES([LOCATIONAPI], [location-api])
AC_SUBST([LOCATIONAPI_CFLAGS])
AC_SUBST([LOCATIONAPI_LIBS])
PKG_CHECK_MODULES([LOCHAL], [loc-hal])
AC_SUBST([LOCHAL_CFLAGS])
AC_SUBST([LOCHAL_LIBS])
PKG_CHECK_MODULES([GPSUTILS], [gps-utils])
AC_SUBST([GPSUTILS_CFLAGS])
AC_SUBST([GPSUTILS_LIBS])
PKG_CHECK_MODULES([LOCAPIMSGPROTO], [location-api-msg-proto])
AC_SUBST([LOCAPIMSGPROTO_CFLAGS])
AC_SUBST([LOCAPIMSGPROTO_LIBS])
AC_ARG_WITH([pwrmgrlib],
AC_HELP_STRING([--with-pwrmgrlib], [with power manager library]))
AM_CONDITIONAL(POWERMANAGER_ENABLED, test "x$with_pwrmgrlib" = "xyes")
AM_COND_IF(POWERMANAGER_ENABLED, [
PKG_CHECK_MODULES([PM], [powermanager])
AC_SUBST([PM_CFLAGS])
AC_SUBST([PM_LIBS])
])
AC_ARG_WITH([systemd],
AC_HELP_STRING([--with-systemd],
[systemd enable, building LE systems which has systemd]))
AM_CONDITIONAL(USE_SYSTEMD, test "x${with_systemd}" = "xyes")
AC_ARG_WITH([auto_feature],
AC_HELP_STRING([--with-auto_feature=@<:@dir@:>@],
[Using Automotive feature]),
[],
with_auto_feature=no)
if test "x$with_auto_feature" != "xno"; then
CPPFLAGS="${CPPFLAGS} -DFEATURE_AUTOMOTIVE"
fi
AM_CONDITIONAL(USE_FEATURE_AUTOMOTIVE, test "x${with_auto_feature}" = "xyes")
AC_ARG_WITH([glib],
AC_HELP_STRING([--with-glib],
[enable glib, building HLOS systems which use glib]))
if (test "x${with_glib}" = "xyes"); then
AC_DEFINE(ENABLE_USEGLIB, 1, [Define if HLOS systems uses glib])
PKG_CHECK_MODULES(GTHREAD, gthread-2.0 >= 2.16, dummy=yes,
AC_MSG_ERROR(GThread >= 2.16 is required))
PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.16, dummy=yes,
AC_MSG_ERROR(GLib >= 2.16 is required))
GLIB_CFLAGS="$GLIB_CFLAGS $GTHREAD_CFLAGS"
GLIB_LIBS="$GLIB_LIBS $GTHREAD_LIBS"
AC_SUBST(GLIB_CFLAGS)
AC_SUBST(GLIB_LIBS)
fi
AM_CONDITIONAL(USE_GLIB, test "x${with_glib}" = "xyes")
AC_ARG_WITH([core_includes],
AC_HELP_STRING([--with-core-includes=@<:@dir@:>@],
[Specify the location of the core headers]),
[core_incdir=$withval],
with_core_includes=no)
if (test "x$with_core_includes" != "xno"); then
CPPFLAGS="${CPPFLAGS} -I${core_incdir}"
fi
AC_CONFIG_FILES([ \
Makefile \
location-hal-daemon.pc
])
AC_OUTPUT

View file

@ -0,0 +1,10 @@
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
Name: location-hal-daemon
Description: location hal daemon service
Version: @VERSION@
Libs: -L${libdir} -llocation-hal-daemon
Cflags: -I${includedir} -I${includedir}/location-hal-daemon

View file

@ -0,0 +1,74 @@
#!/bin/sh
#
# Copyright (c) 2017-2018, 2020 The Linux Foundation. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
# # Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# # Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.
# # Neither the name of The Linux Foundation, nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# Location Hal Daemon - init.d script for /usr/bin/location_hal_daemon
set -e
wait_for_dir_mount() {
while ! [ -d /dev ]
do
echo "waiting for /dev to mount"
done
}
create_set_folder() {
if [ ! -d "${1}" ]
then
mkdir -p "${1}"
chown -R "${2}" "${1}"
chmod "${3}" "${1}"
fi
}
# for location hal daemon
case "$1" in
start)
echo -n "Starting location_hal_initializer" > /dev/kmsg
wait_for_dir_mount
create_set_folder "/dev/socket/location" "gps:gps" 755
create_set_folder "/dev/socket/loc_client" "gps:locclient" 775
create_set_folder "/dev/socket/location/ehub" "gps:gps" 755
echo "Done creating folders for location hal daemon"
;;
stop)
echo -n "Stopping location_hal_initializer" > /dev/kmsg
;;
restart)
$0 stop
sleep 1
$0 start
;;
*)
echo -n "Usage location_hal_initializer { start | stop | restart }" >&2
exit 1
;;
esac
exit 0

View file

@ -0,0 +1,168 @@
/* Copyright (c) 2018-2020 The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation, nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <grp.h>
#include <unistd.h>
#include <sys/prctl.h>
#include <sys/capability.h>
#include <loc_pla.h>
#include <loc_cfg.h>
#include <gps_extended_c.h>
#include <loc_misc_utils.h>
#include "LocationApiService.h"
#define HAL_DAEMON_VERSION "1.1.0"
// this function will block until the directory specified in
// dirName has been created
static inline void waitForDir(const char* dirName) {
// wait for parent direcoty to be created...
struct stat buf_stat;
while (1) {
LOC_LOGd("waiting for %s...", dirName);
int rc = stat(dirName, &buf_stat);
if (!rc) {
break;
}
usleep(100000); //100ms
}
LOC_LOGd("done");
}
int main(int argc, char *argv[])
{
configParamToRead configParamRead = {};
#if FEATURE_AUTOMOTIVE
// enable auto start by default with 100 ms TBF
configParamRead.autoStartGnss = 1;
configParamRead.gnssSessionTbfMs = 100;
#endif
const loc_param_s_type configTable[] =
{
{"AUTO_START_GNSS", &configParamRead.autoStartGnss, NULL, 'n'},
{"GNSS_SESSION_TBF_MS", &configParamRead.gnssSessionTbfMs, NULL, 'n'},
{"DELETE_ALL_BEFORE_AUTO_START", &configParamRead.deleteAllBeforeAutoStart, NULL, 'n'},
{"DELETE_ALL_ON_ENGINE_MASK", &configParamRead.posEngineMask, NULL, 'n'},
{"POSITION_MODE", &configParamRead.positionMode, NULL, 'n'},
};
// read configuration file
UTIL_READ_CONF(LOC_PATH_GPS_CONF, configTable);
if (configParamRead.positionMode != GNSS_SUPL_MODE_MSB) {
configParamRead.positionMode = GNSS_SUPL_MODE_STANDALONE;
}
LOC_LOGi("location hal daemon - ver %s", HAL_DAEMON_VERSION);
loc_boot_kpi_marker("L - Location Probe Start");
waitForDir(SOCKET_DIR_LOCATION);
waitForDir(SOCKET_LOC_CLIENT_DIR);
waitForDir(SOCKET_DIR_EHUB);
LOC_LOGd("starting loc_hal_daemon");
#ifdef INIT_SYSTEM_SYSV
// set supplementary groups for sysvinit
// For systemd, common supplementary groups are set via service files
char groupNames[LOC_MAX_PARAM_NAME] = "gps radio diag powermgr locclient inet vnw";
gid_t groupIds[LOC_PROCESS_MAX_NUM_GROUPS] = {};
char *splitGrpString[LOC_PROCESS_MAX_NUM_GROUPS];
int numGrps = loc_util_split_string(groupNames, splitGrpString,
LOC_PROCESS_MAX_NUM_GROUPS, ' ');
int numGrpIds=0;
for(int i=0; i<numGrps; i++) {
struct group* grp = getgrnam(splitGrpString[i]);
if (grp) {
groupIds[numGrpIds] = grp->gr_gid;
LOC_LOGd("Group %s = %d", splitGrpString[i], groupIds[numGrpIds]);
numGrpIds++;
}
}
if (0 != numGrpIds) {
if(-1 == setgroups(numGrpIds, groupIds)) {
LOC_LOGe("Error: setgroups failed %s", strerror(errno));
}
}
#endif
// check if this process started by root
if (0 == getuid()) {
#ifdef INIT_SYSTEM_SYSTEMD
// started as root.
LOC_LOGE("Error !!! location_hal_daemon started as root");
exit(1);
#else
// Set capabilities
struct __user_cap_header_struct cap_hdr = {};
cap_hdr.version = _LINUX_CAPABILITY_VERSION;
cap_hdr.pid = getpid();
if(prctl(PR_SET_KEEPCAPS, 1) < 0) {
LOC_LOGe("Error: prctl failed. %s", strerror(errno));
}
// Set the group id first and then set the effective userid, to gps.
if(-1 == setgid(GID_GPS)) {
LOC_LOGe("Error: setgid failed. %s", strerror(errno));
}
// Set user id
if(-1 == setuid(UID_GPS)) {
LOC_LOGe("Error: setuid failed. %s", strerror(errno));
}
// Set access to netmgr (QCMAP)
struct __user_cap_data_struct cap_data = {};
cap_data.permitted = (1 << CAP_NET_BIND_SERVICE) | (1 << CAP_NET_ADMIN);
cap_data.effective = cap_data.permitted;
LOC_LOGv("cap_data.permitted: %d", (int)cap_data.permitted);
if(capset(&cap_hdr, &cap_data)) {
LOC_LOGe("Error: capset failed. %s", strerror(errno));
}
#endif
}
// move to root dir
chdir("/");
// start listening for client events - will not return
if (!LocationApiService::getInstance(configParamRead)) {
LOC_LOGd("Failed to start LocationApiService.");
}
// should not reach here...
LOC_LOGd("done");
exit(0);
}