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,101 @@
/*
* 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 "GnssAntennaInfo"
#include "v2_1/GnssAntennaInfo.h"
#include "Utils.h"
#include <log/log.h>
using ::android::hardware::gnss::common::Utils;
namespace android::hardware::gnss::V2_1::implementation {
sp<IGnssAntennaInfoCallback> GnssAntennaInfo::sCallback = nullptr;
GnssAntennaInfo::GnssAntennaInfo() : mMinIntervalMillis(1000) {}
GnssAntennaInfo::~GnssAntennaInfo() {
stop();
}
// Methods from ::android::hardware::gnss::V2_1::IGnssAntennaInfo follow.
Return<GnssAntennaInfo::GnssAntennaInfoStatus> GnssAntennaInfo::setCallback(
const sp<IGnssAntennaInfoCallback>& callback) {
ALOGD("setCallback");
std::unique_lock<std::mutex> lock(mMutex);
sCallback = callback;
if (mIsActive) {
ALOGW("GnssAntennaInfo callback already set. Resetting the callback...");
stop();
}
start();
return GnssAntennaInfoStatus::SUCCESS;
}
Return<void> GnssAntennaInfo::close() {
ALOGD("close");
stop();
std::unique_lock<std::mutex> lock(mMutex);
sCallback = nullptr;
return Void();
}
// Private methods
void GnssAntennaInfo::start() {
ALOGD("start");
mIsActive = true;
mThread = std::thread([this]() {
while (mIsActive == true) {
if (sCallback != nullptr) {
auto antennaInfos = Utils::getMockAntennaInfos();
this->reportAntennaInfo(antennaInfos);
}
/** For mock implementation this is good. On real device, we should only report
antennaInfo at start and when there is a configuration change. **/
std::this_thread::sleep_for(std::chrono::milliseconds(mMinIntervalMillis));
}
});
}
void GnssAntennaInfo::stop() {
ALOGD("stop");
mIsActive = false;
if (mThread.joinable()) {
mThread.join();
}
}
void GnssAntennaInfo::reportAntennaInfo(
const hidl_vec<IGnssAntennaInfoCallback::GnssAntennaInfo>& antennaInfo) const {
std::unique_lock<std::mutex> lock(mMutex);
if (sCallback == nullptr) {
ALOGE("%s: No non-null callback", __func__);
return;
}
auto ret = sCallback->gnssAntennaInfoCb(antennaInfo);
if (!ret.isOk()) {
ALOGE("%s: Unable to invoke callback", __func__);
}
}
} // namespace android::hardware::gnss::V2_1::implementation

View File

