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 #include "dialog_callback_stub.h"
16 #include "hilog_wrapper.h"
17 #include "ui_service_stub.h"
18
19 namespace OHOS {
20 namespace Ace {
DialogCallbackStub(DialogCallback callback)21 DialogCallbackStub::DialogCallbackStub(DialogCallback callback)
22 {
23 callback_ = callback;
24 }
25
~DialogCallbackStub()26 DialogCallbackStub::~DialogCallbackStub()
27 {
28 }
29
OnDialogCallback(int32_t id,const std::string & event,const std::string & params)30 void DialogCallbackStub::OnDialogCallback(int32_t id, const std::string& event, const std::string& params)
31 {
32 callback_(id, event, params);
33 }
34
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)35 int DialogCallbackStub::OnRemoteRequest(
36 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
37 {
38 HILOG_DEBUG("DialogCallbackStub::%{public}s, cmd = %{public}d, flags= %{public}d, code=%{public}d",
39 __func__, code, option.GetFlags(), code);
40 std::u16string descriptor = DialogCallbackStub::GetDescriptor();
41 std::u16string remoteDescriptor = data.ReadInterfaceToken();
42 if (descriptor != remoteDescriptor) {
43 HILOG_INFO("local descriptor is not equal to remote");
44 return ERR_INVALID_STATE;
45 }
46
47 if (code == IDialogCallback::UI_SERVICE_DIALOG_CALLBACK) {
48 return OnDialogCallBackInner(data, reply);
49 }
50 HILOG_WARN("%{public}s, default case, need check.", __func__);
51 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
52 }
53
OnDialogCallBackInner(MessageParcel & data,MessageParcel & reply)54 int DialogCallbackStub::OnDialogCallBackInner(MessageParcel &data, MessageParcel &reply)
55 {
56 int32_t id = data.ReadInt32();
57 const std::string& event = data.ReadString();
58 const std::string& params = data.ReadString();
59 OnDialogCallback(id, event, params);
60 return ERR_NONE;
61 }
62
OnRemoteDied(const wptr<IRemoteObject> & remote)63 void DialogCallbackRecipient::OnRemoteDied(const wptr<IRemoteObject> &remote)
64 {
65 HILOG_ERROR("recv DialogCallbackRecipient death notice");
66
67 if (handler_) {
68 handler_(remote);
69 }
70 }
71
DialogCallbackRecipient(RemoteDiedHandler handler)72 DialogCallbackRecipient::DialogCallbackRecipient(RemoteDiedHandler handler) : handler_(handler)
73 {}
74
~DialogCallbackRecipient()75 DialogCallbackRecipient::~DialogCallbackRecipient()
76 {}
77 } // namespace Ace
78 } // namespace OHOS
79