diff --git a/frameworks/js/avscreen_capture/avscreen_capture_napi.cpp b/frameworks/js/avscreen_capture/avscreen_capture_napi.cpp index bb20fac992562aa4b420f55c1dd91ead793e4f5d..297c01dd6839900aad637712cc3c1e602462bed7 100644 --- a/frameworks/js/avscreen_capture/avscreen_capture_napi.cpp +++ b/frameworks/js/avscreen_capture/avscreen_capture_napi.cpp @@ -20,6 +20,8 @@ #include "media_log.h" #ifndef CROSS_PLATFORM #include "display_manager.h" +#include "media_errors.h" +#include "recorder_napi_utils.h" #endif namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_SCREENCAPTURE, "AVScreenCaptureNapi"}; @@ -49,7 +51,9 @@ napi_value AVScreenCaptureNapi::Init(napi_env env, napi_value exports) { napi_property_descriptor staticProperty[] = { DECLARE_NAPI_STATIC_FUNCTION("createAVScreenCaptureRecorder", JsCreateAVScreenRecorder), - DECLARE_NAPI_STATIC_FUNCTION("reportAVScreenCaptureUserChoice", JsReportAVScreenCaptureUserChoice) + DECLARE_NAPI_STATIC_FUNCTION("reportAVScreenCaptureUserChoice", JsReportAVScreenCaptureUserChoice), + DECLARE_NAPI_STATIC_FUNCTION("getAVScreenCaptureConfigurableParameters", + JsGetAVScreenCaptureConfigurableParameters) }; napi_property_descriptor properties[] = { @@ -262,6 +266,54 @@ napi_value AVScreenCaptureNapi::JsReportAVScreenCaptureUserChoice(napi_env env, return result; } +napi_value AVScreenCaptureNapi::JsGetAVScreenCaptureConfigurableParameters(napi_env env, napi_callback_info info) +{ + MediaTrace trace("AVScreenCapture::JsGetAVScreenCaptureConfigurableParameters"); + const std::string &opt = AVScreenCapturegOpt::GET_CONFIG_PARAMS; + MEDIA_LOGI("Js %{public}s Start", opt.c_str()); + + const int32_t maxParam = 1; + size_t argCount = maxParam; + napi_value args[maxParam] = { nullptr }; + napi_value result = nullptr; + auto asyncCtx = std::make_unique(env); + CHECK_AND_RETURN_RET_LOG(asyncCtx != nullptr, result, "failed to get AsyncContext"); + napi_value jsThis = nullptr; + napi_status status = napi_get_cb_info(env, info, &argCount, args, &jsThis, nullptr); + 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"); + } + 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"); + } + 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"); + } + if (!SystemPermission()) { + CommonNapi::ThrowError(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"); + } + int32_t res = asyncCtx->controller_->GetAVScreenCaptureConfigurableParameters(sessionId, resultStr); + if (res != MSERR_OK) { + CommonNapi::ThrowError(env, MSERR_EXT_API20_SESSION_NOT_EXIST, "session dose not exist."); + } + napi_create_string_utf8(env, resultStr.c_str(), NAPI_AUTO_LENGTH, &result); + napi_value resource = nullptr; + napi_create_string_utf8(env, opt.c_str(), NAPI_AUTO_LENGTH, &resource); + asyncCtx.release(); + MEDIA_LOGI("Js %{public}s End", opt.c_str()); + return result; +} + 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 a4d0077c15073f210762293ab6721e11c113b062..a7b68e9996201b75eafe354d6fe008a2088f2ae7 100644 --- a/frameworks/js/avscreen_capture/avscreen_capture_napi.h +++ b/frameworks/js/avscreen_capture/avscreen_capture_napi.h @@ -29,6 +29,7 @@ namespace Media { namespace AVScreenCapturegOpt { const std::string INIT = "Init"; const std::string REPORT_USER_CHOICE = "ReportAVScreenCaptureUserChoice"; +const std::string GET_CONFIG_PARAMS = "GetAVScreenCaptureConfigurableParameters"; const std::string START_RECORDING = "StartRecording"; const std::string STOP_RECORDING = "StopRecording"; const std::string SKIP_PRIVACY_MODE = "SkipPrivacyMode"; @@ -75,6 +76,10 @@ private: * reportAVScreenCaptureUserChoice(sessionId: number, choice: string): Promise */ static napi_value JsReportAVScreenCaptureUserChoice(napi_env env, napi_callback_info info); + /** + * getAVScreenCaptureConfigurableParameters(sessionId: number): Promise + */ + static napi_value JsGetAVScreenCaptureConfigurableParameters(napi_env env, napi_callback_info info); /** * init(config: AVScreenCaptureRecordConfig): Promise */ diff --git a/frameworks/js/media/media_enum_napi.cpp b/frameworks/js/media/media_enum_napi.cpp index d7356a6b0c93742be834e5fa4277512dfa8b6e67..a9b0539379abc80e6247606885a35e4b574e4626 100644 --- a/frameworks/js/media/media_enum_napi.cpp +++ b/frameworks/js/media/media_enum_napi.cpp @@ -88,6 +88,7 @@ static const std::vector g_AVErrorCode = { { "AVERR_SUPER_RESOLUTION_UNSUPPORTED", MediaServiceExtErrCodeAPI9::MSERR_EXT_API16_SUPER_RESOLUTION_UNSUPPORTED }, { "AVERR_SUPER_RESOLUTION_NOT_ENABLED", MediaServiceExtErrCodeAPI9::MSERR_EXT_API16_SUPER_RESOLUTION_NOT_ENABLED }, { "AVERR_IO_CLEARTEXT_NOT_PERMITTED", MediaServiceExtErrCodeAPI9::MSERR_EXT_API20_IO_CLEARTEXT_NOT_PERMITTED }, + { "AVERR_SESSION_NOT_EXIST", MediaServiceExtErrCodeAPI9::MSERR_EXT_API20_SESSION_NOT_EXIST}, { "AVERR_PARAMETER_OUT_OF_RANGE", MediaServiceExtErrCodeAPI9::MSERR_EXT_API20_PARAM_ERROR_OUT_OF_RANGE }, }; diff --git a/frameworks/native/screen_capture/screen_capture_controller_impl.cpp b/frameworks/native/screen_capture/screen_capture_controller_impl.cpp index 435545dda2fddc3c77eae1025f9aa9d31be334c5..fe0ad14f5dfaa083d4fe4a2cefde3d199686d1fc 100644 --- a/frameworks/native/screen_capture/screen_capture_controller_impl.cpp +++ b/frameworks/native/screen_capture/screen_capture_controller_impl.cpp @@ -45,6 +45,22 @@ void ScreenCaptureControllerImpl::ReportAVScreenCaptureUserChoice(int32_t sessio controllerClient = nullptr; } +int32_t ScreenCaptureControllerImpl::GetAVScreenCaptureConfigurableParameters( + int32_t sessionId, std::string &resultStr) +{ + MEDIA_LOGI("ScreenCaptureController::GetAVScreenCaptureConfigurableParameters start"); + std::shared_ptr controllerClient = + MediaServiceFactory::GetInstance().CreateScreenCaptureControllerClient(); + CHECK_AND_RETURN_RET_LOG(controllerClient != nullptr, MSERR_UNKNOWN, + "failed to CreateScreenCaptureControllerClient"); + int32_t ret = controllerClient->GetAVScreenCaptureConfigurableParameters(sessionId, resultStr); + MEDIA_LOGI("ScreenCaptureController::GetAVScreenCaptureConfigurableParameters Report result: %{public}d", ret); + + (void)MediaServiceFactory::GetInstance().DestroyScreenCaptureControllerClient(controllerClient); + controllerClient = nullptr; + return ret; +} + ScreenCaptureControllerImpl::ScreenCaptureControllerImpl() { MEDIA_LOGD("ScreenCaptureControllerImpl:0x%{public}06" PRIXPTR " Instances create", FAKE_POINTER(this)); diff --git a/frameworks/native/screen_capture/screen_capture_controller_impl.h b/frameworks/native/screen_capture/screen_capture_controller_impl.h index d268f128f43cb16e05299432b92fb70244a51630..b113d01bdd3e35584c60796344b931dbb7d8205d 100644 --- a/frameworks/native/screen_capture/screen_capture_controller_impl.h +++ b/frameworks/native/screen_capture/screen_capture_controller_impl.h @@ -24,6 +24,7 @@ namespace Media { class ScreenCaptureControllerImpl : public ScreenCaptureController, public NoCopyable { public: void ReportAVScreenCaptureUserChoice(int32_t sessionId, std::string choice) override; + int32_t GetAVScreenCaptureConfigurableParameters(int32_t sessionId, std::string &resultStr) override; ScreenCaptureControllerImpl(); ~ScreenCaptureControllerImpl(); }; diff --git a/interfaces/inner_api/native/screen_capture_controller.h b/interfaces/inner_api/native/screen_capture_controller.h index c783680ff08426276e03fd39600904ea628f400c..ddccacc650098a119c65847875888e3155f2100d 100644 --- a/interfaces/inner_api/native/screen_capture_controller.h +++ b/interfaces/inner_api/native/screen_capture_controller.h @@ -26,6 +26,7 @@ namespace Media { class ScreenCaptureController { public: virtual void ReportAVScreenCaptureUserChoice(int32_t sessionId, std::string choice) = 0; + virtual int32_t GetAVScreenCaptureConfigurableParameters(int32_t sessionId, std::string &resultStr) = 0; virtual ~ScreenCaptureController() = default; }; diff --git a/services/BUILD.gn b/services/BUILD.gn index 9177cb746428aacafe13eeca0cf83e98631bcafc..8ebbe68dd80b0f0d553b0f561179e5a7a50d2a2f 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -33,6 +33,8 @@ group("media_services_package") { "etc:screen_capture_notification_image", "etc:screen_capture_stop_dark_image", "etc:screen_capture_stop_image", + "etc:screen_capture_capsule_stop_live2_image", + "etc:screen_capture_light_image", ] } if (player_framework_support_screen_capture) { diff --git a/services/etc/BUILD.gn b/services/etc/BUILD.gn index 7ec625a2b96465f397bc90de25296301107a5ce0..bded1db126ffbcb2a4ff9aa3484bca5851fa1ac9 100644 --- a/services/etc/BUILD.gn +++ b/services/etc/BUILD.gn @@ -106,3 +106,17 @@ ohos_prebuilt_etc("screencapture_config_dac") { part_name = "player_framework" module_install_dir = "etc/param" } + +ohos_prebuilt_etc("screen_capture_capsule_stop_live2_image") { + source = "image/capsule_stop_live2.svg" + subsystem_name = "multimedia" + relative_install_dir = "screencapture" + part_name = "player_framework" +} + +ohos_prebuilt_etc("screen_capture_light_image") { + source = "image/light.svg" + subsystem_name = "multimedia" + relative_install_dir = "screencapture" + part_name = "player_framework" +} \ No newline at end of file diff --git a/services/include/i_screen_capture_controller.h b/services/include/i_screen_capture_controller.h index 143a456911ce6355a02aade639c40419292f5279..61da8b6f174bdc37e6cea162571df008f2cadeaf 100644 --- a/services/include/i_screen_capture_controller.h +++ b/services/include/i_screen_capture_controller.h @@ -24,6 +24,7 @@ namespace Media { class IScreenCaptureController { public: virtual int32_t ReportAVScreenCaptureUserChoice(int32_t sessionId, std::string choice) = 0; + virtual int32_t GetAVScreenCaptureConfigurableParameters(int32_t sessionId, std::string &resultStr) = 0; }; } // namespace Media } // namespace OHOS diff --git a/services/services/screen_capture/client/screen_capture_controller_client.cpp b/services/services/screen_capture/client/screen_capture_controller_client.cpp index 358ae4b9d4339b1b674dd818bef37cfc66d1b62e..de952d6dd436e40c81744e781d07bf211e568589 100644 --- a/services/services/screen_capture/client/screen_capture_controller_client.cpp +++ b/services/services/screen_capture/client/screen_capture_controller_client.cpp @@ -65,5 +65,15 @@ int32_t ScreenCaptureControllerClient::ReportAVScreenCaptureUserChoice(int32_t s return screenCaptureControllerProxy_->ReportAVScreenCaptureUserChoice(sessionId, choice); } +int32_t ScreenCaptureControllerClient::GetAVScreenCaptureConfigurableParameters(int32_t sessionId, + std::string &resultStr) +{ + MEDIA_LOGI("ScreenCaptureControllerClient::GetAVScreenCaptureConfigurableParameters start"); + std::lock_guard lock(mutex_); + CHECK_AND_RETURN_RET_LOG(screenCaptureControllerProxy_ != nullptr, + MSERR_SERVICE_DIED, "proxy does not exist."); + return screenCaptureControllerProxy_->GetAVScreenCaptureConfigurableParameters(sessionId, resultStr); +} + } // namespace Media } // namespace OHOS \ No newline at end of file diff --git a/services/services/screen_capture/client/screen_capture_controller_client.h b/services/services/screen_capture/client/screen_capture_controller_client.h index 01666a157609a6db134227c932d083b325e3a225..b2e7c00b8d4c4a48a23e86f37a006d6e540d3936 100644 --- a/services/services/screen_capture/client/screen_capture_controller_client.h +++ b/services/services/screen_capture/client/screen_capture_controller_client.h @@ -31,6 +31,7 @@ public: // ScreenCaptureControllerClient void MediaServerDied(); int32_t ReportAVScreenCaptureUserChoice(int32_t sessionId, std::string choice) override; + int32_t GetAVScreenCaptureConfigurableParameters(int32_t sessionId, std::string &resultStr) override; private: sptr screenCaptureControllerProxy_ = nullptr; diff --git a/services/services/screen_capture/ipc/i_standard_screen_capture_controller.h b/services/services/screen_capture/ipc/i_standard_screen_capture_controller.h index d2c4ca2e3eea7af285185db29b0ea28568b8ccc9..2febd600f3ee9d9ddf81458c1bdb396eb5a84e0f 100644 --- a/services/services/screen_capture/ipc/i_standard_screen_capture_controller.h +++ b/services/services/screen_capture/ipc/i_standard_screen_capture_controller.h @@ -31,6 +31,7 @@ class IStandardScreenCaptureController : public IRemoteBroker { public: virtual ~IStandardScreenCaptureController() = default; virtual int32_t ReportAVScreenCaptureUserChoice(int32_t sessionId, std::string choice) = 0; + virtual int32_t GetAVScreenCaptureConfigurableParameters(int32_t sessionId, std::string &resultStr) = 0; virtual int32_t DestroyStub() = 0; /** @@ -38,6 +39,7 @@ public: */ enum ScreenCaptureControllerMsg { REPORT_USER_CHOICE, + GET_CONFIG_PARAM, DESTROY, }; diff --git a/services/services/screen_capture/ipc/screen_capture_controller_proxy.cpp b/services/services/screen_capture/ipc/screen_capture_controller_proxy.cpp index bd206900583867f448ee993db77bea2c97f44a06..54c96d9b0125bc3ee883bd100c145e98c7794a24 100644 --- a/services/services/screen_capture/ipc/screen_capture_controller_proxy.cpp +++ b/services/services/screen_capture/ipc/screen_capture_controller_proxy.cpp @@ -75,6 +75,29 @@ int32_t ScreenCaptureControllerProxy::ReportAVScreenCaptureUserChoice(int32_t se return reply.ReadInt32(); } +int32_t ScreenCaptureControllerProxy::GetAVScreenCaptureConfigurableParameters(int32_t sessionId, + std::string &resultStr) +{ + MEDIA_LOGI("ScreenCaptureControllerProxy::GetAVScreenCaptureConfigurableParameters start"); + MessageParcel data; + MessageParcel reply; + MessageOption option; + + bool token = data.WriteInterfaceToken(ScreenCaptureControllerProxy::GetDescriptor()); + CHECK_AND_RETURN_RET_LOG(token, MSERR_INVALID_OPERATION, "Failed to write descriptor!"); + + token = data.WriteInt32(sessionId); + CHECK_AND_RETURN_RET_LOG(token, MSERR_INVALID_OPERATION, "Failed to write sessionId!"); + + int error = Remote()->SendRequest(GET_CONFIG_PARAM, data, reply, option); + CHECK_AND_RETURN_RET_LOG(error == MSERR_OK, MSERR_INVALID_OPERATION, + "GetAVScreenCaptureConfigurableParameters failed, error: %{public}d", error); + int ret = reply.ReadInt32(); + CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, MSERR_INVALID_OPERATION, + "GetAVScreenCaptureConfigurableParameters failed, ret: %{public}d", ret); + resultStr = reply.ReadString(); + return ret; +} } // namespace Media } // namespace OHOS \ No newline at end of file diff --git a/services/services/screen_capture/ipc/screen_capture_controller_proxy.h b/services/services/screen_capture/ipc/screen_capture_controller_proxy.h index 1e40661aacf27cb4f4eeb8313d6e0ad83cda8043..95db353490629af86f05eec346e600f02a8b1867 100644 --- a/services/services/screen_capture/ipc/screen_capture_controller_proxy.h +++ b/services/services/screen_capture/ipc/screen_capture_controller_proxy.h @@ -26,6 +26,7 @@ public: virtual ~ScreenCaptureControllerProxy(); int32_t ReportAVScreenCaptureUserChoice(int32_t sessionId, std::string choice) override; + int32_t GetAVScreenCaptureConfigurableParameters(int32_t sessionId, std::string &resultStr) override; int32_t DestroyStub() override; private: diff --git a/services/services/screen_capture/ipc/screen_capture_controller_stub.cpp b/services/services/screen_capture/ipc/screen_capture_controller_stub.cpp index b8b754e2cd225828c47a80a29dba76c9690b2a44..1884e8547b9b861b83c7496d26481ad811fa37ad 100644 --- a/services/services/screen_capture/ipc/screen_capture_controller_stub.cpp +++ b/services/services/screen_capture/ipc/screen_capture_controller_stub.cpp @@ -57,6 +57,8 @@ int32_t ScreenCaptureControllerStub::Init() "failed to create screenCaptureControllerServer Service"); screenCaptureControllerStubFuncs_[REPORT_USER_CHOICE] = &ScreenCaptureControllerStub::ReportAVScreenCaptureUserChoice; + screenCaptureControllerStubFuncs_[GET_CONFIG_PARAM] = + &ScreenCaptureControllerStub::GetAVScreenCaptureConfigurableParameters; screenCaptureControllerStubFuncs_[DESTROY] = &ScreenCaptureControllerStub::DestroyStub; return MSERR_OK; @@ -131,6 +133,37 @@ int32_t ScreenCaptureControllerStub::ReportAVScreenCaptureUserChoice(MessageParc return MSERR_OK; } +int32_t ScreenCaptureControllerStub::GetAVScreenCaptureConfigurableParameters(int32_t sessionId, std::string &resultStr) +{ + MEDIA_LOGI("ScreenCaptureControllerStub::GetAVScreenCaptureConfigurableParameters start"); + CHECK_AND_RETURN_RET_LOG(screenCaptureControllerServer_ != nullptr, false, + "screen capture controller server is nullptr"); + int32_t appUid = IPCSkeleton::GetCallingUid(); + std::string appName = GetClientBundleName(appUid); + if (GetScreenCaptureSystemParam()["const.multimedia.screencapture.screenrecorderbundlename"] + .compare(appName) != 0) { + MEDIA_LOGE("ScreenCaptureControllerStub called by app name %{public}s", appName.c_str()); + return MSERR_INVALID_OPERATION; + } + return screenCaptureControllerServer_->GetAVScreenCaptureConfigurableParameters(sessionId, resultStr); +} + +int32_t ScreenCaptureControllerStub::GetAVScreenCaptureConfigurableParameters(MessageParcel &data, MessageParcel &reply) +{ + MEDIA_LOGI("ScreenCaptureControllerStub::GetAVScreenCaptureConfigurableParameters start"); + CHECK_AND_RETURN_RET_LOG(screenCaptureControllerServer_ != nullptr, MSERR_INVALID_STATE, + "screen capture controller server is nullptr"); + (void)data; + int32_t sessionId = data.ReadInt32(); + std::string resultStr; + int32_t ret = GetAVScreenCaptureConfigurableParameters(sessionId, resultStr); + MEDIA_LOGI("ScreenCaptureControllerStub::GetAVScreenCaptureConfigurableParameters start resultStr: %{public}s", + resultStr.c_str()); + reply.WriteInt32(ret); + reply.WriteString(resultStr); + return MSERR_OK; +} + } // namespace Media } // namespace OHOS \ No newline at end of file diff --git a/services/services/screen_capture/ipc/screen_capture_controller_stub.h b/services/services/screen_capture/ipc/screen_capture_controller_stub.h index c06dbcfbfa32590b2cb3f8a10938a015e0005ec0..3e88e4ac5d00e0c651fa9e12925da58871fa6de9 100644 --- a/services/services/screen_capture/ipc/screen_capture_controller_stub.h +++ b/services/services/screen_capture/ipc/screen_capture_controller_stub.h @@ -29,6 +29,7 @@ public: virtual ~ScreenCaptureControllerStub(); int32_t ReportAVScreenCaptureUserChoice(int32_t sessionId, std::string choice) override; + int32_t GetAVScreenCaptureConfigurableParameters(int32_t sessionId, std::string &resultStr) override; int32_t DestroyStub() override; int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; @@ -36,6 +37,7 @@ private: ScreenCaptureControllerStub(); int32_t Init(); int32_t ReportAVScreenCaptureUserChoice(MessageParcel &data, MessageParcel &reply); + int32_t GetAVScreenCaptureConfigurableParameters(MessageParcel &data, MessageParcel &reply); int32_t DestroyStub(MessageParcel &data, MessageParcel &reply); std::mutex mutex_; diff --git a/services/services/screen_capture/server/screen_capture_controller_server.cpp b/services/services/screen_capture/server/screen_capture_controller_server.cpp index 88c0cf17e6372476de88e82bc220c00d461fc40d..a119f65bf247cb34d735dbd4baff0dd31253414b 100644 --- a/services/services/screen_capture/server/screen_capture_controller_server.cpp +++ b/services/services/screen_capture/server/screen_capture_controller_server.cpp @@ -56,5 +56,12 @@ int32_t ScreenCaptureControllerServer::ReportAVScreenCaptureUserChoice(int32_t s return ret; } +int32_t ScreenCaptureControllerServer::GetAVScreenCaptureConfigurableParameters(int32_t sessionId, + std::string &resultStr) +{ + MEDIA_LOGI("ScreenCaptureControllerServer::GetAVScreenCaptureConfigurableParameters start"); + int32_t ret = ScreenCaptureServer::GetAVScreenCaptureConfigurableParameters(sessionId, resultStr); + return ret; +} } // namespace Media } // namespace OHOS \ No newline at end of file diff --git a/services/services/screen_capture/server/screen_capture_controller_server.h b/services/services/screen_capture/server/screen_capture_controller_server.h index bda62db6eabf2707cc17d32f3577fb7f27bb9722..fc5c2fa21117af1c0d7fd92d4f3e80d691154088 100644 --- a/services/services/screen_capture/server/screen_capture_controller_server.h +++ b/services/services/screen_capture/server/screen_capture_controller_server.h @@ -34,6 +34,7 @@ public: ~ScreenCaptureControllerServer(); int32_t ReportAVScreenCaptureUserChoice(int32_t sessionId, std::string choice) override; + int32_t GetAVScreenCaptureConfigurableParameters(int32_t sessionId, std::string &resultStr) override; }; } // namespace Media diff --git a/services/services/screen_capture/server/screen_capture_server.cpp b/services/services/screen_capture/server/screen_capture_server.cpp index 36ab6e3d1eb4443f8fd0bd331214ef9604fff3ef..733c42842a0bc6979b518c6de2cc9ce5415f6b02 100644 --- a/services/services/screen_capture/server/screen_capture_server.cpp +++ b/services/services/screen_capture/server/screen_capture_server.cpp @@ -45,6 +45,8 @@ #include #include "session_manager_lite.h" #include "window_manager_lite.h" +#include "want_agent_info.h" +#include "want_agent_helper.h" #ifdef PC_STANDARD #include #endif @@ -65,9 +67,11 @@ static const std::string M4A = "m4a"; static const std::string USER_CHOICE_ALLOW = "true"; static const std::string USER_CHOICE_DENY = "false"; static const std::string CHECK_BOX_SELECTED = "true"; +static const std::string JSON_VALUE_TRUE = "true"; static const std::string BUTTON_NAME_MIC = "mic"; static const std::string BUTTON_NAME_STOP = "stop"; static const std::string ICON_PATH_CAPSULE_STOP = "/etc/screencapture/capsule_stop.svg"; +static const std::string ICON_PATH_CAPSULE_STOP_2_0 = "/etc/screencapture/capsule_stop.svg"; static const std::string ICON_PATH_NOTIFICATION = "/etc/screencapture/notification.png"; static const std::string ICON_PATH_MIC = "/etc/screencapture/mic.svg"; static const std::string ICON_PATH_MIC_OFF = "/etc/screencapture/mic_off.svg"; @@ -830,23 +834,26 @@ void ScreenCaptureServer::GetChoiceFromJson(Json::Value &root, } } -void ScreenCaptureServer::GetBoxSelectedFromJson(Json::Value &root, - const std::string &content, std::string key, bool &checkBoxSelected) +void ScreenCaptureServer::GetValueFromJson(Json::Value &root, + const std::string &content, const std::string key, bool &value) { + value = false; + Json::Reader reader; bool parsingSuccessful = reader.parse(content, root); - checkBoxSelected = false; if (!parsingSuccessful || root.type() != Json::objectValue) { MEDIA_LOGE("Error parsing the string"); return; } const Json::Value keyJson = root[key]; if (!keyJson.isNull() && keyJson.isString()) { - if (CHECK_BOX_SELECTED.compare(keyJson.asString()) == 0) { - checkBoxSelected = true; + if (JSON_VALUE_TRUE.compare(keyJson.asString()) == 0) { + value = true; + } else { + value = false; } } - MEDIA_LOGI("GetBoxSelectedFromJson checkBoxSelected: %{public}d", checkBoxSelected); + MEDIA_LOGI("GetValueFromJson value: %{public}d", value); } void ScreenCaptureServer::SetCaptureConfig(CaptureMode captureMode, int32_t missionId) @@ -859,7 +866,7 @@ void ScreenCaptureServer::SetCaptureConfig(CaptureMode captureMode, int32_t miss } } -void ScreenCaptureServer::PrepareSelectWindow(Json::Value &root, std::shared_ptr &server) +void ScreenCaptureServer::PrepareSelectWindow(Json::Value &root) { if (root.type() != Json::objectValue) { return; @@ -868,20 +875,20 @@ void ScreenCaptureServer::PrepareSelectWindow(Json::Value &root, std::shared_ptr if (!displayIdJson.isNull() && displayIdJson.isInt() && displayIdJson.asInt64() >= 0) { uint64_t displayId = static_cast(displayIdJson.asInt64()); MEDIA_LOGI("Report Select DisplayId: %{public}" PRIu64, displayId); - server->SetDisplayId(displayId); + SetDisplayId(displayId); // 手机模式 missionId displayId 均为-1 - server->SetCaptureConfig(CaptureMode::CAPTURE_SPECIFIED_SCREEN, -1); + SetCaptureConfig(CaptureMode::CAPTURE_SPECIFIED_SCREEN, -1); } const Json::Value missionIdJson = root["missionId"]; if (!missionIdJson.isNull() && missionIdJson.isInt() && missionIdJson.asInt() >= 0) { int32_t missionId = missionIdJson.asInt(); MEDIA_LOGI("Report Select MissionId: %{public}d", missionId); - server->SetMissionId(missionId); - server->SetCaptureConfig(CaptureMode::CAPTURE_SPECIFIED_WINDOW, missionId); + SetMissionId(missionId); + SetCaptureConfig(CaptureMode::CAPTURE_SPECIFIED_WINDOW, missionId); } ScreenCaptureUserSelectionInfo selectionInfo = {0, static_cast(0)}; - server->PrepareUserSelectionInfo(selectionInfo); - server->NotifyUserSelected(selectionInfo); + PrepareUserSelectionInfo(selectionInfo); + NotifyUserSelected(selectionInfo); } int32_t ScreenCaptureServer::ReportAVScreenCaptureUserChoice(int32_t sessionId, const std::string &content) @@ -891,39 +898,83 @@ int32_t ScreenCaptureServer::ReportAVScreenCaptureUserChoice(int32_t sessionId, std::shared_ptr server = GetScreenCaptureServerByIdWithLock(sessionId); CHECK_AND_RETURN_RET_LOG(server != nullptr, MSERR_UNKNOWN, "ReportAVScreenCaptureUserChoice failed to get instance, sessionId: %{public}d", sessionId); + Json::Value root; if (server->captureState_ == AVScreenCaptureState::POPUP_WINDOW) { - MEDIA_LOGI("ReportAVScreenCaptureUserChoice captureState is %{public}d", AVScreenCaptureState::POPUP_WINDOW); - Json::Value root; - std::string choice = "false"; - GetChoiceFromJson(root, content, std::string("choice"), choice); + return server->HandlePopupWindowCase(root, content); + } else if (server->GetSCServerDataType() == DataType::ORIGINAL_STREAM && + server->captureState_ == AVScreenCaptureState::STARTED) { + return server->HandleStreamDataCase(root, content); + } + return MSERR_UNKNOWN; +} - GetBoxSelectedFromJson(root, content, std::string("checkBoxSelected"), server->checkBoxSelected_); - MEDIA_LOGI("ReportAVScreenCaptureUserChoice checkBoxSelected: %{public}d", server->checkBoxSelected_); +int32_t ScreenCaptureServer::HandlePopupWindowCase(Json::Value& root, const std::string &content) +{ + MEDIA_LOGI("ReportAVScreenCaptureUserChoice captureState is %{public}d", AVScreenCaptureState::POPUP_WINDOW); + std::string choice = "false"; + GetChoiceFromJson(root, content, std::string("choice"), choice); + GetValueFromJson(root, content, std::string("checkBoxSelected"), checkBoxSelected_); + + systemPrivacyProtectionSwitch_ = checkBoxSelected_; + appPrivacyProtectionSwitch_ = checkBoxSelected_; + MEDIA_LOGI("ReportAVScreenCaptureUserChoice checkBoxSelected: %{public}d", checkBoxSelected_); - if (server->showShareSystemAudioBox_) { - GetBoxSelectedFromJson(root, content, std::string("isInnerAudioBoxSelected"), - server->isInnerAudioBoxSelected_); - } - MEDIA_LOGI("ReportAVScreenCaptureUserChoice showShareSystemAudioBox:%{public}d," - "isInnerAudioBoxSelected:%{public}d", server->showShareSystemAudioBox_, - server->isInnerAudioBoxSelected_); - - if (USER_CHOICE_ALLOW.compare(choice) == 0) { - PrepareSelectWindow(root, server); - int32_t ret = server->OnReceiveUserPrivacyAuthority(true); - CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, ret, - "ReportAVScreenCaptureUserChoice user choice is true but start failed"); - MEDIA_LOGI("ReportAVScreenCaptureUserChoice user choice is true and start success"); - return MSERR_OK; - } else if (USER_CHOICE_DENY.compare(choice) == 0) { - return server->OnReceiveUserPrivacyAuthority(false); - } else { - MEDIA_LOGW("ReportAVScreenCaptureUserChoice user choice is not support"); - } + if (USER_CHOICE_ALLOW.compare(choice) == 0) { + PrepareSelectWindow(root); + int32_t ret = OnReceiveUserPrivacyAuthority(true); + CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, ret, + "ReportAVScreenCaptureUserChoice user choice is true but start failed"); + MEDIA_LOGI("ReportAVScreenCaptureUserChoice user choice is true and start success"); + return MSERR_OK; + } else if (USER_CHOICE_DENY.compare(choice) == 0) { + return OnReceiveUserPrivacyAuthority(false); + } else { + MEDIA_LOGW("ReportAVScreenCaptureUserChoice user choice is not support"); } return MSERR_UNKNOWN; } +int32_t ScreenCaptureServer::HandleStreamDataCase(Json::Value& root, const std::string &content) +{ + bool stopRecord = false; + GetValueFromJson(root, content, std::string("stopRecording"), stopRecord); + if (stopRecord) { + StopScreenCaptureInner(AVScreenCaptureStateCode::SCREEN_CAPTURE_STATE_INVLID); + MEDIA_LOGI("ReportAVScreenCaptureUserChoice user stop record"); + return MSERR_OK; + } + + GetValueFromJson(root, content, std::string("appPrivacyProtectionSwitch"), + appPrivacyProtectionSwitch_); + GetValueFromJson(root, content, std::string("systemPrivacyProtectionSwitch"), + systemPrivacyProtectionSwitch_); + + SystemPrivacyProtected(virtualScreenId_, systemPrivacyProtectionSwitch_); + AppPrivacyProtected(virtualScreenId_, appPrivacyProtectionSwitch_); + + std::lock_guard lock(mutex_); + NotificationRequest request; + SetPublishRequest(GetLocalLiveViewContent(), notificationId_, request); + request.SetWantAgent(GetWantAgent(callingLabel_, sessionId_)); + return NotificationHelper::PublishNotification(request); +} + +int32_t ScreenCaptureServer::GetAVScreenCaptureConfigurableParameters(int32_t sessionId, std::string &resultStr) +{ + MEDIA_LOGI("GetAVScreenCaptureConfigurableParameters sessionId :%{public}d", + sessionId); + std::shared_ptr server = GetScreenCaptureServerByIdWithLock(sessionId); + CHECK_AND_RETURN_RET_LOG(server != nullptr, MSERR_UNKNOWN, + "GetAVScreenCaptureConfigurableParameters failed to get instance, sessionId: %{public}d", sessionId); + Json::Value root; + root["appPrivacyProtectionSwitch"] = server->appPrivacyProtectionSwitch_; + root["systemPrivacyProtectionSwitch"] = server->systemPrivacyProtectionSwitch_; + Json::FastWriter fastWriter; + resultStr = fastWriter.write(root); + MEDIA_LOGI("GetAVScreenCaptureConfigurableParameters res: %{public}s", resultStr.c_str()); + return MSERR_OK; +} + int32_t ScreenCaptureServer::GetAppPid() { return appInfo_.appPid; @@ -2377,6 +2428,11 @@ int32_t ScreenCaptureServer::StartNotification() request.SetRemoveAllowed(false); request.SetInProgress(true); + if (GetSCServerDataType() == DataType::ORIGINAL_STREAM) { + auto wantAgent = GetWantAgent(callingLabel_, sessionId_); + request.SetWantAgent(wantAgent); + } + MEDIA_LOGI("StartNotification, setWantAgent success"); std::shared_ptr pixelMapTotalSpr = GetPixelMap(ICON_PATH_NOTIFICATION); request.SetLittleIcon(pixelMapTotalSpr); request.SetBadgeIconStyle(NotificationRequest::BadgeStyle::LITTLE); @@ -2391,8 +2447,10 @@ std::string ScreenCaptureServer::GetStringByResourceName(const char* name) { std::string resourceContext; CHECK_AND_RETURN_RET_LOG(resourceManager_ != nullptr, resourceContext, "resourceManager is null"); - if (strcmp(name, NOTIFICATION_SCREEN_RECORDING_TITLE_ID) == 0) { - resourceManager_->GetStringByName(NOTIFICATION_SCREEN_RECORDING_TITLE_ID, resourceContext); + if (strcmp(name, NOTIFICATION_SCREEN_RECORDING_TITLE_ID) == 0 || + strcmp(name, NOTIFICATION_SCREEN_RECORDING_PRIVACY_ON_ID) == 0 || + strcmp(name, NOTIFICATION_SCREEN_RECORDING_PRIVACY_OFF_ID) == 0) { + resourceManager_->GetStringByName(name, resourceContext); MEDIA_LOGD("get NOTIFICATION_SCREEN_RECORDING_TITLE_ID: %{public}s", resourceContext.c_str()); } else { MEDIA_LOGE("resource name is error."); @@ -2442,26 +2500,30 @@ std::shared_ptr ScreenCaptureServer::GetLocalL liveViewText_ = recordingScreenTitleStr; } MEDIA_LOGD("GetLocalLiveViewContent liveViewText: %{public}s", liveViewText_.c_str()); - localLiveViewContent->SetText(liveViewText_); auto capsule = NotificationCapsule(); - capsule.SetBackgroundColor(BACK_GROUND_COLOR); - capsulePxSize_ = static_cast(capsuleVpSize_ * density_); - std::shared_ptr pixelMapCapSpr = GetPixelMapSvg(ICON_PATH_CAPSULE_STOP, capsulePxSize_, capsulePxSize_); - capsule.SetIcon(pixelMapCapSpr); + SetupCapsule(capsule); + if (GetSCServerDataType() == DataType::ORIGINAL_STREAM) { + localLiveViewContent->SetTitle(liveViewText_); + if (!systemPrivacyProtectionSwitch_ && !appPrivacyProtectionSwitch_) { + liveViewSubText_ = GetStringByResourceName(NOTIFICATION_SCREEN_RECORDING_PRIVACY_OFF_ID); + } else { + liveViewSubText_ = GetStringByResourceName(NOTIFICATION_SCREEN_RECORDING_PRIVACY_ON_ID); + } + localLiveViewContent->SetText(liveViewSubText_); + MEDIA_LOGI("GetLocalLiveViewContentc additionalText: %{public}s", liveViewSubText_.c_str()); + capsule.SetTitle(callingLabel_); + } else { + localLiveViewContent->SetText(liveViewText_); + auto countTime = CreateCountTime(); + countTime.SetInitialTime(1); + localLiveViewContent->SetTime(countTime); + localLiveViewContent->addFlag(NotificationLocalLiveViewContent::LiveViewContentInner::TIME); + } localLiveViewContent->SetCapsule(capsule); localLiveViewContent->addFlag(NotificationLocalLiveViewContent::LiveViewContentInner::CAPSULE); - auto countTime = NotificationTime(); - countTime.SetInitialTime(1); - countTime.SetIsCountDown(false); - countTime.SetIsPaused(false); - countTime.SetIsInTitle(true); - - localLiveViewContent->SetTime(countTime); - localLiveViewContent->addFlag(NotificationLocalLiveViewContent::LiveViewContentInner::TIME); - auto basicButton = NotificationLocalLiveViewButton(); basicButton.addSingleButtonName(BUTTON_NAME_STOP); std::shared_ptr pixelMapStopSpr = GetPixelMap(ICON_PATH_STOP); @@ -2472,6 +2534,20 @@ std::shared_ptr ScreenCaptureServer::GetLocalL return localLiveViewContent; } +void ScreenCaptureServer::SetupCapsule(NotificationCapsule& capsule) +{ + capsule.SetBackgroundColor(BACK_GROUND_COLOR); + capsulePxSize_ = static_cast(capsuleVpSize_ * density_); + + std::shared_ptr pixelMapCapSpr; + if (isSystemUI2_) { + pixelMapCapSpr = GetPixelMapSvg(ICON_PATH_CAPSULE_STOP_2_0, capsulePxSize_, capsulePxSize_); + } else { + pixelMapCapSpr = GetPixelMapSvg(ICON_PATH_CAPSULE_STOP, capsulePxSize_, capsulePxSize_); + } + capsule.SetIcon(pixelMapCapSpr); +} + std::shared_ptr ScreenCaptureServer::GetPixelMap(std::string path) { uint32_t errorCode = 0; @@ -2518,7 +2594,12 @@ void ScreenCaptureServer::UpdateMicrophoneEnabled() request.SetUnremovable(true); request.SetInProgress(true); - std::shared_ptr pixelMapTotalSpr = GetPixelMap(ICON_PATH_CAPSULE_STOP); + std::shared_ptr pixelMapTotalSpr; + if (isSystemUI2_) { + pixelMapTotalSpr = GetPixelMap(ICON_PATH_CAPSULE_STOP_2_0); + } else { + pixelMapTotalSpr = GetPixelMap(ICON_PATH_CAPSULE_STOP); + } request.SetLittleIcon(pixelMapTotalSpr); request.SetBadgeIconStyle(NotificationRequest::BadgeStyle::LITTLE); @@ -2531,24 +2612,31 @@ void ScreenCaptureServer::UpdateMicrophoneEnabled() void ScreenCaptureServer::UpdateLiveViewContent() { localLiveViewContent_->SetType(1); - localLiveViewContent_->SetText(liveViewText_); auto capsule = NotificationCapsule(); capsule.SetBackgroundColor(BACK_GROUND_COLOR); - std::shared_ptr pixelMapCapSpr = GetPixelMap(ICON_PATH_CAPSULE_STOP); + std::shared_ptr pixelMapCapSpr; + if (isSystemUI2_) { + pixelMapCapSpr = GetPixelMap(ICON_PATH_CAPSULE_STOP_2_0); + } else { + pixelMapCapSpr = GetPixelMap(ICON_PATH_CAPSULE_STOP); + } capsule.SetIcon(pixelMapCapSpr); + if (GetSCServerDataType() == DataType::ORIGINAL_STREAM) { + localLiveViewContent_->SetTitle(liveViewText_); + localLiveViewContent_->SetText(liveViewSubText_); + capsule.SetTitle(callingLabel_); + } else { + localLiveViewContent_->SetText(liveViewText_); + auto countTime = CreateCountTime(); + + localLiveViewContent_->SetTime(countTime); + localLiveViewContent_->addFlag(NotificationLocalLiveViewContent::LiveViewContentInner::TIME); + } localLiveViewContent_->SetCapsule(capsule); localLiveViewContent_->addFlag(NotificationLocalLiveViewContent::LiveViewContentInner::CAPSULE); - auto countTime = NotificationTime(); - countTime.SetIsCountDown(false); - countTime.SetIsPaused(false); - countTime.SetIsInTitle(true); - - localLiveViewContent_->SetTime(countTime); - localLiveViewContent_->addFlag(NotificationLocalLiveViewContent::LiveViewContentInner::TIME); - auto basicButton = NotificationLocalLiveViewButton(); basicButton.addSingleButtonName(BUTTON_NAME_MIC); if (micCount_.load() % MICROPHONE_STATE_COUNT == MICROPHONE_OFF) { @@ -2567,6 +2655,29 @@ void ScreenCaptureServer::UpdateLiveViewContent() localLiveViewContent_->addFlag(NotificationLocalLiveViewContent::LiveViewContentInner::BUTTON); } +NotificationTime ScreenCaptureServer::CreateCountTime() +{ + auto countTime = NotificationTime(); + countTime.SetIsCountDown(false); + countTime.SetIsPaused(false); + countTime.SetIsInTitle(true); + return countTime; +} + +void ScreenCaptureServer::GetSystemUIFlag() +{ + const std::string systemUITag = "persist.systemui.live2"; + std::string systemUI2; + int32_t systemUIRes = OHOS::system::GetStringParameter(systemUITag, systemUI2, "false"); + if (systemUIRes != 0) { + MEDIA_LOGI("Failed to get systemUI flag, Res: %{public}d", systemUIRes); + isSystemUI2_ = false; + } else { + isSystemUI2_ = (systemUI2 == "true"); + MEDIA_LOGI("get systemUI flag, Res: %{public}d, isSystemUI2_: %{public}d", systemUIRes, isSystemUI2_); + } +} + void ScreenCaptureServer::GetDumpFlag() { const std::string dumpTag = "sys.media.screenCapture.dump.enable"; @@ -2583,6 +2694,7 @@ 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_); @@ -2726,6 +2838,7 @@ int32_t ScreenCaptureServer::CreateVirtualScreen(const std::string &name, sptrStartAbility(want); + MEDIA_LOGI("DestroyPrivacySheet StartAbility end %{public}d", ret); + if (ret != ERR_OK) { + MEDIA_LOGE("Failed to start ability to destroy privacy sheet, error code : %{public}d", ret); + } + + return ret == ERR_OK; +} + bool ScreenCaptureServer::DestroyPopWindow() { if (captureState_ != AVScreenCaptureState::POPUP_WINDOW) { @@ -4027,6 +4167,72 @@ int32_t ScreenCaptureServer::SetScreenCaptureStrategy(ScreenCaptureStrategy stra return MSERR_OK; } +std::shared_ptr ScreenCaptureServer::GetWantAgent( + const std::string& callingLabel, + int32_t sessionId) +{ + MEDIA_LOGI("GetWantAgent, setWantAgent"); + auto want = std::make_shared(); + AppExecFwk::ElementName element("", + GetScreenCaptureSystemParam()["const.multimedia.screencapture.screenrecorderbundlename"], + "com.huawei.hmos.screenrecorder.PrivacyControlAbility"); + want->SetElement(element); + want->SetParam("appLabel", callingLabel); + want->SetParam("sessionId", sessionId); + std::vector> wants; + wants.push_back(want); + MEDIA_LOGI("GetWantAgent, setWantAgent set all params"); + std::vector flags; + flags.push_back(AbilityRuntime::WantAgent::WantAgentConstant::Flags::UPDATE_PRESENT_FLAG); + AbilityRuntime::WantAgent::WantAgentInfo wantAgentInfo(0, + AbilityRuntime::WantAgent::WantAgentConstant::OperationType::START_ABILITY, + flags, wants, nullptr); + MEDIA_LOGI("GetWantAgent, setWantAgent create wantAgentInfo"); + MEDIA_LOGI("GetWantAgent, setWantAgent get wantAgent"); + return OHOS::AbilityRuntime::WantAgent::WantAgentHelper::GetWantAgent(wantAgentInfo); +} + +void ScreenCaptureServer::SetPublishRequest( + const std::shared_ptr& localLiveViewContent, + int32_t notificationId, NotificationRequest& request) +{ + std::shared_ptr notificationContent = + std::make_shared(localLiveViewContent); + + request.SetSlotType(NotificationConstant::SlotType::LIVE_VIEW); + request.SetNotificationId(notificationId); + request.SetContent(notificationContent); + request.SetCreatorUid(AV_SCREEN_CAPTURE_SESSION_UID); + request.SetOwnerUid(AV_SCREEN_CAPTURE_SESSION_UID); + request.SetUnremovable(true); + request.SetInProgress(true); +} + +void ScreenCaptureServer::SystemPrivacyProtected(ScreenId& virtualScreenId, bool systemPrivacyProtectionSwitch) +{ + std::vector screenIds; + screenIds.push_back(virtualScreenId); + auto ret = ScreenManager::GetInstance().SetScreenSkipProtectedWindow(screenIds, systemPrivacyProtectionSwitch); + if (ret == DMError::DM_OK || ret == DMError::DM_ERROR_DEVICE_NOT_SUPPORT) { + MEDIA_LOGI("SystemPrivacyProtected SetScreenSkipProtectedWindow success"); + } else { + MEDIA_LOGI("SystemPrivacyProtected SetScreenSkipProtectedWindow failed, ret: %{public}d", ret); + } +} + +void ScreenCaptureServer::AppPrivacyProtected(ScreenId& virtualScreenId, bool appPrivacyProtectionSwitch) +{ + std::vector privacyWindowTags; + privacyWindowTags.push_back("TAG_SCREEN_PROTECTION_SENSITIVE_APP"); + auto ret = ScreenManager::GetInstance().SetScreenPrivacyWindowTagSwitch(virtualScreenId, + privacyWindowTags, appPrivacyProtectionSwitch); + if (ret == DMError::DM_OK || ret == DMError::DM_ERROR_DEVICE_NOT_SUPPORT) { + MEDIA_LOGI("AppPrivacyProtected SetScreenSkipProtectedWindow success"); + } else { + MEDIA_LOGI("AppPrivacyProtected SetScreenSkipProtectedWindow failed, ret: %{public}d", ret); + } +} + ScreenCaptureObserverCallBack::ScreenCaptureObserverCallBack( std::weak_ptr screenCaptureServer): taskQueObserverCb_("NotifyStopSc") { diff --git a/services/services/screen_capture/server/screen_capture_server.h b/services/services/screen_capture/server/screen_capture_server.h index b99f5ca9904378824c25812d49ccacc0ff56ca15..159a698424d3f1bd08887949d4efb6c7add6407c 100644 --- a/services/services/screen_capture/server/screen_capture_server.h +++ b/services/services/screen_capture/server/screen_capture_server.h @@ -44,10 +44,9 @@ public: static std::shared_ptr CreateScreenCaptureNewInstance(); static int32_t ReportAVScreenCaptureUserChoice(int32_t sessionId, const std::string &content); static int32_t GetRunningScreenCaptureInstancePid(std::list &pidList); + static int32_t GetAVScreenCaptureConfigurableParameters(int32_t sessionId, std::string &resultStr); static void GetChoiceFromJson(Json::Value &root, const std::string &content, std::string key, std::string &value); - static void GetBoxSelectedFromJson(Json::Value &root, const std::string &content, std::string key, - bool &checkBoxSelected); - static void PrepareSelectWindow(Json::Value &root, std::shared_ptr &server); + static void GetValueFromJson(Json::Value &root, const std::string &content, std::string key, bool &value); static void AddScreenCaptureServerMap(int32_t sessionId, std::weak_ptr server); static void RemoveScreenCaptureServerMap(int32_t sessionId); static bool CheckScreenCaptureSessionIdLimit(int32_t curAppUid); @@ -104,6 +103,12 @@ public: void SetSessionId(int32_t sessionId); int32_t OnReceiveUserPrivacyAuthority(bool isAllowed); int32_t StopScreenCaptureByEvent(AVScreenCaptureStateCode stateCode); + std::shared_ptr GetWantAgent(const std::string& callingLabel, + int32_t sessionId); + void SetPublishRequest(const std::shared_ptr& localLiveViewContent, + int32_t notificationId, NotificationRequest& request); + void SystemPrivacyProtected(ScreenId& virtualScreenId, bool systemPrivacyProtectionSwitch); + void AppPrivacyProtected(ScreenId& virtualScreenId, bool appPrivacyProtectionSwitch); #ifdef SUPPORT_CALL int32_t TelCallStateUpdated(bool isInTelCall); int32_t TelCallAudioStateUpdated(bool isInTelCallAudio); @@ -188,6 +193,7 @@ private: void CloseFd(); void ReleaseInner(); void GetDumpFlag(); + void GetSystemUIFlag(); int32_t SetMicrophoneOn(); int32_t SetMicrophoneOff(); @@ -213,6 +219,10 @@ private: int32_t StartPrivacyWindow(); void SetCaptureConfig(CaptureMode captureMode, int32_t missionId = -1); // -1 invalid ScreenScaleMode GetScreenScaleMode(const AVScreenCaptureFillMode &fillMode); + int32_t HandlePopupWindowCase(Json::Value& root, const std::string &content); + int32_t HandleStreamDataCase(Json::Value& root, const std::string &content); + void PrepareSelectWindow(Json::Value &root); + #ifdef PC_STANDARD bool CheckCaptureSpecifiedWindowForSelectWindow(); void SendConfigToUIParams(AAFwk::Want& want); @@ -232,6 +242,7 @@ private: int32_t StartNotification(); std::shared_ptr GetLocalLiveViewContent(); void UpdateLiveViewContent(); + NotificationTime CreateCountTime(); std::shared_ptr GetPixelMap(std::string path); std::shared_ptr GetPixelMapSvg(std::string path, int32_t width, int32_t height); void ResSchedReportData(int64_t value, std::unordered_map payload); @@ -251,6 +262,7 @@ private: int32_t OnTelCallStop(); #endif bool DestroyPopWindow(); + bool DestroyPrivacySheet(); void StopNotStartedScreenCapture(AVScreenCaptureStateCode stateCode); int32_t RegisterWindowLifecycleListener(std::vector windowIdList); int32_t UnRegisterWindowLifecycleListener(); @@ -260,6 +272,7 @@ private: int32_t SetCaptureAreaInner(uint64_t displayId, OHOS::Rect area); bool CheckDisplayArea(uint64_t displayId, OHOS::Rect area); void PrepareUserSelectionInfo(ScreenCaptureUserSelectionInfo &selectionInfo); + void SetupCapsule(NotificationCapsule& capslue); private: std::mutex mutex_; @@ -275,6 +288,8 @@ private: bool checkBoxSelected_ = false; bool showShareSystemAudioBox_ = false; bool isInnerAudioBoxSelected_ = true; + bool appPrivacyProtectionSwitch_ = true; + bool systemPrivacyProtectionSwitch_ = true; std::vector surfaceIdList_ = {}; std::vector surfaceTypeList_ = {}; std::atomic stopAcquireAudioBufferFromAudio_ = false; @@ -284,6 +299,7 @@ private: int32_t notificationId_ = 0; std::string callingLabel_; std::string liveViewText_; + std::string liveViewSubText_; std::atomic micCount_{0}; float density_ = 0.0f; int32_t capsuleVpSize_ = 18; @@ -301,6 +317,7 @@ private: sptr consumer_ = nullptr; bool isConsumerStart_ = false; bool isDump_ = false; + bool isSystemUI2_ = false; ScreenId virtualScreenId_ = SCREEN_ID_INVALID; ScreenId displayScreenId_ = SCREEN_ID_INVALID; std::vector missionIds_; @@ -373,6 +390,10 @@ private: static constexpr int32_t AV_SCREEN_CAPTURE_SESSION_UID = 1013; static constexpr const char* NOTIFICATION_SCREEN_RECORDING_TITLE_ID = "notification_screen_recording_title"; static constexpr const char* QUOTATION_MARKS_STRING = "\""; + static constexpr const char* NOTIFICATION_SCREEN_RECORDING_PRIVACY_ON_ID = + "notification_screen_recording_privacy_on"; + static constexpr const char* NOTIFICATION_SCREEN_RECORDING_PRIVACY_OFF_ID = + "notification_screen_recording_privacy_off"; static constexpr int64_t MAX_INNER_AUDIO_TIMEOUT_IN_NS = 2000000000; // 2s static constexpr int64_t AUDIO_INTERVAL_IN_NS = 20000000; // 20ms static constexpr int64_t NEG_AUDIO_INTERVAL_IN_NS = -20000000; // 20ms diff --git a/test/unittest/screen_capture_test/screen_capture_service_function_unittest/server/src/screen_capture_server_function_unittest.cpp b/test/unittest/screen_capture_test/screen_capture_service_function_unittest/server/src/screen_capture_server_function_unittest.cpp index bb79d29923d1a3367fc2c8c1ebe4681abaf6ca59..438e657795444b7bd39dce62cb227f4037099665 100644 --- a/test/unittest/screen_capture_test/screen_capture_service_function_unittest/server/src/screen_capture_server_function_unittest.cpp +++ b/test/unittest/screen_capture_test/screen_capture_service_function_unittest/server/src/screen_capture_server_function_unittest.cpp @@ -2655,5 +2655,171 @@ HWTEST_F(ScreenCaptureServerFunctionTest, SetVirtualScreenAutoRotation_001, Test screenCaptureServer_->captureConfig_.dataType = DataType::ORIGINAL_STREAM; EXPECT_EQ(screenCaptureServer_->SetVirtualScreenAutoRotation(), MSERR_OK); } + +HWTEST_F(ScreenCaptureServerFunctionTest, GetValueFromJson_001, TestSize.Level2) +{ + Json::Value root; + std::string content = R"({"isEnable": "true"})"; + std::strinf key = "isEnable"; + bool value = false; + screenCaptureServer_->GetValueFromJson(root, content, key, value); + EXPECT_EQ(value, true); +} + +HWTEST_F(ScreenCaptureServerFunctionTest, GetValueFromJson_002, TestSize.Level2) +{ + Json::Value root; + std::string content = R"({"isEnable": "true"})"; + std::strinf key = "Enable"; + bool value = false; + screenCaptureServer_->GetValueFromJson(root, content, key, value); + EXPECT_EQ(value, false); +} + +HWTEST_F(ScreenCaptureServerFunctionTest, GetValueFromJson_003, TestSize.Level2) +{ + Json::Value root; + std::string content = ""; + std::strinf key = "Enable"; + bool value = false; + screenCaptureServer_->GetValueFromJson(root, content, key, value); + EXPECT_EQ(value, false); +} + +HWTEST_F(ScreenCaptureServerFunctionTest, GetValueFromJson_004, TestSize.Level2) +{ + Json::Value root; + std::string content = R"({"isEnable": "true"})"; + std::strinf key = "isEnable"; + bool value = false; + screenCaptureServer_->GetValueFromJson(root, content, key, value); + EXPECT_EQ(value, false); +} + +HWTEST_F(ScreenCaptureServerFunctionTest, SystemPrivacyProtected_001, TestSize.Level2) +{ + ScreenId virtualScreenId = 1; + bool systemPrivacyProtectionSwitch = true; + screenCaptureServer_->SystemPrivacyProtected(virtualScreenId, systemPrivacyProtectionSwitch); + EXPECT_EQ(screenCaptureServer_->captureState_, AVScreenCaptureState::CREATED); +} + +HWTEST_F(ScreenCaptureServerFunctionTest, GetLocalLiveViewContent_001, TestSize.Level2) +{ + std::string callingLabel_ = "TestApp"; + screenCaptureServer_->callingLabel_ = callingLabel_; + auto result = screenCaptureServer_->GetLocalLiveViewContent(); + std::string expectedTitle = "\"TestApp\" 正在使用屏幕"; + EXPECT_EQ(result->GetText(), expectedTitle); +} + +HWTEST_F(ScreenCaptureServerFunctionTest, GetLocalLiveViewContent_002, TestSize.Level2) +{ + std::string callingLabel_ = "TestApp"; + screenCaptureServer_->callingLabel_ = callingLabel_; + screenCaptureServer_->SetDataType(DataType::ORIGINAL_STREAM); + auto result = screenCaptureServer_->GetLocalLiveViewContent(); + std::string expectedTitle = "\"TestApp\" 正在使用屏幕"; + EXPECT_EQ(result->GetTitle(), expectedTitle); +} + +HWTEST_F(ScreenCaptureServerFunctionTest, GetLocalLiveViewContent_003, TestSize.Level2) +{ + std::string callingLabel_ = "TestApp"; + screenCaptureServer_->callingLabel_ = callingLabel_; + screenCaptureServer_->systemPrivacyProtectionSwitch_ = true; + screenCaptureServer_->SetDataType(DataType::ORIGINAL_STREAM); + auto result = screenCaptureServer_->GetLocalLiveViewContent(); + std::string expectedTitle = "\"TestApp\" 正在使用屏幕"; + EXPECT_EQ(result->GetTitle(), expectedTitle); +} + +HWTEST_F(ScreenCaptureServerFunctionTest, HandleStreamDataCase_001, TestSize.Level2) +{ + Json::Value root; + std::string content = R"( + { + "stopRecording": "true", + "appPrivacyProtectionSwitch": "true", + "systemPrivacyProtectionSwitch": "true" + } + )"; + int32_t result = screenCaptureServer_->HandleStreamDataCase(root, content, screenCaptureServer_); + EXPECT_EQ(result, MSERR_OK); +} + +HWTEST_F(ScreenCaptureServerFunctionTest, HandleStreamDataCase_002, TestSize.Level2) +{ + Json::Value root; + std::string content = R"( + { + "stopRecording": "false", + "appPrivacyProtectionSwitch": "true", + "systemPrivacyProtectionSwitch": "true" + } + )"; + int32_t result = screenCaptureServer_->HandleStreamDataCase(root, content, screenCaptureServer_); + EXPECT_EQ(result, MSERR_OK); +} + +HWTEST_F(ScreenCaptureServerFunctionTest, HandleStreamDataCase_003, TestSize.Level2) +{ + Json::Value root; + std::string content = R"( + { + "stopRecording": "false", + "appPrivacyProtectionSwitch": "true", + "systemPrivacyProtectionSwitch": "false" + } + )"; + int32_t result = screenCaptureServer_->HandleStreamDataCase(root, content, screenCaptureServer_); + EXPECT_EQ(result, MSERR_OK); +} + +HWTEST_F(ScreenCaptureServerFunctionTest, HandleStreamDataCase_004, TestSize.Level2) +{ + Json::Value root; + std::string content = R"( + { + "stopRecording": "false", + "appPrivacyProtectionSwitch": "false", + "systemPrivacyProtectionSwitch": "true" + } + )"; + int32_t result = screenCaptureServer_->HandleStreamDataCase(root, content, screenCaptureServer_); + EXPECT_EQ(result, MSERR_OK); +} + +HWTEST_F(ScreenCaptureServerFunctionTest, HandleStreamDataCase_005, TestSize.Level2) +{ + Json::Value root; + std::string content = R"( + { + "stopRecording": "false", + "appPrivacyProtectionSwitch": "false", + "systemPrivacyProtectionSwitch": "false" + } + )"; + int32_t result = screenCaptureServer_->HandleStreamDataCase(root, content, screenCaptureServer_); + EXPECT_EQ(result, MSERR_OK); +} + +HWTEST_F(ScreenCaptureServerFunctionTest, UpdateMicrophoneEnabled_001, TestSize.Level2) +{ + screenCaptureServer_->SetDataType(DataType::ORIGINAL_STREAM); + screenCaptureServer_->StartNotification(); + screenCaptureServer_->isSystemUI2_ = true; + screenCaptureServer_->UpdateMicrophoneEnabled(); + EXPECT_EQ(screenCaptureServer_->isSystemUI2_, true); +} + +HWTEST_F(ScreenCaptureServerFunctionTest, UpdateMicrophoneEnabled_002, TestSize.Level2) +{ + screenCaptureServer_->SetDataType(DataType::ORIGINAL_STREAM); + screenCaptureServer_->StartNotification(); + screenCaptureServer_->isSystemUI2_ = false; + screenCaptureServer_->UpdateMicrophoneEnabled(); + EXPECT_EQ(screenCaptureServer_->isSystemUI2_, false); +} } // Media } // OHOS \ No newline at end of file diff --git a/test/unittest/screen_capture_test/screen_capture_service_function_unittest/server/src/screen_capture_server_function_unittest_window.cpp b/test/unittest/screen_capture_test/screen_capture_service_function_unittest/server/src/screen_capture_server_function_unittest_window.cpp index 383ffc20f88c2a239df548616fcee496dc895642..91d640559a0f92a9b3b2cdd5899f56f0c7237f63 100644 --- a/test/unittest/screen_capture_test/screen_capture_service_function_unittest/server/src/screen_capture_server_function_unittest_window.cpp +++ b/test/unittest/screen_capture_test/screen_capture_service_function_unittest/server/src/screen_capture_server_function_unittest_window.cpp @@ -250,6 +250,116 @@ HWTEST_F(ScreenCaptureServerFunctionTest, ReportAVScreenCaptureUserChoice_012, T ASSERT_EQ(screenCaptureServer_->isInnerAudioBoxSelected_, false); } +HWTEST_F(ScreenCaptureServerFunctionTest, ReportAVScreenCaptureUserChoice_013, TestSize.Level2) +{ + SetInvalidConfig(); + config_.audioInfo.micCapInfo.audioSampleRate = 16000; + config_.audioInfo.micCapInfo.audioChannels = 2; + config_.audioInfo.micCapInfo.audioSource = AudioCaptureSourceType::SOURCE_DEFAULT; + config_.audioInfo.innerCapInfo.audioSampleRate = 16000; + config_.audioInfo.innerCapInfo.audioChannels = 2; + config_.audioInfo.innerCapInfo.audioSource = AudioCaptureSourceType::ALL_PLAYBACK; + ASSERT_EQ(InitStreamScreenCaptureServer(), MSERR_OK); + int32_t sessionId = screenCaptureServer_->sessionId_; + ASSERT_EQ(StartStreamAudioCapture(), MSERR_OK); + screenCaptureServer_->captureState_ = AVScreenCaptureState::POPUP_WINDOW; + screenCaptureServer_->showShareSystemAudioBox_ = false; + screenCaptureServer_->isInnerAudioBoxSelected_ = false; + std::string choice = + "{\"stopRecording\": \"true\"," + "\"appPrivacyProtectionSwitch\": \"true\"," + "\"systemPrivacyProtectionSwitch\": \"true\"}"; + ASSERT_EQ(screenCaptureServer_->ReportAVScreenCaptureUserChoice(sessionId, choice), MSERR_OK); +} + +HWTEST_F(ScreenCaptureServerFunctionTest, ReportAVScreenCaptureUserChoice_014, TestSize.Level2) +{ + SetInvalidConfig(); + config_.audioInfo.micCapInfo.audioSampleRate = 16000; + config_.audioInfo.micCapInfo.audioChannels = 2; + config_.audioInfo.micCapInfo.audioSource = AudioCaptureSourceType::SOURCE_DEFAULT; + config_.audioInfo.innerCapInfo.audioSampleRate = 16000; + config_.audioInfo.innerCapInfo.audioChannels = 2; + config_.audioInfo.innerCapInfo.audioSource = AudioCaptureSourceType::ALL_PLAYBACK; + ASSERT_EQ(InitStreamScreenCaptureServer(), MSERR_OK); + int32_t sessionId = screenCaptureServer_->sessionId_; + ASSERT_EQ(StartStreamAudioCapture(), MSERR_OK); + screenCaptureServer_->captureState_ = AVScreenCaptureState::POPUP_WINDOW; + screenCaptureServer_->showShareSystemAudioBox_ = false; + screenCaptureServer_->isInnerAudioBoxSelected_ = false; + std::string choice = + "{\"stopRecording\": \"false\"," + "\"appPrivacyProtectionSwitch\": \"true\"," + "\"systemPrivacyProtectionSwitch\": \"true\"}"; + ASSERT_EQ(screenCaptureServer_->ReportAVScreenCaptureUserChoice(sessionId, choice), MSERR_OK); +} + +HWTEST_F(ScreenCaptureServerFunctionTest, ReportAVScreenCaptureUserChoice_015, TestSize.Level2) +{ + SetInvalidConfig(); + config_.audioInfo.micCapInfo.audioSampleRate = 16000; + config_.audioInfo.micCapInfo.audioChannels = 2; + config_.audioInfo.micCapInfo.audioSource = AudioCaptureSourceType::SOURCE_DEFAULT; + config_.audioInfo.innerCapInfo.audioSampleRate = 16000; + config_.audioInfo.innerCapInfo.audioChannels = 2; + config_.audioInfo.innerCapInfo.audioSource = AudioCaptureSourceType::ALL_PLAYBACK; + ASSERT_EQ(InitStreamScreenCaptureServer(), MSERR_OK); + int32_t sessionId = screenCaptureServer_->sessionId_; + ASSERT_EQ(StartStreamAudioCapture(), MSERR_OK); + screenCaptureServer_->captureState_ = AVScreenCaptureState::POPUP_WINDOW; + screenCaptureServer_->showShareSystemAudioBox_ = false; + screenCaptureServer_->isInnerAudioBoxSelected_ = false; + std::string choice = + "{\"stopRecording\": \"false\"," + "\"appPrivacyProtectionSwitch\": \"true\"," + "\"systemPrivacyProtectionSwitch\": \"false\"}"; + ASSERT_EQ(screenCaptureServer_->ReportAVScreenCaptureUserChoice(sessionId, choice), MSERR_OK); +} + +HWTEST_F(ScreenCaptureServerFunctionTest, ReportAVScreenCaptureUserChoice_016, TestSize.Level2) +{ + SetInvalidConfig(); + config_.audioInfo.micCapInfo.audioSampleRate = 16000; + config_.audioInfo.micCapInfo.audioChannels = 2; + config_.audioInfo.micCapInfo.audioSource = AudioCaptureSourceType::SOURCE_DEFAULT; + config_.audioInfo.innerCapInfo.audioSampleRate = 16000; + config_.audioInfo.innerCapInfo.audioChannels = 2; + config_.audioInfo.innerCapInfo.audioSource = AudioCaptureSourceType::ALL_PLAYBACK; + ASSERT_EQ(InitStreamScreenCaptureServer(), MSERR_OK); + int32_t sessionId = screenCaptureServer_->sessionId_; + ASSERT_EQ(StartStreamAudioCapture(), MSERR_OK); + screenCaptureServer_->captureState_ = AVScreenCaptureState::POPUP_WINDOW; + screenCaptureServer_->showShareSystemAudioBox_ = false; + screenCaptureServer_->isInnerAudioBoxSelected_ = false; + std::string choice = + "{\"stopRecording\": \"false\"," + "\"appPrivacyProtectionSwitch\": \"false\"," + "\"systemPrivacyProtectionSwitch\": \"true\"}"; + ASSERT_EQ(screenCaptureServer_->ReportAVScreenCaptureUserChoice(sessionId, choice), MSERR_OK); +} + +HWTEST_F(ScreenCaptureServerFunctionTest, ReportAVScreenCaptureUserChoice_017, TestSize.Level2) +{ + SetInvalidConfig(); + config_.audioInfo.micCapInfo.audioSampleRate = 16000; + config_.audioInfo.micCapInfo.audioChannels = 2; + config_.audioInfo.micCapInfo.audioSource = AudioCaptureSourceType::SOURCE_DEFAULT; + config_.audioInfo.innerCapInfo.audioSampleRate = 16000; + config_.audioInfo.innerCapInfo.audioChannels = 2; + config_.audioInfo.innerCapInfo.audioSource = AudioCaptureSourceType::ALL_PLAYBACK; + ASSERT_EQ(InitStreamScreenCaptureServer(), MSERR_OK); + int32_t sessionId = screenCaptureServer_->sessionId_; + ASSERT_EQ(StartStreamAudioCapture(), MSERR_OK); + screenCaptureServer_->captureState_ = AVScreenCaptureState::POPUP_WINDOW; + screenCaptureServer_->showShareSystemAudioBox_ = false; + screenCaptureServer_->isInnerAudioBoxSelected_ = false; + std::string choice = + "{\"stopRecording\": \"false\"," + "\"appPrivacyProtectionSwitch\": \"false\"," + "\"systemPrivacyProtectionSwitch\": \"false\"}"; + ASSERT_EQ(screenCaptureServer_->ReportAVScreenCaptureUserChoice(sessionId, choice), MSERR_OK); +} + #ifdef SUPPORT_SCREEN_CAPTURE_WINDOW_NOTIFICATION HWTEST_F(ScreenCaptureServerFunctionTest, RequestUserPrivacyAuthority_001, TestSize.Level2) { @@ -442,5 +552,13 @@ HWTEST_F(ScreenCaptureServerFunctionTest, GetDisplayIdOfWindows_002, TestSize.Le screenCaptureServer_->missionIds_ = {0}; ASSERT_EQ(screenCaptureServer_->GetDisplayIdOfWindows(defaultDisplayIdValue), defaultDisplayIdValue); } + +HWTEST_F(ScreenCaptureServerFunctionTest, GetAVScreenCaptureConfigurableParameters_001, TestSize.Level2) +{ + int32_t sessionId = screenCapture_->sessionId_; + std::string resultStr; + ASSERT_EQ(screenCaptureServer_->GetAVScreenCaptureConfigurableParameters(sessionId, resultStr), MSERR_OK); + ASSERT_EQ(resultStr, "{\"appPrivacyProtectionSwitch\":false,\"systemPrivacyProtectionSwitch\":false}\n"); +} } // Media } // OHOS \ No newline at end of file diff --git a/test/unittest/screen_capture_test/screen_capture_unittest/src/screen_capture_unit_test.cpp b/test/unittest/screen_capture_test/screen_capture_unittest/src/screen_capture_unit_test.cpp index 473554c1d28f849020ee355c4ae6252f43b2bd71..247fac0b073a1ee936e4d43795910e9d35ae63f1 100644 --- a/test/unittest/screen_capture_test/screen_capture_unittest/src/screen_capture_unit_test.cpp +++ b/test/unittest/screen_capture_test/screen_capture_unittest/src/screen_capture_unit_test.cpp @@ -2402,5 +2402,51 @@ HWTEST_F(ScreenCaptureUnitTest, screen_capture_with_surface_update_surface, Test MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_with_surface_update_surface after"); } +/** + * @tc.name: screen_capture_specified_window_file_01 + * @tc.desc: do screencapture + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ScreenCaptureUnitTest, screen_capture_config_paramer_01, TestSize.Level2) +{ + MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_config_paramer_01 before"); + std::shared_ptr controller = + ScreenCaptureControllerFactory::CreateScreenCaptureController(); + int32_t sessionId = 0; + std::string resultStr = ""; + controller->GetAVScreenCaptureConfigurableParameters(sessionId, resultStr); + RecorderInfo recorderInfo; + SetRecorderInfo("screen_capture_specified_window_file_01.mp4", recorderInfo); + SetConfigFile(config_, recorderInfo); + AudioCaptureInfo innerCapInfo = { + .audioSampleRate = 16000, + .audioChannels = 2, + .audioSource = AudioCaptureSourceType::ALL_PLAYBACK + }; + config_.audioInfo.innerCapInfo = innerCapInfo; + config_.captureMode = CaptureMode::CAPTURE_SPECIFIED_WINDOW; + std::shared_ptr client_ = OHOS::AAFwk::AbilityManagerClient::GetInstance(); + std::string deviceId = ""; + std::vector missionInfos; + auto result = client_->GetMissionInfos(deviceId, 20, missionInfos); + MEDIA_LOGI("screen_capture_specified_window_file_01 missionInfos size:%{public}s, result:%{public}d", + std::to_string(missionInfos.size()).c_str(), result); + for (OHOS::AAFwk::MissionInfo info : missionInfos) { + MEDIA_LOGI("screen_capture_specified_window_file_01 missionId : %{public}d", info.id); + } + if (missionInfos.size() > 0) { + config_.videoInfo.videoCapInfo.taskIDs.push_back(missionInfos[0].id); + } else { + MEDIA_LOGE("screen_capture_specified_window_file_01 GetMissionInfos failed"); + } + + EXPECT_EQ(MSERR_OK, screenCapture_->Init(config_)); + EXPECT_EQ(MSERR_OK, screenCapture_->StartScreenRecording()); + sleep(RECORDER_TIME); + EXPECT_EQ(MSERR_OK, screenCapture_->StopScreenRecording()); + EXPECT_EQ(MSERR_OK, screenCapture_->Release()); + MEDIA_LOGI("ScreenCaptureUnitTest screen_capture_specified_window_file_01 after"); +} } // namespace Media } // namespace OHOS \ No newline at end of file