From 44250620413d9361004a55ab16e3bbcd094a4162 Mon Sep 17 00:00:00 2001 From: cff-gite Date: Mon, 21 Mar 2022 16:30:10 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E4=BF=AE=E6=94=B9sensor=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cff-gite --- interfaces/plugin/include/sensor_napi_utils.h | 2 +- interfaces/plugin/src/sensor_js.cpp | 4 +- interfaces/plugin/src/sensor_napi_utils.cpp | 2 +- .../adapter/include/hdi_connection.h | 2 +- .../adapter/src/hdi_connection.cpp | 6 +-- services/sensor/include/client_info.h | 6 +-- services/sensor/include/sensor_service.h | 2 +- services/sensor/src/client_info.cpp | 39 +++++++++---------- services/sensor/src/sensor_data_processer.cpp | 2 +- services/sensor/src/sensor_dump.cpp | 4 +- services/sensor/src/sensor_manager.cpp | 9 ++--- services/sensor/src/sensor_service.cpp | 10 ++--- utils/include/sensor_basic_data_channel.h | 2 +- utils/include/sensor_basic_info.h | 16 ++++---- utils/src/sensor_basic_data_channel.cpp | 6 +-- utils/src/sensor_basic_info.cpp | 6 +-- 16 files changed, 57 insertions(+), 61 deletions(-) diff --git a/interfaces/plugin/include/sensor_napi_utils.h b/interfaces/plugin/include/sensor_napi_utils.h index 24141c14..12d0385b 100644 --- a/interfaces/plugin/include/sensor_napi_utils.h +++ b/interfaces/plugin/include/sensor_napi_utils.h @@ -102,7 +102,7 @@ struct AsyncCallbackInfo { using ConvertDataFunc = void(*)(napi_env env, AsyncCallbackInfo *asyncCallbackInfo, napi_value result[2]); -bool IsNapiValueSame(napi_env env, napi_value lhs, napi_value rhs); +bool IsSameValue(napi_env env, napi_value lhs, napi_value rhs); bool IsMatchType(napi_env env, napi_value value, napi_valuetype type); diff --git a/interfaces/plugin/src/sensor_js.cpp b/interfaces/plugin/src/sensor_js.cpp index 74072a2c..52ccc3af 100644 --- a/interfaces/plugin/src/sensor_js.cpp +++ b/interfaces/plugin/src/sensor_js.cpp @@ -178,7 +178,7 @@ static bool IsSubscribed(napi_env env, int32_t sensorTypeId, napi_value callback for (auto callbackInfo : callbackInfos) { napi_value sensorCallback = nullptr; napi_get_reference_value(env, callbackInfo->callback[0], &sensorCallback); - if (IsNapiValueSame(env, callback, sensorCallback)) { + if (IsSameValue(env, callback, sensorCallback)) { return true; } } @@ -261,7 +261,7 @@ static uint32_t RemoveCallback(napi_env env, int32_t sensorTypeId, napi_value ca } napi_value sensorCallback = nullptr; napi_get_reference_value(env, (*iter)->callback[0], &sensorCallback); - if (IsNapiValueSame(env, callback, sensorCallback)) { + if (IsSameValue(env, callback, sensorCallback)) { napi_delete_reference(env, (*iter)->callback[0]); (*iter)->callback[0] = nullptr; delete *iter; diff --git a/interfaces/plugin/src/sensor_napi_utils.cpp b/interfaces/plugin/src/sensor_napi_utils.cpp index 40fb2846..752a498a 100644 --- a/interfaces/plugin/src/sensor_napi_utils.cpp +++ b/interfaces/plugin/src/sensor_napi_utils.cpp @@ -25,7 +25,7 @@ using namespace OHOS::HiviewDFX; static constexpr HiLogLabel LABEL = {LOG_CORE, 0xD002708, "SensorJsAPI"}; -bool IsNapiValueSame(napi_env env, napi_value lhs, napi_value rhs) +bool IsSameValue(napi_env env, napi_value lhs, napi_value rhs) { bool result = false; napi_strict_equals(env, lhs, rhs, &result); diff --git a/services/sensor/hdi_connection/adapter/include/hdi_connection.h b/services/sensor/hdi_connection/adapter/include/hdi_connection.h index b5f26cb5..72305705 100644 --- a/services/sensor/hdi_connection/adapter/include/hdi_connection.h +++ b/services/sensor/hdi_connection/adapter/include/hdi_connection.h @@ -62,7 +62,7 @@ private: void UnregisterHdiDeathRecipient(); void reconnect(); void updateSensorBasicInfo(int32_t sensorId, int64_t samplingPeriodNs, int64_t maxReportDelayNs); - void setSensorBasicInfoState(int32_t sensorId, SensorState state); + void setSensorBasicInfoState(int32_t sensorId, bool state); void deleteSensorBasicInfoState(int32_t sensorId); }; } // namespace Sensors diff --git a/services/sensor/hdi_connection/adapter/src/hdi_connection.cpp b/services/sensor/hdi_connection/adapter/src/hdi_connection.cpp index 978d5a5e..376b488e 100644 --- a/services/sensor/hdi_connection/adapter/src/hdi_connection.cpp +++ b/services/sensor/hdi_connection/adapter/src/hdi_connection.cpp @@ -113,7 +113,7 @@ int32_t HdiConnection::EnableSensor(int32_t sensorId) HiLog::Error(LABEL, "%{public}s is failed", __func__); return ret; } - setSensorBasicInfoState(sensorId, SENSOR_ENABLED); + setSensorBasicInfoState(sensorId, true); return ERR_OK; } @@ -249,7 +249,7 @@ void HdiConnection::updateSensorBasicInfo(int32_t sensorId, int64_t samplingPeri sensorBasicInfoMap_[sensorId] = sensorBasicInfo; } -void HdiConnection::setSensorBasicInfoState(int32_t sensorId, SensorState state) +void HdiConnection::setSensorBasicInfoState(int32_t sensorId, bool state) { std::lock_guard sensorInfoLock(sensorBasicInfoMutex_); auto it = sensorBasicInfoMap_.find(sensorId); @@ -334,7 +334,7 @@ void HdiConnection::reconnect() int32_t sensorTypeId = sensorInfo.first; ret = SetBatch(sensorTypeId, sensorInfo.second.GetSamplingPeriodNs(), sensorInfo.second.GetMaxReportDelayNs()); - if (ret < 0 || sensorInfo.second.GetSensorState() != SENSOR_ENABLED) { + if (ret < 0 || sensorInfo.second.GetSensorState() != true) { HiLog::Error(LABEL, "%{public}s sensorTypeId: %{public}d set batch fail or not need enable sensor", __func__, sensorTypeId); continue; diff --git a/services/sensor/include/client_info.h b/services/sensor/include/client_info.h index 61fee175..bc5369ed 100644 --- a/services/sensor/include/client_info.h +++ b/services/sensor/include/client_info.h @@ -52,7 +52,7 @@ public: void RemoveSubscriber(uint32_t sensorId, uint32_t pid); bool UpdateSensorChannel(int32_t pid, const sptr &channel); bool UpdateAppThreadInfo(int32_t pid, int32_t uid, AccessTokenID callerToken); - bool ClearSensorInfo(uint32_t sensorId); + void ClearSensorInfo(uint32_t sensorId); void ClearCurPidSensorInfo(uint32_t sensorId, int32_t pid); bool DestroySensorChannel(int32_t pid); void DestroyAppThreadInfo(int32_t pid); @@ -71,7 +71,7 @@ public: void UpdateCmd(uint32_t sensorId, int32_t uid, int32_t cmdType); void DestroyCmd(int32_t uid); void UpdateDataQueue(int32_t sensorId, struct SensorEvent &event); - std::unordered_map> GetDataQueue(); + std::unordered_map> GetDumpQueue(); void ClearDataQueue(int32_t sensorId); private: @@ -91,7 +91,7 @@ private: std::unordered_map appThreadInfoMap_; std::map, int32_t> clientPidMap_; std::unordered_map>> cmdMap_; - std::unordered_map> dataQueue_; + std::unordered_map> dumpQueue_; }; } // namespace Sensors } // namespace OHOS diff --git a/services/sensor/include/sensor_service.h b/services/sensor/include/sensor_service.h index 95b0f40a..6f46b2af 100644 --- a/services/sensor/include/sensor_service.h +++ b/services/sensor/include/sensor_service.h @@ -79,7 +79,7 @@ private: bool InitSensorList(); bool InitSensorPolicy(); void ReportOnChangeData(uint32_t sensorId); - void ReportSensorUsedInfo(uint32_t sensorId, bool enable); + void ReportSensorSysEvent(uint32_t sensorId, bool enable); SensorServiceState state_; std::mutex serviceLock_; std::mutex sensorsMutex_; diff --git a/services/sensor/src/client_info.cpp b/services/sensor/src/client_info.cpp index c39ee3e0..5517ae87 100644 --- a/services/sensor/src/client_info.cpp +++ b/services/sensor/src/client_info.cpp @@ -40,27 +40,27 @@ constexpr uint32_t MAX_DUMP_DATA_SIZE = 10; constexpr uint32_t HEART_RATE_SENSOR_ID = 83886336; } // namespace -SensorState ClientInfo::GetSensorState(uint32_t sensorId) +bool ClientInfo::GetSensorState(uint32_t sensorId) { HiLog::Debug(LABEL, "%{public}s begin, sensorId : %{public}u", __func__, sensorId); if (sensorId == INVALID_SENSOR_ID) { HiLog::Error(LABEL, "%{public}s sensorId is invalid", __func__); - return SENSOR_DISABLED; + return false; } std::lock_guard clientLock(clientMutex_); auto it = clientMap_.find(sensorId); if (it == clientMap_.end()) { HiLog::Error(LABEL, "%{public}s cannot find sensorId : %{public}u", __func__, sensorId); - return SENSOR_DISABLED; + return false; } for (const auto &pidIt : it->second) { - if (pidIt.second.GetSensorState() == SENSOR_ENABLED) { - return SENSOR_ENABLED; + if (pidIt.second.GetSensorState() == true) { + return false; } } HiLog::Error(LABEL, "%{public}s cannot find sensorinfo, sensorId : %{public}u", __func__, sensorId); - return SENSOR_DISABLED; + return false; } SensorBasicInfo ClientInfo::GetBestSensorInfo(uint32_t sensorId) @@ -110,7 +110,7 @@ bool ClientInfo::OnlyCurPidSensorEnabled(uint32_t sensorId, int32_t pid) } bool ret = false; for (const auto &pidIt : it->second) { - if (pidIt.second.GetSensorState() != SENSOR_ENABLED) { + if (pidIt.second.GetSensorState() != true) { continue; } if (pidIt.first != pid) { @@ -230,7 +230,7 @@ std::vector> ClientInfo::GetSensorChannel(uint32_t bool ClientInfo::UpdateSensorInfo(uint32_t sensorId, int32_t pid, const SensorBasicInfo &sensorInfo) { HiLog::Debug(LABEL, "%{public}s begin, sensorId : %{public}u, pid : %{public}d", __func__, sensorId, pid); - if ((sensorId == INVALID_SENSOR_ID) || (pid <= INVALID_PID) || (sensorInfo.GetSensorState() != SENSOR_ENABLED)) { + if ((sensorId == INVALID_SENSOR_ID) || (pid <= INVALID_PID) || (sensorInfo.GetSensorState() != true)) { HiLog::Error(LABEL, "%{public}s params are invalid", __func__); return false; } @@ -288,21 +288,20 @@ bool ClientInfo::UpdateSensorChannel(int32_t pid, const sptr clientLock(clientMutex_); auto it = clientMap_.find(sensorId); if (it == clientMap_.end()) { HiLog::Debug(LABEL, "%{public}s sensorId not exist, no need to clear it", __func__); - return true; + return; } clientMap_.erase(it); - return true; } void ClientInfo::ClearCurPidSensorInfo(uint32_t sensorId, int32_t pid) @@ -676,11 +675,11 @@ void ClientInfo::UpdateDataQueue(int32_t sensorId, struct SensorEvent &event) return; } std::lock_guard queueLock(dataQueueMutex_); - auto it = dataQueue_.find(sensorId); - if (it == dataQueue_.end()) { + auto it = dumpQueue_.find(sensorId); + if (it == dumpQueue_.end()) { std::queue q; q.push(event); - dataQueue_.insert(std::make_pair(sensorId, q)); + dumpQueue_.insert(std::make_pair(sensorId, q)); return; } it->second.push(event); @@ -689,17 +688,17 @@ void ClientInfo::UpdateDataQueue(int32_t sensorId, struct SensorEvent &event) } } -std::unordered_map> ClientInfo::GetDataQueue() +std::unordered_map> ClientInfo::GetDumpQueue() { - return dataQueue_; + return dumpQueue_; } void ClientInfo::ClearDataQueue(int32_t sensorId) { std::lock_guard queueLock(dataQueueMutex_); - auto it = dataQueue_.find(sensorId); - if (it != dataQueue_.end()) { - dataQueue_.erase(it); + auto it = dumpQueue_.find(sensorId); + if (it != dumpQueue_.end()) { + dumpQueue_.erase(it); } } } // namespace Sensors diff --git a/services/sensor/src/sensor_data_processer.cpp b/services/sensor/src/sensor_data_processer.cpp index c5cb6646..cc1d7788 100644 --- a/services/sensor/src/sensor_data_processer.cpp +++ b/services/sensor/src/sensor_data_processer.cpp @@ -185,7 +185,7 @@ void SensorDataProcesser::ReportData(sptr &channel, stru if (ReportNotContinuousData(cacheBuf, channel, event)) { return; } - uint64_t periodCount = clientInfo_.ComputeBestPeriodCount(sensorId, channel); + int32_t periodCount = clientInfo_.ComputeBestPeriodCount(sensorId, channel); if (periodCount == 0UL) { return; } diff --git a/services/sensor/src/sensor_dump.cpp b/services/sensor/src/sensor_dump.cpp index 6ef5503a..e7f3c92c 100644 --- a/services/sensor/src/sensor_dump.cpp +++ b/services/sensor/src/sensor_dump.cpp @@ -189,7 +189,7 @@ bool SensorDump::DumpOpeningSensor(int32_t fd, const std::vector &sensor dprintf(fd, "Opening sensors:\n"); for (const auto &sensor : sensors) { uint32_t sensorId = sensor.GetSensorId(); - if (clientInfo.GetSensorState(sensorId) == SENSOR_ENABLED) { + if (clientInfo.GetSensorState(sensorId) == true) { dprintf(fd, "sensorId: %8u | sensorType: %s\n", sensorId, sensorMap_[sensorId].c_str()); } } @@ -203,7 +203,7 @@ bool SensorDump::DumpSensorData(int32_t fd, ClientInfo &clientInfo, const std::v return false; } dprintf(fd, "Last 10 packages sensor data:\n"); - auto dataMap = clientInfo.GetDataQueue(); + auto dataMap = clientInfo.GetDumpQueue(); int32_t j = 0; for (auto &sensorData : dataMap) { uint32_t sensorId = sensorData.first; diff --git a/services/sensor/src/sensor_manager.cpp b/services/sensor/src/sensor_manager.cpp index 1476c1af..dcd83f89 100644 --- a/services/sensor/src/sensor_manager.cpp +++ b/services/sensor/src/sensor_manager.cpp @@ -105,7 +105,7 @@ SensorBasicInfo SensorManager::GetSensorInfo(uint32_t sensorId, int64_t sampling if (it == sensorMap_.end()) { sensorInfo.SetSamplingPeriodNs(samplingPeriodNs); sensorInfo.SetMaxReportDelayNs(maxReportDelayNs); - sensorInfo.SetSensorState(SENSOR_ENABLED); + sensorInfo.SetSensorState(true); HiLog::Error(LABEL, "%{public}s sensorId invalid", __func__); return sensorInfo; } @@ -124,7 +124,7 @@ SensorBasicInfo SensorManager::GetSensorInfo(uint32_t sensorId, int64_t sampling int64_t curReportDelayNs = (maxReportDelayNs > supportDelay) ? supportDelay : maxReportDelayNs; sensorInfo.SetSamplingPeriodNs(curSamplingPeriodNs); sensorInfo.SetMaxReportDelayNs(curReportDelayNs); - sensorInfo.SetSensorState(SENSOR_ENABLED); + sensorInfo.SetSensorState(true); HiLog::Debug(LABEL, "%{public}s end", __func__); return sensorInfo; } @@ -170,10 +170,7 @@ bool SensorManager::IsOtherClientUsingSensor(uint32_t sensorId, int32_t clientPi ErrCode SensorManager::AfterDisableSensor(uint32_t sensorId) { HiLog::Debug(LABEL, "%{public}s begin", __func__); - if (!clientInfo_.ClearSensorInfo(sensorId)) { - HiLog::Error(LABEL, "%{public}s ClearSensorInfo failed", __func__); - return CLEAR_SENSOR_INFO_ERR; - } + clientInfo_.ClearSensorInfo(sensorId); if (sensorId == PROXIMITY_SENSOR_ID) { struct SensorEvent event; auto ret = clientInfo_.GetStoreEvent(sensorId, event); diff --git a/services/sensor/src/sensor_service.cpp b/services/sensor/src/sensor_service.cpp index 0072026f..bc0a2f84 100644 --- a/services/sensor/src/sensor_service.cpp +++ b/services/sensor/src/sensor_service.cpp @@ -156,7 +156,7 @@ void SensorService::OnStop() } } -void SensorService::ReportSensorUsedInfo(uint32_t sensorId, bool enable) +void SensorService::ReportSensorSysEvent(uint32_t sensorId, bool enable) { char uidChar[REPORT_STATUS_LEN] = {0}; int32_t uid = this->GetCallingUid(); @@ -243,9 +243,9 @@ ErrCode SensorService::EnableSensor(uint32_t sensorId, int64_t samplingPeriodNs, HiLog::Error(LABEL, "%{public}s sensorId is 0 or maxReportDelayNs exceeded the maximum value", __func__); return ERR_NO_INIT; } - ReportSensorUsedInfo(sensorId, SENSOR_ENABLED); + ReportSensorSysEvent(sensorId, true); std::lock_guard serviceLock(serviceLock_); - if (clientInfo_.GetSensorState(sensorId) == SENSOR_ENABLED) { + if (clientInfo_.GetSensorState(sensorId) == true) { HiLog::Warn(LABEL, "%{public}s sensor has been enabled already", __func__); auto ret = SaveSubscriber(sensorId, samplingPeriodNs, maxReportDelayNs); if (ret != ERR_OK) { @@ -285,14 +285,14 @@ ErrCode SensorService::DisableSensor(uint32_t sensorId) HiLog::Error(LABEL, "%{public}s sensorId is invalid", __func__); return ERR_NO_INIT; } - ReportSensorUsedInfo(sensorId, SENSOR_DISABLED); + ReportSensorSysEvent(sensorId, false); std::lock_guard serviceLock(serviceLock_); const int32_t clientPid = this->GetCallingPid(); if (clientPid < 0) { HiLog::Error(LABEL, "%{public}s clientPid is invalid, clientPid : %{public}d", __func__, clientPid); return CLIENT_PID_INVALID_ERR; } - if (clientInfo_.GetSensorState(sensorId) != SENSOR_ENABLED) { + if (clientInfo_.GetSensorState(sensorId) != true) { HiLog::Error(LABEL, "%{public}s sensor should be enabled first", __func__); return DISABLE_SENSOR_ERR; } diff --git a/utils/include/sensor_basic_data_channel.h b/utils/include/sensor_basic_data_channel.h index 1ce789b0..9b421705 100644 --- a/utils/include/sensor_basic_data_channel.h +++ b/utils/include/sensor_basic_data_channel.h @@ -41,7 +41,7 @@ class SensorBasicDataChannel : public RefBase { public: SensorBasicDataChannel(); virtual ~SensorBasicDataChannel(); - int32_t CreateSensorBasicChannel(size_t sendSize, size_t receiveSize); + int32_t CreateSensorBasicChannel(); int32_t CreateSensorBasicChannel(MessageParcel &data); int32_t DestroySensorBasicChannel(); int32_t GetSendDataFd() const; diff --git a/utils/include/sensor_basic_info.h b/utils/include/sensor_basic_info.h index aaaa29f9..60daeea6 100755 --- a/utils/include/sensor_basic_info.h +++ b/utils/include/sensor_basic_info.h @@ -20,11 +20,11 @@ namespace OHOS { namespace Sensors { -enum SensorState { - SENSOR_DISABLED = 0, - SENSOR_ENABLED = 1, - SENSOR_UNKNOWN_STATE = 2, -}; +// enum SensorState { +// SENSOR_DISABLED = 0, +// SENSOR_ENABLED = 1, +// SENSOR_UNKNOWN_STATE = 2, +// }; class SensorBasicInfo { public: @@ -34,13 +34,13 @@ public: void SetSamplingPeriodNs(int64_t samplingPeriodNs); int64_t GetMaxReportDelayNs() const; void SetMaxReportDelayNs(int64_t maxReportDelayNs); - SensorState GetSensorState() const; - void SetSensorState(SensorState sensorState); + bool GetSensorState() const; + void SetSensorState(bool sensorState); private: int64_t samplingPeriodNs_; int64_t maxReportDelayNs_; - SensorState sensorState_; + bool sensorState_; }; } // namespace Sensors } // namespace OHOS diff --git a/utils/src/sensor_basic_data_channel.cpp b/utils/src/sensor_basic_data_channel.cpp index 3ae2fc33..b11b8ef4 100755 --- a/utils/src/sensor_basic_data_channel.cpp +++ b/utils/src/sensor_basic_data_channel.cpp @@ -38,7 +38,7 @@ SensorBasicDataChannel::SensorBasicDataChannel() : sendFd_(INVALID_FD), receiveF HiLog::Debug(LABEL, "%{public}s isActive_ : %{public}d, sendFd: %{public}d", __func__, isActive_, sendFd_); } -int32_t SensorBasicDataChannel::CreateSensorBasicChannel(size_t sendSize, size_t receiveSize) +int32_t SensorBasicDataChannel::CreateSensorBasicChannel() { if ((sendFd_ != INVALID_FD) || (receiveFd_ != INVALID_FD)) { HiLog::Debug(LABEL, "%{public}s already create socketpair", __func__); @@ -55,8 +55,8 @@ int32_t SensorBasicDataChannel::CreateSensorBasicChannel(size_t sendSize, size_t return SENSOR_CHANNEL_SOCKET_CREATE_ERR; } // set socket attr - setsockopt(socketPair[0], SOL_SOCKET, SO_SNDBUF, &sendSize, sizeof(sendSize)); - setsockopt(socketPair[1], SOL_SOCKET, SO_RCVBUF, &receiveSize, sizeof(receiveSize)); + setsockopt(socketPair[0], SOL_SOCKET, SO_SNDBUF, &DEFAULT_CHANNEL_SIZE, sizeof(DEFAULT_CHANNEL_SIZE)); + setsockopt(socketPair[1], SOL_SOCKET, SO_RCVBUF, &DEFAULT_CHANNEL_SIZE, sizeof(DEFAULT_CHANNEL_SIZE)); int32_t bufferSize = DEFAULT_CHANNEL_SIZE; int32_t ret = setsockopt(socketPair[0], SOL_SOCKET, SO_RCVBUF, &bufferSize, sizeof(bufferSize)); if (ret != 0) { diff --git a/utils/src/sensor_basic_info.cpp b/utils/src/sensor_basic_info.cpp index 959806cc..98f7883b 100755 --- a/utils/src/sensor_basic_info.cpp +++ b/utils/src/sensor_basic_info.cpp @@ -17,7 +17,7 @@ namespace OHOS { namespace Sensors { -SensorBasicInfo::SensorBasicInfo() : samplingPeriodNs_(0L), maxReportDelayNs_(0L), sensorState_(SENSOR_DISABLED) +SensorBasicInfo::SensorBasicInfo() : samplingPeriodNs_(0L), maxReportDelayNs_(0L), sensorState_(false) {} int64_t SensorBasicInfo::GetSamplingPeriodNs() const @@ -40,12 +40,12 @@ void SensorBasicInfo::SetMaxReportDelayNs(int64_t maxReportDelayNs) maxReportDelayNs_ = maxReportDelayNs; } -SensorState SensorBasicInfo::GetSensorState() const +bool SensorBasicInfo::GetSensorState() const { return sensorState_; } -void SensorBasicInfo::SetSensorState(SensorState sensorState) +void SensorBasicInfo::SetSensorState(bool sensorState) { sensorState_ = sensorState; } -- Gitee From 363f4487e518a04f10f7965f71f1988df126f6f4 Mon Sep 17 00:00:00 2001 From: cff-gite Date: Mon, 21 Mar 2022 16:35:28 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=E4=BF=AE=E6=94=B9sensor=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cff-gite --- utils/include/sensor_basic_info.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/utils/include/sensor_basic_info.h b/utils/include/sensor_basic_info.h index 60daeea6..6e7bcfab 100755 --- a/utils/include/sensor_basic_info.h +++ b/utils/include/sensor_basic_info.h @@ -20,11 +20,6 @@ namespace OHOS { namespace Sensors { -// enum SensorState { -// SENSOR_DISABLED = 0, -// SENSOR_ENABLED = 1, -// SENSOR_UNKNOWN_STATE = 2, -// }; class SensorBasicInfo { public: -- Gitee From e6e74d122faf64715a7319e7e3566e2afad493e0 Mon Sep 17 00:00:00 2001 From: cff-gite Date: Mon, 21 Mar 2022 17:02:14 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E4=BF=AE=E6=94=B9sensor=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cff-gite --- frameworks/native/sensor/src/sensor_data_channel.cpp | 3 +-- frameworks/native/sensor/src/sensor_service_client.cpp | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/frameworks/native/sensor/src/sensor_data_channel.cpp b/frameworks/native/sensor/src/sensor_data_channel.cpp index 01dc93fd..641e75f9 100755 --- a/frameworks/native/sensor/src/sensor_data_channel.cpp +++ b/frameworks/native/sensor/src/sensor_data_channel.cpp @@ -40,7 +40,6 @@ std::shared_ptr SensorDataChannel::eventRunner_; namespace { constexpr HiLogLabel LABEL = { LOG_CORE, SensorsLogDomain::SENSOR_NATIVE, "SensorDataChannel" }; // max 100 data in cache buffer -constexpr int32_t SENSOR_READ_DATA_SIZE = sizeof(struct SensorEvent) * 100; constexpr uint32_t STOP_EVENT_ID = 0; } // namespace @@ -77,7 +76,7 @@ int32_t SensorDataChannel::InnerSensorDataChannel() { std::lock_guard eventRunnerLock(eventRunnerMutex_); // create basic data channel - int32_t ret = CreateSensorBasicChannel(SENSOR_READ_DATA_SIZE, SENSOR_READ_DATA_SIZE); + int32_t ret = CreateSensorBasicChannel(); if (ret != ERR_OK) { HiLog::Error(LABEL, "%{public}s create basic channel failed, ret : %{public}d", __func__, ret); return ret; diff --git a/frameworks/native/sensor/src/sensor_service_client.cpp b/frameworks/native/sensor/src/sensor_service_client.cpp index ff57ee06..24533069 100755 --- a/frameworks/native/sensor/src/sensor_service_client.cpp +++ b/frameworks/native/sensor/src/sensor_service_client.cpp @@ -227,7 +227,7 @@ void SensorServiceClient::UpdateSensorInfoMap(uint32_t sensorId, int64_t samplin SensorBasicInfo sensorInfo; sensorInfo.SetSamplingPeriodNs(samplingPeriod); sensorInfo.SetMaxReportDelayNs(maxReportDelay); - sensorInfo.SetSensorState(SensorState::SENSOR_ENABLED); + sensorInfo.SetSensorState(true); sensorInfoMap_[sensorId] = sensorInfo; return; } -- Gitee From ad63b6087dedccb92310e95eb8c09f87969dfeb7 Mon Sep 17 00:00:00 2001 From: cff-gite Date: Tue, 22 Mar 2022 09:38:03 +0800 Subject: [PATCH 4/7] =?UTF-8?q?=E4=BF=AE=E6=94=B9sensor=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cff-gite --- .../native/sensor/src/sensor_data_channel.cpp | 3 ++- .../native/sensor/src/sensor_service_client.cpp | 2 +- .../adapter/include/hdi_connection.h | 2 +- .../adapter/src/hdi_connection.cpp | 6 +++--- services/sensor/src/client_info.cpp | 16 ++++++++-------- services/sensor/src/sensor_dump.cpp | 2 +- services/sensor/src/sensor_manager.cpp | 4 ++-- services/sensor/src/sensor_service.cpp | 8 ++++---- utils/include/sensor_basic_data_channel.h | 2 +- utils/include/sensor_basic_info.h | 11 ++++++++--- utils/src/sensor_basic_data_channel.cpp | 6 +++--- utils/src/sensor_basic_info.cpp | 6 +++--- 12 files changed, 37 insertions(+), 31 deletions(-) diff --git a/frameworks/native/sensor/src/sensor_data_channel.cpp b/frameworks/native/sensor/src/sensor_data_channel.cpp index 641e75f9..01dc93fd 100755 --- a/frameworks/native/sensor/src/sensor_data_channel.cpp +++ b/frameworks/native/sensor/src/sensor_data_channel.cpp @@ -40,6 +40,7 @@ std::shared_ptr SensorDataChannel::eventRunner_; namespace { constexpr HiLogLabel LABEL = { LOG_CORE, SensorsLogDomain::SENSOR_NATIVE, "SensorDataChannel" }; // max 100 data in cache buffer +constexpr int32_t SENSOR_READ_DATA_SIZE = sizeof(struct SensorEvent) * 100; constexpr uint32_t STOP_EVENT_ID = 0; } // namespace @@ -76,7 +77,7 @@ int32_t SensorDataChannel::InnerSensorDataChannel() { std::lock_guard eventRunnerLock(eventRunnerMutex_); // create basic data channel - int32_t ret = CreateSensorBasicChannel(); + int32_t ret = CreateSensorBasicChannel(SENSOR_READ_DATA_SIZE, SENSOR_READ_DATA_SIZE); if (ret != ERR_OK) { HiLog::Error(LABEL, "%{public}s create basic channel failed, ret : %{public}d", __func__, ret); return ret; diff --git a/frameworks/native/sensor/src/sensor_service_client.cpp b/frameworks/native/sensor/src/sensor_service_client.cpp index 24533069..ff57ee06 100755 --- a/frameworks/native/sensor/src/sensor_service_client.cpp +++ b/frameworks/native/sensor/src/sensor_service_client.cpp @@ -227,7 +227,7 @@ void SensorServiceClient::UpdateSensorInfoMap(uint32_t sensorId, int64_t samplin SensorBasicInfo sensorInfo; sensorInfo.SetSamplingPeriodNs(samplingPeriod); sensorInfo.SetMaxReportDelayNs(maxReportDelay); - sensorInfo.SetSensorState(true); + sensorInfo.SetSensorState(SensorState::SENSOR_ENABLED); sensorInfoMap_[sensorId] = sensorInfo; return; } diff --git a/services/sensor/hdi_connection/adapter/include/hdi_connection.h b/services/sensor/hdi_connection/adapter/include/hdi_connection.h index 72305705..b5f26cb5 100644 --- a/services/sensor/hdi_connection/adapter/include/hdi_connection.h +++ b/services/sensor/hdi_connection/adapter/include/hdi_connection.h @@ -62,7 +62,7 @@ private: void UnregisterHdiDeathRecipient(); void reconnect(); void updateSensorBasicInfo(int32_t sensorId, int64_t samplingPeriodNs, int64_t maxReportDelayNs); - void setSensorBasicInfoState(int32_t sensorId, bool state); + void setSensorBasicInfoState(int32_t sensorId, SensorState state); void deleteSensorBasicInfoState(int32_t sensorId); }; } // namespace Sensors diff --git a/services/sensor/hdi_connection/adapter/src/hdi_connection.cpp b/services/sensor/hdi_connection/adapter/src/hdi_connection.cpp index 376b488e..978d5a5e 100644 --- a/services/sensor/hdi_connection/adapter/src/hdi_connection.cpp +++ b/services/sensor/hdi_connection/adapter/src/hdi_connection.cpp @@ -113,7 +113,7 @@ int32_t HdiConnection::EnableSensor(int32_t sensorId) HiLog::Error(LABEL, "%{public}s is failed", __func__); return ret; } - setSensorBasicInfoState(sensorId, true); + setSensorBasicInfoState(sensorId, SENSOR_ENABLED); return ERR_OK; } @@ -249,7 +249,7 @@ void HdiConnection::updateSensorBasicInfo(int32_t sensorId, int64_t samplingPeri sensorBasicInfoMap_[sensorId] = sensorBasicInfo; } -void HdiConnection::setSensorBasicInfoState(int32_t sensorId, bool state) +void HdiConnection::setSensorBasicInfoState(int32_t sensorId, SensorState state) { std::lock_guard sensorInfoLock(sensorBasicInfoMutex_); auto it = sensorBasicInfoMap_.find(sensorId); @@ -334,7 +334,7 @@ void HdiConnection::reconnect() int32_t sensorTypeId = sensorInfo.first; ret = SetBatch(sensorTypeId, sensorInfo.second.GetSamplingPeriodNs(), sensorInfo.second.GetMaxReportDelayNs()); - if (ret < 0 || sensorInfo.second.GetSensorState() != true) { + if (ret < 0 || sensorInfo.second.GetSensorState() != SENSOR_ENABLED) { HiLog::Error(LABEL, "%{public}s sensorTypeId: %{public}d set batch fail or not need enable sensor", __func__, sensorTypeId); continue; diff --git a/services/sensor/src/client_info.cpp b/services/sensor/src/client_info.cpp index 5517ae87..e3e11c87 100644 --- a/services/sensor/src/client_info.cpp +++ b/services/sensor/src/client_info.cpp @@ -40,27 +40,27 @@ constexpr uint32_t MAX_DUMP_DATA_SIZE = 10; constexpr uint32_t HEART_RATE_SENSOR_ID = 83886336; } // namespace -bool ClientInfo::GetSensorState(uint32_t sensorId) +SensorState ClientInfo::GetSensorState(uint32_t sensorId) { HiLog::Debug(LABEL, "%{public}s begin, sensorId : %{public}u", __func__, sensorId); if (sensorId == INVALID_SENSOR_ID) { HiLog::Error(LABEL, "%{public}s sensorId is invalid", __func__); - return false; + return SENSOR_DISABLED; } std::lock_guard clientLock(clientMutex_); auto it = clientMap_.find(sensorId); if (it == clientMap_.end()) { HiLog::Error(LABEL, "%{public}s cannot find sensorId : %{public}u", __func__, sensorId); - return false; + return SENSOR_DISABLED; } for (const auto &pidIt : it->second) { - if (pidIt.second.GetSensorState() == true) { - return false; + if (pidIt.second.GetSensorState() == SENSOR_ENABLED) { + return SENSOR_ENABLED; } } HiLog::Error(LABEL, "%{public}s cannot find sensorinfo, sensorId : %{public}u", __func__, sensorId); - return false; + return SENSOR_DISABLED; } SensorBasicInfo ClientInfo::GetBestSensorInfo(uint32_t sensorId) @@ -110,7 +110,7 @@ bool ClientInfo::OnlyCurPidSensorEnabled(uint32_t sensorId, int32_t pid) } bool ret = false; for (const auto &pidIt : it->second) { - if (pidIt.second.GetSensorState() != true) { + if (pidIt.second.GetSensorState() != SENSOR_ENABLED) { continue; } if (pidIt.first != pid) { @@ -230,7 +230,7 @@ std::vector> ClientInfo::GetSensorChannel(uint32_t bool ClientInfo::UpdateSensorInfo(uint32_t sensorId, int32_t pid, const SensorBasicInfo &sensorInfo) { HiLog::Debug(LABEL, "%{public}s begin, sensorId : %{public}u, pid : %{public}d", __func__, sensorId, pid); - if ((sensorId == INVALID_SENSOR_ID) || (pid <= INVALID_PID) || (sensorInfo.GetSensorState() != true)) { + if ((sensorId == INVALID_SENSOR_ID) || (pid <= INVALID_PID) || (sensorInfo.GetSensorState() != SENSOR_ENABLED)) { HiLog::Error(LABEL, "%{public}s params are invalid", __func__); return false; } diff --git a/services/sensor/src/sensor_dump.cpp b/services/sensor/src/sensor_dump.cpp index e7f3c92c..7c4c7281 100644 --- a/services/sensor/src/sensor_dump.cpp +++ b/services/sensor/src/sensor_dump.cpp @@ -189,7 +189,7 @@ bool SensorDump::DumpOpeningSensor(int32_t fd, const std::vector &sensor dprintf(fd, "Opening sensors:\n"); for (const auto &sensor : sensors) { uint32_t sensorId = sensor.GetSensorId(); - if (clientInfo.GetSensorState(sensorId) == true) { + if (clientInfo.GetSensorState(sensorId) == SENSOR_ENABLED) { dprintf(fd, "sensorId: %8u | sensorType: %s\n", sensorId, sensorMap_[sensorId].c_str()); } } diff --git a/services/sensor/src/sensor_manager.cpp b/services/sensor/src/sensor_manager.cpp index dcd83f89..39aa400e 100644 --- a/services/sensor/src/sensor_manager.cpp +++ b/services/sensor/src/sensor_manager.cpp @@ -105,7 +105,7 @@ SensorBasicInfo SensorManager::GetSensorInfo(uint32_t sensorId, int64_t sampling if (it == sensorMap_.end()) { sensorInfo.SetSamplingPeriodNs(samplingPeriodNs); sensorInfo.SetMaxReportDelayNs(maxReportDelayNs); - sensorInfo.SetSensorState(true); + sensorInfo.SetSensorState(SENSOR_ENABLED); HiLog::Error(LABEL, "%{public}s sensorId invalid", __func__); return sensorInfo; } @@ -124,7 +124,7 @@ SensorBasicInfo SensorManager::GetSensorInfo(uint32_t sensorId, int64_t sampling int64_t curReportDelayNs = (maxReportDelayNs > supportDelay) ? supportDelay : maxReportDelayNs; sensorInfo.SetSamplingPeriodNs(curSamplingPeriodNs); sensorInfo.SetMaxReportDelayNs(curReportDelayNs); - sensorInfo.SetSensorState(true); + sensorInfo.SetSensorState(SENSOR_ENABLED); HiLog::Debug(LABEL, "%{public}s end", __func__); return sensorInfo; } diff --git a/services/sensor/src/sensor_service.cpp b/services/sensor/src/sensor_service.cpp index bc0a2f84..f2145bb8 100644 --- a/services/sensor/src/sensor_service.cpp +++ b/services/sensor/src/sensor_service.cpp @@ -243,9 +243,9 @@ ErrCode SensorService::EnableSensor(uint32_t sensorId, int64_t samplingPeriodNs, HiLog::Error(LABEL, "%{public}s sensorId is 0 or maxReportDelayNs exceeded the maximum value", __func__); return ERR_NO_INIT; } - ReportSensorSysEvent(sensorId, true); + ReportSensorSysEvent(sensorId, SENSOR_ENABLED); std::lock_guard serviceLock(serviceLock_); - if (clientInfo_.GetSensorState(sensorId) == true) { + if (clientInfo_.GetSensorState(sensorId) == SENSOR_ENABLED) { HiLog::Warn(LABEL, "%{public}s sensor has been enabled already", __func__); auto ret = SaveSubscriber(sensorId, samplingPeriodNs, maxReportDelayNs); if (ret != ERR_OK) { @@ -285,14 +285,14 @@ ErrCode SensorService::DisableSensor(uint32_t sensorId) HiLog::Error(LABEL, "%{public}s sensorId is invalid", __func__); return ERR_NO_INIT; } - ReportSensorSysEvent(sensorId, false); + ReportSensorSysEvent(sensorId, SENSOR_DISABLED); std::lock_guard serviceLock(serviceLock_); const int32_t clientPid = this->GetCallingPid(); if (clientPid < 0) { HiLog::Error(LABEL, "%{public}s clientPid is invalid, clientPid : %{public}d", __func__, clientPid); return CLIENT_PID_INVALID_ERR; } - if (clientInfo_.GetSensorState(sensorId) != true) { + if (clientInfo_.GetSensorState(sensorId) != SENSOR_ENABLED) { HiLog::Error(LABEL, "%{public}s sensor should be enabled first", __func__); return DISABLE_SENSOR_ERR; } diff --git a/utils/include/sensor_basic_data_channel.h b/utils/include/sensor_basic_data_channel.h index 9b421705..1ce789b0 100644 --- a/utils/include/sensor_basic_data_channel.h +++ b/utils/include/sensor_basic_data_channel.h @@ -41,7 +41,7 @@ class SensorBasicDataChannel : public RefBase { public: SensorBasicDataChannel(); virtual ~SensorBasicDataChannel(); - int32_t CreateSensorBasicChannel(); + int32_t CreateSensorBasicChannel(size_t sendSize, size_t receiveSize); int32_t CreateSensorBasicChannel(MessageParcel &data); int32_t DestroySensorBasicChannel(); int32_t GetSendDataFd() const; diff --git a/utils/include/sensor_basic_info.h b/utils/include/sensor_basic_info.h index 6e7bcfab..2b7e821a 100755 --- a/utils/include/sensor_basic_info.h +++ b/utils/include/sensor_basic_info.h @@ -20,6 +20,11 @@ namespace OHOS { namespace Sensors { + enum SensorState { + SENSOR_DISABLED = 0, + SENSOR_ENABLED = 1, + SENSOR_UNKNOWN_STATE = 2, + }; class SensorBasicInfo { public: @@ -29,13 +34,13 @@ public: void SetSamplingPeriodNs(int64_t samplingPeriodNs); int64_t GetMaxReportDelayNs() const; void SetMaxReportDelayNs(int64_t maxReportDelayNs); - bool GetSensorState() const; - void SetSensorState(bool sensorState); + SensorState GetSensorState() const; + void SetSensorState(SensorState sensorState); private: int64_t samplingPeriodNs_; int64_t maxReportDelayNs_; - bool sensorState_; + SensorState sensorState_; }; } // namespace Sensors } // namespace OHOS diff --git a/utils/src/sensor_basic_data_channel.cpp b/utils/src/sensor_basic_data_channel.cpp index b11b8ef4..3ae2fc33 100755 --- a/utils/src/sensor_basic_data_channel.cpp +++ b/utils/src/sensor_basic_data_channel.cpp @@ -38,7 +38,7 @@ SensorBasicDataChannel::SensorBasicDataChannel() : sendFd_(INVALID_FD), receiveF HiLog::Debug(LABEL, "%{public}s isActive_ : %{public}d, sendFd: %{public}d", __func__, isActive_, sendFd_); } -int32_t SensorBasicDataChannel::CreateSensorBasicChannel() +int32_t SensorBasicDataChannel::CreateSensorBasicChannel(size_t sendSize, size_t receiveSize) { if ((sendFd_ != INVALID_FD) || (receiveFd_ != INVALID_FD)) { HiLog::Debug(LABEL, "%{public}s already create socketpair", __func__); @@ -55,8 +55,8 @@ int32_t SensorBasicDataChannel::CreateSensorBasicChannel() return SENSOR_CHANNEL_SOCKET_CREATE_ERR; } // set socket attr - setsockopt(socketPair[0], SOL_SOCKET, SO_SNDBUF, &DEFAULT_CHANNEL_SIZE, sizeof(DEFAULT_CHANNEL_SIZE)); - setsockopt(socketPair[1], SOL_SOCKET, SO_RCVBUF, &DEFAULT_CHANNEL_SIZE, sizeof(DEFAULT_CHANNEL_SIZE)); + setsockopt(socketPair[0], SOL_SOCKET, SO_SNDBUF, &sendSize, sizeof(sendSize)); + setsockopt(socketPair[1], SOL_SOCKET, SO_RCVBUF, &receiveSize, sizeof(receiveSize)); int32_t bufferSize = DEFAULT_CHANNEL_SIZE; int32_t ret = setsockopt(socketPair[0], SOL_SOCKET, SO_RCVBUF, &bufferSize, sizeof(bufferSize)); if (ret != 0) { diff --git a/utils/src/sensor_basic_info.cpp b/utils/src/sensor_basic_info.cpp index 98f7883b..959806cc 100755 --- a/utils/src/sensor_basic_info.cpp +++ b/utils/src/sensor_basic_info.cpp @@ -17,7 +17,7 @@ namespace OHOS { namespace Sensors { -SensorBasicInfo::SensorBasicInfo() : samplingPeriodNs_(0L), maxReportDelayNs_(0L), sensorState_(false) +SensorBasicInfo::SensorBasicInfo() : samplingPeriodNs_(0L), maxReportDelayNs_(0L), sensorState_(SENSOR_DISABLED) {} int64_t SensorBasicInfo::GetSamplingPeriodNs() const @@ -40,12 +40,12 @@ void SensorBasicInfo::SetMaxReportDelayNs(int64_t maxReportDelayNs) maxReportDelayNs_ = maxReportDelayNs; } -bool SensorBasicInfo::GetSensorState() const +SensorState SensorBasicInfo::GetSensorState() const { return sensorState_; } -void SensorBasicInfo::SetSensorState(bool sensorState) +void SensorBasicInfo::SetSensorState(SensorState sensorState) { sensorState_ = sensorState; } -- Gitee From b771e56f51ed2c3e57a36d8feb35be6130bfa038 Mon Sep 17 00:00:00 2001 From: cff-gite Date: Tue, 22 Mar 2022 14:34:36 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=E4=BF=AE=E6=94=B9sensor=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cff-gite --- utils/include/sensor_basic_info.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/utils/include/sensor_basic_info.h b/utils/include/sensor_basic_info.h index 2b7e821a..d687788b 100755 --- a/utils/include/sensor_basic_info.h +++ b/utils/include/sensor_basic_info.h @@ -21,9 +21,9 @@ namespace OHOS { namespace Sensors { enum SensorState { - SENSOR_DISABLED = 0, - SENSOR_ENABLED = 1, - SENSOR_UNKNOWN_STATE = 2, + SENSOR_DISABLED = 0, + SENSOR_ENABLED = 1, + SENSOR_UNKNOWN_STATE = 2, }; class SensorBasicInfo { -- Gitee From cf26f48021dcc0441a67f4bbee151e224ca98226 Mon Sep 17 00:00:00 2001 From: cff-gite Date: Tue, 22 Mar 2022 15:18:13 +0800 Subject: [PATCH 6/7] =?UTF-8?q?=E4=BF=AE=E6=94=B9sensor=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cff-gite --- .../native/sensor/src/sensor_agent_proxy.cpp | 2 +- .../sensor/src/sensor_service_client.cpp | 20 +++++++------- interfaces/native/include/sensor_algorithm.h | 1 + interfaces/native/src/geomagnetic_field.cpp | 4 +-- interfaces/plugin/src/sensor_js.cpp | 3 ++- .../adapter/include/hdi_connection.h | 1 + .../adapter/src/hdi_connection.cpp | 4 +-- .../hardware/include/hdi_service_impl.h | 2 +- .../hardware/src/hdi_service_impl.cpp | 27 +++++++++++-------- .../interface/src/sensor_hdi_connection.cpp | 5 +++- services/sensor/include/sensor_service.h | 2 +- services/sensor/src/sensor_dump.cpp | 6 ++--- services/sensor/src/sensor_service.cpp | 2 +- utils/include/sensor_basic_info.h | 4 +-- utils/include/sensors_errors.h | 18 +++++++++++++ 15 files changed, 65 insertions(+), 36 deletions(-) diff --git a/frameworks/native/sensor/src/sensor_agent_proxy.cpp b/frameworks/native/sensor/src/sensor_agent_proxy.cpp index a5522d8d..126e24ef 100644 --- a/frameworks/native/sensor/src/sensor_agent_proxy.cpp +++ b/frameworks/native/sensor/src/sensor_agent_proxy.cpp @@ -75,7 +75,7 @@ std::mutex SensorAgentProxy::chanelMutex_; std::map SensorAgentProxy::g_subscribeMap; std::map SensorAgentProxy::g_unsubscribeMap; -SensorAgentProxy::SensorAgentProxy() +SensorAgentProxy::SensorAgentProxy() : dataChannel_(new (std::nothrow) SensorDataChannel()) {} diff --git a/frameworks/native/sensor/src/sensor_service_client.cpp b/frameworks/native/sensor/src/sensor_service_client.cpp index ff57ee06..f813f235 100755 --- a/frameworks/native/sensor/src/sensor_service_client.cpp +++ b/frameworks/native/sensor/src/sensor_service_client.cpp @@ -40,7 +40,7 @@ constexpr uint32_t WAIT_MS = 200; int32_t SensorServiceClient::InitServiceClient() { - HiLog::Debug(LABEL, "%{public}s begin", __func__); + CALL_LOG_ENTER; std::lock_guard clientLock(clientMutex_); if (sensorServer_ != nullptr) { HiLog::Debug(LABEL, "%{public}s already init", __func__); @@ -91,7 +91,7 @@ bool SensorServiceClient::IsValidSensorId(uint32_t sensorId) int32_t SensorServiceClient::EnableSensor(uint32_t sensorId, int64_t samplingPeriod, int64_t maxReportDelay) { - HiLog::Debug(LABEL, "%{public}s begin", __func__); + CALL_LOG_ENTER; if (!IsValidSensorId(sensorId)) { HiLog::Error(LABEL, "%{public}s sensorId is invalid", __func__); return SENSOR_NATIVE_SAM_ERR; @@ -110,7 +110,7 @@ int32_t SensorServiceClient::EnableSensor(uint32_t sensorId, int64_t samplingPer int32_t SensorServiceClient::DisableSensor(uint32_t sensorId) { - HiLog::Debug(LABEL, "%{public}s begin", __func__); + CALL_LOG_ENTER; if (!IsValidSensorId(sensorId)) { HiLog::Error(LABEL, "%{public}s sensorId is invalid", __func__); return SENSOR_NATIVE_SAM_ERR; @@ -129,7 +129,7 @@ int32_t SensorServiceClient::DisableSensor(uint32_t sensorId) int32_t SensorServiceClient::RunCommand(uint32_t sensorId, int32_t cmdType, int32_t params) { - HiLog::Debug(LABEL, "%{public}s begin", __func__); + CALL_LOG_ENTER; if (!IsValidSensorId(sensorId)) { HiLog::Error(LABEL, "%{public}s sensorId is invalid", __func__); return SENSOR_NATIVE_SAM_ERR; @@ -149,7 +149,7 @@ int32_t SensorServiceClient::RunCommand(uint32_t sensorId, int32_t cmdType, int3 std::vector SensorServiceClient::GetSensorList() { - HiLog::Debug(LABEL, "%{public}s begin", __func__); + CALL_LOG_ENTER; int32_t ret = InitServiceClient(); if (ret != ERR_OK) { HiLog::Error(LABEL, "%{public}s InitServiceClient failed, ret : %{public}d", __func__, ret); @@ -163,7 +163,7 @@ std::vector SensorServiceClient::GetSensorList() int32_t SensorServiceClient::TransferDataChannel(sptr sensorDataChannel) { - HiLog::Debug(LABEL, "%{public}s begin", __func__); + CALL_LOG_ENTER; dataChannel_ = sensorDataChannel; int32_t ret = InitServiceClient(); if (ret != ERR_OK) { @@ -175,7 +175,7 @@ int32_t SensorServiceClient::TransferDataChannel(sptr sensorD int32_t SensorServiceClient::DestroyDataChannel() { - HiLog::Debug(LABEL, "%{public}s begin", __func__); + CALL_LOG_ENTER; int32_t ret = InitServiceClient(); if (ret != ERR_OK) { HiLog::Error(LABEL, "%{public}s InitServiceClient failed, ret : %{public}d", __func__, ret); @@ -186,7 +186,7 @@ int32_t SensorServiceClient::DestroyDataChannel() void SensorServiceClient::ProcessDeathObserver(const wptr &object) { - HiLog::Debug(LABEL, "%{public}s begin", __func__); + CALL_LOG_ENTER; (void)object; if (dataChannel_ == nullptr) { HiLog::Error(LABEL, "%{public}s dataChannel_ cannot be null", __func__); @@ -222,7 +222,7 @@ void SensorServiceClient::ProcessDeathObserver(const wptr &object void SensorServiceClient::UpdateSensorInfoMap(uint32_t sensorId, int64_t samplingPeriod, int64_t maxReportDelay) { - HiLog::Debug(LABEL, "%{public}s begin", __func__); + CALL_LOG_ENTER; std::lock_guard mapLock(mapMutex_); SensorBasicInfo sensorInfo; sensorInfo.SetSamplingPeriodNs(samplingPeriod); @@ -234,7 +234,7 @@ void SensorServiceClient::UpdateSensorInfoMap(uint32_t sensorId, int64_t samplin void SensorServiceClient::DeleteSensorInfoItem(uint32_t sensorId) { - HiLog::Debug(LABEL, "%{public}s begin", __func__); + CALL_LOG_ENTER; std::lock_guard mapLock(mapMutex_); auto it = sensorInfoMap_.find(sensorId); if (it != sensorInfoMap_.end()) { diff --git a/interfaces/native/include/sensor_algorithm.h b/interfaces/native/include/sensor_algorithm.h index 4dd157f0..e8d96685 100644 --- a/interfaces/native/include/sensor_algorithm.h +++ b/interfaces/native/include/sensor_algorithm.h @@ -42,6 +42,7 @@ public: int32_t createRotationAndInclination(std::vector gravity, std::vector geomagnetic, std::vector &rotationMatrix, std::vector &inclinationMatrix); + private: int32_t transformCoordinateSystemImpl(std::vector inRotationMatrix, int32_t axisX, int32_t axisY, std::vector &outRotationMatrix); diff --git a/interfaces/native/src/geomagnetic_field.cpp b/interfaces/native/src/geomagnetic_field.cpp index 239f16c9..1b7c0f2d 100644 --- a/interfaces/native/src/geomagnetic_field.cpp +++ b/interfaces/native/src/geomagnetic_field.cpp @@ -181,8 +181,8 @@ void GeomagneticField::GetLongitudeTrigonometric() cosMLongitude[0] = 1.0f; sinMLongitude[1] = static_cast(sin(geocentricLongitude)); cosMLongitude[1] = static_cast(cos(geocentricLongitude)); - for (int32_t index = 2; index < GAUSSIAN_COEFFICIENT_DIMENSION; ++index) { - int32_t x = index >> 1; + for (uint32_t index = 2; index < GAUSSIAN_COEFFICIENT_DIMENSION; ++index) { + uint32_t x = index >> 1; sinMLongitude[index] = (sinMLongitude[index - x] * cosMLongitude[x] + cosMLongitude[index - x] * sinMLongitude[x]); cosMLongitude[index] = (cosMLongitude[index - x] * cosMLongitude[x] diff --git a/interfaces/plugin/src/sensor_js.cpp b/interfaces/plugin/src/sensor_js.cpp index 52ccc3af..b1c0205c 100644 --- a/interfaces/plugin/src/sensor_js.cpp +++ b/interfaces/plugin/src/sensor_js.cpp @@ -14,6 +14,7 @@ */ #include "sensor_js.h" +#include #include #include #include @@ -227,7 +228,7 @@ static napi_value On(napi_env env, napi_callback_info info) return nullptr; } interval = GetCppInt64(value, env); - HiLog::Debug(LABEL, "%{public}s interval is %{public}lld", __func__, interval); + HiLog::Debug(LABEL, "%{public}s interval is %{public}" PRId64, __func__, interval); } int32_t ret = SubscribeSensor(sensorTypeId, interval, DataCallbackImpl); if (ret != OHOS::ERR_OK) { diff --git a/services/sensor/hdi_connection/adapter/include/hdi_connection.h b/services/sensor/hdi_connection/adapter/include/hdi_connection.h index b5f26cb5..95cd5516 100644 --- a/services/sensor/hdi_connection/adapter/include/hdi_connection.h +++ b/services/sensor/hdi_connection/adapter/include/hdi_connection.h @@ -53,6 +53,7 @@ public: sptr getReportDataCallback(); void ProcessDeathObserver(const wptr &object); + private: DISALLOW_COPY_AND_MOVE(HdiConnection); static ZReportDataCb reportDataCb_; diff --git a/services/sensor/hdi_connection/adapter/src/hdi_connection.cpp b/services/sensor/hdi_connection/adapter/src/hdi_connection.cpp index 978d5a5e..af655e30 100644 --- a/services/sensor/hdi_connection/adapter/src/hdi_connection.cpp +++ b/services/sensor/hdi_connection/adapter/src/hdi_connection.cpp @@ -35,8 +35,8 @@ sptr sensorInterface_ = nullptr; sptr eventCallback_ = nullptr; std::map sensorBasicInfoMap_; std::mutex sensorBasicInfoMutex_; -constexpr int32_t GET_HDI_SERVICE_COUNT = 10; -constexpr uint32_t WAIT_MS = 100; +constexpr int32_t GET_HDI_SERVICE_COUNT = 30; +constexpr uint32_t WAIT_MS = 200; } ZReportDataCb HdiConnection::reportDataCb_ = nullptr; diff --git a/services/sensor/hdi_connection/hardware/include/hdi_service_impl.h b/services/sensor/hdi_connection/hardware/include/hdi_service_impl.h index 46399700..9c9d041e 100644 --- a/services/sensor/hdi_connection/hardware/include/hdi_service_impl.h +++ b/services/sensor/hdi_connection/hardware/include/hdi_service_impl.h @@ -52,7 +52,7 @@ public: private: DISALLOW_COPY_AND_MOVE(HdiServiceImpl); static void DataReportThread(); - std::vector g_enableSensos; + std::vector g_enableSensors; std::thread dataReportThread_; static RecordDataCallback g_callback; static int64_t g_samplingInterval; diff --git a/services/sensor/hdi_connection/hardware/src/hdi_service_impl.cpp b/services/sensor/hdi_connection/hardware/src/hdi_service_impl.cpp index 65842fb9..a4c0f50f 100644 --- a/services/sensor/hdi_connection/hardware/src/hdi_service_impl.cpp +++ b/services/sensor/hdi_connection/hardware/src/hdi_service_impl.cpp @@ -70,15 +70,15 @@ int32_t HdiServiceImpl::EnableSensor(uint32_t sensorId) HiLog::Error(LABEL, "%{public}s enable sensor failed", __func__); return -1; } - if (std::count(supportSensors.begin(), supportSensors.end(), sensorId) == 0) { + if (std::find(supportSensors.begin(), supportSensors.end(), sensorId) == supportSensors.end()) { HiLog::Error(LABEL, "%{public}s not support enable sensorId: %{public}d", __func__, sensorId); - return -1; + return ERR_NO_INIT; } - if (std::count(g_enableSensos.begin(), g_enableSensos.end(), sensorId) != 0) { + if (std::find(g_enableSensors.begin(), g_enableSensors.end(), sensorId) != g_enableSensors.end()) { HiLog::Info(LABEL, "%{public}s sensorId: %{public}d has been enabled", __func__, sensorId); return ERR_OK; } - g_enableSensos.push_back(sensorId); + g_enableSensors.push_back(sensorId); if (!dataReportThread_.joinable() || g_isStop) { if (dataReportThread_.joinable()) { dataReportThread_.join(); @@ -93,17 +93,22 @@ int32_t HdiServiceImpl::EnableSensor(uint32_t sensorId) int32_t HdiServiceImpl::DisableSensor(uint32_t sensorId) { HiLog::Info(LABEL, "%{public}s in", __func__); - if (std::count(supportSensors.begin(), supportSensors.end(), sensorId) == 0) { + if (std::find(supportSensors.begin(), supportSensors.end(), sensorId) == supportSensors.end()) { HiLog::Error(LABEL, "%{public}s not support disable sensorId: %{public}d", __func__, sensorId); - return -1; + return ERR_NO_INIT; } - if (std::count(g_enableSensos.begin(), g_enableSensos.end(), sensorId) == 0) { + if (std::find(g_enableSensors.begin(), g_enableSensors.end(), sensorId) == g_enableSensors.end()) { HiLog::Error(LABEL, "%{public}s sensorId: %{public}d should be enable first", __func__, sensorId); - return -1; + return ERR_NO_INIT; + } + std::vector::iterator iter; + for (iter = g_enableSensors.begin(); iter != g_enableSensors.end(); ++iter) { + if (*iter == sensorId) { + g_enableSensors.erase(iter++); + break; + } } - auto iter = std::remove(g_enableSensos.begin(), g_enableSensos.end(), sensorId); - g_enableSensos.erase(iter, g_enableSensos.end()); - if (g_enableSensos.empty()) { + if (g_enableSensors.empty()) { g_isStop = true; } return ERR_OK; diff --git a/services/sensor/hdi_connection/interface/src/sensor_hdi_connection.cpp b/services/sensor/hdi_connection/interface/src/sensor_hdi_connection.cpp index 78e63162..0d5c04fd 100644 --- a/services/sensor/hdi_connection/interface/src/sensor_hdi_connection.cpp +++ b/services/sensor/hdi_connection/interface/src/sensor_hdi_connection.cpp @@ -22,7 +22,6 @@ namespace OHOS { namespace Sensors { using namespace OHOS::HiviewDFX; - namespace { constexpr HiLogLabel LABEL = { LOG_CORE, SensorsLogDomain::SENSOR_SERVICE, "SensorHdiConnection" }; } @@ -30,6 +29,10 @@ constexpr HiLogLabel LABEL = { LOG_CORE, SensorsLogDomain::SENSOR_SERVICE, "Sens int32_t SensorHdiConnection::ConnectHdi() { iSensorHdiConnection_ = std::make_unique(); + if (iSensorHdiConnection_ == nullptr) { + HiLog::Error(LABEL, "%{public}s failed, iSensorHdiConnection_ cannot be null", __func__); + return ERROR; + } int32_t ret = connectHdiService(); if (ret != ERR_OK) { HiLog::Error(LABEL, "%{public}s connect hdi service failed, try to connect compatible connection", diff --git a/services/sensor/include/sensor_service.h b/services/sensor/include/sensor_service.h index 6f46b2af..b84b37ee 100644 --- a/services/sensor/include/sensor_service.h +++ b/services/sensor/include/sensor_service.h @@ -20,7 +20,6 @@ #include #include - #include "nocopyable.h" #include "system_ability.h" @@ -40,6 +39,7 @@ enum class SensorServiceState { class SensorService : public SystemAbility, public SensorServiceStub { DECLARE_SYSTEM_ABILITY(SensorService) + public: explicit SensorService(int32_t systemAbilityId, bool runOnCreate = false); diff --git a/services/sensor/src/sensor_dump.cpp b/services/sensor/src/sensor_dump.cpp index 7c4c7281..c41921c4 100644 --- a/services/sensor/src/sensor_dump.cpp +++ b/services/sensor/src/sensor_dump.cpp @@ -144,10 +144,10 @@ bool SensorDump::DumpSensorList(int32_t fd, const std::vector &sensors, auto sensorId = sensor.GetSensorId(); dprintf(fd, "sensorId:%8u | sensorType:%s | sensorName:%s | vendorName:%s | maxRange:%f" - "| fifoMaxEventCount:%d | minSamplePeriodNs:%lld | maxSamplePeriodNs:%lld\n", + "| fifoMaxEventCount:%d | minSamplePeriodNs:%" PRId64 " | maxSamplePeriodNs:%" PRId64 "\n", sensorId, sensorMap_[sensorId].c_str(), sensor.GetSensorName().c_str(), sensor.GetVendorName().c_str(), - sensor.GetMaxRange(), sensor.GetFifoMaxEventCount(), (long long) { sensor.GetMinSamplePeriodNs() }, - (long long) { sensor.GetMaxSamplePeriodNs() }); + sensor.GetMaxRange(), sensor.GetFifoMaxEventCount(), sensor.GetMinSamplePeriodNs(), + sensor.GetMaxSamplePeriodNs()); } return true; } diff --git a/services/sensor/src/sensor_service.cpp b/services/sensor/src/sensor_service.cpp index f2145bb8..81f2eeaa 100644 --- a/services/sensor/src/sensor_service.cpp +++ b/services/sensor/src/sensor_service.cpp @@ -236,7 +236,7 @@ ErrCode SensorService::SaveSubscriber(uint32_t sensorId, int64_t samplingPeriodN ErrCode SensorService::EnableSensor(uint32_t sensorId, int64_t samplingPeriodNs, int64_t maxReportDelayNs) { - HiLog::Debug(LABEL, "%{public}s begin, sensorId : %{public}u, samplingPeriodNs : %{public}" + HiLog::Debug(LABEL, "%{public}s begin, sensorId : %{public}u, samplingPeriodNs : %{public}" PRId64, __func__, sensorId, samplingPeriodNs); if ((sensorId == INVALID_SENSOR_ID) || ((samplingPeriodNs != 0L) && ((maxReportDelayNs / samplingPeriodNs) > MAX_EVENT_COUNT))) { diff --git a/utils/include/sensor_basic_info.h b/utils/include/sensor_basic_info.h index d687788b..aaaa29f9 100755 --- a/utils/include/sensor_basic_info.h +++ b/utils/include/sensor_basic_info.h @@ -20,11 +20,11 @@ namespace OHOS { namespace Sensors { - enum SensorState { +enum SensorState { SENSOR_DISABLED = 0, SENSOR_ENABLED = 1, SENSOR_UNKNOWN_STATE = 2, - }; +}; class SensorBasicInfo { public: diff --git a/utils/include/sensors_errors.h b/utils/include/sensors_errors.h index 38a2d16b..d6e5ec6f 100644 --- a/utils/include/sensors_errors.h +++ b/utils/include/sensors_errors.h @@ -17,6 +17,7 @@ #define SENSORS_ERRORS_H #include +#include "hilog/log.h" namespace OHOS { namespace Sensors { @@ -105,6 +106,23 @@ enum { SENSOR_NATIVE_GET_SERVICE_ERR = SENSOR_NATIVE_SAM_ERR + 1, SENSOR_NATIVE_REGSITER_CB_ERR = SENSOR_NATIVE_GET_SERVICE_ERR + 1, }; + +class InnerFunctionTracer { +public: + InnerFunctionTracer(const OHOS::HiviewDFX::HiLogLabel& label, const char *func) + : label_ { label }, func_ { func } + { + OHOS::HiviewDFX::HiLog::Debug(label_, "in %{public}s, enter", func_); + } + ~InnerFunctionTracer() + { + OHOS::HiviewDFX::HiLog::Debug(label_, "in %{public}s, leave", func_); + } +private: + const OHOS::HiviewDFX::HiLogLabel& label_; + const char* func_ { nullptr }; +}; } // namespace Sensors } // namespace OHOS +#define CALL_LOG_ENTER InnerFunctionTracer ___innerFuncTracer___ { LABEL, __FUNCTION__ } #endif // SENSORS_ERRORS_H -- Gitee From b93eae877d495081cb73187510a977f9c27bc9fa Mon Sep 17 00:00:00 2001 From: cff-gite Date: Tue, 22 Mar 2022 15:41:49 +0800 Subject: [PATCH 7/7] =?UTF-8?q?=E4=BF=AE=E6=94=B9sensor=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cff-gite --- .../native/sensor/src/sensor_agent_proxy.cpp | 2 +- .../sensor/src/sensor_service_client.cpp | 20 +++++++------- interfaces/native/include/sensor_algorithm.h | 1 - interfaces/native/src/geomagnetic_field.cpp | 4 +-- interfaces/plugin/src/sensor_js.cpp | 3 +-- .../adapter/include/hdi_connection.h | 1 - .../adapter/src/hdi_connection.cpp | 4 +-- .../hardware/include/hdi_service_impl.h | 2 +- .../hardware/src/hdi_service_impl.cpp | 27 ++++++++----------- .../interface/src/sensor_hdi_connection.cpp | 5 +--- services/sensor/src/sensor_dump.cpp | 6 ++--- services/sensor/src/sensor_service.cpp | 2 +- utils/include/sensors_errors.h | 18 ------------- 13 files changed, 33 insertions(+), 62 deletions(-) diff --git a/frameworks/native/sensor/src/sensor_agent_proxy.cpp b/frameworks/native/sensor/src/sensor_agent_proxy.cpp index 126e24ef..a5522d8d 100644 --- a/frameworks/native/sensor/src/sensor_agent_proxy.cpp +++ b/frameworks/native/sensor/src/sensor_agent_proxy.cpp @@ -75,7 +75,7 @@ std::mutex SensorAgentProxy::chanelMutex_; std::map SensorAgentProxy::g_subscribeMap; std::map SensorAgentProxy::g_unsubscribeMap; -SensorAgentProxy::SensorAgentProxy() +SensorAgentProxy::SensorAgentProxy() : dataChannel_(new (std::nothrow) SensorDataChannel()) {} diff --git a/frameworks/native/sensor/src/sensor_service_client.cpp b/frameworks/native/sensor/src/sensor_service_client.cpp index f813f235..ff57ee06 100755 --- a/frameworks/native/sensor/src/sensor_service_client.cpp +++ b/frameworks/native/sensor/src/sensor_service_client.cpp @@ -40,7 +40,7 @@ constexpr uint32_t WAIT_MS = 200; int32_t SensorServiceClient::InitServiceClient() { - CALL_LOG_ENTER; + HiLog::Debug(LABEL, "%{public}s begin", __func__); std::lock_guard clientLock(clientMutex_); if (sensorServer_ != nullptr) { HiLog::Debug(LABEL, "%{public}s already init", __func__); @@ -91,7 +91,7 @@ bool SensorServiceClient::IsValidSensorId(uint32_t sensorId) int32_t SensorServiceClient::EnableSensor(uint32_t sensorId, int64_t samplingPeriod, int64_t maxReportDelay) { - CALL_LOG_ENTER; + HiLog::Debug(LABEL, "%{public}s begin", __func__); if (!IsValidSensorId(sensorId)) { HiLog::Error(LABEL, "%{public}s sensorId is invalid", __func__); return SENSOR_NATIVE_SAM_ERR; @@ -110,7 +110,7 @@ int32_t SensorServiceClient::EnableSensor(uint32_t sensorId, int64_t samplingPer int32_t SensorServiceClient::DisableSensor(uint32_t sensorId) { - CALL_LOG_ENTER; + HiLog::Debug(LABEL, "%{public}s begin", __func__); if (!IsValidSensorId(sensorId)) { HiLog::Error(LABEL, "%{public}s sensorId is invalid", __func__); return SENSOR_NATIVE_SAM_ERR; @@ -129,7 +129,7 @@ int32_t SensorServiceClient::DisableSensor(uint32_t sensorId) int32_t SensorServiceClient::RunCommand(uint32_t sensorId, int32_t cmdType, int32_t params) { - CALL_LOG_ENTER; + HiLog::Debug(LABEL, "%{public}s begin", __func__); if (!IsValidSensorId(sensorId)) { HiLog::Error(LABEL, "%{public}s sensorId is invalid", __func__); return SENSOR_NATIVE_SAM_ERR; @@ -149,7 +149,7 @@ int32_t SensorServiceClient::RunCommand(uint32_t sensorId, int32_t cmdType, int3 std::vector SensorServiceClient::GetSensorList() { - CALL_LOG_ENTER; + HiLog::Debug(LABEL, "%{public}s begin", __func__); int32_t ret = InitServiceClient(); if (ret != ERR_OK) { HiLog::Error(LABEL, "%{public}s InitServiceClient failed, ret : %{public}d", __func__, ret); @@ -163,7 +163,7 @@ std::vector SensorServiceClient::GetSensorList() int32_t SensorServiceClient::TransferDataChannel(sptr sensorDataChannel) { - CALL_LOG_ENTER; + HiLog::Debug(LABEL, "%{public}s begin", __func__); dataChannel_ = sensorDataChannel; int32_t ret = InitServiceClient(); if (ret != ERR_OK) { @@ -175,7 +175,7 @@ int32_t SensorServiceClient::TransferDataChannel(sptr sensorD int32_t SensorServiceClient::DestroyDataChannel() { - CALL_LOG_ENTER; + HiLog::Debug(LABEL, "%{public}s begin", __func__); int32_t ret = InitServiceClient(); if (ret != ERR_OK) { HiLog::Error(LABEL, "%{public}s InitServiceClient failed, ret : %{public}d", __func__, ret); @@ -186,7 +186,7 @@ int32_t SensorServiceClient::DestroyDataChannel() void SensorServiceClient::ProcessDeathObserver(const wptr &object) { - CALL_LOG_ENTER; + HiLog::Debug(LABEL, "%{public}s begin", __func__); (void)object; if (dataChannel_ == nullptr) { HiLog::Error(LABEL, "%{public}s dataChannel_ cannot be null", __func__); @@ -222,7 +222,7 @@ void SensorServiceClient::ProcessDeathObserver(const wptr &object void SensorServiceClient::UpdateSensorInfoMap(uint32_t sensorId, int64_t samplingPeriod, int64_t maxReportDelay) { - CALL_LOG_ENTER; + HiLog::Debug(LABEL, "%{public}s begin", __func__); std::lock_guard mapLock(mapMutex_); SensorBasicInfo sensorInfo; sensorInfo.SetSamplingPeriodNs(samplingPeriod); @@ -234,7 +234,7 @@ void SensorServiceClient::UpdateSensorInfoMap(uint32_t sensorId, int64_t samplin void SensorServiceClient::DeleteSensorInfoItem(uint32_t sensorId) { - CALL_LOG_ENTER; + HiLog::Debug(LABEL, "%{public}s begin", __func__); std::lock_guard mapLock(mapMutex_); auto it = sensorInfoMap_.find(sensorId); if (it != sensorInfoMap_.end()) { diff --git a/interfaces/native/include/sensor_algorithm.h b/interfaces/native/include/sensor_algorithm.h index e8d96685..4dd157f0 100644 --- a/interfaces/native/include/sensor_algorithm.h +++ b/interfaces/native/include/sensor_algorithm.h @@ -42,7 +42,6 @@ public: int32_t createRotationAndInclination(std::vector gravity, std::vector geomagnetic, std::vector &rotationMatrix, std::vector &inclinationMatrix); - private: int32_t transformCoordinateSystemImpl(std::vector inRotationMatrix, int32_t axisX, int32_t axisY, std::vector &outRotationMatrix); diff --git a/interfaces/native/src/geomagnetic_field.cpp b/interfaces/native/src/geomagnetic_field.cpp index 1b7c0f2d..239f16c9 100644 --- a/interfaces/native/src/geomagnetic_field.cpp +++ b/interfaces/native/src/geomagnetic_field.cpp @@ -181,8 +181,8 @@ void GeomagneticField::GetLongitudeTrigonometric() cosMLongitude[0] = 1.0f; sinMLongitude[1] = static_cast(sin(geocentricLongitude)); cosMLongitude[1] = static_cast(cos(geocentricLongitude)); - for (uint32_t index = 2; index < GAUSSIAN_COEFFICIENT_DIMENSION; ++index) { - uint32_t x = index >> 1; + for (int32_t index = 2; index < GAUSSIAN_COEFFICIENT_DIMENSION; ++index) { + int32_t x = index >> 1; sinMLongitude[index] = (sinMLongitude[index - x] * cosMLongitude[x] + cosMLongitude[index - x] * sinMLongitude[x]); cosMLongitude[index] = (cosMLongitude[index - x] * cosMLongitude[x] diff --git a/interfaces/plugin/src/sensor_js.cpp b/interfaces/plugin/src/sensor_js.cpp index b1c0205c..52ccc3af 100644 --- a/interfaces/plugin/src/sensor_js.cpp +++ b/interfaces/plugin/src/sensor_js.cpp @@ -14,7 +14,6 @@ */ #include "sensor_js.h" -#include #include #include #include @@ -228,7 +227,7 @@ static napi_value On(napi_env env, napi_callback_info info) return nullptr; } interval = GetCppInt64(value, env); - HiLog::Debug(LABEL, "%{public}s interval is %{public}" PRId64, __func__, interval); + HiLog::Debug(LABEL, "%{public}s interval is %{public}lld", __func__, interval); } int32_t ret = SubscribeSensor(sensorTypeId, interval, DataCallbackImpl); if (ret != OHOS::ERR_OK) { diff --git a/services/sensor/hdi_connection/adapter/include/hdi_connection.h b/services/sensor/hdi_connection/adapter/include/hdi_connection.h index 95cd5516..b5f26cb5 100644 --- a/services/sensor/hdi_connection/adapter/include/hdi_connection.h +++ b/services/sensor/hdi_connection/adapter/include/hdi_connection.h @@ -53,7 +53,6 @@ public: sptr getReportDataCallback(); void ProcessDeathObserver(const wptr &object); - private: DISALLOW_COPY_AND_MOVE(HdiConnection); static ZReportDataCb reportDataCb_; diff --git a/services/sensor/hdi_connection/adapter/src/hdi_connection.cpp b/services/sensor/hdi_connection/adapter/src/hdi_connection.cpp index af655e30..978d5a5e 100644 --- a/services/sensor/hdi_connection/adapter/src/hdi_connection.cpp +++ b/services/sensor/hdi_connection/adapter/src/hdi_connection.cpp @@ -35,8 +35,8 @@ sptr sensorInterface_ = nullptr; sptr eventCallback_ = nullptr; std::map sensorBasicInfoMap_; std::mutex sensorBasicInfoMutex_; -constexpr int32_t GET_HDI_SERVICE_COUNT = 30; -constexpr uint32_t WAIT_MS = 200; +constexpr int32_t GET_HDI_SERVICE_COUNT = 10; +constexpr uint32_t WAIT_MS = 100; } ZReportDataCb HdiConnection::reportDataCb_ = nullptr; diff --git a/services/sensor/hdi_connection/hardware/include/hdi_service_impl.h b/services/sensor/hdi_connection/hardware/include/hdi_service_impl.h index 9c9d041e..46399700 100644 --- a/services/sensor/hdi_connection/hardware/include/hdi_service_impl.h +++ b/services/sensor/hdi_connection/hardware/include/hdi_service_impl.h @@ -52,7 +52,7 @@ public: private: DISALLOW_COPY_AND_MOVE(HdiServiceImpl); static void DataReportThread(); - std::vector g_enableSensors; + std::vector g_enableSensos; std::thread dataReportThread_; static RecordDataCallback g_callback; static int64_t g_samplingInterval; diff --git a/services/sensor/hdi_connection/hardware/src/hdi_service_impl.cpp b/services/sensor/hdi_connection/hardware/src/hdi_service_impl.cpp index a4c0f50f..65842fb9 100644 --- a/services/sensor/hdi_connection/hardware/src/hdi_service_impl.cpp +++ b/services/sensor/hdi_connection/hardware/src/hdi_service_impl.cpp @@ -70,15 +70,15 @@ int32_t HdiServiceImpl::EnableSensor(uint32_t sensorId) HiLog::Error(LABEL, "%{public}s enable sensor failed", __func__); return -1; } - if (std::find(supportSensors.begin(), supportSensors.end(), sensorId) == supportSensors.end()) { + if (std::count(supportSensors.begin(), supportSensors.end(), sensorId) == 0) { HiLog::Error(LABEL, "%{public}s not support enable sensorId: %{public}d", __func__, sensorId); - return ERR_NO_INIT; + return -1; } - if (std::find(g_enableSensors.begin(), g_enableSensors.end(), sensorId) != g_enableSensors.end()) { + if (std::count(g_enableSensos.begin(), g_enableSensos.end(), sensorId) != 0) { HiLog::Info(LABEL, "%{public}s sensorId: %{public}d has been enabled", __func__, sensorId); return ERR_OK; } - g_enableSensors.push_back(sensorId); + g_enableSensos.push_back(sensorId); if (!dataReportThread_.joinable() || g_isStop) { if (dataReportThread_.joinable()) { dataReportThread_.join(); @@ -93,22 +93,17 @@ int32_t HdiServiceImpl::EnableSensor(uint32_t sensorId) int32_t HdiServiceImpl::DisableSensor(uint32_t sensorId) { HiLog::Info(LABEL, "%{public}s in", __func__); - if (std::find(supportSensors.begin(), supportSensors.end(), sensorId) == supportSensors.end()) { + if (std::count(supportSensors.begin(), supportSensors.end(), sensorId) == 0) { HiLog::Error(LABEL, "%{public}s not support disable sensorId: %{public}d", __func__, sensorId); - return ERR_NO_INIT; + return -1; } - if (std::find(g_enableSensors.begin(), g_enableSensors.end(), sensorId) == g_enableSensors.end()) { + if (std::count(g_enableSensos.begin(), g_enableSensos.end(), sensorId) == 0) { HiLog::Error(LABEL, "%{public}s sensorId: %{public}d should be enable first", __func__, sensorId); - return ERR_NO_INIT; - } - std::vector::iterator iter; - for (iter = g_enableSensors.begin(); iter != g_enableSensors.end(); ++iter) { - if (*iter == sensorId) { - g_enableSensors.erase(iter++); - break; - } + return -1; } - if (g_enableSensors.empty()) { + auto iter = std::remove(g_enableSensos.begin(), g_enableSensos.end(), sensorId); + g_enableSensos.erase(iter, g_enableSensos.end()); + if (g_enableSensos.empty()) { g_isStop = true; } return ERR_OK; diff --git a/services/sensor/hdi_connection/interface/src/sensor_hdi_connection.cpp b/services/sensor/hdi_connection/interface/src/sensor_hdi_connection.cpp index 0d5c04fd..78e63162 100644 --- a/services/sensor/hdi_connection/interface/src/sensor_hdi_connection.cpp +++ b/services/sensor/hdi_connection/interface/src/sensor_hdi_connection.cpp @@ -22,6 +22,7 @@ namespace OHOS { namespace Sensors { using namespace OHOS::HiviewDFX; + namespace { constexpr HiLogLabel LABEL = { LOG_CORE, SensorsLogDomain::SENSOR_SERVICE, "SensorHdiConnection" }; } @@ -29,10 +30,6 @@ constexpr HiLogLabel LABEL = { LOG_CORE, SensorsLogDomain::SENSOR_SERVICE, "Sens int32_t SensorHdiConnection::ConnectHdi() { iSensorHdiConnection_ = std::make_unique(); - if (iSensorHdiConnection_ == nullptr) { - HiLog::Error(LABEL, "%{public}s failed, iSensorHdiConnection_ cannot be null", __func__); - return ERROR; - } int32_t ret = connectHdiService(); if (ret != ERR_OK) { HiLog::Error(LABEL, "%{public}s connect hdi service failed, try to connect compatible connection", diff --git a/services/sensor/src/sensor_dump.cpp b/services/sensor/src/sensor_dump.cpp index c41921c4..7c4c7281 100644 --- a/services/sensor/src/sensor_dump.cpp +++ b/services/sensor/src/sensor_dump.cpp @@ -144,10 +144,10 @@ bool SensorDump::DumpSensorList(int32_t fd, const std::vector &sensors, auto sensorId = sensor.GetSensorId(); dprintf(fd, "sensorId:%8u | sensorType:%s | sensorName:%s | vendorName:%s | maxRange:%f" - "| fifoMaxEventCount:%d | minSamplePeriodNs:%" PRId64 " | maxSamplePeriodNs:%" PRId64 "\n", + "| fifoMaxEventCount:%d | minSamplePeriodNs:%lld | maxSamplePeriodNs:%lld\n", sensorId, sensorMap_[sensorId].c_str(), sensor.GetSensorName().c_str(), sensor.GetVendorName().c_str(), - sensor.GetMaxRange(), sensor.GetFifoMaxEventCount(), sensor.GetMinSamplePeriodNs(), - sensor.GetMaxSamplePeriodNs()); + sensor.GetMaxRange(), sensor.GetFifoMaxEventCount(), (long long) { sensor.GetMinSamplePeriodNs() }, + (long long) { sensor.GetMaxSamplePeriodNs() }); } return true; } diff --git a/services/sensor/src/sensor_service.cpp b/services/sensor/src/sensor_service.cpp index 81f2eeaa..f2145bb8 100644 --- a/services/sensor/src/sensor_service.cpp +++ b/services/sensor/src/sensor_service.cpp @@ -236,7 +236,7 @@ ErrCode SensorService::SaveSubscriber(uint32_t sensorId, int64_t samplingPeriodN ErrCode SensorService::EnableSensor(uint32_t sensorId, int64_t samplingPeriodNs, int64_t maxReportDelayNs) { - HiLog::Debug(LABEL, "%{public}s begin, sensorId : %{public}u, samplingPeriodNs : %{public}" + HiLog::Debug(LABEL, "%{public}s begin, sensorId : %{public}u, samplingPeriodNs : %{public}" PRId64, __func__, sensorId, samplingPeriodNs); if ((sensorId == INVALID_SENSOR_ID) || ((samplingPeriodNs != 0L) && ((maxReportDelayNs / samplingPeriodNs) > MAX_EVENT_COUNT))) { diff --git a/utils/include/sensors_errors.h b/utils/include/sensors_errors.h index d6e5ec6f..38a2d16b 100644 --- a/utils/include/sensors_errors.h +++ b/utils/include/sensors_errors.h @@ -17,7 +17,6 @@ #define SENSORS_ERRORS_H #include -#include "hilog/log.h" namespace OHOS { namespace Sensors { @@ -106,23 +105,6 @@ enum { SENSOR_NATIVE_GET_SERVICE_ERR = SENSOR_NATIVE_SAM_ERR + 1, SENSOR_NATIVE_REGSITER_CB_ERR = SENSOR_NATIVE_GET_SERVICE_ERR + 1, }; - -class InnerFunctionTracer { -public: - InnerFunctionTracer(const OHOS::HiviewDFX::HiLogLabel& label, const char *func) - : label_ { label }, func_ { func } - { - OHOS::HiviewDFX::HiLog::Debug(label_, "in %{public}s, enter", func_); - } - ~InnerFunctionTracer() - { - OHOS::HiviewDFX::HiLog::Debug(label_, "in %{public}s, leave", func_); - } -private: - const OHOS::HiviewDFX::HiLogLabel& label_; - const char* func_ { nullptr }; -}; } // namespace Sensors } // namespace OHOS -#define CALL_LOG_ENTER InnerFunctionTracer ___innerFuncTracer___ { LABEL, __FUNCTION__ } #endif // SENSORS_ERRORS_H -- Gitee