!12054 隐私蒙版特性

Merge pull request !12054 from chaos/master
This commit is contained in:
openharmony_ci 2025-01-11 11:41:07 +00:00 committed by Gitee
commit 8027ed86b7
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
15 changed files with 212 additions and 0 deletions

View File

@ -117,6 +117,8 @@ public:
const sptr<IDisplayManagerAgent>& displayManagerAgent);
virtual DMError DestroyVirtualScreen(ScreenId screenId);
virtual DMError SetVirtualScreenSurface(ScreenId screenId, sptr<Surface> surface);
virtual DMError SetScreenPrivacyMaskImage(ScreenId screenId,
const std::shared_ptr<Media::PixelMap>& privacyMaskImg);
virtual DMError SetVirtualMirrorScreenCanvasRotation(ScreenId screenId, bool canvasRotation);
virtual DMError SetVirtualMirrorScreenScaleMode(ScreenId screenId, ScreenScaleMode scaleMode);
virtual bool SetSpecifiedScreenPower(ScreenId screenId, ScreenPowerState state, PowerStateChangeReason reason);

View File

@ -236,6 +236,14 @@ DMError ScreenManagerAdapter::SetVirtualScreenSurface(ScreenId screenId, sptr<Su
return displayManagerServiceProxy_->SetVirtualScreenSurface(screenId, surface->GetProducer());
}
DMError ScreenManagerAdapter::SetScreenPrivacyMaskImage(ScreenId screenId,
const std::shared_ptr<Media::PixelMap>& privacyMaskImg)
{
INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
WLOGFI("DisplayManagerAdapter::SetScreenPrivacyMaskImage");
return displayManagerServiceProxy_->SetScreenPrivacyMaskImage(screenId, privacyMaskImg);
}
DMError ScreenManagerAdapter::SetVirtualMirrorScreenCanvasRotation(ScreenId screenId, bool canvasRotation)
{
INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);

View File

