• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 #include "tone_attrs_napi.h"
17 
18 #include "system_sound_log.h"
19 #include "common_napi.h"
20 
21 #include "tokenid_kit.h"
22 #include "ipc_skeleton.h"
23 #include "access_token.h"
24 #include "accesstoken_kit.h"
25 #include "ringtone_common_napi.h"
26 
27 using OHOS::Security::AccessToken::AccessTokenKit;
28 
29 namespace {
30 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_AUDIO_NAPI, "ToneAttrsNapi"};
31 }
32 
33 namespace OHOS {
34 namespace Media {
35 
36 thread_local napi_ref ToneAttrsNapi::sConstructor_ = nullptr;
37 std::shared_ptr<ToneAttrs> ToneAttrsNapi::sToneAttrs_ = nullptr;
38 
ToneAttrsNapi()39 ToneAttrsNapi::ToneAttrsNapi() : env_(nullptr) {}
40 
41 ToneAttrsNapi::~ToneAttrsNapi() = default;
42 
Init(napi_env env,napi_value exports)43 napi_value ToneAttrsNapi::Init(napi_env env, napi_value exports)
44 {
45     napi_status status;
46     napi_value ctorObj;
47     int32_t refCount = 1;
48 
49     napi_property_descriptor tone_attrs_prop[] = {
50         DECLARE_NAPI_FUNCTION("getTitle", GetTitle),
51         DECLARE_NAPI_FUNCTION("setTitle", SetTitle),
52         DECLARE_NAPI_FUNCTION("getFileName", GetFileName),
53         DECLARE_NAPI_FUNCTION("setFileName", SetFileName),
54         DECLARE_NAPI_FUNCTION("getUri", GetUri),
55         DECLARE_NAPI_FUNCTION("getCustomizedType", GetCustomizedType),
56         DECLARE_NAPI_FUNCTION("setCategory", SetCategory),
57         DECLARE_NAPI_FUNCTION("getCategory", GetCategory),
58         DECLARE_NAPI_FUNCTION("setMediaType", SetMediaType),
59         DECLARE_NAPI_FUNCTION("getMediaType", GetMediaType),
60     };
61 
62     status = napi_define_class(env, TONE_ATTRS_NAPI_CLASS_NAME.c_str(), NAPI_AUTO_LENGTH,
63         Construct, nullptr, sizeof(tone_attrs_prop) / sizeof(tone_attrs_prop[0]),
64         tone_attrs_prop, &ctorObj);
65     if (status == napi_ok) {
66         if (napi_create_reference(env, ctorObj, refCount, &sConstructor_) == napi_ok) {
67             status = napi_set_named_property(env, exports, TONE_ATTRS_NAPI_CLASS_NAME.c_str(), ctorObj);
68             if (status == napi_ok) {
69                 return exports;
70             }
71         }
72     }
73 
74     return nullptr;
75 }
76 
Construct(napi_env env,napi_callback_info info)77 napi_value ToneAttrsNapi::Construct(napi_env env, napi_callback_info info)
78 {
79     napi_status status;
80     napi_value jsThis = nullptr;
81     napi_value thisVar = nullptr;
82 
83     status = napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr);
84     if (status == napi_ok) {
85         std::unique_ptr<ToneAttrsNapi> obj = std::make_unique<ToneAttrsNapi>();
86         if (obj != nullptr && thisVar != nullptr) {
87             obj->env_ = env;
88             status = napi_wrap(env, thisVar, static_cast<void*>(obj.get()),
89                                ToneAttrsNapi::Destructor, nullptr, nullptr);
90             if (status == napi_ok) {
91                 obj.release();
92                 return thisVar;
93             }
94         }
95     }
96     MEDIA_LOGE("Failed in ToneAttrsNapi::Construct()!");
97     napi_get_undefined(env, &jsThis);
98     return jsThis;
99 }
100 
Destructor(napi_env env,void * nativeObject,void * finalize_hint)101 void ToneAttrsNapi::Destructor(napi_env env, void *nativeObject, void *finalize_hint)
102 {
103     ToneAttrsNapi *ToneAttrsHelper = reinterpret_cast<ToneAttrsNapi*>(nativeObject);
104     if (ToneAttrsHelper != nullptr) {
105         ObjectRefMap<ToneAttrsNapi>::DecreaseRef(ToneAttrsHelper);
106     }
107 }
108 
NewInstance(napi_env env,std::shared_ptr<ToneAttrs> & nativeToneAttrs,napi_value & out)109 napi_status ToneAttrsNapi::NewInstance(napi_env env, std::shared_ptr<ToneAttrs>& nativeToneAttrs, napi_value& out)
110 {
111     napi_value constructor {};
112     NAPI_CALL_BASE(env, napi_get_reference_value(env, sConstructor_, &constructor), napi_generic_failure);
113     napi_value instance{};
114     NAPI_CALL_BASE(env, napi_new_instance(env, constructor, 0, nullptr, &instance), napi_generic_failure);
115 
116     ToneAttrsNapi* toneAttrsNapi{};
117     NAPI_CALL_BASE(env, napi_unwrap(env, instance, reinterpret_cast<void**>(&toneAttrsNapi)), napi_generic_failure);
118     CHECK_AND_RETURN_RET_LOG(toneAttrsNapi != nullptr, napi_invalid_arg, "toneAttrsNapi is nullptr");
119 
120     toneAttrsNapi->toneAttrs_ = std::move(nativeToneAttrs);
121     out = instance;
122     return napi_ok;
123 }
124 
GetToneAttrs()125 std::shared_ptr<ToneAttrs> ToneAttrsNapi::GetToneAttrs()
126 {
127     return toneAttrs_;
128 }
129 
ThrowErrorAndReturn(napi_env env,const std::string & errMsg,int32_t errCode)130 napi_value ToneAttrsNapi::ThrowErrorAndReturn(napi_env env, const std::string& errMsg, int32_t errCode)
131 {
132     napi_value message = nullptr;
133     napi_value code = nullptr;
134     napi_value errVal = nullptr;
135     napi_value errNameVal = nullptr;
136     napi_value result{};
137     napi_create_string_utf8(env, errMsg.c_str(), NAPI_AUTO_LENGTH, &message);
138     napi_create_error(env, nullptr, message, &errVal);
139     napi_create_int32(env, errCode, &code);
140     napi_set_named_property(env, errVal, "code", code);
141     napi_create_string_utf8(env, errMsg.c_str(), NAPI_AUTO_LENGTH, &errNameVal);
142     napi_set_named_property(env, errVal, "BusinessError", errNameVal);
143     napi_throw(env, errVal);
144     napi_get_undefined(env, &result);
145     return result;
146 }
147 
VerifySelfSystemPermission()148 bool ToneAttrsNapi::VerifySelfSystemPermission()
149 {
150     Security::AccessToken::FullTokenID selfTokenID = IPCSkeleton::GetSelfTokenID();
151     auto tokenTypeFlag = Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(static_cast<uint32_t>(selfTokenID));
152     if (tokenTypeFlag == Security::AccessToken::TOKEN_NATIVE ||
153         tokenTypeFlag == Security::AccessToken::TOKEN_SHELL ||
154         Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(selfTokenID)) {
155         return true;
156     }
157     return false;
158 }
159 
GetTitle(napi_env env,napi_callback_info info)160 napi_value ToneAttrsNapi::GetTitle(napi_env env, napi_callback_info info)
161 {
162     ToneAttrsNapi *toneAttrsNapi = nullptr;
163     napi_value jsThis = nullptr;
164     size_t argc = 0;
165     CHECK_AND_RETURN_RET_LOG(VerifySelfSystemPermission(),
166         ThrowErrorAndReturn(env, NAPI_ERR_PERMISSION_DENIED_INFO, NAPI_ERR_PERMISSION_DENIED),
167         "No system permission");
168 
169     napi_status status = napi_get_cb_info(env, info, &argc, nullptr, &jsThis, nullptr);
170 
171     CHECK_AND_RETURN_RET_LOG((status == napi_ok) && (jsThis != nullptr), nullptr, "jsThis is nullptr");
172     napi_unwrap(env, jsThis, reinterpret_cast<void**>(&toneAttrsNapi));
173     CHECK_AND_RETURN_RET_LOG(toneAttrsNapi != nullptr, nullptr, "toneAttrsNapi is nullptr");
174     CHECK_AND_RETURN_RET_LOG(toneAttrsNapi->toneAttrs_ != nullptr, nullptr, "toneAttrs_ is nullptr");
175     napi_value result;
176     napi_create_string_utf8(env,
177         toneAttrsNapi->toneAttrs_->GetTitle().c_str(), NAPI_AUTO_LENGTH, &result);
178     return result;
179 }
180 
SetTitle(napi_env env,napi_callback_info info)181 napi_value ToneAttrsNapi::SetTitle(napi_env env, napi_callback_info info)
182 {
183     ToneAttrsNapi *toneAttrsNapi = nullptr;
184     napi_value jsThis = nullptr;
185     size_t argc = 1;
186     napi_value argv[1] = {};
187     CHECK_AND_RETURN_RET_LOG(VerifySelfSystemPermission(),
188         ThrowErrorAndReturn(env, NAPI_ERR_PERMISSION_DENIED_INFO, NAPI_ERR_PERMISSION_DENIED),
189         "No system permission");
190 
191     napi_status status = napi_get_cb_info(env, info, &argc, argv, &jsThis, nullptr);
192 
193     napi_valuetype valueType = napi_undefined;
194     napi_typeof(env, argv[0], &valueType);
195     CHECK_AND_RETURN_RET_LOG(valueType == napi_string, nullptr, "title is not string");
196 
197     std::string toneAttrsTitle = CommonNapi::GetStringArgument(env, argv[0]);
198     CHECK_AND_RETURN_RET_LOG(argc == 1 && !toneAttrsTitle.empty(),
199         ThrowErrorAndReturn(env, NAPI_ERR_INPUT_INVALID_INFO, NAPI_ERR_INPUT_INVALID),
200         "invalid arguments");
201     CHECK_AND_RETURN_RET_LOG((status == napi_ok) && (jsThis != nullptr), nullptr, "jsThis is nullptr");
202 
203     napi_unwrap(env, jsThis, reinterpret_cast<void**>(&toneAttrsNapi));
204     CHECK_AND_RETURN_RET_LOG(toneAttrsNapi != nullptr, nullptr, "toneAttrsNapi is nullptr");
205     CHECK_AND_RETURN_RET_LOG(toneAttrsNapi->toneAttrs_ != nullptr, nullptr, "toneAttrs_ is nullptr");
206     toneAttrsNapi->toneAttrs_->SetTitle(toneAttrsTitle);
207     return nullptr;
208 }
209 
GetFileName(napi_env env,napi_callback_info info)210 napi_value ToneAttrsNapi::GetFileName(napi_env env, napi_callback_info info)
211 {
212     ToneAttrsNapi *toneAttrsNapi = nullptr;
213     napi_value jsThis = nullptr;
214     size_t argc = 0;
215     CHECK_AND_RETURN_RET_LOG(VerifySelfSystemPermission(),
216         ThrowErrorAndReturn(env, NAPI_ERR_PERMISSION_DENIED_INFO, NAPI_ERR_PERMISSION_DENIED),
217         "No system permission");
218 
219     napi_status status = napi_get_cb_info(env, info, &argc, nullptr, &jsThis, nullptr);
220     CHECK_AND_RETURN_RET_LOG((status == napi_ok) && (jsThis != nullptr), nullptr, "jsThis is nullptr");
221     napi_unwrap(env, jsThis, reinterpret_cast<void**>(&toneAttrsNapi));
222     CHECK_AND_RETURN_RET_LOG(toneAttrsNapi != nullptr, nullptr, "toneAttrsNapi is nullptr");
223     CHECK_AND_RETURN_RET_LOG(toneAttrsNapi->toneAttrs_ != nullptr, nullptr, "toneAttrs_ is nullptr");
224     napi_value result;
225     napi_create_string_utf8(env,
226         toneAttrsNapi->toneAttrs_->GetFileName().c_str(), NAPI_AUTO_LENGTH, &result);
227     return result;
228 }
229 
SetFileName(napi_env env,napi_callback_info info)230 napi_value ToneAttrsNapi::SetFileName(napi_env env, napi_callback_info info)
231 {
232     ToneAttrsNapi *toneAttrsNapi = nullptr;
233     napi_value jsThis = nullptr;
234     size_t argc = 1;
235     napi_value argv[1] = {};
236     CHECK_AND_RETURN_RET_LOG(VerifySelfSystemPermission(),
237         ThrowErrorAndReturn(env, NAPI_ERR_PERMISSION_DENIED_INFO, NAPI_ERR_PERMISSION_DENIED),
238         "No system permission");
239 
240     napi_status status = napi_get_cb_info(env, info, &argc, argv, &jsThis, nullptr);
241 
242     napi_valuetype valueType = napi_undefined;
243     napi_typeof(env, argv[0], &valueType);
244     CHECK_AND_RETURN_RET_LOG(valueType == napi_string, nullptr, "filename is not string");
245 
246     std::string toneAttrsFileName = CommonNapi::GetStringArgument(env, argv[0]);
247     CHECK_AND_RETURN_RET_LOG(argc == 1 && !toneAttrsFileName.empty(),
248         ThrowErrorAndReturn(env, NAPI_ERR_INPUT_INVALID_INFO, NAPI_ERR_INPUT_INVALID),
249         "invalid arguments");
250     CHECK_AND_RETURN_RET_LOG((status == napi_ok) && (jsThis != nullptr), nullptr, "jsThis is nullptr");
251 
252     napi_unwrap(env, jsThis, reinterpret_cast<void**>(&toneAttrsNapi));
253     CHECK_AND_RETURN_RET_LOG(toneAttrsNapi != nullptr, nullptr, "toneAttrsNapi is nullptr");
254     CHECK_AND_RETURN_RET_LOG(toneAttrsNapi->toneAttrs_ != nullptr, nullptr, "toneAttrs_ is nullptr");
255     toneAttrsNapi->toneAttrs_->SetFileName(toneAttrsFileName);
256     return nullptr;
257 }
258 
GetUri(napi_env env,napi_callback_info info)259 napi_value ToneAttrsNapi::GetUri(napi_env env, napi_callback_info info)
260 {
261     ToneAttrsNapi *toneAttrsNapi = nullptr;
262     napi_value jsThis = nullptr;
263     size_t argc = 0;
264     CHECK_AND_RETURN_RET_LOG(VerifySelfSystemPermission(),
265         ThrowErrorAndReturn(env, NAPI_ERR_PERMISSION_DENIED_INFO, NAPI_ERR_PERMISSION_DENIED),
266         "No system permission");
267 
268     napi_status status = napi_get_cb_info(env, info, &argc, nullptr, &jsThis, nullptr);
269     CHECK_AND_RETURN_RET_LOG((status == napi_ok) && (jsThis != nullptr), nullptr, "jsThis is nullptr");
270     napi_unwrap(env, jsThis, reinterpret_cast<void**>(&toneAttrsNapi));
271     CHECK_AND_RETURN_RET_LOG(toneAttrsNapi != nullptr, nullptr, "toneAttrsNapi is nullptr");
272     CHECK_AND_RETURN_RET_LOG(toneAttrsNapi->toneAttrs_ != nullptr, nullptr, "toneAttrs_ is nullptr");
273     napi_value result;
274     napi_create_string_utf8(env,
275         toneAttrsNapi->toneAttrs_->GetUri().c_str(), NAPI_AUTO_LENGTH, &result);
276     return result;
277 }
278 
GetCustomizedType(napi_env env,napi_callback_info info)279 napi_value ToneAttrsNapi::GetCustomizedType(napi_env env, napi_callback_info info)
280 {
281     ToneAttrsNapi *toneAttrsNapi = nullptr;
282     napi_value jsThis = nullptr;
283     size_t argc = 0;
284     CHECK_AND_RETURN_RET_LOG(VerifySelfSystemPermission(),
285         ThrowErrorAndReturn(env, NAPI_ERR_PERMISSION_DENIED_INFO, NAPI_ERR_PERMISSION_DENIED),
286         "No system permission");
287 
288     napi_status status = napi_get_cb_info(env, info, &argc, nullptr, &jsThis, nullptr);
289     CHECK_AND_RETURN_RET_LOG((status == napi_ok) && (jsThis != nullptr), nullptr, "jsThis is nullptr");
290     napi_unwrap(env, jsThis, reinterpret_cast<void**>(&toneAttrsNapi));
291     CHECK_AND_RETURN_RET_LOG(toneAttrsNapi != nullptr, nullptr, "toneAttrsNapi is nullptr");
292     CHECK_AND_RETURN_RET_LOG(toneAttrsNapi->toneAttrs_ != nullptr, nullptr, "toneAttrs_ is nullptr");
293     napi_value result;
294     napi_create_int32(env, toneAttrsNapi->toneAttrs_->GetCustomizedType(), &result);
295     return result;
296 }
297 
SetCategory(napi_env env,napi_callback_info info)298 napi_value ToneAttrsNapi::SetCategory(napi_env env, napi_callback_info info)
299 {
300     ToneAttrsNapi *toneAttrsNapi = nullptr;
301     napi_value jsThis = nullptr;
302     size_t argc = 1;
303     napi_value argv[1] = {};
304     CHECK_AND_RETURN_RET_LOG(VerifySelfSystemPermission(),
305         ThrowErrorAndReturn(env, NAPI_ERR_PERMISSION_DENIED_INFO, NAPI_ERR_PERMISSION_DENIED),
306         "No system permission");
307 
308     napi_status status = napi_get_cb_info(env, info, &argc, argv, &jsThis, nullptr);
309 
310     napi_valuetype valueType = napi_undefined;
311     napi_typeof(env, argv[0], &valueType);
312 
313     bool isCategoryValid = false;
314     int32_t toneAttrsCategory = TONE_CATEGORY_INVALID;
315     napi_get_value_int32(env, argv[0], &toneAttrsCategory);
316     if (toneAttrsCategory == TONE_CATEGORY_RINGTONE || toneAttrsCategory == TONE_CATEGORY_TEXT_MESSAGE ||
317         toneAttrsCategory == TONE_CATEGORY_NOTIFICATION || toneAttrsCategory == TONE_CATEGORY_ALARM ||
318         toneAttrsCategory == TONE_CATEGORY_CONTACTS) {
319         isCategoryValid = true;
320     }
321     CHECK_AND_RETURN_RET_LOG(argc == 1 && isCategoryValid,
322         ThrowErrorAndReturn(env, NAPI_ERR_INPUT_INVALID_INFO, NAPI_ERR_INPUT_INVALID),
323         "invalid arguments");
324     CHECK_AND_RETURN_RET_LOG((status == napi_ok) && (jsThis != nullptr), nullptr, "jsThis is nullptr");
325 
326     napi_unwrap(env, jsThis, reinterpret_cast<void**>(&toneAttrsNapi));
327     CHECK_AND_RETURN_RET_LOG(toneAttrsNapi != nullptr, nullptr, "toneAttrsNapi is nullptr");
328     CHECK_AND_RETURN_RET_LOG(toneAttrsNapi->toneAttrs_ != nullptr, nullptr, "toneAttrs_ is nullptr");
329     toneAttrsNapi->toneAttrs_->SetCategory(toneAttrsCategory);
330     return nullptr;
331 }
332 
GetCategory(napi_env env,napi_callback_info info)333 napi_value ToneAttrsNapi::GetCategory(napi_env env, napi_callback_info info)
334 {
335     ToneAttrsNapi *toneAttrsNapi = nullptr;
336     napi_value jsThis = nullptr;
337     size_t argc = 0;
338     CHECK_AND_RETURN_RET_LOG(VerifySelfSystemPermission(),
339         ThrowErrorAndReturn(env, NAPI_ERR_PERMISSION_DENIED_INFO, NAPI_ERR_PERMISSION_DENIED),
340         "No system permission");
341 
342     napi_status status = napi_get_cb_info(env, info, &argc, nullptr, &jsThis, nullptr);
343     CHECK_AND_RETURN_RET_LOG((status == napi_ok) && (jsThis != nullptr), nullptr, "jsThis is nullptr");
344     napi_unwrap(env, jsThis, reinterpret_cast<void**>(&toneAttrsNapi));
345     CHECK_AND_RETURN_RET_LOG(toneAttrsNapi != nullptr, nullptr, "toneAttrsNapi is nullptr");
346     CHECK_AND_RETURN_RET_LOG(toneAttrsNapi->toneAttrs_ != nullptr, nullptr, "toneAttrs_ is nullptr");
347     napi_value result;
348     napi_create_int32(env, toneAttrsNapi->toneAttrs_->GetCategory(), &result);
349     return result;
350 }
351 
SetMediaType(napi_env env,napi_callback_info info)352 napi_value ToneAttrsNapi::SetMediaType(napi_env env, napi_callback_info info)
353 {
354     ToneAttrsNapi *toneAttrsNapi = nullptr;
355     napi_value jsThis = nullptr;
356     size_t argc = 1;
357     napi_value argv[1] = {};
358     CHECK_AND_RETURN_RET_LOG(VerifySelfSystemPermission(),
359         ThrowErrorAndReturn(env, NAPI_ERR_PERMISSION_DENIED_INFO, NAPI_ERR_PERMISSION_DENIED),
360         "No system permission");
361 
362     napi_status status = napi_get_cb_info(env, info, &argc, argv, &jsThis, nullptr);
363 
364     napi_valuetype valueType = napi_undefined;
365     napi_typeof(env, argv[0], &valueType);
366 
367     bool isMediaTypeValid = false;
368     int32_t toneAttrsMediaType = MEDIA_TYPE_AUD;
369     napi_get_value_int32(env, argv[0], &toneAttrsMediaType);
370     if (toneAttrsMediaType == MEDIA_TYPE_AUD || toneAttrsMediaType == MEDIA_TYPE_VID) {
371         isMediaTypeValid = true;
372     }
373     CHECK_AND_RETURN_RET_LOG(argc == 1 && isMediaTypeValid,
374         ThrowErrorAndReturn(env, NAPI_ERR_INPUT_INVALID_INFO, NAPI_ERR_INPUT_INVALID),
375         "invalid arguments");
376     CHECK_AND_RETURN_RET_LOG((status == napi_ok) && (jsThis != nullptr), nullptr, "jsThis is nullptr");
377 
378     napi_unwrap(env, jsThis, reinterpret_cast<void**>(&toneAttrsNapi));
379     CHECK_AND_RETURN_RET_LOG(toneAttrsNapi != nullptr, nullptr, "toneAttrsNapi is nullptr");
380     CHECK_AND_RETURN_RET_LOG(toneAttrsNapi->toneAttrs_ != nullptr, nullptr, "toneAttrs_ is nullptr");
381     toneAttrsNapi->toneAttrs_->SetMediaType(static_cast<ToneMediaType>(toneAttrsMediaType));
382     return nullptr;
383 }
384 
GetMediaType(napi_env env,napi_callback_info info)385 napi_value ToneAttrsNapi::GetMediaType(napi_env env, napi_callback_info info)
386 {
387     ToneAttrsNapi *toneAttrsNapi = nullptr;
388     napi_value jsThis = nullptr;
389     size_t argc = 0;
390     CHECK_AND_RETURN_RET_LOG(VerifySelfSystemPermission(),
391         ThrowErrorAndReturn(env, NAPI_ERR_PERMISSION_DENIED_INFO, NAPI_ERR_PERMISSION_DENIED),
392         "No system permission");
393 
394     napi_status status = napi_get_cb_info(env, info, &argc, nullptr, &jsThis, nullptr);
395     CHECK_AND_RETURN_RET_LOG((status == napi_ok) && (jsThis != nullptr), nullptr, "jsThis is nullptr");
396     napi_unwrap(env, jsThis, reinterpret_cast<void**>(&toneAttrsNapi));
397     CHECK_AND_RETURN_RET_LOG(toneAttrsNapi != nullptr, nullptr, "toneAttrsNapi is nullptr");
398     CHECK_AND_RETURN_RET_LOG(toneAttrsNapi->toneAttrs_ != nullptr, nullptr, "toneAttrs_ is nullptr");
399     napi_value result;
400     napi_create_int32(env, static_cast<int32_t>(toneAttrsNapi->toneAttrs_->GetMediaType()), &result);
401     return result;
402 }
403 } // namespace Media
404 } // namespace OHOS