1 /*
2 * Copyright (c) 2021 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 "want_receiver_stub.h"
17
18 #include "hilog_wrapper.h"
19 #include "ipc_types.h"
20
21 #include "pac_map.h"
22
23 namespace OHOS {
24 namespace AAFwk {
WantReceiverStub()25 WantReceiverStub::WantReceiverStub()
26 {
27 requestFuncMap_[WANT_RECEIVER_SEND] = &WantReceiverStub::SendInner;
28 requestFuncMap_[WANT_RECEIVER_PERFORM_RECEIVE] = &WantReceiverStub::PerformReceiveInner;
29 }
30
~WantReceiverStub()31 WantReceiverStub::~WantReceiverStub()
32 {
33 requestFuncMap_.clear();
34 }
35
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)36 int WantReceiverStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
37 {
38 HILOG_DEBUG("WantReceiverStub::OnRemoteRequest, cmd = %d, flags= %d", code, option.GetFlags());
39 std::u16string descriptor = WantReceiverStub::GetDescriptor();
40 std::u16string remoteDescriptor = data.ReadInterfaceToken();
41 if (descriptor != remoteDescriptor) {
42 HILOG_INFO("local descriptor is not equal to remote");
43 return ERR_INVALID_STATE;
44 }
45
46 auto itFunc = requestFuncMap_.find(code);
47 if (itFunc != requestFuncMap_.end()) {
48 auto requestFunc = itFunc->second;
49 if (requestFunc != nullptr) {
50 return (this->*requestFunc)(data, reply);
51 }
52 }
53 HILOG_WARN("WantReceiverStub::OnRemoteRequest, default case, need check.");
54 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
55 }
56
SendInner(MessageParcel & data,MessageParcel & reply)57 int WantReceiverStub::SendInner(MessageParcel &data, MessageParcel &reply)
58 {
59 int32_t resultCode = data.ReadInt32();
60 Send(resultCode);
61 return NO_ERROR;
62 }
63
PerformReceiveInner(MessageParcel & data,MessageParcel & reply)64 int WantReceiverStub::PerformReceiveInner(MessageParcel &data, MessageParcel &reply)
65 {
66 Want *want = data.ReadParcelable<Want>();
67 if (want == nullptr) {
68 HILOG_ERROR("AbilityManagerStub: want is nullptr");
69 return ERR_INVALID_VALUE;
70 }
71
72 int resultCode = data.ReadInt32();
73 std::string bundleName = Str16ToStr8(data.ReadString16());
74
75 WantParams *wantParams = data.ReadParcelable<WantParams>();
76 if (wantParams == nullptr) {
77 HILOG_ERROR("AbilityManagerStub: wantParams is nullptr");
78 return ERR_INVALID_VALUE;
79 }
80
81 bool serialized = data.ReadBool();
82 bool sticky = data.ReadBool();
83 int sendingUser = data.ReadInt32();
84
85 PerformReceive(*want, resultCode, bundleName, *wantParams, serialized, sticky, sendingUser);
86 return NO_ERROR;
87 }
88 } // namespace AAFwk
89 } // namespace OHOS