sm8450-common: Import gps from LA.VENDOR.1.0.r1-12800-WAIPIO.0

Change-Id: Ia76265a8c3326f2b5f9f260ce98807276af80ee3
This commit is contained in:
Arian
2024-01-27 01:37:39 +01:00
parent 106355e12e
commit b9fdaff70a
286 changed files with 72332 additions and 0 deletions

View File

@@ -0,0 +1,82 @@
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := android.hardware.gnss-aidl-impl-qti
# activate the following line for debug purposes only, comment out for production
#LOCAL_SANITIZE_DIAG += $(GNSS_SANITIZE_DIAG)
LOCAL_VENDOR_MODULE := true
LOCAL_MODULE_RELATIVE_PATH := hw
LOCAL_VINTF_FRAGMENTS := android.hardware.gnss-aidl-service-qti.xml
LOCAL_SRC_FILES := \
Gnss.cpp \
GnssConfiguration.cpp \
GnssPowerIndication.cpp \
GnssMeasurementInterface.cpp \
location_api/GnssAPIClient.cpp
LOCAL_HEADER_LIBRARIES := \
libgps.utils_headers \
libloc_core_headers \
libloc_pla_headers \
liblocation_api_headers
LOCAL_SHARED_LIBRARIES := \
libbase \
libbinder_ndk \
android.hardware.gnss-V1-ndk_platform \
liblog \
libcutils \
libqti_vndfwk_detect_vendor \
libutils \
libloc_core \
libgps.utils \
libdl \
liblocation_api
LOCAL_CFLAGS += $(GNSS_CFLAGS)
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := android.hardware.gnss-aidl-service-qti
# activate the following line for debug purposes only, comment out for production
#LOCAL_SANITIZE_DIAG += $(GNSS_SANITIZE_DIAG)
LOCAL_VINTF_FRAGMENTS := android.hardware.gnss-aidl-service-qti.xml
LOCAL_VENDOR_MODULE := true
LOCAL_MODULE_RELATIVE_PATH := hw
LOCAL_INIT_RC := android.hardware.gnss-aidl-service-qti.rc
LOCAL_SRC_FILES := \
service.cpp
LOCAL_HEADER_LIBRARIES := \
libgps.utils_headers \
libloc_core_headers \
libloc_pla_headers \
liblocation_api_headers
LOCAL_SHARED_LIBRARIES := \
liblog \
libcutils \
libdl \
libbase \
libutils \
libgps.utils \
liblocation_api \
libqti_vndfwk_detect_vendor \
libbinder_ndk
LOCAL_SHARED_LIBRARIES += \
libhidlbase \
android.hardware.gnss@1.0 \
android.hardware.gnss@1.1 \
android.hardware.gnss@2.0 \
android.hardware.gnss@2.1 \
android.hardware.gnss-V1-ndk_platform \
android.hardware.gnss-aidl-impl-qti
LOCAL_CFLAGS += $(GNSS_CFLAGS)
include $(BUILD_EXECUTABLE)

View File

