• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
48     ReclaimHandleRequest request;
49     request.pid = pid;
50     request.uid = uid;
51     request.bundleName = pkgName;
52     request.reason = AppStateUpdateReason::SUSPEND_DELAY_START;
53     ReclaimPriorityManager::GetInstance().UpdateReclaimPriority(request);
54 }
55 
OnTransientTaskEnd(const std::shared_ptr<BackgroundTaskMgr::TransientTaskAppInfo> & ttInfo)56 void BgTaskObserver::OnTransientTaskEnd(
57     const std::shared_ptr<BackgroundTaskMgr::TransientTaskAppInfo>& ttInfo)
58 {
59     if (ttInfo == nullptr) {
60         HILOGE("called with null TransientTaskAppInfo");
61         return;
62     }
63     std::string pkgName = ttInfo->GetPackageName();
64     int uid = ttInfo->GetUid();
65     int pid = ttInfo->GetPid();
66     HILOGD("called, pkg=%{public}s, uid=%{public}d, pid=%{public}d", pkgName.c_str(), uid, pid);
67 
68     ReclaimHandleRequest request;
69     request.pid = pid;
70     request.uid = uid;
71     request.bundleName = pkgName;
72     request.reason = AppStateUpdateReason::SUSPEND_DELAY_END;
73     ReclaimPriorityManager::GetInstance().UpdateReclaimPriority(request);
74 }
75 
OnContinuousTaskStart(const std::shared_ptr<BackgroundTaskMgr::ContinuousTaskCallbackInfo> & ctInfo)76 void BgTaskObserver::OnContinuousTaskStart(
77     const std::shared_ptr<BackgroundTaskMgr::ContinuousTaskCallbackInfo>& ctInfo)
78 {
79     if (ctInfo == nullptr) {
80         HILOGE("called with null ContinuousTaskCallbackInfo");
81         return;
82     }
83     int32_t type = ctInfo->GetTypeId();
84     uid_t uid = ctInfo->GetCreatorUid();
85     pid_t pid = ctInfo->GetCreatorPid();
86     std::string abilityName = ctInfo->GetAbilityName();
87     HILOGD("called, abilityName=%{public}s, type=%{public}d uid=%{public}d, pid=%{public}d",
88         abilityName.c_str(), type, uid, pid);
89 
90     ReclaimHandleRequest request;
91     request.pid = pid;
92     request.uid = uid;
93     request.bundleName = abilityName;
94     request.reason = AppStateUpdateReason::BACKGROUND_RUNNING_START;
95     ReclaimPriorityManager::GetInstance().UpdateReclaimPriority(request);
96 }
97 
OnContinuousTaskStop(const std::shared_ptr<BackgroundTaskMgr::ContinuousTaskCallbackInfo> & ctInfo)98 void BgTaskObserver::OnContinuousTaskStop(
99     const std::shared_ptr<BackgroundTaskMgr::ContinuousTaskCallbackInfo>& ctInfo)
100 {
101     if (ctInfo == nullptr) {
102         HILOGE("called with null ContinuousTaskCallbackInfo");
103         return;
104     }
105     int32_t type = ctInfo->GetTypeId();
106     uid_t uid = ctInfo->GetCreatorUid();
107     pid_t pid = ctInfo->GetCreatorPid();
108     std::string abilityName = ctInfo->GetAbilityName();
109     HILOGD("called, abilityName=%{public}s, type=%{public}d uid=%{public}d, pid=%{public}d",
110         abilityName.c_str(), type, uid, pid);
111 
112     ReclaimHandleRequest request;
113     request.pid = pid;
114     request.uid = uid;
115     request.bundleName = abilityName;
116     request.reason = AppStateUpdateReason::BACKGROUND_RUNNING_END;
117     ReclaimPriorityManager::GetInstance().UpdateReclaimPriority(request);
118 }
119 
OnRemoteDied(const wptr<IRemoteObject> & object)120 void BgTaskObserver::OnRemoteDied(const wptr<IRemoteObject> &object)
121 {
122     HILOGE("called");
123 }
124 } // namespace Memory
125 } // namespace OHOS
126