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 "risk_analysis_manager_stub.h"
17
18 #include <future>
19
20 #include "security_guard_define.h"
21 #include "security_guard_log.h"
22
23 namespace OHOS::Security::SecurityGuard {
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)24 int32_t RiskAnalysisManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
25 MessageOption &option)
26 {
27 SGLOGD("%{public}s", __func__);
28 do {
29 if (IRiskAnalysisManager::GetDescriptor() != data.ReadInterfaceToken()) {
30 SGLOGE("descriptor error");
31 break;
32 }
33
34 switch (code) {
35 case CMD_GET_SECURITY_MODEL_RESULT: {
36 return HandleGetSecurityModelResult(data, reply);
37 }
38 case CMD_SET_MODEL_STATE: {
39 return HandleSetModelState(data, reply);
40 }
41 default:
42 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
43 }
44 } while (false);
45 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
46 }
47
HandleGetSecurityModelResult(MessageParcel & data,MessageParcel & reply)48 int32_t RiskAnalysisManagerStub::HandleGetSecurityModelResult(MessageParcel &data, MessageParcel &reply)
49 {
50 // UDID + MODELID + CALLBACK
51 uint32_t expected = sizeof(uint32_t);
52 uint32_t actual = data.GetReadableBytes();
53 if (expected >= actual) {
54 SGLOGE("actual length error, value=%{public}u", actual);
55 return BAD_PARAM;
56 }
57
58 std::string devId = data.ReadString();
59 uint32_t modelId = data.ReadUint32();
60 std::string param = data.ReadString();
61 auto object = data.ReadRemoteObject();
62 if (object == nullptr) {
63 SGLOGE("object is nullptr");
64 return BAD_PARAM;
65 }
66 int32_t ret = RequestSecurityModelResult(devId, modelId, param, object);
67 reply.WriteInt32(ret);
68 return ret;
69 }
70
HandleSetModelState(MessageParcel & data,MessageParcel & reply)71 int32_t RiskAnalysisManagerStub::HandleSetModelState(MessageParcel &data, MessageParcel &reply)
72 {
73 // MODELID + ENABLE
74 uint32_t expected = sizeof(uint32_t) + sizeof(bool);
75 uint32_t actual = data.GetReadableBytes();
76 if (expected >= actual) {
77 SGLOGE("actual length error, value=%{public}u", actual);
78 return BAD_PARAM;
79 }
80
81 uint32_t modelId = data.ReadUint32();
82 bool enable = data.ReadBool();
83 int32_t ret = SetModelState(modelId, enable);
84 reply.WriteInt32(ret);
85 return ret;
86 }
87 }
88