1 /*
2 * Copyright (c) 2023 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 "acquire_data_callback_proxy.h"
17 #include "security_guard_define.h"
18 #include "security_guard_log.h"
19
20 namespace OHOS::Security::SecurityGuard {
OnNotify(const std::vector<SecurityCollector::Event> & events)21 int32_t AcquireDataCallbackProxy::OnNotify(const std::vector<SecurityCollector::Event> &events)
22 {
23 MessageParcel data;
24 MessageParcel reply;
25
26 if (!data.WriteInterfaceToken(GetDescriptor())) {
27 return ERR_INVALID_OPERATION;
28 }
29 if (!data.WriteUint32(events.size())) {
30 SGLOGE("failed to WriteInt32 for parcelable vector size");
31 return WRITE_ERR;
32 }
33
34 for (const auto &event : events) {
35 data.WriteInt64(event.eventId);
36 data.WriteString(event.version);
37 data.WriteString(event.content);
38 data.WriteString(event.extra);
39 data.WriteString(event.timestamp);
40 data.WriteInt32(event.userId);
41 data.WriteString(event.deviceId);
42 if (!data.WriteUint32(event.eventSubscribes.size())) {
43 SGLOGE("failed to write eventSubscribes size");
44 return WRITE_ERR;
45 }
46 for (auto iter : event.eventSubscribes) {
47 if (!data.WriteString(iter)) {
48 SGLOGE("failed to write eventSubscribes");
49 return WRITE_ERR;
50 }
51 }
52 }
53 sptr<IRemoteObject> remote = Remote();
54 if (remote == nullptr) {
55 SGLOGE("remote is nullptr, code = %{public}u", static_cast<uint32_t>(CMD_DATA_SUBSCRIBE_CALLBACK));
56 return NULL_OBJECT;
57 }
58
59 MessageOption option = { MessageOption::TF_ASYNC };
60 SGLOGD("batch callback event num of records= %{public}zu", events.size());
61 return remote->SendRequest(CMD_DATA_SUBSCRIBE_CALLBACK, data, reply, option);
62 }
63
64 }