• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef FOUNDATION_RESOURCESCHEDULE_STANDBY_SERVICE_SERVICES_CORE_INCLUDE_STANDBY_SERVICE_H
17 #define FOUNDATION_RESOURCESCHEDULE_STANDBY_SERVICE_SERVICES_CORE_INCLUDE_STANDBY_SERVICE_H
18 
19 #include <ctime>
20 #include <list>
21 #include <map>
22 #include <memory>
23 #include <mutex>
24 #include <set>
25 #include <string>
26 
27 #include "singleton.h"
28 #include "system_ability.h"
29 
30 #include "istandby_service.h"
31 #include "standby_service_client.h"
32 #include "standby_service_stub.h"
33 #include "singleton.h"
34 
35 namespace OHOS {
36 namespace DevStandbyMgr {
37 enum class ServiceRunningState {
38     STATE_NOT_START,
39     STATE_RUNNING
40 };
41 
42 class StandbyService final : public SystemAbility, public StandbyServiceStub {
43     DECLARE_SYSTEM_ABILITY(StandbyService);
44     DECLARE_DELAYED_SINGLETON(StandbyService);
45 public:
46     StandbyService(const int32_t systemAbilityId, bool runOnCreate);
47     static std::shared_ptr<StandbyService> GetInstance();
48     void OnStart() final;
49     void OnStop() final;
50 
51     ErrCode SubscribeStandbyCallback(const sptr<IStandbyServiceSubscriber>& subscriber,
52         const std::string& subscriberName, const std::string& moduleName) override;
53     ErrCode UnsubscribeStandbyCallback(const sptr<IStandbyServiceSubscriber>& subscriber) override;
54     ErrCode ApplyAllowResource(const ResourceRequest& resourceRequest) override;
55     ErrCode UnapplyAllowResource(const ResourceRequest& resourceRequest) override;
56     ErrCode GetAllowList(uint32_t allowType, std::vector<AllowInfo>& allowInfoList,
57         uint32_t reasonCode) override;
58     ErrCode IsDeviceInStandby(bool& isStandby) override;
59     ErrCode SetNatInterval(uint32_t type, bool enable, uint32_t interval) override;
60     ErrCode DelayHeartBeat(int64_t timestamp) override;
61     ErrCode ReportWorkSchedulerStatus(bool started, int32_t uid, const std::string& bundleName) override;
62     ErrCode GetRestrictList(uint32_t restrictType, std::vector<AllowInfo>& restrictInfoList,
63         uint32_t reasonCode) override;
64     ErrCode IsStrategyEnabled(const std::string& strategyName, bool& isEnabled) override;
65     ErrCode ReportDeviceStateChanged(int32_t type, bool enabled) override;
66     int32_t Dump(int32_t fd, const std::vector<std::u16string>& args) override;
67     void AddPluginSysAbilityListener(int32_t systemAbilityId);
68     ErrCode NotifySystemAbilityStatusChanged(bool isAdded, int32_t systemAbilityId);
69     ErrCode HandleEvent(const uint32_t resType, const int64_t value, const std::string &sceneInfo) override;
70     ErrCode ReportPowerOverused(const std::string &module, uint32_t level) override;
71 
72 private:
73     StandbyService(const StandbyService&) = delete;
74     StandbyService& operator= (const StandbyService&) = delete;
75     StandbyService(StandbyService&&) = delete;
76     StandbyService& operator= (StandbyService&&) = delete;
77     void DumpUsage(std::string& result);
78     void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override;
79     void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override;
80     bool CheckProcessNamePermission(const std::string& processName);
81 
82 private:
83     std::mutex systemAbilityLock_ {};
84     std::atomic<ServiceRunningState> state_ {ServiceRunningState::STATE_NOT_START};
85     std::mutex listenedSALock_ {};
86 };
87 }  // namespace DevStandbyMgr
88 }  // namespace OHOS
89 #endif  // FOUNDATION_RESOURCESCHEDULE_STANDBY_SERVICE_SERVICES_CORE_INCLUDE_STANDBY_SERVICE_H
90