1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "bg_task_observer.h"
17 #include "memmgr_log.h"
18 #include "reclaim_priority_manager.h"
19
20 namespace OHOS {
21 namespace Memory {
22 namespace {
23 const std::string TAG = "BgTaskObserver";
24 }
25
OnConnected()26 void BgTaskObserver::OnConnected()
27 {
28 HILOGI("called");
29 }
30
OnDisconnected()31 void BgTaskObserver::OnDisconnected()
32 {
33 HILOGE("called");
34 }
35
OnTransientTaskStart(const std::shared_ptr<BackgroundTaskMgr::TransientTaskAppInfo> & ttInfo)36 void BgTaskObserver::OnTransientTaskStart(
37 const std::shared_ptr<BackgroundTaskMgr::TransientTaskAppInfo>& ttInfo)
38 {
39 if (ttInfo == nullptr) {
40 HILOGE("called with null TransientTaskAppInfo");
41 return;
42 }
43 std::string pkgName = ttInfo->GetPackageName();
44 int uid = ttInfo->GetUid();
45 int pid = ttInfo->GetPid();
46 HILOGD("called, pkg=%{public}s, uid=%{public}d, pid=%{public}d", pkgName.c_str(), uid, pid);
47 ReclaimPriorityManager::GetInstance().UpdateReclaimPriority(pid, uid, pkgName,
48 AppStateUpdateReason::SUSPEND_DELAY_START);
49 }
50
OnTransientTaskEnd(const std::shared_ptr<BackgroundTaskMgr::TransientTaskAppInfo> & ttInfo)51 void BgTaskObserver::OnTransientTaskEnd(
52 const std::shared_ptr<BackgroundTaskMgr::TransientTaskAppInfo>& ttInfo)
53 {
54 if (ttInfo == nullptr) {
55 HILOGE("called with null TransientTaskAppInfo");
56 return;
57 }
58 std::string pkgName = ttInfo->GetPackageName();
59 int uid = ttInfo->GetUid();
60 int pid = ttInfo->GetPid();
61 HILOGD("called, pkg=%{public}s, uid=%{public}d, pid=%{public}d", pkgName.c_str(), uid, pid);
62 ReclaimPriorityManager::GetInstance().UpdateReclaimPriority(pid, uid, pkgName,
63 AppStateUpdateReason::SUSPEND_DELAY_END);
64 }
65
OnContinuousTaskStart(const std::shared_ptr<BackgroundTaskMgr::ContinuousTaskCallbackInfo> & ctInfo)66 void BgTaskObserver::OnContinuousTaskStart(
67 const std::shared_ptr<BackgroundTaskMgr::ContinuousTaskCallbackInfo>& ctInfo)
68 {
69 if (ctInfo == nullptr) {
70 HILOGE("called with null ContinuousTaskCallbackInfo");
71 return;
72 }
73 int32_t type = ctInfo->GetTypeId();
74 uid_t uid = ctInfo->GetCreatorUid();
75 pid_t pid = ctInfo->GetCreatorPid();
76 std::string abilityName = ctInfo->GetAbilityName();
77 HILOGD("called, abilityName=%{public}s, type=%{public}d uid=%{public}d, pid=%{public}d",
78 abilityName.c_str(), type, uid, pid);
79 ReclaimPriorityManager::GetInstance().UpdateReclaimPriority(pid, uid, abilityName,
80 AppStateUpdateReason::BACKGROUND_RUNNING_START);
81 }
82
OnContinuousTaskStop(const std::shared_ptr<BackgroundTaskMgr::ContinuousTaskCallbackInfo> & ctInfo)83 void BgTaskObserver::OnContinuousTaskStop(
84 const std::shared_ptr<BackgroundTaskMgr::ContinuousTaskCallbackInfo>& ctInfo)
85 {
86 if (ctInfo == nullptr) {
87 HILOGE("called with null ContinuousTaskCallbackInfo");
88 return;
89 }
90 int32_t type = ctInfo->GetTypeId();
91 uid_t uid = ctInfo->GetCreatorUid();
92 pid_t pid = ctInfo->GetCreatorPid();
93 std::string abilityName = ctInfo->GetAbilityName();
94 HILOGD("called, abilityName=%{public}s, type=%{public}d uid=%{public}d, pid=%{public}d",
95 abilityName.c_str(), type, uid, pid);
96 ReclaimPriorityManager::GetInstance().UpdateReclaimPriority(pid, uid, abilityName,
97 AppStateUpdateReason::BACKGROUND_RUNNING_END);
98 }
99
OnRemoteDied(const wptr<IRemoteObject> & object)100 void BgTaskObserver::OnRemoteDied(const wptr<IRemoteObject> &object)
101 {
102 HILOGE("called");
103 }
104 } // namespace Memory
105 } // namespace OHOS
106