From d9ff413bbee13412aa7a72397c8f73c08cfda1d0 Mon Sep 17 00:00:00 2001 From: bailu1992 Date: Mon, 26 Feb 2024 18:23:58 +0800 Subject: [PATCH 1/3] =?UTF-8?q?4.0release=E5=88=86=E6=94=AF=E5=91=8A?= =?UTF-8?q?=E8=AD=A6=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: bailu1992 --- interfaces/native/include/sensor_agent_type.h | 31 +++++------ interfaces/native/src/geomagnetic_field.cpp | 54 +++++++++---------- interfaces/native/src/sensor_algorithm.cpp | 31 +++++++---- .../getactivesensorinfos_fuzzer.cpp | 6 ++- .../register_fuzzer/register_fuzzer.cpp | 6 ++- .../resumesensors_fuzzer.cpp | 6 ++- .../sensoragent_fuzzer/sensoragent_fuzzer.cpp | 3 +- .../suspendsensors_fuzzer.cpp | 6 ++- .../unregister_fuzzer/unregister_fuzzer.cpp | 6 ++- services/sensor/src/client_info.cpp | 3 +- utils/common/include/sensor_utils.h | 30 +++++++++++ utils/common/src/permission_util.cpp | 4 +- 12 files changed, 123 insertions(+), 63 deletions(-) create mode 100644 utils/common/include/sensor_utils.h diff --git a/interfaces/native/include/sensor_agent_type.h b/interfaces/native/include/sensor_agent_type.h index cb8113c2..37880309 100644 --- a/interfaces/native/include/sensor_agent_type.h +++ b/interfaces/native/include/sensor_agent_type.h @@ -228,8 +228,8 @@ typedef struct AccelUncalibratedData { } AccelUncalibratedData; /** - * @brief Defines the uncalibrated gyroscope sensor data structure. Measures the uncalibrated rotational angular velocity of the - * device on three physical axes (x, y, and z) in rad/s. + * @brief Defines the uncalibrated gyroscope sensor data structure. Measures the uncalibrated rotational angular + * velocity of the device on three physical axes (x, y, and z) in rad/s. */ typedef struct GyroUncalibratedData { float x; @@ -241,17 +241,18 @@ typedef struct GyroUncalibratedData { } GyroUncalibratedData; /** - * @brief Defines the significant Motion sensor data structure. Measures whether there is substantial motion in the device on - * the three physical axes (x, y, and z); a value of 1 indicates the presence of large motion; and a value of 0 indicates that - * there is no large movement. + * @brief Defines the significant Motion sensor data structure. Measures whether there is substantial motion in the + * device on the three physical axes (x, y, and z); a value of 1 indicates the presence of large motion; and a value of + * 0 indicates that there is no large movement. */ typedef struct SignificantMotionData { float scalar; } SignificantMotionData; /** - * @brief Defines the pedometer detection sensor data structure. Detects the user's step counting action; if the value is 1, it - * means that the user has generated the action of counting walking; if the value is 0, it means that the user has not moved. + * @brief Defines the pedometer detection sensor data structure. Detects the user's step counting action; if the value + * is 1, it means that the user has generated the action of counting walking; if the value is 0, it means that the user + * has not moved. */ typedef struct PedometerDetectData { float scalar; @@ -298,8 +299,8 @@ typedef struct MagneticFieldData { } MagneticFieldData; /** - * @brief Defines the uncalibrated magnetic field sensor data structure. Measure the uncalibrated ambient geomagnetic field in three - * physical axes (x, y, z) in μT. + * @brief Defines the uncalibrated magnetic field sensor data structure. Measure the uncalibrated ambient geomagnetic + * field in three physical axes (x, y, z) in μT. */ typedef struct MagneticFieldUncalibratedData { float x; @@ -346,8 +347,8 @@ typedef struct RotationVectorData { } RotationVectorData; /** - * @brief Defines the game rotation vector sensor data structure. Measuring device game rotation vector, composite sensor: - * synthesized by acceleration sensor, gyroscope sensor. + * @brief Defines the game rotation vector sensor data structure. Measuring device game rotation vector, composite + * sensor:synthesized by acceleration sensor, gyroscope sensor. */ typedef struct GameRotationVectorData { float x; @@ -357,8 +358,8 @@ typedef struct GameRotationVectorData { } GameRotationVectorData; /** - * @brief Defines the geomagnetic rotation vector sensor data structure. Measuring device geomagnetic rotation vector, composite - * sensor: synthesized by acceleration sensor and magnetic field sensor. + * @brief Defines the geomagnetic rotation vector sensor data structure. Measuring device geomagnetic rotation vector, + * composite sensor: synthesized by acceleration sensor and magnetic field sensor. */ typedef struct GeomagneticRotaVectorData { float x; @@ -368,8 +369,8 @@ typedef struct GeomagneticRotaVectorData { } GeomagneticRotaVectorData; /** - * @brief Defines the proximity light sensor data structure. Measures the proximity or distance of visible objects relative to - * the device display, where 0 indicates proximity and 1 indicates distance. + * @brief Defines the proximity light sensor data structure. Measures the proximity or distance of visible objects + * relative to the device display, where 0 indicates proximity and 1 indicates distance. */ typedef struct ProximityData { float distance; diff --git a/interfaces/native/src/geomagnetic_field.cpp b/interfaces/native/src/geomagnetic_field.cpp index 31929718..327d003e 100644 --- a/interfaces/native/src/geomagnetic_field.cpp +++ b/interfaces/native/src/geomagnetic_field.cpp @@ -94,12 +94,12 @@ constexpr float DELTA_GAUSS_COEFFICIENT_H[13][13] = { constexpr int32_t GAUSSIAN_COEFFICIENT_DIMENSION = 13; std::mutex mutex_; -float northComponent; -float eastComponent; -float downComponent; -float geocentricLatitude; -float geocentricLongitude; -float geocentricRadius; +float g_northComponent; +float g_eastComponent; +float g_downComponent; +float g_geocentricLatitude; +float g_geocentricLongitude; +float g_geocentricRadius; std::vector> schmidtQuasiNormalFactors; std::vector> polynomials(GAUSSIAN_COEFFICIENT_DIMENSION); @@ -115,9 +115,9 @@ GeomagneticField::GeomagneticField(float latitude, float longitude, float altitu schmidtQuasiNormalFactors = GetSchmidtQuasiNormalFactors(GAUSSIAN_COEFFICIENT_DIMENSION); float gcLatitude = fmax(LATITUDE_MIN + PRECISION, fmin(LATITUDE_MAX - PRECISION, latitude)); CalibrateGeocentricCoordinates(gcLatitude, longitude, altitude); - InitLegendreTable(GAUSSIAN_COEFFICIENT_DIMENSION - 1, static_cast(M_PI / 2.0 - geocentricLatitude)); + InitLegendreTable(GAUSSIAN_COEFFICIENT_DIMENSION - 1, static_cast(M_PI / 2.0 - g_geocentricLatitude)); GetRelativeRadiusPower(); - double latDiffRad = ToRadians(gcLatitude) - geocentricLatitude; + double latDiffRad = ToRadians(gcLatitude) - g_geocentricLatitude; CalculateGeomagneticComponent(latDiffRad, timeMillis); } @@ -142,7 +142,7 @@ std::vector> GeomagneticField::GetSchmidtQuasiNormalFactors(i void GeomagneticField::CalculateGeomagneticComponent(double latDiffRad, int64_t timeMillis) { float yearsSinceBase = (timeMillis - WMM_BASE_TIME) / (365.0f * 24.0f * 60.0f * 60.0f * 1000.0f); - float inverseCosLatitude = DERIVATIVE_FACTOR / static_cast(cos(geocentricLatitude)); + float inverseCosLatitude = DERIVATIVE_FACTOR / static_cast(cos(g_geocentricLatitude)); GetLongitudeTrigonometric(); float gcX = 0.0f; float gcY = 0.0f; @@ -167,9 +167,9 @@ void GeomagneticField::CalculateGeomagneticComponent(double latDiffRad, int64_t * polynomials[row][column] * schmidtQuasiNormalFactors[row][column]; } - northComponent = static_cast(gcX * cos(latDiffRad) + gcZ * sin(latDiffRad)); - eastComponent = gcY; - downComponent = static_cast(-gcX * sin(latDiffRad) + gcZ * cos(latDiffRad)); + g_northComponent = static_cast(gcX * cos(latDiffRad) + gcZ * sin(latDiffRad)); + g_eastComponent = gcY; + g_downComponent = static_cast(-gcX * sin(latDiffRad) + gcZ * cos(latDiffRad)); } } @@ -177,8 +177,8 @@ void GeomagneticField::GetLongitudeTrigonometric() { sinMLongitude[0] = 0.0f; cosMLongitude[0] = 1.0f; - sinMLongitude[1] = static_cast(sin(geocentricLongitude)); - cosMLongitude[1] = static_cast(cos(geocentricLongitude)); + sinMLongitude[1] = static_cast(sin(g_geocentricLongitude)); + cosMLongitude[1] = static_cast(cos(g_geocentricLongitude)); for (uint32_t index = 2; index < GAUSSIAN_COEFFICIENT_DIMENSION; ++index) { uint32_t x = index >> 1; sinMLongitude[index] = (sinMLongitude[index - x] * cosMLongitude[x] @@ -191,7 +191,7 @@ void GeomagneticField::GetLongitudeTrigonometric() void GeomagneticField::GetRelativeRadiusPower() { relativeRadiusPower[0] = 1.0f; - relativeRadiusPower[1] = EARTH_REFERENCE_RADIUS / geocentricRadius; + relativeRadiusPower[1] = EARTH_REFERENCE_RADIUS / g_geocentricRadius; for (int32_t index = 2; index < static_cast(relativeRadiusPower.size()); ++index) { relativeRadiusPower[index] = relativeRadiusPower[index - 1] * relativeRadiusPower[1]; } @@ -207,13 +207,13 @@ void GeomagneticField::CalibrateGeocentricCoordinates(float latitude, float long float slat = static_cast(sin(gdLatRad)); float tlat = slat / clat; float latRad = static_cast(sqrt(a2 * clat * clat + b2 * slat * slat)); - geocentricLatitude = static_cast(atan(tlat * (latRad * altitudeKm + b2) + g_geocentricLatitude = static_cast(atan(tlat * (latRad * altitudeKm + b2) / (latRad * altitudeKm + a2))); - geocentricLongitude = static_cast(ToRadians(longitude)); + g_geocentricLongitude = static_cast(ToRadians(longitude)); float radSq = altitudeKm * altitudeKm + 2 * altitudeKm * latRad + (a2 * a2 * clat * clat + b2 * b2 * slat * slat) / (a2 * clat * clat + b2 * slat * slat); - geocentricRadius = static_cast(sqrt(radSq)); + g_geocentricRadius = static_cast(sqrt(radSq)); } void GeomagneticField::InitLegendreTable(int32_t expansionDegree, float thetaRad) @@ -252,26 +252,26 @@ void GeomagneticField::InitLegendreTable(int32_t expansionDegree, float thetaRad float GeomagneticField::ObtainX() { std::lock_guard geomagneticLock(mutex_); - return northComponent; + return g_northComponent; } float GeomagneticField::ObtainY() { std::lock_guard geomagneticLock(mutex_); - return eastComponent; + return g_eastComponent; } float GeomagneticField::ObtainZ() { std::lock_guard geomagneticLock(mutex_); - return downComponent; + return g_downComponent; } float GeomagneticField::ObtainGeomagneticDip() { std::lock_guard geomagneticLock(mutex_); - float horizontalIntensity = hypot(northComponent, eastComponent); - return static_cast(ToDegrees(atan2(downComponent, horizontalIntensity))); + float horizontalIntensity = hypot(g_northComponent, g_eastComponent); + return static_cast(ToDegrees(atan2(g_downComponent, horizontalIntensity))); } double GeomagneticField::ToDegrees(double angrad) @@ -287,21 +287,21 @@ double GeomagneticField::ToRadians(double angdeg) float GeomagneticField::ObtainDeflectionAngle() { std::lock_guard geomagneticLock(mutex_); - return static_cast(ToDegrees(atan2(eastComponent, northComponent))); + return static_cast(ToDegrees(atan2(g_eastComponent, g_northComponent))); } float GeomagneticField::ObtainLevelIntensity() { std::lock_guard geomagneticLock(mutex_); - float horizontalIntensity = hypot(northComponent, eastComponent); + float horizontalIntensity = hypot(g_northComponent, g_eastComponent); return horizontalIntensity; } float GeomagneticField::ObtainTotalIntensity() { std::lock_guard geomagneticLock(mutex_); - float sumOfSquares = northComponent * northComponent + eastComponent * eastComponent - + downComponent * downComponent; + float sumOfSquares = g_northComponent * g_northComponent + g_eastComponent * g_eastComponent + + g_downComponent * g_downComponent; float totalIntensity = static_cast(sqrt(sumOfSquares)); return totalIntensity; } diff --git a/interfaces/native/src/sensor_algorithm.cpp b/interfaces/native/src/sensor_algorithm.cpp index 9157fb0d..f6d4e6e4 100644 --- a/interfaces/native/src/sensor_algorithm.cpp +++ b/interfaces/native/src/sensor_algorithm.cpp @@ -18,6 +18,7 @@ #include #include "sensors_errors.h" +#include "sensor_utils.h" using OHOS::HiviewDFX::HiLog; using OHOS::HiviewDFX::HiLogLabel; @@ -63,7 +64,7 @@ int32_t SensorAlgorithm::TransformCoordinateSystemImpl(std::vector inRota int32_t x = (axisX & 0x3) - 1; int32_t y = (axisY & 0x3) - 1; int32_t z = (axisZ & 0x3) - 1; - if (((x ^ ((z + 1) % 3)) | ( y ^ ((z + 2) % 3))) != 0) { + if (((x ^ ((z + 1) % 3)) | (y ^ ((z + 2) % 3))) != 0) { axisZ ^= 0x80; } int32_t inRotationMatrixLength = static_cast(inRotationMatrix.size()); @@ -73,13 +74,16 @@ int32_t SensorAlgorithm::TransformCoordinateSystemImpl(std::vector inRota int32_t offset = j * matrixDimension; for (int32_t i = 0; i < 3; i++) { if (x == i) { - outRotationMatrix[offset + i] = (axisX >= 0x80) ? -inRotationMatrix[offset + 0] : inRotationMatrix[offset + 0]; + outRotationMatrix[offset + i] = (axisX >= 0x80) ? -inRotationMatrix[offset + 0] : + inRotationMatrix[offset + 0]; } if (y == i) { - outRotationMatrix[offset + i] = (axisY >= 0x80) ? -inRotationMatrix[offset + 1] : inRotationMatrix[offset + 1]; + outRotationMatrix[offset + i] = (axisY >= 0x80) ? -inRotationMatrix[offset + 1] : + inRotationMatrix[offset + 1]; } if (z == i) { - outRotationMatrix[offset + i] = (axisZ >= 0x80) ? -inRotationMatrix[offset + 2] : inRotationMatrix[offset + 2]; + outRotationMatrix[offset + i] = (axisZ >= 0x80) ? -inRotationMatrix[offset + 2] : + inRotationMatrix[offset + 2]; } } } @@ -99,14 +103,16 @@ int32_t SensorAlgorithm::TransformCoordinateSystem(std::vector inRotation return OHOS::Sensors::PARAMETER_ERROR; } int32_t inRotationMatrixLength = static_cast(inRotationMatrix.size()); - if (((inRotationMatrixLength != THREE_DIMENSIONAL_MATRIX_LENGTH) && (inRotationMatrixLength != FOUR_DIMENSIONAL_MATRIX_LENGTH)) - || (inRotationMatrixLength != static_cast(outRotationMatrix.size()))) { + if (((inRotationMatrixLength != THREE_DIMENSIONAL_MATRIX_LENGTH) && + (inRotationMatrixLength != FOUR_DIMENSIONAL_MATRIX_LENGTH)) || + (inRotationMatrixLength != static_cast(outRotationMatrix.size()))) { SEN_HILOGE("Invalid input parameter"); return OHOS::Sensors::PARAMETER_ERROR; } if (inRotationMatrix == outRotationMatrix) { std::vector tempRotationMatrix(inRotationMatrixLength); - if (TransformCoordinateSystemImpl(inRotationMatrix, axisX, axisY, tempRotationMatrix) != OHOS::Sensors::SUCCESS) { + if (TransformCoordinateSystemImpl(inRotationMatrix, axisX, axisY, tempRotationMatrix) != + OHOS::Sensors::SUCCESS) { SEN_HILOGE("TransformCoordinateSystemImpl failed"); return OHOS::Sensors::PARAMETER_ERROR; } @@ -125,6 +131,8 @@ int32_t SensorAlgorithm::GetAltitude(float seaPressure, float currentPressure, f return OHOS::Sensors::PARAMETER_ERROR; } float coef = 1.0f / RECIPROCAL_COEFFICIENT; + float rationOfStandardPressure = IsEqual(seaPressure, 0.0f) ? + std::numeric_limits::max() : currentPressure / seaPressure; float rationOfStandardPressure = currentPressure / seaPressure; float difference = pow(rationOfStandardPressure, coef); *altitude = ZERO_PRESSURE_ALTITUDE * (1.0f - difference); @@ -321,9 +329,12 @@ int32_t SensorAlgorithm::CreateRotationAndInclination(std::vector gravity rotationMatrix[0] = componentH[0]; rotationMatrix[1] = componentH[1]; rotationMatrix[2] = componentH[2]; - rotationMatrix[3 % ROTATION_VECTOR_LENGTH + (3 / ROTATION_VECTOR_LENGTH) * rotationMatrixDimension] = measuredValue[0]; - rotationMatrix[4 % ROTATION_VECTOR_LENGTH + (4 / ROTATION_VECTOR_LENGTH) * rotationMatrixDimension] = measuredValue[1]; - rotationMatrix[5 % ROTATION_VECTOR_LENGTH + (5 / ROTATION_VECTOR_LENGTH) * rotationMatrixDimension] = measuredValue[2]; + rotationMatrix[3 % ROTATION_VECTOR_LENGTH + (3 / ROTATION_VECTOR_LENGTH) * rotationMatrixDimension] = + measuredValue[0]; + rotationMatrix[4 % ROTATION_VECTOR_LENGTH + (4 / ROTATION_VECTOR_LENGTH) * rotationMatrixDimension] = + measuredValue[1]; + rotationMatrix[5 % ROTATION_VECTOR_LENGTH + (5 / ROTATION_VECTOR_LENGTH) * rotationMatrixDimension] = + measuredValue[2]; rotationMatrix[6 % ROTATION_VECTOR_LENGTH + (6 / ROTATION_VECTOR_LENGTH) * rotationMatrixDimension] = gravity[0]; rotationMatrix[7 % ROTATION_VECTOR_LENGTH + (7 / ROTATION_VECTOR_LENGTH) * rotationMatrixDimension] = gravity[1]; rotationMatrix[8 % ROTATION_VECTOR_LENGTH + (8 / ROTATION_VECTOR_LENGTH) * rotationMatrixDimension] = gravity[2]; diff --git a/interfaces/native/test/fuzztest/getactivesensorinfos_fuzzer/getactivesensorinfos_fuzzer.cpp b/interfaces/native/test/fuzztest/getactivesensorinfos_fuzzer/getactivesensorinfos_fuzzer.cpp index c2270ec9..b02b4473 100644 --- a/interfaces/native/test/fuzztest/getactivesensorinfos_fuzzer/getactivesensorinfos_fuzzer.cpp +++ b/interfaces/native/test/fuzztest/getactivesensorinfos_fuzzer/getactivesensorinfos_fuzzer.cpp @@ -41,7 +41,11 @@ void GetObject(const uint8_t *data, size_t size, T &object) if (objectSize > size) { return; } - memcpy_s(&object, objectSize, data, objectSize); + errno_t ret = memcpy_s(&object, objectSize, data, objectSize); + if (ret != EOK) { + SEN_HILOGE("Copy data failed"); + return; + } } void SetUpTestCase() diff --git a/interfaces/native/test/fuzztest/register_fuzzer/register_fuzzer.cpp b/interfaces/native/test/fuzztest/register_fuzzer/register_fuzzer.cpp index b9aad2f6..24f6ed5d 100644 --- a/interfaces/native/test/fuzztest/register_fuzzer/register_fuzzer.cpp +++ b/interfaces/native/test/fuzztest/register_fuzzer/register_fuzzer.cpp @@ -41,7 +41,11 @@ void GetObject(const uint8_t *data, size_t size, T &object) if (objectSize > size) { return; } - memcpy_s(&object, objectSize, data, objectSize); + errno_t ret = memcpy_s(&object, objectSize, data, objectSize); + if (ret != EOK) { + SEN_HILOGE("Copy data failed"); + return; + } } void SetUpTestCase() diff --git a/interfaces/native/test/fuzztest/resumesensors_fuzzer/resumesensors_fuzzer.cpp b/interfaces/native/test/fuzztest/resumesensors_fuzzer/resumesensors_fuzzer.cpp index 8d701c30..5d0dfc4d 100644 --- a/interfaces/native/test/fuzztest/resumesensors_fuzzer/resumesensors_fuzzer.cpp +++ b/interfaces/native/test/fuzztest/resumesensors_fuzzer/resumesensors_fuzzer.cpp @@ -40,7 +40,11 @@ void GetObject(const uint8_t *data, size_t size, T &object) if (objectSize > size) { return; } - memcpy_s(&object, objectSize, data, objectSize); + errno_t ret = memcpy_s(&object, objectSize, data, objectSize); + if (ret != EOK) { + SEN_HILOGE("Copy data failed"); + return; + } } void SetUpTestCase() diff --git a/interfaces/native/test/fuzztest/sensoragent_fuzzer/sensoragent_fuzzer.cpp b/interfaces/native/test/fuzztest/sensoragent_fuzzer/sensoragent_fuzzer.cpp index d780c28d..b45630a0 100644 --- a/interfaces/native/test/fuzztest/sensoragent_fuzzer/sensoragent_fuzzer.cpp +++ b/interfaces/native/test/fuzztest/sensoragent_fuzzer/sensoragent_fuzzer.cpp @@ -34,8 +34,7 @@ bool CheckSensorTypeId(int32_t sensorTypeId) if (ret != 0) { return false; } - for (int32_t i = 0; i < count; i++) - { + for (int32_t i = 0; i < count; i++) { if ((sensorInfo + i)->sensorTypeId == sensorTypeId) { return true; } diff --git a/interfaces/native/test/fuzztest/suspendsensors_fuzzer/suspendsensors_fuzzer.cpp b/interfaces/native/test/fuzztest/suspendsensors_fuzzer/suspendsensors_fuzzer.cpp index f5fc0fea..ae806283 100644 --- a/interfaces/native/test/fuzztest/suspendsensors_fuzzer/suspendsensors_fuzzer.cpp +++ b/interfaces/native/test/fuzztest/suspendsensors_fuzzer/suspendsensors_fuzzer.cpp @@ -40,7 +40,11 @@ void GetObject(const uint8_t *data, size_t size, T &object) if (objectSize > size) { return; } - memcpy_s(&object, objectSize, data, objectSize); + errno_t ret = memcpy_s(&object, objectSize, data, objectSize); + if (ret != EOK) { + SEN_HILOGE("Copy data failed"); + return; + } } void SetUpTestCase() diff --git a/interfaces/native/test/fuzztest/unregister_fuzzer/unregister_fuzzer.cpp b/interfaces/native/test/fuzztest/unregister_fuzzer/unregister_fuzzer.cpp index 073db20f..18e4aa3c 100644 --- a/interfaces/native/test/fuzztest/unregister_fuzzer/unregister_fuzzer.cpp +++ b/interfaces/native/test/fuzztest/unregister_fuzzer/unregister_fuzzer.cpp @@ -41,7 +41,11 @@ void GetObject(const uint8_t *data, size_t size, T &object) if (objectSize > size) { return; } - memcpy_s(&object, objectSize, data, objectSize); + errno_t ret = memcpy_s(&object, objectSize, data, objectSize); + if (ret != EOK) { + SEN_HILOGE("Copy data failed"); + return; + } } void SetUpTestCase() diff --git a/services/sensor/src/client_info.cpp b/services/sensor/src/client_info.cpp index d0c84f5f..f6dc55b9 100644 --- a/services/sensor/src/client_info.cpp +++ b/services/sensor/src/client_info.cpp @@ -751,8 +751,7 @@ int32_t ClientInfo::GetPidByTokenId(AccessTokenID tokenId) { std::lock_guard uidLock(uidMutex_); int32_t pid = INVALID_PID; - auto iter = std::find_if(appThreadInfoMap_.begin(), appThreadInfoMap_.end(), - [tokenId] (auto appThreadInfo) { + auto iter = std::find_if(appThreadInfoMap_.begin(), appThreadInfoMap_.end(), [tokenId] (auto appThreadInfo) { return appThreadInfo.second.callerToken == tokenId; } ); diff --git a/utils/common/include/sensor_utils.h b/utils/common/include/sensor_utils.h new file mode 100644 index 00000000..899bb0ea --- /dev/null +++ b/utils/common/include/sensor_utils.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * 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 SENSOR_UTILS_H +#define SENSOR_UTILS_H + +namespace OHOS { +namespace Sensors { + +template +bool IsEqual(const T &left, const T &right) +{ + return std::abs(left - right) <= std::numeric_limits::epsilon(); +} + +} // namespace Sensors +} // namespace OHOS +#endif // SENSOR_UTILS_H \ No newline at end of file diff --git a/utils/common/src/permission_util.cpp b/utils/common/src/permission_util.cpp index 2e3192d7..3ab56115 100644 --- a/utils/common/src/permission_util.cpp +++ b/utils/common/src/permission_util.cpp @@ -59,8 +59,8 @@ void PermissionUtil::AddPermissionRecord(AccessTokenID tokenID, const std::strin int32_t failCount = status ? 0 : 1; int32_t ret = PrivacyKit::AddPermissionUsedRecord(tokenID, permissionName, successCount, failCount); if (ret != 0) { - SEN_HILOGE("AddPermissionUsedRecord fail, permissionName:%{public}s, successCount:%{public}d, failCount:%{public}d", - permissionName.c_str(), successCount, failCount); + SEN_HILOGE("AddPermissionUsedRecord fail, permissionName:%{public}s, successCount:%{public}d,\ + failCount:%{public}d", permissionName.c_str(), successCount, failCount); } } -- Gitee From 55083ab4b618572a191eebbe9b5e9c5af1e56400 Mon Sep 17 00:00:00 2001 From: bailu1992 Date: Mon, 26 Feb 2024 19:19:26 +0800 Subject: [PATCH 2/3] =?UTF-8?q?4.0release=E5=88=86=E6=94=AF=E5=91=8A?= =?UTF-8?q?=E8=AD=A6=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: bailu1992 --- interfaces/native/src/sensor_algorithm.cpp | 2 +- services/sensor/src/client_info.cpp | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/interfaces/native/src/sensor_algorithm.cpp b/interfaces/native/src/sensor_algorithm.cpp index f6d4e6e4..fad5acc1 100644 --- a/interfaces/native/src/sensor_algorithm.cpp +++ b/interfaces/native/src/sensor_algorithm.cpp @@ -131,7 +131,7 @@ int32_t SensorAlgorithm::GetAltitude(float seaPressure, float currentPressure, f return OHOS::Sensors::PARAMETER_ERROR; } float coef = 1.0f / RECIPROCAL_COEFFICIENT; - float rationOfStandardPressure = IsEqual(seaPressure, 0.0f) ? + float rationOfStandardPressure = OHOS::Sensors::IsEqual(seaPressure, 0.0f) ? std::numeric_limits::max() : currentPressure / seaPressure; float rationOfStandardPressure = currentPressure / seaPressure; float difference = pow(rationOfStandardPressure, coef); diff --git a/services/sensor/src/client_info.cpp b/services/sensor/src/client_info.cpp index f6dc55b9..6a85eb5d 100644 --- a/services/sensor/src/client_info.cpp +++ b/services/sensor/src/client_info.cpp @@ -753,8 +753,7 @@ int32_t ClientInfo::GetPidByTokenId(AccessTokenID tokenId) int32_t pid = INVALID_PID; auto iter = std::find_if(appThreadInfoMap_.begin(), appThreadInfoMap_.end(), [tokenId] (auto appThreadInfo) { return appThreadInfo.second.callerToken == tokenId; - } - ); + }); if (iter != appThreadInfoMap_.end()) { pid = iter->second.pid; } -- Gitee From 4c9ebfd105a3d35d2e031ce319cc469f9bb78d8d Mon Sep 17 00:00:00 2001 From: bailu1992 Date: Mon, 26 Feb 2024 19:32:11 +0800 Subject: [PATCH 3/3] =?UTF-8?q?4.0release=E5=88=86=E6=94=AF=E5=91=8A?= =?UTF-8?q?=E8=AD=A6=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: bailu1992 --- interfaces/native/src/sensor_algorithm.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/interfaces/native/src/sensor_algorithm.cpp b/interfaces/native/src/sensor_algorithm.cpp index fad5acc1..82154bae 100644 --- a/interfaces/native/src/sensor_algorithm.cpp +++ b/interfaces/native/src/sensor_algorithm.cpp @@ -133,7 +133,6 @@ int32_t SensorAlgorithm::GetAltitude(float seaPressure, float currentPressure, f float coef = 1.0f / RECIPROCAL_COEFFICIENT; float rationOfStandardPressure = OHOS::Sensors::IsEqual(seaPressure, 0.0f) ? std::numeric_limits::max() : currentPressure / seaPressure; - float rationOfStandardPressure = currentPressure / seaPressure; float difference = pow(rationOfStandardPressure, coef); *altitude = ZERO_PRESSURE_ALTITUDE * (1.0f - difference); return OHOS::Sensors::SUCCESS; -- Gitee