@@ -0,0 +1,101 @@
/*
* Copyright (C) 2019 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 "GnssConfiguration"
#include "v2_1/GnssConfiguration.h"
#include <log/log.h>
namespace android::hardware::gnss::V2_1::implementation {
using GnssSvInfoV2_1 = V2_1::IGnssCallback::GnssSvInfo;
using BlacklistedSourceV2_1 = V2_1::IGnssConfiguration::BlacklistedSource;
// Methods from ::android::hardware::gnss::V1_0::IGnssConfiguration follow.
Return<bool> GnssConfiguration::setSuplEs(bool enable) {
ALOGD("setSuplEs enable: %d", enable);
// Method deprecated in 2.0 and not expected to be called by the framework.
return false;
}
Return<bool> GnssConfiguration::setSuplVersion(uint32_t) {
return true;
}
Return<bool> GnssConfiguration::setSuplMode(hidl_bitfield<SuplMode>) {
return true;
}
Return<bool> GnssConfiguration::setGpsLock(hidl_bitfield<GpsLock> gpsLock) {
ALOGD("setGpsLock gpsLock: %hhu", static_cast<GpsLock>(gpsLock));
// Method deprecated in 2.0 and not expected to be called by the framework.
return false;
}
Return<bool> GnssConfiguration::setLppProfile(hidl_bitfield<LppProfile>) {
return true;
}
Return<bool> GnssConfiguration::setGlonassPositioningProtocol(hidl_bitfield<GlonassPosProtocol>) {
return true;
}
Return<bool> GnssConfiguration::setEmergencySuplPdn(bool) {
return true;
}
// Methods from ::android::hardware::gnss::V1_1::IGnssConfiguration follow.
Return<bool> GnssConfiguration::setBlacklist(
const hidl_vec<V1_1::IGnssConfiguration::BlacklistedSource>&) {
// TODO (b/122463906): Reuse 1.1 implementation.
return bool{};
}
// Methods from ::android::hardware::gnss::V2_0::IGnssConfiguration follow.
Return<bool> GnssConfiguration::setEsExtensionSec(uint32_t emergencyExtensionSeconds) {
ALOGD("setEsExtensionSec emergencyExtensionSeconds: %d", emergencyExtensionSeconds);
return true;
}
// Methods from ::android::hardware::gnss::V2_1::IGnssConfiguration follow.
Return<bool> GnssConfiguration::setBlacklist_2_1(
const hidl_vec<BlacklistedSourceV2_1>& sourceList) {
std::unique_lock<std::recursive_mutex> lock(mMutex);
mBlacklistedConstellationSet.clear();
mBlacklistedSourceSet.clear();
for (auto source : sourceList) {
if (source.svid == 0) {
// Wildcard blacklist, i.e., blacklist entire constellation.
mBlacklistedConstellationSet.insert(source.constellation);
} else {
mBlacklistedSourceSet.insert(source);
}
}
return true;
}
Return<bool> GnssConfiguration::isBlacklistedV2_1(const GnssSvInfoV2_1& gnssSvInfo) const {
std::unique_lock<std::recursive_mutex> lock(mMutex);
if (mBlacklistedConstellationSet.find(gnssSvInfo.v2_0.constellation) !=
mBlacklistedConstellationSet.end()) {
return true;
}
BlacklistedSourceV2_1 source = {.constellation = gnssSvInfo.v2_0.constellation,
.svid = gnssSvInfo.v2_0.v1_0.svid};
return (mBlacklistedSourceSet.find(source) != mBlacklistedSourceSet.end());
}
} // namespace android::hardware::gnss::V2_1::implementation

View File

@@ -0,0 +1,55 @@
/*
* 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.
*/
#define LOG_TAG "GnssDebug"
#include <log/log.h>
#include "Constants.h"
#include "MockLocation.h"
#include "v2_1/GnssDebug.h"
using namespace ::android::hardware::gnss::common;
namespace android::hardware::gnss::V1_1::implementation {
// Methods from ::android::hardware::gnss::V1_0::IGnssDebug follow.
Return<void> GnssDebug::getDebugData(V1_0::IGnssDebug::getDebugData_cb _hidl_cb) {
PositionDebug positionDebug = {
.valid = true,
.latitudeDegrees = gMockLatitudeDegrees,
.longitudeDegrees = gMockLongitudeDegrees,
.altitudeMeters = gMockAltitudeMeters,
.speedMetersPerSec = gMockSpeedMetersPerSec,
.bearingDegrees = gMockBearingDegrees,
.horizontalAccuracyMeters = kMockHorizontalAccuracyMeters,
.verticalAccuracyMeters = kMockVerticalAccuracyMeters,
.speedAccuracyMetersPerSecond = kMockSpeedAccuracyMetersPerSecond,
.bearingAccuracyDegrees = kMockBearingAccuracyDegrees,
.ageSeconds = 0.99};
TimeDebug timeDebug = {.timeEstimate = kMockTimestamp,
.timeUncertaintyNs = 1000,
.frequencyUncertaintyNsPerSec = 5.0e4};
DebugData data = {.position = positionDebug, .time = timeDebug};
_hidl_cb(data);
return Void();
}
} // namespace android::hardware::gnss::V1_1::implementation

View File

