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 "security_event_query_callback_proxy.h"
17
18 #include "security_guard_define.h"
19 #include "security_guard_log.h"
20
21 namespace OHOS::Security::SecurityGuard {
SecurityEventQueryCallbackProxy(const sptr<OHOS::IRemoteObject> & callback)22 SecurityEventQueryCallbackProxy::SecurityEventQueryCallbackProxy(const sptr<OHOS::IRemoteObject> &callback)
23 : IRemoteProxy<ISecurityEventQueryCallback>(callback)
24 {
25 }
26
OnQuery(const std::vector<SecurityCollector::SecurityEvent> & events)27 void SecurityEventQueryCallbackProxy::OnQuery(const std::vector<SecurityCollector::SecurityEvent> &events)
28 {
29 SGLOGI("start OnQuery");
30 MessageParcel data;
31 MessageParcel reply;
32 if (!data.WriteInterfaceToken(GetDescriptor())) {
33 return;
34 }
35 if (!data.WriteUint32(events.size())) {
36 SGLOGE("failed to WriteInt32 for parcelable vector size");
37 return;
38 }
39
40 for (const auto &event : events) {
41 if (!data.WriteParcelable(&event)) {
42 SGLOGE("failed to WriteParcelable for parcelable");
43 return;
44 }
45 }
46
47 MessageOption option = { MessageOption::TF_SYNC };
48 Remote()->SendRequest(ISecurityEventQueryCallback::CMD_ON_QUERY, data, reply, option);
49 }
50
OnComplete()51 void SecurityEventQueryCallbackProxy::OnComplete()
52 {
53 SGLOGI("start OnComplete");
54 MessageParcel data;
55 MessageParcel reply;
56 if (!data.WriteInterfaceToken(GetDescriptor())) {
57 return;
58 }
59
60 MessageOption option = { MessageOption::TF_SYNC };
61 Remote()->SendRequest(ISecurityEventQueryCallback::CMD_ON_COMPLETE, data, reply, option);
62 }
63
OnError(const std::string & message)64 void SecurityEventQueryCallbackProxy::OnError(const std::string &message)
65 {
66 SGLOGI("start OnError");
67 MessageParcel data;
68 MessageParcel reply;
69 if (!data.WriteInterfaceToken(GetDescriptor())) {
70 return;
71 }
72 if (!data.WriteString(message)) {
73 SGLOGE("failed to WriteString for parcelable vector size");
74 return;
75 }
76
77 MessageOption option = { MessageOption::TF_SYNC };
78 Remote()->SendRequest(ISecurityEventQueryCallback::CMD_ON_ERROR, data, reply, option);
79 }
80 }