!10240 添加截屏校验

Merge pull request !10240 from huangji731/master
This commit is contained in:
openharmony_ci 2024-10-27 14:20:52 +00:00 committed by Gitee
commit c2a4716490
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
9 changed files with 105 additions and 56 deletions

View File

@ -51,9 +51,10 @@ extern "C" {
*
* @param { displayId } this display to be captured.
* @param { pixelMap } the pixelMap of the display by id.
* @return { @link DISPLAY_MANAGER_OK } If the operation is successful
* { @link DISPLAY_MANAGER_ERROR_INVALID_PARAM } If Parameter error.
* @return { @link DISPLAY_MANAGER_OK } If the operation is successful.
* { @link DISPLAY_MANAGER_ERROR_NO_PERMISSION } If no permission.
* { @link DISPLAY_MANAGER_ERROR_INVALID_PARAM } If Parameter error.
* { @link DISPLAY_MANAGER_ERROR_DEVICE_NOT_SUPPORTED } If device not support.
* { @link DISPLAY_MANAGER_ERROR_SYSTEM_ABNORMAL } If display manager service works abnormally.
* @syscap SystemCapability.Window.SessionManager.Core
* @since 14

View File

@ -45,7 +45,7 @@
extern "C" {
#endif
/* display name length */
/** display name length */
#define OH_DISPLAY_NAME_LENGTH 32
/**
@ -153,13 +153,13 @@ typedef enum {
* @version 1.0
*/
typedef struct {
/* rect left */
/** rect left */
int32_t left;
/* rect top */
/** rect top */
int32_t top;
/* rect width */
/** rect width */
uint32_t width;
/* rect height */
/** rect height */
uint32_t height;
} NativeDisplayManager_Rect;
@ -170,16 +170,16 @@ typedef struct {
* @version 1.0
*/
typedef struct {
/* waterfall left rect */
/** waterfall left rect */
NativeDisplayManager_Rect left;
/* waterfall top rect */
/** waterfall top rect */
NativeDisplayManager_Rect top;
/* waterfall right rect */
/** waterfall right rect */
NativeDisplayManager_Rect right;
/* waterfall bottom rect */
/** waterfall bottom rect */
NativeDisplayManager_Rect bottom;
} NativeDisplayManager_WaterfallDisplayAreaRects;
@ -190,13 +190,13 @@ typedef struct {
* @version 1.0
*/
typedef struct {
/* boundingRects length */
/** boundingRects length */
int32_t boundingRectsLength;
/* boundingRects info pointer */
/** boundingRects info pointer */
NativeDisplayManager_Rect *boundingRects;
/* waterfallDisplayAreaRects info */
/** waterfallDisplayAreaRects info */
NativeDisplayManager_WaterfallDisplayAreaRects waterfallDisplayAreaRects;
} NativeDisplayManager_CutoutInfo;
@ -236,10 +236,10 @@ typedef enum {
* @version 1.0
*/
typedef struct {
/* hdrFormat length */
/** hdrFormat length */
uint32_t hdrFormatLength;
/* hdrFormat pointer */
/** hdrFormat pointer */
uint32_t *hdrFormats;
} NativeDisplayManager_DisplayHdrFormat;
@ -250,10 +250,10 @@ typedef struct {
* @version 1.0
*/
typedef struct {
/* color space length */
/** color space length */
uint32_t colorSpaceLength;
/* color space pointer */
/** color space pointer */
uint32_t *colorSpaces;
} NativeDisplayManager_DisplayColorSpace;
@ -264,64 +264,64 @@ typedef struct {
* @version 1.0
*/
typedef struct {
/* display id */
/** display id */
uint32_t id;
/* display name */
/** display name */
char name[OH_DISPLAY_NAME_LENGTH + 1];
/* display is alive */
/** display is alive */
bool isAlive;
/* display width */
/** display width */
int32_t width;
/* display height */
/** display height */
int32_t height;
/* display physical width */
/** display physical width */
int32_t physicalWidth;
/* display physical height */
/** display physical height */
int32_t physicalHeight;
/* display refresh rate */
/** display refresh rate */
uint32_t refreshRate;
/* display available width */
/** display available width */
uint32_t availableWidth;
/* display available height */
/** display available height */
uint32_t availableHeight;
/* display density dpi */
/** display density dpi */
float densityDPI;
/* display density pixels */
/** display density pixels */
float densityPixels;
/* display scale density */
/** display scale density */
float scaledDensity;
/* display xdpi*/
/** display xdpi*/
float xDPI;
/* display ydpi */
/** display ydpi */
float yDPI;
/* display rotation */
/** display rotation */
NativeDisplayManager_Rotation rotation;
/* display state */
/** display state */
NativeDisplayManager_DisplayState state;
/* display orientation */
/** display orientation */
NativeDisplayManager_Orientation orientation;
/* display hdr format */
/** display hdr format */
NativeDisplayManager_DisplayHdrFormat *hdrFormat;
/* display color space */
/** display color space */
NativeDisplayManager_DisplayColorSpace *colorSpace;
} NativeDisplayManager_DisplayInfo;
@ -332,10 +332,10 @@ typedef struct {
* @version 1.0
*/
typedef struct {
/* displays length */
/** displays length */
uint32_t displaysLength;
/* displays pointer */
/** displays pointer */
NativeDisplayManager_DisplayInfo *displaysInfo;
} NativeDisplayManager_DisplaysInfo;

View File

@ -272,13 +272,35 @@ napi_value Resolve(napi_env env, std::unique_ptr<Param> &param)
napi_value result;
napi_value error;
napi_value code;
if (param->wret == DmErrorCode::DM_ERROR_INVALID_PARAM) {
bool isThrowError = true;
if (param->wret != DmErrorCode::DM_OK) {
napi_create_error(env, nullptr, nullptr, &error);
napi_create_int32(env, (int32_t)DmErrorCode::DM_ERROR_INVALID_PARAM, &code);
napi_set_named_property(env, error, "DM_ERROR_INVALID_PARAM", code);
napi_create_int32(env, (int32_t)param->wret, &code);
}
switch (param->wret) {
case DmErrorCode::DM_ERROR_NO_PERMISSION:
napi_set_named_property(env, error, "DM_ERROR_NO_PERMISSION", code);
break;
case DmErrorCode::DM_ERROR_INVALID_PARAM:
napi_set_named_property(env, error, "DM_ERROR_INVALID_PARAM", code);
break;
case DmErrorCode::DM_ERROR_DEVICE_NOT_SUPPORT:
napi_set_named_property(env, error, "DM_ERROR_DEVICE_NOT_SUPPORT", code);
break;
case DmErrorCode::DM_ERROR_SYSTEM_INNORMAL:
napi_set_named_property(env, error, "DM_ERROR_SYSTEM_INNORMAL", code);
break;
default:
isThrowError = false;
WLOGFI("screen shot default.");
break;
}
WLOGFI("screen shot ret=%{public}d.", param->wret);
if (isThrowError) {
napi_throw(env, error);
return error;
} else if (param->wret != DmErrorCode::DM_OK) {
}
if (param->wret != DmErrorCode::DM_OK) {
NAPI_CALL(env, napi_get_undefined(env, &result));
return result;
}

View File

@ -53,10 +53,9 @@ void SnapshotDisplayTest::SetUpTestCase()
WLOGFE("GetDefaultDisplay: failed!\n");
return;
}
WLOGI("GetDefaultDisplay: id %" PRIu64", w %d, h %d, fps %u\n", display->GetId(), display->GetWidth(),
display->GetHeight(), display->GetRefreshRate());
defaultId_ = display->GetId();
WLOGI("GetDefaultDisplay: id[%{public}" PRIu64"], w:[%{public}d], h[%{public}d], fps[%{public}u]",
defaultId_, display->GetWidth(), display->GetHeight(), display->GetRefreshRate());
CommonTestUtils::InjectTokenInfoByHapName(0, "com.ohos.systemui", 0);
const char** perms = new const char *[1];
@ -120,7 +119,8 @@ HWTEST_F(SnapshotDisplayTest, ScreenShotCmdValid01, Function | MediumTest | Leve
}
}
(void)system(defaultCmd_.c_str());
const std::string cmd = defaultCmd_ + " -i " + std::to_string(defaultId_) + " -f " + imgPath[0];
(void)system(cmd.c_str());
for (i = 0; i < testTimeCount_; i++) {
if (CheckFileExist(imgPath[i])) { // ok
@ -149,7 +149,7 @@ HWTEST_F(SnapshotDisplayTest, ScreenShotCmdValid02, Function | MediumTest | Leve
}
}
const std::string cmd = defaultCmd_ + " -i " + std::to_string(defaultId_);
const std::string cmd = defaultCmd_ + " -i " + std::to_string(defaultId_) + " -f " + imgPath[0];
(void)system(cmd.c_str());
for (i = 0; i < testTimeCount_; i++) {
@ -251,7 +251,7 @@ HWTEST_F(SnapshotDisplayTest, ScreenShotCmdValid09, Function | MediumTest | Leve
}
}
const std::string cmd = defaultCmd_ + " -t png";
const std::string cmd = defaultCmd_ + " -f " + imgPath[0] + " -t png";
(void)system(cmd.c_str());
for (i = 0; i < testTimeCount_; i++) {

View File

@ -47,6 +47,7 @@ public:
static std::string GetExternalScreenDefaultMode();
static std::vector<DisplayPhysicalResolution> GetAllDisplayPhysicalConfig();
static std::map<FoldDisplayMode, ScrollableParam> GetAllScrollableParam();
static bool IsSupportCapture();
private:
static std::map<int32_t, std::string> xmlNodeMap_;
@ -61,6 +62,7 @@ private:
static uint32_t curvedAreaInLandscape_;
static std::vector<DisplayPhysicalResolution> displayPhysicalResolution_;
static std::map<FoldDisplayMode, ScrollableParam> scrollableParams_;
static bool isSupportCapture_;
static bool IsValidNode(const xmlNode& currNode);
static void ReadEnableConfigInfo(const xmlNodePtr& currNode);

View File

@ -58,7 +58,8 @@ enum XmlNodeElement {
CAST_BUNDLE_NAME,
CAST_ABILITY_NAME,
PHYSICAL_DISPLAY_RESOLUTION,
SCROLLABLE_PARAM
SCROLLABLE_PARAM,
IS_SUPPORT_CAPTURE
};
}
@ -71,6 +72,7 @@ std::vector<DisplayPhysicalResolution> ScreenSceneConfig::displayPhysicalResolut
std::map<FoldDisplayMode, ScrollableParam> ScreenSceneConfig::scrollableParams_;
std::vector<DMRect> ScreenSceneConfig::subCutoutBoundaryRect_;
bool ScreenSceneConfig::isWaterfallDisplay_ = false;
bool ScreenSceneConfig::isSupportCapture_ = false;
bool ScreenSceneConfig::isScreenCompressionEnableInLandscape_ = false;
uint32_t ScreenSceneConfig::curvedAreaInLandscape_ = 0;
std::map<int32_t, std::string> ScreenSceneConfig::xmlNodeMap_ = {
@ -95,7 +97,8 @@ std::map<int32_t, std::string> ScreenSceneConfig::xmlNodeMap_ = {
{CAST_BUNDLE_NAME, "castBundleName"},
{CAST_ABILITY_NAME, "castAbilityName"},
{PHYSICAL_DISPLAY_RESOLUTION, "physicalDisplayResolution"},
{SCROLLABLE_PARAM, "scrollableParam"}
{SCROLLABLE_PARAM, "scrollableParam"},
{IS_SUPPORT_CAPTURE, "isSupportCapture"}
};
@ -177,6 +180,7 @@ void ScreenSceneConfig::ParseNodeConfig(const xmlNodePtr& currNode)
bool enableConfigCheck = (xmlNodeMap_[IS_WATERFALL_DISPLAY] == nodeName) ||
(xmlNodeMap_[IS_CURVED_COMPRESS_ENABLED] == nodeName) ||
(xmlNodeMap_[IS_RIGHT_POWER_BUTTON] == nodeName) ||
(xmlNodeMap_[IS_SUPPORT_CAPTURE] == nodeName) ||
(xmlNodeMap_[SUPPORT_ROTATE_WITH_SCREEN] == nodeName);
bool numberConfigCheck = (xmlNodeMap_[DPI] == nodeName) ||
(xmlNodeMap_[SUB_DPI] == nodeName) ||
@ -360,6 +364,8 @@ void ScreenSceneConfig::ReadEnableConfigInfo(const xmlNodePtr& currNode)
isWaterfallDisplay_ = true;
} else if (xmlNodeMap_[IS_CURVED_COMPRESS_ENABLED] == nodeName) {
isScreenCompressionEnableInLandscape_ = true;
} else if (xmlNodeMap_[IS_SUPPORT_CAPTURE] == nodeName) {
isSupportCapture_ = true;
}
} else {
enableConfig_[nodeName] = false;
@ -508,6 +514,11 @@ bool ScreenSceneConfig::IsWaterfallDisplay()
return isWaterfallDisplay_;
}
bool ScreenSceneConfig::IsSupportCapture()
{
return isSupportCapture_;
}
void ScreenSceneConfig::SetCurvedCompressionAreaInLandscape()
{
if (intNumbersConfig_[xmlNodeMap_[CURVED_AREA_IN_LANDSCAPE]].size() > 0) {

View File

@ -6070,6 +6070,11 @@ std::shared_ptr<Media::PixelMap> ScreenSessionManager::GetScreenCapture(const Ca
*errorCode = DmErrorCode::DM_ERROR_NO_PERMISSION;
return nullptr;
}
if (!ScreenSceneConfig::IsSupportCapture()) {
TLOGW(WmsLogTag::DMS, "device not support capture.");
*errorCode = DmErrorCode::DM_ERROR_DEVICE_NOT_SUPPORT;
return nullptr;
}
if (!Permission::CheckCallingPermission(CUSTOM_SCREEN_CAPTURE_PERMISSION) && !SessionPermission::IsShellCall()) {
TLOGE(WmsLogTag::DMS, "Permission Denied! clientName: %{public}s, pid: %{public}d.",
SysCapUtil::GetClientName().c_str(), IPCSkeleton::GetCallingRealPid());

View File

@ -2143,13 +2143,17 @@ HWTEST_F(ScreenSessionManagerProxyTest, GetScreenCapture, Function | SmallTest |
std::shared_ptr<Media::PixelMap> res = nullptr;
CaptureOption option;
option.displayId_ = 0;
DmErrorCode* errorCode = nullptr;
DmErrorCode errorCode = DmErrorCode::DM_OK;
std::function<void()> func = [&]() {
res = screenSessionManagerProxy->GetScreenCapture(option, errorCode);
res = screenSessionManagerProxy->GetScreenCapture(option, &errorCode);
};
func();
if (SceneBoardJudgement::IsSceneBoardEnabled()) {
ASSERT_NE(res, nullptr);
if (errorCode == DmErrorCode::DM_OK) {
ASSERT_NE(res, nullptr);
} else {
ASSERT_EQ(res, nullptr);
}
} else {
ASSERT_EQ(res, nullptr);
}

View File

@ -3119,7 +3119,11 @@ HWTEST_F(ScreenSessionManagerTest, GetScreenCapture, Function | SmallTest | Leve
option.displayId_ = 0;
DmErrorCode errCode;
std::shared_ptr<Media::PixelMap> bitMap = ssm->GetScreenCapture(option, &errCode);
ASSERT_NE(bitMap, nullptr);
if (errCode == DmErrorCode::DM_OK) {
ASSERT_NE(bitMap, nullptr);
} else {
ASSERT_EQ(bitMap, nullptr);
}
}
/**