From a825f11e4918526147e92389e9d160a8a3e5b4d7 Mon Sep 17 00:00:00 2001 From: li-yaoyao777 Date: Sat, 28 Dec 2024 10:38:24 +0800 Subject: [PATCH] Modified 5.0.2 branch differences Signed-off-by: li-yaoyao777 --- frameworks/native/src/sensor_agent_proxy.cpp | 7 ++-- frameworks/native/src/sensor_data_channel.cpp | 3 ++ .../src/sensor_file_descriptor_listener.cpp | 5 +++ .../native/src/sensor_service_client.cpp | 9 +++-- .../adapter/src/hdi_connection.cpp | 8 +++++ .../adapter/src/sensor_event_callback.cpp | 5 ++- services/include/sensor_service.h | 3 +- services/src/client_info.cpp | 35 +++++++++++++------ services/src/sensor_data_processer.cpp | 8 +++++ services/src/sensor_manager.cpp | 17 ++++++--- services/src/sensor_service.cpp | 18 +++++++--- utils/common/include/print_sensor_data.h | 1 + utils/common/src/print_sensor_data.cpp | 25 +++++++++++-- .../common/src/sensor_basic_data_channel.cpp | 2 ++ 14 files changed, 115 insertions(+), 31 deletions(-) diff --git a/frameworks/native/src/sensor_agent_proxy.cpp b/frameworks/native/src/sensor_agent_proxy.cpp index 188489b2..c2a5aa78 100644 --- a/frameworks/native/src/sensor_agent_proxy.cpp +++ b/frameworks/native/src/sensor_agent_proxy.cpp @@ -81,6 +81,9 @@ void SensorAgentProxy::HandleSensorData(SensorEvent *events, auto callbacks = GetSubscribeUserCallback(eventStream.sensorTypeId); for (const auto &callback : callbacks) { CHKPV(callback); + if (eventStream.sensorTypeId == SENSOR_TYPE_ID_HALL_EXT) { + PrintSensorData::GetInstance().ControlSensorClientPrint(callback, eventStream); + } callback(&eventStream); PrintSensorData::GetInstance().ControlSensorClientPrint(callback, eventStream); } @@ -197,7 +200,7 @@ int32_t SensorAgentProxy::DeactivateSensor(int32_t sensorId, const SensorUser *u } auto status = unsubscribeMap_[sensorId].insert(user); if (!status.second) { - SEN_HILOGD("User has been unsubscribed"); + SEN_HILOGE("User has been unsubscribed"); } subscribeSet.erase(user); if (subscribeSet.empty()) { @@ -255,7 +258,7 @@ int32_t SensorAgentProxy::SubscribeSensor(int32_t sensorId, const SensorUser *us std::lock_guard subscribeLock(subscribeMutex_); auto status = subscribeMap_[sensorId].insert(user); if (!status.second) { - SEN_HILOGD("User has been subscribed"); + SEN_HILOGE("User has been unsubscribed"); } if (PrintSensorData::GetInstance().IsContinuousType(sensorId)) { PrintSensorData::GetInstance().SavePrintUserInfo(user->callback); diff --git a/frameworks/native/src/sensor_data_channel.cpp b/frameworks/native/src/sensor_data_channel.cpp index 4a2bfc13..4ea4674c 100644 --- a/frameworks/native/src/sensor_data_channel.cpp +++ b/frameworks/native/src/sensor_data_channel.cpp @@ -30,6 +30,7 @@ using namespace OHOS::AppExecFwk; int32_t SensorDataChannel::CreateSensorDataChannel(DataChannelCB callBack, void *data) { + SEN_HILOGI("In"); CHKPR(callBack, SENSOR_NATIVE_REGSITER_CB_ERR); dataCB_ = callBack; privateData_ = data; @@ -48,6 +49,7 @@ int32_t SensorDataChannel::RestoreSensorDataChannel() int32_t SensorDataChannel::InnerSensorDataChannel() { + SEN_HILOGI("In"); std::lock_guard eventRunnerLock(eventRunnerMutex_); // create basic data channel int32_t ret = CreateSensorBasicChannel(); @@ -74,6 +76,7 @@ int32_t SensorDataChannel::InnerSensorDataChannel() SEN_HILOGE("ListenedFdSet insert fd fail, fd:%{public}d", receiveFd); return ERROR; } + SEN_HILOGI("Done"); return ERR_OK; } diff --git a/frameworks/native/src/sensor_file_descriptor_listener.cpp b/frameworks/native/src/sensor_file_descriptor_listener.cpp index a3ea247a..e451b7b3 100644 --- a/frameworks/native/src/sensor_file_descriptor_listener.cpp +++ b/frameworks/native/src/sensor_file_descriptor_listener.cpp @@ -14,6 +14,7 @@ */ #include "sensor_file_descriptor_listener.h" +#include "print_sensor_data.h" #include "sensor_agent_type.h" #include "sensor_basic_data_channel.h" #include "sensor_errors.h" @@ -76,12 +77,16 @@ void SensorFileDescriptorListener::ExcuteCallback(int32_t length) .data = receiveDataBuff_[i].data, .dataLen = receiveDataBuff_[i].dataLen }; + if (receiveDataBuff_[i].sensorTypeId == SENSOR_TYPE_ID_HALL_EXT) { + PrintSensorData::GetInstance().PrintSensorDataLog("ExcuteCallback", receiveDataBuff_[i]); + } channel_->dataCB_(&event, 1, channel_->privateData_); } } void SensorFileDescriptorListener::SetChannel(SensorDataChannel *channel) { + SEN_HILOGI("In"); channel_ = channel; } diff --git a/frameworks/native/src/sensor_service_client.cpp b/frameworks/native/src/sensor_service_client.cpp index 1df5ead9..5529438c 100644 --- a/frameworks/native/src/sensor_service_client.cpp +++ b/frameworks/native/src/sensor_service_client.cpp @@ -177,7 +177,7 @@ std::vector SensorServiceClient::GetSensorList() int32_t SensorServiceClient::TransferDataChannel(sptr sensorDataChannel) { - CALL_LOG_ENTER; + SEN_HILOGI("In"); CHKPR(sensorDataChannel, INVALID_POINTER); { std::lock_guard channelLock(channelMutex_); @@ -196,6 +196,7 @@ int32_t SensorServiceClient::TransferDataChannel(sptr sensorD CHKPR(remoteObject, INVALID_POINTER); ret = sensorServer_->TransferDataChannel(sensorDataChannel, remoteObject); FinishTrace(HITRACE_TAG_SENSORS); + SEN_HILOGI("Done"); return ret; } @@ -279,24 +280,26 @@ void SensorServiceClient::ProcessDeathObserver(const wptr &object void SensorServiceClient::UpdateSensorInfoMap(int32_t sensorId, int64_t samplingPeriod, int64_t maxReportDelay) { - CALL_LOG_ENTER; + SEN_HILOGI("In"); SensorBasicInfo sensorInfo; sensorInfo.SetSamplingPeriodNs(samplingPeriod); sensorInfo.SetMaxReportDelayNs(maxReportDelay); sensorInfo.SetSensorState(true); std::lock_guard mapLock(mapMutex_); sensorInfoMap_[sensorId] = sensorInfo; + SEN_HILOGI("Done"); return; } void SensorServiceClient::DeleteSensorInfoItem(int32_t sensorId) { - CALL_LOG_ENTER; + SEN_HILOGI("In"); std::lock_guard mapLock(mapMutex_); auto it = sensorInfoMap_.find(sensorId); if (it != sensorInfoMap_.end()) { sensorInfoMap_.erase(it); } + SEN_HILOGI("Done"); return; } diff --git a/services/hdi_connection/adapter/src/hdi_connection.cpp b/services/hdi_connection/adapter/src/hdi_connection.cpp index c186868f..7a61a5b1 100644 --- a/services/hdi_connection/adapter/src/hdi_connection.cpp +++ b/services/hdi_connection/adapter/src/hdi_connection.cpp @@ -111,6 +111,7 @@ int32_t HdiConnection::GetSensorList(std::vector &sensorList) int32_t HdiConnection::EnableSensor(int32_t sensorId) { + SEN_HILOGI("In, sensorId:%{public}d", sensorId); CHKPR(g_sensorInterface, ERR_NO_INIT); int32_t ret = g_sensorInterface->Enable(sensorId); if (ret != 0) { @@ -120,11 +121,13 @@ int32_t HdiConnection::EnableSensor(int32_t sensorId) return ret; } SetSensorBasicInfoState(sensorId, true); + SEN_HILOGI("Done, sensorId:%{public}d", sensorId); return ERR_OK; } int32_t HdiConnection::DisableSensor(int32_t sensorId) { + SEN_HILOGI("In, sensorId:%{public}d", sensorId); CHKPR(g_sensorInterface, ERR_NO_INIT); int32_t ret = g_sensorInterface->Disable(sensorId); if (ret != 0) { @@ -134,6 +137,7 @@ int32_t HdiConnection::DisableSensor(int32_t sensorId) return ret; } DeleteSensorBasicInfoState(sensorId); + SEN_HILOGI("Done, sensorId:%{public}d", sensorId); return ERR_OK; } @@ -231,6 +235,7 @@ void HdiConnection::UpdateSensorBasicInfo(int32_t sensorId, int64_t samplingPeri void HdiConnection::SetSensorBasicInfoState(int32_t sensorId, bool state) { + SEN_HILOGI("In, sensorId:%{public}d", sensorId); std::lock_guard sensorInfoLock(g_sensorBasicInfoMutex); auto it = g_sensorBasicInfoMap.find(sensorId); if (it == g_sensorBasicInfoMap.end()) { @@ -238,15 +243,18 @@ void HdiConnection::SetSensorBasicInfoState(int32_t sensorId, bool state) return; } g_sensorBasicInfoMap[sensorId].SetSensorState(state); + SEN_HILOGI("Done, sensorId:%{public}d", sensorId); } void HdiConnection::DeleteSensorBasicInfoState(int32_t sensorId) { + SEN_HILOGI("In, sensorId:%{public}d", sensorId); std::lock_guard sensorInfoLock(g_sensorBasicInfoMutex); auto it = g_sensorBasicInfoMap.find(sensorId); if (it != g_sensorBasicInfoMap.end()) { g_sensorBasicInfoMap.erase(sensorId); } + SEN_HILOGI("Done, sensorId:%{public}d", sensorId); } void HdiConnection::RegisterHdiDeathRecipient() diff --git a/services/hdi_connection/adapter/src/sensor_event_callback.cpp b/services/hdi_connection/adapter/src/sensor_event_callback.cpp index 93a021f8..70b96e50 100644 --- a/services/hdi_connection/adapter/src/sensor_event_callback.cpp +++ b/services/hdi_connection/adapter/src/sensor_event_callback.cpp @@ -83,8 +83,11 @@ int32_t SensorEventCallback::OnDataEvent(const HdfSensorEvents &event) PrintSensorData::GetInstance().ControlSensorHdiPrint(sensorData); std::unique_lock lk(ISensorHdiConnection::dataMutex_); (void)(reportDataCallback_->*(reportDataCb_))(&sensorData, reportDataCallback_); + if (sensorData.sensorTypeId == SENSOR_TYPE_ID_HALL_EXT) { + SEN_HILOGI("dataCondition notify one sensorId: %{public}d", sensorData.sensorTypeId); + } ISensorHdiConnection::dataCondition_.notify_one(); return ERR_OK; } } // namespace Sensors -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/services/include/sensor_service.h b/services/include/sensor_service.h index 174aec47..d493aab8 100644 --- a/services/include/sensor_service.h +++ b/services/include/sensor_service.h @@ -86,7 +86,8 @@ private: void UnregisterClientDeathRecipient(sptr sensorClient); bool InitSensorPolicy(); void ReportOnChangeData(int32_t sensorId); - void ReportSensorSysEvent(int32_t sensorId, bool enable, int32_t pid); + void ReportSensorSysEvent(int32_t sensorId, bool enable, int32_t pid, int64_t samplingPeriodNs = 0, + int64_t maxReportDelayNs = 0); ErrCode DisableSensor(int32_t sensorId, int32_t pid); bool RegisterPermCallback(int32_t sensorId); void UnregisterPermCallback(); diff --git a/services/src/client_info.cpp b/services/src/client_info.cpp index 4f9b6daa..e9640068 100644 --- a/services/src/client_info.cpp +++ b/services/src/client_info.cpp @@ -40,7 +40,7 @@ constexpr int32_t MIN_MAP_SIZE = 0; constexpr uint32_t NO_STORE_EVENT = -2; constexpr uint32_t MAX_SUPPORT_CHANNEL = 200; constexpr uint32_t MAX_DUMP_DATA_SIZE = 10; -} // namespace +} // namespace std::unordered_map> ClientInfo::userGrantPermMap_ = { { ACTIVITY_MOTION_PERMISSION, { SENSOR_TYPE_ID_PEDOMETER_DETECTION, SENSOR_TYPE_ID_PEDOMETER } }, @@ -49,7 +49,7 @@ std::unordered_map> ClientInfo::userGrantPermMap_ bool ClientInfo::GetSensorState(int32_t sensorId) { - CALL_LOG_ENTER; + SEN_HILOGI("In, sensorId:%{public}d", sensorId); if (sensorId == INVALID_SENSOR_ID) { SEN_HILOGE("sensorId is invalid"); return false; @@ -100,7 +100,7 @@ SensorBasicInfo ClientInfo::GetBestSensorInfo(int32_t sensorId) bool ClientInfo::OnlyCurPidSensorEnabled(int32_t sensorId, int32_t pid) { - CALL_LOG_ENTER; + SEN_HILOGI("In, sensorId:%{public}d, pid:%{public}d", sensorId, pid); if ((sensorId == INVALID_SENSOR_ID) || (pid <= INVALID_PID)) { SEN_HILOGE("sensorId or pid is invalid"); return false; @@ -122,12 +122,13 @@ bool ClientInfo::OnlyCurPidSensorEnabled(int32_t sensorId, int32_t pid) } ret = true; } + SEN_HILOGI("Done, sensorId:%{public}d, pid:%{public}d", sensorId, pid); return ret; } bool ClientInfo::UpdateAppThreadInfo(int32_t pid, int32_t uid, AccessTokenID callerToken) { - CALL_LOG_ENTER; + SEN_HILOGI("In, pid:%{public}d", pid); if ((uid == INVALID_UID) || (pid <= INVALID_PID)) { SEN_HILOGE("uid or pid is invalid"); return false; @@ -144,12 +145,13 @@ bool ClientInfo::UpdateAppThreadInfo(int32_t pid, int32_t uid, AccessTokenID cal return ret.second; } appThreadInfoMap_[pid] = appThreadInfo; + SEN_HILOGI("Done, pid:%{public}d", pid); return true; } void ClientInfo::DestroyAppThreadInfo(int32_t pid) { - CALL_LOG_ENTER; + SEN_HILOGI("In, pid:%{public}d", pid); if (pid == INVALID_PID) { SEN_HILOGE("pid is invalid"); return; @@ -161,11 +163,12 @@ void ClientInfo::DestroyAppThreadInfo(int32_t pid) return; } appThreadInfoMap_.erase(appThreadInfoItr); + SEN_HILOGI("Done, pid:%{public}d", pid); } std::vector> ClientInfo::GetSensorChannelByUid(int32_t uid) { - CALL_LOG_ENTER; + SEN_HILOGI("In"); if (uid == INVALID_UID) { SEN_HILOGE("uid is invalid"); return {}; @@ -183,12 +186,13 @@ std::vector> ClientInfo::GetSensorChannelByUid(int3 } sensorChannel.push_back(channelIt->second); } + SEN_HILOGI("Done"); return sensorChannel; } sptr ClientInfo::GetSensorChannelByPid(int32_t pid) { - CALL_LOG_ENTER; + SEN_HILOGI("In, pid:%{public}d", pid); if (pid == INVALID_PID) { SEN_HILOGE("pid is invalid"); return nullptr; @@ -199,6 +203,7 @@ sptr ClientInfo::GetSensorChannelByPid(int32_t pid) SEN_HILOGE("There is no channel belong to the pid"); return nullptr; } + SEN_HILOGI("Done, pid:%{public}d", pid); return channelIt->second; } @@ -231,7 +236,7 @@ std::vector> ClientInfo::GetSensorChannel(int32_t s bool ClientInfo::UpdateSensorInfo(int32_t sensorId, int32_t pid, const SensorBasicInfo &sensorInfo) { - CALL_LOG_ENTER; + SEN_HILOGI("In, sensorId:%{public}d, pid:%{public}d", sensorId, pid); if ((sensorId == INVALID_SENSOR_ID) || (pid <= INVALID_PID) || (!sensorInfo.GetSensorState())) { SEN_HILOGE("Params are invalid"); return false; @@ -250,11 +255,13 @@ bool ClientInfo::UpdateSensorInfo(int32_t sensorId, int32_t pid, const SensorBas return ret.second; } it->second[pid] = sensorInfo; + SEN_HILOGI("Done, sensorId:%{public}d, pid:%{public}d", sensorId, pid); return true; } void ClientInfo::RemoveSubscriber(int32_t sensorId, uint32_t pid) { + SEN_HILOGI("In, sensorId:%{public}d, pid:%{public}u", sensorId, pid); std::lock_guard clientLock(clientMutex_); auto it = clientMap_.find(sensorId); if (it == clientMap_.end()) { @@ -265,10 +272,12 @@ void ClientInfo::RemoveSubscriber(int32_t sensorId, uint32_t pid) if (pidIt != it->second.end()) { it->second.erase(pidIt); } + SEN_HILOGI("Done, sensorId:%{public}d, pid:%{public}d", sensorId, pid); } bool ClientInfo::UpdateSensorChannel(int32_t pid, const sptr &channel) { + SEN_HILOGI("In, pid:%{public}d", pid); CALL_LOG_ENTER; CHKPR(channel, false); if (pid <= INVALID_PID) { @@ -287,11 +296,13 @@ bool ClientInfo::UpdateSensorChannel(int32_t pid, const sptrsecond.size() == MIN_MAP_SIZE) { it = clientMap_.erase(it); } + SEN_HILOGI("Done, sensorId:%{public}d, pid:%{public}d", sensorId, pid); } bool ClientInfo::DestroySensorChannel(int32_t pid) @@ -798,5 +811,5 @@ void ClientInfo::ChangeSensorPerm(AccessTokenID tokenId, const std::string &perm UpdatePermState(pid, sensorId, state); } } -} // namespace Sensors -} // namespace OHOS +} // namespace Sensors +} // namespace OHOS diff --git a/services/src/sensor_data_processer.cpp b/services/src/sensor_data_processer.cpp index 6ea5c6c8..fcd801ad 100644 --- a/services/src/sensor_data_processer.cpp +++ b/services/src/sensor_data_processer.cpp @@ -21,6 +21,7 @@ #include #include "hisysevent.h" +#include "print_sensor_data.h" #include "permission_util.h" #include "securec.h" #include "sensor_basic_data_channel.h" @@ -162,12 +163,16 @@ void SensorDataProcesser::ReportData(sptr &channel, Sens { CHKPV(channel); int32_t sensorId = data.sensorTypeId; + if (sensorId == SENSOR_TYPE_ID_HALL_EXT) { + PrintSensorData::GetInstance().PrintSensorDataLog("ReportData", data); + } auto &cacheBuf = const_cast &>(channel->GetDataCacheBuf()); if (ReportNotContinuousData(cacheBuf, channel, data)) { return; } uint64_t periodCount = clientInfo_.ComputeBestPeriodCount(sensorId, channel); if (periodCount == 0UL) { + SEN_HILOGE("periodCount is zero"); return; } auto fifoCount = clientInfo_.ComputeBestFifoCount(sensorId, channel); @@ -193,6 +198,9 @@ bool SensorDataProcesser::ReportNotContinuousData(std::unordered_mapsecond.GetFlags()) == SENSOR_ONE_SHOT)) { std::vector sendEvents; sendEvents.push_back(data); + if (sensorId == SENSOR_TYPE_ID_HALL_EXT) { + PrintSensorData::GetInstance().PrintSensorDataLog("ReportNotContinuousData", data); + } SendRawData(cacheBuf, channel, sendEvents); return true; } diff --git a/services/src/sensor_manager.cpp b/services/src/sensor_manager.cpp index 18d7897b..b245fa5e 100644 --- a/services/src/sensor_manager.cpp +++ b/services/src/sensor_manager.cpp @@ -35,7 +35,7 @@ constexpr int32_t INVALID_SENSOR_ID = -1; #endif // HDF_DRIVERS_INTERFACE_SENSOR constexpr uint32_t PROXIMITY_SENSOR_ID = 50331904; constexpr float PROXIMITY_FAR = 5.0; -} // namespace +} // namespace #ifdef HDF_DRIVERS_INTERFACE_SENSOR void SensorManager::InitSensorMap(const std::unordered_map &sensorMap, @@ -50,7 +50,7 @@ void SensorManager::InitSensorMap(const std::unordered_map &sen bool SensorManager::SetBestSensorParams(int32_t sensorId, int64_t samplingPeriodNs, int64_t maxReportDelayNs) { - CALL_LOG_ENTER; + SEN_HILOGI("In, sensorId:%{public}d", sensorId); if (sensorId == INVALID_SENSOR_ID) { SEN_HILOGE("sensorId is invalid"); return false; @@ -70,12 +70,13 @@ bool SensorManager::SetBestSensorParams(int32_t sensorId, int64_t samplingPeriod SEN_HILOGE("SetBatch is failed"); return false; } + SEN_HILOGI("Done, sensorId:%{public}d", sensorId); return true; } bool SensorManager::ResetBestSensorParams(int32_t sensorId) { - CALL_LOG_ENTER; + SEN_HILOGI("In, sensorId:%{public}d", sensorId); if (sensorId == INVALID_SENSOR_ID) { SEN_HILOGE("sensorId is invalid"); return false; @@ -87,6 +88,7 @@ bool SensorManager::ResetBestSensorParams(int32_t sensorId) SEN_HILOGE("SetBatch is failed"); return false; } + SEN_HILOGI("Done, sensorId:%{public}d", sensorId); return true; } @@ -111,17 +113,19 @@ void SensorManager::InitSensorMap(const std::unordered_map &sen bool SensorManager::SaveSubscriber(int32_t sensorId, uint32_t pid, int64_t samplingPeriodNs, int64_t maxReportDelayNs) { + SEN_HILOGI("In, sensorId:%{public}d, pid:%{public}u", sensorId, pid); SensorBasicInfo sensorInfo = GetSensorInfo(sensorId, samplingPeriodNs, maxReportDelayNs); if (!clientInfo_.UpdateSensorInfo(sensorId, pid, sensorInfo)) { SEN_HILOGE("UpdateSensorInfo is failed"); return false; } + SEN_HILOGI("Done, sensorId:%{public}d, pid:%{public}u", sensorId, pid); return true; } SensorBasicInfo SensorManager::GetSensorInfo(int32_t sensorId, int64_t samplingPeriodNs, int64_t maxReportDelayNs) { - CALL_LOG_ENTER; + SEN_HILOGI("In, sensorId:%{public}d", sensorId); SensorBasicInfo sensorInfo; std::lock_guard sensorMapLock(sensorMapMutex_); auto it = sensorMap_.find(sensorId); @@ -144,6 +148,7 @@ SensorBasicInfo SensorManager::GetSensorInfo(int32_t sensorId, int64_t samplingP sensorInfo.SetSamplingPeriodNs(curSamplingPeriodNs); sensorInfo.SetMaxReportDelayNs(curReportDelayNs); sensorInfo.SetSensorState(true); + SEN_HILOGI("In, sensorId:%{public}d", sensorId); return sensorInfo; } @@ -161,12 +166,13 @@ bool SensorManager::IsOtherClientUsingSensor(int32_t sensorId, int32_t clientPid } #endif // HDF_DRIVERS_INTERFACE_SENSOR SEN_HILOGD("Other client is using this sensor"); + SEN_HILOGI("Done, sensorId:%{public}d, clientPid:%{public}d", sensorId, clientPid); return true; } ErrCode SensorManager::AfterDisableSensor(int32_t sensorId) { - CALL_LOG_ENTER; + SEN_HILOGI("In, sensorId:%{public}d", sensorId); clientInfo_.ClearSensorInfo(sensorId); if (sensorId == PROXIMITY_SENSOR_ID) { SensorData sensorData; @@ -177,6 +183,7 @@ ErrCode SensorManager::AfterDisableSensor(int32_t sensorId) clientInfo_.StoreEvent(sensorData); } } + SEN_HILOGI("Done, sensorId:%{public}d", sensorId); return ERR_OK; } diff --git a/services/src/sensor_service.cpp b/services/src/sensor_service.cpp index 8b2f78c3..24cc9331 100644 --- a/services/src/sensor_service.cpp +++ b/services/src/sensor_service.cpp @@ -180,7 +180,8 @@ void SensorService::OnStop() #endif // MEMMGR_ENABLE } -void SensorService::ReportSensorSysEvent(int32_t sensorId, bool enable, int32_t pid) +void SensorService::ReportSensorSysEvent(int32_t sensorId, bool enable, int32_t pid, int64_t samplingPeriodNs, + int64_t maxReportDelayNs) { std::string packageName(""); AccessTokenID tokenId = clientInfo_.GetTokenIdByPid(pid); @@ -190,11 +191,14 @@ void SensorService::ReportSensorSysEvent(int32_t sensorId, bool enable, int32_t if (enable) { HiSysEventWrite(HiSysEvent::Domain::SENSOR, "ENABLE_SENSOR", HiSysEvent::EventType::STATISTIC, "LEVEL", logLevel, "UID", uid, "PKG_NAME", packageName, "TYPE", sensorId); - SEN_HILOGI("PackageName:%{public}s open the sensor, sensorId:%{public}d", packageName.c_str(), sensorId); + SEN_HILOGI("PackageName:%{public}s open the sensor, sensorId:%{public}d, pid:%{public}d, " + "samplingPeriodNs:%{public}" PRId64 ", samplingPeriodNs:%{public}" PRId64, packageName.c_str(), + sensorId, pid, samplingPeriodNs, maxReportDelayNs); } else { HiSysEventWrite(HiSysEvent::Domain::SENSOR, "DISABLE_SENSOR", HiSysEvent::EventType::STATISTIC, "LEVEL", logLevel, "UID", uid, "PKG_NAME", packageName, "TYPE", sensorId); - SEN_HILOGI("PackageName:%{public}s close the sensor, sensorId:%{public}d", packageName.c_str(), sensorId); + SEN_HILOGI("PackageName:%{public}s close the sensor, sensorId:%{public}d, pid:%{public}d", + packageName.c_str(), sensorId, pid); } } @@ -227,6 +231,7 @@ void SensorService::ReportOnChangeData(int32_t sensorId) ErrCode SensorService::SaveSubscriber(int32_t sensorId, int64_t samplingPeriodNs, int64_t maxReportDelayNs) { + SEN_HILOGI("In, sensorId:%{public}d", sensorId); if (!sensorManager_.SaveSubscriber(sensorId, GetCallingPid(), samplingPeriodNs, maxReportDelayNs)) { SEN_HILOGE("SaveSubscriber failed"); return UPDATE_SENSOR_INFO_ERR; @@ -241,6 +246,7 @@ ErrCode SensorService::SaveSubscriber(int32_t sensorId, int64_t samplingPeriodNs return SET_SENSOR_CONFIG_ERR; } #endif // HDF_DRIVERS_INTERFACE_SENSOR + SEN_HILOGI("Done, sensorId:%{public}d", sensorId); return ERR_OK; } @@ -281,7 +287,7 @@ ErrCode SensorService::EnableSensor(int32_t sensorId, int64_t samplingPeriodNs, SEN_HILOGE("SaveSubscriber failed"); return ret; } - ReportSensorSysEvent(sensorId, true, pid); + ReportSensorSysEvent(sensorId, true, pid, samplingPeriodNs, maxReportDelayNs); if (ret != ERR_OK) { SEN_HILOGE("ret:%{public}d", ret); } @@ -309,7 +315,7 @@ ErrCode SensorService::EnableSensor(int32_t sensorId, int64_t samplingPeriodNs, if ((!g_isRegister) && (RegisterPermCallback(sensorId))) { g_isRegister = true; } - ReportSensorSysEvent(sensorId, true, pid); + ReportSensorSysEvent(sensorId, true, pid, samplingPeriodNs, maxReportDelayNs); if (isReportActiveInfo_) { ReportActiveInfo(sensorId, pid); } @@ -372,6 +378,7 @@ std::vector SensorService::GetSensorList() ErrCode SensorService::TransferDataChannel(const sptr &sensorBasicDataChannel, const sptr &sensorClient) { + SEN_HILOGI("In"); CHKPR(sensorBasicDataChannel, ERR_NO_INIT); auto pid = GetCallingPid(); auto uid = GetCallingUid(); @@ -386,6 +393,7 @@ ErrCode SensorService::TransferDataChannel(const sptr &s } sensorBasicDataChannel->SetSensorStatus(true); RegisterClientDeathRecipient(sensorClient, pid); + SEN_HILOGI("Done"); return ERR_OK; } diff --git a/utils/common/include/print_sensor_data.h b/utils/common/include/print_sensor_data.h index 39970692..d91a4db5 100644 --- a/utils/common/include/print_sensor_data.h +++ b/utils/common/include/print_sensor_data.h @@ -37,6 +37,7 @@ public: bool IsContinuousType(int32_t sensorId); void SavePrintUserInfo(const RecordSensorCallback callback); void RemovePrintUserInfo(const RecordSensorCallback callback); + void PrintSensorDataLog(const std::string &name, const SensorData &data); private: void PrintClientData(const SensorEvent &event); diff --git a/utils/common/src/print_sensor_data.cpp b/utils/common/src/print_sensor_data.cpp index 45881fdb..98feca68 100644 --- a/utils/common/src/print_sensor_data.cpp +++ b/utils/common/src/print_sensor_data.cpp @@ -85,8 +85,8 @@ void PrintSensorData::PrintHdiData(const SensorData &sensorData) str += "timestamp: " + std::to_string(sensorData.timestamp / LOG_FORMAT_DIVIDER) + ", "; int32_t dataDim = GetDataDimension(sensorData.sensorTypeId); auto data = reinterpret_cast(sensorData.data); - CHKPV(data); for (int32_t i = 0; i < dataDim; ++i) { + CHKPV(data); str.append(std::to_string(*data)); if (i != dataDim - 1) { str.append(", "); @@ -157,8 +157,8 @@ void PrintSensorData::PrintClientData(const SensorEvent &event) str += "timestamp: " + std::to_string(event.timestamp / LOG_FORMAT_DIVIDER) + ", "; int32_t dataDim = GetDataDimension(event.sensorTypeId); auto data = reinterpret_cast(event.data); - CHKPV(data); for (int32_t i = 0; i < dataDim; ++i) { + CHKPV(data); str.append(std::to_string(*data)); if (i != dataDim - 1) { str.append(", "); @@ -209,5 +209,24 @@ void PrintSensorData::ResetHdiCounter(int32_t sensorId) it->second.count = 0; it->second.lastTime = 0; } + +void PrintSensorData::PrintSensorDataLog(const std::string &name, const SensorData &data) +{ + std::string str; + str += "sensorId: " + std::to_string(data.sensorTypeId) + ", "; + str += "timestamp: " + std::to_string(data.timestamp / LOG_FORMAT_DIVIDER) + ", "; + int32_t dataDim = GetDataDimension(data.sensorTypeId); + auto tempData = reinterpret_cast(data.data); + for (int32_t i = 0; i < dataDim; ++i) { + CHKPV(tempData); + str.append(std::to_string(*tempData)); + if (i != dataDim - 1) { + str.append(", "); + } + ++tempData; + } + str.append("\n"); + SEN_HILOGI("%{public}s SensorData: %{public}s", name.c_str(), str.c_str()); +} } // namespace Sensors -} // namespace OHOS +} // namespace OHOS \ No newline at end of file diff --git a/utils/common/src/sensor_basic_data_channel.cpp b/utils/common/src/sensor_basic_data_channel.cpp index dab19291..f64af8e3 100644 --- a/utils/common/src/sensor_basic_data_channel.cpp +++ b/utils/common/src/sensor_basic_data_channel.cpp @@ -45,6 +45,7 @@ SensorBasicDataChannel::SensorBasicDataChannel() : sendFd_(-1), receiveFd_(-1), int32_t SensorBasicDataChannel::CreateSensorBasicChannel() { + SEN_HILOGI("In"); if ((sendFd_ != -1) || (receiveFd_ != -1)) { SEN_HILOGD("Already create socketpair"); return ERR_OK; @@ -86,6 +87,7 @@ int32_t SensorBasicDataChannel::CreateSensorBasicChannel() } sendFd_ = socketPair[0]; receiveFd_ = socketPair[1]; + SEN_HILOGI("Done"); return ERR_OK; CLOSE_SOCK: -- Gitee