• 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 "mem_mgr_proxy.h"
17 #include "memmgr_log.h"
18 
19 namespace OHOS {
20 namespace Memory {
21 namespace {
22 const std::string TAG = "MemMgrProxy";
23 }
24 
GetBundlePriorityList(BundlePriorityList & bundlePrioList)25 int32_t MemMgrProxy::GetBundlePriorityList(BundlePriorityList &bundlePrioList)
26 {
27     HILOGE("called");
28     sptr<IRemoteObject> remote = Remote();
29     MessageParcel data;
30     if (!data.WriteInterfaceToken(IMemMgr::GetDescriptor())) {
31         HILOGE("write interface token failed");
32         return ERR_FLATTEN_OBJECT;
33     }
34     if (!data.WriteParcelable(&bundlePrioList)) {
35         HILOGE("write bundlePrioList failed");
36         return ERR_FLATTEN_OBJECT;
37     }
38     MessageParcel reply;
39     MessageOption option;
40     int32_t error = remote->SendRequest(IMemMgr::MEM_MGR_GET_BUNDLE_PRIORITY_LIST, data, reply, option);
41     if (error != ERR_NONE) {
42         HILOGE("transact failed, error: %{public}d", error);
43         return error;
44     }
45     std::shared_ptr<BundlePriorityList> list
46         = std::shared_ptr<BundlePriorityList>(reply.ReadParcelable<BundlePriorityList>());
47     if (list == nullptr) {
48         return -1;
49     }
50     bundlePrioList = *list;
51     return ERR_OK;
52 }
53 
NotifyDistDevStatus(int32_t pid,int32_t uid,const std::string & name,bool connected)54 int32_t MemMgrProxy::NotifyDistDevStatus(int32_t pid, int32_t uid, const std::string &name, bool connected)
55 {
56     HILOGI("called, pid=%{public}d, uid=%{public}d, name=%{public}s, connected=%{public}d", pid, uid, name.c_str(),
57         connected);
58     sptr<IRemoteObject> remote = Remote();
59     MessageParcel data;
60     if (!data.WriteInterfaceToken(IMemMgr::GetDescriptor())) {
61         HILOGE("write interface token failed");
62         return ERR_FLATTEN_OBJECT;
63     }
64     if (!data.WriteInt32(pid) || !data.WriteInt32(uid) || !data.WriteString(name) || !data.WriteBool(connected)) {
65         HILOGE("write params failed");
66         return ERR_INVALID_DATA;
67     }
68     MessageParcel reply;
69     MessageOption option;
70     int32_t error = remote->SendRequest(IMemMgr::MEM_MGR_NOTIFY_DIST_DEV_STATUS, data, reply, option);
71     if (error != ERR_NONE) {
72         HILOGE("transact failed, error: %{public}d", error);
73         return error;
74     }
75     int32_t ret;
76     if (!reply.ReadInt32(ret)) {
77         HILOGE("read result failed");
78         return IPC_PROXY_ERR;
79     }
80     return ret;
81 }
82 } // namespace Memory
83 } // namespace OHOS
84