@@ -0,0 +1,217 @@
/*
* Copyright (c) 2021, The Linux Foundation. All rights reserved.
* Not a Contribution
*/
/*
* Copyright (C) 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2_0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2_0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define LOG_TAG "LocSvc_GnssInterface"
#define LOG_NDEBUG 0
#include "Gnss.h"
#include <log_util.h>
#include <android/binder_auto_utils.h>
namespace android {
namespace hardware {
namespace gnss {
namespace aidl {
namespace implementation {
void gnssCallbackDied(void* cookie) {
LOC_LOGe("IGnssCallback AIDL service died");
Gnss* iface = static_cast<Gnss*>(cookie);
if (iface != nullptr) {
iface->handleClientDeath();
}
}
ndk::ScopedAStatus Gnss::setCallback(const std::shared_ptr<IGnssCallback>& callback) {
if (callback == nullptr) {
LOC_LOGe("Null callback ignored");
return ndk::ScopedAStatus::fromExceptionCode(STATUS_INVALID_OPERATION);
}
mGnssCallback = callback;
GnssAPIClient* api = getApi();
if (mGnssCallback != nullptr) {
AIBinder_DeathRecipient* recipient = AIBinder_DeathRecipient_new(&gnssCallbackDied);
AIBinder_linkToDeath(callback->asBinder().get(), recipient, this);
}
if (api != nullptr) {
api->gnssUpdateCallbacks(callback);
api->gnssEnable(LOCATION_TECHNOLOGY_TYPE_GNSS);
api->requestCapabilities();
}
return ndk::ScopedAStatus::ok();
}
ndk::ScopedAStatus Gnss::close() {
if (mApi != nullptr) {
mApi->gnssDisable();
}
return ndk::ScopedAStatus::ok();
}
Gnss::Gnss(): mGnssCallback(nullptr) {
memset(&mPendingConfig, 0, sizeof(GnssConfig));
ENTRY_LOG_CALLFLOW();
}
Gnss::~Gnss() {
ENTRY_LOG_CALLFLOW();
if (mApi != nullptr) {
mApi->destroy();
mApi = nullptr;
}
}
void Gnss::handleClientDeath() {
close();
if (mApi != nullptr) {
mApi->gnssUpdateCallbacks(mGnssCallback);
}
mGnssCallback = nullptr;
}
ndk::ScopedAStatus Gnss::updateConfiguration(GnssConfig& gnssConfig) {
ENTRY_LOG_CALLFLOW();
GnssAPIClient* api = getApi();
if (api) {
api->gnssConfigurationUpdate(gnssConfig);
} else if (gnssConfig.flags != 0) {
// api is not ready yet, update mPendingConfig with gnssConfig
mPendingConfig.size = sizeof(GnssConfig);
if (gnssConfig.flags & GNSS_CONFIG_FLAGS_GPS_LOCK_VALID_BIT) {
mPendingConfig.flags |= GNSS_CONFIG_FLAGS_GPS_LOCK_VALID_BIT;
mPendingConfig.gpsLock = gnssConfig.gpsLock;
}
if (gnssConfig.flags & GNSS_CONFIG_FLAGS_SUPL_VERSION_VALID_BIT) {
mPendingConfig.flags |= GNSS_CONFIG_FLAGS_SUPL_VERSION_VALID_BIT;
mPendingConfig.suplVersion = gnssConfig.suplVersion;
}
if (gnssConfig.flags & GNSS_CONFIG_FLAGS_SET_ASSISTANCE_DATA_VALID_BIT) {
mPendingConfig.flags |= GNSS_CONFIG_FLAGS_SET_ASSISTANCE_DATA_VALID_BIT;
mPendingConfig.assistanceServer.size = sizeof(GnssConfigSetAssistanceServer);
mPendingConfig.assistanceServer.type = gnssConfig.assistanceServer.type;
if (mPendingConfig.assistanceServer.hostName != nullptr) {
free((void*)mPendingConfig.assistanceServer.hostName);
mPendingConfig.assistanceServer.hostName =
strdup(gnssConfig.assistanceServer.hostName);
}
mPendingConfig.assistanceServer.port = gnssConfig.assistanceServer.port;
}
if (gnssConfig.flags & GNSS_CONFIG_FLAGS_LPP_PROFILE_VALID_BIT) {
mPendingConfig.flags |= GNSS_CONFIG_FLAGS_LPP_PROFILE_VALID_BIT;
mPendingConfig.lppProfileMask = gnssConfig.lppProfileMask;
}
if (gnssConfig.flags & GNSS_CONFIG_FLAGS_LPPE_CONTROL_PLANE_VALID_BIT) {
mPendingConfig.flags |= GNSS_CONFIG_FLAGS_LPPE_CONTROL_PLANE_VALID_BIT;
mPendingConfig.lppeControlPlaneMask = gnssConfig.lppeControlPlaneMask;
}
if (gnssConfig.flags & GNSS_CONFIG_FLAGS_LPPE_USER_PLANE_VALID_BIT) {
mPendingConfig.flags |= GNSS_CONFIG_FLAGS_LPPE_USER_PLANE_VALID_BIT;
mPendingConfig.lppeUserPlaneMask = gnssConfig.lppeUserPlaneMask;
}
if (gnssConfig.flags & GNSS_CONFIG_FLAGS_AGLONASS_POSITION_PROTOCOL_VALID_BIT) {
mPendingConfig.flags |= GNSS_CONFIG_FLAGS_AGLONASS_POSITION_PROTOCOL_VALID_BIT;
mPendingConfig.aGlonassPositionProtocolMask = gnssConfig.aGlonassPositionProtocolMask;
}
if (gnssConfig.flags & GNSS_CONFIG_FLAGS_EM_PDN_FOR_EM_SUPL_VALID_BIT) {
mPendingConfig.flags |= GNSS_CONFIG_FLAGS_EM_PDN_FOR_EM_SUPL_VALID_BIT;
mPendingConfig.emergencyPdnForEmergencySupl = gnssConfig.emergencyPdnForEmergencySupl;
}
if (gnssConfig.flags & GNSS_CONFIG_FLAGS_SUPL_EM_SERVICES_BIT) {
mPendingConfig.flags |= GNSS_CONFIG_FLAGS_SUPL_EM_SERVICES_BIT;
mPendingConfig.suplEmergencyServices = gnssConfig.suplEmergencyServices;
}
if (gnssConfig.flags & GNSS_CONFIG_FLAGS_SUPL_MODE_BIT) {
mPendingConfig.flags |= GNSS_CONFIG_FLAGS_SUPL_MODE_BIT;
mPendingConfig.suplModeMask = gnssConfig.suplModeMask;
}
if (gnssConfig.flags & GNSS_CONFIG_FLAGS_BLACKLISTED_SV_IDS_BIT) {
mPendingConfig.flags |= GNSS_CONFIG_FLAGS_BLACKLISTED_SV_IDS_BIT;
mPendingConfig.blacklistedSvIds = gnssConfig.blacklistedSvIds;
}
if (gnssConfig.flags & GNSS_CONFIG_FLAGS_EMERGENCY_EXTENSION_SECONDS_BIT) {
mPendingConfig.flags |= GNSS_CONFIG_FLAGS_EMERGENCY_EXTENSION_SECONDS_BIT;
mPendingConfig.emergencyExtensionSeconds = gnssConfig.emergencyExtensionSeconds;
}
}
return ndk::ScopedAStatus::ok();
}
::ndk::ScopedAStatus Gnss::getExtensionGnssConfiguration(
std::shared_ptr<::aidl::android::hardware::gnss::IGnssConfiguration>* _aidl_return) {
ENTRY_LOG_CALLFLOW();
if (mGnssConfiguration == nullptr) {
mGnssConfiguration = SharedRefBase::make<GnssConfiguration>(this);
}
*_aidl_return = mGnssConfiguration;
return ndk::ScopedAStatus::ok();
}
::ndk::ScopedAStatus Gnss::getExtensionGnssPowerIndication(
std::shared_ptr<::aidl::android::hardware::gnss::IGnssPowerIndication>* _aidl_return) {
ENTRY_LOG_CALLFLOW();
if (mGnssPowerIndication == nullptr) {
mGnssPowerIndication = SharedRefBase::make<GnssPowerIndication>();
}
*_aidl_return = mGnssPowerIndication;
return ndk::ScopedAStatus::ok();
}
::ndk::ScopedAStatus Gnss::getExtensionGnssMeasurement(
std::shared_ptr<::aidl::android::hardware::gnss::IGnssMeasurementInterface>* _aidl_return) {
ENTRY_LOG_CALLFLOW();
if (mGnssMeasurementInterface == nullptr) {
mGnssMeasurementInterface = SharedRefBase::make<GnssMeasurementInterface>();
}
*_aidl_return = mGnssMeasurementInterface;
return ndk::ScopedAStatus::ok();
}
GnssAPIClient* Gnss::getApi() {
if (mApi != nullptr) {
return mApi;
}
if (mGnssCallback != nullptr) {
mApi = new GnssAPIClient(mGnssCallback);
} else {
LOC_LOGW("%s] GnssAPIClient is not ready", __FUNCTION__);
return mApi;
}
if (mPendingConfig.size == sizeof(GnssConfig)) {
// we have pending GnssConfig
mApi->gnssConfigurationUpdate(mPendingConfig);
// clear size to invalid mPendingConfig
mPendingConfig.size = 0;
if (mPendingConfig.assistanceServer.hostName != nullptr) {
free((void*)mPendingConfig.assistanceServer.hostName);
}
}
return mApi;
}
} // namespace implementation
} // namespace aidl
} // namespace gnss
} // namespace hardware
} // namespace android

View File

@@ -0,0 +1,88 @@
/*
* Copyright (c) 2021, The Linux Foundation. All rights reserved.
* Not a Contribution
*/
/*
* Copyright (C) 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2_0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2_0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef ANDROID_HARDWARE_GNSS_AIDL_GNSS_H
#define ANDROID_HARDWARE_GNSS_AIDL_GNSS_H
#include <aidl/android/hardware/gnss/BnGnss.h>
#include <aidl/android/hardware/gnss/IGnssCallback.h>
#include <aidl/android/hardware/gnss/BnGnssPowerIndication.h>
#include <aidl/android/hardware/gnss/BnGnssMeasurementInterface.h>
#include <aidl/android/hardware/gnss/BnGnssConfiguration.h>
#include <aidl/android/hardware/gnss/BnGnssPsds.h>
#include "location_api/GnssAPIClient.h"
#include "GnssConfiguration.h"
#include "GnssPowerIndication.h"
#include "GnssMeasurementInterface.h"
namespace android {
namespace hardware {
namespace gnss {
namespace aidl {
namespace implementation {
using ::aidl::android::hardware::gnss::GnssConstellationType;
using ::aidl::android::hardware::gnss::BnGnss;
using ::aidl::android::hardware::gnss::IGnssCallback;
using ::aidl::android::hardware::gnss::IGnssPowerIndication;
using ::aidl::android::hardware::gnss::IGnssMeasurementInterface;
using ::std::shared_ptr;
struct Gnss : public BnGnss {
Gnss();
~Gnss();
ndk::ScopedAStatus setCallback(const shared_ptr<IGnssCallback>& callback) override;
ndk::ScopedAStatus close() override;
::ndk::ScopedAStatus getExtensionPsds(
shared_ptr<::aidl::android::hardware::gnss::IGnssPsds>* _aidl_return) override {
return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION));
}
::ndk::ScopedAStatus getExtensionGnssConfiguration(
shared_ptr<::aidl::android::hardware::gnss::IGnssConfiguration>* _aidl_return) override;
::ndk::ScopedAStatus getExtensionGnssPowerIndication(
shared_ptr<IGnssPowerIndication>* _aidl_return) override;
::ndk::ScopedAStatus getExtensionGnssMeasurement(
shared_ptr<IGnssMeasurementInterface>* _aidl_return) override;
// These methods are not part of the IGnss base class.
GnssAPIClient* getApi();
ndk::ScopedAStatus updateConfiguration(GnssConfig& gnssConfig);
void handleClientDeath();
private:
GnssAPIClient* mApi;
shared_ptr<GnssConfiguration> mGnssConfiguration = nullptr;
shared_ptr<GnssPowerIndication> mGnssPowerIndication = nullptr;
shared_ptr<GnssMeasurementInterface> mGnssMeasurementInterface = nullptr;
GnssConfig mPendingConfig;
shared_ptr<IGnssCallback> mGnssCallback = nullptr;
};
} // namespace implementation
} // namespace aidl
} // namespace gnss
} // namespace hardware
} // namespace android
#endif // ANDROID_HARDWARE_GNSS_AIDL_GNSS_H

View File

@@ -0,0 +1,274 @@
/*
* Copyright (c) 2021, The Linux Foundation. All rights reserved.
* Not a Contribution
*/
/*
* Copyright (C) 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define LOG_TAG "GnssConfigurationAidl"
#include "Gnss.h"
#include <log_util.h>
namespace android {
namespace hardware {
namespace gnss {
namespace aidl {
namespace implementation {
GnssConfiguration::GnssConfiguration(Gnss* gnss) : mGnss(gnss) {
}
ndk::ScopedAStatus GnssConfiguration::setSuplVersion(int version) {
if (mGnss == nullptr) {
LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__);
return ndk::ScopedAStatus::fromExceptionCode(STATUS_INVALID_OPERATION);
}
GnssConfig config;
memset(&config, 0, sizeof(GnssConfig));
config.size = sizeof(GnssConfig);
config.flags = GNSS_CONFIG_FLAGS_SUPL_VERSION_VALID_BIT;
switch (version) {
case 0x00020004:
config.suplVersion = GNSS_CONFIG_SUPL_VERSION_2_0_4;
break;
case 0x00020002:
config.suplVersion = GNSS_CONFIG_SUPL_VERSION_2_0_2;
break;
case 0x00020000:
config.suplVersion = GNSS_CONFIG_SUPL_VERSION_2_0_0;
break;
case 0x00010000:
config.suplVersion = GNSS_CONFIG_SUPL_VERSION_1_0_0;
break;
default:
LOC_LOGE("%s]: invalid version: 0x%x.", __FUNCTION__, version);
return ndk::ScopedAStatus::fromExceptionCode(STATUS_INVALID_OPERATION);
}
return mGnss->updateConfiguration(config);
}
ndk::ScopedAStatus GnssConfiguration::setSuplMode(int mode) {
if (mGnss == nullptr) {
LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__);
return ndk::ScopedAStatus::fromExceptionCode(STATUS_INVALID_OPERATION);
}
GnssConfig config;
memset(&config, 0, sizeof(GnssConfig));
config.size = sizeof(GnssConfig);
config.flags = GNSS_CONFIG_FLAGS_SUPL_MODE_BIT;
switch (mode) {
case 0:
config.suplModeMask = 0; // STANDALONE ONLY
break;
case 1:
config.suplModeMask = GNSS_CONFIG_SUPL_MODE_MSB_BIT;
break;
case 2:
config.suplModeMask = GNSS_CONFIG_SUPL_MODE_MSA_BIT;
break;
case 3:
config.suplModeMask = GNSS_CONFIG_SUPL_MODE_MSB_BIT | GNSS_CONFIG_SUPL_MODE_MSA_BIT;
break;
default:
LOC_LOGE("%s]: invalid mode: %d.", __FUNCTION__, mode);
return ndk::ScopedAStatus::fromExceptionCode(STATUS_INVALID_OPERATION);
}
return mGnss->updateConfiguration(config);
}
ndk::ScopedAStatus GnssConfiguration::setLppProfile(int lppProfileMask) {
if (mGnss == nullptr) {
LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__);
return ndk::ScopedAStatus::fromExceptionCode(STATUS_INVALID_OPERATION);
}
GnssConfig config = {};
config.size = sizeof(GnssConfig);
config.flags = GNSS_CONFIG_FLAGS_LPP_PROFILE_VALID_BIT;
config.lppProfileMask = GNSS_CONFIG_LPP_PROFILE_RRLP_ON_LTE; //default
if (lppProfileMask & (1<<0)) {
config.lppProfileMask |= GNSS_CONFIG_LPP_PROFILE_USER_PLANE_BIT;
}
if (lppProfileMask & (1<<1)) {
config.lppProfileMask |= GNSS_CONFIG_LPP_PROFILE_CONTROL_PLANE_BIT;
}
if (lppProfileMask & (1<<2)) {
config.lppProfileMask |= GNSS_CONFIG_LPP_PROFILE_USER_PLANE_OVER_NR5G_SA_BIT;
}
if (lppProfileMask & (1<<3)) {
config.lppProfileMask |= GNSS_CONFIG_LPP_PROFILE_CONTROL_PLANE_OVER_NR5G_SA_BIT;
}
return mGnss->updateConfiguration(config);
}
ndk::ScopedAStatus GnssConfiguration::setGlonassPositioningProtocol(int protocol) {
if (mGnss == nullptr) {
LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__);
return ndk::ScopedAStatus::fromExceptionCode(STATUS_INVALID_OPERATION);
}
GnssConfig config;
memset(&config, 0, sizeof(GnssConfig));
config.size = sizeof(GnssConfig);
config.flags = GNSS_CONFIG_FLAGS_AGLONASS_POSITION_PROTOCOL_VALID_BIT;
if (protocol & (1<<0)) {
config.aGlonassPositionProtocolMask |= GNSS_CONFIG_RRC_CONTROL_PLANE_BIT;
}
if (protocol & (1<<1)) {
config.aGlonassPositionProtocolMask |= GNSS_CONFIG_RRLP_USER_PLANE_BIT;
}
if (protocol & (1<<2)) {
config.aGlonassPositionProtocolMask |= GNSS_CONFIG_LLP_USER_PLANE_BIT;
}
if (protocol & (1<<3)) {
config.aGlonassPositionProtocolMask |= GNSS_CONFIG_LLP_CONTROL_PLANE_BIT;
}
return mGnss->updateConfiguration(config);
}
ndk::ScopedAStatus GnssConfiguration::setEmergencySuplPdn(bool enabled) {
if (mGnss == nullptr) {
LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__);
return ndk::ScopedAStatus::fromExceptionCode(STATUS_INVALID_OPERATION);
}
GnssConfig config;
memset(&config, 0, sizeof(GnssConfig));
config.size = sizeof(GnssConfig);
config.flags = GNSS_CONFIG_FLAGS_EM_PDN_FOR_EM_SUPL_VALID_BIT;
config.emergencyPdnForEmergencySupl = (enabled ?
GNSS_CONFIG_EMERGENCY_PDN_FOR_EMERGENCY_SUPL_YES :
GNSS_CONFIG_EMERGENCY_PDN_FOR_EMERGENCY_SUPL_NO);
return mGnss->updateConfiguration(config);
}
ndk::ScopedAStatus GnssConfiguration::setEsExtensionSec(int emergencyExtensionSeconds) {
ENTRY_LOG_CALLFLOW();
if (mGnss == nullptr) {
LOC_LOGe("mGnss is nullptr");
return ndk::ScopedAStatus::fromExceptionCode(STATUS_INVALID_OPERATION);
}
GnssConfig config;
memset(&config, 0, sizeof(GnssConfig));
config.size = sizeof(GnssConfig);
config.flags = GNSS_CONFIG_FLAGS_EMERGENCY_EXTENSION_SECONDS_BIT;
config.emergencyExtensionSeconds = emergencyExtensionSeconds;
return mGnss->updateConfiguration(config);
}
ndk::ScopedAStatus GnssConfiguration::setBlocklist(const vector<BlocklistedSource>& sourceList) {
ENTRY_LOG_CALLFLOW();
if (nullptr == mGnss) {
LOC_LOGe("mGnss is null");
return ndk::ScopedAStatus::fromExceptionCode(STATUS_INVALID_OPERATION);
}
// blValid is true if sourceList is empty, i.e. clearing the BL;
// if sourceList is not empty, blValid is initialied to false, and later
// updated in the for loop to become true only if there is at least
// one {constellation, svid} in the list that is valid.
bool blValid = (0 == sourceList.size());
GnssConfig config;
memset(&config, 0, sizeof(GnssConfig));
config.size = sizeof(GnssConfig);
config.flags = GNSS_CONFIG_FLAGS_BLACKLISTED_SV_IDS_BIT;
config.blacklistedSvIds.clear();
GnssSvIdSource source = {};
for (int idx = 0; idx < (int)sourceList.size(); idx++) {
// Set blValid true if any one source is valid
blValid = setBlocklistedSource(source, sourceList[idx]) || blValid;
config.blacklistedSvIds.push_back(source);
}
// Update configuration only if blValid is true
// i.e. only if atleast one source is valid for sourceListing
if (!blValid) {
return ndk::ScopedAStatus::fromExceptionCode(STATUS_INVALID_OPERATION);
}
return mGnss->updateConfiguration(config);
}
bool GnssConfiguration::setBlocklistedSource(GnssSvIdSource& copyToSource,
const BlocklistedSource& copyFromSource) {
bool retVal = true;
uint16_t svIdOffset = 0;
copyToSource.size = sizeof(GnssSvIdSource);
copyToSource.svId = copyFromSource.svid;
switch (copyFromSource.constellation) {
case GnssConstellationType::GPS:
copyToSource.constellation = GNSS_SV_TYPE_GPS;
LOC_LOGe("GPS SVs can't be blocklisted.");
retVal = false;
break;
case GnssConstellationType::SBAS:
copyToSource.constellation = GNSS_SV_TYPE_SBAS;
LOC_LOGe("SBAS SVs can't be blocklisted.");
retVal = false;
break;
case GnssConstellationType::GLONASS:
copyToSource.constellation = GNSS_SV_TYPE_GLONASS;
svIdOffset = GNSS_SV_CONFIG_GLO_INITIAL_SV_ID - 1;
break;
case GnssConstellationType::QZSS:
copyToSource.constellation = GNSS_SV_TYPE_QZSS;
svIdOffset = GNSS_SV_CONFIG_QZSS_INITIAL_SV_ID - 1;
break;
case GnssConstellationType::BEIDOU:
copyToSource.constellation = GNSS_SV_TYPE_BEIDOU;
svIdOffset = GNSS_SV_CONFIG_BDS_INITIAL_SV_ID - 1;
break;
case GnssConstellationType::GALILEO:
copyToSource.constellation = GNSS_SV_TYPE_GALILEO;
svIdOffset = GNSS_SV_CONFIG_GAL_INITIAL_SV_ID - 1;
break;
case GnssConstellationType::IRNSS:
copyToSource.constellation = GNSS_SV_TYPE_NAVIC;
svIdOffset = GNSS_SV_CONFIG_NAVIC_INITIAL_SV_ID - 1;
break;
default:
copyToSource.constellation = GNSS_SV_TYPE_UNKNOWN;
LOC_LOGe("Invalid constellation %hhu", copyFromSource.constellation);
retVal = false;
break;
}
if (copyToSource.svId > 0 && svIdOffset > 0) {
copyToSource.svId += svIdOffset;
}
return retVal;
}
} // namespace implementation
} // namespace aidl
} // namespace gnss
} // namespace hardware
} // namespace android

View File

@@ -0,0 +1,88 @@
/*
* Copyright (c) 2021, The Linux Foundation. All rights reserved.
* Not a Contribution
*/
/*
* Copyright (C) 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <aidl/android/hardware/gnss/BnGnssConfiguration.h>
#include <aidl/android/hardware/gnss/GnssConstellationType.h>
#include <aidl/android/hardware/gnss/BlocklistedSource.h>
#include <mutex>
#include <unordered_set>
#include <vector>
namespace android {
namespace hardware {
namespace gnss {
namespace aidl {
namespace implementation {
using ::aidl::android::hardware::gnss::GnssConstellationType;
using ::aidl::android::hardware::gnss::BlocklistedSource;
using ::aidl::android::hardware::gnss::BnGnssConfiguration;
struct BlocklistedSourceHash {
inline int operator()(const BlocklistedSource& source) const {
return int(source.constellation) * 1000 + int(source.svid);
}
};
struct BlocklistedSourceEqual {
inline bool operator()(const BlocklistedSource& s1, const BlocklistedSource& s2) const {
return (s1.constellation == s2.constellation) && (s1.svid == s2.svid);
}
};
using std::vector;
using BlocklistedSourceSet =
std::unordered_set<BlocklistedSource, BlocklistedSourceHash, BlocklistedSourceEqual>;
using BlocklistedConstellationSet = std::unordered_set<GnssConstellationType>;
struct Gnss;
struct GnssConfiguration : public BnGnssConfiguration {
public:
GnssConfiguration(Gnss* gnss);
ndk::ScopedAStatus setSuplVersion(int) override;
ndk::ScopedAStatus setSuplMode(int) override;
ndk::ScopedAStatus setLppProfile(int) override;
ndk::ScopedAStatus setGlonassPositioningProtocol(int) override;
ndk::ScopedAStatus setEmergencySuplPdn(bool) override;
ndk::ScopedAStatus setEsExtensionSec(int) override;
ndk::ScopedAStatus setBlocklist(const vector<BlocklistedSource>& blocklist) override;
private:
Gnss* mGnss = nullptr;
bool setBlocklistedSource(GnssSvIdSource& copyToSource,
const BlocklistedSource& copyFromSource);
BlocklistedSourceSet mBlocklistedSourceSet;
BlocklistedConstellationSet mBlocklistedConstellationSet;
mutable std::recursive_mutex mMutex;
};
} // namespace implementation
} // namespace aidl
} // namespace gnss
} // namespace hardware
} // namespace android

View File

@@ -0,0 +1,673 @@
/*
* Copyright (c) 2021, The Linux Foundation. All rights reserved.
* Not a Contribution
*/
/*
* Copyright (C) 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define LOG_TAG "GnssMeasurementInterfaceAidl"
#include <log_util.h>
#include "GnssMeasurementInterface.h"
#include <android/binder_auto_utils.h>
#include <aidl/android/hardware/gnss/BnGnss.h>
#include <inttypes.h>
#include <loc_misc_utils.h>
using aidl::android::hardware::gnss::ElapsedRealtime;
using aidl::android::hardware::gnss::GnssClock;
using aidl::android::hardware::gnss::GnssData;
using aidl::android::hardware::gnss::GnssMeasurement;
using aidl::android::hardware::gnss::GnssSignalType;
using aidl::android::hardware::gnss::GnssConstellationType;
using aidl::android::hardware::gnss::GnssMultipathIndicator;
namespace android {
namespace hardware {
namespace gnss {
namespace aidl {
namespace implementation {
GnssMeasurementInterface::GnssMeasurementInterface() :
mDeathRecipient(AIBinder_DeathRecipient_new(GnssMeasurementInterface::gnssMeasurementDied)),
mTracking(false) {
}
::ndk::ScopedAStatus GnssMeasurementInterface::setCallback(
const std::shared_ptr<IGnssMeasurementCallback>& in_callback,
bool in_enableFullTracking, bool in_enableCorrVecOutputs) {
LOC_LOGd("setCallback: enableFullTracking: %d enableCorrVecOutputs: %d",
(int)in_enableFullTracking,
(int)in_enableCorrVecOutputs);
std::unique_lock<std::mutex> lock(mMutex);
if (nullptr == in_callback) {
LOC_LOGe("callback is nullptr");
return ndk::ScopedAStatus::fromExceptionCode(STATUS_INVALID_OPERATION);
}
AIBinder_linkToDeath(in_callback->asBinder().get(), mDeathRecipient, this);
mGnssMeasurementCbIface = in_callback;
lock.unlock();
startTracking(in_enableFullTracking ? GNSS_POWER_MODE_M1 : GNSS_POWER_MODE_M2);
return ndk::ScopedAStatus::ok();
}
::ndk::ScopedAStatus GnssMeasurementInterface::close() {
LOC_LOGd("()");
if (nullptr != mGnssMeasurementCbIface) {
AIBinder_unlinkToDeath(mGnssMeasurementCbIface->asBinder().get(), mDeathRecipient, this);
mGnssMeasurementCbIface = nullptr;
}
std::unique_lock<std::mutex> lock(mMutex);
mTracking = false;
lock.unlock();
locAPIStopTracking();
return ndk::ScopedAStatus::ok();
}
void GnssMeasurementInterface::onGnssMeasurementsCb(
GnssMeasurementsNotification gnssMeasurementsNotification) {
std::unique_lock<std::mutex> lock(mMutex);
LOC_LOGd("(count: %u active: %d)", gnssMeasurementsNotification.count, mTracking);
if (mTracking) {
auto gnssMeasurementCbIface = mGnssMeasurementCbIface;
if (gnssMeasurementCbIface != nullptr) {
GnssData gnssData = {};
convertGnssData(gnssMeasurementsNotification, gnssData);
printGnssData(gnssData);
lock.unlock();
gnssMeasurementCbIface->gnssMeasurementCb(gnssData);
}
}
}
void GnssMeasurementInterface::gnssMeasurementDied(void* cookie) {
LOC_LOGe("IGnssMeasurementCallback service died");
GnssMeasurementInterface* iface = static_cast<GnssMeasurementInterface*>(cookie);
//clean up, i.e. iface->close();
if (iface != nullptr) {
iface->close();
}
}
void GnssMeasurementInterface::startTracking(
GnssPowerMode powerMode, uint32_t timeBetweenMeasurement) {
LocationCallbacks locationCallbacks;
memset(&locationCallbacks, 0, sizeof(LocationCallbacks));
locationCallbacks.size = sizeof(LocationCallbacks);
locationCallbacks.trackingCb = nullptr;
locationCallbacks.batchingCb = nullptr;
locationCallbacks.geofenceBreachCb = nullptr;
locationCallbacks.geofenceStatusCb = nullptr;
locationCallbacks.gnssLocationInfoCb = nullptr;
locationCallbacks.gnssNiCb = nullptr;
locationCallbacks.gnssSvCb = nullptr;
locationCallbacks.gnssNmeaCb = nullptr;
locationCallbacks.gnssMeasurementsCb = nullptr;
if (nullptr != mGnssMeasurementCbIface) {
locationCallbacks.gnssMeasurementsCb =
[this](GnssMeasurementsNotification gnssMeasurementsNotification) {
onGnssMeasurementsCb(gnssMeasurementsNotification);
};
}
locAPISetCallbacks(locationCallbacks);
TrackingOptions options = {};
memset(&options, 0, sizeof(TrackingOptions));
options.size = sizeof(TrackingOptions);
options.minInterval = 1000;
options.mode = GNSS_SUPL_MODE_STANDALONE;
if (GNSS_POWER_MODE_INVALID != powerMode) {
options.powerMode = powerMode;
options.tbm = timeBetweenMeasurement;
}
std::unique_lock<std::mutex> lock(mMutex);
mTracking = true;
lock.unlock();
LOC_LOGd("start tracking session");
locAPIStartTracking(options);
}
void GnssMeasurementInterface::convertGnssData(GnssMeasurementsNotification& in, GnssData& out) {
out.measurements.resize(in.count);
for (size_t i = 0; i < in.count; i++) {
out.measurements[i].flags = 0;
convertGnssMeasurement(in.measurements[i], out.measurements[i]);
}
convertGnssClock(in.clock, out.clock);
convertElapsedRealtimeNanos(in, out.elapsedRealtime);
}
void GnssMeasurementInterface::convertGnssMeasurement(
GnssMeasurementsData& in, GnssMeasurement& out) {
// flags
convertGnssFlags(in, out);
// svid
convertGnssSvId(in, out.svid);
// signalType
convertGnssSignalType(in, out.signalType);
// timeOffsetNs
out.timeOffsetNs = in.timeOffsetNs;
// state
convertGnssState(in, out);
// receivedSvTimeInNs
out.receivedSvTimeInNs = in.receivedSvTimeNs;
// receivedSvTimeUncertaintyInNs
out.receivedSvTimeUncertaintyInNs = in.receivedSvTimeUncertaintyNs;
// antennaCN0DbHz
out.antennaCN0DbHz = in.carrierToNoiseDbHz;
// basebandCN0DbHz
out.basebandCN0DbHz = in.basebandCarrierToNoiseDbHz;
// pseudorangeRateMps
out.pseudorangeRateMps = in.pseudorangeRateMps;
// pseudorangeRateUncertaintyMps
out.pseudorangeRateUncertaintyMps = in.pseudorangeRateUncertaintyMps;
// accumulatedDeltaRangeState
convertGnssAccumulatedDeltaRangeState(in, out);
// accumulatedDeltaRangeM
out.accumulatedDeltaRangeM = in.adrMeters;
// accumulatedDeltaRangeUncertaintyM
out.accumulatedDeltaRangeUncertaintyM = in.adrUncertaintyMeters;
// carrierCycles
out.carrierCycles = in.carrierCycles;
// carrierPhase
out.carrierPhase = in.carrierPhase;
// carrierPhaseUncertainty
out.carrierPhaseUncertainty = in.carrierPhaseUncertainty;
// multipathIndicator
convertGnssMultipathIndicator(in, out);
// snrDb
out.snrDb = in.signalToNoiseRatioDb;
// agcLevelDb
out.agcLevelDb = in.agcLevelDb;
// fullInterSignalBiasNs
out.fullInterSignalBiasNs = in.fullInterSignalBiasNs;
// fullInterSignalBiasUncertaintyNs
out.fullInterSignalBiasUncertaintyNs = in.fullInterSignalBiasUncertaintyNs;
// satelliteInterSignalBiasNs
out.satelliteInterSignalBiasNs = in.satelliteInterSignalBiasNs;
// satelliteInterSignalBiasUncertaintyNs
out.satelliteInterSignalBiasUncertaintyNs = in.satelliteInterSignalBiasUncertaintyNs;
// satellitePvt
convertGnssSatellitePvt(in, out);
// correlationVectors
/* This is not supported, the corresponding flag is not set */
}
void GnssMeasurementInterface::convertGnssFlags(GnssMeasurementsData& in, GnssMeasurement& out) {
if (in.flags & GNSS_MEASUREMENTS_DATA_SIGNAL_TO_NOISE_RATIO_BIT)
out.flags |= out.HAS_SNR;
if (in.flags & GNSS_MEASUREMENTS_DATA_CARRIER_FREQUENCY_BIT)
out.flags |= out.HAS_CARRIER_FREQUENCY;
if (in.flags & GNSS_MEASUREMENTS_DATA_CARRIER_CYCLES_BIT)
out.flags |= out.HAS_CARRIER_CYCLES;
if (in.flags & GNSS_MEASUREMENTS_DATA_CARRIER_PHASE_BIT)
out.flags |= out.HAS_CARRIER_PHASE;
if (in.flags & GNSS_MEASUREMENTS_DATA_CARRIER_PHASE_UNCERTAINTY_BIT)
out.flags |= out.HAS_CARRIER_PHASE_UNCERTAINTY;
if (in.flags & GNSS_MEASUREMENTS_DATA_AUTOMATIC_GAIN_CONTROL_BIT)
out.flags |= out.HAS_AUTOMATIC_GAIN_CONTROL;
if (in.flags & GNSS_MEASUREMENTS_DATA_FULL_ISB_BIT)
out.flags |= out.HAS_FULL_ISB;
if (in.flags & GNSS_MEASUREMENTS_DATA_FULL_ISB_UNCERTAINTY_BIT)
out.flags |= out.HAS_FULL_ISB_UNCERTAINTY;
if (in.flags & GNSS_MEASUREMENTS_DATA_SATELLITE_ISB_BIT)
out.flags |= out.HAS_SATELLITE_ISB;
if (in.flags & GNSS_MEASUREMENTS_DATA_SATELLITE_ISB_UNCERTAINTY_BIT)
out.flags |= out.HAS_SATELLITE_ISB_UNCERTAINTY;
if (in.flags & GNSS_MEASUREMENTS_DATA_SATELLITE_PVT_BIT)
out.flags |= out.HAS_SATELLITE_PVT;
if (in.flags & GNSS_MEASUREMENTS_DATA_CORRELATION_VECTOR_BIT)
out.flags |= out.HAS_CORRELATION_VECTOR;
}
void GnssMeasurementInterface::convertGnssSvId(GnssMeasurementsData& in, int& out) {
switch (in.svType) {
case GNSS_SV_TYPE_GPS:
out = in.svId;
break;
case GNSS_SV_TYPE_SBAS:
out = in.svId;
break;
case GNSS_SV_TYPE_GLONASS:
if (in.svId != 255) { // OSN is known
out = in.svId - GLO_SV_PRN_MIN + 1;
} else { // OSN is not known, report FCN
out = in.gloFrequency + 92;
}
break;
case GNSS_SV_TYPE_QZSS:
out = in.svId;
break;
case GNSS_SV_TYPE_BEIDOU:
out = in.svId - BDS_SV_PRN_MIN + 1;
break;
case GNSS_SV_TYPE_GALILEO:
out = in.svId - GAL_SV_PRN_MIN + 1;
break;
case GNSS_SV_TYPE_NAVIC:
out = in.svId - NAVIC_SV_PRN_MIN + 1;
break;
default:
out = in.svId;
break;
}
}
void GnssMeasurementInterface::convertGnssSignalType(
GnssMeasurementsData& in, GnssSignalType& out) {
convertGnssConstellationType(in.svType, out.constellation);
out.carrierFrequencyHz = in.carrierFrequencyHz;
convertGnssMeasurementsCodeType(in.codeType, in.otherCodeTypeName, out);
}
void GnssMeasurementInterface::convertGnssConstellationType(
GnssSvType& in, GnssConstellationType& out) {
switch (in) {
case GNSS_SV_TYPE_GPS:
out = GnssConstellationType::GPS;
break;
case GNSS_SV_TYPE_SBAS:
out = GnssConstellationType::SBAS;
break;
case GNSS_SV_TYPE_GLONASS:
out = GnssConstellationType::GLONASS;
break;
case GNSS_SV_TYPE_QZSS:
out = GnssConstellationType::QZSS;
break;
case GNSS_SV_TYPE_BEIDOU:
out = GnssConstellationType::BEIDOU;
break;
case GNSS_SV_TYPE_GALILEO:
out = GnssConstellationType::GALILEO;
break;
case GNSS_SV_TYPE_NAVIC:
out = GnssConstellationType::IRNSS;
break;
case GNSS_SV_TYPE_UNKNOWN:
default:
out = GnssConstellationType::UNKNOWN;
break;
}
}
void GnssMeasurementInterface::convertGnssMeasurementsCodeType(
GnssMeasurementsCodeType& inCodeType,
char* inOtherCodeTypeName, GnssSignalType& out) {
switch (inCodeType) {
case GNSS_MEASUREMENTS_CODE_TYPE_A:
out.codeType = out.CODE_TYPE_A;
break;
case GNSS_MEASUREMENTS_CODE_TYPE_B:
out.codeType = out.CODE_TYPE_B;
break;
case GNSS_MEASUREMENTS_CODE_TYPE_C:
out.codeType = out.CODE_TYPE_C;
break;
case GNSS_MEASUREMENTS_CODE_TYPE_I:
out.codeType = out.CODE_TYPE_I;
break;
case GNSS_MEASUREMENTS_CODE_TYPE_L:
out.codeType = out.CODE_TYPE_L;
break;
case GNSS_MEASUREMENTS_CODE_TYPE_M:
out.codeType = out.CODE_TYPE_M;
break;
case GNSS_MEASUREMENTS_CODE_TYPE_N:
out.codeType = out.CODE_TYPE_N;
break;
case GNSS_MEASUREMENTS_CODE_TYPE_P:
out.codeType = out.CODE_TYPE_P;
break;
case GNSS_MEASUREMENTS_CODE_TYPE_Q:
out.codeType = out.CODE_TYPE_Q;
break;
case GNSS_MEASUREMENTS_CODE_TYPE_S:
out.codeType = out.CODE_TYPE_S;
break;
case GNSS_MEASUREMENTS_CODE_TYPE_W:
out.codeType = out.CODE_TYPE_W;
break;
case GNSS_MEASUREMENTS_CODE_TYPE_X:
out.codeType = out.CODE_TYPE_X;
break;
case GNSS_MEASUREMENTS_CODE_TYPE_Y:
out.codeType = out.CODE_TYPE_Y;
break;
case GNSS_MEASUREMENTS_CODE_TYPE_Z:
out.codeType = out.CODE_TYPE_Z;
break;
case GNSS_MEASUREMENTS_CODE_TYPE_OTHER:
default:
out.codeType = inOtherCodeTypeName;
break;
}
}
void GnssMeasurementInterface::convertGnssState(GnssMeasurementsData& in, GnssMeasurement& out) {
if (in.stateMask & GNSS_MEASUREMENTS_STATE_CODE_LOCK_BIT)
out.state |= out.STATE_CODE_LOCK;
if (in.stateMask & GNSS_MEASUREMENTS_STATE_BIT_SYNC_BIT)
out.state |= out.STATE_BIT_SYNC;
if (in.stateMask & GNSS_MEASUREMENTS_STATE_SUBFRAME_SYNC_BIT)
out.state |= out.STATE_SUBFRAME_SYNC;
if (in.stateMask & GNSS_MEASUREMENTS_STATE_TOW_DECODED_BIT)
out.state |= out.STATE_TOW_DECODED;
if (in.stateMask & GNSS_MEASUREMENTS_STATE_MSEC_AMBIGUOUS_BIT)
out.state |= out.STATE_MSEC_AMBIGUOUS;
if (in.stateMask & GNSS_MEASUREMENTS_STATE_SYMBOL_SYNC_BIT)
out.state |= out.STATE_SYMBOL_SYNC;
if (in.stateMask & GNSS_MEASUREMENTS_STATE_GLO_STRING_SYNC_BIT)
out.state |= out.STATE_GLO_STRING_SYNC;
if (in.stateMask & GNSS_MEASUREMENTS_STATE_GLO_TOD_DECODED_BIT)
out.state |= out.STATE_GLO_TOD_DECODED;
if (in.stateMask & GNSS_MEASUREMENTS_STATE_BDS_D2_BIT_SYNC_BIT)
out.state |= out.STATE_BDS_D2_BIT_SYNC;
if (in.stateMask & GNSS_MEASUREMENTS_STATE_BDS_D2_SUBFRAME_SYNC_BIT)
out.state |= out.STATE_BDS_D2_SUBFRAME_SYNC;
if (in.stateMask & GNSS_MEASUREMENTS_STATE_GAL_E1BC_CODE_LOCK_BIT)
out.state |= out.STATE_GAL_E1BC_CODE_LOCK;
if (in.stateMask & GNSS_MEASUREMENTS_STATE_GAL_E1C_2ND_CODE_LOCK_BIT)
out.state |= out.STATE_GAL_E1C_2ND_CODE_LOCK;
if (in.stateMask & GNSS_MEASUREMENTS_STATE_GAL_E1B_PAGE_SYNC_BIT)
out.state |= out.STATE_GAL_E1B_PAGE_SYNC;
if (in.stateMask & GNSS_MEASUREMENTS_STATE_SBAS_SYNC_BIT)
out.state |= out.STATE_SBAS_SYNC;
if (in.stateMask & GNSS_MEASUREMENTS_STATE_TOW_KNOWN_BIT)
out.state |= out.STATE_TOW_KNOWN;
if (in.stateMask & GNSS_MEASUREMENTS_STATE_GLO_TOD_KNOWN_BIT)
out.state |= out.STATE_GLO_TOD_KNOWN;
if (in.stateMask & GNSS_MEASUREMENTS_STATE_2ND_CODE_LOCK_BIT)
out.state |= out.STATE_2ND_CODE_LOCK;
}
void GnssMeasurementInterface::convertGnssAccumulatedDeltaRangeState(
GnssMeasurementsData& in, GnssMeasurement& out) {
if (in.adrStateMask & GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_VALID_BIT)
out.accumulatedDeltaRangeState |= out.ADR_STATE_VALID;
if (in.adrStateMask & GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_RESET_BIT)
out.accumulatedDeltaRangeState |= out.ADR_STATE_RESET;
if (in.adrStateMask & GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_CYCLE_SLIP_BIT)
out.accumulatedDeltaRangeState |= out.ADR_STATE_CYCLE_SLIP;
if (in.adrStateMask & GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_HALF_CYCLE_RESOLVED_BIT)
out.accumulatedDeltaRangeState |= out.ADR_STATE_HALF_CYCLE_RESOLVED;
}
void GnssMeasurementInterface::convertGnssMultipathIndicator(
GnssMeasurementsData& in, GnssMeasurement& out) {
switch (in.multipathIndicator) {
case GNSS_MEASUREMENTS_MULTIPATH_INDICATOR_PRESENT:
out.multipathIndicator = GnssMultipathIndicator::PRESENT;
break;
case GNSS_MEASUREMENTS_MULTIPATH_INDICATOR_NOT_PRESENT:
out.multipathIndicator = GnssMultipathIndicator::NOT_PRESENT;
break;
case GNSS_MEASUREMENTS_MULTIPATH_INDICATOR_UNKNOWN:
default:
out.multipathIndicator = GnssMultipathIndicator::UNKNOWN;
break;
}
}
void GnssMeasurementInterface::convertGnssSatellitePvtFlags(GnssMeasurementsData& in,
GnssMeasurement& out) {
if (in.satellitePvt.flags & GNSS_SATELLITE_PVT_POSITION_VELOCITY_CLOCK_INFO_BIT)
out.satellitePvt.flags |= out.satellitePvt.HAS_POSITION_VELOCITY_CLOCK_INFO;
if (in.satellitePvt.flags & GNSS_SATELLITE_PVT_IONO_BIT)
out.satellitePvt.flags |= out.satellitePvt.HAS_IONO;
if (in.satellitePvt.flags & GNSS_SATELLITE_PVT_TROPO_BIT)
out.satellitePvt.flags |= out.satellitePvt.HAS_TROPO;
}
void GnssMeasurementInterface::convertGnssSatellitePvt(
GnssMeasurementsData& in, GnssMeasurement& out) {
// flags
convertGnssSatellitePvtFlags(in, out);
// satPosEcef
out.satellitePvt.satPosEcef.posXMeters = in.satellitePvt.satPosEcef.posXMeters;
out.satellitePvt.satPosEcef.posYMeters = in.satellitePvt.satPosEcef.posYMeters;
out.satellitePvt.satPosEcef.posZMeters = in.satellitePvt.satPosEcef.posZMeters;
out.satellitePvt.satPosEcef.ureMeters = in.satellitePvt.satPosEcef.ureMeters;
// satVelEcef
out.satellitePvt.satVelEcef.velXMps = in.satellitePvt.satVelEcef.velXMps;
out.satellitePvt.satVelEcef.velYMps = in.satellitePvt.satVelEcef.velYMps;
out.satellitePvt.satVelEcef.velZMps = in.satellitePvt.satVelEcef.velZMps;
out.satellitePvt.satVelEcef.ureRateMps = in.satellitePvt.satVelEcef.ureRateMps;
// satClockInfo
out.satellitePvt.satClockInfo.satHardwareCodeBiasMeters =
in.satellitePvt.satClockInfo.satHardwareCodeBiasMeters;
out.satellitePvt.satClockInfo.satTimeCorrectionMeters =
in.satellitePvt.satClockInfo.satTimeCorrectionMeters;
out.satellitePvt.satClockInfo.satClkDriftMps = in.satellitePvt.satClockInfo.satClkDriftMps;
// ionoDelayMeters
out.satellitePvt.ionoDelayMeters = in.satellitePvt.ionoDelayMeters;
// tropoDelayMeters
out.satellitePvt.tropoDelayMeters = in.satellitePvt.tropoDelayMeters;
}
void GnssMeasurementInterface::convertGnssClock(
GnssMeasurementsClock& in, GnssClock& out) {
// gnssClockFlags
if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_LEAP_SECOND_BIT)
out.gnssClockFlags |= out.HAS_LEAP_SECOND;
if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_TIME_UNCERTAINTY_BIT)
out.gnssClockFlags |= out.HAS_TIME_UNCERTAINTY;
if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_FULL_BIAS_BIT)
out.gnssClockFlags |= out.HAS_FULL_BIAS;
if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_BIAS_BIT)
out.gnssClockFlags |= out.HAS_BIAS;
if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_BIAS_UNCERTAINTY_BIT)
out.gnssClockFlags |= out.HAS_BIAS_UNCERTAINTY;
if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_DRIFT_BIT)
out.gnssClockFlags |= out.HAS_DRIFT;
if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_DRIFT_UNCERTAINTY_BIT)
out.gnssClockFlags |= out.HAS_DRIFT_UNCERTAINTY;
// leapSecond
out.leapSecond = in.leapSecond;
// timeNs
out.timeNs = in.timeNs;
// timeUncertaintyNs
out.timeUncertaintyNs = in.timeUncertaintyNs;
// fullBiasNs
out.fullBiasNs = in.fullBiasNs;
// biasNs
out.biasNs = in.biasNs;
// biasUncertaintyNs
out.biasUncertaintyNs = in.biasUncertaintyNs;
// driftNsps
out.driftNsps = in.driftNsps;
// driftUncertaintyNsps
out.driftUncertaintyNsps = in.driftUncertaintyNsps;
// hwClockDiscontinuityCount
out.hwClockDiscontinuityCount = in.hwClockDiscontinuityCount;
// referenceSignalTypeForIsb
convertGnssConstellationType(in.referenceSignalTypeForIsb.svType,
out.referenceSignalTypeForIsb.constellation);
out.referenceSignalTypeForIsb.carrierFrequencyHz =
in.referenceSignalTypeForIsb.carrierFrequencyHz;
convertGnssMeasurementsCodeType(in.referenceSignalTypeForIsb.codeType,
in.referenceSignalTypeForIsb.otherCodeTypeName,
out.referenceSignalTypeForIsb);
}
void GnssMeasurementInterface::convertElapsedRealtimeNanos(
GnssMeasurementsNotification& in, ElapsedRealtime& elapsedRealtime) {
if (in.clock.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_ELAPSED_REAL_TIME_BIT) {
elapsedRealtime.flags |= elapsedRealtime.HAS_TIMESTAMP_NS;
elapsedRealtime.timestampNs = in.clock.elapsedRealTime;
elapsedRealtime.flags |= elapsedRealtime.HAS_TIME_UNCERTAINTY_NS;
elapsedRealtime.timeUncertaintyNs = in.clock.elapsedRealTimeUnc;
LOC_LOGd("elapsedRealtime.timestampNs=%" PRIi64 ""
" elapsedRealtime.timeUncertaintyNs=%" PRIi64 " elapsedRealtime.flags=0x%X",
elapsedRealtime.timestampNs,
elapsedRealtime.timeUncertaintyNs, elapsedRealtime.flags);
}
}
void GnssMeasurementInterface::printGnssData(GnssData& data) {
LOC_LOGd(" Measurements Info for %d satellites", data.measurements.size());
for (size_t i = 0; i < data.measurements.size(); i++) {
LOC_LOGd("%02d : flags: 0x%08x,"
" svid: %d,"
" signalType.constellation: %u,"
" signalType.carrierFrequencyHz: %.2f,"
" signalType.codeType: %s,"
" timeOffsetNs: %.2f,"
" state: 0x%08x,"
" receivedSvTimeInNs: %" PRIu64
" receivedSvTimeUncertaintyInNs: %" PRIu64
" antennaCN0DbHz: %.2f,"
" basebandCN0DbHz: %.2f,"
" pseudorangeRateMps : %.2f,"
" pseudorangeRateUncertaintyMps : %.2f,\n"
" accumulatedDeltaRangeState: 0x%08x,"
" accumulatedDeltaRangeM: %.2f, "
" accumulatedDeltaRangeUncertaintyM : %.2f, "
" carrierCycles: %" PRIu64
" carrierPhase: %.2f,"
" carrierPhaseUncertainty: %.2f,"
" multipathIndicator: %u,"
" snrDb: %.2f,"
" agcLevelDb: %.2f,"
" fullInterSignalBiasNs: %.2f,"
" fullInterSignalBiasUncertaintyNs: %.2f,"
" satelliteInterSignalBiasNs: %.2f,"
" satelliteInterSignalBiasUncertaintyNs: %.2f",
i + 1,
data.measurements[i].flags,
data.measurements[i].svid,
data.measurements[i].signalType.constellation,
data.measurements[i].signalType.carrierFrequencyHz,
data.measurements[i].signalType.codeType.c_str(),
data.measurements[i].timeOffsetNs,
data.measurements[i].state,
data.measurements[i].receivedSvTimeInNs,
data.measurements[i].receivedSvTimeUncertaintyInNs,
data.measurements[i].antennaCN0DbHz,
data.measurements[i].basebandCN0DbHz,
data.measurements[i].pseudorangeRateMps,
data.measurements[i].pseudorangeRateUncertaintyMps,
data.measurements[i].accumulatedDeltaRangeState,
data.measurements[i].accumulatedDeltaRangeM,
data.measurements[i].accumulatedDeltaRangeUncertaintyM,
data.measurements[i].carrierCycles,
data.measurements[i].carrierPhase,
data.measurements[i].carrierPhaseUncertainty,
data.measurements[i].multipathIndicator,
data.measurements[i].snrDb,
data.measurements[i].agcLevelDb,
data.measurements[i].fullInterSignalBiasNs,
data.measurements[i].fullInterSignalBiasUncertaintyNs,
data.measurements[i].satelliteInterSignalBiasNs,
data.measurements[i].satelliteInterSignalBiasUncertaintyNs
);
LOC_LOGd(" satellitePvt.flags: 0x%04x,"
" satellitePvt.satPosEcef.posXMeters: %.2f,"
" satellitePvt.satPosEcef.posYMeters: %.2f,"
" satellitePvt.satPosEcef.posZMeters: %.2f,"
" satellitePvt.satPosEcef.ureMeters: %.2f,"
" satellitePvt.satVelEcef.velXMps: %.2f,"
" satellitePvt.satVelEcef.velYMps: %.2f,"
" satellitePvt.satVelEcef.velZMps: %.2f,"
" satellitePvt.satVelEcef.ureRateMps: %.2f,"
" satellitePvt.satClockInfo.satHardwareCodeBiasMeters: %.2f,"
" satellitePvt.satClockInfo.satTimeCorrectionMeters: %.2f,"
" satellitePvt.satClockInfo.satClkDriftMps: %.2f,"
" satellitePvt.ionoDelayMeters: %.2f,"
" satellitePvt.tropoDelayMeters: %.2f",
data.measurements[i].satellitePvt.flags,
data.measurements[i].satellitePvt.satPosEcef.posXMeters,
data.measurements[i].satellitePvt.satPosEcef.posYMeters,
data.measurements[i].satellitePvt.satPosEcef.posZMeters,
data.measurements[i].satellitePvt.satPosEcef.ureMeters,
data.measurements[i].satellitePvt.satVelEcef.velXMps,
data.measurements[i].satellitePvt.satVelEcef.velYMps,
data.measurements[i].satellitePvt.satVelEcef.velZMps,
data.measurements[i].satellitePvt.satVelEcef.ureRateMps,
data.measurements[i].satellitePvt.satClockInfo.satHardwareCodeBiasMeters,
data.measurements[i].satellitePvt.satClockInfo.satTimeCorrectionMeters,
data.measurements[i].satellitePvt.satClockInfo.satClkDriftMps,
data.measurements[i].satellitePvt.ionoDelayMeters,
data.measurements[i].satellitePvt.tropoDelayMeters
);
}
LOC_LOGd(" Clocks Info "
" gnssClockFlags: 0x%04x,"
" leapSecond: %d,"
" timeNs: %" PRId64
" timeUncertaintyNs: %.2f,"
" fullBiasNs: %" PRId64
" biasNs: %.2f,"
" biasUncertaintyNs: %.2f,"
" driftNsps: %.2f,"
" driftUncertaintyNsps: %.2f,"
" hwClockDiscontinuityCount: %u,"
" referenceSignalTypeForIsb.constellation: %u,"
" referenceSignalTypeForIsb.carrierFrequencyHz: %.2f,"
" referenceSignalTypeForIsb.codeType: %s",
data.clock.gnssClockFlags,
data.clock.leapSecond,
data.clock.timeNs,
data.clock.timeUncertaintyNs,
data.clock.fullBiasNs,
data.clock.biasNs,
data.clock.biasUncertaintyNs,
data.clock.driftNsps,
data.clock.driftUncertaintyNsps,
data.clock.hwClockDiscontinuityCount,
data.clock.referenceSignalTypeForIsb.constellation,
data.clock.referenceSignalTypeForIsb.carrierFrequencyHz,
data.clock.referenceSignalTypeForIsb.codeType.c_str());
LOC_LOGd(" ElapsedRealtime "
" flags: 0x%08x,"
" timestampNs: %" PRId64", "
" timeUncertaintyNs: %.2f",
data.elapsedRealtime.flags,
data.elapsedRealtime.timestampNs,
data.elapsedRealtime.timeUncertaintyNs);
}
} // namespace implementation
} // namespace aidl
} // namespace gnss
} // namespace hardware
} // namespace android

