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_proxy.h"
17
18 #include "security_guard_define.h"
19 #include "security_guard_log.h"
20
21 namespace OHOS::Security::SecurityGuard {
RiskAnalysisManagerProxy(const sptr<IRemoteObject> & impl)22 RiskAnalysisManagerProxy::RiskAnalysisManagerProxy(const sptr<IRemoteObject> &impl)
23 : IRemoteProxy<IRiskAnalysisManager>(impl)
24 {
25 }
26
RequestSecurityModelResult(const std::string & devId,uint32_t modelId,const std::string & param,const sptr<IRemoteObject> & callback)27 int32_t RiskAnalysisManagerProxy::RequestSecurityModelResult(const std::string &devId, uint32_t modelId,
28 const std::string ¶m, const sptr<IRemoteObject> &callback)
29 {
30 MessageParcel data;
31 MessageParcel reply;
32
33 if (!data.WriteInterfaceToken(GetDescriptor())) {
34 SGLOGE("WriteInterfaceToken error");
35 return WRITE_ERR;
36 }
37 data.WriteString(devId);
38 data.WriteUint32(modelId);
39 data.WriteString(param);
40 data.WriteRemoteObject(callback);
41
42 MessageOption option = { MessageOption::TF_SYNC };
43 int ret = Remote()->SendRequest(CMD_GET_SECURITY_MODEL_RESULT, data, reply, option);
44 if (ret != ERR_NONE) {
45 SGLOGE("ret=%{public}d", ret);
46 return ret;
47 }
48 ret = reply.ReadInt32();
49 SGLOGD("reply=%{public}d", ret);
50 return ret;
51 }
52
SetModelState(uint32_t modelId,bool enable)53 int32_t RiskAnalysisManagerProxy::SetModelState(uint32_t modelId, bool enable)
54 {
55 MessageParcel data;
56 MessageParcel reply;
57
58 if (!data.WriteInterfaceToken(GetDescriptor())) {
59 SGLOGE("WriteInterfaceToken error");
60 return WRITE_ERR;
61 }
62 data.WriteUint32(modelId);
63 data.WriteBool(enable);
64
65 MessageOption option = { MessageOption::TF_SYNC };
66 int ret = Remote()->SendRequest(CMD_SET_MODEL_STATE, data, reply, option);
67 if (ret != ERR_NONE) {
68 SGLOGE("ret=%{public}d", ret);
69 return ret;
70 }
71 return reply.ReadInt32();
72 }
73 }