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 "dslm_callback_proxy.h"
17 
18 #include "hilog/log_cpp.h"
19 #include "message_option.h"
20 #include "message_parcel.h"
21 
22 #include "device_security_defines.h"
23 #include "utils_log.h"
24 
25 namespace OHOS {
26 namespace Security {
27 namespace DeviceSecurityLevel {
28 using namespace OHOS::HiviewDFX;
DslmCallbackProxy(const sptr<IRemoteObject> & impl)29 DslmCallbackProxy::DslmCallbackProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<IDeviceSecurityLevelCallback>(impl)
30 {
31 }
32 
ResponseDeviceSecurityLevel(uint32_t cookie,const ResponseInfo & response)33 int32_t DslmCallbackProxy::ResponseDeviceSecurityLevel(uint32_t cookie, const ResponseInfo &response)
34 {
35     MessageParcel data;
36     MessageParcel reply;
37 
38     sptr<IRemoteObject> remote = Remote();
39     if (remote == nullptr) {
40         SECURITY_LOG_ERROR("Remote is nullptr");
41         return ERR_INVALID_PARA;
42     }
43     if (!data.WriteInterfaceToken(GetDescriptor())) {
44         return ERR_INVALID_PARA;
45     }
46 
47     data.WriteUint32(cookie);
48     data.WriteUint32(response.result);
49     data.WriteUint32(response.level);
50 
51     if (response.extraBuff != nullptr && response.extraLen != 0) {
52         data.WriteUint32(response.extraLen);
53         data.WriteBuffer(response.extraBuff, response.extraLen);
54     }
55 
56     MessageOption ipcOption = {MessageOption::TF_ASYNC};
57     return remote->SendRequest(CMD_SET_DEVICE_SECURITY_LEVEL, data, reply, ipcOption);
58 }
59 } // namespace DeviceSecurityLevel
60 } // namespace Security
61 } // namespace OHOS
62