1 /*
2  * Copyright (c) 2023-2024 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 #include "mediakeysystem_service_callback_proxy.h"
16 #include "drm_log.h"
17 #include "remote_request_code.h"
18 
19 namespace OHOS {
20 namespace DrmStandard {
MediaKeySystemServiceCallbackProxy(const sptr<IRemoteObject> & impl)21 MediaKeySystemServiceCallbackProxy::MediaKeySystemServiceCallbackProxy(const sptr<IRemoteObject> &impl)
22     : IRemoteProxy<IMediaKeySystemServiceCallback>(impl) {};
23 
SendEvent(DrmEventType event,int32_t extra,const std::vector<uint8_t> & data)24 int32_t MediaKeySystemServiceCallbackProxy::SendEvent(DrmEventType event, int32_t extra,
25     const std::vector<uint8_t> &data)
26 {
27     MessageParcel parcelData;
28     MessageParcel reply;
29     MessageOption option;
30     DRM_INFO_LOG("SendEvent called, event:%{public}d", event);
31     if (!parcelData.WriteInterfaceToken(GetDescriptor())) {
32         DRM_ERR_LOG("SendEvent Write interface token failed.");
33         return IPC_PROXY_ERR;
34     }
35     if (!parcelData.WriteInt32(event)) {
36         DRM_ERR_LOG("SendEvent Write event failed.");
37         return IPC_PROXY_ERR;
38     }
39     if (!parcelData.WriteInt32(extra)) {
40         DRM_ERR_LOG("SendEvent Write extra failed.");
41         return IPC_PROXY_ERR;
42     }
43     if (!parcelData.WriteUint32(data.size())) {
44         DRM_ERR_LOG("SendEvent Write data size failed.");
45         return IPC_PROXY_ERR;
46     }
47     for (auto item : data) {
48         if (!parcelData.WriteUint8(item)) {
49             DRM_ERR_LOG("SendEvent Write data failed.");
50             return IPC_PROXY_ERR;
51         }
52     }
53     int32_t ret = Remote()->SendRequest(MEDIA_KEY_SYSTEM_SERVICE_CALLBACK_SEND_EVENT, parcelData, reply, option);
54     if (ret != ERR_OK) {
55         DRM_ERR_LOG("SendEvent failed, errcode: %{public}d", ret);
56     }
57     return ret;
58 }
59 } // namespace DrmStandard
60 } // namespace OHOS
61