1e0dac50fSopenharmony_ci/*
2e0dac50fSopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd.
3e0dac50fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4e0dac50fSopenharmony_ci * you may not use this file except in compliance with the License.
5e0dac50fSopenharmony_ci * You may obtain a copy of the License at
6e0dac50fSopenharmony_ci *
7e0dac50fSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8e0dac50fSopenharmony_ci *
9e0dac50fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10e0dac50fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11e0dac50fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12e0dac50fSopenharmony_ci * See the License for the specific language governing permissions and
13e0dac50fSopenharmony_ci * limitations under the License.
14e0dac50fSopenharmony_ci */
15e0dac50fSopenharmony_ci
16e0dac50fSopenharmony_ci#include <iostream>
17e0dac50fSopenharmony_ci
18e0dac50fSopenharmony_ci#include "dm_common.h"
19e0dac50fSopenharmony_ci#include "parameters.h"
20e0dac50fSopenharmony_ci#include "screen_manager.h"
21e0dac50fSopenharmony_ci#include "setresolution_utils.h"
22e0dac50fSopenharmony_ci
23e0dac50fSopenharmony_ciusing namespace OHOS;
24e0dac50fSopenharmony_ciusing namespace OHOS::Rosen;
25e0dac50fSopenharmony_ciusing OHOS::system::GetIntParameter;
26e0dac50fSopenharmony_ci
27e0dac50fSopenharmony_ci// ENG mode
28e0dac50fSopenharmony_ciconstexpr int32_t DEBUG_ON_DEFAULT = 0;
29e0dac50fSopenharmony_cistatic const std::string ENG_PARAMETER = "const.debuggable";
30e0dac50fSopenharmony_cistatic const bool IS_ENG_MODE = static_cast<bool>(GetIntParameter(ENG_PARAMETER, DEBUG_ON_DEFAULT));
31e0dac50fSopenharmony_ci
32e0dac50fSopenharmony_ciint main(int argc, char *argv[])
33e0dac50fSopenharmony_ci{
34e0dac50fSopenharmony_ci    CmdArgments cmdArgments;
35e0dac50fSopenharmony_ci
36e0dac50fSopenharmony_ci    if (!SetResolutionUtils::ProcessArgs(argc, argv, cmdArgments)) {
37e0dac50fSopenharmony_ci        return 0;
38e0dac50fSopenharmony_ci    }
39e0dac50fSopenharmony_ci
40e0dac50fSopenharmony_ci    if (!IS_ENG_MODE) {
41e0dac50fSopenharmony_ci        std::cout << "current mode is not debuggable, just return." << std::endl;
42e0dac50fSopenharmony_ci        return 0;
43e0dac50fSopenharmony_ci    }
44e0dac50fSopenharmony_ci
45e0dac50fSopenharmony_ci    if (!cmdArgments.isWidthSet || !cmdArgments.isHeightSet || !cmdArgments.isDpiSet) {
46e0dac50fSopenharmony_ci        std::cout << "Error! Must set width, height and dpi." << std::endl;
47e0dac50fSopenharmony_ci        return 0;
48e0dac50fSopenharmony_ci    }
49e0dac50fSopenharmony_ci    std::cout << "width: " << cmdArgments.width << " height: " << cmdArgments.height <<
50e0dac50fSopenharmony_ci        " dpi: " << cmdArgments.dpi << std::endl;
51e0dac50fSopenharmony_ci
52e0dac50fSopenharmony_ci    std::vector<sptr<Rosen::Screen>> screens;
53e0dac50fSopenharmony_ci    Rosen::ScreenManager::GetInstance().GetAllScreens(screens);
54e0dac50fSopenharmony_ci    if (screens.size() == 0) {
55e0dac50fSopenharmony_ci        return 0;
56e0dac50fSopenharmony_ci    }
57e0dac50fSopenharmony_ci    DMError ret = screens[0]->SetResolution(cmdArgments.width, cmdArgments.height, cmdArgments.dpi);
58e0dac50fSopenharmony_ci    if (ret != DMError::DM_OK) {
59e0dac50fSopenharmony_ci        std::cout<< "Error! SetResolution failed!" << std::endl;
60e0dac50fSopenharmony_ci        return 0;
61e0dac50fSopenharmony_ci    }
62e0dac50fSopenharmony_ci    std::cout<< "SetResolution successful!" << std::endl;
63e0dac50fSopenharmony_ci    return 0;
64e0dac50fSopenharmony_ci}