• 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 "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 &param, const sptr<IRemoteObject> &callback)
29 {
30     SGLOGI("enter RiskAnalysisManagerProxy RequestSecurityModelResult");
31     MessageParcel data;
32     MessageParcel reply;
33 
34     if (!data.WriteInterfaceToken(GetDescriptor())) {
35         SGLOGE("WriteInterfaceToken error");
36         return WRITE_ERR;
37     }
38 
39     data.WriteUint32(modelId);
40     data.WriteString(param);
41     data.WriteRemoteObject(callback);
42 
43     MessageOption option = { MessageOption::TF_SYNC };
44     sptr<IRemoteObject> remote = Remote();
45     if (remote == nullptr) {
46         SGLOGE("Remote error");
47         return NULL_OBJECT;
48     }
49     int ret = remote->SendRequest(CMD_GET_SECURITY_MODEL_RESULT, data, reply, option);
50     if (ret != ERR_NONE) {
51         SGLOGE("ret=%{public}d", ret);
52         return ret;
53     }
54     ret = reply.ReadInt32();
55     SGLOGD("reply=%{public}d", ret);
56     return ret;
57 }
58 
SetModelState(uint32_t modelId,bool enable)59 int32_t RiskAnalysisManagerProxy::SetModelState(uint32_t modelId, bool enable)
60 {
61     MessageParcel data;
62     MessageParcel reply;
63 
64     if (!data.WriteInterfaceToken(GetDescriptor())) {
65         SGLOGE("WriteInterfaceToken error");
66         return WRITE_ERR;
67     }
68     data.WriteUint32(modelId);
69     data.WriteBool(enable);
70 
71     MessageOption option = { MessageOption::TF_SYNC };
72     sptr<IRemoteObject> remote = Remote();
73     if (remote == nullptr) {
74         SGLOGE("Remote error");
75         return NULL_OBJECT;
76     }
77     int ret = remote->SendRequest(CMD_SET_MODEL_STATE, data, reply, option);
78     if (ret != ERR_NONE) {
79         SGLOGE("ret=%{public}d", ret);
80         return ret;
81     }
82     return reply.ReadInt32();
83 }
84 }