• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     }
41     sptr<IRemoteObject> remote = Remote();
42     if (remote == nullptr) {
43         SGLOGE("remote is nullptr, code = %{public}u", static_cast<uint32_t>(CMD_DATA_SUBSCRIBE_CALLBACK));
44         return NULL_OBJECT;
45     }
46 
47     MessageOption option = { MessageOption::TF_SYNC };
48     SGLOGD("batch callback event num of records= %{public}zu", events.size());
49     return remote->SendRequest(CMD_DATA_SUBSCRIBE_CALLBACK, data, reply, option);
50 }
51 
52 }