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_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 (*)(MediaKeySessionServiceStub *stub, MessageParcel &data,
26 MessageParcel &reply, MessageOption &option);
27 struct ProcessRemoteRequestFuncArray {
28 OHOS::DrmStandard::MediaKeySessionServiceRequestCode requestCode;
29 ProcessRemoteRequestFunc processFunc;
30 };
31
32 static int32_t ProcessGetMediaDecryptModule(MediaKeySessionServiceStub *stub, MessageParcel &data,
33 MessageParcel &reply, MessageOption &option);
34
35 static int32_t ProcessReleaseKeySession(MediaKeySessionServiceStub *stub, MessageParcel &data, MessageParcel &reply,
36 MessageOption &option);
37
38 static int32_t ProcessMediaKeyRequest(MediaKeySessionServiceStub *stub, MessageParcel &data, MessageParcel &reply,
39 MessageOption &option);
40
41 static int32_t ProcessMediaKeyResponse(MediaKeySessionServiceStub *stub, MessageParcel &data, MessageParcel &reply,
42 MessageOption &option);
43
44 static int32_t ProcessOfflineReleaseRequest(MediaKeySessionServiceStub *stub, MessageParcel &data, MessageParcel &reply,
45 MessageOption &option);
46
47 static int32_t ProcessOfflineReleaseResponse(MediaKeySessionServiceStub *stub, MessageParcel &data,
48 MessageParcel &reply, MessageOption &option);
49
50 static int32_t ProcessCheckMediaKeyStatus(MediaKeySessionServiceStub *stub, MessageParcel &data, MessageParcel &reply,
51 MessageOption &option);
52
53 static int32_t ProcessRestoreOfflineMediaKey(MediaKeySessionServiceStub *stub, MessageParcel &data,
54 MessageParcel &reply, MessageOption &option);
55
56 static int32_t ProcessClearMediaKeys(MediaKeySessionServiceStub *stub, MessageParcel &data, MessageParcel &reply,
57 MessageOption &option);
58
59 static int32_t ProcessSetCallback(MediaKeySessionServiceStub *stub, MessageParcel &data, MessageParcel &reply,
60 MessageOption &option);
61
62 static int32_t ProcessRequireSecureDecoder(MediaKeySessionServiceStub *stub, MessageParcel &data, MessageParcel &reply,
63 MessageOption &option);
64
65 static int32_t ProcessGetContentProtectionLevel(MediaKeySessionServiceStub *stub, MessageParcel &data,
66 MessageParcel &reply, MessageOption &option);
67
68 static int32_t ProcessSetListenerObject(MediaKeySessionServiceStub *stub, MessageParcel &data,
69 MessageParcel &reply, MessageOption &option);
70
71 static struct ProcessRemoteRequestFuncArray g_mediaKeySessionServiceStubRequestProcessFunc[] = {
72 {GET_MEDIA_DECRYPT_MODULE, ProcessGetMediaDecryptModule},
73 {KEY_SESSION_RELEASE, ProcessReleaseKeySession},
74 {MEDIA_KEY_SESSION_GENERATE_LICENSE_REQUEST, ProcessMediaKeyRequest},
75 {MEDIA_KEY_SESSION_PROCESS_LICENSE_RESPONSE, ProcessMediaKeyResponse},
76 {MEDIA_KEY_SESSION_GENERATE_OFFLINE_RELEASE_REQUEST, ProcessOfflineReleaseRequest},
77 {MEDIA_KEY_SESSION_PROCESS_OFFLINE_RELEASE_RESPONSE, ProcessOfflineReleaseResponse},
78 {MEDIA_KEY_SESSION_GENERATE_CHECK_LICENSE_STATUS, ProcessCheckMediaKeyStatus},
79 {MEDIA_KEY_SESSION_RESTORE_OFFLINEKEYS, ProcessRestoreOfflineMediaKey},
80 {MEDIA_KEY_SESSION_REMOVE_LICENSE, ProcessClearMediaKeys},
81 {MEDIA_KEY_SESSION_SET_CALLBACK, ProcessSetCallback},
82 {MEDIA_KEY_SESSION_REQUIRE_SECURE_DECODER, ProcessRequireSecureDecoder},
83 {MEDIA_KEY_SESSION_SET_LISTENER_OBJ, ProcessSetListenerObject},
84 {MEDIA_KEY_SESSION_GETSECURITYLEVEL, ProcessGetContentProtectionLevel},
85 };
86
ProcessGetMediaDecryptModule(MediaKeySessionServiceStub * stub,MessageParcel & data,MessageParcel & reply,MessageOption & option)87 static int32_t ProcessGetMediaDecryptModule(MediaKeySessionServiceStub *stub, MessageParcel &data,
88 MessageParcel &reply, MessageOption &option)
89 {
90 DRM_INFO_LOG("ProcessGetMediaDecryptModule enter.");
91 sptr<IMediaDecryptModuleService> decryptModuleServiceProxy = nullptr;
92 int32_t ret = stub->GetMediaDecryptModule(decryptModuleServiceProxy);
93 if (ret != DRM_OK) {
94 DRM_ERR_LOG("GetMediaDecryptModule failed. errCode:%{public}d", ret);
95 return ret;
96 }
97 if (!reply.WriteRemoteObject(decryptModuleServiceProxy->AsObject())) {
98 DRM_ERR_LOG("Write MediaDecryptModule obj failed.");
99 return IPC_STUB_WRITE_PARCEL_ERR;
100 }
101 return DRM_OK;
102 }
103
ProcessReleaseKeySession(MediaKeySessionServiceStub * stub,MessageParcel & data,MessageParcel & reply,MessageOption & option)104 static int32_t ProcessReleaseKeySession(MediaKeySessionServiceStub *stub, MessageParcel &data, MessageParcel &reply,
105 MessageOption &option)
106 {
107 DRM_INFO_LOG("ProcessReleaseKeySession enter.");
108 int32_t ret = stub->Release();
109 return ret;
110 }
111
ProcessMediaKeyRequest(MediaKeySessionServiceStub * stub,MessageParcel & data,MessageParcel & reply,MessageOption & option)112 static int32_t ProcessMediaKeyRequest(MediaKeySessionServiceStub *stub, MessageParcel &data, MessageParcel &reply,
113 MessageOption &option)
114 {
115 DRM_INFO_LOG("ProcessMediaKeyRequest enter.");
116 IMediaKeySessionService::MediaKeyRequestInfo licenseRequestInfo;
117 IMediaKeySessionService::MediaKeyRequest licenseRequest;
118 int32_t optionalDataMapSize = data.ReadInt32();
119 DRM_CHECK_AND_RETURN_RET_LOG(optionalDataMapSize < DATA_MAX_LEN, DRM_MEMORY_ERROR,
120 "The size of optionalData is too large.");
121 for (int32_t i = 0; i < optionalDataMapSize; i++) {
122 std::string name = data.ReadString();
123 std::string value = data.ReadString();
124 licenseRequestInfo.optionalData.insert(std::make_pair(name, value));
125 }
126 licenseRequestInfo.mediaKeyType = (OHOS::DrmStandard::IMediaKeySessionService::MediaKeyType)data.ReadInt32();
127 licenseRequestInfo.mimeType = data.ReadString();
128 int32_t initDataSize = data.ReadInt32();
129 DRM_CHECK_AND_RETURN_RET_LOG(initDataSize < DATA_MAX_LEN, DRM_MEMORY_ERROR, "The size of initData is too large.");
130 if (initDataSize != 0) {
131 const uint8_t *initDataBuf = static_cast<const uint8_t *>(data.ReadUnpadBuffer(initDataSize));
132 if (initDataBuf == nullptr) {
133 DRM_ERR_LOG("ReadUnpadBuffer failed.");
134 return IPC_STUB_WRITE_PARCEL_ERR;
135 }
136 licenseRequestInfo.initData.assign(initDataBuf, initDataBuf + initDataSize);
137 }
138 int32_t ret = stub->GenerateMediaKeyRequest(licenseRequestInfo, licenseRequest);
139 DRM_CHECK_AND_RETURN_RET_LOG(ret == DRM_OK, ret, "GenerateMediaKeyRequest faild, errCode:%{public}d", ret);
140 if (!reply.WriteString(licenseRequest.mDefaultURL)) {
141 DRM_ERR_LOG("Write licenseRequest.mDefaultURL GenerateMediaKeyRequest failed.");
142 return IPC_STUB_WRITE_PARCEL_ERR;
143 }
144
145 if (!reply.WriteInt32(licenseRequest.requestType)) {
146 DRM_ERR_LOG("Write requestType GenerateMediaKeyRequest failed.");
147 return IPC_STUB_WRITE_PARCEL_ERR;
148 }
149 if (!reply.WriteInt32(licenseRequest.mData.size())) {
150 DRM_ERR_LOG("Write licenseRequestmDatasize GenerateMediaKeyRequest failed.");
151 return IPC_STUB_WRITE_PARCEL_ERR;
152 }
153 DRM_CHECK_AND_RETURN_RET_LOG(licenseRequest.mData.size() < REQUEST_MAX_LEN, DRM_MEMORY_ERROR,
154 "The size of mData is too large.");
155 if (licenseRequest.mData.size() != 0) {
156 if (!reply.WriteBuffer(licenseRequest.mData.data(), licenseRequest.mData.size())) {
157 DRM_ERR_LOG("GenerateMediaKeyRequest write mData failed.");
158 return IPC_STUB_WRITE_PARCEL_ERR;
159 }
160 }
161 return ret;
162 }
163
ProcessMediaKeyResponse(MediaKeySessionServiceStub * stub,MessageParcel & data,MessageParcel & reply,MessageOption & option)164 static int32_t ProcessMediaKeyResponse(MediaKeySessionServiceStub *stub, MessageParcel &data, MessageParcel &reply,
165 MessageOption &option)
166 {
167 DRM_INFO_LOG("ProcessMediaKeyResponse enter.");
168 std::vector<uint8_t> response;
169 std::vector<uint8_t> licenseId;
170 int32_t responseSize = data.ReadInt32();
171 DRM_CHECK_AND_RETURN_RET_LOG(responseSize < RESPONSE_MAX_LEN, DRM_MEMORY_ERROR,
172 "The size of response is too large.");
173 if (responseSize != 0) {
174 const uint8_t *responseBuf = static_cast<const uint8_t *>(data.ReadUnpadBuffer(responseSize));
175 if (responseBuf == nullptr) {
176 DRM_ERR_LOG("ProcessMediaKeyResponse read response failed.");
177 return IPC_STUB_WRITE_PARCEL_ERR;
178 }
179 response.assign(responseBuf, responseBuf + responseSize);
180 }
181 int32_t ret = stub->ProcessMediaKeyResponse(licenseId, response);
182 DRM_CHECK_AND_RETURN_RET_LOG(ret == DRM_OK, ret, "ProcessMediaKeyResponse faild, ret:%{public}d", ret);
183 if (!reply.WriteInt32(licenseId.size())) {
184 DRM_ERR_LOG("GenerateMediaKeyRequest Write licenseId.size failed.");
185 return IPC_STUB_WRITE_PARCEL_ERR;
186 }
187 DRM_CHECK_AND_RETURN_RET_LOG(licenseId.size() < LICENSEID_MAX_LEN, DRM_MEMORY_ERROR,
188 "The size of licenseId is too large.");
189 if (licenseId.size() != 0) {
190 if (!reply.WriteBuffer(licenseId.data(), licenseId.size())) {
191 DRM_ERR_LOG("GenerateMediaKeyRequest write licenseId failed.");
192 return IPC_STUB_WRITE_PARCEL_ERR;
193 }
194 }
195 return ret;
196 }
197
ProcessOfflineReleaseRequest(MediaKeySessionServiceStub * stub,MessageParcel & data,MessageParcel & reply,MessageOption & option)198 static int32_t ProcessOfflineReleaseRequest(MediaKeySessionServiceStub *stub, MessageParcel &data, MessageParcel &reply,
199 MessageOption &option)
200 {
201 DRM_INFO_LOG("ProcessOfflineReleaseRequest enter.");
202 std::vector<uint8_t> licenseId;
203 int32_t licenseIdSize = data.ReadInt32();
204 DRM_CHECK_AND_RETURN_RET_LOG(licenseIdSize < LICENSEID_MAX_LEN, DRM_MEMORY_ERROR,
205 "The size of licenseId is too large.");
206 if (licenseIdSize != 0) {
207 const uint8_t *licenseIdBuf = static_cast<const uint8_t *>(data.ReadUnpadBuffer(licenseIdSize));
208 if (licenseIdBuf == nullptr) {
209 DRM_ERR_LOG("ProcessOfflineReleaseRequest read licenseId failed.");
210 return IPC_STUB_WRITE_PARCEL_ERR;
211 }
212 licenseId.assign(licenseIdBuf, licenseIdBuf + licenseIdSize);
213 }
214 std::vector<uint8_t> releaseRequest;
215 int32_t ret = stub->GenerateOfflineReleaseRequest(licenseId, releaseRequest);
216 DRM_CHECK_AND_RETURN_RET_LOG(ret == DRM_OK, ret, "GenerateOfflineReleaseRequest faild, errCode:%{public}d", ret);
217 if (!reply.WriteInt32(releaseRequest.size())) {
218 DRM_ERR_LOG("Write releaseRequest.size failed.");
219 return IPC_STUB_WRITE_PARCEL_ERR;
220 }
221 DRM_CHECK_AND_RETURN_RET_LOG(releaseRequest.size() < REQUEST_MAX_LEN, DRM_MEMORY_ERROR,
222 "The size of releaseRequest is too large.");
223 if (releaseRequest.size() != 0) {
224 if (!reply.WriteBuffer(releaseRequest.data(), releaseRequest.size())) {
225 DRM_ERR_LOG("ProcessOfflineReleaseRequest Write licenseId failed.");
226 return IPC_STUB_WRITE_PARCEL_ERR;
227 }
228 }
229 return ret;
230 }
231
ProcessOfflineReleaseResponse(MediaKeySessionServiceStub * stub,MessageParcel & data,MessageParcel & reply,MessageOption & option)232 static int32_t ProcessOfflineReleaseResponse(MediaKeySessionServiceStub *stub, MessageParcel &data,
233 MessageParcel &reply, MessageOption &option)
234 {
235 DRM_INFO_LOG("ProcessOfflineReleaseResponse enter.");
236 int32_t licenseIdSize = data.ReadInt32();
237 std::vector<uint8_t> licenseId;
238 DRM_CHECK_AND_RETURN_RET_LOG(licenseIdSize < LICENSEID_MAX_LEN, DRM_MEMORY_ERROR,
239 "The size of licenseId is too large.");
240 const uint8_t *licenseIdBuf = static_cast<const uint8_t *>(data.ReadUnpadBuffer(licenseIdSize));
241 if (licenseIdBuf == nullptr) {
242 DRM_ERR_LOG("ProcessOfflineReleaseResponse read licenseId failed.");
243 return IPC_STUB_WRITE_PARCEL_ERR;
244 }
245 licenseId.assign(licenseIdBuf, licenseIdBuf + licenseIdSize);
246 std::vector<uint8_t> response;
247 int32_t responseSize = data.ReadInt32();
248 DRM_CHECK_AND_RETURN_RET_LOG(responseSize < RESPONSE_MAX_LEN, DRM_MEMORY_ERROR,
249 "The size of response is too large.");
250 if (responseSize != 0) {
251 const uint8_t *responseBuf = static_cast<const uint8_t *>(data.ReadUnpadBuffer(responseSize));
252 if (responseBuf == nullptr) {
253 DRM_ERR_LOG("ProcessOfflineReleaseResponse read response failed.");
254 return IPC_STUB_WRITE_PARCEL_ERR;
255 }
256 response.assign(responseBuf, responseBuf + responseSize);
257 }
258 int32_t ret = stub->ProcessOfflineReleaseResponse(licenseId, response);
259 DRM_CHECK_AND_RETURN_RET_LOG(ret == DRM_OK, ret, "ProcessOfflineReleaseResponse faild, errCode:%{public}d", ret);
260 return ret;
261 }
262
ProcessCheckMediaKeyStatus(MediaKeySessionServiceStub * stub,MessageParcel & data,MessageParcel & reply,MessageOption & option)263 static int32_t ProcessCheckMediaKeyStatus(MediaKeySessionServiceStub *stub, MessageParcel &data, MessageParcel &reply,
264 MessageOption &option)
265 {
266 DRM_INFO_LOG("ProcessCheckMediaKeyStatus enter.");
267 std::map<std::string, std::string> licenseStatus;
268 int32_t ret = stub->CheckMediaKeyStatus(licenseStatus);
269 DRM_CHECK_AND_RETURN_RET_LOG(ret == DRM_OK, ret, "CheckMediaKeyStatus faild, errCode:%{public}d", ret);
270
271 reply.WriteInt32(licenseStatus.size());
272 for (auto licenseStatu : licenseStatus) {
273 reply.WriteString(licenseStatu.first);
274 reply.WriteString(licenseStatu.second);
275 }
276 return ret;
277 }
278
ProcessRestoreOfflineMediaKey(MediaKeySessionServiceStub * stub,MessageParcel & data,MessageParcel & reply,MessageOption & option)279 static int32_t ProcessRestoreOfflineMediaKey(MediaKeySessionServiceStub *stub, MessageParcel &data,
280 MessageParcel &reply, MessageOption &option)
281 {
282 DRM_INFO_LOG("ProcessRestoreOfflineMediaKey enter.");
283 std::vector<uint8_t> licenseId;
284 int32_t licenseIdSize = data.ReadInt32();
285 DRM_CHECK_AND_RETURN_RET_LOG(licenseIdSize < LICENSEID_MAX_LEN, DRM_MEMORY_ERROR,
286 "The size of licenseId is too large.");
287 if (licenseIdSize != 0) {
288 const uint8_t *licenseIdBuf = static_cast<const uint8_t *>(data.ReadUnpadBuffer(licenseIdSize));
289 if (licenseIdBuf == nullptr) {
290 DRM_ERR_LOG("ProcessRestoreOfflineMediaKey read licenseId failed.");
291 return IPC_STUB_WRITE_PARCEL_ERR;
292 }
293 licenseId.assign(licenseIdBuf, licenseIdBuf + licenseIdSize);
294 }
295 int32_t ret = stub->RestoreOfflineMediaKeys(licenseId);
296 DRM_CHECK_AND_RETURN_RET_LOG(ret == DRM_OK, ret, "RestoreOfflineMediaKeys faild, errCode:%{public}d", ret);
297 return ret;
298 }
299
ProcessClearMediaKeys(MediaKeySessionServiceStub * stub,MessageParcel & data,MessageParcel & reply,MessageOption & option)300 static int32_t ProcessClearMediaKeys(MediaKeySessionServiceStub *stub, MessageParcel &data, MessageParcel &reply,
301 MessageOption &option)
302 {
303 DRM_INFO_LOG("ProcessClearMediaKeys enter.");
304 int32_t ret = stub->ClearMediaKeys();
305 DRM_CHECK_AND_RETURN_RET_LOG(ret == DRM_OK, ret, "ClearMediaKeys faild, errCode:%{public}d", ret);
306 return ret;
307 }
308
ProcessSetCallback(MediaKeySessionServiceStub * stub,MessageParcel & data,MessageParcel & reply,MessageOption & option)309 static int32_t ProcessSetCallback(MediaKeySessionServiceStub *stub, MessageParcel &data, MessageParcel &reply,
310 MessageOption &option)
311 {
312 DRM_INFO_LOG("ProcessSetCallback enter.");
313 auto remoteObject = data.ReadRemoteObject();
314 if (remoteObject == nullptr) {
315 DRM_ERR_LOG("ProcessSetCallback ReadRemoteObject is null");
316 return IPC_STUB_INVALID_DATA_ERR;
317 }
318 auto callback = iface_cast<IMediaKeySessionServiceCallback>(remoteObject);
319 if (callback == nullptr) {
320 DRM_ERR_LOG("iface_cast cast nullptr");
321 return IPC_STUB_INVALID_DATA_ERR;
322 }
323 int32_t ret = stub->SetCallback(callback);
324 DRM_CHECK_AND_RETURN_RET_LOG(ret == DRM_OK, ret, "SetCallback faild, errCode:%{public}d", ret);
325 return ret;
326 }
327
ProcessRequireSecureDecoder(MediaKeySessionServiceStub * stub,MessageParcel & data,MessageParcel & reply,MessageOption & option)328 static int32_t ProcessRequireSecureDecoder(MediaKeySessionServiceStub *stub, MessageParcel &data, MessageParcel &reply,
329 MessageOption &option)
330 {
331 DRM_INFO_LOG("ProcessRequireSecureDecoder enter.");
332 std::string mimeType = data.ReadString();
333 bool status;
334 int32_t ret = stub->RequireSecureDecoderModule(mimeType, &status);
335 DRM_CHECK_AND_RETURN_RET_LOG(ret == DRM_OK, ret, "ProcessRequireSecureDecoder faild, errCode:%{public}d", ret);
336 reply.WriteBool(status);
337 return ret;
338 }
339
MediaKeySessionClientDied(pid_t pid)340 void MediaKeySessionServiceStub::MediaKeySessionClientDied(pid_t pid)
341 {
342 DRM_ERR_LOG("MediaKeySession client has died, pid:%{public}d", pid);
343 }
344
SetListenerObject(const sptr<IRemoteObject> & object)345 int32_t MediaKeySessionServiceStub::SetListenerObject(const sptr<IRemoteObject> &object)
346 {
347 std::lock_guard<std::recursive_mutex> lock(drmSessionStubMutex_);
348 pid_t pid = IPCSkeleton::GetCallingPid();
349 if (clientListener_ != nullptr && clientListener_->AsObject() != nullptr && deathRecipient_ != nullptr) {
350 DRM_DEBUG_LOG("This MediaKeySessionServiceStub has already set listener!");
351 (void)clientListener_->AsObject()->RemoveDeathRecipient(deathRecipient_);
352 deathRecipient_ = nullptr;
353 clientListener_ = nullptr;
354 }
355
356 DRM_CHECK_AND_RETURN_RET_LOG(object != nullptr, DRM_MEMORY_ERROR, "set listener object is nullptr");
357 sptr<IDrmListener> clientListener_ = iface_cast<IDrmListener>(object);
358 DRM_CHECK_AND_RETURN_RET_LOG(
359 clientListener_ != nullptr, DRM_MEMORY_ERROR, "failed to convert IDrmListener");
360 deathRecipient_ = new (std::nothrow) DrmDeathRecipient(pid);
361 DRM_CHECK_AND_RETURN_RET_LOG(deathRecipient_ != nullptr, DRM_MEMORY_ERROR, "failed to new DrmDeathRecipient");
362 deathRecipient_->SetNotifyCb([this] (pid_t pid) {
363 this->MediaKeySessionClientDied(pid);
364 });
365 if (clientListener_->AsObject() != nullptr) {
366 (void)clientListener_->AsObject()->AddDeathRecipient(deathRecipient_);
367 }
368 DRM_DEBUG_LOG("MediaKeySession client pid pid:%{public}d", pid);
369 return DRM_OK;
370 }
371
ProcessSetListenerObject(MediaKeySessionServiceStub * stub,MessageParcel & data,MessageParcel & reply,MessageOption & option)372 static int32_t ProcessSetListenerObject(MediaKeySessionServiceStub *stub, MessageParcel &data,
373 MessageParcel &reply, MessageOption &option)
374 {
375 DRM_INFO_LOG("ProcessSetListenerObject.");
376 (void)reply;
377 sptr<IRemoteObject> object = data.ReadRemoteObject();
378 int32_t ret = stub->SetListenerObject(object);
379 DRM_CHECK_AND_RETURN_RET_LOG(ret == DRM_OK, ret,
380 "ProcessSetListenerObject faild, errCode:%{public}d", ret);
381 return ret;
382 }
383
ProcessGetContentProtectionLevel(MediaKeySessionServiceStub * stub,MessageParcel & data,MessageParcel & reply,MessageOption & option)384 static int32_t ProcessGetContentProtectionLevel(MediaKeySessionServiceStub *stub, MessageParcel &data,
385 MessageParcel &reply, MessageOption &option)
386 {
387 DRM_INFO_LOG("ProcessGetContentProtectionLevel enter.");
388 IMediaKeySessionService::ContentProtectionLevel securityLevel =
389 IMediaKeySessionService::CONTENT_PROTECTION_LEVEL_UNKNOWN;
390 int32_t ret = stub->GetContentProtectionLevel(&securityLevel);
391 DRM_CHECK_AND_RETURN_RET_LOG(ret == DRM_OK, ret, "ProcessGetContentProtectionLevel faild, errCode:%{public}d", ret);
392 if (!reply.WriteInt32(securityLevel)) {
393 DRM_ERR_LOG("Write GetContentProtectionLevel failed.");
394 return IPC_STUB_WRITE_PARCEL_ERR;
395 }
396 return ret;
397 }
398
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)399 int32_t MediaKeySessionServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
400 MessageOption &option)
401 {
402 DRM_INFO_LOG("OnRemoteRequest enter.");
403 int32_t ret = DRM_ERROR;
404 DRM_DEBUG_LOG("OnRemoteRequest, cmd = %{public}u", code);
405 DRM_DEBUG_LOG("0x%{public}06" PRIXPTR " is keySessionServiceStub", FAKE_POINTER(this));
406
407 DRM_CHECK_AND_RETURN_RET_LOG(data.ReadInterfaceToken() == GetDescriptor(), ret,
408 "ReadInterfaceToken failed.");
409
410 DRM_CHECK_AND_RETURN_RET_LOG((code >= GET_MEDIA_DECRYPT_MODULE) && (code <= MEDIA_KEY_SESSION_GETSECURITYLEVEL),
411 IPCObjectStub::OnRemoteRequest(code, data, reply, option),
412 "code not match, need check MediaKeySessionServiceStub");
413 return g_mediaKeySessionServiceStubRequestProcessFunc[code].processFunc(this, data, reply, option);
414 }
415 } // DrmStandard
416 } // OHOS