1 /*
2 * Copyright (c) 2021-2024 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_tag_wrapper.h"
19
20 namespace OHOS {
21 namespace AAFwk {
WantReceiverStub()22 WantReceiverStub::WantReceiverStub() {}
23
~WantReceiverStub()24 WantReceiverStub::~WantReceiverStub() {}
25
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)26 int WantReceiverStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
27 {
28 TAG_LOGD(AAFwkTag::WANTAGENT, "cmd = %d, flags= %d", code, option.GetFlags());
29 std::u16string descriptor = WantReceiverStub::GetDescriptor();
30 std::u16string remoteDescriptor = data.ReadInterfaceToken();
31 if (descriptor != remoteDescriptor) {
32 TAG_LOGE(AAFwkTag::WANTAGENT, "local descriptor is not equal to remote");
33 return ERR_INVALID_STATE;
34 }
35
36 switch (code) {
37 case WANT_RECEIVER_SEND:
38 return SendInner(data, reply);
39 case WANT_RECEIVER_PERFORM_RECEIVE:
40 return PerformReceiveInner(data, reply);
41 }
42 TAG_LOGW(AAFwkTag::WANTAGENT, "default case, need check");
43 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
44 }
45
SendInner(MessageParcel & data,MessageParcel & reply)46 int WantReceiverStub::SendInner(MessageParcel &data, MessageParcel &reply)
47 {
48 int32_t resultCode = data.ReadInt32();
49 Send(resultCode);
50 return NO_ERROR;
51 }
52
PerformReceiveInner(MessageParcel & data,MessageParcel & reply)53 int WantReceiverStub::PerformReceiveInner(MessageParcel &data, MessageParcel &reply)
54 {
55 Want *want = data.ReadParcelable<Want>();
56 if (want == nullptr) {
57 TAG_LOGE(AAFwkTag::WANTAGENT, "want is nullptr");
58 return ERR_INVALID_VALUE;
59 }
60
61 int resultCode = data.ReadInt32();
62 std::string bundleName = Str16ToStr8(data.ReadString16());
63
64 WantParams *wantParams = data.ReadParcelable<WantParams>();
65 if (wantParams == nullptr) {
66 TAG_LOGE(AAFwkTag::WANTAGENT, "wantParams is nullptr");
67 delete want;
68 return ERR_INVALID_VALUE;
69 }
70
71 bool serialized = data.ReadBool();
72 bool sticky = data.ReadBool();
73 int sendingUser = data.ReadInt32();
74 PerformReceive(*want, resultCode, bundleName, *wantParams, serialized, sticky, sendingUser);
75 delete want;
76 delete wantParams;
77 return NO_ERROR;
78 }
79 } // namespace AAFwk
80 } // namespace OHOS
81