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