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 "mediakeysystem_service_stub.h"
17 #include "drm_error_code.h"
18 #include "drm_log.h"
19 #include "ipc_skeleton.h"
20 #include "xcollie/xcollie.h"
21 #include "xcollie/xcollie_define.h"
22
23 namespace OHOS {
24 namespace DrmStandard {
25 using ProcessRemoteRequestFunc = int32_t (*)(MediaKeySystemServiceStub *stub, MessageParcel &data, MessageParcel &reply,
26 MessageOption &option);
27
28 struct ProcessRemoteRequestFuncArray {
29 OHOS::DrmStandard::MediaKeySystemServiceRequestCode requestCode;
30 ProcessRemoteRequestFunc processFunc;
31 };
32
33 static int32_t ProcessCreatekeySession(MediaKeySystemServiceStub *stub, MessageParcel &data, MessageParcel &reply,
34 MessageOption &option);
35
36 static int32_t ProcessKeySystemRequest(MediaKeySystemServiceStub *stub, MessageParcel &data, MessageParcel &reply,
37 MessageOption &option);
38
39 static int32_t ProcessKeySystemResponse(MediaKeySystemServiceStub *stub, MessageParcel &data, MessageParcel &reply,
40 MessageOption &option);
41
42 static int32_t ProcessSetConfigurationString(MediaKeySystemServiceStub *stub, MessageParcel &data, MessageParcel &reply,
43 MessageOption &option);
44
45 static int32_t ProcessGetConfigurationString(MediaKeySystemServiceStub *stub, MessageParcel &data, MessageParcel &reply,
46 MessageOption &option);
47
48 static int32_t ProcessSetConfigurationByteArray(MediaKeySystemServiceStub *stub, MessageParcel &data,
49 MessageParcel &reply, MessageOption &option);
50
51 static int32_t ProcessGetConfigurationByteArray(MediaKeySystemServiceStub *stub, MessageParcel &data,
52 MessageParcel &reply, MessageOption &option);
53
54 static int32_t ProcessGetMetircs(MediaKeySystemServiceStub *stub, MessageParcel &data, MessageParcel &reply,
55 MessageOption &option);
56
57 static int32_t ProcessReleaseKeySystem(MediaKeySystemServiceStub *stub, MessageParcel &data, MessageParcel &reply,
58 MessageOption &option);
59
60 static int32_t ProcessGetMaxContentProtectionLevel(MediaKeySystemServiceStub *stub, MessageParcel &data,
61 MessageParcel &reply, MessageOption &option);
62
63 static int32_t ProcessGetCertificateStatus(MediaKeySystemServiceStub *stub, MessageParcel &data, MessageParcel &reply,
64 MessageOption &option);
65
66 static int32_t ProcessGetOfflineMediaKeyIds(MediaKeySystemServiceStub *stub, MessageParcel &data, MessageParcel &reply,
67 MessageOption &option);
68
69 static int32_t ProcessGetOfflineMediaKeyStatus(MediaKeySystemServiceStub *stub, MessageParcel &data,
70 MessageParcel &reply, MessageOption &option);
71
72 static int32_t ProcessRemoveOfflineMediaKey(MediaKeySystemServiceStub *stub, MessageParcel &data, MessageParcel &reply,
73 MessageOption &option);
74
75 static int32_t ProcessSetListenerObject(MediaKeySystemServiceStub *stub, MessageParcel &data, MessageParcel &reply,
76 MessageOption &option);
77
78 static int32_t ProcessSetCallabck(MediaKeySystemServiceStub *stub, MessageParcel &data, MessageParcel &reply,
79 MessageOption &option);
80
81 static struct ProcessRemoteRequestFuncArray g_mediaKeySystemServiceStubRequestProcessFunc[] = {
82 {MEDIA_KEY_SYSTEM_CREATE_KEY_SESSION, ProcessCreatekeySession},
83 {MEDIA_KEY_SYSTEM_GENERATE_KEYSYSTEM_REQUEST, ProcessKeySystemRequest},
84 {MEDIA_KEY_SYSTEM_PROCESS_KEYSYSTEM_RESPONSE, ProcessKeySystemResponse},
85 {MEDIA_KEY_SYSTEM_SETCONFIGURATION_STRING, ProcessSetConfigurationString},
86 {MEDIA_KEY_SYSTEM_GETCONFIGURATION_STRING, ProcessGetConfigurationString},
87 {MEDIA_KEY_SYSTEM_SETCONFIGURATION_BYTEARRAY, ProcessSetConfigurationByteArray},
88 {MEDIA_KEY_SYSTEM_GETCONFIGURATION_BYTEARRAY, ProcessGetConfigurationByteArray},
89 {MEDIA_KEY_SYSTEM_GETMETRIC, ProcessGetMetircs},
90 {MEDIA_KEY_SYSTEM_RELEASE, ProcessReleaseKeySystem},
91 {MEDIA_KEY_SYSTEM_GETMAXSECURITYLEVEL, ProcessGetMaxContentProtectionLevel},
92 {MEDIA_KEY_SYSTEM_GETCERTIFICATESTATUS, ProcessGetCertificateStatus},
93 {MEDIA_KEY_SYSTEM_GET_OFFLINELICENSEIDS, ProcessGetOfflineMediaKeyIds},
94 {MEDIA_KEY_SYSTEM_GET_OFFLINEKEY_STATUS, ProcessGetOfflineMediaKeyStatus},
95 {MEDIA_KEY_SYSTEM_REMOVE_OFFLINELICENSE, ProcessRemoveOfflineMediaKey},
96 {MEDIA_KEY_SYSTEM_SET_LISTENER_OBJ, ProcessSetListenerObject},
97 {MEDIA_KEY_SYSTEM_SETCALLBACK, ProcessSetCallabck},
98 };
99
MediaKeySystemServiceStub()100 MediaKeySystemServiceStub::MediaKeySystemServiceStub()
101 {
102 DRM_INFO_LOG("MediaKeySystemServiceStub enter.");
103 }
104
~MediaKeySystemServiceStub()105 MediaKeySystemServiceStub::~MediaKeySystemServiceStub()
106 {
107 DRM_INFO_LOG("~MediaKeySystemServiceStub enter.");
108 deathRecipient_ = nullptr;
109 clientListener_ = nullptr;
110 }
111
ProcessCreatekeySession(MediaKeySystemServiceStub * stub,MessageParcel & data,MessageParcel & reply,MessageOption & option)112 static int32_t ProcessCreatekeySession(MediaKeySystemServiceStub *stub, MessageParcel &data, MessageParcel &reply,
113 MessageOption &option)
114 {
115 DRM_INFO_LOG("ProcessCreatekeySession enter.");
116 sptr<IMediaKeySessionService> keySessionServiceProxy = nullptr;
117 const int32_t securityLevel = data.ReadInt32();
118 int32_t ret = stub->CreateMediaKeySession((IMediaKeySessionService::ContentProtectionLevel)securityLevel,
119 keySessionServiceProxy);
120 DRM_CHECK_AND_RETURN_RET_LOG(ret == DRM_OK, ret, "CreateMediaKeySession faild, errCode:%{public}d",
121 ret);
122
123 if (!reply.WriteRemoteObject(keySessionServiceProxy->AsObject())) {
124 DRM_ERR_LOG("CreateMediaKeySession Write MediaKeySession obj failed.");
125 return IPC_STUB_WRITE_PARCEL_ERR;
126 }
127 return ret;
128 }
129
ProcessKeySystemRequest(MediaKeySystemServiceStub * stub,MessageParcel & data,MessageParcel & reply,MessageOption & option)130 static int32_t ProcessKeySystemRequest(MediaKeySystemServiceStub *stub, MessageParcel &data, MessageParcel &reply,
131 MessageOption &option)
132 {
133 DRM_INFO_LOG("ProcessKeySystemRequest enter.");
134 std::vector<uint8_t> request;
135 std::string defaultUrl;
136 int32_t ret = stub->GenerateKeySystemRequest(request, defaultUrl);
137 DRM_CHECK_AND_RETURN_RET_LOG(ret == DRM_OK, ret, "ProcessKeySystemRequest faild, errCode:%{public}d", ret);
138 if (!reply.WriteString(defaultUrl)) {
139 DRM_ERR_LOG("Write GenerateKeySystemRequest failed.");
140 return IPC_STUB_WRITE_PARCEL_ERR;
141 }
142 if (!reply.WriteInt32(request.size())) {
143 DRM_ERR_LOG("Write request size failed.");
144 return IPC_STUB_WRITE_PARCEL_ERR;
145 }
146 DRM_CHECK_AND_RETURN_RET_LOG(request.size() < REQUEST_MAX_LEN, DRM_MEMORY_ERROR,
147 "The size of request is too large.");
148 if (request.size() != 0) {
149 if (!reply.WriteBuffer(request.data(), request.size())) {
150 DRM_ERR_LOG("RestoreOfflineMediaKeys write request failed.");
151 return IPC_STUB_WRITE_PARCEL_ERR;
152 }
153 }
154 return ret;
155 }
156
ProcessKeySystemResponse(MediaKeySystemServiceStub * stub,MessageParcel & data,MessageParcel & reply,MessageOption & option)157 static int32_t ProcessKeySystemResponse(MediaKeySystemServiceStub *stub, MessageParcel &data, MessageParcel &reply,
158 MessageOption &option)
159 {
160 DRM_INFO_LOG("ProcessKeySystemResponse enter.");
161 std::vector<uint8_t> response;
162 int32_t responseSize = data.ReadInt32();
163 DRM_CHECK_AND_RETURN_RET_LOG(responseSize < RESPONSE_MAX_LEN, DRM_MEMORY_ERROR,
164 "The size of response is too large.");
165 if (responseSize != 0) {
166 const uint8_t *responseBuf = static_cast<const uint8_t *>(data.ReadUnpadBuffer(responseSize));
167 if (responseBuf == nullptr) {
168 DRM_ERR_LOG("ProcessOfflineReleaseResponse read response failed.");
169 return IPC_STUB_WRITE_PARCEL_ERR;
170 }
171 response.assign(responseBuf, responseBuf + responseSize);
172 }
173 int32_t ret = stub->ProcessKeySystemResponse(response);
174 DRM_CHECK_AND_RETURN_RET_LOG(ret == DRM_OK, ret, "ProcessKeySystemResponse faild, errCode:%{public}d", ret);
175 return ret;
176 }
177
ProcessSetConfigurationString(MediaKeySystemServiceStub * stub,MessageParcel & data,MessageParcel & reply,MessageOption & option)178 static int32_t ProcessSetConfigurationString(MediaKeySystemServiceStub *stub, MessageParcel &data, MessageParcel &reply,
179 MessageOption &option)
180 {
181 DRM_INFO_LOG("ProcessSetConfigurationString enter.");
182 std::string configName = data.ReadString();
183 std::string value = data.ReadString();
184 int32_t ret = stub->SetConfigurationString(configName, value);
185 DRM_CHECK_AND_RETURN_RET_LOG(ret == DRM_OK, ret, "ProcessSetConfigurationString faild, errCode:%{public}d", ret);
186 return ret;
187 }
188
ProcessGetConfigurationString(MediaKeySystemServiceStub * stub,MessageParcel & data,MessageParcel & reply,MessageOption & option)189 static int32_t ProcessGetConfigurationString(MediaKeySystemServiceStub *stub, MessageParcel &data, MessageParcel &reply,
190 MessageOption &option)
191 {
192 DRM_INFO_LOG("ProcessGetConfigurationString enter.");
193 std::string configName = data.ReadString();
194 std::string value;
195 int32_t ret = stub->GetConfigurationString(configName, value);
196 DRM_CHECK_AND_RETURN_RET_LOG(ret == DRM_OK, ret, "ProcessGetConfigurationString faild, errCode:%{public}d", ret);
197 if (!reply.WriteString(value)) {
198 DRM_ERR_LOG("ProcessGetConfigurationString write value failed.");
199 return IPC_STUB_WRITE_PARCEL_ERR;
200 }
201 return ret;
202 }
203
ProcessSetConfigurationByteArray(MediaKeySystemServiceStub * stub,MessageParcel & data,MessageParcel & reply,MessageOption & option)204 static int32_t ProcessSetConfigurationByteArray(MediaKeySystemServiceStub *stub, MessageParcel &data,
205 MessageParcel &reply, MessageOption &option)
206 {
207 DRM_INFO_LOG("ProcessSetConfigurationByteArray enter.");
208 std::string configName = data.ReadString();
209 std::vector<uint8_t> value;
210 int32_t valueSize = data.ReadInt32();
211 DRM_CHECK_AND_RETURN_RET_LOG(valueSize < RESPONSE_MAX_LEN, DRM_MEMORY_ERROR,
212 "The size of configurate value is too large.");
213 if (valueSize != 0) {
214 const uint8_t *valueBuf = static_cast<const uint8_t *>(data.ReadUnpadBuffer(valueSize));
215 if (valueBuf == nullptr) {
216 DRM_ERR_LOG("ProcessSetConfigurationByteArray read value failed.");
217 return IPC_STUB_WRITE_PARCEL_ERR;
218 }
219 value.assign(valueBuf, valueBuf + valueSize);
220 }
221 int32_t ret = stub->SetConfigurationByteArray(configName, value);
222 DRM_CHECK_AND_RETURN_RET_LOG(ret == DRM_OK, ret, "ProcessSetConfigurationByteArray faild, errCode:%{public}d", ret);
223 return ret;
224 }
225
ProcessGetConfigurationByteArray(MediaKeySystemServiceStub * stub,MessageParcel & data,MessageParcel & reply,MessageOption & option)226 static int32_t ProcessGetConfigurationByteArray(MediaKeySystemServiceStub *stub, MessageParcel &data,
227 MessageParcel &reply, MessageOption &option)
228 {
229 DRM_INFO_LOG("ProcessGetConfigurationByteArray enter.");
230 std::string configName = data.ReadString();
231 std::vector<uint8_t> value;
232 int32_t ret = stub->GetConfigurationByteArray(configName, value);
233 DRM_CHECK_AND_RETURN_RET_LOG(ret == DRM_OK, ret, "ProcessGetConfigurationByteArray faild, errCode:%{public}d", ret);
234 if (!reply.WriteInt32(value.size())) {
235 DRM_ERR_LOG("Write value size failed.");
236 return IPC_STUB_WRITE_PARCEL_ERR;
237 }
238 DRM_CHECK_AND_RETURN_RET_LOG(value.size() < RESPONSE_MAX_LEN, DRM_MEMORY_ERROR,
239 "The size of configurate value is too large.");
240 if (value.size() != 0) {
241 if (!reply.WriteBuffer(value.data(), value.size())) {
242 DRM_ERR_LOG("ProcessGetConfigurationByteArray write value failed.");
243 return IPC_STUB_WRITE_PARCEL_ERR;
244 }
245 }
246 return ret;
247 }
248
ProcessGetMetircs(MediaKeySystemServiceStub * stub,MessageParcel & data,MessageParcel & reply,MessageOption & option)249 static int32_t ProcessGetMetircs(MediaKeySystemServiceStub *stub, MessageParcel &data, MessageParcel &reply,
250 MessageOption &option)
251 {
252 DRM_INFO_LOG("ProcessGetMetircs enter.");
253 std::vector<IMediaKeySystemService::MetircKeyValue> metrics;
254 int32_t ret = stub->GetStatistics(metrics);
255 DRM_CHECK_AND_RETURN_RET_LOG(ret == DRM_OK, ret, "ProcessGetMetircs faild, errCode:%{public}d", ret);
256 reply.WriteInt32(metrics.size());
257 for (auto info : metrics) {
258 reply.WriteString(info.name);
259 reply.WriteString(info.value);
260 }
261 return ret;
262 }
263
ProcessReleaseKeySystem(MediaKeySystemServiceStub * stub,MessageParcel & data,MessageParcel & reply,MessageOption & option)264 static int32_t ProcessReleaseKeySystem(MediaKeySystemServiceStub *stub, MessageParcel &data, MessageParcel &reply,
265 MessageOption &option)
266 {
267 DRM_INFO_LOG("ProcessReleaseKeySystem enter.");
268 int32_t ret = stub->Release();
269 DRM_CHECK_AND_RETURN_RET_LOG(ret == DRM_OK, ret, "ProcessReleaseKeySystem faild, errCode:%{public}d", ret);
270 return ret;
271 }
272
ProcessGetMaxContentProtectionLevel(MediaKeySystemServiceStub * stub,MessageParcel & data,MessageParcel & reply,MessageOption & option)273 static int32_t ProcessGetMaxContentProtectionLevel(MediaKeySystemServiceStub *stub, MessageParcel &data,
274 MessageParcel &reply, MessageOption &option)
275 {
276 DRM_INFO_LOG("ProcessGetMaxContentProtectionLevel enter.");
277 IMediaKeySessionService::ContentProtectionLevel securityLevel =
278 IMediaKeySessionService::CONTENT_PROTECTION_LEVEL_UNKNOWN;
279 int32_t ret = stub->GetMaxContentProtectionLevel(&securityLevel);
280 DRM_CHECK_AND_RETURN_RET_LOG(ret == DRM_OK, ret, "ProcessGetMaxContentProtectionLevel faild, errCode:%{public}d",
281 ret);
282 if (!reply.WriteInt32(securityLevel)) {
283 DRM_ERR_LOG("Write ProcessGetMaxContentProtectionLevel failed.");
284 return IPC_STUB_WRITE_PARCEL_ERR;
285 }
286 return ret;
287 }
288
ProcessGetCertificateStatus(MediaKeySystemServiceStub * stub,MessageParcel & data,MessageParcel & reply,MessageOption & option)289 static int32_t ProcessGetCertificateStatus(MediaKeySystemServiceStub *stub, MessageParcel &data, MessageParcel &reply,
290 MessageOption &option)
291 {
292 DRM_INFO_LOG("ProcessGetCertificateStatus enter.");
293 IMediaKeySystemService::CertificateStatus certStatus = IMediaKeySystemService::CERT_STATUS_PROVISIONED;
294 int32_t ret = stub->GetCertificateStatus(&certStatus);
295 DRM_CHECK_AND_RETURN_RET_LOG(ret == DRM_OK, ret, "ProcessGetCertificateStatus faild, errCode:%{public}d", ret);
296 if (!reply.WriteInt32(certStatus)) {
297 DRM_ERR_LOG("ProcessGetCertificateStatus write certStatus failed.");
298 return IPC_STUB_WRITE_PARCEL_ERR;
299 }
300 return ret;
301 }
302
ProcessGetOfflineMediaKeyIds(MediaKeySystemServiceStub * stub,MessageParcel & data,MessageParcel & reply,MessageOption & option)303 static int32_t ProcessGetOfflineMediaKeyIds(MediaKeySystemServiceStub *stub, MessageParcel &data, MessageParcel &reply,
304 MessageOption &option)
305 {
306 DRM_INFO_LOG("ProcessGetOfflineMediaKeyIds enter.");
307 std::vector<std::vector<uint8_t>> licenseIds;
308 int32_t ret = stub->GetOfflineMediaKeyIds(licenseIds);
309 DRM_CHECK_AND_RETURN_RET_LOG(ret == DRM_OK, ret, "ProcessGetOfflineMediaKeyIds faild, errCode:%{public}d", ret);
310
311 reply.WriteUint32(licenseIds.size());
312 if (licenseIds.size() == 0 || licenseIds.size() > LICENSEID_MAX_LEN) {
313 DRM_DEBUG_LOG("licenseIds size is error.");
314 return ret;
315 }
316 for (uint32_t i = 0; i < licenseIds.size(); i++) {
317 uint32_t licenseIdSize = licenseIds[i].size();
318 reply.WriteUint32(licenseIdSize);
319 if (licenseIdSize == 0 || licenseIdSize > LICENSEID_MAX_LEN) {
320 continue;
321 }
322 if (!reply.WriteBuffer(licenseIds[i].data(), licenseIdSize)) {
323 DRM_ERR_LOG("ProcessGetOfflineMediaKeyIds write licenseId failed.");
324 return IPC_STUB_WRITE_PARCEL_ERR;
325 }
326 }
327 return ret;
328 }
329
ProcessGetOfflineMediaKeyStatus(MediaKeySystemServiceStub * stub,MessageParcel & data,MessageParcel & reply,MessageOption & option)330 static int32_t ProcessGetOfflineMediaKeyStatus(MediaKeySystemServiceStub *stub, MessageParcel &data,
331 MessageParcel &reply, MessageOption &option)
332 {
333 DRM_INFO_LOG("ProcessGetOfflineMediaKeyStatus enter.");
334 std::vector<uint8_t> licenseId;
335 int32_t licenseIdSize = data.ReadInt32();
336 DRM_CHECK_AND_RETURN_RET_LOG(licenseIdSize < LICENSEID_MAX_LEN, DRM_MEMORY_ERROR,
337 "The size of licenseId is too large.");
338 if (licenseIdSize != 0) {
339 const uint8_t *licenseIdBuf = static_cast<const uint8_t *>(data.ReadUnpadBuffer(licenseIdSize));
340 if (licenseIdBuf == nullptr) {
341 DRM_ERR_LOG(":ProcessGetOfflineMediaKeyStatus read licenseId failed.");
342 return IPC_STUB_WRITE_PARCEL_ERR;
343 }
344 licenseId.assign(licenseIdBuf, licenseIdBuf + licenseIdSize);
345 }
346 IMediaKeySessionService::OfflineMediaKeyStatus status;
347 int32_t ret = stub->GetOfflineMediaKeyStatus(licenseId, status);
348 DRM_CHECK_AND_RETURN_RET_LOG(ret == DRM_OK, ret, "ProcessGetOfflineMediaKeyStatus faild, errCode:%{public}d", ret);
349 if (!reply.WriteInt32((int32_t)status)) {
350 DRM_ERR_LOG("Write state failed.");
351 return IPC_STUB_WRITE_PARCEL_ERR;
352 }
353 return ret;
354 }
355
ProcessRemoveOfflineMediaKey(MediaKeySystemServiceStub * stub,MessageParcel & data,MessageParcel & reply,MessageOption & option)356 static int32_t ProcessRemoveOfflineMediaKey(MediaKeySystemServiceStub *stub, MessageParcel &data, MessageParcel &reply,
357 MessageOption &option)
358 {
359 DRM_INFO_LOG("ProcessRemoveOfflineMediaKey enter.");
360 std::vector<uint8_t> licenseId;
361 int32_t licenseIdSize = data.ReadInt32();
362 DRM_CHECK_AND_RETURN_RET_LOG(licenseIdSize < LICENSEID_MAX_LEN, DRM_MEMORY_ERROR,
363 "The size of licenseId is too large.");
364 if (licenseIdSize != 0) {
365 const uint8_t *licenseIdBuf = static_cast<const uint8_t *>(data.ReadUnpadBuffer(licenseIdSize));
366 if (licenseIdBuf == nullptr) {
367 DRM_ERR_LOG("ProcessRemoveOfflineMediaKey read licenseId failed.");
368 return IPC_STUB_WRITE_PARCEL_ERR;
369 }
370 licenseId.assign(licenseIdBuf, licenseIdBuf + licenseIdSize);
371 }
372 int32_t ret = stub->ClearOfflineMediaKeys(licenseId);
373 DRM_CHECK_AND_RETURN_RET_LOG(ret == DRM_OK, ret, "ProcessRemoveOfflineMediaKey faild, errCode:%{public}d", ret);
374 return ret;
375 }
376
MediaKeySystemClientDied(pid_t pid)377 void MediaKeySystemServiceStub::MediaKeySystemClientDied(pid_t pid)
378 {
379 DRM_ERR_LOG("MediaKeySystemService client has died, pid:%{public}d", pid);
380 }
381
SetListenerObject(const sptr<IRemoteObject> & object)382 int32_t MediaKeySystemServiceStub::SetListenerObject(const sptr<IRemoteObject> &object)
383 {
384 pid_t pid = IPCSkeleton::GetCallingPid();
385 if (clientListener_ != nullptr && clientListener_->AsObject() != nullptr && deathRecipient_ != nullptr) {
386 DRM_DEBUG_LOG("This MediaKeySystemServiceStub has already set listener!");
387 (void)clientListener_->AsObject()->RemoveDeathRecipient(deathRecipient_);
388 deathRecipient_ = nullptr;
389 clientListener_ = nullptr;
390 }
391
392 DRM_CHECK_AND_RETURN_RET_LOG(object != nullptr, DRM_MEMORY_ERROR, "set listener object is nullptr");
393 sptr<IDrmListener> clientListener_ = iface_cast<IDrmListener>(object);
394 DRM_CHECK_AND_RETURN_RET_LOG(
395 clientListener_ != nullptr, DRM_MEMORY_ERROR, "failed to convert IDrmListener");
396 deathRecipient_ = new (std::nothrow) DrmDeathRecipient(pid);
397 DRM_CHECK_AND_RETURN_RET_LOG(deathRecipient_ != nullptr, DRM_MEMORY_ERROR, "failed to new DrmDeathRecipient");
398 deathRecipient_->SetNotifyCb([this] (pid_t pid) {
399 this->MediaKeySystemClientDied(pid);
400 });
401 if (clientListener_->AsObject() != nullptr) {
402 (void)clientListener_->AsObject()->AddDeathRecipient(deathRecipient_);
403 }
404 return DRM_OK;
405 }
406
ProcessSetListenerObject(MediaKeySystemServiceStub * stub,MessageParcel & data,MessageParcel & reply,MessageOption & option)407 static int32_t ProcessSetListenerObject(MediaKeySystemServiceStub *stub, MessageParcel &data, MessageParcel &reply,
408 MessageOption &option)
409 {
410 DRM_INFO_LOG("ProcessSetListenerObject.");
411 (void)reply;
412 sptr<IRemoteObject> object = data.ReadRemoteObject();
413 int32_t ret = stub->SetListenerObject(object);
414 DRM_CHECK_AND_RETURN_RET_LOG(ret == DRM_OK, ret,
415 "ProcessSetListenerObject faild, errCode:%{public}d", ret);
416 return ret;
417 }
418
ProcessSetCallabck(MediaKeySystemServiceStub * stub,MessageParcel & data,MessageParcel & reply,MessageOption & option)419 static int32_t ProcessSetCallabck(MediaKeySystemServiceStub *stub, MessageParcel &data, MessageParcel &reply,
420 MessageOption &option)
421 {
422 DRM_INFO_LOG("ProcessSetCallabck enter.");
423 auto remoteObject = data.ReadRemoteObject();
424 if (remoteObject == nullptr) {
425 DRM_ERR_LOG("ProcessSetCallabck remote is null");
426 return IPC_STUB_INVALID_DATA_ERR;
427 }
428 auto callback = iface_cast<IMediaKeySystemServiceCallback>(remoteObject);
429 if (callback == nullptr) {
430 DRM_ERR_LOG("ProcessSetCallabck iface_cast nullptr");
431 return IPC_STUB_INVALID_DATA_ERR;
432 }
433 int32_t ret = stub->SetCallback(callback);
434 DRM_CHECK_AND_RETURN_RET_LOG(ret == DRM_OK, ret, "ProcessSetCallabck faild, errCode:%{public}d", ret);
435 return ret;
436 }
437
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)438 int32_t MediaKeySystemServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
439 MessageOption &option)
440 {
441 DRM_CHECK_AND_RETURN_RET_LOG(data.ReadInterfaceToken() == GetDescriptor(), -1,
442 "ReadInterfaceToken failed.");
443 DRM_INFO_LOG("OnRemoteRequest, cmd = %{public}u", code);
444
445 DRM_CHECK_AND_RETURN_RET_LOG((code >= MEDIA_KEY_SYSTEM_CREATE_KEY_SESSION) &&
446 (code <= MEDIA_KEY_SYSTEM_SETCALLBACK),
447 IPCObjectStub::OnRemoteRequest(code, data, reply, option),
448 "code not match, need check MediaKeySystemServiceStub");
449
450 return g_mediaKeySystemServiceStubRequestProcessFunc[code].processFunc(this, data, reply, option);
451 }
452 } // namespace DrmStandard
453 } // namespace OHOS