View File

@@ -0,0 +1,90 @@
/*
* Copyright (c) 2021, The Linux Foundation. All rights reserved.
* Not a Contribution
*/
/*
* Copyright (C) 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <aidl/android/hardware/gnss/BnGnssMeasurementInterface.h>
#include <aidl/android/hardware/gnss/BnGnssMeasurementCallback.h>
#include <atomic>
#include <mutex>
#include <thread>
#include <LocationAPIClientBase.h>
#include <gps_extended_c.h>
using aidl::android::hardware::gnss::ElapsedRealtime;
using aidl::android::hardware::gnss::GnssClock;
using aidl::android::hardware::gnss::GnssData;
using aidl::android::hardware::gnss::GnssMeasurement;
using aidl::android::hardware::gnss::GnssSignalType;
using aidl::android::hardware::gnss::GnssConstellationType;
namespace android {
namespace hardware {
namespace gnss {
namespace aidl {
namespace implementation {
using ::aidl::android::hardware::gnss::BnGnssMeasurementInterface;
using ::aidl::android::hardware::gnss::IGnssMeasurementCallback;
struct GnssMeasurementInterface : public BnGnssMeasurementInterface, public LocationAPIClientBase {
public:
GnssMeasurementInterface();
~GnssMeasurementInterface() {}
::ndk::ScopedAStatus setCallback(
const std::shared_ptr<IGnssMeasurementCallback>& in_callback,
bool in_enableFullTracking, bool in_enableCorrVecOutputs) override;
::ndk::ScopedAStatus close() override;
// callbacks we are interested in
void onGnssMeasurementsCb(GnssMeasurementsNotification gnssMeasurementsNotification) final;
private:
std::shared_ptr<IGnssMeasurementCallback> mGnssMeasurementCbIface = nullptr;
// Synchronization lock for mGnssMeasurementCbIface
mutable std::mutex mMutex;
AIBinder_DeathRecipient* mDeathRecipient;
bool mTracking;
static void gnssMeasurementDied(void* cookie);
void startTracking(GnssPowerMode powerMode = GNSS_POWER_MODE_INVALID,
uint32_t timeBetweenMeasurement = GPS_DEFAULT_FIX_INTERVAL_MS);
void convertGnssData(GnssMeasurementsNotification& in, GnssData& out);
void convertGnssMeasurement(GnssMeasurementsData& in, GnssMeasurement& out);
void convertGnssFlags(GnssMeasurementsData& in, GnssMeasurement& out);
static void convertGnssSvId(GnssMeasurementsData& in, int& out);
void convertGnssSignalType(GnssMeasurementsData& in, GnssSignalType& out);
static void convertGnssConstellationType(GnssSvType& in, GnssConstellationType& out);
void convertGnssMeasurementsCodeType(GnssMeasurementsCodeType& inCodeType,
char* inOtherCodeTypeName, GnssSignalType& out);
void convertGnssState(GnssMeasurementsData& in, GnssMeasurement& out);
void convertGnssAccumulatedDeltaRangeState(GnssMeasurementsData& in, GnssMeasurement& out);
void convertGnssMultipathIndicator(GnssMeasurementsData& in, GnssMeasurement& out);
void convertGnssSatellitePvtFlags(GnssMeasurementsData& in, GnssMeasurement& out);
void convertGnssSatellitePvt(GnssMeasurementsData& in, GnssMeasurement& out);
void convertGnssClock(GnssMeasurementsClock& in, GnssClock& out);
void convertElapsedRealtimeNanos(GnssMeasurementsNotification& in,
ElapsedRealtime& elapsedRealtime);
void printGnssData(GnssData& data);
};
} // namespace implementation
} // namespace aidl
} // namespace gnss
} // namespace hardware
} // namespace android

View File

@@ -0,0 +1,152 @@
/*
* Copyright (c) 2021, The Linux Foundation. All rights reserved.
* Not a Contribution
*/
/*
* Copyright (C) 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define LOG_TAG "GnssPowerIndicationAidl"
#include "GnssPowerIndication.h"
#include <android/binder_auto_utils.h>
#include <log_util.h>
#include <inttypes.h>
#include "loc_misc_utils.h"
typedef const GnssInterface* (getLocationInterface)();
namespace android {
namespace hardware {
namespace gnss {
namespace aidl {
namespace implementation {
static GnssPowerIndication* spGnssPowerIndication = nullptr;
GnssPowerIndication::GnssPowerIndication() :
mDeathRecipient(AIBinder_DeathRecipient_new(GnssPowerIndication::gnssPowerIndicationDied)) {
spGnssPowerIndication = this;
}
GnssPowerIndication::~GnssPowerIndication() {
spGnssPowerIndication = nullptr;
}
::ndk::ScopedAStatus GnssPowerIndication::setCallback(
const std::shared_ptr<IGnssPowerIndicationCallback>& in_callback) {
std::unique_lock<std::mutex> lock(mMutex);
if (nullptr == in_callback) {
LOC_LOGe("callback is nullptr");
return ndk::ScopedAStatus::fromExceptionCode(STATUS_INVALID_OPERATION);
}
AIBinder_linkToDeath(in_callback->asBinder().get(), mDeathRecipient, this);
mGnssPowerIndicationCb = in_callback;
static bool getGnssInterfaceFailed = false;
if (nullptr == mGnssInterface && !getGnssInterfaceFailed) {
void * libHandle = nullptr;
getLocationInterface* getter = (getLocationInterface*)
dlGetSymFromLib(libHandle, "libgnss.so", "getGnssInterface");
if (NULL == getter) {
getGnssInterfaceFailed = true;
} else {
mGnssInterface = (GnssInterface*)(*getter)();
}
}
if (nullptr != mGnssInterface) {
mGnssInterface->powerIndicationInit(piGnssPowerIndicationCb);
} else {
LOC_LOGe("mGnssInterface is nullptr");
return ndk::ScopedAStatus::fromExceptionCode(STATUS_INVALID_OPERATION);
}
lock.unlock();
mGnssPowerIndicationCb->setCapabilitiesCb(IGnssPowerIndicationCallback::CAPABILITY_TOTAL);
return ndk::ScopedAStatus::ok();
}
void GnssPowerIndication::cleanup() {
LOC_LOGd("()");
if (nullptr != mGnssPowerIndicationCb) {
AIBinder_unlinkToDeath(mGnssPowerIndicationCb->asBinder().get(), mDeathRecipient, this);
mGnssPowerIndicationCb = nullptr;
}
}
void GnssPowerIndication::gnssPowerIndicationDied(void* cookie) {
LOC_LOGe("IGnssPowerIndicationCallback service died");
GnssPowerIndication* iface = static_cast<GnssPowerIndication*>(cookie);
if (iface != nullptr) {
iface->cleanup();
}
}
ndk::ScopedAStatus GnssPowerIndication::requestGnssPowerStats() {
LOC_LOGd("requestGnssPowerStats");
std::unique_lock<std::mutex> lock(mMutex);
if (nullptr != mGnssInterface) {
lock.unlock();
mGnssInterface->powerIndicationRequest();
} else {
LOC_LOGe("mGnssInterface is nullptr");
}
return ndk::ScopedAStatus::ok();
}
void GnssPowerIndication::piGnssPowerIndicationCb(GnssPowerStatistics gnssPowerStatistics) {
if (nullptr != spGnssPowerIndication) {
spGnssPowerIndication->gnssPowerIndicationCb(gnssPowerStatistics);
} else {
LOC_LOGe("spGnssPowerIndication is nullptr");
}
}
void GnssPowerIndication::gnssPowerIndicationCb(GnssPowerStatistics gnssPowerStatistics) {
GnssPowerStats gnssPowerStats = {};
gnssPowerStats.elapsedRealtime.flags |= gnssPowerStats.elapsedRealtime.HAS_TIMESTAMP_NS;
gnssPowerStats.elapsedRealtime.timestampNs = gnssPowerStatistics.elapsedRealTime;
gnssPowerStats.elapsedRealtime.flags |= gnssPowerStats.elapsedRealtime.HAS_TIME_UNCERTAINTY_NS;
gnssPowerStats.elapsedRealtime.timeUncertaintyNs = gnssPowerStatistics.elapsedRealTimeUnc;
gnssPowerStats.totalEnergyMilliJoule = gnssPowerStatistics.totalEnergyMilliJoule;
LOC_LOGd("gnssPowerStats.elapsedRealtime.flags: 0x%08X"
" gnssPowerStats.elapsedRealtime.timestampNs: %" PRId64", "
" gnssPowerStats.elapsedRealtime.timeUncertaintyNs: %.2f,"
" gnssPowerStatistics.totalEnergyMilliJoule = %.2f",
gnssPowerStats.elapsedRealtime.flags,
gnssPowerStats.elapsedRealtime.timestampNs,
gnssPowerStats.elapsedRealtime.timeUncertaintyNs,
gnssPowerStats.totalEnergyMilliJoule);
std::unique_lock<std::mutex> lock(mMutex);
auto gnssPowerIndicationCb = mGnssPowerIndicationCb;
lock.unlock();
if (nullptr != gnssPowerIndicationCb) {
gnssPowerIndicationCb->gnssPowerStatsCb(gnssPowerStats);
}
}
} // namespace implementation
} // namespace aidl
} // namespace gnss
} // namespace hardware
} // namespace android

View File

@@ -0,0 +1,62 @@
/*
* Copyright (c) 2021, The Linux Foundation. All rights reserved.
* Not a Contribution
*/
/*
* Copyright (C) 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <aidl/android/hardware/gnss/BnGnssPowerIndication.h>
#include <location_interface.h>
namespace android {
namespace hardware {
namespace gnss {
namespace aidl {
namespace implementation {
using ::aidl::android::hardware::gnss::BnGnssPowerIndication;
using ::aidl::android::hardware::gnss::IGnssPowerIndicationCallback;
using ::aidl::android::hardware::gnss::GnssPowerStats;
struct GnssPowerIndication : public BnGnssPowerIndication {
public:
GnssPowerIndication();
~GnssPowerIndication();
::ndk::ScopedAStatus setCallback(
const std::shared_ptr<IGnssPowerIndicationCallback>& in_callback) override;
::ndk::ScopedAStatus requestGnssPowerStats() override;
void cleanup();
// callbacks we are interested in
void gnssPowerIndicationCb(GnssPowerStatistics gnssPowerStatistics);
static void piGnssPowerIndicationCb(GnssPowerStatistics gnssPowerStatistics);
private:
std::shared_ptr<IGnssPowerIndicationCallback> mGnssPowerIndicationCb = nullptr;
// Synchronization lock for mGnssPowerIndicationCb
mutable std::mutex mMutex;
AIBinder_DeathRecipient* mDeathRecipient;
const GnssInterface* mGnssInterface = nullptr;
static void gnssPowerIndicationDied(void* cookie);
};
} // namespace implementation
} // namespace aidl
} // namespace gnss
} // namespace hardware
} // namespace android

View File

@@ -0,0 +1,180 @@
This text file is provided to comply with the attribution requirements of
the licenses herein, but see NOTICE for license terms of this software.
The Apache 2.0 license can be found at http://www.apache.org/licenses/LICENSE-2.0.html
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS

View File

@@ -0,0 +1,40 @@
This NOTICE file contains certain notices of software components included
with the software that Qualcomm Technologies, Inc. ("Qualcomm Technologies") is required to
provide you. Notwithstanding anything in the notices in this file, your use
of these software components together with the Qualcomm Technologies software (Qualcomm Technologies
software hereinafter referred to as "Software") is subject to the terms of
your license from Qualcomm Technologies. Compliance with all copyright laws and software
license agreements included in the notice section of this file are the
responsibility of the user. Except as may be granted by separate express
written agreement, this file provides no license to any patents,
trademarks, copyrights, or other intellectual property.
Copyright (c) 2021 Qualcomm Technologies, Inc. All rights reserved.
Qualcomm is a registered trademark and registered service mark of
QUALCOMM Incorporated. All other trademarks and service marks are the
property of their respective owners.
________________________________________
NOTICES
________________________________________
Copyright 2020, The Android Open-Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
________________________________________
Note: Any files for which the above Apache License notices are required
to be provided are not contributions.
A copy of the Apache 2.0 license is included in the file LICENSE
for attribution purposes only.

View File

@@ -0,0 +1,6 @@
service gnss_service /vendor/bin/hw/android.hardware.gnss-aidl-service-qti
interface aidl android.hardware.gnss.IGnss/default
interface aidl vendor.qti.gnss.ILocAidlGnss/default
class hal
user gps
group system gps radio vendor_qti_diag

View File

@@ -0,0 +1,33 @@
<!-- Copyright (c) 2021, 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.
-->
<manifest version="1.0" type="device">
<hal format="aidl">
<name>android.hardware.gnss</name>
<fqname>IGnss/default</fqname>
</hal>
</manifest>

View File

@@ -0,0 +1,177 @@
/* Copyright (c) 2017-2021, 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.
*
*/
#define LOG_NDEBUG 0
#define LOG_TAG "LocSvc_GnssAPIClient"
#include <log_util.h>
#include <loc_cfg.h>
#include "GnssAPIClient.h"
#include <LocContext.h>
namespace android {
namespace hardware {
namespace gnss {
namespace aidl {
namespace implementation {
GnssAPIClient::GnssAPIClient(const shared_ptr<IGnssCallback>& gpsCb) :
LocationAPIClientBase(),
mControlClient(new LocationAPIControlClient()),
mTracking(false),
mLocationCapabilitiesMask(0),
mLocationCapabilitiesCached(false),
mGnssCbIface(gpsCb) {
LOC_LOGD("%s]: (%p)", __FUNCTION__, &gpsCb);
initLocationOptions();
}
GnssAPIClient::~GnssAPIClient() {
LOC_LOGD("%s]: ()", __FUNCTION__);
if (mControlClient) {
delete mControlClient;
mControlClient = nullptr;
}
}
void GnssAPIClient::setCallbacks() {
LocationCallbacks locationCallbacks;
memset(&locationCallbacks, 0, sizeof(LocationCallbacks));
locationCallbacks.size = sizeof(LocationCallbacks);
if (mGnssCbIface != nullptr) {
locationCallbacks.capabilitiesCb = [this](LocationCapabilitiesMask capabilitiesMask) {
onCapabilitiesCb(capabilitiesMask);
};
}
locAPISetCallbacks(locationCallbacks);
}
// for GpsInterface
void GnssAPIClient::gnssUpdateCallbacks(const shared_ptr<IGnssCallback>& gpsCb) {
mMutex.lock();
mGnssCbIface = gpsCb;
mMutex.unlock();
if (gpsCb != nullptr) {
setCallbacks();
}
}
void GnssAPIClient::initLocationOptions() {
// set default LocationOptions.
memset(&mTrackingOptions, 0, sizeof(TrackingOptions));
mTrackingOptions.size = sizeof(TrackingOptions);
mTrackingOptions.minInterval = 1000;
mTrackingOptions.minDistance = 0;
mTrackingOptions.mode = GNSS_SUPL_MODE_STANDALONE;
}
bool GnssAPIClient::gnssStart() {
LOC_LOGD("%s]: ()", __FUNCTION__);
mMutex.lock();
mTracking = true;
mMutex.unlock();
locAPIStartTracking(mTrackingOptions);
return true;
}
bool GnssAPIClient::gnssStop() {
LOC_LOGD("%s]: ()", __FUNCTION__);
mMutex.lock();
mTracking = false;
mMutex.unlock();
locAPIStopTracking();
return true;
}
void GnssAPIClient::requestCapabilities() {
// only send capablities if it's already cached, otherwise the first time LocationAPI
// is initialized, capabilities will be sent by LocationAPI
if (mLocationCapabilitiesCached) {
onCapabilitiesCb(mLocationCapabilitiesMask);
}
}
void GnssAPIClient::gnssEnable(LocationTechnologyType techType) {
LOC_LOGD("%s]: (%0d)", __FUNCTION__, techType);
if (mControlClient == nullptr) {
return;
}
mControlClient->locAPIEnable(techType);
}
void GnssAPIClient::gnssDisable() {
LOC_LOGD("%s]: ()", __FUNCTION__);
if (mControlClient == nullptr) {
return;
}
mControlClient->locAPIDisable();
}
void GnssAPIClient::gnssConfigurationUpdate(const GnssConfig& gnssConfig) {
LOC_LOGD("%s]: (%02x)", __FUNCTION__, gnssConfig.flags);
if (mControlClient == nullptr) {
return;
}
mControlClient->locAPIGnssUpdateConfig(gnssConfig);
}
// callbacks
void GnssAPIClient::onCapabilitiesCb(LocationCapabilitiesMask capabilitiesMask) {
LOC_LOGD("%s]: (%02x)", __FUNCTION__, capabilitiesMask);
mLocationCapabilitiesMask = capabilitiesMask;
mLocationCapabilitiesCached = true;
mMutex.lock();
auto gnssCbIface(mGnssCbIface);
mMutex.unlock();
uint32_t capabilities = 0;
if (capabilitiesMask & LOCATION_CAPABILITIES_CONSTELLATION_ENABLEMENT_BIT) {
capabilities |= IGnssCallback::CAPABILITY_SATELLITE_BLOCKLIST;
}
// CORRELATION_VECTOR not supported.
capabilities |= IGnssCallback::CAPABILITY_SATELLITE_PVT;
if (capabilitiesMask & LOCATION_CAPABILITIES_MEASUREMENTS_CORRECTION_BIT) {
capabilities |= IGnssCallback::CAPABILITY_MEASUREMENT_CORRECTIONS_FOR_DRIVING;
}
if (gnssCbIface != nullptr) {
auto r = gnssCbIface->gnssSetCapabilitiesCb(capabilities);
if (!r.isOk()) {
LOC_LOGe("Error from AIDL gnssSetCapabilitiesCb");
}
}
}
} // namespace implementation
} // namespace aidl
} // namespace gnss
} // namespace hardware
} // namespace android

