Check the return value of HIDL Callbacks
GNSS HAL needs to check the return value of HIDL Callbacks to avoid crashing when things go wrong. Bug: 37987256 Change-Id: I4a5e33f7f4d85c887bc91fa71336a78151c3ce3b CRs-fixed: 2044206
This commit is contained in:
parent
f4f9b5c5a6
commit
4c265534bb
4 changed files with 86 additions and 18 deletions
|
@ -157,7 +157,11 @@ void BatchingAPIClient::onBatchingCb(size_t count, Location* location)
|
|||
for (size_t i = 0; i < count; i++) {
|
||||
convertGnssLocation(location[i], locationVec[i]);
|
||||
}
|
||||
mGnssBatchingCbIface->gnssLocationBatchCb(locationVec);
|
||||
auto r = mGnssBatchingCbIface->gnssLocationBatchCb(locationVec);
|
||||
if (!r.isOk()) {
|
||||
LOC_LOGE("%s] Error from gnssLocationBatchCb description=%s",
|
||||
__func__, r.description().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -155,9 +155,13 @@ void GeofenceAPIClient::onGeofenceBreachCb(GeofenceBreachNotification geofenceBr
|
|||
continue;
|
||||
}
|
||||
|
||||
mGnssGeofencingCbIface->gnssGeofenceTransitionCb(
|
||||
auto r = mGnssGeofencingCbIface->gnssGeofenceTransitionCb(
|
||||
geofenceBreachNotification.ids[i], gnssLocation, transition,
|
||||
static_cast<GnssUtcTime>(geofenceBreachNotification.timestamp));
|
||||
if (!r.isOk()) {
|
||||
LOC_LOGE("%s] Error from gnssGeofenceTransitionCb description=%s",
|
||||
__func__, r.description().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -173,7 +177,11 @@ void GeofenceAPIClient::onGeofenceStatusCb(GeofenceStatusNotification geofenceSt
|
|||
}
|
||||
GnssLocation gnssLocation;
|
||||
memset(&gnssLocation, 0, sizeof(GnssLocation));
|
||||
mGnssGeofencingCbIface->gnssGeofenceStatusCb(status, gnssLocation);
|
||||
auto r = mGnssGeofencingCbIface->gnssGeofenceStatusCb(status, gnssLocation);
|
||||
if (!r.isOk()) {
|
||||
LOC_LOGE("%s] Error from gnssGeofenceStatusCb description=%s",
|
||||
__func__, r.description().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -188,7 +196,11 @@ void GeofenceAPIClient::onAddGeofencesCb(size_t count, LocationError* errors, ui
|
|||
status = IGnssGeofenceCallback::GeofenceStatus::OPERATION_SUCCESS;
|
||||
else if (errors[i] == LOCATION_ERROR_ID_EXISTS)
|
||||
status = IGnssGeofenceCallback::GeofenceStatus::ERROR_ID_EXISTS;
|
||||
mGnssGeofencingCbIface->gnssGeofenceAddCb(ids[i], status);
|
||||
auto r = mGnssGeofencingCbIface->gnssGeofenceAddCb(ids[i], status);
|
||||
if (!r.isOk()) {
|
||||
LOC_LOGE("%s] Error from gnssGeofenceAddCb description=%s",
|
||||
__func__, r.description().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -204,7 +216,11 @@ void GeofenceAPIClient::onRemoveGeofencesCb(size_t count, LocationError* errors,
|
|||
status = IGnssGeofenceCallback::GeofenceStatus::OPERATION_SUCCESS;
|
||||
else if (errors[i] == LOCATION_ERROR_ID_UNKNOWN)
|
||||
status = IGnssGeofenceCallback::GeofenceStatus::ERROR_ID_UNKNOWN;
|
||||
mGnssGeofencingCbIface->gnssGeofenceRemoveCb(ids[i], status);
|
||||
auto r = mGnssGeofencingCbIface->gnssGeofenceRemoveCb(ids[i], status);
|
||||
if (!r.isOk()) {
|
||||
LOC_LOGE("%s] Error from gnssGeofenceRemoveCb description=%s",
|
||||
__func__, r.description().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -220,7 +236,11 @@ void GeofenceAPIClient::onPauseGeofencesCb(size_t count, LocationError* errors,
|
|||
status = IGnssGeofenceCallback::GeofenceStatus::OPERATION_SUCCESS;
|
||||
else if (errors[i] == LOCATION_ERROR_ID_UNKNOWN)
|
||||
status = IGnssGeofenceCallback::GeofenceStatus::ERROR_ID_UNKNOWN;
|
||||
mGnssGeofencingCbIface->gnssGeofencePauseCb(ids[i], status);
|
||||
auto r = mGnssGeofencingCbIface->gnssGeofencePauseCb(ids[i], status);
|
||||
if (!r.isOk()) {
|
||||
LOC_LOGE("%s] Error from gnssGeofencePauseCb description=%s",
|
||||
__func__, r.description().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -236,7 +256,11 @@ void GeofenceAPIClient::onResumeGeofencesCb(size_t count, LocationError* errors,
|
|||
status = IGnssGeofenceCallback::GeofenceStatus::OPERATION_SUCCESS;
|
||||
else if (errors[i] == LOCATION_ERROR_ID_UNKNOWN)
|
||||
status = IGnssGeofenceCallback::GeofenceStatus::ERROR_ID_UNKNOWN;
|
||||
mGnssGeofencingCbIface->gnssGeofenceResumeCb(ids[i], status);
|
||||
auto r = mGnssGeofencingCbIface->gnssGeofenceResumeCb(ids[i], status);
|
||||
if (!r.isOk()) {
|
||||
LOC_LOGE("%s] Error from gnssGeofenceResumeCb description=%s",
|
||||
__func__, r.description().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -248,7 +248,11 @@ void GnssAPIClient::onCapabilitiesCb(LocationCapabilitiesMask capabilitiesMask)
|
|||
data |= IGnssCallback::Capabilities::MSB;
|
||||
if (capabilitiesMask & LOCATION_CAPABILITIES_GNSS_MSA_BIT)
|
||||
data |= IGnssCallback::Capabilities::MSA;
|
||||
mGnssCbIface->gnssSetCapabilitesCb(data);
|
||||
auto r = mGnssCbIface->gnssSetCapabilitesCb(data);
|
||||
if (!r.isOk()) {
|
||||
LOC_LOGE("%s] Error from gnssSetCapabilitesCb description=%s",
|
||||
__func__, r.description().c_str());
|
||||
}
|
||||
}
|
||||
if (mGnssCbIface != nullptr) {
|
||||
IGnssCallback::GnssSystemInfo gnssInfo;
|
||||
|
@ -257,7 +261,11 @@ void GnssAPIClient::onCapabilitiesCb(LocationCapabilitiesMask capabilitiesMask)
|
|||
gnssInfo.yearOfHw = 2017;
|
||||
}
|
||||
LOC_LOGV("%s:%d] set_system_info_cb (%d)", __FUNCTION__, __LINE__, gnssInfo.yearOfHw);
|
||||
mGnssCbIface->gnssSetSystemInfoCb(gnssInfo);
|
||||
auto r = mGnssCbIface->gnssSetSystemInfoCb(gnssInfo);
|
||||
if (!r.isOk()) {
|
||||
LOC_LOGE("%s] Error from gnssSetSystemInfoCb description=%s",
|
||||
__func__, r.description().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -267,7 +275,11 @@ void GnssAPIClient::onTrackingCb(Location location)
|
|||
if (mGnssCbIface != nullptr) {
|
||||
GnssLocation gnssLocation;
|
||||
convertGnssLocation(location, gnssLocation);
|
||||
mGnssCbIface->gnssLocationCb(gnssLocation);
|
||||
auto r = mGnssCbIface->gnssLocationCb(gnssLocation);
|
||||
if (!r.isOk()) {
|
||||
LOC_LOGE("%s] Error from gnssLocationCb description=%s",
|
||||
__func__, r.description().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -353,7 +365,11 @@ void GnssAPIClient::onGnssSvCb(GnssSvNotification gnssSvNotification)
|
|||
if (mGnssCbIface != nullptr) {
|
||||
IGnssCallback::GnssSvStatus svStatus;
|
||||
convertGnssSvStatus(gnssSvNotification, svStatus);
|
||||
mGnssCbIface->gnssSvStatusCb(svStatus);
|
||||
auto r = mGnssCbIface->gnssSvStatusCb(svStatus);
|
||||
if (!r.isOk()) {
|
||||
LOC_LOGE("%s] Error from gnssSvStatusCb description=%s",
|
||||
__func__, r.description().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -362,8 +378,12 @@ void GnssAPIClient::onGnssNmeaCb(GnssNmeaNotification gnssNmeaNotification)
|
|||
if (mGnssCbIface != nullptr) {
|
||||
android::hardware::hidl_string nmeaString;
|
||||
nmeaString.setToExternal(gnssNmeaNotification.nmea, gnssNmeaNotification.length);
|
||||
mGnssCbIface->gnssNmeaCb(static_cast<GnssUtcTime>(gnssNmeaNotification.timestamp),
|
||||
nmeaString);
|
||||
auto r = mGnssCbIface->gnssNmeaCb(
|
||||
static_cast<GnssUtcTime>(gnssNmeaNotification.timestamp), nmeaString);
|
||||
if (!r.isOk()) {
|
||||
LOC_LOGE("%s] Error from gnssNmeaCb nmea=%s length=%u description=%s", __func__,
|
||||
gnssNmeaNotification.nmea, gnssNmeaNotification.length, r.description().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -371,8 +391,16 @@ void GnssAPIClient::onStartTrackingCb(LocationError error)
|
|||
{
|
||||
LOC_LOGD("%s]: (%d)", __FUNCTION__, error);
|
||||
if (error == LOCATION_ERROR_SUCCESS && mGnssCbIface != nullptr) {
|
||||
mGnssCbIface->gnssStatusCb(IGnssCallback::GnssStatusValue::ENGINE_ON);
|
||||
mGnssCbIface->gnssStatusCb(IGnssCallback::GnssStatusValue::SESSION_BEGIN);
|
||||
auto r = mGnssCbIface->gnssStatusCb(IGnssCallback::GnssStatusValue::ENGINE_ON);
|
||||
if (!r.isOk()) {
|
||||
LOC_LOGE("%s] Error from gnssStatusCb ENGINE_ON description=%s",
|
||||
__func__, r.description().c_str());
|
||||
}
|
||||
r = mGnssCbIface->gnssStatusCb(IGnssCallback::GnssStatusValue::SESSION_BEGIN);
|
||||
if (!r.isOk()) {
|
||||
LOC_LOGE("%s] Error from gnssStatusCb SESSION_BEGIN description=%s",
|
||||
__func__, r.description().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -380,8 +408,16 @@ void GnssAPIClient::onStopTrackingCb(LocationError error)
|
|||
{
|
||||
LOC_LOGD("%s]: (%d)", __FUNCTION__, error);
|
||||
if (error == LOCATION_ERROR_SUCCESS && mGnssCbIface != nullptr) {
|
||||
mGnssCbIface->gnssStatusCb(IGnssCallback::GnssStatusValue::SESSION_END);
|
||||
mGnssCbIface->gnssStatusCb(IGnssCallback::GnssStatusValue::ENGINE_OFF);
|
||||
auto r = mGnssCbIface->gnssStatusCb(IGnssCallback::GnssStatusValue::SESSION_END);
|
||||
if (!r.isOk()) {
|
||||
LOC_LOGE("%s] Error from gnssStatusCb SESSION_END description=%s",
|
||||
__func__, r.description().c_str());
|
||||
}
|
||||
r = mGnssCbIface->gnssStatusCb(IGnssCallback::GnssStatusValue::ENGINE_OFF);
|
||||
if (!r.isOk()) {
|
||||
LOC_LOGE("%s] Error from gnssStatusCb ENGINE_OFF description=%s",
|
||||
__func__, r.description().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -146,7 +146,11 @@ void MeasurementAPIClient::onGnssMeasurementsCb(
|
|||
if (mGnssMeasurementCbIface != nullptr) {
|
||||
IGnssMeasurementCallback::GnssData gnssData;
|
||||
convertGnssData(gnssMeasurementsNotification, gnssData);
|
||||
mGnssMeasurementCbIface->GnssMeasurementCb(gnssData);
|
||||
auto r = mGnssMeasurementCbIface->GnssMeasurementCb(gnssData);
|
||||
if (!r.isOk()) {
|
||||
LOC_LOGE("%s] Error from GnssMeasurementCb description=%s",
|
||||
__func__, r.description().c_str());
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&mLock);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue