feat: 添加电池和GPS支持,更新配置文件,新增相关脚本和服务

This commit is contained in:
2025-09-16 17:46:18 +08:00
parent fffe32888c
commit 15936404b6
75 changed files with 3541 additions and 0 deletions

View File

@@ -0,0 +1,69 @@
/*
* 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.
*/
// package {
// // See: http://go/android-license-faq
// // A large-scale-change added 'default_applicable_licenses' to import
// // all of the 'license_kinds' from "hardware_interfaces_license"
// // to get the below license kinds:
// // SPDX-license-identifier-Apache-2.0
// default_applicable_licenses: ["hardware_interfaces_license"],
// }
cc_binary {
name: "android.hardware.gnss-service",
relative_install_path: "hw",
// init_rc: [
// "gnss-xxx-service.rc",
// ],
vintf_fragments: [
"gnss-xxx.xml",
"gnss-xxx@2.1-service.xml",
],
vendor: true,
cflags: [
"-Wall",
"-Wextra",
],
shared_libs: [
"libbase",
"libcutils",
"libbinder_ndk",
"libhidlbase",
"libutils",
"liblog",
"android.hardware.gnss@2.1",
"android.hardware.gnss@2.0",
"android.hardware.gnss@1.1",
"android.hardware.gnss@1.0",
"android.hardware.gnss.measurement_corrections@1.1",
"android.hardware.gnss.measurement_corrections@1.0",
"android.hardware.gnss.visibility_control@1.0",
"android.hardware.gnss-V1-ndk_platform",
],
srcs: [
"Gnss.cpp",
"GnssHidlHal.cpp",
"GnssPowerIndication.cpp",
"GnssPsds.cpp",
"GnssConfiguration.cpp",
"GnssMeasurementInterface.cpp",
"service.cpp",
],
static_libs: [
"android.hardware.gnss@common-default-lib2",
],
}

View File

@@ -0,0 +1,91 @@
/*
* 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 "GnssAidl"
#include "Gnss.h"
#include <log/log.h>
#include "GnssConfiguration.h"
#include "GnssMeasurementInterface.h"
#include "GnssPsds.h"
namespace aidl::android::hardware::gnss {
std::shared_ptr<IGnssCallback> Gnss::sGnssCallback = nullptr;
ndk::ScopedAStatus Gnss::setCallback(const std::shared_ptr<IGnssCallback>& callback) {
ALOGD("Gnss::setCallback");
if (callback == nullptr) {
ALOGE("%s: Null callback ignored", __func__);
return ndk::ScopedAStatus::fromExceptionCode(STATUS_INVALID_OPERATION);
}
sGnssCallback = callback;
int capabilities = (int)(IGnssCallback::CAPABILITY_SATELLITE_BLOCKLIST |
IGnssCallback::CAPABILITY_SATELLITE_PVT |
IGnssCallback::CAPABILITY_CORRELATION_VECTOR);
auto status = sGnssCallback->gnssSetCapabilitiesCb(capabilities);
if (!status.isOk()) {
ALOGE("%s: Unable to invoke callback.gnssSetCapabilities", __func__);
}
return ndk::ScopedAStatus::ok();
}
ndk::ScopedAStatus Gnss::close() {
ALOGD("Gnss::close");
sGnssCallback = nullptr;
return ndk::ScopedAStatus::ok();
}
ndk::ScopedAStatus Gnss::getExtensionPsds(std::shared_ptr<IGnssPsds>* iGnssPsds) {
ALOGD("Gnss::getExtensionPsds");
*iGnssPsds = SharedRefBase::make<GnssPsds>();
return ndk::ScopedAStatus::ok();
}
ndk::ScopedAStatus Gnss::getExtensionGnssConfiguration(
std::shared_ptr<IGnssConfiguration>* iGnssConfiguration) {
ALOGD("Gnss::getExtensionGnssConfiguration");
if (mGnssConfiguration == nullptr) {
mGnssConfiguration = SharedRefBase::make<GnssConfiguration>();
}
*iGnssConfiguration = mGnssConfiguration;
return ndk::ScopedAStatus::ok();
}
ndk::ScopedAStatus Gnss::getExtensionGnssPowerIndication(
std::shared_ptr<IGnssPowerIndication>* iGnssPowerIndication) {
ALOGD("Gnss::getExtensionGnssPowerIndication");
if (mGnssPowerIndication == nullptr) {
mGnssPowerIndication = SharedRefBase::make<GnssPowerIndication>();
}
*iGnssPowerIndication = mGnssPowerIndication;
return ndk::ScopedAStatus::ok();
}
ndk::ScopedAStatus Gnss::getExtensionGnssMeasurement(
std::shared_ptr<IGnssMeasurementInterface>* iGnssMeasurement) {
ALOGD("Gnss::getExtensionGnssMeasurement");
*iGnssMeasurement = SharedRefBase::make<GnssMeasurementInterface>();
return ndk::ScopedAStatus::ok();
}
} // namespace aidl::android::hardware::gnss

View File

@@ -0,0 +1,48 @@
/*
* 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.
*/
#pragma once
#include <aidl/android/hardware/gnss/BnGnss.h>
#include <aidl/android/hardware/gnss/BnGnssConfiguration.h>
#include <aidl/android/hardware/gnss/BnGnssMeasurementInterface.h>
#include <aidl/android/hardware/gnss/BnGnssPowerIndication.h>
#include <aidl/android/hardware/gnss/BnGnssPsds.h>
#include "GnssConfiguration.h"
#include "GnssPowerIndication.h"
namespace aidl::android::hardware::gnss {
class Gnss : public BnGnss {
public:
ndk::ScopedAStatus setCallback(const std::shared_ptr<IGnssCallback>& callback) override;
ndk::ScopedAStatus close() override;
ndk::ScopedAStatus getExtensionPsds(std::shared_ptr<IGnssPsds>* iGnssPsds) override;
ndk::ScopedAStatus getExtensionGnssConfiguration(
std::shared_ptr<IGnssConfiguration>* iGnssConfiguration) override;
ndk::ScopedAStatus getExtensionGnssPowerIndication(
std::shared_ptr<IGnssPowerIndication>* iGnssPowerIndication) override;
ndk::ScopedAStatus getExtensionGnssMeasurement(
std::shared_ptr<IGnssMeasurementInterface>* iGnssMeasurement) override;
std::shared_ptr<GnssConfiguration> mGnssConfiguration;
std::shared_ptr<GnssPowerIndication> mGnssPowerIndication;
private:
static std::shared_ptr<IGnssCallback> sGnssCallback;
};
} // namespace aidl::android::hardware::gnss

View File

@@ -0,0 +1,52 @@
/*
* 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 "GnssConfiguration.h"
#include <log/log.h>
namespace aidl::android::hardware::gnss {
ndk::ScopedAStatus GnssConfiguration::setBlocklist(const vector<BlocklistedSource>& sourceList) {
ALOGD("GnssConfiguration::setBlocklist");
std::unique_lock<std::recursive_mutex> lock(mMutex);
mBlocklistedConstellationSet.clear();
mBlocklistedSourceSet.clear();
for (const auto& source : sourceList) {
if (source.svid == 0) {
// Wildcard blocklist, i.e., blocklist entire constellation.
mBlocklistedConstellationSet.insert(source.constellation);
} else {
mBlocklistedSourceSet.insert(source);
}
}
return ndk::ScopedAStatus::ok();
}
bool GnssConfiguration::isBlocklistedV2_1(const GnssSvInfoV2_1& gnssSvInfo) const {
std::unique_lock<std::recursive_mutex> lock(mMutex);
if (mBlocklistedConstellationSet.find(static_cast<GnssConstellationType>(
gnssSvInfo.v2_0.constellation)) != mBlocklistedConstellationSet.end()) {
return true;
}
BlocklistedSource source = {
.constellation = static_cast<GnssConstellationType>(gnssSvInfo.v2_0.constellation),
.svid = gnssSvInfo.v2_0.v1_0.svid};
return (mBlocklistedSourceSet.find(source) != mBlocklistedSourceSet.end());
}
} // namespace aidl::android::hardware::gnss

View File

@@ -0,0 +1,72 @@
/*
* 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.
*/
#pragma once
#include <aidl/android/hardware/gnss/BnGnssConfiguration.h>
#include <android/hardware/gnss/2.1/IGnssCallback.h>
#include <mutex>
#include <unordered_set>
#include <vector>
namespace aidl::android::hardware::gnss {
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 GnssSvInfoV2_1 = ::android::hardware::gnss::V2_1::IGnssCallback::GnssSvInfo;
using std::vector;
using BlocklistedSourceSet =
std::unordered_set<BlocklistedSource, BlocklistedSourceHash, BlocklistedSourceEqual>;
using BlocklistedConstellationSet =
std::unordered_set<android::hardware::gnss::GnssConstellationType>;
struct GnssConfiguration : public BnGnssConfiguration {
public:
ndk::ScopedAStatus setSuplVersion(int) override { return ndk::ScopedAStatus::ok(); }
ndk::ScopedAStatus setSuplMode(int) override { return ndk::ScopedAStatus::ok(); }
ndk::ScopedAStatus setLppProfile(int) override { return ndk::ScopedAStatus::ok(); }
ndk::ScopedAStatus setGlonassPositioningProtocol(int) override {
return ndk::ScopedAStatus::ok();
}
ndk::ScopedAStatus setEmergencySuplPdn(bool) override { return ndk::ScopedAStatus::ok(); }
ndk::ScopedAStatus setEsExtensionSec(int) override { return ndk::ScopedAStatus::ok(); }
ndk::ScopedAStatus setBlocklist(const vector<BlocklistedSource>& blocklist) override;
bool isBlocklistedV2_1(const GnssSvInfoV2_1& gnssSvInfo) const;
private:
BlocklistedSourceSet mBlocklistedSourceSet;
BlocklistedConstellationSet mBlocklistedConstellationSet;
mutable std::recursive_mutex mMutex;
};
} // namespace aidl::android::hardware::gnss

View File

@@ -0,0 +1,65 @@
/*
* 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 "GnssHidlHal"
#include "GnssHidlHal.h"
namespace aidl::android::hardware::gnss {
using GnssSvInfo = ::android::hardware::gnss::V2_1::IGnssCallback::GnssSvInfo;
GnssHidlHal::GnssHidlHal(const std::shared_ptr<Gnss>& gnssAidl) : mGnssAidl(gnssAidl) {
Gnss* iGnss = mGnssAidl.get();
std::shared_ptr<IGnssConfiguration> iGnssConfiguration;
auto status = iGnss->getExtensionGnssConfiguration(&iGnssConfiguration);
if (!status.isOk()) {
ALOGE("Failed to getExtensionGnssConfiguration.");
} else {
mGnssConfigurationAidl = iGnss->mGnssConfiguration;
}
std::shared_ptr<IGnssPowerIndication> iGnssPowerIndication;
status = iGnss->getExtensionGnssPowerIndication(&iGnssPowerIndication);
if (!status.isOk()) {
ALOGE("Failed to getExtensionGnssPowerIndication.");
} else {
mGnssPowerIndicationAidl = iGnss->mGnssPowerIndication;
}
};
hidl_vec<GnssSvInfo> GnssHidlHal::filterBlocklistedSatellitesV2_1(
hidl_vec<GnssSvInfo> gnssSvInfoList) {
if (mGnssConfigurationAidl == nullptr) {
ALOGE("Handle to AIDL GnssConfiguration is not available.");
return gnssSvInfoList;
}
for (uint32_t i = 0; i < gnssSvInfoList.size(); i++) {
if (mGnssConfigurationAidl->isBlocklistedV2_1(gnssSvInfoList[i])) {
ALOGD("Blocklisted constellation: %d, svid: %d",
(int)gnssSvInfoList[i].v2_0.constellation, gnssSvInfoList[i].v2_0.v1_0.svid);
gnssSvInfoList[i].v2_0.v1_0.svFlag &= ~static_cast<uint8_t>(
::android::hardware::gnss::V1_0::IGnssCallback::GnssSvFlags::USED_IN_FIX);
}
}
return gnssSvInfoList;
}
void GnssHidlHal::notePowerConsumption() {
mGnssPowerIndicationAidl->notePowerConsumption();
}
} // namespace aidl::android::hardware::gnss

View File

@@ -0,0 +1,42 @@
/*
* 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.
*/
#pragma once
#include "Gnss.h"
#include "GnssConfiguration.h"
#include "v2_1/GnssTemplate.h"
namespace aidl::android::hardware::gnss {
class GnssHidlHal : public ::android::hardware::gnss::common::implementation::GnssTemplate<
::android::hardware::gnss::V2_1::IGnss> {
public:
GnssHidlHal(const std::shared_ptr<Gnss>& gnssAidl);
private:
hidl_vec<::android::hardware::gnss::V2_1::IGnssCallback::GnssSvInfo>
filterBlocklistedSatellitesV2_1(
hidl_vec<::android::hardware::gnss::V2_1::IGnssCallback::GnssSvInfo> gnssSvInfoList)
override;
void notePowerConsumption() override;
std::shared_ptr<Gnss> mGnssAidl;
std::shared_ptr<GnssConfiguration> mGnssConfigurationAidl;
std::shared_ptr<GnssPowerIndication> mGnssPowerIndicationAidl;
};
} // namespace aidl::android::hardware::gnss

View File

@@ -0,0 +1,94 @@
/*
* 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 "GnssMeasIfaceAidl"
#include "GnssMeasurementInterface.h"
#include <aidl/android/hardware/gnss/BnGnss.h>
#include <log/log.h>
#include "Utils.h"
namespace aidl::android::hardware::gnss {
using Utils = ::android::hardware::gnss::common::Utils;
std::shared_ptr<IGnssMeasurementCallback> GnssMeasurementInterface::sCallback = nullptr;
GnssMeasurementInterface::GnssMeasurementInterface() : mMinIntervalMillis(1000) {}
GnssMeasurementInterface::~GnssMeasurementInterface() {
stop();
}
ndk::ScopedAStatus GnssMeasurementInterface::setCallback(
const std::shared_ptr<IGnssMeasurementCallback>& callback, const bool enableFullTracking,
const bool enableCorrVecOutputs) {
ALOGD("setCallback: enableFullTracking: %d enableCorrVecOutputs: %d", (int)enableFullTracking,
(int)enableCorrVecOutputs);
std::unique_lock<std::mutex> lock(mMutex);
sCallback = callback;
if (mIsActive) {
ALOGW("GnssMeasurement callback already set. Resetting the callback...");
stop();
}
start(enableCorrVecOutputs);
return ndk::ScopedAStatus::ok();
}
ndk::ScopedAStatus GnssMeasurementInterface::close() {
ALOGD("close");
stop();
std::unique_lock<std::mutex> lock(mMutex);
sCallback = nullptr;
return ndk::ScopedAStatus::ok();
}
void GnssMeasurementInterface::start(const bool enableCorrVecOutputs) {
ALOGD("start");
mIsActive = true;
mThread = std::thread([this, enableCorrVecOutputs]() {
while (mIsActive == true) {
auto measurement = Utils::getMockMeasurement(enableCorrVecOutputs);
this->reportMeasurement(measurement);
std::this_thread::sleep_for(std::chrono::milliseconds(mMinIntervalMillis));
}
});
mThread.detach();
}
void GnssMeasurementInterface::stop() {
ALOGD("stop");
mIsActive = false;
}
void GnssMeasurementInterface::reportMeasurement(const GnssData& data) {
ALOGD("reportMeasurement()");
std::shared_ptr<IGnssMeasurementCallback> callbackCopy;
{
std::unique_lock<std::mutex> lock(mMutex);
if (sCallback == nullptr) {
ALOGE("%s: GnssMeasurement::sCallback is null.", __func__);
return;
}
callbackCopy = sCallback;
}
callbackCopy->gnssMeasurementCb(data);
}
} // namespace aidl::android::hardware::gnss

View File

@@ -0,0 +1,52 @@
/*
* 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.
*/
#pragma once
#include <aidl/android/hardware/gnss/BnGnssMeasurementCallback.h>
#include <aidl/android/hardware/gnss/BnGnssMeasurementInterface.h>
#include <atomic>
#include <mutex>
#include <thread>
namespace aidl::android::hardware::gnss {
struct GnssMeasurementInterface : public BnGnssMeasurementInterface {
public:
GnssMeasurementInterface();
~GnssMeasurementInterface();
ndk::ScopedAStatus setCallback(const std::shared_ptr<IGnssMeasurementCallback>& callback,
const bool enableFullTracking,
const bool enableCorrVecOutputs) override;
ndk::ScopedAStatus close() override;
private:
void start(const bool enableCorrVecOutputs);
void stop();
void reportMeasurement(const GnssData&);
std::atomic<long> mMinIntervalMillis;
std::atomic<bool> mIsActive;
std::thread mThread;
// Guarded by mMutex
static std::shared_ptr<IGnssMeasurementCallback> sCallback;
// Synchronization lock for sCallback
mutable std::mutex mMutex;
};
} // namespace aidl::android::hardware::gnss

