diff --git a/hisysevent.yaml b/hisysevent.yaml index 5a8c6b1ff93ea9dab7cedbdae4a71985cffcb48d..825e13212c74a6dc2904dd931c95cd61ab115411 100644 --- a/hisysevent.yaml +++ b/hisysevent.yaml @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2025 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -14,9 +14,44 @@ domain: TIME MISC_TIME_STATISTIC_REPORT: - __BASE: {type: STATISTIC, level: MINOR, tag: PowerStats, desc: trigger timer report} - CALLER_PID: {type: INT32, desc: the process id} - CALLER_UID: {type: INT32, desc: the user id} + __BASE: {type: STATISTIC, level: CRITICAL, tag: PowerStats, desc: trigger timer report, preserve: true} TIMER_TYPE: {type: INT32, desc: the timer type} TRIGGER_TIME: {type: INT64, desc: the trigger time} - INTERVAL: {type: INT32, desc: the interval time} \ No newline at end of file + CALLER_UID: {type: INT32, desc: the user id} + INTERVAL: {type: INT32, desc: the interval time} + CALLER_PID: {type: INT32, desc: the process id} + BUNDLE_OR_PROCESS_NAME: {type: STRING, desc: the trigger bundle or process name} + TIMER_SIZE: {type: INT32, desc: Number of trigger with the same timestamp} + +ALARM_COUNT: + __BASE: {type: STATISTIC, level: CRITICAL, desc: Timer quantity statistics, preserve: true} + TIMER_NUM: {type: INT32, desc: timer number} + TOP_UID: {type: INT32, arrsize: 5, desc: The top five UID with the highest timer quantity} + TOP_NUM: {type: INT32, arrsize: 5, desc: The top five timer quantity} + TOP_STRATED_NUM: {type: INT32, arrsize: 5, desc: The number of timers started under the top five UID with the highest quantity} + +BEHAVIOR_TIME: + __BASE: {type: BEHAVIOR, level: CRITICAL, desc: time or timezone behavior, preserve: true} + EVENT_CODE: {type: INT32, desc: event code} + CALLER_UID: {type: INT32, desc: caller uid} + CALLER_NAME: {type: STRING, desc: caller bundle name or process name} + ORIGINAL_TIME: {type: STRING, desc: original time or timezone} + SET_TIME: {type: STRING, desc: set time or timezone} + NTP_TIME: {type: INT64, desc: NTP time} + +BEHAVIOR_TIMER: + __BASE: {type: BEHAVIOR, level: CRITICAL, desc: timer behavior, preserve: true} + EVENT_CODE: {type: INT32, desc: event code} + TIMER_ID: {type: UINT32, desc: timer id} + TRIGGER_TIME: {type: INT64, desc: trigger time} + CALLER_UID: {type: INT32, desc: caller uid} + CALLER_NAME: {type: STRING, desc: caller bundle or process name} + INTERVAL: {type: UINT32, desc: trigger interval} + +FUNC_FAULT: + __BASE: {type: FAULT, level: CRITICAL, desc: Time fault error, preserve: true} + EVENT_CODE: {type: INT32, desc: event code} + ERR_CODE: {type: INT32, desc: error code or system error} + CALLER_UID: {type: INT32, desc: caller uid} + CALLER_NAME: {type: STRING, desc: caller bundle name or process name} + EXTRA: {type: STRING, desc: extra infomation} \ No newline at end of file diff --git a/services/dfx/include/time_sysevent.h b/services/dfx/include/time_sysevent.h index 99fb9af3efad1277963002fb1ff3f9d50157f91d..6b09f84d5aa6327c1531a85842c1812bae650cef 100644 --- a/services/dfx/include/time_sysevent.h +++ b/services/dfx/include/time_sysevent.h @@ -21,7 +21,41 @@ namespace OHOS { namespace MiscServices { -void StatisticReporter(int32_t callerPid, int32_t size, std::shared_ptr timer); +constexpr int32_t START_TIMER_OFFSET = 0x00000000; +constexpr int32_t TRIGGER_TIMER_OFFSET = 0x00000100; +constexpr int32_t TIMER_FAULT_OFFSET = 0x00000200; +constexpr int32_t MODIFY_TIME_OFFSET = 0x01000000; +constexpr int32_t EXACT_OFFSET = 4; +static const int COUNT_REPORT_ARRAY_LENGTH = 5; + +enum ReportEventCode : int32_t { + RTC_WAKEUP_EXACT_TIMER_START = START_TIMER_OFFSET, + RTC_NONWAKEUP_EXACT_TIMER_START, + REALTIME_WAKEUP_EXACT_TIMER_START, + REALTIME_NONWAKEUP_EXACT_TIMER_START, + RTC_WAKEUP_NONEXACT_TIMER_START, + RTC_NONWAKEUP_NONEXACT_TIMER_START, + REALTIME_WAKEUP_NONEXACT_TIMER_START, + REALTIME_NONWAKEUP_NONEXACT_TIMER_START, + RTC_WAKEUP_EXACT_TIMER_TRIGGER = TRIGGER_TIMER_OFFSET, + RTC_NONWAKEUP_EXACT_TIMER_TRIGGER, + REALTIME_WAKEUP_EXACT_TIMER_TRIGGER, + REALTIME_NONWAKEUP_EXACT_TIMER_TRIGGER, + RTC_WAKEUP_NONEXACT_TIMER_TRIGGER, + RTC_NONWAKEUP_NONEXACT_TIMER_TRIGGER, + REALTIME_WAKEUP_NONEXACT_TIMER_TRIGGER, + REALTIME_NONWAKEUP_NONEXACT_TIMER_TRIGGER, + TIMER_WANTAGENT_FAULT_REPORT = TIMER_FAULT_OFFSET, + SET_TIME = MODIFY_TIME_OFFSET, + NTP_REFRESH, + SET_TIMEZONE, +}; +void StatisticReporter(int32_t size, std::shared_ptr timer); +void TimeBehaviorReport(ReportEventCode eventCode, std::string originTime, std::string newTime, int64_t ntpTime); +void TimerBehaviorReport(std::shared_ptr timer, bool isStart); +void TimerCountStaticReporter(int count, int (&uidArr)[COUNT_REPORT_ARRAY_LENGTH], + int (&createTimerCountArr)[COUNT_REPORT_ARRAY_LENGTH], int (&startTimerCountArr)[COUNT_REPORT_ARRAY_LENGTH]); +void TimeServiceFaultReporter(ReportEventCode eventCode, int errCode, std::string extraInfo); } // namespace MiscServices } // namespace OHOS #endif // TIME_SYSEVENT_H diff --git a/services/dfx/src/time_sysevent.cpp b/services/dfx/src/time_sysevent.cpp index 0bb18793a65c18572db05bfb21e54f6e3ad7eec0..e414b5ba0bd249579f482627ac4bf2e9361bd7c0 100644 --- a/services/dfx/src/time_sysevent.cpp +++ b/services/dfx/src/time_sysevent.cpp @@ -15,8 +15,12 @@ #include "time_sysevent.h" +#include + #include "hisysevent.h" #include "time_hilog.h" +#include "time_file_utils.h" +#include "ipc_skeleton.h" namespace OHOS { namespace MiscServices { @@ -24,25 +28,133 @@ namespace { using HiSysEventNameSpace = OHOS::HiviewDFX::HiSysEvent; } // namespace -void StatisticReporter(int32_t callerPid, int32_t size, std::shared_ptr timer) +std::string GetBundleOrProcessName() +{ + std::string bundleOrProcessName = TimeFileUtils::GetBundleNameByTokenID(IPCSkeleton::GetCallingTokenID()); + if (bundleOrProcessName.empty()) { + bundleOrProcessName = TimeFileUtils::GetNameByPid(IPCSkeleton::GetCallingPid()); + } + return bundleOrProcessName; +} + +void StatisticReporter(int32_t size, std::shared_ptr timer) { if (timer == nullptr) { return; } int32_t callerUid = timer->uid; + int32_t callerPid = timer->pid; std::string bundleOrProcessName = timer->bundleName; int32_t type = timer->type; int64_t triggerTime = timer->whenElapsed.time_since_epoch().count(); auto interval = static_cast(timer->repeatInterval.count()); - int ret = HiSysEventWrite(HiSysEventNameSpace::Domain::TIME, "MISC_TIME_STATISTIC_REPORT", - HiSysEventNameSpace::EventType::STATISTIC, "CALLER_PID", callerPid, "CALLER_UID", callerUid, - "BUNDLE_OR_PROCESS_NAME", bundleOrProcessName, "TIMER_SIZE", size, "TIMER_TYPE", type, - "TRIGGER_TIME", triggerTime, "INTERVAL", interval); + struct HiSysEventParam params[] = { + {"CALLER_PID", HISYSEVENT_INT32, {.i32 = callerPid}, 0}, + {"CALLER_UID", HISYSEVENT_INT32, {.i32 = callerUid}, 0}, + {"BUNDLE_OR_PROCESS_NAME", HISYSEVENT_STRING, {.s = const_cast(bundleOrProcessName.c_str())}, 0}, + {"TIMER_SIZE", HISYSEVENT_INT32, {.i32 = size}, 0}, + {"TIMER_TYPE", HISYSEVENT_INT32, {.i32 = type}, 0}, + {"TRIGGER_TIME", HISYSEVENT_INT64, {.i64 = triggerTime}, 0}, + {"INTERVAL", HISYSEVENT_UINT64, {.ui64 = interval}, 0} + }; + int ret = OH_HiSysEvent_Write("TIME", "MISC_TIME_STATISTIC_REPORT", HISYSEVENT_STATISTIC, params, + sizeof(params)/sizeof(params[0])); if (ret != 0) { TIME_HILOGE(TIME_MODULE_SERVICE, "hisysevent Statistic failed! pid %{public}d,uid %{public}d,timer type %{public}d", callerPid, callerUid, type); } } + +void TimeBehaviorReport(ReportEventCode eventCode, std::string originTime, std::string newTime, int64_t ntpTime) +{ + std::string bundleOrProcessName = GetBundleOrProcessName(); + struct HiSysEventParam params[] = { + {"EVENT_CODE", HISYSEVENT_INT32, {.i32 = eventCode}, 0}, + {"CALLER_UID", HISYSEVENT_INT32, {.i32 = IPCSkeleton::GetCallingUid()}, 0}, + {"CALLER_NAME", HISYSEVENT_STRING, {.s = const_cast(bundleOrProcessName.c_str())}, 0}, + {"ORIGINAL_TIME", HISYSEVENT_STRING, {.s = const_cast(originTime.c_str())}, 0}, + {"SET_TIME", HISYSEVENT_STRING, {.s = const_cast(newTime.c_str())}, 0}, + {"NTP_TIME", HISYSEVENT_INT64, {.i64 = ntpTime}, 0} + }; + int ret = OH_HiSysEvent_Write("TIME", "BEHAVIOR_TIME", HISYSEVENT_BEHAVIOR, params, + sizeof(params)/sizeof(params[0])); + if (ret != 0) { + TIME_HILOGE(TIME_MODULE_SERVICE, "TimeBehaviorReport failed! eventCode %{public}d, name:%{public}s," + "ret:%{public}d", eventCode, bundleOrProcessName.c_str(), ret); + } +} + +void TimerBehaviorReport(std::shared_ptr timer, bool isStart) +{ + if (timer == nullptr) { + return; + } + int triggerOffset = isStart ? RTC_WAKEUP_EXACT_TIMER_START : RTC_WAKEUP_EXACT_TIMER_TRIGGER; + int exactOffset = (timer->windowLength == std::chrono::milliseconds::zero()) ? 0 : EXACT_OFFSET; + ReportEventCode eventCode = static_cast(triggerOffset + timer->type + exactOffset); + auto bundleOrProcessName = timer->bundleName; + auto interval = static_cast(timer->repeatInterval.count()); + struct HiSysEventParam params[] = { + {"EVENT_CODE", HISYSEVENT_INT32, {.i32 = eventCode}, 0}, + {"TIMER_ID", HISYSEVENT_UINT32, {.ui32 = timer->id}, 0}, + {"TRIGGER_TIME", HISYSEVENT_INT64, {.i64 = timer->when.count()}, 0}, + {"CALLER_UID", HISYSEVENT_INT32, {.i32 = timer->uid}, 0}, + {"CALLER_NAME", HISYSEVENT_STRING, {.s = const_cast(bundleOrProcessName.c_str())}, 0}, + {"INTERVAL", HISYSEVENT_UINT32, {.ui32 =interval}, 0} + }; + int ret = OH_HiSysEvent_Write("TIME", "BEHAVIOR_TIMER", HISYSEVENT_BEHAVIOR, params, + sizeof(params)/sizeof(params[0])); + if (ret != 0) { + TIME_HILOGE(TIME_MODULE_SERVICE, "TimerBehaviorReport failed! eventCode:%{public}d," + "id:%{public}" PRIu64 " name:%{public}s", static_cast(eventCode), timer->id, + bundleOrProcessName.c_str()); + } +} + +void TimerCountStaticReporter(int count, int (&uidArr)[COUNT_REPORT_ARRAY_LENGTH], + int (&createTimerCountArr)[COUNT_REPORT_ARRAY_LENGTH], int (&startTimerCountArr)[COUNT_REPORT_ARRAY_LENGTH]) +{ + struct HiSysEventParam params[] = { + {"TIMER_NUM", HISYSEVENT_INT32, {.i32 = count}, 0}, + {"TOP_UID", HISYSEVENT_INT32_ARRAY, {.array = uidArr}, COUNT_REPORT_ARRAY_LENGTH}, + {"TOP_NUM", HISYSEVENT_INT32_ARRAY, {.array = createTimerCountArr}, COUNT_REPORT_ARRAY_LENGTH}, + {"TOP_STRAT_NUM", HISYSEVENT_INT32_ARRAY, {.array = startTimerCountArr}, COUNT_REPORT_ARRAY_LENGTH} + }; + int ret = OH_HiSysEvent_Write("TIME", "ALARM_COUNT", HISYSEVENT_STATISTIC, + params, sizeof(params)/sizeof(params[0])); + if (ret != 0) { + std::string uidStr = ""; + std::string createCountStr = ""; + std::string startCountStr = ""; + for (int i = 0; i < COUNT_REPORT_ARRAY_LENGTH; i++) { + uidStr = uidStr + std::to_string(uidArr[i]) + " "; + createCountStr = createCountStr + std::to_string(createTimerCountArr[i]) + " "; + startCountStr = startCountStr + std::to_string(startTimerCountArr[i]) + " "; + } + TIME_HILOGE(TIME_MODULE_SERVICE, "TimerCountStaticReporter failed! count:%{public}d, uid:[%{public}s]," + "create count:[%{public}s], startcount:[%{public}s]", count, uidStr.c_str(), createCountStr.c_str(), + startCountStr.c_str()); + } +} + +void TimeServiceFaultReporter(ReportEventCode eventCode, int errCode, std::string extraInfo) +{ + int uid = IPCSkeleton::GetCallingUid(); + std::string bundleOrProcessName = GetBundleOrProcessName(); + struct HiSysEventParam params[] = { + {"EVENT_CODE", HISYSEVENT_INT32, {.i32 = eventCode}, 0}, + {"ERR_CODE", HISYSEVENT_INT32, {.i32 = errCode}, 0}, + {"CALLER_UID", HISYSEVENT_INT32, {.i32 = uid}, 0}, + {"CALLER_NAME", HISYSEVENT_STRING, {.s = const_cast(bundleOrProcessName.c_str())}, 0}, + {"EXTRA", HISYSEVENT_STRING, {.s = const_cast(extraInfo.c_str())}, 0} + }; + int ret = OH_HiSysEvent_Write("TIME", "FUNC_FAULT", HISYSEVENT_FAULT, + params, sizeof(params)/sizeof(params[0])); + if (ret != 0) { + TIME_HILOGE(TIME_MODULE_SERVICE, "TimeServiceFaultReporter failed! eventCode:%{public}d errorcode:%{public}d" + "callname:%{public}s", eventCode, errCode, bundleOrProcessName.c_str()); + } +} } // namespace MiscServices } // namespace OHOS \ No newline at end of file diff --git a/services/time/src/sntp_client.cpp b/services/time/src/sntp_client.cpp index c293d88ab0df6ce62a885a7b67fa50b68cbd5749..e6ac5df913b3d8fc078176273969a689df3df38d 100644 --- a/services/time/src/sntp_client.cpp +++ b/services/time/src/sntp_client.cpp @@ -31,6 +31,7 @@ #include #include "time_common.h" +#include "time_sysevent.h" namespace OHOS { namespace MiscServices { @@ -257,11 +258,8 @@ bool SNTPClient::ReceivedMessage(char *buffer) _sntpMsg._transmitTimestamp = GetNtpTimestamp64(TRANSMIT_TIMESTAMP_OFFSET, buffer); int64_t _originClient = m_originateTimestamp; int64_t _receiveServer = ConvertNtpToStamp(_sntpMsg._receiveTimestamp); - if (_receiveServer == 0) { - return false; - } int64_t _transmitServer = ConvertNtpToStamp(_sntpMsg._transmitTimestamp); - if (_transmitServer == 0) { + if (_transmitServer == 0 || _receiveServer == 0) { return false; } int64_t _receiveClient = receiveBootTime; @@ -276,6 +274,9 @@ bool SNTPClient::ReceivedMessage(char *buffer) "_receiveClient:%{public}s", std::to_string(_originClient).c_str(), std::to_string(_receiveServer).c_str(), std::to_string(_transmitServer).c_str(), std::to_string(_receiveClient).c_str()); + TimeBehaviorReport(ReportEventCode::NTP_REFRESH, + std::to_string(_originClient) + "|" + std::to_string(_receiveClient), + std::to_string(_transmitServer) + "|" + std::to_string(_receiveServer), mNtpTime); return true; } diff --git a/services/time/src/time_zone_info.cpp b/services/time/src/time_zone_info.cpp index 8c478b65be9943ad365f26e42818b812d5cbec6f..7f72e52286c6d4c52e0d7d4777c4ad853d73ac93 100644 --- a/services/time/src/time_zone_info.cpp +++ b/services/time/src/time_zone_info.cpp @@ -20,6 +20,7 @@ #include "time_zone_info.h" #include "ipc_skeleton.h" #include "time_file_utils.h" +#include "time_sysevent.h" namespace OHOS { namespace MiscServices { @@ -78,6 +79,7 @@ bool TimeZoneInfo::SetTimezone(const std::string &timezoneId) return false; } curTimezoneId_ = timezoneId; + TimeBehaviorReport(ReportEventCode::SET_TIMEZONE, curTimezoneId_, timezoneId, 0); return true; } diff --git a/services/time_system_ability.cpp b/services/time_system_ability.cpp index d86510f7b070f8262ebd5f0cf71a0ddb74792153..ed965d5244ca4831e80897dc8e4d54ee0297e902 100644 --- a/services/time_system_ability.cpp +++ b/services/time_system_ability.cpp @@ -567,6 +567,8 @@ bool TimeSystemAbility::SetRealTime(int64_t time) TimeServiceNotify::GetInstance().PublishTimeChangeEvents(currentTime); } TimeTickNotify::GetInstance().Callback(); + int64_t curtime = NtpTrustedTime::GetInstance().CurrentTimeMillis(); + TimeBehaviorReport(ReportEventCode::SET_TIME, std::to_string(beforeTime), std::to_string(time), curtime); return true; } diff --git a/services/time_system_ability.h b/services/time_system_ability.h index 0e8f7462641246bfc7cfc3a39772fb0774dd7162..65a7deb0f9f73ef009b0e9346fde245d31358da0 100644 --- a/services/time_system_ability.h +++ b/services/time_system_ability.h @@ -37,6 +37,7 @@ #include "ipc_skeleton.h" #include "time_permission.h" #include "simple_timer_info.h" +#include "time_sysevent.h" #ifdef RDB_ENABLE #include "rdb_helper.h" #include "timer_database.h" diff --git a/services/timer/include/timer_manager.h b/services/timer/include/timer_manager.h index 75f376d91487eacc8c02cf6685a847fd5b1de7c3..333d696d0a4705ee1bb7b1ecb44db08c2d294257 100644 --- a/services/timer/include/timer_manager.h +++ b/services/timer/include/timer_manager.h @@ -153,7 +153,7 @@ private: void IncreaseTimerCount(int uid); void DecreaseTimerCount(int uid); void CheckTimerCount(); - void ShowTimerCountByUid(); + void ShowTimerCountByUid(int count); void AddTimerName(int uid, std::string name, uint64_t timerId); void DeleteTimerName(int uid, std::string name, uint64_t timerId); diff --git a/services/timer/include/timer_proxy.h b/services/timer/include/timer_proxy.h index 13bbea64a4bbabba78d7c0dd5c09c70a817a328e..457ff76a2710357a3e7792d6d49b81fae16b5112 100644 --- a/services/timer/include/timer_proxy.h +++ b/services/timer/include/timer_proxy.h @@ -48,6 +48,7 @@ public: void RecordProxyTimerMap(const std::shared_ptr &alarm, bool isPid); void RemoveUidTimerMap(const std::shared_ptr &alarm); void RemoveUidTimerMap(const uint64_t id); + int32_t CountUidTimerMapByUid(int32_t uid); bool IsProxy(const int32_t uid, const int32_t pid); #ifdef HIDUMPER_ENABLE bool ShowProxyTimerInfo(int fd, const int64_t now); diff --git a/services/timer/src/timer_manager.cpp b/services/timer/src/timer_manager.cpp index f0a87f835b1cd03db2252ba447f6a2d5c44e7e23..b75650df12f4b0e12bb01cc40763f6912f2d46b9 100644 --- a/services/timer/src/timer_manager.cpp +++ b/services/timer/src/timer_manager.cpp @@ -354,7 +354,7 @@ void TimerManager::CheckTimerCount() if (count > (timerOutOfRangeTimes_ + 1) * TIMER_ALARM_COUNT) { timerOutOfRangeTimes_ += 1; TIME_HILOGI(TIME_MODULE_SERVICE, "%{public}d timer in system", count); - ShowTimerCountByUid(); + ShowTimerCountByUid(count); lastTimerOutOfRangeTime_ = GetBootTimeNs(); return; } @@ -362,26 +362,37 @@ void TimerManager::CheckTimerCount() if (count > MAX_TIMER_ALARM_COUNT && currentBootTime - lastTimerOutOfRangeTime_ > std::chrono::minutes(TIMER_ALRAM_INTERVAL)) { TIME_HILOGI(TIME_MODULE_SERVICE, "%{public}d timer in system", count); - ShowTimerCountByUid(); + ShowTimerCountByUid(count); lastTimerOutOfRangeTime_ = currentBootTime; return; } } -void TimerManager::ShowTimerCountByUid() +void TimerManager::ShowTimerCountByUid(int count) { std::string uidStr = ""; std::string countStr = ""; + int uidArr[TIMER_COUNT_TOP_NUM]; + int createTimerCountArr[TIMER_COUNT_TOP_NUM]; + int startTimerCountArr[TIMER_COUNT_TOP_NUM]; auto size = static_cast(timerCount_.size()); std::sort(timerCount_.begin(), timerCount_.end(), [](const std::pair& a, const std::pair& b) { return a.second > b.second; }); auto limitedSize = (size > TIMER_COUNT_TOP_NUM) ? TIMER_COUNT_TOP_NUM : size; + int index = 0; for (auto it = timerCount_.begin(); it != timerCount_.begin() + limitedSize; ++it) { - uidStr = uidStr + std::to_string(it->first) + " "; - countStr = countStr + std::to_string(it->second) + " "; - } + int uid = it->first; + int createTimerCount = it->second; + uidStr = uidStr + std::to_string(uid) + " "; + countStr = countStr + std::to_string(createTimerCount) + " "; + uidArr[index] = uid; + createTimerCountArr[index] = createTimerCount; + startTimerCountArr[index] = TimerProxy::GetInstance().CountUidTimerMapByUid(uid); + ++index; + } + TimerCountStaticReporter(count, uidArr, createTimerCountArr, startTimerCountArr); TIME_HILOGI(TIME_MODULE_SERVICE, "Top uid:[%{public}s], nums:[%{public}s]", uidStr.c_str(), countStr.c_str()); } @@ -984,11 +995,10 @@ void TimerManager::DeliverTimersLocked(const std::vectorwakeup) { #ifdef POWER_MANAGER_ENABLE - TIME_HILOGD(TIME_MODULE_SERVICE, "id: %{public}" PRId64 ", uid: %{public}d bundleName: %{public}s", - timer->id, timer->uid, timer->bundleName.c_str()); AddRunningLock(USE_LOCK_ONE_SEC_IN_NANO); #endif - StatisticReporter(IPCSkeleton::GetCallingPid(), wakeupNums, timer); + TimerBehaviorReport(timer, false); + StatisticReporter(wakeupNums, timer); } if (timer->callback) { if (TimerProxy::GetInstance().CallbackAlarmIfNeed(timer) == PEER_END_DEAD @@ -1097,6 +1107,9 @@ bool TimerManager::NotifyWantAgent(const std::shared_ptr &timer) OHOS::AbilityRuntime::WantAgent::TriggerInfo paramsInfo("", nullptr, want, WANTAGENT_CODE_ELEVEN); auto code = AbilityRuntime::WantAgent::WantAgentHelper::TriggerWantAgent(wantAgent, nullptr, paramsInfo); TIME_SIMPLIFY_HILOGW(TIME_MODULE_SERVICE, "trigWA ret: %{public}d", code); + if (code != ERR_OK) { + TimeServiceFaultReporter(ReportEventCode::TIMER_WANTAGENT_FAULT_REPORT, code, ""); + } return code == ERR_OK; } diff --git a/services/timer/src/timer_proxy.cpp b/services/timer/src/timer_proxy.cpp index cc1672ce995ea40943eea47a29864d48e50a5e27..c123dd40552e4ef34a33a46d8cfc7a16f6cdd598 100644 --- a/services/timer/src/timer_proxy.cpp +++ b/services/timer/src/timer_proxy.cpp @@ -180,6 +180,16 @@ void TimerProxy::EraseAlarmItem( } } +int32_t TimerProxy::CountUidTimerMapByUid(int32_t uid) +{ + std::lock_guard lock(uidTimersMutex_); + auto it = uidTimersMap_.find(uid); + if (it == uidTimersMap_.end()) { + return 0; + } + return it->second.size(); +} + void TimerProxy::RecordUidTimerMap(const std::shared_ptr &alarm, const bool isRebatched) { if (isRebatched) { @@ -281,7 +291,6 @@ void TimerProxy::UpdateProxyWhenElapsedForProxyTimers(int32_t uid, int pid, TIME_HILOGD(TIME_MODULE_SERVICE, "uid:%{public}d pid: %{public}d is already proxy", uid, pid); return; } - std::lock_guard lockUidTimers(uidTimersMutex_); std::vector timerList; auto itUidTimersMap = uidTimersMap_.find(uid); @@ -319,7 +328,6 @@ bool TimerProxy::RestoreProxyWhenElapsed(const int uid, const int pid, TIME_HILOGD(TIME_MODULE_SERVICE, "uid:%{public}d pid:%{public}d not in proxy.", uid, pid); return false; } - std::lock_guard lockPidTimers(uidTimersMutex_); auto itTimer = uidTimersMap_.find(uid); if (uidTimersMap_.find(uid) == uidTimersMap_.end()) { @@ -346,7 +354,6 @@ bool TimerProxy::RestoreProxyWhenElapsed(const int uid, const int pid, now.time_since_epoch().count()); insertAlarmCallback(itTimerInfo->second, needRetrigger); } - return true; }