1ba5c3796Sopenharmony_ci/* 2ba5c3796Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 3ba5c3796Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4ba5c3796Sopenharmony_ci * you may not use this file except in compliance with the License. 5ba5c3796Sopenharmony_ci * You may obtain a copy of the License at 6ba5c3796Sopenharmony_ci * 7ba5c3796Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8ba5c3796Sopenharmony_ci * 9ba5c3796Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10ba5c3796Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11ba5c3796Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12ba5c3796Sopenharmony_ci * See the License for the specific language governing permissions and 13ba5c3796Sopenharmony_ci * limitations under the License. 14ba5c3796Sopenharmony_ci */ 15ba5c3796Sopenharmony_ci 16ba5c3796Sopenharmony_ci#ifndef OHOS_MEMORY_MEMMGR_NANDLIFE_CONTROLLER_H 17ba5c3796Sopenharmony_ci#define OHOS_MEMORY_MEMMGR_NANDLIFE_CONTROLLER_H 18ba5c3796Sopenharmony_ci 19ba5c3796Sopenharmony_ci#include "single_instance.h" 20ba5c3796Sopenharmony_ci#include "event_handler.h" 21ba5c3796Sopenharmony_ci#include "memmgr_config_manager.h" 22ba5c3796Sopenharmony_ci 23ba5c3796Sopenharmony_cinamespace OHOS { 24ba5c3796Sopenharmony_cinamespace Memory { 25ba5c3796Sopenharmony_ciclass NandLifeController { 26ba5c3796Sopenharmony_ci DECLARE_SINGLE_INSTANCE_BASE(NandLifeController); 27ba5c3796Sopenharmony_ci 28ba5c3796Sopenharmony_cipublic: 29ba5c3796Sopenharmony_ci bool Init(); 30ba5c3796Sopenharmony_ciprivate: 31ba5c3796Sopenharmony_ci std::shared_ptr<AppExecFwk::EventHandler> handler_; 32ba5c3796Sopenharmony_ci NandLifeConfig config_; 33ba5c3796Sopenharmony_ci 34ba5c3796Sopenharmony_ci unsigned long long DAILY_SWAP_OUT_QUOTA_KB; 35ba5c3796Sopenharmony_ci unsigned long long TOTAL_SWAP_OUT_QUOTA_KB; 36ba5c3796Sopenharmony_ci 37ba5c3796Sopenharmony_ci unsigned long long lastSwapOutKB_ = 0; 38ba5c3796Sopenharmony_ci unsigned long long nowSwapOutKB_ = 0; 39ba5c3796Sopenharmony_ci 40ba5c3796Sopenharmony_ci unsigned long long minsToday_ = 0; 41ba5c3796Sopenharmony_ci unsigned long long swapOutKBToday_ = 0; 42ba5c3796Sopenharmony_ci 43ba5c3796Sopenharmony_ci unsigned long long minsSinceBirth_ = 0; 44ba5c3796Sopenharmony_ci unsigned long long swapOutKBSinceBirth_ = 0; 45ba5c3796Sopenharmony_ci 46ba5c3796Sopenharmony_ci unsigned long long iter_ = 0; 47ba5c3796Sopenharmony_ci 48ba5c3796Sopenharmony_ci NandLifeController(); 49ba5c3796Sopenharmony_ci bool GetEventHandler(); 50ba5c3796Sopenharmony_ci bool IsNandLifeParamExist(); 51ba5c3796Sopenharmony_ci void PrintNandLifeParam(); 52ba5c3796Sopenharmony_ci bool LoadNandLifeParam(); 53ba5c3796Sopenharmony_ci bool IsSwapOutClosedPermently(); 54ba5c3796Sopenharmony_ci bool GetAndValidateNandLifeConfig(); 55ba5c3796Sopenharmony_ci void SetTimer(); 56ba5c3796Sopenharmony_ci void CheckSwapOut(); 57ba5c3796Sopenharmony_ci bool GetSwapOutKBSinceKernelBoot(unsigned long long &ret); 58ba5c3796Sopenharmony_ci bool CheckReachedDailyLimit(); 59ba5c3796Sopenharmony_ci bool CheckReachedTotalLimit(); 60ba5c3796Sopenharmony_ci bool SetParameterRetry(const std::string ¶mName, const std::string ¶mValue, int retryTimes); 61ba5c3796Sopenharmony_ci bool UpdateNandLifeParam(); 62ba5c3796Sopenharmony_ci 63ba5c3796Sopenharmony_ci void OpenSwapOutTemporarily(const std::string &reason); 64ba5c3796Sopenharmony_ci void CloseSwapOutTemporarily(const std::string &reason); 65ba5c3796Sopenharmony_ci void OpenSwapOutPermanently(); 66ba5c3796Sopenharmony_ci void CloseSwapOutPermanently(); 67ba5c3796Sopenharmony_ci}; 68ba5c3796Sopenharmony_ci} // namespace Memory 69ba5c3796Sopenharmony_ci} // namespace OHOS 70ba5c3796Sopenharmony_ci#endif // OHOS_MEMORY_MEMMGR_NANDLIFE_CONTROLLER_H 71