GPS: block CPI injection for those fixes orginate from modem

GNSS adapter to block CPI injection for CPI originates from modem.
One source of the fix is QNP fix from modem. Only fixes that
comes within time threshold and with latitude and longitude
falls within the same proximity will be blocked.

Change-Id: If67a164d1e1c75735979f048a9f8dc93f0b0a41f
CRs-fixed: 2260721
This commit is contained in:
Kevin Tang 2018-07-03 10:45:56 -07:00
parent 271cfd8a00
commit 56c4dd4420
4 changed files with 104 additions and 10 deletions

View file

@ -84,7 +84,8 @@ GnssAdapter::GnssAdapter() :
mOdcpiInjectedPositionCount(0),
mSystemStatus(SystemStatus::getInstance(mMsgTask)),
mServerUrl(":"),
mXtraObserver(mSystemStatus->getOsObserver(), mMsgTask)
mXtraObserver(mSystemStatus->getOsObserver(), mMsgTask),
mBlockCPIInfo{}
{
LOC_LOGD("%s]: Constructor %p", __func__, this);
mLocPositionMode.mode = LOC_POSITION_MODE_INVALID;
@ -1599,26 +1600,39 @@ GnssAdapter::injectLocationCommand(double latitude, double longitude, float accu
struct MsgInjectLocation : public LocMsg {
LocApiBase& mApi;
ContextBase& mContext;
BlockCPIInfo& mBlockCPI;
double mLatitude;
double mLongitude;
float mAccuracy;
inline MsgInjectLocation(LocApiBase& api,
ContextBase& context,
BlockCPIInfo& blockCPIInfo,
double latitude,
double longitude,
float accuracy) :
LocMsg(),
mApi(api),
mContext(context),
mBlockCPI(blockCPIInfo),
mLatitude(latitude),
mLongitude(longitude),
mAccuracy(accuracy) {}
inline virtual void proc() const {
mApi.injectPosition(mLatitude, mLongitude, mAccuracy);
if ((uptimeMillis() <= mBlockCPI.blockedTillTsMs) &&
(fabs(mLatitude-mBlockCPI.latitude) <= mBlockCPI.latLonDiffThreshold) &&
(fabs(mLongitude-mBlockCPI.longitude) <= mBlockCPI.latLonDiffThreshold)) {
LOC_LOGD("%s]: positon injeciton blocked: lat: %f, lon: %f, accuracy: %f",
__func__, mLatitude, mLongitude, mAccuracy);
} else {
mApi.injectPosition(mLatitude, mLongitude, mAccuracy);
}
}
};
sendMsg(new MsgInjectLocation(*mLocApi, *mContext, latitude, longitude, accuracy));
sendMsg(new MsgInjectLocation(*mLocApi, *mContext, mBlockCPIInfo,
latitude, longitude, accuracy));
}
void
@ -1652,6 +1666,43 @@ GnssAdapter::injectTimeCommand(int64_t time, int64_t timeReference, int32_t unce
sendMsg(new MsgInjectTime(*mLocApi, *mContext, time, timeReference, uncertainty));
}
// This command is to called to block the position to be injected to the modem.
// This can happen for network position that comes from modem.
void
GnssAdapter::blockCPICommand(double latitude, double longitude,
float accuracy, int blockDurationMsec,
double latLonDiffThreshold)
{
struct MsgBlockCPI : public LocMsg {
BlockCPIInfo& mDstCPIInfo;
BlockCPIInfo mSrcCPIInfo;
inline MsgBlockCPI(BlockCPIInfo& dstCPIInfo,
BlockCPIInfo& srcCPIInfo) :
mDstCPIInfo(dstCPIInfo),
mSrcCPIInfo(srcCPIInfo) {}
inline virtual void proc() const {
// in the same hal thread, save the cpi to be blocked
// the global variable
mDstCPIInfo = mSrcCPIInfo;
}
};
// construct the new block CPI info and queue on the same thread
// for processing
BlockCPIInfo blockCPIInfo;
blockCPIInfo.latitude = latitude;
blockCPIInfo.longitude = longitude;
blockCPIInfo.accuracy = accuracy;
blockCPIInfo.blockedTillTsMs = uptimeMillis() + blockDurationMsec;
blockCPIInfo.latLonDiffThreshold = latLonDiffThreshold;
LOC_LOGD("%s]: block CPI lat: %f, lon: %f ", __func__, latitude, longitude);
// send a message to record down the coarse position
// to be blocked from injection in the master copy (mBlockCPIInfo)
sendMsg(new MsgBlockCPI(mBlockCPIInfo, blockCPIInfo));
}
void
GnssAdapter::addClientCommand(LocationAPI* client, const LocationCallbacks& callbacks)
{
@ -3225,13 +3276,25 @@ void GnssAdapter::injectOdcpiCommand(const Location& location)
void GnssAdapter::injectOdcpi(const Location& location)
{
mLocApi->injectPosition(location, true);
if (mOdcpiRequestActive) {
mOdcpiInjectedPositionCount++;
if (mOdcpiInjectedPositionCount >=
ODCPI_INJECTED_POSITION_COUNT_PER_REQUEST) {
mOdcpiRequestActive = false;
mOdcpiInjectedPositionCount = 0;
if (LOCATION_HAS_LAT_LONG_BIT & location.flags) {
if ((uptimeMillis() <= mBlockCPIInfo.blockedTillTsMs) &&
(fabs(location.latitude-mBlockCPIInfo.latitude) <=
mBlockCPIInfo.latLonDiffThreshold) &&
(fabs(location.longitude-mBlockCPIInfo.longitude) <=
mBlockCPIInfo.latLonDiffThreshold)) {
LOC_LOGD("%s]: positon injeciton blocked: lat: %f, lon: %f, accuracy: %f",
__func__, location.latitude, location.longitude, location.accuracy);
} else {
mLocApi->injectPosition(location, true);
if (mOdcpiRequestActive) {
mOdcpiInjectedPositionCount++;
if (mOdcpiInjectedPositionCount >=
ODCPI_INJECTED_POSITION_COUNT_PER_REQUEST) {
mOdcpiRequestActive = false;
mOdcpiInjectedPositionCount = 0;
}
}
}
}
}

View file

@ -76,6 +76,19 @@ typedef struct {
uint32_t svIdOffset;
} NmeaSvMeta;
typedef struct {
double latitude;
double longitude;
float accuracy;
// the CPI will be blocked until the boot time
// specified in blockedTillTsMs
int64_t blockedTillTsMs;
// CPIs whose both latitude and longitude differ
// no more than latLonThreshold will be blocked
// in units of degree
double latLonDiffThreshold;
} BlockCPIInfo;
using namespace loc_core;
namespace loc_core {
@ -124,6 +137,9 @@ class GnssAdapter : public LocAdapterBase {
std::string mServerUrl;
XtraSystemStatusObserver mXtraObserver;
/* === Misc ===================================================================== */
BlockCPIInfo mBlockCPIInfo;
/*==== CONVERSION ===================================================================*/
static void convertOptions(LocPosMode& out, const TrackingOptions& trackingOptions);
static void convertLocation(Location& out, const UlpLocation& ulpLocation,
@ -336,6 +352,8 @@ public:
void injectLocationCommand(double latitude, double longitude, float accuracy);
void injectTimeCommand(int64_t time, int64_t timeReference, int32_t uncertainty);
void blockCPICommand(double latitude, double longitude, float accuracy,
int blockDurationMsec, double latLonDiffThreshold);
};
#endif //GNSS_ADAPTER_H

View file

@ -70,6 +70,9 @@ static void updateConnectionStatus(bool connected, int8_t type);
static void odcpiInit(const OdcpiRequestCallback& callback);
static void odcpiInject(const Location& location);
static void blockCPI(double latitude, double longitude, float accuracy,
int blockDurationMsec, double latLonDiffThreshold);
static const GnssInterface gGnssInterface = {
sizeof(GnssInterface),
initialize,
@ -101,6 +104,7 @@ static const GnssInterface gGnssInterface = {
updateConnectionStatus,
odcpiInit,
odcpiInject,
blockCPI,
};
#ifndef DEBUG_X86
@ -327,3 +331,10 @@ static void odcpiInject(const Location& location)
}
}
static void blockCPI(double latitude, double longitude, float accuracy,
int blockDurationMsec, double latLonDiffThreshold) {
if (NULL != gGnssAdapter) {
gGnssAdapter->blockCPICommand(latitude, longitude, accuracy,
blockDurationMsec, latLonDiffThreshold);
}
}

View file

@ -63,6 +63,8 @@ struct GnssInterface {
void (*updateConnectionStatus)(bool connected, int8_t type);
void (*odcpiInit)(const OdcpiRequestCallback& callback);
void (*odcpiInject)(const Location& location);
void (*blockCPI)(double latitude, double longitude, float accuracy,
int blockDurationMsec, double latLonDiffThreshold);
};
struct FlpInterface {