@@ -0,0 +1,143 @@
/*
* Copyright (C) 2019 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 "GnssMeasurement"
#include "v2_1/GnssMeasurement.h"
#include <log/log.h>
#include "Utils.h"
namespace android::hardware::gnss::V2_1::implementation {
using common::Utils;
sp<V2_1::IGnssMeasurementCallback> GnssMeasurement::sCallback_2_1 = nullptr;
sp<V2_0::IGnssMeasurementCallback> GnssMeasurement::sCallback_2_0 = nullptr;
GnssMeasurement::GnssMeasurement() : mMinIntervalMillis(1000) {}
GnssMeasurement::~GnssMeasurement() {
stop();
}
// Methods from V1_0::IGnssMeasurement follow.
Return<V1_0::IGnssMeasurement::GnssMeasurementStatus> GnssMeasurement::setCallback(
const sp<V1_0::IGnssMeasurementCallback>&) {
// TODO implement
return V1_0::IGnssMeasurement::GnssMeasurementStatus{};
}
Return<void> GnssMeasurement::close() {
ALOGD("close");
stop();
std::unique_lock<std::mutex> lock(mMutex);
sCallback_2_1 = nullptr;
sCallback_2_0 = nullptr;
return Void();
}
// Methods from V1_1::IGnssMeasurement follow.
Return<V1_0::IGnssMeasurement::GnssMeasurementStatus> GnssMeasurement::setCallback_1_1(
const sp<V1_1::IGnssMeasurementCallback>&, bool) {
// TODO implement
return V1_0::IGnssMeasurement::GnssMeasurementStatus{};
}
// Methods from V2_0::IGnssMeasurement follow.
Return<V1_0::IGnssMeasurement::GnssMeasurementStatus> GnssMeasurement::setCallback_2_0(
const sp<V2_0::IGnssMeasurementCallback>& callback, bool) {
ALOGD("setCallback_2_0");
std::unique_lock<std::mutex> lock(mMutex);
sCallback_2_0 = callback;
if (mIsActive) {
ALOGW("GnssMeasurement callback already set. Resetting the callback...");
stop();
}
start();
return V1_0::IGnssMeasurement::GnssMeasurementStatus::SUCCESS;
}
// Methods from V2_1::IGnssMeasurement follow.
Return<V1_0::IGnssMeasurement::GnssMeasurementStatus> GnssMeasurement::setCallback_2_1(
const sp<V2_1::IGnssMeasurementCallback>& callback, bool) {
ALOGD("setCallback_2_1");
std::unique_lock<std::mutex> lock(mMutex);
sCallback_2_1 = callback;
if (mIsActive) {
ALOGW("GnssMeasurement callback already set. Resetting the callback...");
stop();
}
start();
return V1_0::IGnssMeasurement::GnssMeasurementStatus::SUCCESS;
}
void GnssMeasurement::start() {
ALOGD("start");
mIsActive = true;
mThread = std::thread([this]() {
while (mIsActive == true) {
if (sCallback_2_1 != nullptr) {
auto measurement = Utils::getMockMeasurementV2_1();
this->reportMeasurement(measurement);
} else {
auto measurement = Utils::getMockMeasurementV2_0();
this->reportMeasurement(measurement);
}
std::this_thread::sleep_for(std::chrono::milliseconds(mMinIntervalMillis));
}
});
}
void GnssMeasurement::stop() {
ALOGD("stop");
mIsActive = false;
if (mThread.joinable()) {
mThread.join();
}
}
void GnssMeasurement::reportMeasurement(const V2_0::IGnssMeasurementCallback::GnssData& data) {
ALOGD("reportMeasurement()");
std::unique_lock<std::mutex> lock(mMutex);
if (sCallback_2_0 == nullptr) {
ALOGE("%s: GnssMeasurement::sCallback_2_0 is null.", __func__);
return;
}
auto ret = sCallback_2_0->gnssMeasurementCb_2_0(data);
if (!ret.isOk()) {
ALOGE("%s: Unable to invoke callback", __func__);
}
}
void GnssMeasurement::reportMeasurement(const V2_1::IGnssMeasurementCallback::GnssData& data) {
ALOGD("reportMeasurement()");
std::unique_lock<std::mutex> lock(mMutex);
if (sCallback_2_1 == nullptr) {
ALOGE("%s: GnssMeasurement::sCallback_2_1 is null.", __func__);
return;
}
auto ret = sCallback_2_1->gnssMeasurementCb_2_1(data);
if (!ret.isOk()) {
ALOGE("%s: Unable to invoke callback", __func__);
}
}
} // namespace android::hardware::gnss::V2_1::implementation

View File

@@ -0,0 +1,103 @@
/*
* Copyright (C) 2019 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 "GnssMeasurementCorrections"
#include "v2_1/GnssMeasurementCorrections.h"
#include <log/log.h>
namespace android::hardware::gnss::measurement_corrections::V1_1::implementation {
GnssMeasurementCorrections::GnssMeasurementCorrections() {}
GnssMeasurementCorrections::~GnssMeasurementCorrections() {}
// Methods from V1_0::IMeasurementCorrections follow.
Return<bool> GnssMeasurementCorrections::setCorrections(
const V1_0::MeasurementCorrections& corrections) {
ALOGD("setCorrections");
ALOGD("corrections = lat: %f, lng: %f, alt: %f, hUnc: %f, vUnc: %f, toa: %llu, "
"satCorrections.size: %d",
corrections.latitudeDegrees, corrections.longitudeDegrees, corrections.altitudeMeters,
corrections.horizontalPositionUncertaintyMeters,
corrections.verticalPositionUncertaintyMeters,
static_cast<unsigned long long>(corrections.toaGpsNanosecondsOfWeek),
static_cast<int>(corrections.satCorrections.size()));
for (auto singleSatCorrection : corrections.satCorrections) {
ALOGD("singleSatCorrection = flags: %d, constellation: %d, svid: %d, cfHz: %f, probLos: %f,"
" epl: %f, eplUnc: %f",
static_cast<int>(singleSatCorrection.singleSatCorrectionFlags),
static_cast<int>(singleSatCorrection.constellation),
static_cast<int>(singleSatCorrection.svid), singleSatCorrection.carrierFrequencyHz,
singleSatCorrection.probSatIsLos, singleSatCorrection.excessPathLengthMeters,
singleSatCorrection.excessPathLengthUncertaintyMeters);
ALOGD("reflecting plane = lat: %f, lng: %f, alt: %f, azm: %f",
singleSatCorrection.reflectingPlane.latitudeDegrees,
singleSatCorrection.reflectingPlane.longitudeDegrees,
singleSatCorrection.reflectingPlane.altitudeMeters,
singleSatCorrection.reflectingPlane.azimuthDegrees);
}
return true;
}
Return<bool> GnssMeasurementCorrections::setCallback(
const sp<V1_0::IMeasurementCorrectionsCallback>& callback) {
using Capabilities = V1_0::IMeasurementCorrectionsCallback::Capabilities;
auto ret =
callback->setCapabilitiesCb(Capabilities::LOS_SATS | Capabilities::EXCESS_PATH_LENGTH |
Capabilities::REFLECTING_PLANE);
if (!ret.isOk()) {
ALOGE("%s: Unable to invoke callback", __func__);
return false;
}
return true;
}
// Methods from V1_1::IMeasurementCorrections follow.
Return<bool> GnssMeasurementCorrections::setCorrections_1_1(
const V1_1::MeasurementCorrections& corrections) {
ALOGD("setCorrections_1_1");
ALOGD("corrections = lat: %f, lng: %f, alt: %f, hUnc: %f, vUnc: %f, toa: %llu,"
"satCorrections.size: %d, hasEnvironmentBearing: %d, environmentBearingDeg: %f,"
"environmentBearingUncDeg: %f",
corrections.v1_0.latitudeDegrees, corrections.v1_0.longitudeDegrees,
corrections.v1_0.altitudeMeters, corrections.v1_0.horizontalPositionUncertaintyMeters,
corrections.v1_0.verticalPositionUncertaintyMeters,
static_cast<unsigned long long>(corrections.v1_0.toaGpsNanosecondsOfWeek),
static_cast<int>(corrections.v1_0.satCorrections.size()),
corrections.hasEnvironmentBearing, corrections.environmentBearingDegrees,
corrections.environmentBearingUncertaintyDegrees);
for (auto singleSatCorrection : corrections.satCorrections) {
ALOGD("singleSatCorrection = flags: %d, constellation: %d, svid: %d, cfHz: %f, probLos: %f,"
" epl: %f, eplUnc: %f",
static_cast<int>(singleSatCorrection.v1_0.singleSatCorrectionFlags),
static_cast<int>(singleSatCorrection.constellation),
static_cast<int>(singleSatCorrection.v1_0.svid),
singleSatCorrection.v1_0.carrierFrequencyHz, singleSatCorrection.v1_0.probSatIsLos,
singleSatCorrection.v1_0.excessPathLengthMeters,
singleSatCorrection.v1_0.excessPathLengthUncertaintyMeters);
ALOGD("reflecting plane = lat: %f, lng: %f, alt: %f, azm: %f",
singleSatCorrection.v1_0.reflectingPlane.latitudeDegrees,
singleSatCorrection.v1_0.reflectingPlane.longitudeDegrees,
singleSatCorrection.v1_0.reflectingPlane.altitudeMeters,
singleSatCorrection.v1_0.reflectingPlane.azimuthDegrees);
}
return true;
}
} // namespace android::hardware::gnss::measurement_corrections::V1_1::implementation