1 /*
2 * Copyright (c) 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 "sec_comp_dialog_callback_proxy.h"
17
18 #include "sec_comp_log.h"
19
20 namespace OHOS {
21 namespace Security {
22 namespace SecurityComponent {
23 namespace {
24 static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {
25 LOG_CORE, SECURITY_DOMAIN_SECURITY_COMPONENT, "SecCompDialogCallbackProxy"
26 };
27 }
28
SecCompDialogCallbackProxy(const sptr<IRemoteObject> & impl)29 SecCompDialogCallbackProxy::SecCompDialogCallbackProxy(const sptr<IRemoteObject>& impl)
30 : IRemoteProxy<ISecCompDialogCallback>(impl) {
31 }
32
~SecCompDialogCallbackProxy()33 SecCompDialogCallbackProxy::~SecCompDialogCallbackProxy()
34 {}
35
OnDialogClosed(int32_t result)36 void SecCompDialogCallbackProxy::OnDialogClosed(int32_t result)
37 {
38 MessageParcel data;
39 if (!data.WriteInterfaceToken(ISecCompDialogCallback::GetDescriptor())) {
40 SC_LOG_ERROR(LABEL, "Write descriptor failed.");
41 return;
42 }
43 if (!data.WriteInt32(result)) {
44 SC_LOG_ERROR(LABEL, "Write int32 failed.");
45 return;
46 }
47
48 MessageParcel reply;
49 MessageOption option(MessageOption::TF_SYNC);
50 sptr<IRemoteObject> remote = Remote();
51 if (remote == nullptr) {
52 SC_LOG_ERROR(LABEL, "Remote service is null.");
53 return;
54 }
55 int32_t requestResult = remote->SendRequest(
56 static_cast<uint32_t>(ISecCompDialogCallback::ON_DIALOG_CLOSED), data, reply, option);
57 if (requestResult != NO_ERROR) {
58 SC_LOG_ERROR(LABEL, "send request fail, result: %{public}d", requestResult);
59 return;
60 }
61
62 SC_LOG_INFO(LABEL, "SendRequest success");
63 }
64 } // namespace SecurityComponent
65 } // namespace Security
66 } // namespace OHOS
67