View File

@@ -0,0 +1,68 @@
/*
* 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 <aidl/android/hardware/gnss/BnGnss.h>
#include <log/log.h>
#include <utils/SystemClock.h>
namespace aidl::android::hardware::gnss {
std::shared_ptr<IGnssPowerIndicationCallback> GnssPowerIndication::sCallback = nullptr;
ndk::ScopedAStatus GnssPowerIndication::setCallback(
const std::shared_ptr<IGnssPowerIndicationCallback>& callback) {
ALOGD("setCallback");
std::unique_lock<std::mutex> lock(mMutex);
sCallback = callback;
sCallback->setCapabilitiesCb(IGnssPowerIndicationCallback::CAPABILITY_TOTAL |
IGnssPowerIndicationCallback::CAPABILITY_SINGLEBAND_TRACKING |
IGnssPowerIndicationCallback::CAPABILITY_MULTIBAND_TRACKING |
IGnssPowerIndicationCallback::CAPABILITY_SINGLEBAND_ACQUISITION |
IGnssPowerIndicationCallback::CAPABILITY_MULTIBAND_ACQUISITION |
IGnssPowerIndicationCallback::CAPABILITY_OTHER_MODES);
return ndk::ScopedAStatus::ok();
}
ndk::ScopedAStatus GnssPowerIndication::requestGnssPowerStats() {
ALOGD("requestGnssPowerStats");
std::unique_lock<std::mutex> lock(mMutex);
ElapsedRealtime elapsedRealtime = {
.flags = ElapsedRealtime::HAS_TIMESTAMP_NS | ElapsedRealtime::HAS_TIME_UNCERTAINTY_NS,
.timestampNs = ::android::elapsedRealtimeNano(),
.timeUncertaintyNs = 1000,
};
GnssPowerStats gnssPowerStats = {
.elapsedRealtime = elapsedRealtime,
.totalEnergyMilliJoule = 1.500e+3 + numLocationReported * 22.0,
.singlebandTrackingModeEnergyMilliJoule = 0.0,
.multibandTrackingModeEnergyMilliJoule = 1.28e+2 + numLocationReported * 4.0,
.singlebandAcquisitionModeEnergyMilliJoule = 0.0,
.multibandAcquisitionModeEnergyMilliJoule = 3.65e+2 + numLocationReported * 15.0,
.otherModesEnergyMilliJoule = {1.232e+2, 3.234e+3},
};
sCallback->gnssPowerStatsCb(gnssPowerStats);
return ndk::ScopedAStatus::ok();
}
void GnssPowerIndication::notePowerConsumption() {
numLocationReported++;
}
} // namespace aidl::android::hardware::gnss

View File

@@ -0,0 +1,41 @@
/*
* 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.
*/
#pragma once
#include <aidl/android/hardware/gnss/BnGnssPowerIndication.h>
namespace aidl::android::hardware::gnss {
struct GnssPowerIndication : public BnGnssPowerIndication {
public:
ndk::ScopedAStatus setCallback(
const std::shared_ptr<IGnssPowerIndicationCallback>& callback) override;
ndk::ScopedAStatus requestGnssPowerStats() override;
void notePowerConsumption();
private:
// Guarded by mMutex
static std::shared_ptr<IGnssPowerIndicationCallback> sCallback;
// Synchronization lock for sCallback
mutable std::mutex mMutex;
int numLocationReported;
};
} // namespace aidl::android::hardware::gnss

View File

