告警清理,使用 namespace 封装函数和变量

Signed-off-by: chenxingyu (V) <c60039285@china.huawei.com>
This commit is contained in:
chenxingyu (V) 2024-05-27 14:40:56 +08:00
parent b70a793a60
commit 0488b39da5

View File

@ -33,10 +33,36 @@ using OHOS::system::GetParameter;
// developer mode
static const std::string DEVELOPER_MODE_STATE_ON_DEFAULT = "false";
static const std::string DEVELOPER_MODE_PARAMETER = "const.security.developermode.state";
namespace {
const std::string IS_DEVELOPER_MODE = GetParameter(DEVELOPER_MODE_PARAMETER, DEVELOPER_MODE_STATE_ON_DEFAULT);
}
bool GetScreenshotByCmdArgments(CmdArgments& cmdArgments, sptr<Display> display,
std::shared_ptr<OHOS::Media::PixelMap>& pixelMap);
static bool GetScreenshotByCmdArgments(CmdArgments& cmdArgments, sptr<Display> display,
std::shared_ptr<OHOS::Media::PixelMap>& pixelMap)
{
if (!cmdArgments.isWidthSet && !cmdArgments.isHeightSet) {
pixelMap = DisplayManager::GetInstance().GetScreenshot(cmdArgments.displayId); // default width & height
} else {
if (!cmdArgments.isWidthSet) {
cmdArgments.width = display->GetWidth();
std::cout << "process: reset to display's width " << cmdArgments.width << std::endl;
}
if (!cmdArgments.isHeightSet) {
cmdArgments.height = display->GetHeight();
std::cout << "process: reset to display's height " << cmdArgments.height << std::endl;
}
if (!SnapShotUtils::CheckWidthAndHeightValid(cmdArgments.width, cmdArgments.height)) {
std::cout << "error: width " << cmdArgments.width << " height " <<
cmdArgments.height << " invalid!" << std::endl;
return true;
}
const Media::Rect rect = {0, 0, display->GetWidth(), display->GetHeight()};
const Media::Size size = {cmdArgments.width, cmdArgments.height};
constexpr int rotation = 0;
pixelMap = DisplayManager::GetInstance().GetScreenshot(cmdArgments.displayId, rect, size, rotation);
}
return false;
}
int main(int argc, char *argv[])
{
@ -81,31 +107,4 @@ int main(int argc, char *argv[])
cmdArgments.fileName << " as jpeg, width " << pixelMap->GetWidth() <<
", height " << pixelMap->GetHeight() << std::endl;
return 0;
}
bool GetScreenshotByCmdArgments(CmdArgments& cmdArgments, sptr<Display> display,
std::shared_ptr<OHOS::Media::PixelMap>& pixelMap)
{
if (!cmdArgments.isWidthSet && !cmdArgments.isHeightSet) {
pixelMap = DisplayManager::GetInstance().GetScreenshot(cmdArgments.displayId); // default width & height
} else {
if (!cmdArgments.isWidthSet) {
cmdArgments.width = display->GetWidth();
std::cout << "process: reset to display's width " << cmdArgments.width << std::endl;
}
if (!cmdArgments.isHeightSet) {
cmdArgments.height = display->GetHeight();
std::cout << "process: reset to display's height " << cmdArgments.height << std::endl;
}
if (!SnapShotUtils::CheckWidthAndHeightValid(cmdArgments.width, cmdArgments.height)) {
std::cout << "error: width " << cmdArgments.width << " height " <<
cmdArgments.height << " invalid!" << std::endl;
return true;
}
const Media::Rect rect = {0, 0, display->GetWidth(), display->GetHeight()};
const Media::Size size = {cmdArgments.width, cmdArgments.height};
constexpr int rotation = 0;
pixelMap = DisplayManager::GetInstance().GetScreenshot(cmdArgments.displayId, rect, size, rotation);
}
return false;
}