1ba5c3796Sopenharmony_ci/*
2ba5c3796Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd.
3ba5c3796Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4ba5c3796Sopenharmony_ci * you may not use this file except in compliance with the License.
5ba5c3796Sopenharmony_ci * You may obtain a copy of the License at
6ba5c3796Sopenharmony_ci *
7ba5c3796Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8ba5c3796Sopenharmony_ci *
9ba5c3796Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10ba5c3796Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11ba5c3796Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12ba5c3796Sopenharmony_ci * See the License for the specific language governing permissions and
13ba5c3796Sopenharmony_ci * limitations under the License.
14ba5c3796Sopenharmony_ci */
15ba5c3796Sopenharmony_ci
16ba5c3796Sopenharmony_ci#include "extension_connection_observer.h"
17ba5c3796Sopenharmony_ci
18ba5c3796Sopenharmony_ci#include "mem_mgr_event_center.h"
19ba5c3796Sopenharmony_ci#include "memmgr_log.h"
20ba5c3796Sopenharmony_ci#include "reclaim_priority_manager.h"
21ba5c3796Sopenharmony_ci
22ba5c3796Sopenharmony_cinamespace OHOS {
23ba5c3796Sopenharmony_cinamespace Memory {
24ba5c3796Sopenharmony_cinamespace {
25ba5c3796Sopenharmony_ciconst std::string TAG = "ExtConnObs";
26ba5c3796Sopenharmony_ci}
27ba5c3796Sopenharmony_ci
28ba5c3796Sopenharmony_civoid ExtensionConnectionObserver::OnExtensionConnected(const AbilityRuntime::ConnectionData& data)
29ba5c3796Sopenharmony_ci{
30ba5c3796Sopenharmony_ci    HILOGI("%{public}s(%{public}d,%{public}d) --> [%{public}s|%{public}s|%{public}s](%{public}d,%{public}d) "
31ba5c3796Sopenharmony_ci        "with type %{public}d", data.callerName.c_str(), data.callerPid, data.callerUid,
32ba5c3796Sopenharmony_ci        data.extensionBundleName.c_str(), data.extensionModuleName.c_str(), data.extensionName.c_str(),
33ba5c3796Sopenharmony_ci        data.extensionPid, data.extensionUid, static_cast<int32_t>(data.extensionType));
34ba5c3796Sopenharmony_ci
35ba5c3796Sopenharmony_ci    ReclaimPriorityManager::GetInstance().UpdateReclaimPriority(
36ba5c3796Sopenharmony_ci        CallerRequest({data.callerPid, data.callerUid, data.callerName},
37ba5c3796Sopenharmony_ci            {data.extensionPid, data.extensionUid, data.extensionBundleName},
38ba5c3796Sopenharmony_ci            AppStateUpdateReason::BIND_EXTENSION));
39ba5c3796Sopenharmony_ci}
40ba5c3796Sopenharmony_ci
41ba5c3796Sopenharmony_civoid ExtensionConnectionObserver::OnExtensionDisconnected(const AbilityRuntime::ConnectionData& data)
42ba5c3796Sopenharmony_ci{
43ba5c3796Sopenharmony_ci    HILOGI("%{public}s(%{public}d,%{public}d) -/-> [%{public}s|%{public}s|%{public}s](%{public}d,%{public}d) "
44ba5c3796Sopenharmony_ci        "with type %{public}d", data.callerName.c_str(), data.callerPid, data.callerUid,
45ba5c3796Sopenharmony_ci        data.extensionBundleName.c_str(), data.extensionModuleName.c_str(), data.extensionName.c_str(),
46ba5c3796Sopenharmony_ci        data.extensionPid, data.extensionUid, static_cast<int32_t>(data.extensionType));
47ba5c3796Sopenharmony_ci
48ba5c3796Sopenharmony_ci    ReclaimPriorityManager::GetInstance().UpdateReclaimPriority(
49ba5c3796Sopenharmony_ci        CallerRequest({data.callerPid, data.callerUid, data.callerName},
50ba5c3796Sopenharmony_ci            {data.extensionPid, data.extensionUid, data.extensionBundleName},
51ba5c3796Sopenharmony_ci            AppStateUpdateReason::UNBIND_EXTENSION));
52ba5c3796Sopenharmony_ci}
53ba5c3796Sopenharmony_ci
54ba5c3796Sopenharmony_civoid ExtensionConnectionObserver::OnDlpAbilityOpened(const AbilityRuntime::DlpStateData& data)
55ba5c3796Sopenharmony_ci{
56ba5c3796Sopenharmony_ci    HILOGI("%{public}s(%{public}d,%{public}d) --> [%{public}s|%{public}s|%{public}s](%{public}d,%{public}d)",
57ba5c3796Sopenharmony_ci        data.callerName.c_str(), data.callerPid, data.callerUid, data.targetBundleName.c_str(),
58ba5c3796Sopenharmony_ci        data.targetModuleName.c_str(), data.targetAbilityName.c_str(), data.targetPid, data.targetUid);
59ba5c3796Sopenharmony_ci
60ba5c3796Sopenharmony_ci    ReclaimHandleRequest request;
61ba5c3796Sopenharmony_ci    request.callerPid = data.callerPid;
62ba5c3796Sopenharmony_ci    request.callerUid = data.callerUid;
63ba5c3796Sopenharmony_ci    request.callerBundleName = data.callerName;
64ba5c3796Sopenharmony_ci    request.pid = data.targetPid;
65ba5c3796Sopenharmony_ci    request.uid = data.targetUid;
66ba5c3796Sopenharmony_ci    request.bundleName = data.targetBundleName;
67ba5c3796Sopenharmony_ci    request.reason =  AppStateUpdateReason::BIND_EXTENSION;
68ba5c3796Sopenharmony_ci    ReclaimPriorityManager::GetInstance().UpdateReclaimPriority(
69ba5c3796Sopenharmony_ci        CallerRequest({data.callerPid, data.callerUid, data.callerName},
70ba5c3796Sopenharmony_ci            {data.targetPid, data.targetUid, data.targetBundleName},
71ba5c3796Sopenharmony_ci            AppStateUpdateReason::BIND_EXTENSION));
72ba5c3796Sopenharmony_ci}
73ba5c3796Sopenharmony_ci
74ba5c3796Sopenharmony_civoid ExtensionConnectionObserver::OnDlpAbilityClosed(const AbilityRuntime::DlpStateData& data)
75ba5c3796Sopenharmony_ci{
76ba5c3796Sopenharmony_ci    HILOGI("%{public}s(%{public}d,%{public}d) -/-> [%{public}s|%{public}s|%{public}s](%{public}d,%{public}d)",
77ba5c3796Sopenharmony_ci        data.callerName.c_str(), data.callerPid, data.callerUid, data.targetBundleName.c_str(),
78ba5c3796Sopenharmony_ci        data.targetModuleName.c_str(), data.targetAbilityName.c_str(), data.targetPid, data.targetUid);
79ba5c3796Sopenharmony_ci
80ba5c3796Sopenharmony_ci    ReclaimHandleRequest request;
81ba5c3796Sopenharmony_ci    request.callerPid = data.callerPid;
82ba5c3796Sopenharmony_ci    request.callerUid = data.callerUid;
83ba5c3796Sopenharmony_ci    request.callerBundleName = data.callerName;
84ba5c3796Sopenharmony_ci    request.pid = data.targetPid;
85ba5c3796Sopenharmony_ci    request.uid = data.targetUid;
86ba5c3796Sopenharmony_ci    request.bundleName = data.targetBundleName;
87ba5c3796Sopenharmony_ci    request.reason =  AppStateUpdateReason::UNBIND_EXTENSION;
88ba5c3796Sopenharmony_ci    ReclaimPriorityManager::GetInstance().UpdateReclaimPriority(
89ba5c3796Sopenharmony_ci        CallerRequest({data.callerPid, data.callerUid, data.callerName},
90ba5c3796Sopenharmony_ci            {data.targetPid, data.targetUid, data.targetBundleName},
91ba5c3796Sopenharmony_ci            AppStateUpdateReason::UNBIND_EXTENSION));
92ba5c3796Sopenharmony_ci}
93ba5c3796Sopenharmony_ci
94ba5c3796Sopenharmony_civoid ExtensionConnectionObserver::OnServiceDied()
95ba5c3796Sopenharmony_ci{
96ba5c3796Sopenharmony_ci    HILOGE("called");
97ba5c3796Sopenharmony_ci    MemMgrEventCenter::GetInstance().OnExtensionServiceDied();
98ba5c3796Sopenharmony_ci}
99ba5c3796Sopenharmony_ci} // namespace Memory
100ba5c3796Sopenharmony_ci} // namespace OHOS
101