• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     sptr<IRemoteObject> remote = Remote();
49     if (remote == nullptr) {
50         SGLOGE("Remote error");
51         return;
52     }
53     remote->SendRequest(ISecurityEventQueryCallback::CMD_ON_QUERY, data, reply, option);
54 }
55 
OnComplete()56 void SecurityEventQueryCallbackProxy::OnComplete()
57 {
58     SGLOGI("start OnComplete");
59     MessageParcel data;
60     MessageParcel reply;
61     if (!data.WriteInterfaceToken(GetDescriptor())) {
62         return;
63     }
64 
65     MessageOption option = { MessageOption::TF_SYNC };
66     sptr<IRemoteObject> remote = Remote();
67     if (remote == nullptr) {
68         SGLOGE("Remote error");
69         return;
70     }
71     remote->SendRequest(ISecurityEventQueryCallback::CMD_ON_COMPLETE, data, reply, option);
72 }
73 
OnError(const std::string & message)74 void SecurityEventQueryCallbackProxy::OnError(const std::string &message)
75 {
76     SGLOGI("start OnError");
77     MessageParcel data;
78     MessageParcel reply;
79     if (!data.WriteInterfaceToken(GetDescriptor())) {
80         return;
81     }
82     if (!data.WriteString(message)) {
83         SGLOGE("failed to WriteString for parcelable vector size");
84         return;
85     }
86 
87     MessageOption option = { MessageOption::TF_SYNC };
88     sptr<IRemoteObject> remote = Remote();
89     if (remote == nullptr) {
90         SGLOGE("Remote error");
91         return;
92     }
93     remote->SendRequest(ISecurityEventQueryCallback::CMD_ON_ERROR, data, reply, option);
94 }
95 }