diff --git a/interfaces/plugin/include/sensor_napi_utils.h b/interfaces/plugin/include/sensor_napi_utils.h index 24141c147a30172575ac513a45dcc63345277f2a..12d0385b4e4fe78659fb95f47c565ef2fc1610f3 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 74072a2cf2a7ffa67575f5a21af74407aefa00d9..52ccc3af997bb70695a63d2e4eee104e3dd61c57 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 40fb28462e185d6b2ce47df8627da13959ae9aa6..752a498abfb755c26e31e6a510b0545e122ab15f 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/include/client_info.h b/services/sensor/include/client_info.h index 61fee175593735a4a262ef2120c04bc5ce6032e1..bc5369ed6fb68475041cb5524b2a379633f11bce 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 95b0f40a1671782b53c955355e3727b34ade7276..b84b37eec4171fcd53a7302bbe11054c0384b1ad 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); @@ -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 c39ee3e0730762635d1e5fefce32c51189d7f495..e3e11c87d7ff4b7898f25d1cfd6d644e27a26a66 100644 --- a/services/sensor/src/client_info.cpp +++ b/services/sensor/src/client_info.cpp @@ -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 c5cb664642e08a163d1118c9e5de02ab88a48e56..cc1d7788579a44f03a8125ed70ff0d896e204397 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 6ef5503aabd8b21c22258621938c91cf14b0f1d4..7c4c7281657282bfe330ac82db6776dfb9b7444e 100644 --- a/services/sensor/src/sensor_dump.cpp +++ b/services/sensor/src/sensor_dump.cpp @@ -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 1476c1aff8dbdb792b2b8d0c7014b25592a9df29..39aa400ec16eac461a3bea13004d2d5ad625d975 100644 --- a/services/sensor/src/sensor_manager.cpp +++ b/services/sensor/src/sensor_manager.cpp @@ -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 0072026f44a272eaa050be112888e97f9085e2a8..f2145bb86a51ba1f7ff3842e5c30b01f814750aa 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,7 +243,7 @@ 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, SENSOR_ENABLED); std::lock_guard serviceLock(serviceLock_); if (clientInfo_.GetSensorState(sensorId) == SENSOR_ENABLED) { HiLog::Warn(LABEL, "%{public}s sensor has been enabled already", __func__); @@ -285,7 +285,7 @@ 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, SENSOR_DISABLED); std::lock_guard serviceLock(serviceLock_); const int32_t clientPid = this->GetCallingPid(); if (clientPid < 0) {