diff --git a/services/services/screen_capture/server/screen_capture_server.cpp b/services/services/screen_capture/server/screen_capture_server.cpp index ef5238319ddfecae2db76b6fa483e5b8f6c96cb1..7ff1b252af858115fbb0b15438d382e488ecd517 100644 --- a/services/services/screen_capture/server/screen_capture_server.cpp +++ b/services/services/screen_capture/server/screen_capture_server.cpp @@ -61,6 +61,7 @@ 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 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"; @@ -570,6 +571,25 @@ void ScreenCaptureServer::GetChoiceFromJson(Json::Value &root, } } +void ScreenCaptureServer::GetBoxSelectedFromJson(Json::Value &root, + const std::string &content, std::string key, bool &checkBoxSelected) +{ + 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; + } + } + MEDIA_LOGI("GetBoxSelectedFromJson checkBoxSelected: %{public}d", checkBoxSelected); +} + void ScreenCaptureServer::SetCaptureConfig(CaptureMode captureMode, int32_t missionId) { captureConfig_.captureMode = captureMode; @@ -614,6 +634,10 @@ int32_t ScreenCaptureServer::ReportAVScreenCaptureUserChoice(int32_t sessionId, Json::Value root; std::string choice = "false"; GetChoiceFromJson(root, content, std::string("choice"), choice); + + GetBoxSelectedFromJson(root, content, std::string("checkBoxSelected"), server->checkBoxSelected_); + MEDIA_LOGI("ReportAVScreenCaptureUserChoice checkBoxSelected: %{public}d", server->checkBoxSelected_); + if (USER_CHOICE_ALLOW.compare(choice) == 0) { PrepareSelectWindow(root, server); int32_t ret = server->OnReceiveUserPrivacyAuthority(true); @@ -1905,6 +1929,14 @@ int32_t ScreenCaptureServer::StartScreenCaptureInner(bool isPrivacyAuthorityEnab isPrivacyAuthorityEnabled_ = isPrivacyAuthorityEnabled; captureState_ = AVScreenCaptureState::POPUP_WINDOW; isScreenCaptureAuthority_ = CheckPrivacyWindowSkipPermission(); + + if (GetSCServerDataType() == DataType::ORIGINAL_STREAM) { + showSensitiveCheckBox_ = true; + checkBoxSelected_ = true; + } + MEDIA_LOGI("StartScreenCaptureInner showSensitiveCheckBox: %{public}d, checkBoxSelected: %{public}d", + showSensitiveCheckBox_, checkBoxSelected_); + if (!isScreenCaptureAuthority_ && IsUserPrivacyAuthorityNeeded()) { ret = RequestUserPrivacyAuthority(); if (ret != MSERR_OK) { @@ -2009,6 +2041,10 @@ int32_t ScreenCaptureServer::StartPrivacyWindow() comStr += std::to_string(appInfo_.appUid); comStr += "\",\"appLabel\":\""; comStr += callingLabel_; + comStr += "\",\"showSensitiveCheckBox\":\""; + comStr += std::to_string(showSensitiveCheckBox_); + comStr += "\",\"checkBoxSelected\":\""; + comStr += std::to_string(checkBoxSelected_); comStr += "\"}"; AAFwk::Want want; @@ -2022,6 +2058,8 @@ int32_t ScreenCaptureServer::StartPrivacyWindow() want.SetParam("params", comStr); want.SetParam("appLabel", callingLabel_); want.SetParam("sessionId", sessionId_); + want.SetParam("showSensitiveCheckBox", showSensitiveCheckBox_); + want.SetParam("checkBoxSelected", checkBoxSelected_); SendConfigToUIParams(want); ret = AAFwk::AbilityManagerClient::GetInstance()->StartAbility(want); MEDIA_LOGI("StartAbility end %{public}d, DeviceType : PC", ret); @@ -2376,7 +2414,7 @@ int32_t ScreenCaptureServer::StartStreamHomeVideoCapture() int32_t ScreenCaptureServer::CreateVirtualScreen(const std::string &name, sptr consumer) { MediaTrace trace("ScreenCaptureServer::CreateVirtualScreen"); - MEDIA_LOGI("CreateVirtualScreen Start"); + MEDIA_LOGI("0x%{public}06" PRIXPTR " CreateVirtualScreen Start", FAKE_POINTER(this)); isConsumerStart_ = false; VirtualScreenOption virScrOption = InitVirtualScreenOption(name, consumer); sptr display = Rosen::DisplayManager::GetInstance().GetDefaultDisplaySync(); @@ -2395,6 +2433,16 @@ int32_t ScreenCaptureServer::CreateVirtualScreen(const std::string &name, sptr= 0, MSERR_UNKNOWN, "CreateVirtualScreen failed, invalid screenId"); + if (captureConfig_.dataType == DataType::ORIGINAL_STREAM && checkBoxSelected_) { + MEDIA_LOGI("CreateVirtualScreen checkBoxSelected: %{public}d", checkBoxSelected_); + std::vector screenIds; + screenIds.push_back(virtualScreenId_); + auto ret = ScreenManager::GetInstance().SetScreenSkipProtectedWindow(screenIds, true); + CHECK_AND_RETURN_RET_LOG(ret == DMError::DM_OK || ret == DMError::DM_ERROR_DEVICE_NOT_SUPPORT, MSERR_UNKNOWN, + "0x%{public}06" PRIXPTR " SetScreenSkipProtectedWindow failed, ret: %{public}d", FAKE_POINTER(this), ret); + MEDIA_LOGI("0x%{public}06" PRIXPTR " SetScreenSkipProtectedWindow success", FAKE_POINTER(this)); + } + if (!showCursor_) { MEDIA_LOGI("CreateVirtualScreen without cursor"); int32_t ret = ShowCursorInner(); diff --git a/services/services/screen_capture/server/screen_capture_server.h b/services/services/screen_capture/server/screen_capture_server.h index 74d40053b83f320b77d2c7f705488053347860eb..66a2f2f939d53b3a1bb35b2906e8f5272bf66cc9 100644 --- a/services/services/screen_capture/server/screen_capture_server.h +++ b/services/services/screen_capture/server/screen_capture_server.h @@ -45,6 +45,8 @@ public: static int32_t ReportAVScreenCaptureUserChoice(int32_t sessionId, const std::string &content); static int32_t GetRunningScreenCaptureInstancePid(std::list &pidList); 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 AddScreenCaptureServerMap(int32_t sessionId, std::weak_ptr server); static void RemoveScreenCaptureServerMap(int32_t sessionId); @@ -244,6 +246,8 @@ private: bool showCursor_ = true; bool isMicrophoneSwitchTurnOn_ = true; bool isPrivacyAuthorityEnabled_ = false; + bool showSensitiveCheckBox_ = false; + bool checkBoxSelected_ = false; std::vector surfaceIdList_ = {}; int32_t sessionId_ = 0; diff --git a/test/unittest/screen_capture_test/screen_capture_service_function_unittest/server/src/screen_capture_server_function_unittest_multiInstance.cpp b/test/unittest/screen_capture_test/screen_capture_service_function_unittest/server/src/screen_capture_server_function_unittest_multiInstance.cpp index cc7ae3de9dad09ec3fa1d54c3567979a428b789d..a27a35b584bec0699de3dabf3b40d7fe27ed61c0 100644 --- a/test/unittest/screen_capture_test/screen_capture_service_function_unittest/server/src/screen_capture_server_function_unittest_multiInstance.cpp +++ b/test/unittest/screen_capture_test/screen_capture_service_function_unittest/server/src/screen_capture_server_function_unittest_multiInstance.cpp @@ -756,5 +756,50 @@ HWTEST_F(ScreenCaptureServerFunctionTest, CheckSpecifiedDataTypeNum_002, TestSiz ASSERT_EQ(ScreenCaptureServer::CheckSCServerSpecifiedDataTypeNum(server->appInfo_.appUid, server->captureConfig_.dataType), false); } + +/** +* @tc.name: GetBoxSelectedFromJson_001 +* @tc.desc: content invalid +* @tc.type: FUNC +*/ +HWTEST_F(ScreenCaptureServerFunctionTest, GetBoxSelectedFromJson_001, TestSize.Level2) +{ + Json::Value root; + std::string content = "ghgh%^&%^$*^(}{^af&**)"; + bool value = false; + screenCaptureServer_->GetBoxSelectedFromJson(root, content, "choice", value); + ASSERT_NE(screenCaptureServer_, nullptr); + ASSERT_EQ(value, false); +} + +/** +* @tc.name: GetBoxSelectedFromJson_002 +* @tc.desc: choice valid +* @tc.type: FUNC +*/ +HWTEST_F(ScreenCaptureServerFunctionTest, GetBoxSelectedFromJson_002, TestSize.Level2) +{ + Json::Value root; + std::string content = "{\"choice\": \"true\"}"; + bool value = false; + screenCaptureServer_->GetBoxSelectedFromJson(root, content, "choice", value); + ASSERT_NE(screenCaptureServer_, nullptr); + ASSERT_EQ(value, true); +} + +/** +* @tc.name: GetBoxSelectedFromJson_003 +* @tc.desc: choice invalid +* @tc.type: FUNC +*/ +HWTEST_F(ScreenCaptureServerFunctionTest, GetBoxSelectedFromJson_003, TestSize.Level2) +{ + Json::Value root; + std::string content = "{\"choice\": \"abcd\"}"; + bool value = false; + screenCaptureServer_->GetBoxSelectedFromJson(root, content, "choice", value); + ASSERT_NE(screenCaptureServer_, nullptr); + ASSERT_EQ(value, false); +} } // Media } // OHOS \ No newline at end of file