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 "mem_mgr_proxy.h" 17ba5c3796Sopenharmony_ci 18ba5c3796Sopenharmony_ci#include "mem_mgr_constant.h" 19ba5c3796Sopenharmony_ci#include "memmgr_log.h" 20ba5c3796Sopenharmony_ci#include "parcel.h" 21ba5c3796Sopenharmony_ci 22ba5c3796Sopenharmony_cinamespace OHOS { 23ba5c3796Sopenharmony_cinamespace Memory { 24ba5c3796Sopenharmony_cinamespace { 25ba5c3796Sopenharmony_ciconst std::string TAG = "MemMgrProxy"; 26ba5c3796Sopenharmony_ci} 27ba5c3796Sopenharmony_ci 28ba5c3796Sopenharmony_ciint32_t MemMgrProxy::GetBundlePriorityList(BundlePriorityList &bundlePrioList) 29ba5c3796Sopenharmony_ci{ 30ba5c3796Sopenharmony_ci HILOGE("called"); 31ba5c3796Sopenharmony_ci sptr<IRemoteObject> remote = Remote(); 32ba5c3796Sopenharmony_ci if (remote == nullptr) { 33ba5c3796Sopenharmony_ci HILOGE("remote is nullptr"); 34ba5c3796Sopenharmony_ci return ERR_NULL_OBJECT; 35ba5c3796Sopenharmony_ci } 36ba5c3796Sopenharmony_ci MessageParcel data; 37ba5c3796Sopenharmony_ci if (!data.WriteInterfaceToken(IMemMgr::GetDescriptor())) { 38ba5c3796Sopenharmony_ci HILOGE("write interface token failed"); 39ba5c3796Sopenharmony_ci return ERR_FLATTEN_OBJECT; 40ba5c3796Sopenharmony_ci } 41ba5c3796Sopenharmony_ci if (!data.WriteParcelable(&bundlePrioList)) { 42ba5c3796Sopenharmony_ci HILOGE("write bundlePrioList failed"); 43ba5c3796Sopenharmony_ci return ERR_FLATTEN_OBJECT; 44ba5c3796Sopenharmony_ci } 45ba5c3796Sopenharmony_ci MessageParcel reply; 46ba5c3796Sopenharmony_ci MessageOption option; 47ba5c3796Sopenharmony_ci int32_t error = remote->SendRequest( 48ba5c3796Sopenharmony_ci static_cast<uint32_t>(MemMgrInterfaceCode::MEM_MGR_GET_BUNDLE_PRIORITY_LIST), data, reply, option); 49ba5c3796Sopenharmony_ci if (error != ERR_NONE) { 50ba5c3796Sopenharmony_ci HILOGE("transact failed, error: %{public}d", error); 51ba5c3796Sopenharmony_ci return error; 52ba5c3796Sopenharmony_ci } 53ba5c3796Sopenharmony_ci std::shared_ptr<BundlePriorityList> list 54ba5c3796Sopenharmony_ci = std::shared_ptr<BundlePriorityList>(reply.ReadParcelable<BundlePriorityList>()); 55ba5c3796Sopenharmony_ci if (list == nullptr) { 56ba5c3796Sopenharmony_ci return -1; 57ba5c3796Sopenharmony_ci } 58ba5c3796Sopenharmony_ci bundlePrioList = *list; 59ba5c3796Sopenharmony_ci return ERR_OK; 60ba5c3796Sopenharmony_ci} 61ba5c3796Sopenharmony_ci 62ba5c3796Sopenharmony_ciint32_t MemMgrProxy::NotifyDistDevStatus(int32_t pid, int32_t uid, const std::string &name, bool connected) 63ba5c3796Sopenharmony_ci{ 64ba5c3796Sopenharmony_ci HILOGI("called, pid=%{public}d, uid=%{public}d, name=%{public}s, connected=%{public}d", pid, uid, name.c_str(), 65ba5c3796Sopenharmony_ci connected); 66ba5c3796Sopenharmony_ci sptr<IRemoteObject> remote = Remote(); 67ba5c3796Sopenharmony_ci if (remote == nullptr) { 68ba5c3796Sopenharmony_ci HILOGE("remote is nullptr"); 69ba5c3796Sopenharmony_ci return ERR_NULL_OBJECT; 70ba5c3796Sopenharmony_ci } 71ba5c3796Sopenharmony_ci MessageParcel data; 72ba5c3796Sopenharmony_ci if (!data.WriteInterfaceToken(IMemMgr::GetDescriptor())) { 73ba5c3796Sopenharmony_ci HILOGE("write interface token failed"); 74ba5c3796Sopenharmony_ci return ERR_FLATTEN_OBJECT; 75ba5c3796Sopenharmony_ci } 76ba5c3796Sopenharmony_ci if (!data.WriteInt32(pid) || !data.WriteInt32(uid) || !data.WriteString(name) || !data.WriteBool(connected)) { 77ba5c3796Sopenharmony_ci HILOGE("write params failed"); 78ba5c3796Sopenharmony_ci return ERR_INVALID_DATA; 79ba5c3796Sopenharmony_ci } 80ba5c3796Sopenharmony_ci MessageParcel reply; 81ba5c3796Sopenharmony_ci MessageOption option; 82ba5c3796Sopenharmony_ci int32_t error = remote->SendRequest( 83ba5c3796Sopenharmony_ci static_cast<uint32_t>(MemMgrInterfaceCode::MEM_MGR_NOTIFY_DIST_DEV_STATUS), data, reply, option); 84ba5c3796Sopenharmony_ci if (error != ERR_NONE) { 85ba5c3796Sopenharmony_ci HILOGE("transact failed, error: %{public}d", error); 86ba5c3796Sopenharmony_ci return error; 87ba5c3796Sopenharmony_ci } 88ba5c3796Sopenharmony_ci int32_t ret; 89ba5c3796Sopenharmony_ci if (!reply.ReadInt32(ret)) { 90ba5c3796Sopenharmony_ci HILOGE("read result failed"); 91ba5c3796Sopenharmony_ci return IPC_PROXY_ERR; 92ba5c3796Sopenharmony_ci } 93ba5c3796Sopenharmony_ci return ret; 94ba5c3796Sopenharmony_ci} 95ba5c3796Sopenharmony_ci 96ba5c3796Sopenharmony_ciint32_t MemMgrProxy::GetKillLevelOfLmkd(int32_t &killLevel) 97ba5c3796Sopenharmony_ci{ 98ba5c3796Sopenharmony_ci HILOGI("called"); 99ba5c3796Sopenharmony_ci sptr<IRemoteObject> remote = Remote(); 100ba5c3796Sopenharmony_ci if (remote == nullptr) { 101ba5c3796Sopenharmony_ci HILOGE("remote is nullptr"); 102ba5c3796Sopenharmony_ci return ERR_NULL_OBJECT; 103ba5c3796Sopenharmony_ci } 104ba5c3796Sopenharmony_ci MessageParcel data; 105ba5c3796Sopenharmony_ci if (!data.WriteInterfaceToken(IMemMgr::GetDescriptor())) { 106ba5c3796Sopenharmony_ci HILOGE("write interface token failed"); 107ba5c3796Sopenharmony_ci return ERR_FLATTEN_OBJECT; 108ba5c3796Sopenharmony_ci } 109ba5c3796Sopenharmony_ci 110ba5c3796Sopenharmony_ci MessageParcel reply; 111ba5c3796Sopenharmony_ci MessageOption option; 112ba5c3796Sopenharmony_ci int32_t error = remote->SendRequest( 113ba5c3796Sopenharmony_ci static_cast<uint32_t>(MemMgrInterfaceCode::MEM_MGR_GET_KILL_LEVEL_OF_LMKD), data, reply, option); 114ba5c3796Sopenharmony_ci if (error != ERR_NONE) { 115ba5c3796Sopenharmony_ci HILOGE("transact failed, error: %{public}d", error); 116ba5c3796Sopenharmony_ci return error; 117ba5c3796Sopenharmony_ci } 118ba5c3796Sopenharmony_ci 119ba5c3796Sopenharmony_ci int32_t curKillLevel = 0; 120ba5c3796Sopenharmony_ci if (!reply.ReadInt32(curKillLevel)) { 121ba5c3796Sopenharmony_ci HILOGE("read result failed"); 122ba5c3796Sopenharmony_ci return IPC_PROXY_ERR; 123ba5c3796Sopenharmony_ci } 124ba5c3796Sopenharmony_ci killLevel = curKillLevel; 125ba5c3796Sopenharmony_ci return ERR_OK; 126ba5c3796Sopenharmony_ci} 127ba5c3796Sopenharmony_ci 128ba5c3796Sopenharmony_ci#ifdef USE_PURGEABLE_MEMORY 129ba5c3796Sopenharmony_ciint32_t MemMgrProxy::RegisterActiveApps(int32_t pid, int32_t uid) 130ba5c3796Sopenharmony_ci{ 131ba5c3796Sopenharmony_ci HILOGI("called, pid=%{public}d, uid=%{public}d", pid, uid); 132ba5c3796Sopenharmony_ci sptr<IRemoteObject> remote = Remote(); 133ba5c3796Sopenharmony_ci if (remote == nullptr) { 134ba5c3796Sopenharmony_ci HILOGE("remote is nullptr"); 135ba5c3796Sopenharmony_ci return ERR_NULL_OBJECT; 136ba5c3796Sopenharmony_ci } 137ba5c3796Sopenharmony_ci MessageParcel data; 138ba5c3796Sopenharmony_ci if (!data.WriteInterfaceToken(IMemMgr::GetDescriptor())) { 139ba5c3796Sopenharmony_ci HILOGE("write interface token failed"); 140ba5c3796Sopenharmony_ci return ERR_FLATTEN_OBJECT; 141ba5c3796Sopenharmony_ci } 142ba5c3796Sopenharmony_ci if (!data.WriteInt32(pid) || !data.WriteInt32(uid)) { 143ba5c3796Sopenharmony_ci HILOGE("write params failed"); 144ba5c3796Sopenharmony_ci return ERR_INVALID_DATA; 145ba5c3796Sopenharmony_ci } 146ba5c3796Sopenharmony_ci MessageParcel reply; 147ba5c3796Sopenharmony_ci MessageOption option; 148ba5c3796Sopenharmony_ci int32_t error = remote->SendRequest( 149ba5c3796Sopenharmony_ci static_cast<uint32_t>(MemMgrInterfaceCode::MEM_MGR_REGISTER_ACTIVE_APPS), data, reply, option); 150ba5c3796Sopenharmony_ci if (error != ERR_NONE) { 151ba5c3796Sopenharmony_ci HILOGE("transact failed, error: %{public}d", error); 152ba5c3796Sopenharmony_ci return error; 153ba5c3796Sopenharmony_ci } 154ba5c3796Sopenharmony_ci int32_t ret; 155ba5c3796Sopenharmony_ci if (!reply.ReadInt32(ret)) { 156ba5c3796Sopenharmony_ci HILOGE("read result failed"); 157ba5c3796Sopenharmony_ci return IPC_PROXY_ERR; 158ba5c3796Sopenharmony_ci } 159ba5c3796Sopenharmony_ci return ret; 160ba5c3796Sopenharmony_ci} 161ba5c3796Sopenharmony_ci 162ba5c3796Sopenharmony_ciint32_t MemMgrProxy::DeregisterActiveApps(int32_t pid, int32_t uid) 163ba5c3796Sopenharmony_ci{ 164ba5c3796Sopenharmony_ci HILOGI("called, pid=%{public}d, uid=%{public}d", pid, uid); 165ba5c3796Sopenharmony_ci sptr<IRemoteObject> remote = Remote(); 166ba5c3796Sopenharmony_ci if (remote == nullptr) { 167ba5c3796Sopenharmony_ci HILOGE("remote is nullptr"); 168ba5c3796Sopenharmony_ci return ERR_NULL_OBJECT; 169ba5c3796Sopenharmony_ci } 170ba5c3796Sopenharmony_ci MessageParcel data; 171ba5c3796Sopenharmony_ci if (!data.WriteInterfaceToken(IMemMgr::GetDescriptor())) { 172ba5c3796Sopenharmony_ci HILOGE("write interface token failed"); 173ba5c3796Sopenharmony_ci return ERR_FLATTEN_OBJECT; 174ba5c3796Sopenharmony_ci } 175ba5c3796Sopenharmony_ci if (!data.WriteInt32(pid) || !data.WriteInt32(uid)) { 176ba5c3796Sopenharmony_ci HILOGE("write params failed"); 177ba5c3796Sopenharmony_ci return ERR_INVALID_DATA; 178ba5c3796Sopenharmony_ci } 179ba5c3796Sopenharmony_ci MessageParcel reply; 180ba5c3796Sopenharmony_ci MessageOption option; 181ba5c3796Sopenharmony_ci int32_t error = remote->SendRequest( 182ba5c3796Sopenharmony_ci static_cast<uint32_t>(MemMgrInterfaceCode::MEM_MGR_DEREGISTER_ACTIVE_APPS), data, reply, option); 183ba5c3796Sopenharmony_ci if (error != ERR_NONE) { 184ba5c3796Sopenharmony_ci HILOGE("transact failed, error: %{public}d", error); 185ba5c3796Sopenharmony_ci return error; 186ba5c3796Sopenharmony_ci } 187ba5c3796Sopenharmony_ci int32_t ret; 188ba5c3796Sopenharmony_ci if (!reply.ReadInt32(ret)) { 189ba5c3796Sopenharmony_ci HILOGE("read result failed"); 190ba5c3796Sopenharmony_ci return IPC_PROXY_ERR; 191ba5c3796Sopenharmony_ci } 192ba5c3796Sopenharmony_ci return ret; 193ba5c3796Sopenharmony_ci} 194ba5c3796Sopenharmony_ci 195ba5c3796Sopenharmony_ciint32_t MemMgrProxy::SubscribeAppState(const sptr<IAppStateSubscriber> &subscriber) 196ba5c3796Sopenharmony_ci{ 197ba5c3796Sopenharmony_ci HILOGI("called"); 198ba5c3796Sopenharmony_ci if (subscriber == nullptr) { 199ba5c3796Sopenharmony_ci HILOGE("subscriber is null"); 200ba5c3796Sopenharmony_ci return ERR_NULL_OBJECT; 201ba5c3796Sopenharmony_ci } 202ba5c3796Sopenharmony_ci sptr<IRemoteObject> remote = Remote(); 203ba5c3796Sopenharmony_ci if (remote == nullptr) { 204ba5c3796Sopenharmony_ci HILOGE("remote is nullptr"); 205ba5c3796Sopenharmony_ci return ERR_NULL_OBJECT; 206ba5c3796Sopenharmony_ci } 207ba5c3796Sopenharmony_ci MessageParcel data; 208ba5c3796Sopenharmony_ci if (!data.WriteInterfaceToken(IMemMgr::GetDescriptor())) { 209ba5c3796Sopenharmony_ci HILOGE("write interface token failed"); 210ba5c3796Sopenharmony_ci return ERR_FLATTEN_OBJECT; 211ba5c3796Sopenharmony_ci } 212ba5c3796Sopenharmony_ci if (!data.WriteRemoteObject(subscriber->AsObject())) { 213ba5c3796Sopenharmony_ci HILOGE("write subscriber failed"); 214ba5c3796Sopenharmony_ci return ERR_INVALID_DATA; 215ba5c3796Sopenharmony_ci } 216ba5c3796Sopenharmony_ci MessageParcel reply; 217ba5c3796Sopenharmony_ci MessageOption option; 218ba5c3796Sopenharmony_ci int32_t error = remote->SendRequest( 219ba5c3796Sopenharmony_ci static_cast<uint32_t>(MemMgrInterfaceCode::MEM_MGR_SUBSCRIBE_APP_STATE), data, reply, option); 220ba5c3796Sopenharmony_ci if (error != ERR_NONE) { 221ba5c3796Sopenharmony_ci HILOGE("transact failed, error: %{public}d", error); 222ba5c3796Sopenharmony_ci return error; 223ba5c3796Sopenharmony_ci } 224ba5c3796Sopenharmony_ci int32_t ret; 225ba5c3796Sopenharmony_ci if (!reply.ReadInt32(ret)) { 226ba5c3796Sopenharmony_ci HILOGE("read result failed"); 227ba5c3796Sopenharmony_ci return IPC_PROXY_ERR; 228ba5c3796Sopenharmony_ci } 229ba5c3796Sopenharmony_ci return ret; 230ba5c3796Sopenharmony_ci} 231ba5c3796Sopenharmony_ci 232ba5c3796Sopenharmony_ciint32_t MemMgrProxy::UnsubscribeAppState(const sptr<IAppStateSubscriber> &subscriber) 233ba5c3796Sopenharmony_ci{ 234ba5c3796Sopenharmony_ci HILOGI("called"); 235ba5c3796Sopenharmony_ci if (subscriber == nullptr) { 236ba5c3796Sopenharmony_ci HILOGE("subscriber is null"); 237ba5c3796Sopenharmony_ci return ERR_NULL_OBJECT; 238ba5c3796Sopenharmony_ci } 239ba5c3796Sopenharmony_ci sptr<IRemoteObject> remote = Remote(); 240ba5c3796Sopenharmony_ci if (remote == nullptr) { 241ba5c3796Sopenharmony_ci HILOGE("remote is nullptr"); 242ba5c3796Sopenharmony_ci return ERR_NULL_OBJECT; 243ba5c3796Sopenharmony_ci } 244ba5c3796Sopenharmony_ci MessageParcel data; 245ba5c3796Sopenharmony_ci if (!data.WriteInterfaceToken(IMemMgr::GetDescriptor())) { 246ba5c3796Sopenharmony_ci HILOGE("write interface token failed"); 247ba5c3796Sopenharmony_ci return ERR_FLATTEN_OBJECT; 248ba5c3796Sopenharmony_ci } 249ba5c3796Sopenharmony_ci if (!data.WriteRemoteObject(subscriber->AsObject())) { 250ba5c3796Sopenharmony_ci HILOGE("write subscriber failed"); 251ba5c3796Sopenharmony_ci return ERR_INVALID_DATA; 252ba5c3796Sopenharmony_ci } 253ba5c3796Sopenharmony_ci MessageParcel reply; 254ba5c3796Sopenharmony_ci MessageOption option; 255ba5c3796Sopenharmony_ci int32_t error = remote->SendRequest( 256ba5c3796Sopenharmony_ci static_cast<uint32_t>(MemMgrInterfaceCode::MEM_MGR_UNSUBSCRIBE_APP_STATE), data, reply, option); 257ba5c3796Sopenharmony_ci if (error != ERR_NONE) { 258ba5c3796Sopenharmony_ci HILOGE("transact failed, error: %{public}d", error); 259ba5c3796Sopenharmony_ci return error; 260ba5c3796Sopenharmony_ci } 261ba5c3796Sopenharmony_ci int32_t ret; 262ba5c3796Sopenharmony_ci if (!reply.ReadInt32(ret)) { 263ba5c3796Sopenharmony_ci HILOGE("read result failed"); 264ba5c3796Sopenharmony_ci return IPC_PROXY_ERR; 265ba5c3796Sopenharmony_ci } 266ba5c3796Sopenharmony_ci return ret; 267ba5c3796Sopenharmony_ci} 268ba5c3796Sopenharmony_ci 269ba5c3796Sopenharmony_ciint32_t MemMgrProxy::GetAvailableMemory(int32_t &memSize) 270ba5c3796Sopenharmony_ci{ 271ba5c3796Sopenharmony_ci HILOGI("called"); 272ba5c3796Sopenharmony_ci sptr<IRemoteObject> remote = Remote(); 273ba5c3796Sopenharmony_ci if (remote == nullptr) { 274ba5c3796Sopenharmony_ci HILOGE("remote is nullptr"); 275ba5c3796Sopenharmony_ci return ERR_NULL_OBJECT; 276ba5c3796Sopenharmony_ci } 277ba5c3796Sopenharmony_ci MessageParcel data; 278ba5c3796Sopenharmony_ci if (!data.WriteInterfaceToken(IMemMgr::GetDescriptor())) { 279ba5c3796Sopenharmony_ci HILOGE("write interface token failed"); 280ba5c3796Sopenharmony_ci return ERR_FLATTEN_OBJECT; 281ba5c3796Sopenharmony_ci } 282ba5c3796Sopenharmony_ci MessageParcel reply; 283ba5c3796Sopenharmony_ci MessageOption option; 284ba5c3796Sopenharmony_ci int32_t error = remote->SendRequest( 285ba5c3796Sopenharmony_ci static_cast<uint32_t>(MemMgrInterfaceCode::MEM_MGR_GET_AVAILABLE_MEMORY), data, reply, option); 286ba5c3796Sopenharmony_ci if (error != ERR_NONE) { 287ba5c3796Sopenharmony_ci HILOGE("transact failed, error: %{public}d", error); 288ba5c3796Sopenharmony_ci return error; 289ba5c3796Sopenharmony_ci } 290ba5c3796Sopenharmony_ci if (!reply.ReadInt32(memSize)) { 291ba5c3796Sopenharmony_ci HILOGE("read result failed"); 292ba5c3796Sopenharmony_ci return IPC_PROXY_ERR; 293ba5c3796Sopenharmony_ci } 294ba5c3796Sopenharmony_ci return ERR_OK; 295ba5c3796Sopenharmony_ci} 296ba5c3796Sopenharmony_ci 297ba5c3796Sopenharmony_ciint32_t MemMgrProxy::GetTotalMemory(int32_t &memSize) 298ba5c3796Sopenharmony_ci{ 299ba5c3796Sopenharmony_ci HILOGI("called"); 300ba5c3796Sopenharmony_ci sptr<IRemoteObject> remote = Remote(); 301ba5c3796Sopenharmony_ci if (remote == nullptr) { 302ba5c3796Sopenharmony_ci HILOGE("remote is nullptr"); 303ba5c3796Sopenharmony_ci return ERR_NULL_OBJECT; 304ba5c3796Sopenharmony_ci } 305ba5c3796Sopenharmony_ci MessageParcel data; 306ba5c3796Sopenharmony_ci if (!data.WriteInterfaceToken(IMemMgr::GetDescriptor())) { 307ba5c3796Sopenharmony_ci HILOGE("write interface token failed"); 308ba5c3796Sopenharmony_ci return ERR_FLATTEN_OBJECT; 309ba5c3796Sopenharmony_ci } 310ba5c3796Sopenharmony_ci MessageParcel reply; 311ba5c3796Sopenharmony_ci MessageOption option; 312ba5c3796Sopenharmony_ci int32_t error = remote->SendRequest( 313ba5c3796Sopenharmony_ci static_cast<uint32_t>(MemMgrInterfaceCode::MEM_MGR_GET_TOTAL_MEMORY), data, reply, option); 314ba5c3796Sopenharmony_ci if (error != ERR_NONE) { 315ba5c3796Sopenharmony_ci HILOGE("transact failed, error: %{public}d", error); 316ba5c3796Sopenharmony_ci return error; 317ba5c3796Sopenharmony_ci } 318ba5c3796Sopenharmony_ci if (!reply.ReadInt32(memSize)) { 319ba5c3796Sopenharmony_ci HILOGE("read result failed"); 320ba5c3796Sopenharmony_ci return IPC_PROXY_ERR; 321ba5c3796Sopenharmony_ci } 322ba5c3796Sopenharmony_ci return ERR_OK; 323ba5c3796Sopenharmony_ci} 324ba5c3796Sopenharmony_ci#endif // USE_PURGEABLE_MEMORY 325ba5c3796Sopenharmony_ci 326ba5c3796Sopenharmony_ciint32_t MemMgrProxy::OnWindowVisibilityChanged(const std::vector<sptr<MemMgrWindowInfo>> &MemMgrWindowInfo) 327ba5c3796Sopenharmony_ci{ 328ba5c3796Sopenharmony_ci HILOGD("called"); 329ba5c3796Sopenharmony_ci sptr<IRemoteObject> remote = Remote(); 330ba5c3796Sopenharmony_ci if (remote == nullptr) { 331ba5c3796Sopenharmony_ci HILOGE("remote is nullptr"); 332ba5c3796Sopenharmony_ci return ERR_NULL_OBJECT; 333ba5c3796Sopenharmony_ci } 334ba5c3796Sopenharmony_ci MessageParcel data; 335ba5c3796Sopenharmony_ci if (!data.WriteInterfaceToken(IMemMgr::GetDescriptor())) { 336ba5c3796Sopenharmony_ci HILOGE("write interface token failed"); 337ba5c3796Sopenharmony_ci return ERR_FLATTEN_OBJECT; 338ba5c3796Sopenharmony_ci } 339ba5c3796Sopenharmony_ci if (!data.WriteUint32(static_cast<uint32_t>(MemMgrWindowInfo.size()))) { 340ba5c3796Sopenharmony_ci HILOGE("write MemMgrWindowInfo size failed"); 341ba5c3796Sopenharmony_ci return ERR_INVALID_DATA; 342ba5c3796Sopenharmony_ci } 343ba5c3796Sopenharmony_ci for (auto &info : MemMgrWindowInfo) { 344ba5c3796Sopenharmony_ci if (!data.WriteParcelable(info)) { 345ba5c3796Sopenharmony_ci HILOGE("write MemMgrWindowInfo failed"); 346ba5c3796Sopenharmony_ci return ERR_INVALID_DATA; 347ba5c3796Sopenharmony_ci } 348ba5c3796Sopenharmony_ci } 349ba5c3796Sopenharmony_ci MessageParcel reply; 350ba5c3796Sopenharmony_ci MessageOption option; 351ba5c3796Sopenharmony_ci int32_t error = remote->SendRequest( 352ba5c3796Sopenharmony_ci static_cast<uint32_t>(MemMgrInterfaceCode::MEM_MGR_ON_WINDOW_VISIBILITY_CHANGED), data, reply, option); 353ba5c3796Sopenharmony_ci if (error != ERR_NONE) { 354ba5c3796Sopenharmony_ci HILOGE("transact failed, error: %{public}d", error); 355ba5c3796Sopenharmony_ci return error; 356ba5c3796Sopenharmony_ci } 357ba5c3796Sopenharmony_ci int32_t ret; 358ba5c3796Sopenharmony_ci if (!reply.ReadInt32(ret)) { 359ba5c3796Sopenharmony_ci HILOGE("read result failed"); 360ba5c3796Sopenharmony_ci return IPC_PROXY_ERR; 361ba5c3796Sopenharmony_ci } 362ba5c3796Sopenharmony_ci return ret; 363ba5c3796Sopenharmony_ci} 364ba5c3796Sopenharmony_ci 365ba5c3796Sopenharmony_ciint32_t MemMgrProxy::GetReclaimPriorityByPid(int32_t pid, int32_t &priority) 366ba5c3796Sopenharmony_ci{ 367ba5c3796Sopenharmony_ci HILOGD("called"); 368ba5c3796Sopenharmony_ci sptr<IRemoteObject> remote = Remote(); 369ba5c3796Sopenharmony_ci if (remote == nullptr) { 370ba5c3796Sopenharmony_ci HILOGE("remote is nullptr"); 371ba5c3796Sopenharmony_ci return ERR_NULL_OBJECT; 372ba5c3796Sopenharmony_ci } 373ba5c3796Sopenharmony_ci MessageParcel data; 374ba5c3796Sopenharmony_ci if (!data.WriteInterfaceToken(IMemMgr::GetDescriptor())) { 375ba5c3796Sopenharmony_ci HILOGE("write interface token failed"); 376ba5c3796Sopenharmony_ci return ERR_FLATTEN_OBJECT; 377ba5c3796Sopenharmony_ci } 378ba5c3796Sopenharmony_ci if (!data.WriteInt32(pid)) { 379ba5c3796Sopenharmony_ci HILOGE("write pid failed"); 380ba5c3796Sopenharmony_ci return ERR_INVALID_DATA; 381ba5c3796Sopenharmony_ci } 382ba5c3796Sopenharmony_ci MessageParcel reply; 383ba5c3796Sopenharmony_ci MessageOption option; 384ba5c3796Sopenharmony_ci int32_t error = remote->SendRequest( 385ba5c3796Sopenharmony_ci static_cast<uint32_t>(MemMgrInterfaceCode::MEM_MGR_GET_PRIORITY_BY_PID), data, reply, option); 386ba5c3796Sopenharmony_ci if (error != ERR_NONE) { 387ba5c3796Sopenharmony_ci HILOGE("transact failed, error: %{public}d", error); 388ba5c3796Sopenharmony_ci return error; 389ba5c3796Sopenharmony_ci } 390ba5c3796Sopenharmony_ci 391ba5c3796Sopenharmony_ci int32_t curPriority = RECLAIM_PRIORITY_UNKNOWN + 1; 392ba5c3796Sopenharmony_ci if (!reply.ReadInt32(curPriority)) { 393ba5c3796Sopenharmony_ci HILOGE("read result failed"); 394ba5c3796Sopenharmony_ci return IPC_PROXY_ERR; 395ba5c3796Sopenharmony_ci } 396ba5c3796Sopenharmony_ci priority = curPriority; 397ba5c3796Sopenharmony_ci return ERR_OK; 398ba5c3796Sopenharmony_ci} 399ba5c3796Sopenharmony_ci 400ba5c3796Sopenharmony_ciint32_t MemMgrProxy::NotifyProcessStateChangedSync(const MemMgrProcessStateInfo &processStateInfo) 401ba5c3796Sopenharmony_ci{ 402ba5c3796Sopenharmony_ci HILOGD("called"); 403ba5c3796Sopenharmony_ci sptr<IRemoteObject> remote = Remote(); 404ba5c3796Sopenharmony_ci if (remote == nullptr) { 405ba5c3796Sopenharmony_ci HILOGE("remote is nullptr"); 406ba5c3796Sopenharmony_ci return ERR_NULL_OBJECT; 407ba5c3796Sopenharmony_ci } 408ba5c3796Sopenharmony_ci MessageParcel data; 409ba5c3796Sopenharmony_ci if (!data.WriteInterfaceToken(IMemMgr::GetDescriptor())) { 410ba5c3796Sopenharmony_ci HILOGE("write interface token failed"); 411ba5c3796Sopenharmony_ci return ERR_FLATTEN_OBJECT; 412ba5c3796Sopenharmony_ci } 413ba5c3796Sopenharmony_ci if (!data.WriteParcelable(&processStateInfo)) { 414ba5c3796Sopenharmony_ci HILOGE("write data failed"); 415ba5c3796Sopenharmony_ci return ERR_INVALID_DATA; 416ba5c3796Sopenharmony_ci } 417ba5c3796Sopenharmony_ci MessageParcel reply; 418ba5c3796Sopenharmony_ci MessageOption option; 419ba5c3796Sopenharmony_ci int32_t error = remote->SendRequest( 420ba5c3796Sopenharmony_ci static_cast<uint32_t>(MemMgrInterfaceCode::MEM_MGR_NOTIFY_PROCESS_STATE_CHANGED_SYNC), data, reply, option); 421ba5c3796Sopenharmony_ci if (error != ERR_NONE) { 422ba5c3796Sopenharmony_ci HILOGE("transact failed, error: %{public}d", error); 423ba5c3796Sopenharmony_ci return error; 424ba5c3796Sopenharmony_ci } 425ba5c3796Sopenharmony_ci int32_t ret; 426ba5c3796Sopenharmony_ci if (!reply.ReadInt32(ret)) { 427ba5c3796Sopenharmony_ci HILOGE("read result failed"); 428ba5c3796Sopenharmony_ci return IPC_PROXY_ERR; 429ba5c3796Sopenharmony_ci } 430ba5c3796Sopenharmony_ci return ret; 431ba5c3796Sopenharmony_ci} 432ba5c3796Sopenharmony_ci 433ba5c3796Sopenharmony_ciint32_t MemMgrProxy::NotifyProcessStateChangedAsync(const MemMgrProcessStateInfo &processStateInfo) 434ba5c3796Sopenharmony_ci{ 435ba5c3796Sopenharmony_ci HILOGD("called"); 436ba5c3796Sopenharmony_ci sptr<IRemoteObject> remote = Remote(); 437ba5c3796Sopenharmony_ci if (remote == nullptr) { 438ba5c3796Sopenharmony_ci HILOGE("remote is nullptr"); 439ba5c3796Sopenharmony_ci return ERR_NULL_OBJECT; 440ba5c3796Sopenharmony_ci } 441ba5c3796Sopenharmony_ci MessageParcel data; 442ba5c3796Sopenharmony_ci if (!data.WriteInterfaceToken(IMemMgr::GetDescriptor())) { 443ba5c3796Sopenharmony_ci HILOGE("write interface token failed"); 444ba5c3796Sopenharmony_ci return ERR_FLATTEN_OBJECT; 445ba5c3796Sopenharmony_ci } 446ba5c3796Sopenharmony_ci if (!data.WriteParcelable(&processStateInfo)) { 447ba5c3796Sopenharmony_ci HILOGE("write data failed"); 448ba5c3796Sopenharmony_ci return ERR_INVALID_DATA; 449ba5c3796Sopenharmony_ci } 450ba5c3796Sopenharmony_ci MessageParcel reply; 451ba5c3796Sopenharmony_ci MessageOption option; 452ba5c3796Sopenharmony_ci int32_t error = remote->SendRequest( 453ba5c3796Sopenharmony_ci static_cast<uint32_t>(MemMgrInterfaceCode::MEM_MGR_NOTIFY_PROCESS_STATE_CHANGED_ASYNC), data, reply, option); 454ba5c3796Sopenharmony_ci if (error != ERR_NONE) { 455ba5c3796Sopenharmony_ci HILOGE("transact failed, error: %{public}d", error); 456ba5c3796Sopenharmony_ci return error; 457ba5c3796Sopenharmony_ci } 458ba5c3796Sopenharmony_ci int32_t ret; 459ba5c3796Sopenharmony_ci if (!reply.ReadInt32(ret)) { 460ba5c3796Sopenharmony_ci HILOGE("read result failed"); 461ba5c3796Sopenharmony_ci return IPC_PROXY_ERR; 462ba5c3796Sopenharmony_ci } 463ba5c3796Sopenharmony_ci return ret; 464ba5c3796Sopenharmony_ci} 465ba5c3796Sopenharmony_ci 466ba5c3796Sopenharmony_ciint32_t MemMgrProxy::NotifyProcessStatus(int32_t pid, int32_t type, int32_t status, int32_t saId) 467ba5c3796Sopenharmony_ci{ 468ba5c3796Sopenharmony_ci HILOGD("called"); 469ba5c3796Sopenharmony_ci sptr<IRemoteObject> remote = Remote(); 470ba5c3796Sopenharmony_ci if (remote == nullptr) { 471ba5c3796Sopenharmony_ci HILOGE("remote is nullptr"); 472ba5c3796Sopenharmony_ci return ERR_NULL_OBJECT; 473ba5c3796Sopenharmony_ci } 474ba5c3796Sopenharmony_ci MessageParcel data; 475ba5c3796Sopenharmony_ci if (!data.WriteInterfaceToken(IMemMgr::GetDescriptor())) { 476ba5c3796Sopenharmony_ci HILOGE("write interface token failed"); 477ba5c3796Sopenharmony_ci return ERR_FLATTEN_OBJECT; 478ba5c3796Sopenharmony_ci } 479ba5c3796Sopenharmony_ci if (!data.WriteInt32(pid)) { 480ba5c3796Sopenharmony_ci HILOGE("write pid failed"); 481ba5c3796Sopenharmony_ci return ERR_INVALID_DATA; 482ba5c3796Sopenharmony_ci } 483ba5c3796Sopenharmony_ci if (!data.WriteInt32(type)) { 484ba5c3796Sopenharmony_ci HILOGE("write type failed"); 485ba5c3796Sopenharmony_ci return ERR_INVALID_DATA; 486ba5c3796Sopenharmony_ci } 487ba5c3796Sopenharmony_ci if (!data.WriteInt32(status)) { 488ba5c3796Sopenharmony_ci HILOGE("write status failed"); 489ba5c3796Sopenharmony_ci return ERR_INVALID_DATA; 490ba5c3796Sopenharmony_ci } 491ba5c3796Sopenharmony_ci if (!data.WriteInt32(saId)) { 492ba5c3796Sopenharmony_ci HILOGE("write saId failed"); 493ba5c3796Sopenharmony_ci return ERR_INVALID_DATA; 494ba5c3796Sopenharmony_ci } 495ba5c3796Sopenharmony_ci MessageParcel reply; 496ba5c3796Sopenharmony_ci MessageOption option; 497ba5c3796Sopenharmony_ci int32_t error = remote->SendRequest( 498ba5c3796Sopenharmony_ci static_cast<uint32_t>(MemMgrInterfaceCode::MEM_MGR_NOTIFY_PROCESS_STATUS), data, reply, option); 499ba5c3796Sopenharmony_ci if (error != ERR_NONE) { 500ba5c3796Sopenharmony_ci HILOGE("transact failed, error: %{public}d", error); 501ba5c3796Sopenharmony_ci } 502ba5c3796Sopenharmony_ci return ERR_OK; 503ba5c3796Sopenharmony_ci} 504ba5c3796Sopenharmony_ci 505ba5c3796Sopenharmony_ciint32_t MemMgrProxy::SetCritical(int32_t pid, bool critical, int32_t saId) 506ba5c3796Sopenharmony_ci{ 507ba5c3796Sopenharmony_ci HILOGD("called"); 508ba5c3796Sopenharmony_ci sptr<IRemoteObject> remote = Remote(); 509ba5c3796Sopenharmony_ci if (remote == nullptr) { 510ba5c3796Sopenharmony_ci HILOGE("remote is nullptr"); 511ba5c3796Sopenharmony_ci return ERR_NULL_OBJECT; 512ba5c3796Sopenharmony_ci } 513ba5c3796Sopenharmony_ci MessageParcel data; 514ba5c3796Sopenharmony_ci if (!data.WriteInterfaceToken(IMemMgr::GetDescriptor())) { 515ba5c3796Sopenharmony_ci HILOGE("write interface token failed"); 516ba5c3796Sopenharmony_ci return ERR_FLATTEN_OBJECT; 517ba5c3796Sopenharmony_ci } 518ba5c3796Sopenharmony_ci if (!data.WriteInt32(pid)) { 519ba5c3796Sopenharmony_ci HILOGE("write pid failed"); 520ba5c3796Sopenharmony_ci return ERR_INVALID_DATA; 521ba5c3796Sopenharmony_ci } 522ba5c3796Sopenharmony_ci if (!data.WriteBool(critical)) { 523ba5c3796Sopenharmony_ci HILOGE("write critical failed"); 524ba5c3796Sopenharmony_ci return ERR_INVALID_DATA; 525ba5c3796Sopenharmony_ci } 526ba5c3796Sopenharmony_ci if (!data.WriteInt32(saId)) { 527ba5c3796Sopenharmony_ci HILOGE("write saId failed"); 528ba5c3796Sopenharmony_ci return ERR_INVALID_DATA; 529ba5c3796Sopenharmony_ci } 530ba5c3796Sopenharmony_ci MessageParcel reply; 531ba5c3796Sopenharmony_ci MessageOption option; 532ba5c3796Sopenharmony_ci int32_t error = remote->SendRequest( 533ba5c3796Sopenharmony_ci static_cast<uint32_t>(MemMgrInterfaceCode::MEM_MGR_SET_CRITICAL), data, reply, option); 534ba5c3796Sopenharmony_ci if (error != ERR_NONE) { 535ba5c3796Sopenharmony_ci HILOGE("transact failed, error: %{public}d", error); 536ba5c3796Sopenharmony_ci } 537ba5c3796Sopenharmony_ci return ERR_OK; 538ba5c3796Sopenharmony_ci} 539ba5c3796Sopenharmony_ci} // namespace Memory 540ba5c3796Sopenharmony_ci} // namespace OHOS 541