@@ -0,0 +1,44 @@
/*
* 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 "GnssPsdsAidl"
#include "GnssPsds.h"
#include <aidl/android/hardware/gnss/BnGnss.h>
#include <log/log.h>
namespace aidl::android::hardware::gnss {
std::shared_ptr<IGnssPsdsCallback> GnssPsds::sCallback = nullptr;
ndk::ScopedAStatus GnssPsds::setCallback(const std::shared_ptr<IGnssPsdsCallback>& callback) {
ALOGD("setCallback");
std::unique_lock<std::mutex> lock(mMutex);
sCallback = callback;
return ndk::ScopedAStatus::ok();
}
ndk::ScopedAStatus GnssPsds::injectPsdsData(PsdsType psdsType,
const std::vector<uint8_t>& psdsData) {
ALOGD("injectPsdsData. psdsType: %d, psdsData: %d bytes", static_cast<int>(psdsType),
static_cast<int>(psdsData.size()));
if (psdsData.size() > 0) {
return ndk::ScopedAStatus::ok();
} else {
return ndk::ScopedAStatus::fromServiceSpecificError(IGnss::ERROR_INVALID_ARGUMENT);
}
}
} // namespace aidl::android::hardware::gnss

View File

@@ -0,0 +1,37 @@
/*
* 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.
*/
#pragma once
#include <aidl/android/hardware/gnss/BnGnssPsds.h>
namespace aidl::android::hardware::gnss {
struct GnssPsds : public BnGnssPsds {
public:
ndk::ScopedAStatus setCallback(const std::shared_ptr<IGnssPsdsCallback>& callback) override;
ndk::ScopedAStatus injectPsdsData(PsdsType psdsType,
const std::vector<uint8_t>& psdsData) override;
private:
// Guarded by mMutex
static std::shared_ptr<IGnssPsdsCallback> sCallback;
// Synchronization lock for sCallback
mutable std::mutex mMutex;
};
} // namespace aidl::android::hardware::gnss

View File

@@ -0,0 +1,4 @@
service gnss /vendor/bin/hw/android.hardware.gnss-service
class hal
user nobody
group nobody

View File

@@ -0,0 +1,9 @@
<manifest version="1.0" type="device">
<hal format="aidl">
<name>android.hardware.gnss</name>
<interface>
<name>IGnss</name>
<instance>default</instance>
</interface>
</hal>
</manifest>

View File

@@ -0,0 +1,12 @@
<manifest version="1.0" type="device">
<hal format="hidl">
<name>android.hardware.gnss</name>
<transport>hwbinder</transport>
<version>2.1</version>
<version>1.1</version>
<interface>
<name>IGnss</name>
<instance>default</instance>
</interface>
</hal>
</manifest>

View File

@@ -0,0 +1,58 @@
/*
* 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.
*/
#define LOG_TAG "Gnss-main"
#include <android-base/logging.h>
#include <android/binder_manager.h>
#include <android/binder_process.h>
#include <hidl/HidlSupport.h>
#include <hidl/HidlTransportSupport.h>
#include <log/log.h>
#include <pthread.h>
#include "Gnss.h"
#include "GnssHidlHal.h"
using aidl::android::hardware::gnss::Gnss;
using aidl::android::hardware::gnss::GnssHidlHal;
using ::android::OK;
using ::android::sp;
using ::android::hardware::configureRpcThreadpool;
using ::android::hardware::joinRpcThreadpool;
using ::android::hardware::gnss::V2_1::IGnss;
int main() {
ABinderProcess_setThreadPoolMaxThreadCount(1);
ABinderProcess_startThreadPool();
std::shared_ptr<Gnss> gnssAidl = ndk::SharedRefBase::make<Gnss>();
const std::string instance = std::string() + Gnss::descriptor + "/default";
binder_status_t status =
AServiceManager_addService(gnssAidl->asBinder().get(), instance.c_str());
CHECK(status == STATUS_OK);
sp<IGnss> gnss = new GnssHidlHal(gnssAidl);
configureRpcThreadpool(1, true /* will join */);
if (gnss->registerAsService() != OK) {
ALOGE("Could not register gnss 2.1 service.");
return 0;
}
joinRpcThreadpool();
ABinderProcess_joinThreadPool();
return EXIT_FAILURE; // should not reach
}