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_sender_stub.h"
17
18#include "hilog_tag_wrapper.h"
19#include "ipc_types.h"
20
21namespace OHOS {
22namespace AAFwk {
23WantSenderStub::WantSenderStub() {}
24
25WantSenderStub::~WantSenderStub() {}
26
27int WantSenderStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
28{
29    TAG_LOGD(AAFwkTag::WANTAGENT, "cmd = %d, flags= %d", code, option.GetFlags());
30    std::u16string descriptor = WantSenderStub::GetDescriptor();
31    std::u16string remoteDescriptor = data.ReadInterfaceToken();
32    if (descriptor != remoteDescriptor) {
33        TAG_LOGE(AAFwkTag::WANTAGENT, "local descriptor invalid");
34        return ERR_INVALID_STATE;
35    }
36
37    if (code == (WANT_SENDER_SEND)) {
38        return SendInner(data, reply);
39    }
40    TAG_LOGW(AAFwkTag::WANTAGENT, "default case, need check");
41    return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
42}
43
44int WantSenderStub::SendInner(MessageParcel &data, MessageParcel &reply)
45{
46    SenderInfo *senderInfo = data.ReadParcelable<SenderInfo>();
47    if (senderInfo == nullptr) {
48        TAG_LOGE(AAFwkTag::WANTAGENT, "null senderInfo");
49        return ERR_INVALID_VALUE;
50    }
51    Send(*senderInfo);
52    delete senderInfo;
53    return NO_ERROR;
54}
55}  // namespace AAFwk
56}  // namespace OHOS
57