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 "remote_request_code.h"
17 #include "drm_log.h"
18 #include "drm_error_code.h"
19 #include "mediakeysystemfactory_service_proxy.h"
20
21 namespace OHOS {
22 namespace DrmStandard {
MediaKeySystemFactoryServiceProxy(const sptr<IRemoteObject> & impl)23 MediaKeySystemFactoryServiceProxy::MediaKeySystemFactoryServiceProxy(const sptr<IRemoteObject> &impl)
24 : IRemoteProxy<IMediaKeySystemFactoryService>(impl)
25 {
26 }
27
SetListenerObject(const sptr<IRemoteObject> & object)28 int32_t MediaKeySystemFactoryServiceProxy::SetListenerObject(const sptr<IRemoteObject> &object)
29 {
30 DRM_INFO_LOG("SetListenerObject enter.");
31 MessageParcel data;
32 MessageParcel reply;
33 MessageOption option;
34
35 data.WriteInterfaceToken(GetDescriptor());
36
37 if (!data.WriteRemoteObject(object)) {
38 DRM_ERR_LOG("WriteRemoteObject failed.");
39 return IPC_PROXY_ERR;
40 }
41
42 int ret = Remote()->SendRequest(MEDIA_KEY_SYSTEM_FACTORY_SET_LISTENER_OBJ, data, reply, option);
43 if (ret != DRM_OK) {
44 DRM_ERR_LOG("Set listener obj failed, error: %{public}d", ret);
45 return IPC_PROXY_ERR;
46 }
47 DRM_INFO_LOG("SetListenerObject exit.");
48 return DRM_OK;
49 }
50
IsMediaKeySystemSupported(std::string & uuid,bool * isSurpported)51 int32_t MediaKeySystemFactoryServiceProxy::IsMediaKeySystemSupported(std::string &uuid, bool *isSurpported)
52 {
53 DRM_INFO_LOG("one param enter.");
54 MessageParcel data;
55 MessageParcel reply;
56 MessageOption option;
57
58 if (!data.WriteInterfaceToken(GetDescriptor())) {
59 DRM_ERR_LOG(
60 "One param Write interface token failed.");
61 return IPC_PROXY_ERR;
62 }
63
64 if (!data.WriteInt32(ARGS_NUM_ONE)) {
65 DRM_ERR_LOG("One param Write paramNum failed.");
66 return IPC_PROXY_ERR;
67 }
68
69 if (!data.WriteString(uuid)) {
70 DRM_ERR_LOG("Write uuid failed.");
71 return IPC_PROXY_ERR;
72 }
73
74 int32_t ret = Remote()->SendRequest(MEDIA_KEY_SYSTEM_FACTORY_IS_MEDIA_KEY_SYSTEM_SURPPORTED, data, reply, option);
75 if (ret != DRM_OK) {
76 DRM_ERR_LOG("SendRequest failed, errcode: %{public}d", ret);
77 return ret;
78 }
79
80 *isSurpported = reply.ReadBool();
81 return ret;
82 }
83
IsMediaKeySystemSupported(std::string & uuid,std::string & mimeType,bool * isSurpported)84 int32_t MediaKeySystemFactoryServiceProxy::IsMediaKeySystemSupported(std::string &uuid, std::string &mimeType,
85 bool *isSurpported)
86 {
87 DRM_INFO_LOG("Two param enter.");
88 MessageParcel data;
89 MessageParcel reply;
90 MessageOption option;
91
92 if (!data.WriteInterfaceToken(GetDescriptor())) {
93 DRM_ERR_LOG("Two params Write interface token failed.");
94 return IPC_PROXY_ERR;
95 }
96
97 if (!data.WriteInt32(ARGS_NUM_TWO)) {
98 DRM_ERR_LOG("Two params Write paramNum failed.");
99 return IPC_PROXY_ERR;
100 }
101
102 if (!data.WriteString(uuid)) {
103 DRM_ERR_LOG("Two params Write uuid failed.");
104 return IPC_PROXY_ERR;
105 }
106
107 if (!data.WriteString(mimeType)) {
108 DRM_ERR_LOG("Two params Write mimeType failed.");
109 return IPC_PROXY_ERR;
110 }
111
112 int32_t ret = Remote()->SendRequest(MEDIA_KEY_SYSTEM_FACTORY_IS_MEDIA_KEY_SYSTEM_SURPPORTED, data, reply, option);
113 if (ret != DRM_OK) {
114 DRM_ERR_LOG("SendRequest failed, errcode: %{public}d", ret);
115 return ret;
116 }
117
118 *isSurpported = reply.ReadBool();
119 return ret;
120 }
121
IsMediaKeySystemSupported(std::string & uuid,std::string & mimeType,int32_t securityLevel,bool * isSurpported)122 int32_t MediaKeySystemFactoryServiceProxy::IsMediaKeySystemSupported(std::string &uuid, std::string &mimeType,
123 int32_t securityLevel, bool *isSurpported)
124 {
125 DRM_INFO_LOG("Three param called, enter.");
126 MessageParcel data;
127 MessageParcel reply;
128 MessageOption option;
129
130 if (!data.WriteInterfaceToken(GetDescriptor())) {
131 DRM_ERR_LOG("Three params Write interface token failed.");
132 return IPC_PROXY_ERR;
133 }
134
135 if (!data.WriteInt32(ARGS_NUM_THREE)) {
136 DRM_ERR_LOG("Three params Write paramNum failed.");
137 return IPC_PROXY_ERR;
138 }
139
140 if (!data.WriteString(uuid)) {
141 DRM_ERR_LOG("Three params Write uuid failed.");
142 return IPC_PROXY_ERR;
143 }
144
145 if (!data.WriteString(mimeType)) {
146 DRM_ERR_LOG("Three params Write mimeType failed.");
147 return IPC_PROXY_ERR;
148 }
149
150 if (!data.WriteInt32(securityLevel)) {
151 DRM_ERR_LOG("Three params Write securityLevel failed.");
152 return IPC_PROXY_ERR;
153 }
154
155 int32_t ret = Remote()->SendRequest(MEDIA_KEY_SYSTEM_FACTORY_IS_MEDIA_KEY_SYSTEM_SURPPORTED, data, reply, option);
156 if (ret != DRM_OK) {
157 DRM_ERR_LOG("SendRequest failed, errcode: %{public}d", ret);
158 return ret;
159 }
160
161 *isSurpported = reply.ReadBool();
162 return ret;
163 }
164
GetMediaKeySystems(std::map<std::string,std::string> & keySystemNames)165 int32_t MediaKeySystemFactoryServiceProxy::GetMediaKeySystems(std::map<std::string, std::string> &keySystemNames)
166 {
167 DRM_INFO_LOG("GetMediaKeySystems enter.");
168 MessageParcel data;
169 MessageParcel reply;
170 MessageOption option;
171
172 if (!data.WriteInterfaceToken(MediaKeySystemFactoryServiceProxy::GetDescriptor())) {
173 DRM_ERR_LOG("Write interface token failed.");
174 return IPC_PROXY_ERR;
175 }
176 int32_t ret =
177 MediaKeySystemFactoryServiceProxy::Remote()->SendRequest(MEDIA_KEY_SYSTEM_FACTORY_GET_MEDIA_KEYSYSTEM_NAME,
178 data, reply, option);
179 if (ret != DRM_OK) {
180 DRM_ERR_LOG("SendRequest failed, errcode: %{public}d", ret);
181 return ret;
182 }
183 int32_t mediaKeySystemNameMapSize = reply.ReadInt32();
184 for (int32_t i = 0; i < mediaKeySystemNameMapSize; i++) {
185 std::string name = reply.ReadString();
186 std::string uuid = reply.ReadString();
187 keySystemNames.insert(std::make_pair(name, uuid));
188 }
189 return ret;
190 }
191
GetMediaKeySystemUuid(std::string & name,std::string & uuid)192 int32_t MediaKeySystemFactoryServiceProxy::GetMediaKeySystemUuid(std::string &name, std::string &uuid)
193 {
194 DRM_INFO_LOG("GetMediaKeySystemUuid enter.");
195 MessageParcel data;
196 MessageParcel reply;
197 MessageOption option;
198
199 if (!data.WriteInterfaceToken(MediaKeySystemFactoryServiceProxy::GetDescriptor())) {
200 DRM_ERR_LOG("Write interface token failed.");
201 return IPC_PROXY_ERR;
202 }
203 if (!data.WriteString(name)) {
204 DRM_ERR_LOG("Write configName failed.");
205 return IPC_PROXY_ERR;
206 }
207 int32_t ret =
208 MediaKeySystemFactoryServiceProxy::Remote()->SendRequest(MEDIA_KEY_SYSTEM_FACTORY_GET_MEDIA_KEYSYSTEM_UUID,
209 data, reply, option);
210 if (ret != DRM_OK) {
211 DRM_ERR_LOG("SendRequest failed, errcode: %{public}d", ret);
212 return ret;
213 }
214 uuid = reply.ReadString();
215 return ret;
216 }
217
CreateMediaKeySystem(std::string & name,sptr<IMediaKeySystemService> & mediaKeySystemProxy)218 int32_t MediaKeySystemFactoryServiceProxy::CreateMediaKeySystem(std::string &name,
219 sptr<IMediaKeySystemService> &mediaKeySystemProxy)
220 {
221 DRM_INFO_LOG("CreateMediaKeySystem enter.");
222 MessageParcel data;
223 MessageParcel reply;
224 MessageOption option;
225 if (!data.WriteInterfaceToken(GetDescriptor())) {
226 DRM_ERR_LOG("Write interface token failed.");
227 return IPC_PROXY_ERR;
228 }
229
230 if (!data.WriteString(name)) {
231 DRM_ERR_LOG("Write format failed.");
232 return IPC_PROXY_ERR;
233 }
234
235 int32_t ret = Remote()->SendRequest(MEDIA_KEY_SYSTEM_FACTORY_CREATE_MEDIA_KEYSYSTEM, data, reply, option);
236 if (ret != DRM_OK) {
237 DRM_ERR_LOG("SendRequest failed, errcode: %{public}d", ret);
238 return ret;
239 }
240
241 auto remoteObject = reply.ReadRemoteObject();
242 if (remoteObject != nullptr) {
243 mediaKeySystemProxy = iface_cast<IMediaKeySystemService>(remoteObject);
244 } else {
245 DRM_ERR_LOG("mediaKeySystemProxy is nullptr");
246 ret = IPC_PROXY_ERR;
247 }
248 return ret;
249 }
250 } // DrmStandard
251 } // OHOS