• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 "key_session_service_callback_proxy.h"
17 #include "drm_log.h"
18 #include "remote_request_code.h"
19 #include "drm_error_code.h"
20 
21 namespace OHOS {
22 namespace DrmStandard {
MediaKeySessionServiceCallbackProxy(const sptr<IRemoteObject> & impl)23 MediaKeySessionServiceCallbackProxy::MediaKeySessionServiceCallbackProxy(const sptr<IRemoteObject> &impl)
24     : IRemoteProxy<IMediaKeySessionServiceCallback>(impl) {};
25 
SendEvent(DrmEventType event,int32_t extra,const std::vector<uint8_t> & data)26 int32_t MediaKeySessionServiceCallbackProxy::SendEvent(DrmEventType event, int32_t extra,
27     const std::vector<uint8_t> &data)
28 {
29     MessageParcel parcelData;
30     MessageParcel reply;
31     MessageOption option;
32     DRM_INFO_LOG("SendEvent called, event:%{public}d", event);
33     if (!parcelData.WriteInterfaceToken(GetDescriptor())) {
34         DRM_ERR_LOG("SendEvent Write interface token failed.");
35         return IPC_PROXY_ERR;
36     }
37     if (!parcelData.WriteInt32(event)) {
38         DRM_ERR_LOG("SendEvent Write event failed.");
39         return IPC_PROXY_ERR;
40     }
41     if (!parcelData.WriteInt32(extra)) {
42         DRM_ERR_LOG("SendEvent Write extra failed.");
43         return IPC_PROXY_ERR;
44     }
45     if (!parcelData.WriteUint32(data.size())) {
46         DRM_ERR_LOG("SendEvent Write data size failed.");
47         return IPC_PROXY_ERR;
48     }
49     DRM_CHECK_AND_RETURN_RET_LOG(data.size() < DATA_MAX_LEN, DRM_INNER_ERR_MEMORY_ERROR,
50         "The size of data is too large.");
51     if (data.size() != 0) {
52         if (!parcelData.WriteBuffer(data.data(), data.size())) {
53             DRM_ERR_LOG("SendEvent write data failed.");
54             return IPC_PROXY_ERR;
55         }
56     }
57 
58     int32_t ret = Remote()->SendRequest(MEDIA_KEY_SESSION_SERVICE_CALLBACK_SEND_EVENT, parcelData, reply, option);
59     if (ret != 0) {
60         DRM_ERR_LOG("SendEvent failed, errorcode: %{public}d", ret);
61     }
62     return ret;
63 }
64 
SendEventKeyChanged(std::map<std::vector<uint8_t>,MediaKeySessionKeyStatus> statusTable,bool hasNewGoodLicense)65 int32_t MediaKeySessionServiceCallbackProxy::SendEventKeyChanged(
66     std::map<std::vector<uint8_t>, MediaKeySessionKeyStatus> statusTable, bool hasNewGoodLicense)
67 {
68     MessageParcel parcelData;
69     MessageParcel reply;
70     MessageOption option;
71     DRM_INFO_LOG("SendEventKeyChanged enter.");
72     if (!parcelData.WriteInterfaceToken(GetDescriptor())) {
73         DRM_ERR_LOG("Write interface token failed.");
74         return IPC_PROXY_ERR;
75     }
76 
77     uint32_t mapSize = statusTable.size();
78     if (!parcelData.WriteUint32(mapSize)) {
79         DRM_ERR_LOG("Write mapSize failed.");
80         return IPC_PROXY_ERR;
81     }
82     for (auto item : statusTable) {
83         uint32_t idSize = item.first.size();
84         (void)parcelData.WriteUint32(idSize);
85         DRM_CHECK_AND_RETURN_RET_LOG(idSize < DATA_MAX_LEN, DRM_INNER_ERR_MEMORY_ERROR,
86             "The size of data is too large.");
87         if (idSize != 0) {
88             if (!parcelData.WriteBuffer(item.first.data(), idSize)) {
89                 DRM_ERR_LOG("write data failed.");
90                 return IPC_PROXY_ERR;
91             }
92         }
93         (void)parcelData.WriteInt32(static_cast<int32_t>(item.second));
94     }
95 
96     if (!parcelData.WriteBool(hasNewGoodLicense)) {
97         DRM_ERR_LOG("Write extra failed.");
98         return IPC_PROXY_ERR;
99     }
100 
101     int32_t ret =
102         Remote()->SendRequest(MEDIA_KEY_SESSION_SERVICE_CALLBACK_SEND_EVENT_KEY_CHANGED, parcelData, reply, option);
103     if (ret != ERR_NONE) {
104         DRM_ERR_LOG("failed, errorcode: %{public}d", ret);
105     }
106     return ret;
107 }
108 } // DrmStandard
109 } // namespace OHOS