• 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 "security_collector_manager_callback_proxy.h"
17 #include "security_collector_define.h"
18 #include "security_collector_log.h"
19 
20 namespace OHOS::Security::SecurityCollector {
21 
OnNotify(const Event & event)22 int32_t SecurityCollectorManagerCallbackProxy::OnNotify(const Event &event)
23 {
24     MessageParcel data;
25     MessageParcel reply;
26 
27     if (!data.WriteInterfaceToken(GetDescriptor())) {
28         return ERR_INVALID_OPERATION;
29     }
30 
31     data.WriteInt64(event.eventId);
32     data.WriteString(event.version);
33     data.WriteString(event.content);
34     data.WriteString(event.extra);
35 
36     if (!data.WriteUint32(event.eventSubscribes.size())) {
37         LOGE("failed to write eventSubscribes size");
38         return WRITE_ERR;
39     }
40     for (auto iter : event.eventSubscribes) {
41         if (!data.WriteString(iter)) {
42             LOGE("failed to write eventSubscribes");
43             return WRITE_ERR;
44         }
45     }
46     sptr<IRemoteObject> remote = Remote();
47     if (remote == nullptr) {
48         LOGE("remote is nullptr, code = %{public}u", static_cast<uint32_t>(CMD_COLLECTOR_NOTIFY));
49         return NULL_OBJECT;
50     }
51 
52     MessageOption option = { MessageOption::TF_ASYNC };
53     return remote->SendRequest(CMD_COLLECTOR_NOTIFY, data, reply, option);
54 }
55 }