• 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 #include "system_ability_definition.h"
30 
31 #include "standby_service_stub.h"
32 #include "single_instance.h"
33 
34 namespace OHOS {
35 namespace DevStandbyMgr {
36 enum class ServiceRunningState {
37     STATE_NOT_START,
38     STATE_RUNNING
39 };
40 
41 class StandbyService final : public SystemAbility, public StandbyServiceStub {
42     DECLARE_SYSTEM_ABILITY(StandbyService);
43     DECLARE_SINGLE_INSTANCE(StandbyService);
44 public:
45     StandbyService(const int32_t systemAbilityId, bool runOnCreate);
46     void OnStart() final;
47     void OnStop() final;
48 
49     ErrCode SubscribeStandbyCallback(const sptr<IStandbyServiceSubscriber>& subscriber) override;
50     ErrCode UnsubscribeStandbyCallback(const sptr<IStandbyServiceSubscriber>& subscriber) override;
51     ErrCode ApplyAllowResource(const sptr<ResourceRequest>& resourceRequest) override;
52     ErrCode UnapplyAllowResource(const sptr<ResourceRequest>& resourceRequest) override;
53     ErrCode GetAllowList(uint32_t allowType, std::vector<AllowInfo>& allowInfoList,
54         uint32_t reasonCode) override;
55     ErrCode IsDeviceInStandby(bool& isStandby) override;
56     ErrCode ReportWorkSchedulerStatus(bool started, int32_t uid, const std::string& bundleName) override;
57     ErrCode GetRestrictList(uint32_t restrictType, std::vector<AllowInfo>& restrictInfoList,
58         uint32_t reasonCode) override;
59     ErrCode IsStrategyEnabled(const std::string& strategyName, bool& isEnabled) override;
60     ErrCode ReportDeviceStateChanged(DeviceStateType type, bool enabled) override;
61     int32_t Dump(int32_t fd, const std::vector<std::u16string>& args) override;
62     void AddPluginSysAbilityListener(int32_t systemAbilityId);
63     ErrCode NotifySystemAbilityStatusChanged(bool isAdded, int32_t systemAbilityId);
64     ErrCode HandleEvent(const uint32_t resType, const int64_t value, const std::string &sceneInfo) override;
65 
66 private:
67     void DumpUsage(std::string& result);
68     void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override;
69     void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override;
70 
71 private:
72     std::mutex systemAbilityLock_ {};
73     ServiceRunningState state_ {ServiceRunningState::STATE_NOT_START};
74     uint32_t dependsReady_ = 0;
75     std::mutex listenedSALock_ {};
76 };
77 }  // namespace DevStandbyMgr
78 }  // namespace OHOS
79 #endif  // FOUNDATION_RESOURCESCHEDULE_STANDBY_SERVICE_SERVICES_CORE_INCLUDE_STANDBY_SERVICE_H