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