1a69a01cdSopenharmony_ci/* 2a69a01cdSopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 3a69a01cdSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4a69a01cdSopenharmony_ci * you may not use this file except in compliance with the License. 5a69a01cdSopenharmony_ci * You may obtain a copy of the License at 6a69a01cdSopenharmony_ci * 7a69a01cdSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8a69a01cdSopenharmony_ci * 9a69a01cdSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10a69a01cdSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11a69a01cdSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12a69a01cdSopenharmony_ci * See the License for the specific language governing permissions and 13a69a01cdSopenharmony_ci * limitations under the License. 14a69a01cdSopenharmony_ci */ 15a69a01cdSopenharmony_ci 16a69a01cdSopenharmony_ci#include "rotate_input.h" 17a69a01cdSopenharmony_ci 18a69a01cdSopenharmony_ci#include "input_manager.h" 19a69a01cdSopenharmony_ci#include "screen.h" 20a69a01cdSopenharmony_ci#include "screen_manager.h" 21a69a01cdSopenharmony_ci#include "wukong_define.h" 22a69a01cdSopenharmony_ci#include "report.h" 23a69a01cdSopenharmony_cinamespace OHOS { 24a69a01cdSopenharmony_cinamespace WuKong { 25a69a01cdSopenharmony_ciconst int ONE = 1; 26a69a01cdSopenharmony_ciconst int TWO = 2; 27a69a01cdSopenharmony_ciconst int THREE = 3; 28a69a01cdSopenharmony_ciconst int FOUR = 4; 29a69a01cdSopenharmony_ciRotateInput::RotateInput() : InputAction() 30a69a01cdSopenharmony_ci{ 31a69a01cdSopenharmony_ci std::shared_ptr<MultimodeInputMsg> multimodeInputMsg = std::make_shared<MultimodeInputMsg>(); 32a69a01cdSopenharmony_ci multimodeInputMsg->inputType_ = INPUTTYPE_ROTATEINPUT; 33a69a01cdSopenharmony_ci inputedMsgObject_ = multimodeInputMsg; 34a69a01cdSopenharmony_ci} 35a69a01cdSopenharmony_ci 36a69a01cdSopenharmony_ciRotateInput::~RotateInput() 37a69a01cdSopenharmony_ci{ 38a69a01cdSopenharmony_ci} 39a69a01cdSopenharmony_ci 40a69a01cdSopenharmony_ciErrCode RotateInput::OrderInput(const std::shared_ptr<SpcialTestObject>& specialTestObject) 41a69a01cdSopenharmony_ci{ 42a69a01cdSopenharmony_ci ErrCode result = OHOS::ERR_OK; 43a69a01cdSopenharmony_ci std::vector<sptr<Rosen::Screen>> screens; 44a69a01cdSopenharmony_ci Rosen::ScreenManager::GetInstance().GetAllScreens(screens); 45a69a01cdSopenharmony_ci 46a69a01cdSopenharmony_ci uint32_t orientation = static_cast<uint32_t>((rand() % FOUR) + ONE); 47a69a01cdSopenharmony_ci switch (orientation) { 48a69a01cdSopenharmony_ci case ONE: 49a69a01cdSopenharmony_ci INFO_LOG("Rotate orientation is VERTICAL"); 50a69a01cdSopenharmony_ci break; 51a69a01cdSopenharmony_ci case TWO: 52a69a01cdSopenharmony_ci INFO_LOG("Rotate orientation is HORIZONTAL"); 53a69a01cdSopenharmony_ci break; 54a69a01cdSopenharmony_ci case THREE: 55a69a01cdSopenharmony_ci INFO_LOG("Rotate orientation is REVERSE_VERTICAL"); 56a69a01cdSopenharmony_ci break; 57a69a01cdSopenharmony_ci case FOUR: 58a69a01cdSopenharmony_ci INFO_LOG("Rotate orientation is REVERSE_HORIZONTAL"); 59a69a01cdSopenharmony_ci break; 60a69a01cdSopenharmony_ci 61a69a01cdSopenharmony_ci default: 62a69a01cdSopenharmony_ci break; 63a69a01cdSopenharmony_ci } 64a69a01cdSopenharmony_ci if (screens[0] == nullptr) { 65a69a01cdSopenharmony_ci ERROR_LOG("Failed to get home screen data"); 66a69a01cdSopenharmony_ci return OHOS::ERR_INVALID_VALUE; 67a69a01cdSopenharmony_ci } 68a69a01cdSopenharmony_ci screens[0]->SetOrientation(static_cast<Rosen::Orientation>(orientation)); 69a69a01cdSopenharmony_ci Report::GetInstance()->SyncInputInfo(inputedMsgObject_); 70a69a01cdSopenharmony_ci return result; 71a69a01cdSopenharmony_ci} 72a69a01cdSopenharmony_ci 73a69a01cdSopenharmony_ciErrCode RotateInput::RandomInput() 74a69a01cdSopenharmony_ci{ 75a69a01cdSopenharmony_ci ErrCode result = OHOS::ERR_OK; 76a69a01cdSopenharmony_ci std::vector<sptr<Rosen::Screen>> screens; 77a69a01cdSopenharmony_ci Rosen::ScreenManager::GetInstance().GetAllScreens(screens); 78a69a01cdSopenharmony_ci 79a69a01cdSopenharmony_ci uint32_t orientation = static_cast<uint32_t>((rand() % FOUR) + ONE); 80a69a01cdSopenharmony_ci switch (orientation) { 81a69a01cdSopenharmony_ci case ONE: 82a69a01cdSopenharmony_ci INFO_LOG("Rotate orientation is VERTICAL"); 83a69a01cdSopenharmony_ci break; 84a69a01cdSopenharmony_ci case TWO: 85a69a01cdSopenharmony_ci INFO_LOG("Rotate orientation is HORIZONTAL"); 86a69a01cdSopenharmony_ci break; 87a69a01cdSopenharmony_ci case THREE: 88a69a01cdSopenharmony_ci INFO_LOG("Rotate orientation is REVERSE_VERTICAL"); 89a69a01cdSopenharmony_ci break; 90a69a01cdSopenharmony_ci case FOUR: 91a69a01cdSopenharmony_ci INFO_LOG("Rotate orientation is REVERSE_HORIZONTAL"); 92a69a01cdSopenharmony_ci break; 93a69a01cdSopenharmony_ci 94a69a01cdSopenharmony_ci default: 95a69a01cdSopenharmony_ci break; 96a69a01cdSopenharmony_ci } 97a69a01cdSopenharmony_ci if (screens.size() == 0) { 98a69a01cdSopenharmony_ci ERROR_LOG("Failed to get home screen data"); 99a69a01cdSopenharmony_ci return OHOS::ERR_INVALID_VALUE; 100a69a01cdSopenharmony_ci } 101a69a01cdSopenharmony_ci screens[0]->SetOrientation(static_cast<Rosen::Orientation>(orientation)); 102a69a01cdSopenharmony_ci Report::GetInstance()->SyncInputInfo(inputedMsgObject_); 103a69a01cdSopenharmony_ci return result; 104a69a01cdSopenharmony_ci} 105a69a01cdSopenharmony_ci 106a69a01cdSopenharmony_ciInputType RotateInput::GetInputInfo() 107a69a01cdSopenharmony_ci{ 108a69a01cdSopenharmony_ci return INPUTTYPE_ROTATEINPUT; 109a69a01cdSopenharmony_ci} 110a69a01cdSopenharmony_ci} // namespace WuKong 111a69a01cdSopenharmony_ci} // namespace OHOS 112