diff --git a/frameworks/js/avscreen_capture/avscreen_capture_napi.cpp b/frameworks/js/avscreen_capture/avscreen_capture_napi.cpp index c91ff0b24238d252cad9ebcb62690b997935c116..83763a287d40f3311449ec1c9a44c7eb192a7dc5 100644 --- a/frameworks/js/avscreen_capture/avscreen_capture_napi.cpp +++ b/frameworks/js/avscreen_capture/avscreen_capture_napi.cpp @@ -283,28 +283,28 @@ napi_value AVScreenCaptureNapi::JsGetAVScreenCaptureConfigurableParameters(napi_ CHECK_AND_RETURN_RET_LOG(status == napi_ok && jsThis != nullptr, nullptr, "failed to napi_get_cb_info"); MEDIA_LOGI("argCount %{public}zu", argCount); if (argCount < maxParam) { - CommonNapi::ThrowError(env, MSERR_EXT_API9_PERMISSION_DENIED, "parameter missing"); + ThrowCustomError(env, MSERR_EXT_API9_PERMISSION_DENIED, "parameter missing"); } napi_valuetype valueType = napi_undefined; if (napi_typeof(env, args[0], &valueType) != napi_ok || valueType != napi_number) { - CommonNapi::ThrowError(env, MSERR_EXT_API9_PERMISSION_DENIED, "invalid parameter type"); + ThrowCustomError(env, MSERR_EXT_API9_PERMISSION_DENIED, "invalid parameter type"); } int32_t sessionId; status = napi_get_value_int32(env, args[0], &sessionId); if (status != napi_ok) { - CommonNapi::ThrowError(env, MSERR_EXT_API9_PERMISSION_DENIED, "invalid parameter type"); + ThrowCustomError(env, MSERR_EXT_API9_PERMISSION_DENIED, "invalid parameter type"); } if (!SystemPermission()) { - CommonNapi::ThrowError(env, MSERR_EXT_API9_PERMISSION_DENIED, "permission denied"); + ThrowCustomError(env, MSERR_EXT_API9_PERMISSION_DENIED, "permission denied"); } std::string resultStr = ""; asyncCtx->controller_ = ScreenCaptureControllerFactory::CreateScreenCaptureController(); if (asyncCtx->controller_ == nullptr) { - CommonNapi::ThrowError(env, MSERR_EXT_API9_PERMISSION_DENIED, "failed to create controller"); + ThrowCustomError(env, MSERR_EXT_API9_PERMISSION_DENIED, "failed to create controller"); } int32_t res = asyncCtx->controller_->GetAVScreenCaptureConfigurableParameters(sessionId, resultStr); if (res != MSERR_OK) { - CommonNapi::ThrowError(env, MSERR_EXT_API20_SESSION_NOT_EXIST, "session does not exist."); + ThrowCustomError(env, MSERR_EXT_API20_SESSION_NOT_EXIST, "session does not exist."); } napi_create_string_utf8(env, resultStr.c_str(), NAPI_AUTO_LENGTH, &result); napi_value resource = nullptr; @@ -314,6 +314,22 @@ napi_value AVScreenCaptureNapi::JsGetAVScreenCaptureConfigurableParameters(napi_ return result; } +napi_value AVScreenCaptureNapi::ThrowCustomError(napi_env env, int32_t errorCode, const char* errorMessage) +{ + napi_value message = nullptr; + napi_value error = nullptr; + napi_value codeValue = nullptr; + napi_value propName = nullptr; + + napi_create_string_utf8(env, errorMessage, NAPI_AUTO_LENGTH, &message); + napi_create_error(env, nullptr, message, &error); + napi_create_int32(env, errorCode, &codeValue); + napi_create_string_utf8(env, "code", NAPI_AUTO_LENGTH, &propName); + napi_set_property(env, error, propName, codeValue); + napi_throw(env, error); + return nullptr; +} + void AVScreenCaptureNapi::AsyncJsReportAVScreenCaptureUserChoice(napi_env env, void* data) { AVScreenCaptureAsyncContext* asyncCtx = reinterpret_cast(data); diff --git a/frameworks/js/avscreen_capture/avscreen_capture_napi.h b/frameworks/js/avscreen_capture/avscreen_capture_napi.h index a7b68e9996201b75eafe354d6fe008a2088f2ae7..166e4c52910a337f3e51b19569cd27116b78a632 100644 --- a/frameworks/js/avscreen_capture/avscreen_capture_napi.h +++ b/frameworks/js/avscreen_capture/avscreen_capture_napi.h @@ -141,6 +141,7 @@ private: static int32_t CheckAudioChannelCount(const int32_t &audioChannelCount); static napi_status GetWindowIDsVectorParams(std::vector &windowIDsVec, napi_env env, napi_value* args); static AVScreenCaptureFillMode GetScreenCaptureFillMode(const int32_t &fillMode); + static napi_value ThrowCustomError(napi_env env, int32_t errorCode, const char* errorMessage); AVScreenCaptureNapi(); ~AVScreenCaptureNapi(); diff --git a/services/services/screen_capture/server/screen_capture_server.cpp b/services/services/screen_capture/server/screen_capture_server.cpp index 4b0c0c788831e3787afd2b3d684a78c2e3e308ca..8229ce2d89880cd3e95574137245524ba15edd64 100644 --- a/services/services/screen_capture/server/screen_capture_server.cpp +++ b/services/services/screen_capture/server/screen_capture_server.cpp @@ -2313,6 +2313,7 @@ int32_t ScreenCaptureServer::StartScreenCaptureInner(bool isPrivacyAuthorityEnab CHECK_AND_RETURN_RET_LOG(display != nullptr, MSERR_UNKNOWN, "GetDefaultDisplaySync failed"); density_ = display->GetVirtualPixelRatio(); + GetSystemUIFlag(); appName_ = GetClientBundleName(appInfo_.appUid); callingLabel_ = GetBundleResourceLabel(appName_); MEDIA_LOGD("StartScreenCaptureInner callingLabel: %{public}s", callingLabel_.c_str()); @@ -2772,7 +2773,6 @@ int32_t ScreenCaptureServer::StartScreenCapture(bool isPrivacyAuthorityEnabled) startTime_ = GetCurrentMillisecond(); statisticalEventInfo_.enableMic = isMicrophoneSwitchTurnOn_; GetDumpFlag(); - GetSystemUIFlag(); MEDIA_LOGI("ScreenCaptureServer: 0x%{public}06" PRIXPTR " StartScreenCapture start, " "isPrivacyAuthorityEnabled:%{public}s, captureState:%{public}d.", FAKE_POINTER(this), isPrivacyAuthorityEnabled ? "true" : "false", captureState_);