@ -595,6 +595,12 @@ DMError ScreenManager::SetVirtualScreenSurface(ScreenId screenId, sptr<Surface>
return SingletonContainer::Get<ScreenManagerAdapter>().SetVirtualScreenSurface(screenId, surface);
}
DMError ScreenManager::SetScreenPrivacyMaskImage(ScreenId screenId,
const std::shared_ptr<Media::PixelMap>& privacyMaskImg)
{
return SingletonContainer::Get<ScreenManagerAdapter>().SetScreenPrivacyMaskImage(screenId, privacyMaskImg);
}
DMError ScreenManager::ResizeVirtualScreen(ScreenId screenId, uint32_t width, uint32_t height)
{
return SingletonContainer::Get<ScreenManagerAdapter>().ResizeVirtualScreen(screenId, width, height);

View File

@ -47,6 +47,10 @@ public:
const sptr<IRemoteObject>& displayManagerAgent) = 0;
virtual DMError DestroyVirtualScreen(ScreenId screenId) = 0;
virtual DMError SetVirtualScreenSurface(ScreenId screenId, sptr<IBufferProducer> surface) = 0;
virtual DMError SetScreenPrivacyMaskImage(ScreenId screenId, const std::shared_ptr<Media::PixelMap>& privacyMaskImg)
{
return DMError::DM_ERROR_DEVICE_NOT_SUPPORT;
}
virtual DMError SetVirtualMirrorScreenCanvasRotation(ScreenId screenId, bool rotate) { return DMError::DM_OK; }
virtual DMError SetVirtualMirrorScreenScaleMode(ScreenId screenId, ScreenScaleMode scaleMode)
{

View File

@ -55,6 +55,7 @@ enum class DisplayManagerMessage : unsigned int {
TRANS_ID_SET_VIRTUAL_PIXEL_RATIO_SYSTEM,
TRANS_ID_SET_RESOLUTION,
TRANS_ID_GET_DENSITY_IN_CURRENT_RESOLUTION,
TRANS_ID_SET_SCREEN_PRIVACY_MASKIMAGE,
TRANS_ID_SCREENGROUP_BASE = 1100,
TRANS_ID_SCREEN_MAKE_MIRROR = TRANS_ID_SCREENGROUP_BASE,
TRANS_ID_SCREEN_MAKE_MIRROR_WITH_REGION,

View File

@ -22,6 +22,7 @@
#include "screen_group.h"
#include "wm_single_instance.h"
#include "wm_single_instance.h"
#include <pixel_map.h>
namespace OHOS::Rosen {
class ScreenManager : public RefBase {
@ -209,6 +210,15 @@ public:
* @return DM_OK means set success, others means set failed.
*/
DMError SetVirtualScreenSurface(ScreenId screenId, sptr<Surface> surface);
/**
* @brief Set privacy image.
*
* @param screenId Screen id.
* @param privacyMaskImg PixelMap object.
* @return DM_OK means set success, others means set failed.
*/
DMError SetScreenPrivacyMaskImage(ScreenId screenId, const std::shared_ptr<Media::PixelMap>& privacyMaskImg);
/**
* @brief Resize virtual screen

View File

@ -53,6 +53,8 @@ ohos_shared_library("screen_napi") {
"graphic_surface:surface", # use for SurfaceUtils
"hilog:libhilog",
"hitrace:hitrace_meter",
"image_framework:image",
"image_framework:image_native",
"napi:ace_napi",
]

View File

@ -28,6 +28,7 @@
#include "singleton_container.h"
#include "surface_utils.h"
#include "window_manager_hilog.h"
#include "pixel_map_napi.h"
namespace OHOS {
namespace Rosen {
@ -135,6 +136,12 @@ static napi_value SetVirtualScreenSurface(napi_env env, napi_callback_info info)
return (me != nullptr) ? me->OnSetVirtualScreenSurface(env, info) : nullptr;
}
static napi_value SetScreenPrivacyMaskImage(napi_env env, napi_callback_info info)
{
JsScreenManager* me = CheckParamsAndGetThis<JsScreenManager>(env, info);
return (me != nullptr) ? me->OnSetScreenPrivacyMaskImage(env, info) : nullptr;
}
static napi_value IsScreenRotationLocked(napi_env env, napi_callback_info info)
{
JsScreenManager* me = CheckParamsAndGetThis<JsScreenManager>(env, info);
@ -1047,6 +1054,58 @@ napi_value OnSetVirtualScreenSurface(napi_env env, napi_callback_info info)
return result;
}
napi_value OnSetScreenPrivacyMaskImage(napi_env env, napi_callback_info info)
{
WLOGI("JsScreenManager::OnSetScreenPrivacyMaskImage is called");
DmErrorCode errCode = DmErrorCode::DM_OK;
int64_t screenId = -1LL;
size_t argc = 4;
std::string errMsg = "";
napi_value argv[4] = {nullptr};
std::shared_ptr<Media::PixelMap> privacyMaskImg;
napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
if (argc < ARGC_ONE) {
WLOGFE("[NAPI]Argc is invalid: %{public}zu", argc);
errMsg = "Invalid args count, need 1 args at least!";
errCode = DmErrorCode::DM_ERROR_INVALID_PARAM;
} else {
if (!ConvertFromJsValue(env, argv[0], screenId)) {
errMsg = "Failed to convert parameter to screen id.";
errCode = DmErrorCode::DM_ERROR_INVALID_PARAM;
}
if (argc > ARGC_ONE && GetType(env, argv[1]) == napi_object) {
privacyMaskImg = OHOS::Media::PixelMapNapi::GetPixelMap(env, argv[1]);
if (privacyMaskImg == nullptr) {
errMsg = "Failed to convert parameter to pixelmap.";
errCode = DmErrorCode::DM_ERROR_INVALID_PARAM;
}
}
}
if (errCode != DmErrorCode::DM_OK) {
WLOGFE("JsScreenManager::OnSetScreenPrivacyMaskImage failed, Invalidate params.");
return NapiThrowError(env, DmErrorCode::DM_ERROR_INVALID_PARAM, errMsg);
}
NapiAsyncTask::CompleteCallback complete = [screenId, privacyMaskImg](napi_env env, NapiAsyncTask& task,
int32_t status) {
auto res = DM_JS_TO_ERROR_CODE_MAP.at(
SingletonContainer::Get<ScreenManager>().SetScreenPrivacyMaskImage(screenId, privacyMaskImg));
if (res != DmErrorCode::DM_OK) {
task.Reject(env, CreateJsError(env, static_cast<int32_t>(res), "SetScreenPrivacyMaskImage failed."));
WLOGFE("JSScreenManager::SetScreenPrivacyMaskImage failed.");
return;
} else {
task.Resolve(env, NapiGetUndefined(env));
WLOGFI("JSScreenManager::SetScreenPrivacyMaskImage success.");
}
};
napi_value lastParam = (privacyMaskImg != nullptr && argc >= ARGC_THREE && GetType(env, argv[ARGC_THREE - 1]) ==
napi_function) ? argv[ARGC_THREE - 1] : argv[ARGC_TWO - 1];
napi_value result = nullptr;
NapiAsyncTask::Schedule("JSScreenManager::SetScreenPrivacyMaskImage", env,
CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
return result;
}
napi_value OnIsScreenRotationLocked(napi_env env, napi_callback_info info)
{
size_t argc = 4;
@ -1337,6 +1396,8 @@ napi_value JsScreenManagerInit(napi_env env, napi_value exportObj)
BindNativeFunction(env, exportObj, "destroyVirtualScreen", moduleName, JsScreenManager::DestroyVirtualScreen);
BindNativeFunction(env, exportObj, "setVirtualScreenSurface", moduleName,
JsScreenManager::SetVirtualScreenSurface);
BindNativeFunction(env, exportObj, "setScreenPrivacyMaskImage", moduleName,
JsScreenManager::SetScreenPrivacyMaskImage);
BindNativeFunction(env, exportObj, "setScreenRotationLocked", moduleName,
JsScreenManager::SetScreenRotationLocked);
BindNativeFunction(env, exportObj, "isScreenRotationLocked", moduleName,

View File

@ -20,6 +20,7 @@
#include <system_ability.h>
#include <mutex>
#include <condition_variable>
#include <pixel_map.h>
#include "common/include/task_scheduler.h"
#include "dm_common.h"
@ -104,6 +105,8 @@ public:
virtual ScreenId CreateVirtualScreen(VirtualScreenOption option,
const sptr<IRemoteObject>& displayManagerAgent) override;
virtual DMError SetVirtualScreenSurface(ScreenId screenId, sptr<IBufferProducer> surface) override;
virtual DMError SetScreenPrivacyMaskImage(ScreenId screenId,
const std::shared_ptr<Media::PixelMap>& privacyMaskImg) override;
virtual DMError SetVirtualMirrorScreenCanvasRotation(ScreenId screenId, bool autoRotate) override;
virtual DMError SetVirtualMirrorScreenScaleMode(ScreenId screenId, ScreenScaleMode scaleMode) override;
virtual DMError DestroyVirtualScreen(ScreenId screenId) override;

View File

@ -47,6 +47,11 @@ public:
{
return DMError::DM_OK;
}
virtual DMError SetScreenPrivacyMaskImage(ScreenId screenId,
const std::shared_ptr<Media::PixelMap>& privacyMaskImg) override
{
return DMError::DM_OK;
}
virtual DMError SetVirtualMirrorScreenCanvasRotation(ScreenId screenId, bool autoRotate) override
{
return DMError::DM_OK;

View File

@ -77,6 +77,9 @@ public:
virtual DMError DestroyVirtualScreen(ScreenId screenId) override;
virtual DMError SetVirtualScreenSurface(ScreenId screenId, sptr<IBufferProducer> surface) override;
virtual DMError SetScreenPrivacyMaskImage(ScreenId screenId,
const std::shared_ptr<Media::PixelMap>& privacyMaskImg) override;
virtual DMError ResizeVirtualScreen(ScreenId screenId, uint32_t width, uint32_t height) override;

View File

@ -3541,6 +3541,46 @@ DMError ScreenSessionManager::SetVirtualScreenSurface(ScreenId screenId, sptr<IB
return DMError::DM_OK;
}
DMError ScreenSessionManager::SetScreenPrivacyMaskImage(ScreenId screenId,
const std::shared_ptr<Media::PixelMap>& privacyMaskImg)
{
if (!(Permission::IsSystemCalling() && Permission::CheckCallingPermission(SCREEN_CAPTURE_PERMISSION)) &&
!SessionPermission::IsShellCall()) {
TLOGE(WmsLogTag::DMS, "Permission Denied! calling clientName: %{public}s, calling pid: %{public}d",
SysCapUtil::GetClientName().c_str(), IPCSkeleton::GetCallingPid());
return DMError::DM_ERROR_NOT_SYSTEM_APP;
}
sptr<ScreenSession> screenSession = GetScreenSession(screenId);
if (screenSession == nullptr) {
TLOGE(WmsLogTag::DMS, "No such screen.");
return DMError::DM_ERROR_INVALID_PARAM;
}
ScreenId rsScreenId;
if (!screenIdManager_.ConvertToRsScreenId(screenId, rsScreenId)) {
TLOGE(WmsLogTag::DMS, "No corresponding rsId.");
return DMError::DM_ERROR_INVALID_PARAM;
}
int32_t res = -1;
if (privacyMaskImg == nullptr) {
TLOGE(WmsLogTag::DMS, "Clearing screen privacy mask image for screenId: %{public}" PRIu64"",
static_cast<uint64_t>(screenId));
res = rsInterface_.SetScreenSecurityMask(rsScreenId, nullptr);
if (res != 0) {
TLOGE(WmsLogTag::DMS, "Fail to set privacy mask image in RenderService");
return DMError::DM_ERROR_RENDER_SERVICE_FAILED;
}
return DMError::DM_OK;
}
TLOGE(WmsLogTag::DMS, "Setting screen privacy mask image for screenId: %{public}" PRIu64"",
static_cast<uint64_t>(screenId));
res = rsInterface_.SetScreenSecurityMask(rsScreenId, privacyMaskImg);
if (res != 0) {
TLOGE(WmsLogTag::DMS, "Fail to set privacy mask image in RenderService");
return DMError::DM_ERROR_RENDER_SERVICE_FAILED;
}
return DMError::DM_OK;
}
DMError ScreenSessionManager::SetVirtualMirrorScreenScaleMode(ScreenId screenId, ScreenScaleMode scaleMode)
{
if (!SessionPermission::IsSystemCalling()) {

View File

@ -1136,6 +1136,47 @@ DMError ScreenSessionManagerProxy::SetVirtualScreenSurface(ScreenId screenId, sp
return static_cast<DMError>(reply.ReadInt32());
}
DMError ScreenSessionManagerProxy::SetScreenPrivacyMaskImage(ScreenId screenId,
const std::shared_ptr<Media::PixelMap>& privacyMaskImg)
{
WLOGFW("SCB: ScreenSessionManagerProxy::SetScreenPrivacyMaskImage: ENTER");
sptr<IRemoteObject> remote = Remote();
if (remote == nullptr) {
WLOGFW("SCB: ScreenSessionManagerProxy::SetScreenPrivacyMaskImage: remote is nullptr");
return DMError::DM_ERROR_REMOTE_CREATE_FAILED;
}
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(GetDescriptor())) {
WLOGFE("SCB: ScreenSessionManagerProxy::SetScreenPrivacyMaskImage: WriteInterfaceToken failed");
return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
}
if (privacyMaskImg != nullptr) {
if (!data.WriteBool(true) || !data.WriteParcelable(privacyMaskImg.get())) {
WLOGFW("SCB: ScreenSessionManagerProxy::SetScreenPrivacyMaskImage: Write privacyMaskImg failed");
return DMError::DM_ERROR_IPC_FAILED;
}
} else {
if (!data.WriteBool(false)) {
WLOGFW("SCB: ScreenSessionManagerProxy::SetScreenPrivacyMaskImage: failed");
return DMError::DM_ERROR_IPC_FAILED;
}
}
if (!data.WriteUint64(static_cast<uint64_t>(screenId))) {
WLOGFW("SCB: ScreenSessionManagerProxy::SetScreenPrivacyMaskImage: Write screenId failed");
return DMError::DM_ERROR_IPC_FAILED;
}
if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SET_SCREEN_PRIVACY_MASKIMAGE),
data, reply, option) != ERR_NONE) {
WLOGFW("SCB: ScreenSessionManagerProxy::SetScreenPrivacyMaskImage: SendRequest failed");
return DMError::DM_ERROR_IPC_FAILED;
}
return static_cast<DMError>(reply.ReadInt32());
}
DMError ScreenSessionManagerProxy::SetVirtualMirrorScreenCanvasRotation(ScreenId screenId, bool canvasRotation)
{
WLOGFW("SCB: ScreenSessionManagerProxy::SetVirtualMirrorScreenCanvasRotation: ENTER");

View File

@ -240,6 +240,20 @@ int32_t ScreenSessionManagerStub::OnRemoteRequest(uint32_t code, MessageParcel&
static_cast<void>(reply.WriteInt32(static_cast<int32_t>(result)));
break;
}
case DisplayManagerMessage::TRANS_ID_SET_SCREEN_PRIVACY_MASKIMAGE: {
ScreenId screenId = static_cast<ScreenId>(data.ReadUint64());
std::shared_ptr<Media::PixelMap> privacyMaskImg{nullptr};
bool isPrivacyMaskImgValid = data.ReadBool();
if (isPrivacyMaskImgValid) {
privacyMaskImg = std::shared_ptr<Media::PixelMap>(data.ReadParcelable<Media::PixelMap>());
DMError result = SetScreenPrivacyMaskImage(screenId, privacyMaskImg);
reply.WriteInt32(static_cast<int32_t>(result));
} else {
DMError result = SetScreenPrivacyMaskImage(screenId, nullptr);
reply.WriteInt32(static_cast<int32_t>(result));
}
break;
}
case DisplayManagerMessage::TRANS_ID_SET_VIRTUAL_SCREEN_CANVAS_ROTATION: {
ScreenId screenId = static_cast<ScreenId>(data.ReadUint64());
bool autoRotate = data.ReadBool();

View File

@ -2906,6 +2906,18 @@ HWTEST_F(ScreenSessionManagerTest, SwitchUser, Function | SmallTest | Level3)
ssm->SwitchUser();
}
/**
* @tc.name: SetScreenPrivacyMaskImage001
* @tc.desc: SetScreenPrivacyMaskImage001
* @tc.type: FUNC
*/
HWTEST_F(ScreenSessionManagerTest, SetScreenPrivacyMaskImage001, Function | SmallTest | Level3)
{
ScreenId screenId = DEFAULT_SCREEN_ID;
auto ret = ssm_->SetScreenPrivacyMaskImage(screenId, nullptr);
ASSERT_EQ(ret, DMError::DM_OK);
}
/**
* @tc.name: ScbClientDeathCallback
* @tc.desc: ScbClientDeathCallback