diff --git a/android/visibility_control/1.0/GnssVisibilityControl.cpp b/android/visibility_control/1.0/GnssVisibilityControl.cpp index 82e465cc..5a8c697a 100644 --- a/android/visibility_control/1.0/GnssVisibilityControl.cpp +++ b/android/visibility_control/1.0/GnssVisibilityControl.cpp @@ -66,6 +66,13 @@ void GnssVisibilityControl::nfwStatusCb(GnssNfwNotification notification) { } } +bool GnssVisibilityControl::isInEmergencySession() { + if (nullptr != spGnssVisibilityControl) { + return spGnssVisibilityControl->isE911Session(); + } + return false; +} + static void convertGnssNfwNotification(GnssNfwNotification& in, IGnssVisibilityControlCallback::NfwNotification& out) { @@ -97,6 +104,22 @@ void GnssVisibilityControl::statusCb(GnssNfwNotification notification) { } } +bool GnssVisibilityControl::isE911Session() { + + if (mGnssVisibilityControlCbIface != nullptr) { + auto r = mGnssVisibilityControlCbIface->isInEmergencySession(); + if (!r.isOk()) { + LOC_LOGw("Error invoking NFW status cb %s", r.description().c_str()); + return false; + } else { + return (r); + } + } else { + LOC_LOGw("setCallback has not been called yet"); + return false; + } +} + // Methods from ::android::hardware::gnss::visibility_control::V1_0::IGnssVisibilityControl follow. Return GnssVisibilityControl::enableNfwLocationAccess(const hidl_vec<::android::hardware::hidl_string>& proxyApps) { @@ -131,6 +154,7 @@ Return GnssVisibilityControl::setCallback(const ::android::sp<::android::h NfwCbInfo cbInfo = {}; cbInfo.visibilityControlCb = (void*)nfwStatusCb; + cbInfo.isInEmergencySession = (void*)isInEmergencySession; mGnss->getGnssInterface()->nfwInit(cbInfo); diff --git a/android/visibility_control/1.0/GnssVisibilityControl.h b/android/visibility_control/1.0/GnssVisibilityControl.h index 4eaea51e..9c26e384 100644 --- a/android/visibility_control/1.0/GnssVisibilityControl.h +++ b/android/visibility_control/1.0/GnssVisibilityControl.h @@ -68,9 +68,11 @@ struct GnssVisibilityControl : public IGnssVisibilityControl { Return setCallback(const ::android::sp<::android::hardware::gnss::visibility_control::V1_0::IGnssVisibilityControlCallback>& callback) override; void statusCb(GnssNfwNotification notification); + bool isE911Session(); /* Data call setup callback passed down to GNSS HAL implementation */ static void nfwStatusCb(GnssNfwNotification notification); + static bool isInEmergencySession(); private: Gnss* mGnss = nullptr; diff --git a/gnss/GnssAdapter.cpp b/gnss/GnssAdapter.cpp index 436681a6..e1143fd2 100644 --- a/gnss/GnssAdapter.cpp +++ b/gnss/GnssAdapter.cpp @@ -94,7 +94,8 @@ GnssAdapter::GnssAdapter() : mPowerOn(false), mAllowFlpNetworkFixes(0), mGnssEnergyConsumedCb(nullptr), - mPowerStateCb(nullptr) + mPowerStateCb(nullptr), + mIsE911Session(NULL) { LOC_LOGD("%s]: Constructor %p", __func__, this); mLocPositionMode.mode = LOC_POSITION_MODE_INVALID; @@ -3394,21 +3395,36 @@ GnssAdapter::requestNiNotifyEvent(const GnssNiNotification ¬ify, const void* struct MsgReportNiNotify : public LocMsg { GnssAdapter& mAdapter; + LocApiBase& mApi; const GnssNiNotification mNotify; const void* mData; inline MsgReportNiNotify(GnssAdapter& adapter, + LocApiBase& api, const GnssNiNotification& notify, const void* data) : LocMsg(), mAdapter(adapter), + mApi(api), mNotify(notify), mData(data) {} inline virtual void proc() const { - mAdapter.requestNiNotify(mNotify, mData); + if (GNSS_NI_TYPE_EMERGENCY_SUPL == mNotify.type || + GNSS_NI_TYPE_CONTROL_PLANE == mNotify.type) { + if (mAdapter.getE911State() || + ((GNSS_CONFIG_SUPL_EMERGENCY_SERVICES_NO == ContextBase::mGps_conf.SUPL_ES) && + (GNSS_NI_TYPE_EMERGENCY_SUPL == mNotify.type))) { + mApi.informNiResponse(GNSS_NI_RESPONSE_ACCEPT, mData); + } + else { + mApi.informNiResponse(GNSS_NI_RESPONSE_DENY, mData); + } + } else { + mAdapter.requestNiNotify(mNotify, mData); + } } }; - sendMsg(new MsgReportNiNotify(*this, notify, data)); + sendMsg(new MsgReportNiNotify(*this, *mLocApi, notify, data)); return true; } diff --git a/gnss/GnssAdapter.h b/gnss/GnssAdapter.h index ae5f5f1e..6f652e63 100644 --- a/gnss/GnssAdapter.h +++ b/gnss/GnssAdapter.h @@ -165,8 +165,10 @@ class GnssAdapter : public LocAdapterBase { /* ==== NFW =========================================================================== */ NfwStatusCb mNfwCb; + IsInEmergencySession mIsE911Session; inline void initNfw(const NfwCbInfo& cbInfo) { mNfwCb = (NfwStatusCb)cbInfo.visibilityControlCb; + mIsE911Session = (IsInEmergencySession)cbInfo.isInEmergencySession; } /* ==== ODCPI ========================================================================== */ @@ -396,6 +398,12 @@ public: mNfwCb(notification); } } + inline bool getE911State(void) { + if (NULL != mIsE911Session) { + return mIsE911Session(); + } + return false; + } /*======== GNSSDEBUG ================================================================*/ bool getDebugReport(GnssDebugReport& report); diff --git a/utils/gps_extended_c.h b/utils/gps_extended_c.h index 279fa20f..18517839 100644 --- a/utils/gps_extended_c.h +++ b/utils/gps_extended_c.h @@ -2115,6 +2115,7 @@ typedef void (*AgnssStatusIpV4Cb)(AGnssExtStatusIpV4 status); * Callback with NFW information. */ typedef void(*NfwStatusCb)(GnssNfwNotification notification); +typedef bool(*IsInEmergencySession)(void); /* * Callback with AGNSS(IpV6) status information.