1 /*
2 * Copyright (C) 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 "napi/native_api.h"
16 #include <cstdint>
17 #include <hilog/log.h>
18 #include "multimedia/drm_framework/native_drm_common.h"
19 #include "multimedia/drm_framework/native_drm_err.h"
20 #include "multimedia/drm_framework/native_mediakeysystem.h"
21 #include "multimedia/drm_framework/native_mediakeysession.h"
22 #include <ctime>
23 #include <cstring>
24 #include <cstdio>
25 #include <cstdlib>
26 #include <iostream>
27 #include <sys/socket.h>
28 #include <netinet/in.h>
29 #include <arpa/inet.h>
30 #include <unistd.h>
31 #include <netdb.h>
32
33 // hilog必加的宏,不加无法打印
34 #undef LOG_DOMAIN
35 #undef LOG_TAG
36 #define LOG_DOMAIN 0x3200 // 全局domain宏,标识业务领域
37 #define LOG_TAG "MY_DRM" // 全局tag宏,标识模块日志tag
38 // https请求宏定义
39 #define CURLEASYGETINFO 200
40 // drm module 宏定义
41 #define OPTIONS_NUM 3
42 #define DATA_BUFF_LEN 10000
43 #define DATA_BLUESPONSE_LEN 50
44 #define DATA_REQUESTINFO_LEN 139
45 #define ERROR_DATA_REQUESTINFO_LEN 139
46 #define PROVISION_DEFAULT_URL "http://default.com"
47 #define CLEAR_PLAY "com.clearplay.drm"
48 #define WISE_PLAY "com.wiseplay.drm"
49 #define LICENSE_ONLINE 1
50 #define LICENSE_OFFLINE 0
51 #define HTTP_TIMEOUT 10
52 #define URL_LICENSE "http://license.dev.trustdta.com:8080/drmproxy/v3/getLicense"
53 #define DRM_PLUGIN_COUNT 8
54 #define REQUESTINFODATA \
55 { \
56 0x00, 0x00, 0x00, 0x8B, 0x70, 0x73, 0x73, 0x68, 0x00, 0x00, 0x00, 0x00, 0x3D, 0x5E, 0x6D, 0x35, 0x9B, 0x9A, \
57 0x41, 0xE8, 0xB8, 0x43, 0xDD, 0x3C, 0x6E, 0x72, 0xC4, 0x2C, 0x00, 0x00, 0x00, 0x6B, 0x7B, 0x22, 0x76, \
58 0x65, 0x72, 0x73, 0x69, 0x6F, 0x6E, 0x22, 0x3A, 0x22, 0x56, 0x31, 0x2E, 0x30, 0x22, 0x2C, 0x22, 0x63, \
59 0x6F, 0x6E, 0x74, 0x65, 0x6E, 0x74, 0x49, 0x44, 0x22, 0x3A, 0x22, 0x64, 0x48, 0x4D, 0x74, 0x4D, 0x6A, \
60 0x59, 0x30, 0x4C, 0x54, 0x45, 0x77, 0x4F, 0x44, 0x41, 0x74, 0x59, 0x57, 0x56, 0x7A, 0x22, 0x2C, 0x22, \
61 0x6B, 0x69, 0x64, 0x73, 0x22, 0x3A, 0x5B, 0x22, 0x47, 0x2B, 0x45, 0x6B, 0x2F, 0x2B, 0x58, 0x6D, 0x55, \
62 0x6B, 0x70, 0x42, 0x48, 0x51, 0x67, 0x58, 0x59, 0x57, 0x51, 0x51, 0x49, 0x67, 0x3D, 0x3D, 0x22, 0x5D, \
63 0x2C, 0x22, 0x65, 0x6E, 0x73, 0x63, 0x68, 0x65, 0x6D, 0x61, 0x22, 0x3A, 0x22, 0x63, 0x62, 0x63, 0x31, \
64 0x22, 0x7D \
65 }
66 #define ERRORREQUESTINFODATA \
67 { \
68 0x00, 0x00, 0x00, 0x8B, 0x70, 0x73, 0x73, 0x68, 0x00, 0x00, 0x00, 0x00, 0x3D, 0x5E, 0x6D, 0x35, 0x9B, 0x9A, \
69 0x41, 0xE8, 0xB8, 0x43, 0xDD \
70 }
71 #define OFFLINERESPONSE \
72 { \
73 0x31, 0x64, 0x6E, 0x5A, 0x32, 0x4E, 0x57, 0x74, 0x76, 0x4D, 0x47, 0x34, 0x34, 0x4E, 0x6A, 0x42, 0x30, 0x4D, \
74 0x32, 0x77, 0x33, 0x4E, 0x67, 0x3D, 0x3D, 0x3A, 0x59, 0x7A, 0x56, 0x78, 0x63, 0x48, 0x64, 0x70, 0x61, \
75 0x6D, 0x30, 0x34, 0x59, 0x57, 0x45, 0x34, 0x5A, 0x48, 0x6B, 0x79, 0x4D, 0x67, 0x3D, 0x3D \
76 }
77 #define ONLINERESPONSE \
78 { \
79 0x30, 0x64, 0x6E, 0x5A, 0x32, 0x4E, 0x57, 0x74, 0x76, 0x4D, 0x47, 0x34, 0x34, 0x4E, 0x6A, 0x42, 0x30, 0x4D, \
80 0x32, 0x77, 0x33, 0x4E, 0x67, 0x3D, 0x3D, 0x3A, 0x59, 0x7A, 0x56, 0x78, 0x63, 0x48, 0x64, 0x70, 0x61, \
81 0x6D, 0x30, 0x34, 0x59, 0x57, 0x45, 0x34, 0x5A, 0x48, 0x6B, 0x79, 0x4D, 0x67, 0x3D, 0x3D \
82 }
83
84 #define CHECK_RETURN(cond, ret) \
85 do { \
86 if ((cond)) { \
87 OH_LOG_ERROR(LOG_APP, "testCL_failed ,ret = %{public}d", ret); \
88 return ret; \
89 } \
90 } while (0)
91 #define CHECK_GOTO(expressions, label) \
92 do { \
93 if (expressions) { \
94 OH_LOG_ERROR(LOG_APP, "testCL_goto"); \
95 goto label; \
96 } \
97 } while (0)
98 #define CHECK_PRINTF(cond, ret) \
99 do { \
100 if (cond) { \
101 OH_LOG_ERROR(LOG_APP, "testCL_check failed ,ret = %{public}d", ret); \
102 } \
103 } while (0)
104
splitStringToIntArray(char * str,uint8_t * temp)105 void splitStringToIntArray(char *str, uint8_t *temp) {
106 int i = 0;
107 char *p = str;
108 char *q;
109 while ((q = strchr(p, ',')) != NULL) {
110 temp[i++] = atoi(p);
111 p = q + 1;
112 }
113 temp[i] = atoi(p);
114 }
judge_uuid(void)115 static const char *judge_uuid(void) {
116 bool isSupport = OH_MediaKeySystem_IsSupported(CLEAR_PLAY);
117 if (isSupport == 1) {
118 return CLEAR_PLAY;
119 } else {
120 return WISE_PLAY;
121 }
122 }
123
getHttp(const std::string & url,unsigned char * request,uint32_t requestLen,unsigned char * response,int32_t * responseLen,uint32_t timeout)124 int getHttp(const std::string &url, unsigned char *request, uint32_t requestLen, unsigned char *response,
125 int32_t *responseLen, uint32_t timeout) {
126 int ret = -1;
127 struct addrinfo hints, *res, *p;
128 int sockfd;
129 struct sockaddr_in server_addr;
130 char host[1024], port[10];
131 std::string path;
132
133 // Parse URL
134 std::string::size_type pos1 = url.find("://");
135 std::string::size_type pos2 = url.find('/', pos1 + 3);
136
137 if (pos1 == std::string::npos) {
138 pos1 = 0;
139 } else {
140 pos1 += 3;
141 }
142
143 std::string::size_type pos3 = url.find(':', pos1);
144 if (pos3 != std::string::npos && pos3 < pos2) {
145 strncpy(host, url.substr(pos1, pos3 - pos1).c_str(), sizeof(host));
146 strncpy(port, url.substr(pos3 + 1, pos2 - pos3 - 1).c_str(), sizeof(port));
147 } else {
148 strncpy(host, url.substr(pos1, pos2 - pos1).c_str(), sizeof(host));
149 strncpy(port, "80", sizeof(port)); // default HTTP port
150 }
151
152 if (pos2 == std::string::npos) {
153 path = "/";
154 } else {
155 path = url.substr(pos2);
156 }
157
158 // Prepare HTTP request
159 std::string requestStr = "POST " + path +
160 " HTTP/1.1\r\n"
161 "Host: " +
162 host +
163 "\r\n"
164 "Content-Type: application/json\r\n"
165 "Content-Length: " +
166 std::to_string(requestLen) +
167 "\r\n"
168 "Connection: close\r\n\r\n";
169 std::string requestData(reinterpret_cast<char *>(request), requestLen);
170 requestStr += requestData;
171
172 // Set up hints for getaddrinfo
173 memset(&hints, 0, sizeof hints);
174 hints.ai_family = AF_UNSPEC;
175 hints.ai_socktype = SOCK_STREAM;
176
177 // Get address info
178 if (getaddrinfo(host, port, &hints, &res) != 0) {
179 std::cerr << "getaddrinfo failed" << std::endl;
180 return -1;
181 }
182
183 // Create socket
184 for (p = res; p != nullptr; p = p->ai_next) {
185 sockfd = socket(p->ai_family, p->ai_socktype, p->ai_protocol);
186 if (sockfd == -1) {
187 continue;
188 }
189 if (connect(sockfd, p->ai_addr, p->ai_addrlen) != -1) {
190 break;
191 }
192 close(sockfd);
193 }
194
195 if (p == nullptr) {
196 std::cerr << "failed to connect" << std::endl;
197 freeaddrinfo(res);
198 return -1;
199 }
200
201 freeaddrinfo(res);
202
203 // Send HTTP request
204 if (send(sockfd, requestStr.c_str(), requestStr.length(), 0) == -1) {
205 std::cerr << "send failed" << std::endl;
206 close(sockfd);
207 return -1;
208 }
209
210 // Receive HTTP response
211 std::string responseStr;
212 char buffer[4096];
213 ssize_t bytesReceived;
214 while ((bytesReceived = recv(sockfd, buffer, sizeof(buffer) - 1, 0)) > 0) {
215 buffer[bytesReceived] = '\0';
216 responseStr += buffer;
217 }
218
219 if (bytesReceived == -1) {
220 std::cerr << "recv failed" << std::endl;
221 close(sockfd);
222 return -1;
223 }
224
225 close(sockfd);
226
227 // Parse response
228 std::string::size_type bodyStart = responseStr.find("\r\n\r\n");
229 if (bodyStart == std::string::npos) {
230 std::cerr << "Invalid response format" << std::endl;
231 return -1;
232 }
233
234 std::string responseBody = responseStr.substr(bodyStart + 4);
235 *responseLen = responseBody.size();
236 memcpy(response, responseBody.c_str(), *responseLen);
237
238 return 0;
239 }
240
getCertificate(MediaKeySystem * drmKeySystem)241 static int getCertificate(MediaKeySystem *drmKeySystem) {
242 uint8_t requestData[DATA_BUFF_LEN] = {0};
243 int32_t requestLen = DATA_BUFF_LEN;
244 char defaultURLData[DATA_BUFF_LEN] = {0};
245 int32_t defaultURLDataLen = DATA_BUFF_LEN;
246 uint8_t responseData[DATA_BUFF_LEN] = {0};
247 int32_t responseDataLen_out = DATA_BUFF_LEN;
248 Drm_ErrCode ret2 = OH_MediaKeySystem_GenerateKeySystemRequest(drmKeySystem, requestData, &requestLen,
249 defaultURLData, defaultURLDataLen);
250 CHECK_RETURN((ret2 != DRM_ERR_OK), -2);
251 if (strcmp(judge_uuid(), CLEAR_PLAY) != 0) {
252 int getRet = getHttp(defaultURLData, requestData, (uint32_t)requestLen, responseData, &responseDataLen_out,
253 HTTP_TIMEOUT); // 设备证书申请
254 CHECK_RETURN((getRet != 0), getRet);
255 } else {
256 memset(responseData, 0x55, DATA_BLUESPONSE_LEN);
257 responseDataLen_out = DATA_BLUESPONSE_LEN;
258 }
259 Drm_ErrCode ret3 = OH_MediaKeySystem_ProcessKeySystemResponse(drmKeySystem, responseData, responseDataLen_out);
260 CHECK_RETURN((ret3 != DRM_ERR_OK), -3);
261 return 0;
262 }
getLicense(MediaKeySession * mediaKeySession,char isOnline,uint8_t * keydata,int32_t * keylen)263 static int getLicense(MediaKeySession *mediaKeySession, char isOnline, uint8_t *keydata, int32_t *keylen) {
264 DRM_MediaKeyRequestInfo requestInfo;
265 memset(&requestInfo, 0, sizeof(DRM_MediaKeyRequestInfo));
266 if (isOnline) {
267 requestInfo.type = MEDIA_KEY_TYPE_ONLINE;
268 } else {
269 requestInfo.type = MEDIA_KEY_TYPE_OFFLINE;
270 }
271 unsigned char passhData[DATA_REQUESTINFO_LEN] = REQUESTINFODATA;
272 memcpy(requestInfo.initData, passhData, DATA_REQUESTINFO_LEN);
273 requestInfo.initDataLen = DATA_REQUESTINFO_LEN;
274
275 requestInfo.optionsCount = 1;
276 memcpy(requestInfo.mimeType, (char *)"video/mp4", sizeof("video/mp4"));
277 memcpy(requestInfo.optionName[0], (char *)"optionalDataName", sizeof("optionalDataName"));
278 memcpy(requestInfo.optionData[0], (char *)"optionalDataValue", sizeof("optionalDataValue"));
279 DRM_MediaKeyRequest requestData;
280 memset(&requestData, 0, sizeof(DRM_MediaKeyRequest));
281 Drm_ErrCode ret1 = OH_MediaKeySession_GenerateMediaKeyRequest(mediaKeySession, &requestInfo, &requestData);
282 CHECK_RETURN((ret1 != DRM_ERR_OK), -1);
283
284 uint8_t keyId[DATA_BUFF_LEN] = {0};
285 int32_t keyIdLen = DATA_BUFF_LEN;
286 uint8_t responseData[DATA_BUFF_LEN] = {0};
287 int32_t responseLen = DATA_BUFF_LEN;
288 if (strcmp(judge_uuid(), CLEAR_PLAY) == 0) {
289 if (isOnline) {
290 uint8_t blue_onData[DATA_BLUESPONSE_LEN] = ONLINERESPONSE;
291 memcpy(responseData, blue_onData, sizeof(blue_onData));
292 } else {
293 uint8_t blue_offData[DATA_BLUESPONSE_LEN] = OFFLINERESPONSE;
294 memcpy(responseData, blue_offData, sizeof(blue_offData));
295 }
296 responseLen = DATA_BLUESPONSE_LEN;
297 } else {
298 int ret3 = getHttp(URL_LICENSE, requestData.data, (uint32_t)requestData.dataLen, responseData, &responseLen,
299 HTTP_TIMEOUT);
300 CHECK_RETURN(ret3 != 0, ret3);
301 }
302 Drm_ErrCode ret2 =
303 OH_MediaKeySession_ProcessMediaKeyResponse(mediaKeySession, responseData, responseLen, keyId, &keyIdLen);
304 CHECK_RETURN((ret2 != DRM_ERR_OK), -2);
305 memcpy(keydata, keyId, keyIdLen);
306 memcpy(keylen, &keyIdLen, sizeof(int32_t));
307 return 0;
308 }
getOnLicResponseData(MediaKeySession * mediaKeySession,uint8_t * response,int32_t * responselen)309 static void getOnLicResponseData(MediaKeySession *mediaKeySession, uint8_t *response, int32_t *responselen) {
310 DRM_MediaKeyRequestInfo requestInfo;
311 memset(&requestInfo, 0, sizeof(DRM_MediaKeyRequestInfo));
312 unsigned char testData[DATA_REQUESTINFO_LEN] = REQUESTINFODATA;
313 requestInfo.type = MEDIA_KEY_TYPE_ONLINE;
314 requestInfo.initDataLen = sizeof(testData);
315 requestInfo.optionsCount = 1;
316 memcpy(requestInfo.mimeType, (char *)"video/mp4", sizeof("video/mp4"));
317 memcpy(requestInfo.initData, testData, sizeof(testData));
318 memcpy(requestInfo.optionName[0], (char *)"optionalDataName", sizeof("optionalDataName"));
319 memcpy(requestInfo.optionData[0], (char *)"optionalDataValue", sizeof("optionalDataValue"));
320 DRM_MediaKeyRequest requestData;
321 memset(&requestData, 0, sizeof(DRM_MediaKeyRequest));
322 Drm_ErrCode ret6 = OH_MediaKeySession_GenerateMediaKeyRequest(mediaKeySession, &requestInfo, &requestData);
323 CHECK_PRINTF((ret6 != DRM_ERR_OK), ret6);
324 uint8_t responseData[DATA_BUFF_LEN] = {0};
325 int32_t responseLenOut = DATA_BUFF_LEN;
326 int ret3 = getHttp(URL_LICENSE, requestData.data, (uint32_t)requestData.dataLen, responseData, &responseLenOut,
327 HTTP_TIMEOUT);
328 CHECK_PRINTF((ret3 != 0), ret3);
329 memcpy(response, responseData, responseLenOut);
330 memcpy(responselen, &responseLenOut, sizeof(int32_t));
331 return;
332 }
GetOfflineMediaKeyIds(napi_env env,napi_callback_info info)333 static napi_value GetOfflineMediaKeyIds(napi_env env, napi_callback_info info) {
334 napi_value result;
335 const char *backString = "GetOfflineMediaKeyIds failed";
336 MediaKeySystem *drmKeySystem = nullptr;
337 Drm_ErrCode ret1 = OH_MediaKeySystem_Create(judge_uuid(), &drmKeySystem);
338 if (ret1 != DRM_ERR_OK) {
339 OH_LOG_ERROR(LOG_APP, "testCL_GetOfflineMediaKeyIds failed!");
340 napi_create_string_utf8(env, backString, strlen(backString), &result);
341 return result;
342 }
343 DRM_OfflineMediakeyIdArray mediaKeyIds;
344 memset(&mediaKeyIds, 0x00, sizeof(DRM_OfflineMediakeyIdArray));
345 Drm_ErrCode ret2 = OH_MediaKeySystem_GetOfflineMediaKeyIds(drmKeySystem, &mediaKeyIds);
346 if ((ret2 == DRM_ERR_OK) && (mediaKeyIds.idsCount != 0)) {
347 Drm_ErrCode ret5 = OH_MediaKeySystem_Destroy(drmKeySystem);
348 if (ret5 != DRM_ERR_OK) {
349 OH_LOG_ERROR(LOG_APP, "testCL_GetOfflineMediaKeyIds failed!");
350 napi_create_string_utf8(env, backString, strlen(backString), &result);
351 return result;
352 }
353 napi_create_string_utf8(env, (const char *)&mediaKeyIds.ids[0][0], (size_t)mediaKeyIds.idsLen[0], &result);
354 return result;
355 } else {
356 OH_LOG_DEBUG(LOG_APP, "testCL_generate offline key!");
357 DRM_ContentProtectionLevel level = CONTENT_PROTECTION_LEVEL_SW_CRYPTO;
358 MediaKeySession *drmKeySession = nullptr;
359 Drm_ErrCode ret3 = OH_MediaKeySystem_CreateMediaKeySession(drmKeySystem, &level, &drmKeySession);
360 if (ret3 != DRM_ERR_OK) {
361 OH_MediaKeySystem_Destroy(drmKeySystem);
362 OH_LOG_ERROR(LOG_APP, "testCL_GetOfflineMediaKeyIds failed!");
363 napi_create_string_utf8(env, backString, strlen(backString), &result);
364 return result;
365 }
366 uint8_t keyData[DATA_BUFF_LEN] = {0};
367 int32_t keyDataLen = DATA_BUFF_LEN;
368 int licRet = getLicense(drmKeySession, LICENSE_OFFLINE, keyData, &keyDataLen);
369 Drm_ErrCode ret4 = OH_MediaKeySession_Destroy(drmKeySession);
370 Drm_ErrCode ret5 = OH_MediaKeySystem_Destroy(drmKeySystem);
371 if ((ret5 != DRM_ERR_OK) || (ret4 != DRM_ERR_OK) || (licRet != 0)) {
372 OH_LOG_ERROR(LOG_APP, "testCL_GetOfflineMediaKeyIds failed!");
373 napi_create_string_utf8(env, backString, strlen(backString), &result);
374 return result;
375 }
376 napi_create_string_utf8(env, (const char *)keyData, (size_t)keyDataLen, &result);
377 return result;
378 }
379 }
GetCertificateStatus(napi_env env,napi_callback_info info)380 static napi_value GetCertificateStatus(napi_env env, napi_callback_info info) {
381 napi_value result;
382 size_t argc = 2;
383 napi_value args[2] = {nullptr};
384
385 Drm_ErrCode ret = DRM_ERR_INVALID_VAL;
386 MediaKeySystem *drmKeySystem = nullptr;
387 ret = OH_MediaKeySystem_Create(judge_uuid(), &drmKeySystem);
388 if (ret != DRM_ERR_OK) {
389 napi_create_int32(env, DRM_ERR_INVALID_VAL, &result);
390 return result;
391 }
392 DRM_CertificateStatus status = CERT_STATUS_UNAVAILABLE;
393 ret = OH_MediaKeySystem_GetCertificateStatus(drmKeySystem, &status);
394 if (ret != DRM_ERR_OK) {
395 napi_create_int32(env, DRM_ERR_INVALID_VAL, &result);
396 return result;
397 }
398 ret = OH_MediaKeySystem_Destroy(drmKeySystem);
399 if (ret != DRM_ERR_OK) {
400 napi_create_int32(env, DRM_ERR_INVALID_VAL, &result);
401 return result;
402 }
403 napi_create_int32(env, status, &result);
404 return result;
405 }
Test_KeySystemSupported(napi_env env,napi_callback_info info)406 static napi_value Test_KeySystemSupported(napi_env env, napi_callback_info info) {
407 bool isSupport;
408 napi_value res;
409 size_t argc = 2;
410 napi_value args[2] = {nullptr};
411 size_t uuidLen = 0;
412 char *uuid = nullptr;
413 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
414 napi_get_value_string_utf8(env, args[0], nullptr, 0, &uuidLen);
415 uuid = new char[uuidLen + 1];
416 napi_get_value_string_utf8(env, args[0], uuid, uuidLen + 1, &uuidLen);
417
418 char *uuid_ptr = nullptr;
419 if (strcmp(uuid, " ") != 0) {
420 uuid_ptr = uuid;
421 }
422 isSupport = OH_MediaKeySystem_IsSupported(uuid_ptr);
423 napi_create_int32(env, isSupport, &res);
424 return res;
425 }
Test_KeySystemSupported2(napi_env env,napi_callback_info info)426 static napi_value Test_KeySystemSupported2(napi_env env, napi_callback_info info) {
427 bool isSupport;
428 napi_value res;
429 size_t argc = 2;
430 napi_value args[2] = {nullptr};
431 size_t uuidLen = 0;
432 char *uuid = nullptr;
433 size_t mineTypeLen = 0;
434 char *mineType = nullptr;
435
436 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
437 napi_get_value_string_utf8(env, args[0], nullptr, 0, &uuidLen);
438 uuid = new char[uuidLen + 1];
439 napi_get_value_string_utf8(env, args[0], uuid, uuidLen + 1, &uuidLen);
440
441 napi_get_value_string_utf8(env, args[1], nullptr, 0, &mineTypeLen);
442 mineType = new char[mineTypeLen + 1];
443 napi_get_value_string_utf8(env, args[1], mineType, mineTypeLen + 1, &mineTypeLen);
444 char *uuid_ptr = nullptr;
445 if (strcmp(uuid, " ") != 0) {
446 uuid_ptr = uuid;
447 }
448 char *mineType_ptr = nullptr;
449 if (strcmp(mineType, " ") != 0) {
450 mineType_ptr = mineType;
451 }
452 isSupport = OH_MediaKeySystem_IsSupported2(uuid_ptr, mineType_ptr);
453 napi_create_int32(env, isSupport, &res);
454 return res;
455 }
Test_KeySystemSupported3(napi_env env,napi_callback_info info)456 static napi_value Test_KeySystemSupported3(napi_env env, napi_callback_info info) {
457 bool isSupport;
458 napi_value res;
459 size_t argc = 3;
460 napi_value args[3] = {nullptr};
461 size_t uuidLen = 0;
462 char *uuid = nullptr;
463 size_t mineTypeLen = 0;
464 char *mineType = nullptr;
465 int32_t securityLevel;
466
467 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
468 napi_get_value_string_utf8(env, args[0], nullptr, 0, &uuidLen);
469 uuid = new char[uuidLen + 1];
470 napi_get_value_string_utf8(env, args[0], uuid, uuidLen + 1, &uuidLen);
471
472 napi_get_value_string_utf8(env, args[1], nullptr, 0, &mineTypeLen);
473 mineType = new char[mineTypeLen + 1];
474 napi_get_value_string_utf8(env, args[1], mineType, mineTypeLen + 1, &mineTypeLen);
475
476 napi_get_value_int32(env, args[2], &securityLevel);
477 char *uuid_ptr = nullptr;
478 if (strcmp(uuid, " ") != 0) {
479 uuid_ptr = uuid;
480 }
481 char *mineType_ptr = nullptr;
482 if (strcmp(mineType, " ") != 0) {
483 mineType_ptr = mineType;
484 }
485 isSupport = OH_MediaKeySystem_IsSupported3(uuid_ptr, mineType_ptr, (DRM_ContentProtectionLevel)securityLevel);
486 napi_create_int32(env, isSupport, &res);
487 return res;
488 }
Test_MediaKeySystem_Create(napi_env env,napi_callback_info info)489 static napi_value Test_MediaKeySystem_Create(napi_env env, napi_callback_info info) {
490 napi_value result;
491 Drm_ErrCode ret = DRM_ERR_INVALID_VAL;
492 size_t argc = 2;
493 napi_value args[2] = {nullptr};
494 size_t uuidLen = 0;
495 char *uuid = nullptr;
496 size_t inStringLen = 0;
497 char *inString = nullptr;
498
499 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
500 napi_get_value_string_utf8(env, args[0], nullptr, 0, &uuidLen);
501 uuid = new char[uuidLen + 1];
502 napi_get_value_string_utf8(env, args[0], uuid, uuidLen + 1, &uuidLen);
503
504 napi_get_value_string_utf8(env, args[1], nullptr, 0, &inStringLen);
505 inString = new char[inStringLen + 1];
506 napi_get_value_string_utf8(env, args[1], inString, inStringLen + 1, &inStringLen);
507 const char *uuid_ptr = nullptr;
508 MediaKeySystem *drmKeySystem = nullptr;
509 Drm_ErrCode ret1 = DRM_ERR_INVALID_VAL;
510 if (strcmp(uuid, " ") != 0) {
511 uuid_ptr = uuid;
512 }
513 if (strcmp(inString, " ") != 0) {
514 ret1 = OH_MediaKeySystem_Create(uuid_ptr, &drmKeySystem);
515 } else {
516 ret1 = OH_MediaKeySystem_Create(uuid_ptr, nullptr);
517 }
518 if (ret1 == DRM_ERR_OK) {
519 Drm_ErrCode ret2 = OH_MediaKeySystem_Destroy(drmKeySystem);
520 ret = (ret2 == DRM_ERR_OK) ? DRM_ERR_OK : DRM_ERR_INVALID_VAL;
521 }
522 napi_create_int32(env, ret, &result);
523 return result;
524 }
Test_MediaKeySystem_SetConfigurationString(napi_env env,napi_callback_info info)525 static napi_value Test_MediaKeySystem_SetConfigurationString(napi_env env, napi_callback_info info) {
526 napi_value result;
527 Drm_ErrCode ret = DRM_ERR_INVALID_VAL;
528 size_t argc = 3;
529 napi_value args[3] = {nullptr};
530 size_t stringLen = 0;
531 char *inString = nullptr;
532 size_t valueLen = 0;
533 char *inValue = nullptr;
534 MediaKeySystem *drmKeySystem = nullptr;
535 size_t sysLen = 0;
536 char *inSys = nullptr;
537 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
538 napi_get_value_string_utf8(env, args[0], nullptr, 0, &sysLen);
539 inSys = new char[sysLen + 1];
540 napi_get_value_string_utf8(env, args[0], inSys, sysLen + 1, &sysLen);
541 napi_get_value_string_utf8(env, args[1], nullptr, 0, &stringLen);
542 inString = new char[stringLen + 1];
543 napi_get_value_string_utf8(env, args[1], inString, stringLen + 1, &stringLen);
544 napi_get_value_string_utf8(env, args[2], nullptr, 0, &valueLen);
545 inValue = new char[valueLen + 1];
546 napi_get_value_string_utf8(env, args[2], inValue, valueLen + 1, &valueLen);
547
548 Drm_ErrCode ret1 = OH_MediaKeySystem_Create(judge_uuid(), &drmKeySystem);
549 MediaKeySystem *system_ptr = nullptr;
550 if (strcmp(inSys, " ") != 0) {
551 system_ptr = drmKeySystem;
552 }
553 char *name_ptr = nullptr;
554 if (strcmp(inString, " ")) {
555 name_ptr = inString;
556 }
557 char *value_ptr = nullptr;
558 if (strcmp(inValue, " ")) {
559 value_ptr = inValue;
560 }
561 Drm_ErrCode ret2 = OH_MediaKeySystem_SetConfigurationString(system_ptr, name_ptr, value_ptr);
562 char outBuff[DATA_BUFF_LEN] = {0};
563 int32_t outBuffLen = DATA_BUFF_LEN;
564
565 if (ret2 == DRM_ERR_OK) {
566 Drm_ErrCode ret4 = OH_MediaKeySystem_GetConfigurationString(drmKeySystem, inString, outBuff, outBuffLen);
567 if ((ret2 == DRM_ERR_OK) && (strncmp(outBuff, inValue, outBuffLen) == 0)) {
568 ret2 = DRM_ERR_OK;
569 } else {
570 ret2 = DRM_ERR_INVALID_VAL;
571 }
572 }
573 Drm_ErrCode ret3 = OH_MediaKeySystem_Destroy(drmKeySystem);
574 if (ret1 == DRM_ERR_OK && ret2 == DRM_ERR_OK && ret3 == DRM_ERR_OK) {
575 ret = DRM_ERR_OK;
576 } else {
577 ret = DRM_ERR_INVALID_VAL;
578 }
579 napi_create_int32(env, ret, &result);
580 return result;
581 }
Test_MediaKeySystem_GetConfigurationString(napi_env env,napi_callback_info info)582 static napi_value Test_MediaKeySystem_GetConfigurationString(napi_env env, napi_callback_info info) {
583 napi_value result;
584 Drm_ErrCode ret = DRM_ERR_INVALID_VAL;
585 size_t argc = 4;
586 napi_value args[4] = {nullptr};
587 size_t sysLen = 0;
588 char *inSys = nullptr;
589 size_t configNameLen = 0;
590 char *configName = nullptr;
591 size_t valueLen = 0;
592 char *inValue = nullptr;
593 int32_t outValueLen = 0;
594
595 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
596 napi_get_value_string_utf8(env, args[0], nullptr, 0, &sysLen);
597 inSys = new char[sysLen + 1];
598 napi_get_value_string_utf8(env, args[0], inSys, sysLen + 1, &sysLen);
599 napi_get_value_string_utf8(env, args[1], nullptr, 0, &configNameLen);
600 configName = new char[configNameLen + 1];
601 napi_get_value_string_utf8(env, args[1], configName, configNameLen + 1, &configNameLen);
602 napi_get_value_string_utf8(env, args[2], nullptr, 0, &valueLen);
603 inValue = new char[valueLen + 1];
604 napi_get_value_string_utf8(env, args[2], inValue, valueLen + 1, &valueLen);
605 napi_get_value_int32(env, args[3], &outValueLen);
606
607 MediaKeySystem *drmKeySystem = nullptr;
608 Drm_ErrCode ret1 = OH_MediaKeySystem_Create(judge_uuid(), &drmKeySystem);
609
610 const char *set_val = "test";
611 Drm_ErrCode ret2 = DRM_ERR_OK;
612 if ((0 == strcmp(judge_uuid(), CLEAR_PLAY)) && (0 != strcmp(configName, " "))) {
613 ret2 = OH_MediaKeySystem_SetConfigurationString(drmKeySystem, configName, set_val);
614 }
615 MediaKeySystem *system_ptr = nullptr;
616 if (strcmp(inSys, " ") != 0) {
617 system_ptr = drmKeySystem;
618 }
619 char *name_ptr = nullptr;
620 if (0 != strcmp(configName, " ")) {
621 name_ptr = configName;
622 }
623 char *outValue = nullptr;
624 char outBuff[DATA_BUFF_LEN];
625 if (0 != strncmp(inValue, " ", valueLen)) {
626 outValue = outBuff;
627 }
628 Drm_ErrCode ret3 = OH_MediaKeySystem_GetConfigurationString(system_ptr, name_ptr, outValue, outValueLen);
629
630 if (ret3 == DRM_ERR_OK) {
631 if (strcmp(judge_uuid(), CLEAR_PLAY) == 0) {
632 ret3 = (strncmp(outValue, set_val, strlen(set_val)) == 0) ? DRM_ERR_OK : DRM_ERR_INVALID_VAL;
633 }
634 }
635 Drm_ErrCode ret4 = OH_MediaKeySystem_Destroy(drmKeySystem);
636 if (ret1 == DRM_ERR_OK && ret2 == DRM_ERR_OK && ret3 == DRM_ERR_OK && ret4 == DRM_ERR_OK) { //
637 ret = DRM_ERR_OK;
638 } else {
639 ret = DRM_ERR_INVALID_VAL;
640 }
641 napi_create_int32(env, ret, &result);
642 return result;
643 }
Test_MediaKeySystem_SetConfigurationByteArray(napi_env env,napi_callback_info info)644 static napi_value Test_MediaKeySystem_SetConfigurationByteArray(napi_env env, napi_callback_info info) {
645 napi_value result;
646 Drm_ErrCode ret = DRM_ERR_INVALID_VAL;
647 size_t argc = 4;
648 napi_value args[4] = {nullptr};
649 size_t stringLen = 0;
650 char *inString = nullptr;
651 size_t valueLen = 0;
652 char *inValue = nullptr;
653 size_t sysLen = 0;
654 char *inSys = nullptr;
655 MediaKeySystem *drmKeySystem = nullptr;
656
657 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
658 napi_get_value_string_utf8(env, args[0], nullptr, 0, &sysLen);
659 inSys = new char[sysLen + 1];
660 napi_get_value_string_utf8(env, args[0], inSys, sysLen + 1, &sysLen);
661 napi_get_value_string_utf8(env, args[1], nullptr, 0, &stringLen);
662 inString = new char[stringLen + 1];
663 napi_get_value_string_utf8(env, args[1], inString, stringLen + 1, &stringLen);
664 napi_get_value_string_utf8(env, args[2], nullptr, 0, &valueLen);
665 inValue = new char[valueLen + 1];
666 napi_get_value_string_utf8(env, args[2], inValue, valueLen + 1, &valueLen);
667 int32_t valueDataLen = 0;
668 napi_get_value_int32(env, args[3], &valueDataLen);
669
670 Drm_ErrCode ret1 = OH_MediaKeySystem_Create(judge_uuid(), &drmKeySystem);
671 char *name_ptr = nullptr;
672 if (0 != strncmp(inString, " ", stringLen)) {
673 name_ptr = inString;
674 }
675 uint8_t *data_ptr = nullptr;
676 if (0 != strncmp(inValue, " ", valueLen)) {
677 data_ptr = (uint8_t *)inValue;
678 }
679 MediaKeySystem *system_ptr = nullptr;
680 if (0 != strncmp(inSys, " ", sysLen)) {
681 system_ptr = drmKeySystem;
682 }
683 uint8_t outValue[DATA_BUFF_LEN] = {0};
684 int32_t outValueLen = DATA_BUFF_LEN;
685 Drm_ErrCode ret2 = OH_MediaKeySystem_SetConfigurationByteArray(system_ptr, name_ptr, data_ptr, valueDataLen);
686
687 if (ret2 == DRM_ERR_OK) {
688 Drm_ErrCode ret4 = OH_MediaKeySystem_GetConfigurationByteArray(drmKeySystem, name_ptr, outValue, &outValueLen);
689 if (ret4 == DRM_ERR_OK) {
690 ret2 = (0 == memcmp(outValue, data_ptr, valueDataLen)) ? DRM_ERR_OK : DRM_ERR_INVALID_VAL;
691 }
692 }
693 Drm_ErrCode ret3 = OH_MediaKeySystem_Destroy(drmKeySystem);
694 if (ret1 == DRM_ERR_OK && ret2 == DRM_ERR_OK && ret3 == DRM_ERR_OK) {
695 ret = DRM_ERR_OK;
696 } else {
697 ret = DRM_ERR_INVALID_VAL;
698 }
699 napi_create_int32(env, ret, &result);
700 return result;
701 }
Test_MediaKeySystem_GetConfigurationByteArray(napi_env env,napi_callback_info info)702 static napi_value Test_MediaKeySystem_GetConfigurationByteArray(napi_env env, napi_callback_info info) {
703 napi_value result;
704 Drm_ErrCode ret = DRM_ERR_INVALID_VAL;
705 size_t argc = 5;
706 napi_value args[5] = {nullptr};
707 size_t sysLen = 0;
708 char *inSys = nullptr;
709 size_t configNameLen = 0;
710 char *configName = nullptr;
711 char *value = nullptr;
712 size_t valueLen = 0;
713 size_t valueLenStringLen = 0;
714 char *valueLenString = nullptr;
715 MediaKeySystem *drmKeySystem = nullptr;
716 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
717 napi_get_value_string_utf8(env, args[0], nullptr, 0, &sysLen);
718 inSys = new char[sysLen + 1];
719 napi_get_value_string_utf8(env, args[0], inSys, sysLen + 1, &sysLen);
720
721 napi_get_value_string_utf8(env, args[1], nullptr, 0, &configNameLen);
722 configName = new char[configNameLen + 1];
723 napi_get_value_string_utf8(env, args[1], configName, configNameLen + 1, &configNameLen);
724
725 napi_get_value_string_utf8(env, args[2], nullptr, 0, &valueLen);
726 value = new char[valueLen + 1];
727 napi_get_value_string_utf8(env, args[2], value, valueLen + 1, &valueLen);
728
729 napi_get_value_string_utf8(env, args[3], nullptr, 0, &valueLenStringLen);
730 valueLenString = new char[valueLenStringLen + 1];
731 napi_get_value_string_utf8(env, args[3], valueLenString, valueLenStringLen + 1, &valueLenStringLen);
732
733 Drm_ErrCode ret2 = DRM_ERR_OK;
734 Drm_ErrCode ret1 = OH_MediaKeySystem_Create(judge_uuid(), &drmKeySystem);
735 if (0 == strcmp(judge_uuid(), CLEAR_PLAY)) {
736 uint8_t valueData[10];
737 memset(valueData, 0x55, 10);
738 ret2 = OH_MediaKeySystem_SetConfigurationByteArray(drmKeySystem, configName, valueData,
739 10); // 蓝区没有默认值,需要先set;
740 }
741 MediaKeySystem *system_ptr = nullptr;
742 if (0 != strcmp(inSys, " ")) {
743 system_ptr = drmKeySystem;
744 }
745 const char *configName_ptr = nullptr;
746 if (0 != strcmp(configName, " ")) {
747 configName_ptr = configName;
748 }
749 uint8_t *value_ptr = nullptr;
750 uint8_t valueData[DATA_BUFF_LEN] = {0};
751 if (0 != strcmp(value, " ")) {
752 value_ptr = valueData;
753 }
754 int32_t *valueLen_ptr = nullptr;
755 int32_t valueLenData = DATA_BUFF_LEN;
756 if (0 != strcmp(valueLenString, " ")) {
757 valueLen_ptr = &valueLenData;
758 }
759 Drm_ErrCode ret3 = OH_MediaKeySystem_GetConfigurationByteArray(system_ptr, configName_ptr, value_ptr, valueLen_ptr);
760 Drm_ErrCode ret4 = OH_MediaKeySystem_Destroy(drmKeySystem);
761 if (ret1 == DRM_ERR_OK && ret2 == DRM_ERR_OK && ret3 == DRM_ERR_OK && ret4 == DRM_ERR_OK) {
762 ret = DRM_ERR_OK;
763 } else {
764 ret = DRM_ERR_INVALID_VAL;
765 }
766 napi_create_int32(env, ret, &result);
767 return result;
768 }
Test_MediaKeySystem_GetStatistics(napi_env env,napi_callback_info info)769 static napi_value Test_MediaKeySystem_GetStatistics(napi_env env, napi_callback_info info) {
770 napi_value result;
771 size_t argc = 2;
772 napi_value args[2] = {nullptr};
773 size_t sysLen = 0;
774 char *inSys = nullptr;
775 size_t statisticsLen = 0;
776 char *statistics = nullptr;
777 Drm_ErrCode ret = DRM_ERR_INVALID_VAL;
778
779 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
780 napi_get_value_string_utf8(env, args[0], nullptr, 0, &sysLen);
781 inSys = new char[sysLen + 1];
782 napi_get_value_string_utf8(env, args[0], inSys, sysLen + 1, &sysLen);
783 napi_get_value_string_utf8(env, args[1], nullptr, 0, &statisticsLen);
784 statistics = new char[statisticsLen + 1];
785 napi_get_value_string_utf8(env, args[1], statistics, statisticsLen + 1, &statisticsLen);
786
787 MediaKeySystem *drmKeySystem = nullptr;
788 Drm_ErrCode ret1 = OH_MediaKeySystem_Create(judge_uuid(), &drmKeySystem);
789
790 MediaKeySystem *system_ptr = nullptr;
791 if (strcmp(inSys, " ") != 0) {
792 system_ptr = drmKeySystem;
793 }
794 DRM_Statistics *statisticsData_ptr = nullptr;
795 DRM_Statistics statisticsData;
796 memset(&statisticsData, 0x00, sizeof(DRM_Statistics));
797 if (strcmp(statistics, " ")) {
798 statisticsData_ptr = &statisticsData;
799 }
800 Drm_ErrCode ret2 = OH_MediaKeySystem_GetStatistics(system_ptr, statisticsData_ptr);
801 OH_LOG_DEBUG(LOG_APP, "testCL_statisticsCount = %{public}d", statisticsData.statisticsCount);
802 for (int i = 0; i < statisticsData.statisticsCount; i++) {
803 OH_LOG_DEBUG(LOG_APP, "testCL_statisticsName[%{public}d]: %{public}s", i, statisticsData.statisticsName[i]);
804 OH_LOG_DEBUG(LOG_APP, "testCL_Description[%{public}d]: %{public}s", i, statisticsData.statisticsDescription[i]);
805 }
806
807 Drm_ErrCode ret3 = OH_MediaKeySystem_Destroy(drmKeySystem);
808 if (ret1 == DRM_ERR_OK && ret2 == DRM_ERR_OK && ret3 == DRM_ERR_OK) {
809 ret = DRM_ERR_OK;
810 } else {
811 ret = DRM_ERR_INVALID_VAL;
812 }
813 napi_create_int32(env, ret, &result);
814 return result;
815 }
Test_MediaKeySystem_GetMaxContentProtectionLevel(napi_env env,napi_callback_info info)816 static napi_value Test_MediaKeySystem_GetMaxContentProtectionLevel(napi_env env, napi_callback_info info) {
817 napi_value result;
818 size_t argc = 3;
819 napi_value args[3] = {nullptr};
820 size_t sysLen = 0;
821 char *inSys = nullptr;
822 size_t levelLen = 0;
823 char *inLevel = nullptr;
824 Drm_ErrCode ret = DRM_ERR_INVALID_VAL;
825 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
826 napi_get_value_string_utf8(env, args[0], nullptr, 0, &sysLen);
827 inSys = new char[sysLen + 1];
828 napi_get_value_string_utf8(env, args[0], inSys, sysLen + 1, &sysLen);
829 napi_get_value_string_utf8(env, args[1], nullptr, 0, &levelLen);
830 inLevel = new char[levelLen + 1];
831 napi_get_value_string_utf8(env, args[1], inLevel, levelLen + 1, &levelLen);
832
833 MediaKeySystem *drmKeySystem = nullptr;
834 Drm_ErrCode ret1 = OH_MediaKeySystem_Create(judge_uuid(), &drmKeySystem);
835 MediaKeySystem *system_ptr = nullptr;
836 if (strcmp(inSys, " ") != 0) {
837 system_ptr = drmKeySystem;
838 }
839 DRM_ContentProtectionLevel securityLevel = CONTENT_PROTECTION_LEVEL_UNKNOWN;
840 DRM_ContentProtectionLevel *level_ptr = nullptr;
841 if (strcmp(inLevel, " ") != 0) {
842 level_ptr = &securityLevel;
843 }
844 Drm_ErrCode ret2 = OH_MediaKeySystem_GetMaxContentProtectionLevel(system_ptr, level_ptr);
845 OH_LOG_DEBUG(LOG_APP, "testCL_MaxContentProtectionLevel is %{public}d", securityLevel);
846 Drm_ErrCode ret3 = OH_MediaKeySystem_Destroy(drmKeySystem);
847 if (ret1 == DRM_ERR_OK && ret2 == DRM_ERR_OK && ret3 == DRM_ERR_OK) {
848 ret = DRM_ERR_OK;
849 } else {
850 ret = DRM_ERR_INVALID_VAL;
851 }
852 napi_create_int32(env, ret, &result);
853 return result;
854 }
GetMaxContentProtectionLevel(napi_env env,napi_callback_info info)855 static napi_value GetMaxContentProtectionLevel(napi_env env, napi_callback_info info) {
856 napi_value result;
857 size_t argc = 3;
858 napi_value args[3] = {nullptr};
859 size_t sysLen = 0;
860 char *inSys = nullptr;
861 size_t levelLen = 0;
862 char *inLevel = nullptr;
863 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
864 napi_get_value_string_utf8(env, args[0], nullptr, 0, &sysLen);
865 inSys = new char[sysLen + 1];
866 napi_get_value_string_utf8(env, args[0], inSys, sysLen + 1, &sysLen);
867 napi_get_value_string_utf8(env, args[1], nullptr, 0, &levelLen);
868 inLevel = new char[levelLen + 1];
869 napi_get_value_string_utf8(env, args[1], inLevel, levelLen + 1, &levelLen);
870
871 MediaKeySystem *drmKeySystem = nullptr;
872 Drm_ErrCode ret1 = OH_MediaKeySystem_Create(judge_uuid(), &drmKeySystem);
873 OH_LOG_DEBUG(LOG_APP, "testCL_MediaKeySystem_Create result is %{public}d", ret1);
874 MediaKeySystem *system_ptr = nullptr;
875 if (strcmp(inSys, " ") != 0) {
876 system_ptr = drmKeySystem;
877 }
878 DRM_ContentProtectionLevel securityLevel = CONTENT_PROTECTION_LEVEL_UNKNOWN;
879 DRM_ContentProtectionLevel *level_ptr = nullptr;
880 if (strcmp(inLevel, " ") != 0) {
881 level_ptr = &securityLevel;
882 }
883 Drm_ErrCode ret2 = OH_MediaKeySystem_GetMaxContentProtectionLevel(system_ptr, level_ptr);
884 OH_LOG_DEBUG(LOG_APP, "testCL_GetMaxContentProtectionLevel result is %{public}d", ret2);
885 OH_LOG_DEBUG(LOG_APP, "testCL_MaxContentProtectionLevel is %{public}d", securityLevel);
886 Drm_ErrCode ret3 = OH_MediaKeySystem_Destroy(drmKeySystem);
887 OH_LOG_DEBUG(LOG_APP, "testCL_MediaKeySystem_Destroy result is %{public}d", ret3);
888 napi_create_int32(env, (int32_t)securityLevel, &result);
889 return result;
890 }
Test_CreateMediaKeySession(napi_env env,napi_callback_info info)891 static napi_value Test_CreateMediaKeySession(napi_env env, napi_callback_info info) {
892 napi_value result;
893 size_t argc = 3;
894 napi_value args[3] = {nullptr};
895 size_t sysLen = 0;
896 char *inSys = nullptr;
897 int32_t level = 0;
898 size_t sessionLen = 0;
899 char *inSession = nullptr;
900 Drm_ErrCode ret = DRM_ERR_INVALID_VAL;
901 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
902 napi_get_value_string_utf8(env, args[0], nullptr, 0, &sysLen);
903 inSys = new char[sysLen + 1];
904 napi_get_value_string_utf8(env, args[0], inSys, sysLen + 1, &sysLen);
905 napi_get_value_int32(env, args[1], &level);
906 napi_get_value_string_utf8(env, args[2], nullptr, 0, &sessionLen);
907 inSession = new char[sessionLen + 1];
908 napi_get_value_string_utf8(env, args[2], inSession, sessionLen + 1, &sessionLen);
909
910 MediaKeySystem *drmKeySystem = nullptr;
911 Drm_ErrCode ret1 = OH_MediaKeySystem_Create(judge_uuid(), &drmKeySystem);
912 MediaKeySystem *system_ptr = nullptr;
913 if ((0 != strcmp(inSys, " "))) {
914 system_ptr = drmKeySystem;
915 }
916 DRM_ContentProtectionLevel *level_ptr = nullptr;
917 if (level != -1) {
918 level_ptr = (DRM_ContentProtectionLevel *)&level;
919 }
920 MediaKeySession *drmKeySession = nullptr;
921 MediaKeySession **session_ptr = nullptr;
922 if (0 != strcmp(inSession, " ")) {
923 session_ptr = &drmKeySession;
924 }
925 Drm_ErrCode ret2 = OH_MediaKeySystem_CreateMediaKeySession(system_ptr, level_ptr, session_ptr);
926 Drm_ErrCode ret3 = DRM_ERR_OK;
927 if (ret2 == DRM_ERR_OK && (drmKeySession != nullptr)) {
928 Drm_ErrCode ret3 = OH_MediaKeySession_Destroy(drmKeySession);
929 }
930 Drm_ErrCode ret4 = OH_MediaKeySystem_Destroy(drmKeySystem);
931 if (ret1 == DRM_ERR_OK && ret2 == DRM_ERR_OK && ret3 == DRM_ERR_OK && ret4 == DRM_ERR_OK) {
932 ret = DRM_ERR_OK;
933 } else {
934 ret = DRM_ERR_INVALID_VAL;
935 }
936 napi_create_int32(env, ret, &result);
937 return result;
938 }
Test_MediaKeySystem_GenerateKeySystemRequest(napi_env env,napi_callback_info info)939 static napi_value Test_MediaKeySystem_GenerateKeySystemRequest(napi_env env, napi_callback_info info) {
940 napi_value result;
941 size_t argc = 5;
942 napi_value args[5] = {nullptr};
943 size_t sysLen = 0;
944 char *inSys = nullptr;
945 size_t requestStringLen = 0;
946 char *inRequestString = nullptr;
947 size_t requestLenStingLen = 0;
948 char *requestLenSting = nullptr;
949 size_t defaultUrlStingLen = 0;
950 char *defaultUrlSting = nullptr;
951 int32_t defaultUrlLen = 0;
952 Drm_ErrCode ret = DRM_ERR_INVALID_VAL;
953
954 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
955 napi_get_value_string_utf8(env, args[0], nullptr, 0, &sysLen);
956 inSys = new char[sysLen + 1];
957 napi_get_value_string_utf8(env, args[0], inSys, sysLen + 1, &sysLen);
958
959 napi_get_value_string_utf8(env, args[1], nullptr, 0, &requestStringLen);
960 inRequestString = new char[requestStringLen + 1];
961 napi_get_value_string_utf8(env, args[1], inRequestString, requestStringLen + 1, &requestStringLen);
962
963 napi_get_value_string_utf8(env, args[2], nullptr, 0, &requestLenStingLen);
964 requestLenSting = new char[requestLenStingLen + 1];
965 napi_get_value_string_utf8(env, args[2], requestLenSting, requestLenStingLen + 1, &requestLenStingLen);
966
967 napi_get_value_string_utf8(env, args[3], nullptr, 0, &defaultUrlStingLen);
968 defaultUrlSting = new char[defaultUrlStingLen + 1];
969 napi_get_value_string_utf8(env, args[3], defaultUrlSting, defaultUrlStingLen + 1, &defaultUrlStingLen);
970
971 napi_get_value_int32(env, args[4], &defaultUrlLen);
972
973 MediaKeySystem *drmKeySystem = nullptr;
974 Drm_ErrCode ret1 = OH_MediaKeySystem_Create(judge_uuid(), &drmKeySystem);
975 MediaKeySystem *system_ptr = nullptr;
976 if ((0 != strcmp(inSys, " "))) {
977 system_ptr = drmKeySystem;
978 }
979 uint8_t *request_ptr = nullptr;
980 uint8_t requestData[DATA_BUFF_LEN] = {0};
981 if ((0 != strcmp(inRequestString, " "))) {
982 request_ptr = requestData;
983 }
984 int32_t *requestLen_ptr = nullptr;
985 int32_t outRequestLen = DATA_BUFF_LEN;
986 if ((0 != strcmp(requestLenSting, " "))) {
987 requestLen_ptr = &outRequestLen;
988 }
989 char *urlData_ptr = nullptr;
990 char urlData[DATA_BUFF_LEN] = {0};
991 int32_t UrlLen = DATA_BUFF_LEN;
992 if ((0 != strcmp(defaultUrlSting, " "))) {
993 urlData_ptr = urlData;
994 }
995 if ((defaultUrlLen != 0) && (defaultUrlLen != -1)) {
996 defaultUrlLen = UrlLen;
997 }
998 Drm_ErrCode ret2 =
999 OH_MediaKeySystem_GenerateKeySystemRequest(system_ptr, request_ptr, requestLen_ptr, urlData_ptr, defaultUrlLen);
1000 Drm_ErrCode ret3 = OH_MediaKeySystem_Destroy(drmKeySystem);
1001 if (ret1 == DRM_ERR_OK && ret2 == DRM_ERR_OK && ret3 == DRM_ERR_OK) {
1002 ret = DRM_ERR_OK;
1003 } else {
1004 ret = DRM_ERR_INVALID_VAL;
1005 }
1006 napi_create_int32(env, ret, &result);
1007 return result;
1008 }
Test_MediaKeySystem_ProcessKeySystemResponse(napi_env env,napi_callback_info info)1009 static napi_value Test_MediaKeySystem_ProcessKeySystemResponse(napi_env env, napi_callback_info info) {
1010 napi_value result;
1011 size_t argc = 3;
1012 napi_value args[3] = {nullptr};
1013 size_t inSys_len = 0;
1014 char *inSys = nullptr;
1015 size_t response_len = 0;
1016 char *response = nullptr;
1017 Drm_ErrCode ret = DRM_ERR_INVALID_VAL;
1018 int32_t responseDataLen = 0;
1019 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1020 napi_get_value_string_utf8(env, args[0], nullptr, 0, &inSys_len);
1021 inSys = new char[inSys_len + 1];
1022 napi_get_value_string_utf8(env, args[0], inSys, inSys_len + 1, &inSys_len);
1023 napi_get_value_string_utf8(env, args[1], nullptr, 0, &response_len);
1024 response = new char[response_len + 1];
1025 napi_get_value_string_utf8(env, args[1], response, response_len + 1, &response_len);
1026 napi_get_value_int32(env, args[2], &responseDataLen);
1027
1028 MediaKeySystem *drmKeySystem = nullptr;
1029 Drm_ErrCode ret1 = OH_MediaKeySystem_Create(judge_uuid(), &drmKeySystem);
1030 MediaKeySystem *system_ptr = nullptr;
1031 if ((0 != strcmp(inSys, " "))) {
1032 system_ptr = drmKeySystem;
1033 }
1034 uint8_t *responseData_ptr = nullptr;
1035 uint8_t requestData[DATA_BUFF_LEN] = {0};
1036 int32_t requestLen = DATA_BUFF_LEN;
1037 char defaultURLData[DATA_BUFF_LEN] = {0};
1038 int32_t defaultURLDataLen = DATA_BUFF_LEN;
1039 uint8_t responseData[DATA_BUFF_LEN] = {0};
1040 int32_t responseDataLen_out = DATA_BUFF_LEN;
1041
1042 if (strncmp(response, "genResponse", response_len) == 0) {
1043 Drm_ErrCode ret3 = OH_MediaKeySystem_GenerateKeySystemRequest(drmKeySystem, requestData, &requestLen,
1044 defaultURLData, defaultURLDataLen);
1045 if (ret3 == DRM_ERR_OK) {
1046 int getRet = getHttp(defaultURLData, requestData, (uint32_t)requestLen, responseData, &responseDataLen_out,
1047 HTTP_TIMEOUT); // 设备证书申请
1048 if (getRet != 0) {
1049 OH_LOG_ERROR(LOG_APP, "testCL_getHttp failed ,Ret = %{public}d", getRet);
1050 }
1051 responseData_ptr = responseData;
1052 if (responseDataLen > 0) {
1053 responseDataLen = responseDataLen_out;
1054 }
1055 }
1056 } else if (0 != strncmp(response, " ", response_len)) {
1057 responseData_ptr = (uint8_t *)response;
1058 OH_LOG_DEBUG(LOG_APP, "testCL_input responseData");
1059 } else {
1060 responseData_ptr = nullptr;
1061 OH_LOG_DEBUG(LOG_APP, "testCL_responseData is nullptr");
1062 }
1063 Drm_ErrCode ret4 = OH_MediaKeySystem_ProcessKeySystemResponse(system_ptr, responseData_ptr, responseDataLen);
1064 Drm_ErrCode ret5 = OH_MediaKeySystem_Destroy(drmKeySystem);
1065 if (ret1 == DRM_ERR_OK && ret4 == DRM_ERR_OK && ret5 == DRM_ERR_OK) {
1066 ret = DRM_ERR_OK;
1067 } else {
1068 ret = DRM_ERR_INVALID_VAL;
1069 }
1070 napi_create_int32(env, ret, &result);
1071 return result;
1072 }
Test_MediaKeySystem_GetOfflineMediaKeyIds(napi_env env,napi_callback_info info)1073 static napi_value Test_MediaKeySystem_GetOfflineMediaKeyIds(napi_env env, napi_callback_info info) {
1074 napi_value result;
1075 size_t argc = 3;
1076 napi_value args[3] = {nullptr};
1077 size_t sysLen = 0;
1078 char *inSys = nullptr;
1079 size_t keyIdsLen = 0;
1080 char *keyIds = nullptr;
1081 size_t keySourceLen = 0;
1082 char *keySource = nullptr;
1083 Drm_ErrCode ret = DRM_ERR_INVALID_VAL;
1084 Drm_ErrCode ret3 = DRM_ERR_INVALID_VAL;
1085 MediaKeySystem *drmKeySystem = nullptr;
1086 MediaKeySession *drmKeySession = nullptr;
1087 DRM_ContentProtectionLevel contentProtectionLevel = CONTENT_PROTECTION_LEVEL_SW_CRYPTO;
1088
1089 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1090 napi_get_value_string_utf8(env, args[0], nullptr, 0, &sysLen);
1091 inSys = new char[sysLen + 1];
1092 napi_get_value_string_utf8(env, args[0], inSys, sysLen + 1, &sysLen);
1093 napi_get_value_string_utf8(env, args[1], nullptr, 0, &keyIdsLen);
1094 keyIds = new char[keyIdsLen + 1];
1095 napi_get_value_string_utf8(env, args[1], keyIds, keyIdsLen + 1, &keyIdsLen);
1096 napi_get_value_string_utf8(env, args[2], nullptr, 0, &keySourceLen);
1097 keySource = new char[keySourceLen + 1];
1098 napi_get_value_string_utf8(env, args[2], keySource, keySourceLen + 1, &keySourceLen);
1099
1100 Drm_ErrCode ret1 = OH_MediaKeySystem_Create(judge_uuid(), &drmKeySystem);
1101 Drm_ErrCode ret2 = OH_MediaKeySystem_CreateMediaKeySession(drmKeySystem, &contentProtectionLevel, &drmKeySession);
1102 uint8_t keyData[DATA_BUFF_LEN] = {0};
1103 int32_t keyDataLen = DATA_BUFF_LEN;
1104 int reslicense = getLicense(drmKeySession, LICENSE_OFFLINE, keyData, &keyDataLen); // 确保生成离线license
1105 if (reslicense != 0) {
1106 OH_LOG_ERROR(LOG_APP, "testCL_get offline license failed!");
1107 }
1108 MediaKeySystem *system_ptr = nullptr;
1109 if ((0 != strcmp(inSys, " "))) {
1110 system_ptr = drmKeySystem;
1111 }
1112 DRM_OfflineMediakeyIdArray *offlineMediaKeyIds_ptr = nullptr;
1113 DRM_OfflineMediakeyIdArray mediaKeyIds;
1114 memset(&mediaKeyIds, 0, sizeof(DRM_OfflineMediakeyIdArray));
1115 if ((0 != strcmp(keyIds, " "))) {
1116 offlineMediaKeyIds_ptr = &mediaKeyIds;
1117 }
1118 ret3 = OH_MediaKeySystem_GetOfflineMediaKeyIds(system_ptr, offlineMediaKeyIds_ptr);
1119 if (ret3 == DRM_ERR_OK) {
1120 ret3 = (mediaKeyIds.idsCount != 0) ? DRM_ERR_OK : DRM_ERR_INVALID_VAL;
1121 OH_LOG_DEBUG(LOG_APP, "testCL_offline mediaKeyIds count is %{public}d", mediaKeyIds.idsCount);
1122 for (int i = 0; i < mediaKeyIds.idsCount;
1123 i++) { // 与./data/vendor/mediakeysystem/chinadrm/license.dat中keyid(十六进制)一致
1124 OH_LOG_DEBUG(LOG_APP, "testCL_offline mediaKeyIds[%{public}d] is %{public}s", i, mediaKeyIds.ids[i]);
1125 }
1126 }
1127 Drm_ErrCode ret4 = OH_MediaKeySession_Destroy(drmKeySession);
1128 Drm_ErrCode ret5 = OH_MediaKeySystem_Destroy(drmKeySystem);
1129
1130 if (ret1 == DRM_ERR_OK && ret2 == DRM_ERR_OK && ret3 == DRM_ERR_OK && ret4 == DRM_ERR_OK && ret5 == DRM_ERR_OK) {
1131 ret = DRM_ERR_OK;
1132 } else {
1133 ret = DRM_ERR_INVALID_VAL;
1134 }
1135 napi_create_int32(env, ret, &result);
1136 return result;
1137 }
Test_MediaKeySystem_GetOfflineMediaKeyStatus(napi_env env,napi_callback_info info)1138 static napi_value Test_MediaKeySystem_GetOfflineMediaKeyStatus(napi_env env, napi_callback_info info) {
1139 napi_value result;
1140 size_t argc = 5;
1141 napi_value args[5] = {nullptr};
1142 size_t sysLen = 0;
1143 char *inSys = nullptr;
1144 size_t keyIdStringLen = 0;
1145 char *keyIdString = nullptr;
1146 int32_t offlineMediaKeyIdLen = 0;
1147 size_t statusStringLen = 0;
1148 char *statusString = nullptr;
1149 int32_t expectStatus;
1150 Drm_ErrCode ret = DRM_ERR_INVALID_VAL;
1151
1152 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1153 napi_get_value_string_utf8(env, args[0], nullptr, 0, &sysLen);
1154 inSys = new char[sysLen + 1];
1155 napi_get_value_string_utf8(env, args[0], inSys, sysLen + 1, &sysLen);
1156 napi_get_value_string_utf8(env, args[1], nullptr, 0, &keyIdStringLen);
1157 keyIdString = new char[keyIdStringLen + 1];
1158 napi_get_value_string_utf8(env, args[1], keyIdString, keyIdStringLen + 1, &keyIdStringLen);
1159 napi_get_value_int32(env, args[2], &offlineMediaKeyIdLen);
1160 napi_get_value_string_utf8(env, args[3], nullptr, 0, &statusStringLen);
1161 statusString = new char[statusStringLen + 1];
1162 napi_get_value_string_utf8(env, args[3], statusString, statusStringLen + 1, &statusStringLen);
1163 napi_get_value_int32(env, args[4], &expectStatus);
1164
1165 MediaKeySystem *drmKeySystem = nullptr;
1166 Drm_ErrCode ret1 = OH_MediaKeySystem_Create(judge_uuid(), &drmKeySystem);
1167 DRM_ContentProtectionLevel level = CONTENT_PROTECTION_LEVEL_SW_CRYPTO;
1168 MediaKeySession *drmKeySession = nullptr;
1169 Drm_ErrCode ret2 = OH_MediaKeySystem_CreateMediaKeySession(drmKeySystem, &level, &drmKeySession);
1170 uint8_t *keyId_ptr = nullptr;
1171 uint8_t keyData[DATA_BUFF_LEN] = {0};
1172 int32_t keyDataLen = DATA_BUFF_LEN;
1173 if (strncmp(keyIdString, "genKey", keyIdStringLen) == 0) {
1174 getLicense(drmKeySession, LICENSE_OFFLINE, keyData, &keyDataLen); // 确保生成离线license
1175 keyId_ptr = keyData;
1176 if (offlineMediaKeyIdLen > 0) {
1177 offlineMediaKeyIdLen = keyDataLen;
1178 }
1179 } else if (strncmp(keyIdString, " ", keyIdStringLen) != 0) {
1180 keyId_ptr = (uint8_t *)keyIdString;
1181 } else {
1182 keyId_ptr = nullptr;
1183 }
1184 MediaKeySystem *system_ptr = nullptr;
1185 if ((0 != strncmp(inSys, " ", sysLen))) {
1186 system_ptr = drmKeySystem;
1187 }
1188 DRM_OfflineMediaKeyStatus status = OFFLINE_MEDIA_KEY_STATUS_UNKNOWN;
1189 DRM_OfflineMediaKeyStatus *status_ptr = nullptr;
1190 if ((0 != strncmp(statusString, " ", statusStringLen))) {
1191 status_ptr = &status;
1192 }
1193 Drm_ErrCode ret4 =
1194 OH_MediaKeySystem_GetOfflineMediaKeyStatus(system_ptr, keyId_ptr, offlineMediaKeyIdLen, status_ptr);
1195 Drm_ErrCode ret5 = DRM_ERR_INVALID_VAL;
1196 if (ret4 == DRM_ERR_OK) { // 获取到license
1197 ret5 = ((int32_t)status == expectStatus) ? DRM_ERR_OK : DRM_ERR_INVALID_VAL;
1198 }
1199 Drm_ErrCode ret6 = OH_MediaKeySession_Destroy(drmKeySession);
1200 Drm_ErrCode ret7 = OH_MediaKeySystem_Destroy(drmKeySystem);
1201 if (ret1 == DRM_ERR_OK && ret2 == DRM_ERR_OK && ret4 == DRM_ERR_OK && ret6 == DRM_ERR_OK && ret7 == DRM_ERR_OK) {
1202 ret = DRM_ERR_OK;
1203 } else {
1204 ret = DRM_ERR_INVALID_VAL;
1205 }
1206 napi_create_int32(env, ret, &result);
1207 return result;
1208 }
Test_MediaKeySystem_ClearOfflineMediaKeys(napi_env env,napi_callback_info info)1209 static napi_value Test_MediaKeySystem_ClearOfflineMediaKeys(napi_env env, napi_callback_info info) {
1210 napi_value result;
1211 size_t argc = 3;
1212 napi_value args[3] = {nullptr};
1213 char *inSys = nullptr;
1214 size_t sysLen = 0;
1215 char *keyIdString = nullptr;
1216 size_t keyIdStringLen = 0;
1217 int32_t offlineMediaKeyIdLen = 0;
1218 Drm_ErrCode ret = DRM_ERR_INVALID_VAL;
1219 MediaKeySystem *drmKeySystem = nullptr;
1220
1221 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1222 napi_get_value_string_utf8(env, args[0], nullptr, 0, &sysLen);
1223 inSys = new char[sysLen + 1];
1224 napi_get_value_string_utf8(env, args[0], inSys, sysLen + 1, &sysLen);
1225 napi_get_value_string_utf8(env, args[1], nullptr, 0, &keyIdStringLen);
1226 keyIdString = new char[keyIdStringLen + 1];
1227 napi_get_value_string_utf8(env, args[1], keyIdString, keyIdStringLen + 1, &keyIdStringLen);
1228 napi_get_value_int32(env, args[2], &offlineMediaKeyIdLen);
1229
1230 DRM_ContentProtectionLevel level = CONTENT_PROTECTION_LEVEL_SW_CRYPTO;
1231 MediaKeySession *mediaKeySession = nullptr;
1232 Drm_ErrCode ret1 = OH_MediaKeySystem_Create(judge_uuid(), &drmKeySystem);
1233 Drm_ErrCode ret2 = OH_MediaKeySystem_CreateMediaKeySession(drmKeySystem, &level, &mediaKeySession);
1234
1235 MediaKeySystem *system_ptr = nullptr;
1236 if ((0 != strcmp(inSys, " "))) {
1237 system_ptr = drmKeySystem;
1238 }
1239 uint8_t *keyId_ptr = nullptr;
1240 uint8_t keyData[DATA_BUFF_LEN] = {0};
1241 int32_t keyDataLen = DATA_BUFF_LEN;
1242 if (strncmp(keyIdString, "genKey", keyIdStringLen) == 0) {
1243 getLicense(mediaKeySession, LICENSE_OFFLINE, keyData, &keyDataLen); // 确保生成离线license
1244 keyId_ptr = keyData;
1245 if (offlineMediaKeyIdLen > 0) {
1246 offlineMediaKeyIdLen = keyDataLen;
1247 }
1248 } else if ((0 != strcmp(keyIdString, " "))) {
1249 keyId_ptr = (uint8_t *)keyIdString;
1250 } else {
1251 keyId_ptr = nullptr;
1252 }
1253 Drm_ErrCode ret3 = OH_MediaKeySystem_ClearOfflineMediaKeys(system_ptr, keyId_ptr, offlineMediaKeyIdLen);
1254 DRM_OfflineMediaKeyStatus status = OFFLINE_MEDIA_KEY_STATUS_USABLE;
1255 if (ret3 == DRM_ERR_OK) {
1256 Drm_ErrCode ret6 =
1257 OH_MediaKeySystem_GetOfflineMediaKeyStatus(system_ptr, keyId_ptr, offlineMediaKeyIdLen, &status);
1258 if (ret6 == DRM_ERR_OK) {
1259 ret3 = (status != OFFLINE_MEDIA_KEY_STATUS_USABLE) ? DRM_ERR_OK : DRM_ERR_INVALID_VAL;
1260 }
1261 }
1262 Drm_ErrCode ret4 = OH_MediaKeySession_Destroy(mediaKeySession);
1263 Drm_ErrCode ret5 = OH_MediaKeySystem_Destroy(drmKeySystem);
1264 if (ret1 == DRM_ERR_OK && ret2 == DRM_ERR_OK && ret3 == DRM_ERR_OK && ret4 == DRM_ERR_OK && ret5 == DRM_ERR_OK) {
1265 ret = DRM_ERR_OK;
1266 } else {
1267 ret = DRM_ERR_INVALID_VAL;
1268 }
1269 napi_create_int32(env, ret, &result);
1270 return result;
1271 }
Test_MediaKeySystem_GetCertificateStatus(napi_env env,napi_callback_info info)1272 static napi_value Test_MediaKeySystem_GetCertificateStatus(napi_env env, napi_callback_info info) {
1273 napi_value result;
1274 size_t argc = 2;
1275 napi_value args[2] = {nullptr};
1276 size_t sysLen = 0;
1277 char *inSys = nullptr;
1278 size_t StatusLen = 0;
1279 char *Status = nullptr;
1280 Drm_ErrCode ret = DRM_ERR_INVALID_VAL;
1281 MediaKeySystem *drmKeySystem = nullptr;
1282
1283 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1284 napi_get_value_string_utf8(env, args[0], nullptr, 0, &sysLen);
1285 inSys = new char[sysLen + 1];
1286 napi_get_value_string_utf8(env, args[0], inSys, sysLen + 1, &sysLen);
1287 napi_get_value_string_utf8(env, args[1], nullptr, 0, &StatusLen);
1288 Status = new char[StatusLen + 1];
1289 napi_get_value_string_utf8(env, args[1], Status, StatusLen + 1, &StatusLen);
1290
1291 Drm_ErrCode ret1 = OH_MediaKeySystem_Create(judge_uuid(), &drmKeySystem);
1292 MediaKeySystem *system_ptr = nullptr;
1293 if ((0 != strcmp(inSys, " "))) {
1294 system_ptr = drmKeySystem;
1295 }
1296 DRM_CertificateStatus status = CERT_STATUS_UNAVAILABLE;
1297 DRM_CertificateStatus *cerStatus_ptr = nullptr;
1298 if ((0 != strcmp(Status, " "))) {
1299 cerStatus_ptr = &status;
1300 }
1301 Drm_ErrCode ret2 = OH_MediaKeySystem_GetCertificateStatus(system_ptr, cerStatus_ptr);
1302 if (ret2 == DRM_ERR_OK) {
1303 OH_LOG_DEBUG(LOG_APP, "testCL_CertificateStatus is %{public}d", status);
1304 }
1305 Drm_ErrCode ret3 = OH_MediaKeySystem_Destroy(drmKeySystem);
1306 if (ret1 == DRM_ERR_OK && ret2 == DRM_ERR_OK && ret3 == DRM_ERR_OK) {
1307 ret = DRM_ERR_OK;
1308 } else {
1309 ret = DRM_ERR_INVALID_VAL;
1310 }
1311 napi_create_int32(env, ret, &result);
1312 return result;
1313 }
Test_MediaKeySystem_Destroy(napi_env env,napi_callback_info info)1314 static napi_value Test_MediaKeySystem_Destroy(napi_env env, napi_callback_info info) {
1315 napi_value result;
1316 Drm_ErrCode ret = DRM_ERR_INVALID_VAL;
1317 size_t argc = 2;
1318 napi_value args[2] = {nullptr};
1319 size_t inSysLen = 0;
1320 char *inSys = nullptr;
1321 int32_t count = 0;
1322 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1323 napi_get_value_string_utf8(env, args[0], nullptr, 0, &inSysLen);
1324 inSys = new char[inSysLen + 1];
1325 napi_get_value_string_utf8(env, args[0], inSys, inSysLen + 1, &inSysLen);
1326 napi_get_value_int32(env, args[1], &count);
1327
1328 MediaKeySystem *drmKeySystem = nullptr;
1329 Drm_ErrCode ret1 = OH_MediaKeySystem_Create(judge_uuid(), &drmKeySystem);
1330 MediaKeySystem *system_ptr = nullptr;
1331 if (strcmp(inSys, " ") != 0) {
1332 system_ptr = drmKeySystem;
1333 }
1334 Drm_ErrCode ret2 = DRM_ERR_INVALID_VAL;
1335 for (int i = 0; i < count; i++) {
1336 ret2 = OH_MediaKeySystem_Destroy(system_ptr);
1337 }
1338 if (ret1 == DRM_ERR_OK && ret2 == DRM_ERR_OK) {
1339 ret = DRM_ERR_OK;
1340 }
1341 napi_create_int32(env, ret, &result);
1342 return result;
1343 }
1344 uint8_t Flag_SysCallBack = 0;
TestSystemCallBack(DRM_EventType eventType,uint8_t * eventInfo,int32_t infoLen,char * extra)1345 Drm_ErrCode TestSystemCallBack(DRM_EventType eventType, uint8_t *eventInfo, int32_t infoLen, char *extra) {
1346 OH_LOG_DEBUG(LOG_APP, "testCL_Enter systemCallBack func!");
1347 Flag_SysCallBack = 1;
1348 return DRM_ERR_OK;
1349 }
Test_MediaKeySystem_SetMediaKeySystemCallback(napi_env env,napi_callback_info info)1350 static napi_value Test_MediaKeySystem_SetMediaKeySystemCallback(napi_env env, napi_callback_info info) {
1351 napi_value result;
1352 size_t argc = 2;
1353 napi_value args[2] = {nullptr};
1354 size_t inSysLen = 0;
1355 char *inSys = nullptr;
1356 Drm_ErrCode ret = DRM_ERR_INVALID_VAL;
1357
1358 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1359 napi_get_value_string_utf8(env, args[0], nullptr, 0, &inSysLen);
1360 inSys = new char[inSysLen + 1];
1361 napi_get_value_string_utf8(env, args[0], inSys, inSysLen + 1, &inSysLen);
1362
1363 MediaKeySystem *drmKeySystem = nullptr;
1364 Drm_ErrCode ret1 = OH_MediaKeySystem_Create(judge_uuid(), &drmKeySystem);
1365 MediaKeySystem *system_ptr = nullptr;
1366 if ((0 != strcmp(inSys, " "))) {
1367 system_ptr = drmKeySystem;
1368 OH_LOG_DEBUG(LOG_APP, "testCL_SetMediaKeySystemCallback system is not nullptr!");
1369 }
1370 Drm_ErrCode ret2 = OH_MediaKeySystem_SetMediaKeySystemCallback(system_ptr, TestSystemCallBack);
1371 MediaKeySession *drmKeySession = nullptr;
1372 DRM_ContentProtectionLevel level = CONTENT_PROTECTION_LEVEL_SW_CRYPTO;
1373 // Trigger callback
1374 if (strcmp(judge_uuid(), CLEAR_PLAY) == 0) { // clearpaly直接申请设备证书,触发回调
1375 int retCert = getCertificate(drmKeySystem);
1376 CHECK_PRINTF((retCert != 0), retCert);
1377 Drm_ErrCode ret4 = OH_MediaKeySystem_CreateMediaKeySession(drmKeySystem, &level, &drmKeySession);
1378 if (ret4 == DRM_ERR_OK) {
1379 Drm_ErrCode ret5 = OH_MediaKeySession_Destroy(drmKeySession);
1380 CHECK_PRINTF((ret5 != DRM_ERR_OK), ret5);
1381 }
1382 if ((ret2 == DRM_ERR_OK)) {
1383 ret2 = (Flag_SysCallBack == 1) ? DRM_ERR_OK : DRM_ERR_INVALID_VAL;
1384 }
1385 } else { // wiseplay手动删除证书,创建session失败,触发回调
1386 DRM_CertificateStatus status = CERT_STATUS_UNAVAILABLE;
1387 Drm_ErrCode ret3 = OH_MediaKeySystem_GetCertificateStatus(drmKeySystem, &status);
1388 if ((ret3 == DRM_ERR_OK) && (status != CERT_STATUS_PROVISIONED)) {
1389 Drm_ErrCode ret4 = OH_MediaKeySystem_CreateMediaKeySession(drmKeySystem, &level, &drmKeySession);
1390 if (ret4 == DRM_ERR_OK) {
1391 Drm_ErrCode ret5 = OH_MediaKeySession_Destroy(drmKeySession);
1392 CHECK_PRINTF((ret5 != DRM_ERR_OK), ret5);
1393 }
1394 if ((ret2 == DRM_ERR_OK)) {
1395 ret2 = (Flag_SysCallBack == 1) ? DRM_ERR_OK : DRM_ERR_INVALID_VAL;
1396 }
1397 int retCert = getCertificate(drmKeySystem);
1398 CHECK_PRINTF((retCert != 0), retCert);
1399 }
1400 }
1401 Drm_ErrCode ret6 = OH_MediaKeySystem_Destroy(drmKeySystem);
1402 Flag_SysCallBack = 0; // 清标志
1403 if (ret1 == DRM_ERR_OK && ret2 == DRM_ERR_OK && ret6 == DRM_ERR_OK) {
1404 ret = DRM_ERR_OK;
1405 } else {
1406 ret = DRM_ERR_INVALID_VAL;
1407 }
1408 napi_create_int32(env, ret, &result);
1409 return result;
1410 }
1411 // session
Test_MediaKeySession_GenerateMediaKeyRequest(napi_env env,napi_callback_info info)1412 static napi_value Test_MediaKeySession_GenerateMediaKeyRequest(napi_env env, napi_callback_info info) {
1413 napi_value result;
1414 size_t argc = 3;
1415 napi_value args[3] = {nullptr};
1416 size_t inSessionLen = 0;
1417 char *inSession = nullptr;
1418 size_t infoLen = 0;
1419 char *infoString = nullptr;
1420 size_t RequestLen = 0;
1421 char *request = nullptr;
1422 Drm_ErrCode ret = DRM_ERR_INVALID_VAL;
1423 MediaKeySystem *drmKeySystem = nullptr;
1424 MediaKeySession *drmKeySession = nullptr;
1425 DRM_ContentProtectionLevel sessionLevel = CONTENT_PROTECTION_LEVEL_SW_CRYPTO;
1426
1427 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1428 napi_get_value_string_utf8(env, args[0], nullptr, 0, &inSessionLen);
1429 inSession = new char[inSessionLen + 1];
1430 napi_get_value_string_utf8(env, args[0], inSession, inSessionLen + 1, &inSessionLen);
1431
1432 napi_get_value_string_utf8(env, args[1], nullptr, 0, &infoLen);
1433 infoString = new char[infoLen + 1];
1434 napi_get_value_string_utf8(env, args[1], infoString, infoLen + 1, &infoLen);
1435
1436 napi_get_value_string_utf8(env, args[2], nullptr, 0, &RequestLen);
1437 request = new char[RequestLen + 1];
1438 napi_get_value_string_utf8(env, args[2], request, RequestLen + 1, &RequestLen);
1439
1440 unsigned char testData[DATA_REQUESTINFO_LEN] = REQUESTINFODATA;
1441 unsigned char errorTestData[ERROR_DATA_REQUESTINFO_LEN] = ERRORREQUESTINFODATA;
1442 DRM_MediaKeyRequestInfo requestInfo;
1443 requestInfo.type = MEDIA_KEY_TYPE_OFFLINE;
1444 if ((0 == strcmp(infoString, "err_dataLen"))) {
1445 requestInfo.initDataLen = -1;
1446 } else {
1447 requestInfo.initDataLen = sizeof(testData);
1448 }
1449 if ((0 == strcmp(infoString, "err_data"))) {
1450 memcpy(requestInfo.initData, errorTestData, sizeof(errorTestData));
1451 } else {
1452 memcpy(requestInfo.initData, testData, sizeof(testData));
1453 }
1454 if ((0 == strcmp(infoString, "err_mineType"))) {
1455 memcpy(requestInfo.mimeType, "111/222222", sizeof("111/222222"));
1456 } else {
1457 memcpy(requestInfo.mimeType, "video/mp4", sizeof("video/mp4"));
1458 }
1459 if ((0 == strcmp(infoString, "err_optCount"))) {
1460 requestInfo.optionsCount = MAX_MEDIA_KEY_REQUEST_OPTION_COUNT << 1;
1461 for (int i = 0; i < MAX_MEDIA_KEY_REQUEST_OPTION_COUNT; i++) {
1462 strncpy(requestInfo.optionName[i], "optionalDataName", strlen("optionalDataName"));
1463 strncpy(requestInfo.optionData[i], "optionalDataValue", strlen("optionalDataValue"));
1464 }
1465 } else {
1466 requestInfo.optionsCount = OPTIONS_NUM;
1467 for (int i = 0; i < requestInfo.optionsCount; i++) {
1468 strncpy(requestInfo.optionName[i], "optionalDataName", strlen("optionalDataName"));
1469 strncpy(requestInfo.optionData[i], "optionalDataValue", strlen("optionalDataValue"));
1470 }
1471 }
1472 DRM_MediaKeyRequestInfo *requestInfo_ptr = nullptr;
1473 if ((0 != strcmp(infoString, " "))) {
1474 requestInfo_ptr = &requestInfo;
1475 }
1476 DRM_MediaKeyRequest *mediaKeyRequest_ptr = nullptr;
1477 DRM_MediaKeyRequest mediaKeyRequest;
1478 if ((0 != strcmp(request, " "))) {
1479 mediaKeyRequest_ptr = &mediaKeyRequest;
1480 }
1481 Drm_ErrCode ret1 = OH_MediaKeySystem_Create(judge_uuid(), &drmKeySystem);
1482 Drm_ErrCode ret2 = OH_MediaKeySystem_CreateMediaKeySession(drmKeySystem, &sessionLevel, &drmKeySession);
1483 MediaKeySession *session_ptr = nullptr;
1484 if ((0 != strcmp(inSession, " "))) {
1485 session_ptr = drmKeySession;
1486 }
1487 Drm_ErrCode ret3 = OH_MediaKeySession_GenerateMediaKeyRequest(session_ptr, requestInfo_ptr, mediaKeyRequest_ptr);
1488 Drm_ErrCode ret4 = OH_MediaKeySession_Destroy(drmKeySession);
1489 Drm_ErrCode ret5 = OH_MediaKeySystem_Destroy(drmKeySystem);
1490 if (ret1 == DRM_ERR_OK && ret2 == DRM_ERR_OK && ret3 == DRM_ERR_OK && ret4 == DRM_ERR_OK && ret5 == DRM_ERR_OK) {
1491 ret = DRM_ERR_OK;
1492 } else {
1493 ret = DRM_ERR_INVALID_VAL;
1494 }
1495 napi_create_int32(env, ret, &result);
1496 return result;
1497 }
Test_MediaKeySession_ProcessMediaKeyResponse(napi_env env,napi_callback_info info)1498 static napi_value Test_MediaKeySession_ProcessMediaKeyResponse(napi_env env, napi_callback_info info) {
1499 napi_value result;
1500 size_t argc = 5;
1501 napi_value args[5] = {nullptr};
1502 size_t inSessionLen = 0;
1503 char *inSession = nullptr;
1504 size_t inResponseStringLen = 0;
1505 char *inResponseString = nullptr;
1506 int32_t responseLen = 0;
1507 size_t KeyIdStringLen = 0;
1508 char *KeyIdString = nullptr;
1509 size_t KeyIdLenStringLen = 0;
1510 char *KeyIdLenString = nullptr;
1511 Drm_ErrCode ret = DRM_ERR_INVALID_VAL;
1512 DRM_ContentProtectionLevel sessionLevel = CONTENT_PROTECTION_LEVEL_SW_CRYPTO;
1513 MediaKeySystem *drmKeySystem = nullptr;
1514 MediaKeySession *drmKeySession = nullptr;
1515
1516 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1517 napi_get_value_string_utf8(env, args[0], nullptr, 0, &inSessionLen);
1518 inSession = new char[inSessionLen + 1];
1519 napi_get_value_string_utf8(env, args[0], inSession, inSessionLen + 1, &inSessionLen);
1520
1521 napi_get_value_string_utf8(env, args[1], nullptr, 0, &inResponseStringLen);
1522 inResponseString = new char[inResponseStringLen + 1];
1523 napi_get_value_string_utf8(env, args[1], inResponseString, inResponseStringLen + 1, &inResponseStringLen);
1524
1525 napi_get_value_int32(env, args[2], &responseLen);
1526
1527 napi_get_value_string_utf8(env, args[3], nullptr, 0, &KeyIdStringLen);
1528 KeyIdString = new char[KeyIdStringLen + 1];
1529 napi_get_value_string_utf8(env, args[3], KeyIdString, KeyIdStringLen + 1, &KeyIdStringLen);
1530
1531 napi_get_value_string_utf8(env, args[4], nullptr, 0, &KeyIdLenStringLen);
1532 KeyIdLenString = new char[KeyIdLenStringLen + 1];
1533 napi_get_value_string_utf8(env, args[4], KeyIdLenString, KeyIdLenStringLen + 1, &KeyIdLenStringLen);
1534
1535 Drm_ErrCode ret1 = OH_MediaKeySystem_Create(judge_uuid(), &drmKeySystem);
1536 Drm_ErrCode ret2 = OH_MediaKeySystem_CreateMediaKeySession(drmKeySystem, &sessionLevel, &drmKeySession);
1537
1538 MediaKeySession *session_ptr = nullptr;
1539 if ((0 != strcmp(inSession, " "))) {
1540 session_ptr = drmKeySession;
1541 }
1542 uint8_t *response_ptr = nullptr;
1543 uint8_t responseData[DATA_BUFF_LEN] = {0};
1544 int32_t responseLenOut = DATA_BUFF_LEN;
1545 if (strcmp(inResponseString, "genResponse") == 0) {
1546 getOnLicResponseData(drmKeySession, responseData, &responseLenOut);
1547 OH_LOG_DEBUG(LOG_APP, "testCL_responseData is %{public}s , len = %{public}d", responseData, responseLenOut);
1548 response_ptr = responseData;
1549 if (responseLen > 0) {
1550 responseLen = responseLenOut;
1551 }
1552 } else if (strcmp(inResponseString, " ") != 0) {
1553 response_ptr = (uint8_t *)malloc(inResponseStringLen);
1554 splitStringToIntArray(inResponseString, response_ptr);
1555 }
1556 uint8_t *keyIds_ptr = nullptr;
1557 uint8_t keyIdsBuff[DATA_BUFF_LEN];
1558 if ((0 != strcmp(KeyIdString, " "))) {
1559 keyIds_ptr = keyIdsBuff;
1560 }
1561 int32_t *keyIdLen_ptr = nullptr;
1562 int32_t keyIdLen = DATA_BUFF_LEN;
1563 if ((0 != strcmp(KeyIdLenString, " "))) {
1564 keyIdLen_ptr = &keyIdLen;
1565 }
1566 Drm_ErrCode ret3 =
1567 OH_MediaKeySession_ProcessMediaKeyResponse(session_ptr, response_ptr, responseLen, keyIds_ptr, keyIdLen_ptr);
1568 Drm_ErrCode ret4 = OH_MediaKeySession_Destroy(drmKeySession);
1569 Drm_ErrCode ret5 = OH_MediaKeySystem_Destroy(drmKeySystem);
1570 if ((response_ptr != nullptr) && (strcmp(inResponseString, "genResponse") != 0)) {
1571 free(response_ptr);
1572 }
1573 if (ret1 == DRM_ERR_OK && ret2 == DRM_ERR_OK && ret3 == DRM_ERR_OK && ret4 == DRM_ERR_OK && ret5 == DRM_ERR_OK) {
1574 ret = DRM_ERR_OK;
1575 } else {
1576 ret = DRM_ERR_INVALID_VAL;
1577 }
1578 napi_create_int32(env, ret, &result);
1579 return result;
1580 }
Test_MediaKeySession_CheckMediaKeyStatus(napi_env env,napi_callback_info info)1581 static napi_value Test_MediaKeySession_CheckMediaKeyStatus(napi_env env, napi_callback_info info) {
1582 napi_value result;
1583 size_t argc = 3;
1584 napi_value args[3] = {nullptr};
1585 size_t inSessionLen = 0;
1586 char *inSession = nullptr;
1587 size_t inStatusLen = 0;
1588 char *inStatus = nullptr;
1589 int32_t licenseNum = 0;
1590 Drm_ErrCode ret = DRM_ERR_INVALID_VAL;
1591 MediaKeySystem *drmKeySystem = nullptr;
1592 MediaKeySession *drmKeySession = nullptr;
1593 DRM_ContentProtectionLevel sessionLevel = CONTENT_PROTECTION_LEVEL_SW_CRYPTO;
1594
1595 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1596 napi_get_value_string_utf8(env, args[0], nullptr, 0, &inSessionLen);
1597 inSession = new char[inSessionLen + 1];
1598 napi_get_value_string_utf8(env, args[0], inSession, inSessionLen + 1, &inSessionLen);
1599 napi_get_value_string_utf8(env, args[1], nullptr, 0, &inStatusLen);
1600 inStatus = new char[inStatusLen + 1];
1601 napi_get_value_string_utf8(env, args[1], inStatus, inStatusLen + 1, &inStatusLen);
1602 napi_get_value_int32(env, args[2], &licenseNum);
1603
1604 Drm_ErrCode ret1 = OH_MediaKeySystem_Create(judge_uuid(), &drmKeySystem);
1605 Drm_ErrCode ret2 = OH_MediaKeySystem_CreateMediaKeySession(drmKeySystem, &sessionLevel, &drmKeySession);
1606
1607 uint8_t keyData[10][DATA_BUFF_LEN] = {0};
1608 int32_t keyDataLen[10] = {DATA_BUFF_LEN};
1609 for (int i = 0; i < licenseNum; i++) {
1610 int res = getLicense(drmKeySession, LICENSE_ONLINE, keyData[i], &keyDataLen[i]);
1611 CHECK_PRINTF((res != 0), res);
1612 }
1613 MediaKeySession *sessoin_ptr = nullptr;
1614 DRM_MediaKeyStatus mediaKeyStatus;
1615 memset(&mediaKeyStatus, 0, sizeof(DRM_MediaKeyStatus));
1616 DRM_MediaKeyStatus *mediaKeyStatus_ptr = nullptr;
1617 if (0 != strcmp(inSession, " ")) {
1618 sessoin_ptr = drmKeySession;
1619 }
1620 if (0 != strcmp(inStatus, " ")) {
1621 mediaKeyStatus_ptr = &mediaKeyStatus;
1622 }
1623 Drm_ErrCode ret3 = OH_MediaKeySession_CheckMediaKeyStatus(sessoin_ptr, mediaKeyStatus_ptr);
1624 if (ret3 == DRM_ERR_OK) {
1625 OH_LOG_DEBUG(LOG_APP, "testCL_CheckMediaKeyStatus, count = %{public}d", mediaKeyStatus.statusCount);
1626 for (int i = 0; i < mediaKeyStatus.statusCount; i++) {
1627 OH_LOG_DEBUG(LOG_APP, "testCL_CheckMediaKeyStatus statusName[%{public}d] is %{public}s", i,
1628 mediaKeyStatus.statusName[i]);
1629 OH_LOG_DEBUG(LOG_APP, "testCL_CheckMediaKeyStatus statusValue[%{public}d] is %{public}s", i,
1630 mediaKeyStatus.statusValue[i]);
1631 }
1632 } else {
1633 OH_LOG_ERROR(LOG_APP, "testCL_CheckMediaKeyStatus failed,ret = %{public}d", ret3);
1634 }
1635 Drm_ErrCode ret4 = OH_MediaKeySession_Destroy(drmKeySession);
1636 Drm_ErrCode ret5 = OH_MediaKeySystem_Destroy(drmKeySystem);
1637 if (ret1 == DRM_ERR_OK && ret2 == DRM_ERR_OK && ret3 == DRM_ERR_OK && ret4 == DRM_ERR_OK && ret5 == DRM_ERR_OK) {
1638 ret = DRM_ERR_OK;
1639 } else {
1640 ret = DRM_ERR_INVALID_VAL;
1641 }
1642 napi_create_int32(env, ret, &result);
1643 return result;
1644 }
Test_MediaKeySession_ClearMediaKeys(napi_env env,napi_callback_info info)1645 static napi_value Test_MediaKeySession_ClearMediaKeys(napi_env env, napi_callback_info info) {
1646 napi_value result;
1647 size_t argc = 2;
1648 napi_value args[2] = {nullptr};
1649 size_t inSessionLen = 0;
1650 char *inSession = nullptr;
1651 Drm_ErrCode ret = DRM_ERR_INVALID_VAL;
1652 DRM_ContentProtectionLevel sessionLevel = CONTENT_PROTECTION_LEVEL_SW_CRYPTO;
1653 MediaKeySystem *drmKeySystem = nullptr;
1654 MediaKeySession *drmKeySession = nullptr;
1655
1656 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1657 napi_get_value_string_utf8(env, args[0], nullptr, 0, &inSessionLen);
1658 inSession = new char[inSessionLen + 1];
1659 napi_get_value_string_utf8(env, args[0], inSession, inSessionLen + 1, &inSessionLen);
1660
1661 Drm_ErrCode ret1 = OH_MediaKeySystem_Create(judge_uuid(), &drmKeySystem);
1662 Drm_ErrCode ret2 = OH_MediaKeySystem_CreateMediaKeySession(drmKeySystem, &sessionLevel, &drmKeySession);
1663 uint8_t keyData[DATA_BUFF_LEN] = {0};
1664 int32_t keyDataLen = DATA_BUFF_LEN;
1665 getLicense(drmKeySession, LICENSE_ONLINE, keyData, &keyDataLen);
1666 DRM_MediaKeyStatus status_before;
1667 memset(&status_before, 0, sizeof(DRM_MediaKeyStatus));
1668 Drm_ErrCode ret6 = OH_MediaKeySession_CheckMediaKeyStatus(drmKeySession, &status_before);
1669 if (ret6 == DRM_ERR_OK) {
1670 for (int i = 0; i < status_before.statusCount; i++) {
1671 OH_LOG_DEBUG(LOG_APP, "testCL_before clear, statusName[%{public}d] is %{public}s", i,
1672 status_before.statusName[i]);
1673 OH_LOG_DEBUG(LOG_APP, "testCL_before clear, statusValue[%{public}d] is %{public}s", i,
1674 status_before.statusValue[i]);
1675 }
1676 } else {
1677 OH_LOG_ERROR(LOG_APP, "testCL_before ClearMediaKeys check status failed ret = %{public}d", ret6);
1678 }
1679 MediaKeySession *session_ptr = nullptr;
1680 if (0 != strcmp(inSession, " ")) {
1681 session_ptr = drmKeySession;
1682 }
1683 Drm_ErrCode ret3 = OH_MediaKeySession_ClearMediaKeys(session_ptr);
1684 DRM_MediaKeyStatus status_after;
1685 memset(&status_after, 0, sizeof(DRM_MediaKeyStatus));
1686 Drm_ErrCode ret7 = OH_MediaKeySession_CheckMediaKeyStatus(drmKeySession, &status_after);
1687 if (ret7 == DRM_ERR_OK) {
1688 for (int i = 0; i < status_after.statusCount; i++) {
1689 OH_LOG_DEBUG(LOG_APP, "testCL_after clear, statusName[%{public}d] is %{public}s", i,
1690 status_after.statusName[i]);
1691 OH_LOG_DEBUG(LOG_APP, "testCL_after clear, statusValue[%{public}d] is %{public}s", i,
1692 status_after.statusValue[i]);
1693 }
1694 } else {
1695 OH_LOG_ERROR(LOG_APP, "testCL_after ClearMediaKeys check status failed,ret = %{public}d", ret7);
1696 }
1697 Drm_ErrCode ret4 = OH_MediaKeySession_Destroy(drmKeySession);
1698 Drm_ErrCode ret5 = OH_MediaKeySystem_Destroy(drmKeySystem);
1699 if (ret1 == DRM_ERR_OK && ret2 == DRM_ERR_OK && ret3 == DRM_ERR_OK && ret4 == DRM_ERR_OK && ret5 == DRM_ERR_OK) {
1700 ret = DRM_ERR_OK;
1701 } else {
1702 ret = DRM_ERR_INVALID_VAL;
1703 }
1704 napi_create_int32(env, ret, &result);
1705 return result;
1706 }
Test_MediaKeySession_GetContentProtectionLevel(napi_env env,napi_callback_info info)1707 static napi_value Test_MediaKeySession_GetContentProtectionLevel(napi_env env, napi_callback_info info) {
1708 napi_value result;
1709 size_t argc = 2;
1710 napi_value args[2] = {nullptr};
1711 size_t inSessionLen = 0;
1712 char *inSession = nullptr;
1713 size_t inLevelLen = 0;
1714 char *inLevelSting = nullptr;
1715 Drm_ErrCode ret = DRM_ERR_INVALID_VAL;
1716 MediaKeySystem *drmKeySystem = nullptr;
1717 MediaKeySession *drmKeySession = nullptr;
1718 DRM_ContentProtectionLevel sessionLevel = CONTENT_PROTECTION_LEVEL_SW_CRYPTO;
1719
1720 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1721 napi_get_value_string_utf8(env, args[0], nullptr, 0, &inSessionLen);
1722 inSession = new char[inSessionLen + 1];
1723 napi_get_value_string_utf8(env, args[0], inSession, inSessionLen + 1, &inSessionLen);
1724
1725 napi_get_value_string_utf8(env, args[1], nullptr, 0, &inLevelLen);
1726 inLevelSting = new char[inLevelLen + 1];
1727 napi_get_value_string_utf8(env, args[1], inLevelSting, inLevelLen + 1, &inLevelLen);
1728
1729 Drm_ErrCode ret1 = OH_MediaKeySystem_Create(judge_uuid(), &drmKeySystem);
1730 Drm_ErrCode ret2 = OH_MediaKeySystem_CreateMediaKeySession(drmKeySystem, &sessionLevel, &drmKeySession);
1731 MediaKeySession *session = nullptr;
1732 if (0 != strcmp(inSession, " ")) {
1733 session = drmKeySession;
1734 }
1735 DRM_ContentProtectionLevel *contentProtectionLevel = nullptr;
1736 DRM_ContentProtectionLevel outLevel = CONTENT_PROTECTION_LEVEL_UNKNOWN;
1737 if (0 != strcmp(inLevelSting, " ")) {
1738 contentProtectionLevel = &outLevel;
1739 }
1740 Drm_ErrCode ret3 = OH_MediaKeySession_GetContentProtectionLevel(session, contentProtectionLevel);
1741 if (ret3 == DRM_ERR_OK) {
1742 ret3 = (outLevel == sessionLevel) ? DRM_ERR_OK : DRM_ERR_INVALID_VAL;
1743 }
1744 Drm_ErrCode ret4 = OH_MediaKeySession_Destroy(drmKeySession);
1745 Drm_ErrCode ret5 = OH_MediaKeySystem_Destroy(drmKeySystem);
1746 if (ret1 == DRM_ERR_OK && ret2 == DRM_ERR_OK && ret3 == DRM_ERR_OK && ret4 == DRM_ERR_OK && ret5 == DRM_ERR_OK) {
1747 ret = DRM_ERR_OK;
1748 } else {
1749 ret = DRM_ERR_INVALID_VAL;
1750 }
1751 napi_create_int32(env, ret, &result);
1752 return result;
1753 }
Test_MediaKeySession_RequireSecureDecoderModule(napi_env env,napi_callback_info info)1754 static napi_value Test_MediaKeySession_RequireSecureDecoderModule(napi_env env, napi_callback_info info) {
1755 napi_value result;
1756 size_t argc = 4;
1757 napi_value args[4] = {nullptr};
1758 size_t inSessionLen = 0;
1759 char *inSession = nullptr;
1760 size_t mimeTypeLen = 0;
1761 char *mimeType = nullptr;
1762 size_t statusLen = 0;
1763 char *statusString = nullptr;
1764 bool expectStatus = 0;
1765 Drm_ErrCode ret = DRM_ERR_INVALID_VAL;
1766 MediaKeySystem *drmKeySystem = nullptr;
1767 MediaKeySession *drmKeySession = nullptr;
1768
1769 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1770 napi_get_value_string_utf8(env, args[0], nullptr, 0, &inSessionLen);
1771 inSession = new char[inSessionLen + 1];
1772 napi_get_value_string_utf8(env, args[0], inSession, inSessionLen + 1, &inSessionLen);
1773
1774 napi_get_value_string_utf8(env, args[1], nullptr, 0, &mimeTypeLen);
1775 mimeType = new char[mimeTypeLen + 1];
1776 napi_get_value_string_utf8(env, args[1], mimeType, mimeTypeLen + 1, &mimeTypeLen);
1777
1778 napi_get_value_string_utf8(env, args[2], nullptr, 0, &statusLen);
1779 statusString = new char[statusLen + 1];
1780 napi_get_value_string_utf8(env, args[2], statusString, statusLen + 1, &statusLen);
1781
1782 napi_get_value_bool(env, args[3], &expectStatus);
1783
1784 Drm_ErrCode ret1 = OH_MediaKeySystem_Create(judge_uuid(), &drmKeySystem);
1785 DRM_ContentProtectionLevel sessionLevel = CONTENT_PROTECTION_LEVEL_UNKNOWN;
1786 MediaKeySession *session_ptr = nullptr;
1787 if (0 == strcmp(inSession, "hw")) {
1788 sessionLevel = CONTENT_PROTECTION_LEVEL_HW_CRYPTO;
1789 } else if (0 == strcmp(inSession, "sw")) {
1790 sessionLevel = CONTENT_PROTECTION_LEVEL_SW_CRYPTO;
1791 } else if (0 == strcmp(inSession, "enhanced_hw")) {
1792 sessionLevel = CONTENT_PROTECTION_LEVEL_ENHANCED_HW_CRYPTO;
1793 } else if (0 == strcmp(inSession, "max")) {
1794 sessionLevel = CONTENT_PROTECTION_LEVEL_MAX;
1795 } else {
1796 sessionLevel = CONTENT_PROTECTION_LEVEL_UNKNOWN;
1797 }
1798 OH_LOG_DEBUG(LOG_APP, "testCL_RequireSecureDecoderModule session level = %{public}d", sessionLevel);
1799 Drm_ErrCode ret2 = OH_MediaKeySystem_CreateMediaKeySession(drmKeySystem, &sessionLevel, &drmKeySession);
1800 if (0 != strcmp(inSession, " ")) {
1801 session_ptr = drmKeySession;
1802 }
1803 char *mineType_ptr = nullptr;
1804 if (0 != strcmp(mimeType, " ")) {
1805 mineType_ptr = mimeType;
1806 }
1807 bool *status_ptr = nullptr;
1808 bool outStatus = 0;
1809 if (0 != strcmp(statusString, " ")) {
1810 status_ptr = &outStatus;
1811 OH_LOG_DEBUG(LOG_APP, "testCL_RequireSecureDecoderModule, outStatus = %{public}d", outStatus);
1812 OH_LOG_DEBUG(LOG_APP, "testCL_RequireSecureDecoderModule, expectStatus = %{public}d", expectStatus);
1813 }
1814
1815 Drm_ErrCode ret3 = OH_MediaKeySession_RequireSecureDecoderModule(session_ptr, mineType_ptr, status_ptr);
1816 if (ret3 == DRM_ERR_OK) {
1817 ret3 = (outStatus == expectStatus) ? DRM_ERR_OK : DRM_ERR_INVALID_VAL;
1818 }
1819 Drm_ErrCode ret4 = OH_MediaKeySession_Destroy(drmKeySession);
1820 Drm_ErrCode ret5 = OH_MediaKeySystem_Destroy(drmKeySystem);
1821 if (ret1 == DRM_ERR_OK && ret2 == DRM_ERR_OK && ret3 == DRM_ERR_OK && ret4 == DRM_ERR_OK && ret5 == DRM_ERR_OK) {
1822 ret = DRM_ERR_OK;
1823 } else {
1824 ret = DRM_ERR_INVALID_VAL;
1825 }
1826 napi_create_int32(env, ret, &result);
1827 return result;
1828 }
1829 uint8_t Flag_EnterEventCallBack = 0;
1830 uint8_t Flag_EnterChangeCallBack = 0;
TestSessionEventCallBack(DRM_EventType eventType,uint8_t * info,int32_t infoLen,char * extra)1831 Drm_ErrCode TestSessionEventCallBack(DRM_EventType eventType, uint8_t *info, int32_t infoLen, char *extra) {
1832 OH_LOG_DEBUG(LOG_APP, "testCL_Enter SessionEventCallBack");
1833 Flag_EnterEventCallBack = 1;
1834 return DRM_ERR_OK;
1835 }
TestSessionKeyChangeCallback(DRM_KeysInfo * keysInfo,bool newKeysAvailable)1836 Drm_ErrCode TestSessionKeyChangeCallback(DRM_KeysInfo *keysInfo, bool newKeysAvailable) {
1837 OH_LOG_DEBUG(LOG_APP, "testCL_Enter SessionKeyChangeCallback");
1838 Flag_EnterChangeCallBack = 1;
1839 return DRM_ERR_OK;
1840 }
Test_MediaKeySession_SetMediaKeySessionCallback(napi_env env,napi_callback_info info)1841 static napi_value Test_MediaKeySession_SetMediaKeySessionCallback(napi_env env, napi_callback_info info) {
1842 napi_value result;
1843 size_t argc = 2;
1844 napi_value args[2] = {nullptr};
1845 size_t inSessionLen = 0;
1846 char *inSession = nullptr;
1847 size_t callBackLen = 0;
1848 char *callBack = nullptr;
1849 Drm_ErrCode ret = DRM_ERR_INVALID_VAL;
1850 MediaKeySystem *drmKeySystem = nullptr;
1851 MediaKeySession *drmKeySession = nullptr;
1852 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1853 napi_get_value_string_utf8(env, args[0], nullptr, 0, &inSessionLen);
1854 inSession = new char[inSessionLen + 1];
1855 napi_get_value_string_utf8(env, args[0], inSession, inSessionLen + 1, &inSessionLen);
1856 napi_get_value_string_utf8(env, args[1], nullptr, 0, &callBackLen);
1857 callBack = new char[callBackLen + 1];
1858 napi_get_value_string_utf8(env, args[1], callBack, callBackLen + 1, &callBackLen);
1859 Drm_ErrCode ret1 = OH_MediaKeySystem_Create(judge_uuid(), &drmKeySystem);
1860 DRM_ContentProtectionLevel sessionLevel = CONTENT_PROTECTION_LEVEL_SW_CRYPTO;
1861 Drm_ErrCode ret2 = OH_MediaKeySystem_CreateMediaKeySession(drmKeySystem, &sessionLevel, &drmKeySession);
1862 MediaKeySession_Callback SessionCallBack;
1863 SessionCallBack.eventCallback = TestSessionEventCallBack;
1864 SessionCallBack.keyChangeCallback = TestSessionKeyChangeCallback;
1865 MediaKeySession *session_ptr = nullptr;
1866 MediaKeySession_Callback *callback_ptr = nullptr;
1867 if (0 != strcmp(inSession, " ")) {
1868 session_ptr = drmKeySession;
1869 }
1870 if (0 != strcmp(callBack, " ")) {
1871 callback_ptr = &SessionCallBack;
1872 }
1873 Drm_ErrCode ret3 = OH_MediaKeySession_SetMediaKeySessionCallback(session_ptr, callback_ptr);
1874 uint8_t keyData[DATA_BUFF_LEN] = {0};
1875 int32_t keyDataLen = DATA_BUFF_LEN;
1876 int resLice = getLicense(drmKeySession, LICENSE_ONLINE, keyData, &keyDataLen); // 申请license,触发回调
1877 if ((ret3 == DRM_ERR_OK) && (resLice == 0)) {
1878 ret3 = ((Flag_EnterEventCallBack == 1) || (Flag_EnterChangeCallBack == 1)) ? DRM_ERR_OK : DRM_ERR_INVALID_VAL;
1879 }
1880 Drm_ErrCode ret4 = OH_MediaKeySession_Destroy(drmKeySession);
1881 Drm_ErrCode ret5 = OH_MediaKeySystem_Destroy(drmKeySystem);
1882 Flag_EnterEventCallBack = 0;
1883 Flag_EnterChangeCallBack = 0;
1884 if (ret1 == DRM_ERR_OK && ret3 == DRM_ERR_OK && ret2 == DRM_ERR_OK && ret4 == DRM_ERR_OK && ret5 == DRM_ERR_OK) {
1885 ret = DRM_ERR_OK;
1886 } else {
1887 ret = DRM_ERR_INVALID_VAL;
1888 }
1889 napi_create_int32(env, ret, &result);
1890 return result;
1891 }
Test_MediaKeySession_GenerateOfflineReleaseRequest(napi_env env,napi_callback_info info)1892 static napi_value Test_MediaKeySession_GenerateOfflineReleaseRequest(napi_env env, napi_callback_info info) {
1893 napi_value result;
1894 size_t argc = 5;
1895 napi_value args[5] = {nullptr};
1896 size_t inSessionLen = 0;
1897 char *inSession = nullptr;
1898 size_t KeyIdStringLen = 0;
1899 char *KeyIdString = nullptr;
1900 int32_t offlineKeyIdLen = 0;
1901 size_t requestStringLen = 0;
1902 char *requestString = nullptr;
1903 size_t requestLenStringLen = 0;
1904 char *requestLenString = nullptr;
1905 Drm_ErrCode ret = DRM_ERR_INVALID_VAL;
1906 DRM_ContentProtectionLevel sessionLevel = CONTENT_PROTECTION_LEVEL_SW_CRYPTO;
1907 MediaKeySystem *drmKeySystem = nullptr;
1908 MediaKeySession *drmKeySession = nullptr;
1909
1910 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1911 napi_get_value_string_utf8(env, args[0], nullptr, 0, &inSessionLen);
1912 inSession = new char[inSessionLen + 1];
1913 napi_get_value_string_utf8(env, args[0], inSession, inSessionLen + 1, &inSessionLen);
1914
1915 napi_get_value_string_utf8(env, args[1], nullptr, 0, &KeyIdStringLen);
1916 KeyIdString = new char[KeyIdStringLen + 1];
1917 napi_get_value_string_utf8(env, args[1], KeyIdString, KeyIdStringLen + 1, &KeyIdStringLen);
1918
1919 napi_get_value_int32(env, args[2], &offlineKeyIdLen);
1920
1921 napi_get_value_string_utf8(env, args[3], nullptr, 0, &requestStringLen);
1922 requestString = new char[requestStringLen + 1];
1923 napi_get_value_string_utf8(env, args[3], requestString, requestStringLen + 1, &requestStringLen);
1924
1925 napi_get_value_string_utf8(env, args[4], nullptr, 0, &requestLenStringLen);
1926 requestLenString = new char[requestLenStringLen + 1];
1927 napi_get_value_string_utf8(env, args[4], requestLenString, requestLenStringLen + 1, &requestLenStringLen);
1928
1929 Drm_ErrCode ret1 = OH_MediaKeySystem_Create(judge_uuid(), &drmKeySystem);
1930 Drm_ErrCode ret2 = OH_MediaKeySystem_CreateMediaKeySession(drmKeySystem, &sessionLevel, &drmKeySession);
1931 MediaKeySession *session_ptr = nullptr;
1932 if (0 != strcmp(inSession, " ")) {
1933 session_ptr = drmKeySession;
1934 }
1935 uint8_t *KeyId_ptr = nullptr;
1936 uint8_t keyData[DATA_BUFF_LEN] = {0};
1937 int32_t keyDataLen = DATA_BUFF_LEN;
1938 if (strcmp(KeyIdString, "genKey") == 0) {
1939 getLicense(drmKeySession, LICENSE_OFFLINE, keyData, &keyDataLen); // 确保生成离线license
1940 KeyId_ptr = keyData;
1941 if (offlineKeyIdLen > 0) {
1942 offlineKeyIdLen = keyDataLen;
1943 }
1944 } else if (0 != strcmp(KeyIdString, " ")) {
1945 KeyId_ptr = (uint8_t *)malloc(KeyIdStringLen);
1946 splitStringToIntArray(KeyIdString, KeyId_ptr);
1947 }
1948 uint8_t data[DATA_BUFF_LEN] = {0};
1949 uint8_t *releaseRequest_ptr = nullptr;
1950 if (0 != strcmp(requestString, " ")) {
1951 releaseRequest_ptr = data;
1952 }
1953 int32_t releaseRequestLen = DATA_BUFF_LEN;
1954 int32_t *releaseRequestLen_ptr = nullptr;
1955 if (0 != strcmp(requestLenString, " ")) {
1956 releaseRequestLen_ptr = &releaseRequestLen;
1957 }
1958 Drm_ErrCode ret3 = OH_MediaKeySession_GenerateOfflineReleaseRequest(session_ptr, KeyId_ptr, offlineKeyIdLen,
1959 releaseRequest_ptr, releaseRequestLen_ptr);
1960 Drm_ErrCode ret4 = OH_MediaKeySession_Destroy(drmKeySession);
1961 Drm_ErrCode ret5 = OH_MediaKeySystem_Destroy(drmKeySystem);
1962 if (ret1 == DRM_ERR_OK && ret2 == DRM_ERR_OK && ret3 == DRM_ERR_OK && ret4 == DRM_ERR_OK && ret5 == DRM_ERR_OK) {
1963 ret = DRM_ERR_OK;
1964 } else {
1965 ret = DRM_ERR_INVALID_VAL;
1966 }
1967 if ((KeyId_ptr != nullptr) && (strcmp(KeyIdString, "genKey") != 0)) {
1968 free(KeyId_ptr);
1969 }
1970 napi_create_int32(env, ret, &result);
1971 return result;
1972 }
Test_MediaKeySession_ProcessOfflineReleaseResponse(napi_env env,napi_callback_info info)1973 static napi_value Test_MediaKeySession_ProcessOfflineReleaseResponse(napi_env env, napi_callback_info info) {
1974 napi_value result;
1975 size_t argc = 5;
1976 napi_value args[5] = {nullptr};
1977 size_t inSessionLen = 0;
1978 char *inSession = nullptr;
1979 size_t KeyIdLen = 0;
1980 char *KeyId = nullptr;
1981 int32_t offlineKeyIdLen = 0;
1982 size_t releaseResponseLen = 0;
1983 char *releaseResponse = nullptr;
1984 int32_t responseLen = 0;
1985 Drm_ErrCode ret = DRM_ERR_INVALID_VAL;
1986 DRM_ContentProtectionLevel sessionLevel = CONTENT_PROTECTION_LEVEL_SW_CRYPTO;
1987 MediaKeySystem *drmKeySystem = nullptr;
1988 MediaKeySession *drmKeySession = nullptr;
1989
1990 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1991 napi_get_value_string_utf8(env, args[0], nullptr, 0, &inSessionLen);
1992 inSession = new char[inSessionLen + 1];
1993 napi_get_value_string_utf8(env, args[0], inSession, inSessionLen + 1, &inSessionLen);
1994 napi_get_value_string_utf8(env, args[1], nullptr, 0, &KeyIdLen);
1995 KeyId = new char[KeyIdLen + 1];
1996 napi_get_value_string_utf8(env, args[1], KeyId, KeyIdLen + 1, &KeyIdLen);
1997 napi_get_value_int32(env, args[2], &offlineKeyIdLen);
1998 napi_get_value_string_utf8(env, args[3], nullptr, 0, &releaseResponseLen);
1999 releaseResponse = new char[releaseResponseLen + 1];
2000 napi_get_value_string_utf8(env, args[3], releaseResponse, releaseResponseLen + 1, &releaseResponseLen);
2001 napi_get_value_int32(env, args[4], &responseLen);
2002 Drm_ErrCode ret1 = OH_MediaKeySystem_Create(judge_uuid(), &drmKeySystem);
2003 Drm_ErrCode ret2 = OH_MediaKeySystem_CreateMediaKeySession(drmKeySystem, &sessionLevel, &drmKeySession);
2004 MediaKeySession *session_ptr = nullptr;
2005 if (0 != strcmp(inSession, " ")) {
2006 session_ptr = drmKeySession;
2007 }
2008 uint8_t *keyId_ptr = nullptr;
2009 uint8_t keyData[DATA_BUFF_LEN] = {0};
2010 int32_t keyDataLen = DATA_BUFF_LEN;
2011 if (strcmp(KeyId, "genKey") == 0) {
2012 getLicense(drmKeySession, LICENSE_OFFLINE, keyData, &keyDataLen); // 确保生成离线license
2013 keyId_ptr = keyData;
2014 if (offlineKeyIdLen > 0) {
2015 offlineKeyIdLen = keyDataLen;
2016 }
2017 } else if (0 != strcmp(KeyId, " ")) {
2018 keyId_ptr = (uint8_t *)malloc(KeyIdLen);
2019 splitStringToIntArray(KeyId, keyId_ptr);
2020 }
2021 uint8_t *releaseResponse_ptr = nullptr;
2022 if (0 != strcmp(releaseResponse, " ")) {
2023 releaseResponse_ptr = (uint8_t *)malloc(releaseResponseLen);
2024 splitStringToIntArray(releaseResponse, releaseResponse_ptr);
2025 }
2026 Drm_ErrCode ret3 = OH_MediaKeySession_ProcessOfflineReleaseResponse(session_ptr, keyId_ptr, offlineKeyIdLen,
2027 releaseResponse_ptr, responseLen);
2028 Drm_ErrCode ret4 = OH_MediaKeySession_Destroy(drmKeySession);
2029 Drm_ErrCode ret5 = OH_MediaKeySystem_Destroy(drmKeySystem);
2030 if (ret1 == DRM_ERR_OK && ret2 == DRM_ERR_OK && ret3 == DRM_ERR_OK && ret4 == DRM_ERR_OK && ret5 == DRM_ERR_OK) {
2031 ret = DRM_ERR_OK;
2032 } else {
2033 ret = DRM_ERR_INVALID_VAL;
2034 }
2035 if (keyId_ptr != nullptr && strcmp(KeyId, "genKey") != 0) {
2036 free(keyId_ptr);
2037 }
2038 if (releaseResponse_ptr != nullptr) {
2039 free(releaseResponse_ptr);
2040 }
2041 napi_create_int32(env, ret, &result);
2042 return result;
2043 }
Test_MediaKeySession_RestoreOfflineMediaKeys(napi_env env,napi_callback_info info)2044 static napi_value Test_MediaKeySession_RestoreOfflineMediaKeys(napi_env env, napi_callback_info info) {
2045 napi_value result;
2046 size_t argc = 3;
2047 napi_value args[3] = {nullptr};
2048 size_t inSessionLen = 0;
2049 char *inSession = nullptr;
2050 size_t KeyIdLen = 0;
2051 char *KeyId = nullptr;
2052 int32_t offlineKeyIdLen = 0;
2053 Drm_ErrCode ret = DRM_ERR_INVALID_VAL;
2054 DRM_ContentProtectionLevel sessionLevel = CONTENT_PROTECTION_LEVEL_SW_CRYPTO;
2055 MediaKeySystem *drmKeySystem = nullptr;
2056 MediaKeySession *drmKeySession = nullptr;
2057
2058 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
2059 napi_get_value_string_utf8(env, args[0], nullptr, 0, &inSessionLen);
2060 inSession = new char[inSessionLen + 1];
2061 napi_get_value_string_utf8(env, args[0], inSession, inSessionLen + 1, &inSessionLen);
2062 napi_get_value_string_utf8(env, args[1], nullptr, 0, &KeyIdLen);
2063 KeyId = new char[KeyIdLen + 1];
2064 napi_get_value_string_utf8(env, args[1], KeyId, KeyIdLen + 1, &KeyIdLen);
2065 napi_get_value_int32(env, args[2], &offlineKeyIdLen);
2066 Drm_ErrCode ret1 = OH_MediaKeySystem_Create(judge_uuid(), &drmKeySystem);
2067 Drm_ErrCode ret2 = OH_MediaKeySystem_CreateMediaKeySession(drmKeySystem, &sessionLevel, &drmKeySession);
2068 uint8_t *keyId_ptr = nullptr;
2069 uint8_t keyData[DATA_BUFF_LEN] = {0};
2070 int32_t keyDataLen = DATA_BUFF_LEN;
2071 if (strcmp(KeyId, "getKey") == 0) {
2072 getLicense(drmKeySession, LICENSE_OFFLINE, keyData, &keyDataLen); // 确保生成离线license
2073 keyId_ptr = keyData;
2074 if (offlineKeyIdLen > 0) {
2075 offlineKeyIdLen = keyDataLen;
2076 }
2077 } else if (0 != strcmp(KeyId, " ")) {
2078 keyId_ptr = (uint8_t *)malloc(KeyIdLen);
2079 splitStringToIntArray(KeyId, keyId_ptr);
2080 } else
2081 ;
2082 MediaKeySession *session_ptr = nullptr;
2083 if (0 != strcmp(inSession, " ")) {
2084 session_ptr = drmKeySession;
2085 }
2086 Drm_ErrCode ret3 = OH_MediaKeySession_RestoreOfflineMediaKeys(session_ptr, keyId_ptr, offlineKeyIdLen);
2087 Drm_ErrCode ret4 = OH_MediaKeySession_Destroy(drmKeySession);
2088 Drm_ErrCode ret5 = OH_MediaKeySystem_Destroy(drmKeySystem);
2089 if (ret1 == DRM_ERR_OK && ret2 == DRM_ERR_OK && ret3 == DRM_ERR_OK && ret4 == DRM_ERR_OK && ret5 == DRM_ERR_OK) {
2090 ret = DRM_ERR_OK;
2091 } else {
2092 ret = DRM_ERR_INVALID_VAL;
2093 }
2094 if (keyId_ptr != nullptr && strcmp(KeyId, "getKey") != 0) {
2095 free(keyId_ptr);
2096 }
2097 napi_create_int32(env, ret, &result);
2098 return result;
2099 }
2100 // add cases
Test_CreateMediaKeySession_multi(napi_env env,napi_callback_info info)2101 static napi_value Test_CreateMediaKeySession_multi(napi_env env, napi_callback_info info) {
2102 napi_value result;
2103 size_t argc = 2;
2104 napi_value args[2] = {nullptr};
2105 int32_t sessionNum = 0;
2106 Drm_ErrCode ret = DRM_ERR_INVALID_VAL;
2107 Drm_ErrCode ret2 = DRM_ERR_INVALID_VAL;
2108 Drm_ErrCode ret4 = DRM_ERR_INVALID_VAL;
2109 MediaKeySystem *drmKeySystem = nullptr;
2110 DRM_ContentProtectionLevel level = CONTENT_PROTECTION_LEVEL_SW_CRYPTO;
2111 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
2112 napi_get_value_int32(env, args[0], &sessionNum);
2113 MediaKeySession *drmKeySession[100] = {nullptr};
2114 Drm_ErrCode ret1 = OH_MediaKeySystem_Create(judge_uuid(), &drmKeySystem);
2115 uint32_t count_create = 0;
2116 for (int i = 0; i < sessionNum; i++) {
2117 ret2 = OH_MediaKeySystem_CreateMediaKeySession(drmKeySystem, &level, &drmKeySession[i]);
2118 CHECK_GOTO(ret2 != DRM_ERR_OK, EXIT1);
2119 count_create++;
2120 }
2121 EXIT1:
2122 for (int i = 0; i < (count_create); i++) {
2123 ret4 = OH_MediaKeySession_Destroy(drmKeySession[i]);
2124 }
2125 Drm_ErrCode ret3 = OH_MediaKeySystem_Destroy(drmKeySystem);
2126 if (ret1 == DRM_ERR_OK && (count_create == sessionNum) && ret3 == DRM_ERR_OK && ret4 == DRM_ERR_OK) {
2127 ret = DRM_ERR_OK;
2128 } else {
2129 ret = DRM_ERR_INVALID_VAL;
2130 }
2131 napi_create_int32(env, ret, &result);
2132 return result;
2133 }
Test_MediaKeySession_ProcessOfflineReleaseResponse_multi(napi_env env,napi_callback_info info)2134 static napi_value Test_MediaKeySession_ProcessOfflineReleaseResponse_multi(napi_env env, napi_callback_info info) {
2135 napi_value result;
2136 size_t argc = 5;
2137 napi_value args[5] = {nullptr};
2138 int32_t releaseNum = 0;
2139
2140 Drm_ErrCode ret = DRM_ERR_INVALID_VAL;
2141 DRM_ContentProtectionLevel sessionLevel = CONTENT_PROTECTION_LEVEL_SW_CRYPTO;
2142 MediaKeySystem *drmKeySystem = nullptr;
2143 MediaKeySession *drmKeySession = nullptr;
2144
2145 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
2146 napi_get_value_int32(env, args[0], &releaseNum);
2147
2148 Drm_ErrCode ret1 = OH_MediaKeySystem_Create(judge_uuid(), &drmKeySystem);
2149 Drm_ErrCode ret2 = OH_MediaKeySystem_CreateMediaKeySession(drmKeySystem, &sessionLevel, &drmKeySession);
2150 uint8_t keyData[DATA_BUFF_LEN] = {0};
2151 int32_t keyDataLen = DATA_BUFF_LEN;
2152 getLicense(drmKeySession, LICENSE_OFFLINE, keyData, &keyDataLen); // 确保生成离线license
2153 Drm_ErrCode ret3 = DRM_ERR_INVALID_VAL;
2154
2155 if (strcmp(judge_uuid(), CLEAR_PLAY) == 0) {
2156 uint8_t releaseResponseData[50] = OFFLINERESPONSE;
2157 int32_t responseLen = 50;
2158 for (int i = 0; i < releaseNum; i++) {
2159 ret3 = OH_MediaKeySession_ProcessOfflineReleaseResponse(drmKeySession, keyData, keyDataLen,
2160 releaseResponseData, responseLen);
2161 }
2162 } else {
2163 ret3 = DRM_ERR_OK;
2164 }
2165 Drm_ErrCode ret5 = OH_MediaKeySession_Destroy(drmKeySession);
2166 Drm_ErrCode ret6 = OH_MediaKeySystem_Destroy(drmKeySystem);
2167 if (ret1 == DRM_ERR_OK && ret2 == DRM_ERR_OK && ret3 == DRM_ERR_OK && ret5 == DRM_ERR_OK && ret6 == DRM_ERR_OK) {
2168 ret = DRM_ERR_OK;
2169 } else {
2170 ret = DRM_ERR_INVALID_VAL;
2171 }
2172 napi_create_int32(env, ret, &result);
2173 return result;
2174 }
Test_MediaKeySystem_SetConfigurationString_multi(napi_env env,napi_callback_info info)2175 static napi_value Test_MediaKeySystem_SetConfigurationString_multi(napi_env env, napi_callback_info info) {
2176 napi_value result;
2177 Drm_ErrCode ret = DRM_ERR_INVALID_VAL;
2178 MediaKeySystem *drmKeySystem = nullptr;
2179 Drm_ErrCode ret1 = OH_MediaKeySystem_Create(judge_uuid(), &drmKeySystem);
2180 Drm_ErrCode ret2 = OH_MediaKeySystem_SetConfigurationString(drmKeySystem, "version", "4500000");
2181 Drm_ErrCode ret3 = OH_MediaKeySystem_SetConfigurationString(drmKeySystem, "version", "2.2");
2182
2183 char outBuff[20] = {0};
2184 int32_t outBuffLen = 20;
2185 Drm_ErrCode ret4 = DRM_ERR_INVALID_VAL;
2186 if (ret2 == DRM_ERR_OK && ret3 == DRM_ERR_OK) {
2187 ret4 = OH_MediaKeySystem_GetConfigurationString(drmKeySystem, "version", outBuff, outBuffLen);
2188 if (strncmp(outBuff, "2.2", outBuffLen) == 0) {
2189 ret4 = DRM_ERR_OK;
2190 } else {
2191 ret4 = DRM_ERR_INVALID_VAL;
2192 }
2193 }
2194 Drm_ErrCode ret5 = OH_MediaKeySystem_Destroy(drmKeySystem);
2195 if (ret1 == DRM_ERR_OK && ret2 == DRM_ERR_OK && ret5 == DRM_ERR_OK && ret4 == DRM_ERR_OK) {
2196 ret = DRM_ERR_OK;
2197 } else {
2198 ret = DRM_ERR_INVALID_VAL;
2199 }
2200 napi_create_int32(env, ret3, &result);
2201 return result;
2202 }
2203
2204 // add api
2205 uint8_t Flag_SetCallback = 0;
testMediaSystemSetCallBack(MediaKeySystem * mediaKeySystem,DRM_EventType eventType,uint8_t * drmInfo,int32_t infoLen,char * extra)2206 Drm_ErrCode testMediaSystemSetCallBack(MediaKeySystem *mediaKeySystem, DRM_EventType eventType, uint8_t *drmInfo,
2207 int32_t infoLen, char *extra) {
2208 OH_LOG_DEBUG(LOG_APP, "testCL_testMediaSystemSetCallBack ok");
2209 Flag_SetCallback = 1;
2210 return DRM_ERR_OK;
2211 }
Test_MediaKeySystem_SetCallback(napi_env env,napi_callback_info info)2212 static napi_value Test_MediaKeySystem_SetCallback(napi_env env, napi_callback_info info) {
2213 napi_value result;
2214 size_t argc = 2;
2215 napi_value args[2] = {nullptr};
2216 size_t inSystemLen = 0;
2217 char *inSystem = nullptr;
2218 size_t callBackLen = 0;
2219 char *callBack = nullptr;
2220 Drm_ErrCode ret = DRM_ERR_INVALID_VAL;
2221 MediaKeySystem *drmKeySystem = nullptr;
2222 MediaKeySession *drmKeySession = nullptr;
2223 DRM_ContentProtectionLevel level = CONTENT_PROTECTION_LEVEL_SW_CRYPTO;
2224
2225 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
2226 napi_get_value_string_utf8(env, args[0], nullptr, 0, &inSystemLen);
2227 inSystem = new char[inSystemLen + 1];
2228 napi_get_value_string_utf8(env, args[0], inSystem, inSystemLen + 1, &inSystemLen);
2229 napi_get_value_string_utf8(env, args[1], nullptr, 0, &callBackLen);
2230 callBack = new char[callBackLen + 1];
2231 napi_get_value_string_utf8(env, args[1], callBack, callBackLen + 1, &callBackLen);
2232
2233 Drm_ErrCode ret1 = OH_MediaKeySystem_Create(judge_uuid(), &drmKeySystem);
2234 MediaKeySystem *sys_ptr = nullptr;
2235 OH_MediaKeySystem_Callback callback_ptr = nullptr;
2236 if (0 != strcmp(inSystem, " ")) {
2237 sys_ptr = drmKeySystem;
2238 }
2239 if (0 != strcmp(callBack, " ")) {
2240 callback_ptr = &testMediaSystemSetCallBack;
2241 }
2242 Drm_ErrCode ret2 = OH_MediaKeySystem_SetCallback(sys_ptr, callback_ptr); // DRM_ERR_OK; // SDK12
2243 CHECK_PRINTF((ret2 != DRM_ERR_OK), ret2);
2244 // Trigger callback
2245 if (strcmp(judge_uuid(), CLEAR_PLAY) == 0) { // clearpaly直接申请设备证书,触发回调
2246 int retCert = getCertificate(drmKeySystem);
2247 CHECK_PRINTF((retCert != 0), retCert);
2248
2249 Drm_ErrCode ret4 = OH_MediaKeySystem_CreateMediaKeySession(drmKeySystem, &level, &drmKeySession);
2250 if (ret4 == DRM_ERR_OK) {
2251 Drm_ErrCode ret5 = OH_MediaKeySession_Destroy(drmKeySession);
2252 CHECK_PRINTF((ret5 != DRM_ERR_OK), ret5);
2253 }
2254 if ((ret2 == DRM_ERR_OK) && (callback_ptr != nullptr)) {
2255 ret2 = (Flag_SetCallback == 1) ? DRM_ERR_OK : DRM_ERR_INVALID_VAL;
2256 }
2257 } else { // wiseplay手动删除证书,创建session失败,触发回调
2258 // triggering events: no provision then createSession failed
2259 DRM_CertificateStatus certStatus = CERT_STATUS_UNAVAILABLE;
2260 Drm_ErrCode ret3 = OH_MediaKeySystem_GetCertificateStatus(drmKeySystem, &certStatus);
2261 if (ret3 == DRM_ERR_OK && certStatus != CERT_STATUS_PROVISIONED) {
2262 Drm_ErrCode ret4 = OH_MediaKeySystem_CreateMediaKeySession(drmKeySystem, &level, &drmKeySession);
2263 if (ret4 == DRM_ERR_OK) {
2264 Drm_ErrCode ret5 = OH_MediaKeySession_Destroy(drmKeySession);
2265 CHECK_PRINTF((ret5 != DRM_ERR_OK), ret5);
2266 }
2267 if ((ret2 == DRM_ERR_OK) && (callback_ptr != nullptr)) {
2268 ret2 = (Flag_SetCallback == 1) ? DRM_ERR_OK : DRM_ERR_INVALID_VAL;
2269 }
2270 }
2271 }
2272 Drm_ErrCode ret6 = OH_MediaKeySystem_Destroy(drmKeySystem);
2273 Flag_SetCallback = 0; // clear flags
2274 if (ret1 == DRM_ERR_OK && ret2 == DRM_ERR_OK && ret6 == DRM_ERR_OK) {
2275 ret = DRM_ERR_OK;
2276 } else {
2277 ret = DRM_ERR_INVALID_VAL;
2278 }
2279 napi_create_int32(env, ret, &result);
2280 return result;
2281 }
2282 // session callBack
2283 uint8_t Flag_SetSesEventCallback = 0;
2284 uint8_t Flag_SetSesChangeCallback = 0;
sessoinEventCallBackTest(MediaKeySession * mediaKeySessoin,DRM_EventType eventType,uint8_t * info,int32_t infoLen,char * extra)2285 Drm_ErrCode sessoinEventCallBackTest(MediaKeySession *mediaKeySessoin, DRM_EventType eventType, uint8_t *info,
2286 int32_t infoLen, char *extra) {
2287 OH_LOG_DEBUG(LOG_APP, "testCL_sessoinEventCallBackTest ok;eventType = %{public}d, infoLen = %{public}d", eventType,
2288 infoLen);
2289 Flag_SetSesEventCallback = 1;
2290 return DRM_ERR_OK;
2291 }
sessoinKeyChangeCallBackTest(MediaKeySession * mediaKeySessoin,DRM_KeysInfo * keysInfo,bool hasNewGoodKeys)2292 Drm_ErrCode sessoinKeyChangeCallBackTest(MediaKeySession *mediaKeySessoin, DRM_KeysInfo *keysInfo,
2293 bool hasNewGoodKeys) {
2294 OH_LOG_DEBUG(LOG_APP, "testCL_sessionKeyChangeCallBackTest ok;hasNewGoodKeys = %{public}d", hasNewGoodKeys);
2295 Flag_SetSesChangeCallback = 1;
2296 return DRM_ERR_OK;
2297 }
Test_MediaKeySession_SetCallback(napi_env env,napi_callback_info info)2298 static napi_value Test_MediaKeySession_SetCallback(napi_env env, napi_callback_info info) {
2299 napi_value result;
2300 size_t argc = 2;
2301 napi_value args[2] = {nullptr};
2302 size_t inSystemLen = 0;
2303 char *inSystem = nullptr;
2304 size_t callBackLen = 0;
2305 char *callBack = nullptr;
2306 Drm_ErrCode ret = DRM_ERR_INVALID_VAL;
2307 MediaKeySystem *drmKeySystem = nullptr;
2308 MediaKeySession *drmKeySession = nullptr;
2309 DRM_ContentProtectionLevel sessionLevel = CONTENT_PROTECTION_LEVEL_SW_CRYPTO;
2310 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
2311 napi_get_value_string_utf8(env, args[0], nullptr, 0, &inSystemLen);
2312 inSystem = new char[inSystemLen + 1];
2313 napi_get_value_string_utf8(env, args[0], inSystem, inSystemLen + 1, &inSystemLen);
2314 napi_get_value_string_utf8(env, args[1], nullptr, 0, &callBackLen);
2315 callBack = new char[callBackLen + 1];
2316 napi_get_value_string_utf8(env, args[1], callBack, callBackLen + 1, &callBackLen);
2317
2318 Drm_ErrCode ret1 = OH_MediaKeySystem_Create(judge_uuid(), &drmKeySystem);
2319 Drm_ErrCode ret2 = OH_MediaKeySystem_CreateMediaKeySession(drmKeySystem, &sessionLevel, &drmKeySession);
2320
2321 OH_MediaKeySession_Callback testCallback;
2322 memset(&testCallback, 0, sizeof(OH_MediaKeySession_Callback));
2323 testCallback.eventCallback = &sessoinEventCallBackTest;
2324 testCallback.keyChangeCallback = &sessoinKeyChangeCallBackTest;
2325 MediaKeySession *session_ptr = nullptr;
2326 OH_MediaKeySession_Callback *callback_ptr = nullptr;
2327 if (0 != strcmp(inSystem, " ")) {
2328 session_ptr = drmKeySession;
2329 }
2330 if (0 != strcmp(callBack, " ")) {
2331 callback_ptr = &testCallback;
2332 }
2333 Drm_ErrCode ret4 = OH_MediaKeySession_SetCallback(session_ptr, callback_ptr);
2334 // triggering events: get license
2335 uint8_t keyData[DATA_BUFF_LEN] = {0};
2336 int32_t keyDataLen = DATA_BUFF_LEN;
2337 int resLice = getLicense(drmKeySession, LICENSE_OFFLINE, keyData, &keyDataLen);
2338 if ((ret4 == DRM_ERR_OK) && (resLice == 0) && (callback_ptr != nullptr)) {
2339 ret4 = ((Flag_SetSesEventCallback == 1) || (Flag_SetSesChangeCallback == 1)) ? DRM_ERR_OK : DRM_ERR_INVALID_VAL;
2340 }
2341 Drm_ErrCode ret5 = OH_MediaKeySession_Destroy(drmKeySession);
2342 Drm_ErrCode ret6 = OH_MediaKeySystem_Destroy(drmKeySystem);
2343 Flag_SetSesChangeCallback = 0;
2344 Flag_SetSesEventCallback = 0;
2345 if (ret1 == DRM_ERR_OK && ret2 == DRM_ERR_OK && ret4 == DRM_ERR_OK && ret5 == DRM_ERR_OK && ret6 == DRM_ERR_OK) {
2346 ret = DRM_ERR_OK;
2347 } else {
2348 ret = DRM_ERR_INVALID_VAL;
2349 }
2350 napi_create_int32(env, ret, &result);
2351 return result;
2352 }
Test_MediaKeySystem_GetMediaKeySystems(napi_env env,napi_callback_info info)2353 static napi_value Test_MediaKeySystem_GetMediaKeySystems(napi_env env, napi_callback_info info) {
2354 napi_value result;
2355 size_t argc = 2;
2356 napi_value args[2] = {nullptr};
2357 size_t inSystemLen = 0;
2358 char *inSystem = nullptr;
2359 size_t callBackLen = 0;
2360 char *callBack = nullptr;
2361
2362 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
2363 napi_get_value_string_utf8(env, args[0], nullptr, 0, &inSystemLen);
2364 inSystem = new char[inSystemLen + 1];
2365 napi_get_value_string_utf8(env, args[0], inSystem, inSystemLen + 1, &inSystemLen);
2366 napi_get_value_string_utf8(env, args[1], nullptr, 0, &callBackLen);
2367 callBack = new char[callBackLen + 1];
2368 napi_get_value_string_utf8(env, args[1], callBack, callBackLen + 1, &callBackLen);
2369
2370 uint32_t count = DRM_PLUGIN_COUNT;
2371 DRM_MediaKeySystemDescription descriptions[DRM_PLUGIN_COUNT];
2372 memset(descriptions, 0, sizeof(descriptions));
2373 DRM_MediaKeySystemDescription *des_ptr = nullptr;
2374 uint32_t *count_ptr = nullptr;
2375 if (0 != strcmp(inSystem, " ")) {
2376 des_ptr = descriptions;
2377 }
2378 if (0 != strcmp(callBack, " ")) {
2379 count_ptr = &count;
2380 }
2381 Drm_ErrCode ret = OH_MediaKeySystem_GetMediaKeySystems(des_ptr, count_ptr);
2382 if (ret == DRM_ERR_OK) {
2383 for (int i = 0; i < count; i++) {
2384 OH_LOG_DEBUG(LOG_APP, "testCL_GetMediaKeySystems, name[%{public}d] is %{public}s", i, descriptions[i].name);
2385 OH_LOG_DEBUG(LOG_APP, "testCL_GetMediaKeySystems, uuid[%{public}d] is %{public}s", i, descriptions[i].uuid);
2386 }
2387 }
2388 napi_create_int32(env, ret, &result);
2389 return result;
2390 }
2391
2392 EXTERN_C_START
Init(napi_env env,napi_value exports)2393 static napi_value Init(napi_env env, napi_value exports) {
2394 napi_property_descriptor desc[] = {
2395 {"GetOfflineMediaKeyIds", nullptr, GetOfflineMediaKeyIds, nullptr, nullptr, nullptr, napi_default, nullptr},
2396 {"GetCertificateStatus", nullptr, GetCertificateStatus, nullptr, nullptr, nullptr, napi_default, nullptr},
2397 {"Test_KeySystemSupported", nullptr, Test_KeySystemSupported, nullptr, nullptr, nullptr, napi_default, nullptr},
2398 {"Test_KeySystemSupported2", nullptr, Test_KeySystemSupported2, nullptr, nullptr, nullptr, napi_default,
2399 nullptr},
2400 {"Test_KeySystemSupported3", nullptr, Test_KeySystemSupported3, nullptr, nullptr, nullptr, napi_default,
2401 nullptr},
2402 {"Test_MediaKeySystem_Create", nullptr, Test_MediaKeySystem_Create, nullptr, nullptr, nullptr, napi_default,
2403 nullptr},
2404 {"Test_MediaKeySystem_SetConfigurationString", nullptr, Test_MediaKeySystem_SetConfigurationString, nullptr,
2405 nullptr, nullptr, napi_default, nullptr},
2406 {"Test_MediaKeySystem_GetConfigurationString", nullptr, Test_MediaKeySystem_GetConfigurationString, nullptr,
2407 nullptr, nullptr, napi_default, nullptr},
2408 {"Test_MediaKeySystem_SetConfigurationByteArray", nullptr, Test_MediaKeySystem_SetConfigurationByteArray,
2409 nullptr, nullptr, nullptr, napi_default, nullptr},
2410 {"Test_MediaKeySystem_GetConfigurationByteArray", nullptr, Test_MediaKeySystem_GetConfigurationByteArray,
2411 nullptr, nullptr, nullptr, napi_default, nullptr},
2412 {"Test_MediaKeySystem_SetMediaKeySystemCallback", nullptr, Test_MediaKeySystem_SetMediaKeySystemCallback,
2413 nullptr, nullptr, nullptr, napi_default, nullptr},
2414 {"Test_MediaKeySystem_GetStatistics", nullptr, Test_MediaKeySystem_GetStatistics, nullptr, nullptr, nullptr,
2415 napi_default, nullptr},
2416 {"Test_MediaKeySystem_GetMaxContentProtectionLevel", nullptr, Test_MediaKeySystem_GetMaxContentProtectionLevel,
2417 nullptr, nullptr, nullptr, napi_default, nullptr},
2418 {"GetMaxContentProtectionLevel", nullptr, GetMaxContentProtectionLevel,nullptr, nullptr, nullptr, napi_default,
2419 nullptr},
2420 {"Test_MediaKeySystem_GenerateKeySystemRequest", nullptr, Test_MediaKeySystem_GenerateKeySystemRequest, nullptr,
2421 nullptr, nullptr, napi_default, nullptr},
2422 {"Test_MediaKeySystem_ProcessKeySystemResponse", nullptr, Test_MediaKeySystem_ProcessKeySystemResponse, nullptr,
2423 nullptr, nullptr, napi_default, nullptr},
2424 {"Test_MediaKeySystem_GetOfflineMediaKeyIds", nullptr, Test_MediaKeySystem_GetOfflineMediaKeyIds, nullptr,
2425 nullptr, nullptr, napi_default, nullptr},
2426 {"Test_MediaKeySystem_Destroy", nullptr, Test_MediaKeySystem_Destroy, nullptr, nullptr, nullptr, napi_default,
2427 nullptr},
2428 {"Test_CreateMediaKeySession", nullptr, Test_CreateMediaKeySession, nullptr, nullptr, nullptr, napi_default,
2429 nullptr},
2430 {"Test_MediaKeySystem_GetCertificateStatus", nullptr, Test_MediaKeySystem_GetCertificateStatus, nullptr,
2431 nullptr, nullptr, napi_default, nullptr},
2432 {"Test_MediaKeySession_GenerateMediaKeyRequest", nullptr, Test_MediaKeySession_GenerateMediaKeyRequest, nullptr,
2433 nullptr, nullptr, napi_default, nullptr},
2434 {"Test_MediaKeySession_ProcessMediaKeyResponse", nullptr, Test_MediaKeySession_ProcessMediaKeyResponse, nullptr,
2435 nullptr, nullptr, napi_default, nullptr},
2436 {"Test_MediaKeySession_CheckMediaKeyStatus", nullptr, Test_MediaKeySession_CheckMediaKeyStatus, nullptr,
2437 nullptr, nullptr, napi_default, nullptr},
2438 {"Test_MediaKeySession_ClearMediaKeys", nullptr, Test_MediaKeySession_ClearMediaKeys, nullptr, nullptr, nullptr,
2439 napi_default, nullptr},
2440 {"Test_MediaKeySession_GenerateOfflineReleaseRequest", nullptr,
2441 Test_MediaKeySession_GenerateOfflineReleaseRequest, nullptr, nullptr, nullptr, napi_default, nullptr},
2442 {"Test_MediaKeySession_ProcessOfflineReleaseResponse", nullptr,
2443 Test_MediaKeySession_ProcessOfflineReleaseResponse, nullptr, nullptr, nullptr, napi_default, nullptr},
2444 {"Test_MediaKeySession_RestoreOfflineMediaKeys", nullptr, Test_MediaKeySession_RestoreOfflineMediaKeys, nullptr,
2445 nullptr, nullptr, napi_default, nullptr},
2446 {"Test_MediaKeySession_GetContentProtectionLevel", nullptr, Test_MediaKeySession_GetContentProtectionLevel,
2447 nullptr, nullptr, nullptr, napi_default, nullptr},
2448 {"Test_MediaKeySession_RequireSecureDecoderModule", nullptr, Test_MediaKeySession_RequireSecureDecoderModule,
2449 nullptr, nullptr, nullptr, napi_default, nullptr},
2450 {"Test_MediaKeySession_SetMediaKeySessionCallback", nullptr, Test_MediaKeySession_SetMediaKeySessionCallback,
2451 nullptr, nullptr, nullptr, napi_default, nullptr},
2452 {"Test_MediaKeySystem_GetOfflineMediaKeyStatus", nullptr, Test_MediaKeySystem_GetOfflineMediaKeyStatus, nullptr,
2453 nullptr, nullptr, napi_default, nullptr},
2454 {"Test_MediaKeySystem_ClearOfflineMediaKeys", nullptr, Test_MediaKeySystem_ClearOfflineMediaKeys, nullptr,
2455 nullptr, nullptr, napi_default, nullptr},
2456 {"Test_CreateMediaKeySession_multi", nullptr, Test_CreateMediaKeySession_multi, nullptr, nullptr, nullptr,
2457 napi_default, nullptr},
2458 {"Test_MediaKeySession_ProcessOfflineReleaseResponse_multi", nullptr,
2459 Test_MediaKeySession_ProcessOfflineReleaseResponse_multi, nullptr, nullptr, nullptr, napi_default, nullptr},
2460 {"Test_MediaKeySystem_SetConfigurationString_multi", nullptr, Test_MediaKeySystem_SetConfigurationString_multi,
2461 nullptr, nullptr, nullptr, napi_default, nullptr},
2462 {"Test_MediaKeySystem_SetCallback", nullptr, Test_MediaKeySystem_SetCallback, nullptr, nullptr, nullptr,
2463 napi_default, nullptr},
2464 {"Test_MediaKeySession_SetCallback", nullptr, Test_MediaKeySession_SetCallback, nullptr, nullptr, nullptr,
2465 napi_default, nullptr},
2466 {"Test_MediaKeySystem_GetMediaKeySystems", nullptr, Test_MediaKeySystem_GetMediaKeySystems, nullptr, nullptr,
2467 nullptr, napi_default, nullptr},
2468 };
2469 napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);
2470 return exports;
2471 }
2472 EXTERN_C_END
2473
2474 static napi_module demoModule = {
2475 .nm_version = 1,
2476 .nm_flags = 0,
2477 .nm_filename = nullptr,
2478 .nm_register_func = Init,
2479 .nm_modname = "entry",
2480 .nm_priv = ((void *)0),
2481 .reserved = {0},
2482 };
2483
RegisterEntryModule(void)2484 extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); }
2485