View File

@@ -0,0 +1,85 @@
/* Copyright (c) 2017-2021, 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 GNSS_API_CLINET_H
#define GNSS_API_CLINET_H
#include <mutex>
#include <aidl/android/hardware/gnss/IGnssCallback.h>
#include <LocationAPIClientBase.h>
namespace android {
namespace hardware {
namespace gnss {
namespace aidl {
namespace implementation {
using ::std::shared_ptr;
using ::aidl::android::hardware::gnss::IGnssCallback;
class GnssAPIClient : public LocationAPIClientBase {
public:
GnssAPIClient(const shared_ptr<IGnssCallback>& gpsCb);
GnssAPIClient(const GnssAPIClient&) = delete;
GnssAPIClient& operator=(const GnssAPIClient&) = delete;
// for GpsInterface
void gnssUpdateCallbacks(const shared_ptr<IGnssCallback>& gpsCb);
bool gnssStart();
bool gnssStop();
void requestCapabilities();
// these apis using LocationAPIControlClient
void gnssConfigurationUpdate(const GnssConfig& gnssConfig);
void gnssEnable(LocationTechnologyType techType);
void gnssDisable();
// callbacks we are interested in
void onCapabilitiesCb(LocationCapabilitiesMask capabilitiesMask) final;
private:
virtual ~GnssAPIClient();
void setCallbacks();
void initLocationOptions();
std::mutex mMutex;
bool mTracking;
TrackingOptions mTrackingOptions;
LocationAPIControlClient* mControlClient;
LocationCapabilitiesMask mLocationCapabilitiesMask;
bool mLocationCapabilitiesCached;
shared_ptr<IGnssCallback> mGnssCbIface;
};
} // namespace implementation
} // namespace aidl
} // namespace gnss
} // namespace hardware
} // namespace android
#endif // GNSS_API_CLINET_H

View File

@@ -0,0 +1,107 @@
/*
* Copyright (c) 2021, The Linux Foundation. All rights reserved.
* Not a Contribution
*/
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2_0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2_0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <aidl/android/hardware/gnss/IGnss.h>
#include <android/hardware/gnss/2.1/IGnss.h>
#include <hidl/LegacySupport.h>
#include "loc_cfg.h"
#include "loc_misc_utils.h"
#include <android/binder_manager.h>
#include <android/binder_process.h>
#include "Gnss.h"
#include <pthread.h>
#include <log_util.h>
extern "C" {
#include "vndfwk-detect.h"
}
#ifdef LOG_TAG
#undef LOG_TAG
#endif
#define LOG_TAG "android.hardware.gnss-aidl-impl-qti"
#ifdef ARCH_ARM_32
#define DEFAULT_HW_BINDER_MEM_SIZE 65536
#endif
using android::hardware::configureRpcThreadpool;
using android::hardware::registerPassthroughServiceImplementation;
using android::hardware::joinRpcThreadpool;
using ::android::sp;
using android::status_t;
using android::OK;
typedef int vendorEnhancedServiceMain(int /* argc */, char* /* argv */ []);
using GnssAidl = ::android::hardware::gnss::aidl::implementation::Gnss;
using ::android::hardware::gnss::V1_0::GnssLocation;
using android::hardware::gnss::V2_1::IGnss;
int main() {
ABinderProcess_setThreadPoolMaxThreadCount(1);
ABinderProcess_startThreadPool();
ALOGI("%s, start Gnss HAL process", __FUNCTION__);
std::shared_ptr<GnssAidl> gnssAidl = ndk::SharedRefBase::make<GnssAidl>();
const std::string instance = std::string() + GnssAidl::descriptor + "/default";
if (gnssAidl != nullptr) {
binder_status_t status =
AServiceManager_addService(gnssAidl->asBinder().get(), instance.c_str());
if (STATUS_OK == status) {
ALOGD("register IGnss AIDL service success");
} else {
ALOGD("Error while register IGnss AIDL service, status: %d", status);
}
}
int vendorInfo = getVendorEnhancedInfo();
// The magic number 2 points to
// #define VND_ENHANCED_SYS_STATUS_BIT 0x02 in vndfwk-detect.c
bool vendorEnhanced = ( vendorInfo & 2 );
setVendorEnhanced(vendorEnhanced);
#ifdef ARCH_ARM_32
android::hardware::ProcessState::initWithMmapSize((size_t)(DEFAULT_HW_BINDER_MEM_SIZE));
#endif
configureRpcThreadpool(1, true);
status_t ret;
ret = registerPassthroughServiceImplementation<IGnss>();
if (ret == OK) {
// Loc AIDL service
#define VENDOR_AIDL_LIB "vendor.qti.gnss-service.so"
void* libAidlHandle = NULL;
vendorEnhancedServiceMain* aidlMainMethod = (vendorEnhancedServiceMain*)
dlGetSymFromLib(libAidlHandle, VENDOR_AIDL_LIB, "main");
if (NULL != aidlMainMethod) {
ALOGI("start LocAidl service");
(*aidlMainMethod)(0, NULL);
}
// Loc AIDL service end
joinRpcThreadpool();
ABinderProcess_joinThreadPool();
} else {
ALOGE("Error while registering IGnss HIDL 2.1 service: %d", ret);
}
return EXIT_FAILURE; // should not reach
}