1 /* 2 * Copyright (c) 2022 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 "rotate_input.h" 17 18 #include "input_manager.h" 19 #include "screen.h" 20 #include "screen_manager.h" 21 #include "wukong_define.h" 22 #include "report.h" 23 namespace OHOS { 24 namespace WuKong { 25 const int ONE = 1; 26 const int TWO = 2; 27 const int THREE = 3; 28 const int FOUR = 4; RotateInput()29RotateInput::RotateInput() : InputAction() 30 { 31 std::shared_ptr<MultimodeInputMsg> multimodeInputMsg = std::make_shared<MultimodeInputMsg>(); 32 multimodeInputMsg->inputType_ = INPUTTYPE_ROTATEINPUT; 33 inputedMsgObject_ = multimodeInputMsg; 34 } 35 ~RotateInput()36RotateInput::~RotateInput() 37 { 38 } 39 OrderInput(const std::shared_ptr<SpcialTestObject>& specialTestObject)40ErrCode RotateInput::OrderInput(const std::shared_ptr<SpcialTestObject>& specialTestObject) 41 { 42 ErrCode result = OHOS::ERR_OK; 43 std::vector<sptr<Rosen::Screen>> screens; 44 Rosen::ScreenManager::GetInstance().GetAllScreens(screens); 45 46 uint32_t orientation = static_cast<uint32_t>((rand() % FOUR) + ONE); 47 switch (orientation) { 48 case ONE: 49 INFO_LOG("Rotate orientation is VERTICAL"); 50 break; 51 case TWO: 52 INFO_LOG("Rotate orientation is HORIZONTAL"); 53 break; 54 case THREE: 55 INFO_LOG("Rotate orientation is REVERSE_VERTICAL"); 56 break; 57 case FOUR: 58 INFO_LOG("Rotate orientation is REVERSE_HORIZONTAL"); 59 break; 60 61 default: 62 break; 63 } 64 if (screens[0] == nullptr) { 65 ERROR_LOG("Failed to get home screen data"); 66 return OHOS::ERR_INVALID_VALUE; 67 } 68 screens[0]->SetOrientation(static_cast<Rosen::Orientation>(orientation)); 69 Report::GetInstance()->SyncInputInfo(inputedMsgObject_); 70 return result; 71 } 72 RandomInput()73ErrCode RotateInput::RandomInput() 74 { 75 ErrCode result = OHOS::ERR_OK; 76 std::vector<sptr<Rosen::Screen>> screens; 77 Rosen::ScreenManager::GetInstance().GetAllScreens(screens); 78 79 uint32_t orientation = static_cast<uint32_t>((rand() % FOUR) + ONE); 80 switch (orientation) { 81 case ONE: 82 INFO_LOG("Rotate orientation is VERTICAL"); 83 break; 84 case TWO: 85 INFO_LOG("Rotate orientation is HORIZONTAL"); 86 break; 87 case THREE: 88 INFO_LOG("Rotate orientation is REVERSE_VERTICAL"); 89 break; 90 case FOUR: 91 INFO_LOG("Rotate orientation is REVERSE_HORIZONTAL"); 92 break; 93 94 default: 95 break; 96 } 97 if (screens.size() == 0) { 98 ERROR_LOG("Failed to get home screen data"); 99 return OHOS::ERR_INVALID_VALUE; 100 } 101 screens[0]->SetOrientation(static_cast<Rosen::Orientation>(orientation)); 102 Report::GetInstance()->SyncInputInfo(inputedMsgObject_); 103 return result; 104 } 105 GetInputInfo()106InputType RotateInput::GetInputInfo() 107 { 108 return INPUTTYPE_ROTATEINPUT; 109 } 110 } // namespace WuKong 111 } // namespace OHOS 112