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 "maintenance_state.h" 17 18 #include "standby_service_log.h" 19 #include "standby_config_manager.h" 20 #include "iconstraint_manager_adapter.h" 21 #include "istate_manager_adapter.h" 22 #include "standby_service_impl.h" 23 #include "time_provider.h" 24 25 namespace OHOS { 26 namespace DevStandbyMgr { BeginState()27ErrCode MaintenanceState::BeginState() 28 { 29 auto stateManagerPtr = stateManager_.lock(); 30 if (!stateManagerPtr) { 31 STANDBYSERVICE_LOGW("state manager is nullptr, can not begin current state"); 32 return ERR_STATE_MANAGER_IS_NULLPTR; 33 } 34 nextState_ = stateManagerPtr->GetPreState(); 35 int64_t endMaintTimeOut = 0; 36 if (nextState_ == StandbyState::NAP) { 37 endMaintTimeOut = StandbyConfigManager::GetInstance()->GetStandbyParam(NAP_MAINTENANCE_TIMEOUT); 38 } else { 39 endMaintTimeOut = StandbyConfigManager::GetInstance()->GetStandbyParam(SLEEP_MAINT_TIMEOUT); 40 } 41 endMaintTimeOut = endMaintTimeOut * TimeConstant::MSEC_PER_SEC; 42 return StartStateTransitionTimer(endMaintTimeOut); 43 } 44 EndState()45ErrCode MaintenanceState::EndState() 46 { 47 StopTimedTask(TRANSIT_NEXT_STATE_TIMED_TASK); 48 handler_->RemoveTask(TRANSIT_NEXT_STATE_TIMED_TASK); 49 return ERR_OK; 50 } 51 CheckTransitionValid(uint32_t nextState)52bool MaintenanceState::CheckTransitionValid(uint32_t nextState) 53 { 54 if (nextState == StandbyState::DARK) { 55 STANDBYSERVICE_LOGE("can not transit from maintenance to dark"); 56 return false; 57 } 58 return true; 59 } 60 EndEvalCurrentState(bool evalResult)61void MaintenanceState::EndEvalCurrentState(bool evalResult) 62 {} 63 } // namespace DevStandbyMgr 64 } // namespace OHOS