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 #ifndef FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_SERVICES_TRANSIENT_TASK_INCLUDE_PKG_DELAY_SUSPEND_INFO_H 17 #define FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_SERVICES_TRANSIENT_TASK_INCLUDE_PKG_DELAY_SUSPEND_INFO_H 18 19 #include <memory> 20 #include <string> 21 22 #include "bgtask_common.h" 23 #include "delay_suspend_info_ex.h" 24 #include "timer_manager.h" 25 26 namespace OHOS { 27 namespace BackgroundTaskMgr { 28 using std::shared_ptr; 29 using std::vector; 30 using std::string; 31 32 class PkgDelaySuspendInfo { 33 public: PkgDelaySuspendInfo(const string & pkg,const int32_t & uid,const shared_ptr<TimerManager> & timerManager)34 PkgDelaySuspendInfo(const string& pkg, const int32_t& uid, const shared_ptr<TimerManager>& timerManager) 35 : pkg_(pkg), uid_(uid), timerManager_(timerManager) {} 36 ~PkgDelaySuspendInfo() = default; 37 ErrCode IsAllowRequest(); 38 void AddRequest(const shared_ptr<DelaySuspendInfoEx>& delayInfo, const int32_t delayTime); 39 void RemoveRequest(const int32_t requestId); 40 int32_t GetRemainDelayTime(const int32_t requestId); 41 void StartAccounting(const int32_t requestId = -1); 42 void StopAccounting(const int32_t requestId); 43 void StopAccountingAll(); 44 void UpdateQuota(bool reset = false); 45 GetPkg()46 inline const string& GetPkg() const 47 { 48 return pkg_; 49 } 50 GetUid()51 inline int32_t GetUid() const 52 { 53 return uid_; 54 } 55 IsRequestEmpty()56 inline bool IsRequestEmpty() const 57 { 58 return requestList_.empty(); 59 } 60 GetRequestSize()61 inline size_t GetRequestSize() const 62 { 63 return requestList_.size(); 64 } 65 GetQuota()66 inline int32_t GetQuota() const 67 { 68 return quota_; 69 } 70 71 private: 72 string pkg_ {""}; 73 int32_t uid_ {-1}; 74 int32_t quota_ {INIT_QUOTA}; 75 int32_t spendTime_ {0}; 76 int32_t baseTime_ {0}; 77 bool isCounting_ {false}; 78 shared_ptr<TimerManager> timerManager_ {nullptr}; 79 vector<shared_ptr<DelaySuspendInfoEx>> requestList_; 80 }; 81 } // namespace BackgroundTaskMgr 82 } // namespace OHOS 83 #endif // FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_SERVICES_TRANSIENT_TASK_INCLUDE_PKG_DELAY_SUSPEND_INFO_H