diff --git a/services/time_system_ability.cpp b/services/time_system_ability.cpp index 61b88907dcb2f7aa24e290095f6e5107768f5133..4734a3f94b166d581a89d1359b792caea817b468 100644 --- a/services/time_system_ability.cpp +++ b/services/time_system_ability.cpp @@ -259,7 +259,8 @@ int32_t TimeSystemAbility::CreateTimer(const std::shared_ptr &timerO }; int64_t triggerTime = 0; GetWallTimeMs(triggerTime); - StatisticReporter(IPCSkeleton::GetCallingPid(), uid, timerOptions->type, triggerTime, timerOptions->interval); + int pid = IPCSkeleton::GetCallingPid(); + StatisticReporter(pid, uid, timerOptions->type, triggerTime, timerOptions->interval); if (timerManagerHandler_ == nullptr) { TIME_HILOGE(TIME_MODULE_SERVICE, "Timer manager nullptr."); timerManagerHandler_ = TimerManager::Create(); @@ -273,7 +274,7 @@ int32_t TimeSystemAbility::CreateTimer(const std::shared_ptr &timerO TIME_HILOGW(TIME_MODULE_SERVICE, "App not support create idle timer."); paras.flag = 0; } - return timerManagerHandler_->CreateTimer(paras, callbackFunc, timerOptions->wantAgent, uid, timerId); + return timerManagerHandler_->CreateTimer(paras, callbackFunc, timerOptions->wantAgent, uid, pid, timerId); } int32_t TimeSystemAbility::CreateTimer(TimerPara ¶s, std::function Callback, @@ -287,7 +288,8 @@ int32_t TimeSystemAbility::CreateTimer(TimerPara ¶s, std::functionCreateTimer(paras, std::move(Callback), nullptr, 0, timerId); + int pid = IPCSkeleton::GetCallingPid(); + return timerManagerHandler_->CreateTimer(paras, std::move(Callback), nullptr, 0, pid, timerId); } int32_t TimeSystemAbility::StartTimer(uint64_t timerId, uint64_t triggerTime) diff --git a/services/timer/include/timer_info.h b/services/timer/include/timer_info.h index 8e6ad89652832f9885a9138f2b5b7ccd22597594..fdb0de64d2133d88823d1489be080e2dca8e199d 100644 --- a/services/timer/include/timer_info.h +++ b/services/timer/include/timer_info.h @@ -33,6 +33,7 @@ public: const std::shared_ptr wantAgent; const uint32_t flags; const int uid; + const int pid; uint64_t count {}; std::chrono::milliseconds when; @@ -55,6 +56,7 @@ public: std::shared_ptr wantAgent, uint32_t flags, int uid, + int pid, const std::string &bundleName); virtual ~TimerInfo() = default; bool operator==(const TimerInfo &other) const; diff --git a/services/timer/include/timer_manager.h b/services/timer/include/timer_manager.h index c5300994119d08307d21fe400a8569baf7803b35..3d26d15cfc496a3ba9de7bc9d6497c1a0dee6962 100644 --- a/services/timer/include/timer_manager.h +++ b/services/timer/include/timer_manager.h @@ -42,6 +42,7 @@ public: std::function callback, std::shared_ptr wantAgent, int uid, + int pid, uint64_t &timerId) override; int32_t StartTimer(uint64_t timerId, uint64_t triggerTime) override; int32_t StopTimer(uint64_t timerId) override; @@ -68,6 +69,7 @@ private: std::function callback, std::shared_ptr wantAgent, int uid, + int pid, const std::string &bundleName); void SetHandlerLocked(uint64_t id, int type, @@ -81,6 +83,7 @@ private: uint32_t flags, bool doValidate, uint64_t callingUid, + uint64_t callingPid, const std::string &bundleName); void RemoveHandler(uint64_t id); void RemoveLocked(uint64_t id); diff --git a/services/timer/include/timer_manager_interface.h b/services/timer/include/timer_manager_interface.h index 571603dc9018f80fc3167d77892cc51077ffd424..05ea717d897de882d6a22e0f3916fc4cdb85854e 100644 --- a/services/timer/include/timer_manager_interface.h +++ b/services/timer/include/timer_manager_interface.h @@ -31,6 +31,7 @@ struct TimerEntry { std::function callback; std::shared_ptr wantAgent; int uid; + int pid; std::string bundleName; }; @@ -55,7 +56,9 @@ public: virtual int32_t CreateTimer(TimerPara ¶s, std::function callback, std::shared_ptr wantAgent, - int uid, uint64_t &timerId) = 0; + int uid, + int pid, + uint64_t &timerId) = 0; virtual int32_t StartTimer(uint64_t timerId, uint64_t triggerTime) = 0; virtual int32_t StopTimer(uint64_t timerId) = 0; diff --git a/services/timer/src/timer_info.cpp b/services/timer/src/timer_info.cpp index 52b6a13a336f2976d939e2bbf8d8ffaf2dd416af..34b50fdfb11ac5e9bbd5b35ec0f7a45e09eee1c2 100644 --- a/services/timer/src/timer_info.cpp +++ b/services/timer/src/timer_info.cpp @@ -41,6 +41,7 @@ TimerInfo::TimerInfo(uint64_t _id, int _type, std::shared_ptr _wantAgent, uint32_t _flags, int _uid, + int _pid, const std::string &_bundleName) : id {_id}, type {_type}, @@ -50,6 +51,7 @@ TimerInfo::TimerInfo(uint64_t _id, int _type, wantAgent {_wantAgent}, flags {_flags}, uid {_uid}, + pid {_pid}, when {_when}, windowLength {_windowLength}, whenElapsed {_whenElapsed}, diff --git a/services/timer/src/timer_manager.cpp b/services/timer/src/timer_manager.cpp index 75e79d203815aae96cefd6ce0c363772f31eee84..dbb278c0ace64cc14d1ed6bf036b08d87759bc09 100644 --- a/services/timer/src/timer_manager.cpp +++ b/services/timer/src/timer_manager.cpp @@ -91,6 +91,7 @@ int32_t TimerManager::CreateTimer(TimerPara ¶s, std::function callback, std::shared_ptr wantAgent, int uid, + int pid, uint64_t &timerId) { TIME_HILOGI(TIME_MODULE_SERVICE, @@ -112,6 +113,7 @@ int32_t TimerManager::CreateTimer(TimerPara ¶s, std::move(callback), wantAgent, uid, + pid, bundleName }); std::lock_guard lock(entryMapMutex_); @@ -139,6 +141,7 @@ int32_t TimerManager::StartTimer(uint64_t timerId, uint64_t triggerTime) timerInfo->callback, timerInfo->wantAgent, timerInfo->uid, + timerInfo->pid, timerInfo->bundleName); return E_TIME_OK; } @@ -203,6 +206,7 @@ void TimerManager::SetHandler(uint64_t id, std::function callback, std::shared_ptr wantAgent, int uid, + int pid, const std::string &bundleName) { TIME_HILOGI(TIME_MODULE_SERVICE, @@ -253,6 +257,7 @@ void TimerManager::SetHandler(uint64_t id, static_cast(flag), true, uid, + pid, bundleName); } @@ -267,11 +272,13 @@ void TimerManager::SetHandlerLocked(uint64_t id, int type, uint32_t flags, bool doValidate, uint64_t callingUid, + uint64_t callingPid, const std::string &bundleName) { TIME_HILOGD(TIME_MODULE_SERVICE, "start id: %{public}" PRId64 "", id); auto alarm = std::make_shared(id, type, when, whenElapsed, windowLength, maxWhen, - interval, std::move(callback), wantAgent, flags, callingUid, bundleName); + interval, std::move(callback), wantAgent, flags, + callingUid, callingPid, bundleName); SetHandlerLocked(alarm, false, doValidate, false); TIME_HILOGD(TIME_MODULE_SERVICE, "end"); } @@ -949,7 +956,7 @@ void TimerManager::HandleRepeatTimer( auto nextElapsed = timer->whenElapsed + delta; SetHandlerLocked(timer->id, timer->type, timer->when + delta, nextElapsed, timer->windowLength, MaxTriggerTime(nowElapsed, nextElapsed, timer->repeatInterval), timer->repeatInterval, timer->callback, - timer->wantAgent, timer->flags, true, timer->uid, timer->bundleName); + timer->wantAgent, timer->flags, true, timer->uid, timer->pid, timer->bundleName); } }