• 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_stub.h"
17 #include "memmgr_log.h"
18 
19 namespace OHOS {
20 namespace Memory {
21 namespace {
22     const std::string TAG = "MemMgrStub";
23 }
24 
MemMgrStub()25 MemMgrStub::MemMgrStub()
26 {
27     memberFuncMap_[static_cast<uint32_t>(IMemMgr::MEM_MGR_GET_BUNDLE_PRIORITY_LIST)] =
28         &MemMgrStub::HandleGetBunldePriorityList;
29     memberFuncMap_[static_cast<uint32_t>(IMemMgr::MEM_MGR_NOTIFY_DIST_DEV_STATUS)] =
30         &MemMgrStub::HandleNotifyDistDevStatus;
31 }
32 
~MemMgrStub()33 MemMgrStub::~MemMgrStub()
34 {
35     memberFuncMap_.clear();
36 }
37 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)38 int MemMgrStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
39 {
40     HILOGI("MemMgrStub::OnReceived, code = %{public}d, flags= %{public}d.", code, option.GetFlags());
41     std::u16string descriptor = MemMgrStub::GetDescriptor();
42     std::u16string remoteDescriptor = data.ReadInterfaceToken();
43     if (descriptor != remoteDescriptor) {
44         HILOGE("local descriptor is not equal to remote");
45         return ERR_INVALID_STATE;
46     }
47 
48     auto itFunc = memberFuncMap_.find(code);
49     if (itFunc != memberFuncMap_.end()) {
50         auto memberFunc = itFunc->second;
51         if (memberFunc != nullptr) {
52             return (this->*memberFunc)(data, reply);
53         }
54     }
55     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
56 }
57 
HandleGetBunldePriorityList(MessageParcel & data,MessageParcel & reply)58 int32_t MemMgrStub::HandleGetBunldePriorityList(MessageParcel &data, MessageParcel &reply)
59 {
60     HILOGI("called");
61     std::shared_ptr<BundlePriorityList> list
62         = std::shared_ptr<BundlePriorityList>(data.ReadParcelable<BundlePriorityList>());
63 
64     if (!list) {
65         HILOGE("BundlePriorityList ReadParcelable failed");
66         return -1;
67     }
68     int32_t ret = GetBundlePriorityList(*list);
69     reply.WriteParcelable(list.get());
70     return ret;
71 }
72 
HandleNotifyDistDevStatus(MessageParcel & data,MessageParcel & reply)73 int32_t MemMgrStub::HandleNotifyDistDevStatus(MessageParcel &data, MessageParcel &reply)
74 {
75     HILOGI("called");
76     int32_t pid = 0;
77     int32_t uid = 0;
78     std::string name;
79     bool connected;
80     if (!data.ReadInt32(pid) || !data.ReadInt32(uid) || !data.ReadString(name) || !data.ReadBool(connected)) {
81         HILOGE("read params failed");
82         return IPC_STUB_ERR;
83     }
84     HILOGI("called, pid=%{public}d, uid=%{public}d, name=%{public}s, connected=%{public}d", pid, uid, name.c_str(),
85         connected);
86 
87     int32_t ret = NotifyDistDevStatus(pid, uid, name, connected);
88     if (!reply.WriteInt32(ret)) {
89         return IPC_STUB_ERR;
90     }
91     return ret;
92 }
93 } // namespace Memory
94 } // namespace OHOS
95