• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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_stub.h"
17 
18 #include "security_collector_define.h"
19 #include "security_collector_log.h"
20 namespace {
21     constexpr size_t MAX_SUB_SIZE = 10000;
22 }
23 namespace OHOS::Security::SecurityCollector {
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)24 int32_t SecurityCollectorManagerCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
25     MessageOption &option)
26 {
27     if (SecurityCollectorManagerCallbackStub::GetDescriptor() != data.ReadInterfaceToken()) {
28         LOGE("Descriptor error");
29         return NO_PERMISSION;
30     }
31 
32     if (code == SecurityCollectorManagerCallbackStub::CMD_COLLECTOR_NOTIFY) {
33         uint32_t expected = sizeof(uint64_t);
34         uint32_t actual = data.GetReadableBytes();
35         if (actual <= expected) {
36             LOGE("actual length error, value=%{public}u", actual);
37             return BAD_PARAM;
38         }
39 
40         Event event;
41         event.eventId = data.ReadInt64();
42         event.version = data.ReadString();
43         event.content = data.ReadString();
44         event.extra = data.ReadString();
45         uint32_t size = data.ReadUint32();
46         if (size > MAX_SUB_SIZE) {
47             LOGE("the subs size error");
48             return BAD_PARAM;
49         }
50         for (uint32_t i = 0; i < size; i++) {
51             event.eventSubscribes.insert(data.ReadString());
52         }
53         OnNotify(event);
54         return SUCCESS;
55     }
56 
57     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
58 }
59 }