• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 POWER_MODE_THREAD_H
17 #define POWER_MODE_THREAD_H
18 
19 #include <common_event_data.h>
20 #include <common_event_manager.h>
21 #include <common_event_publish_info.h>
22 #include <common_event_support.h>
23 
24 #include "ipower_mode_callback.h"
25 
26 #define FLAG_FALSE (-1)
27 #define LAST_MODE_FLAG 0
28 #define SETTINGS_PRIVIDER_VALUE_LCD_BRIGHTNESS 99
29 #define SETTINGS_PRIVIDER_VALUE_VIBRATION 1
30 #define SETTINGS_PRIVIDER_VALUE_ROTATION 1
31 
32 namespace OHOS {
33 namespace PowerMgr {
34 class PowerModeModule {
35 public:
36     PowerModeModule();
37     ~PowerModeModule() = default;
38     void SetModeItem(PowerMode mode);
39     PowerMode GetModeItem();
40     void EnableMode(PowerMode mode, bool isBoot = false);
41     void AddPowerModeCallback(const sptr<IPowerModeCallback>& callback);
42     void DelPowerModeCallback(const sptr<IPowerModeCallback>& callback);
43 
44 private:
45     using IntentWant = OHOS::AAFwk::Want;
46 
47     class CallbackManager : public IRemoteObject::DeathRecipient {
48     public:
49         void OnRemoteDied(const wptr<IRemoteObject>& remote) override;
50         void AddCallback(const sptr<IPowerModeCallback>& callback);
51         void RemoveCallback(const sptr<IPowerModeCallback>& callback);
52         void WaitingCallback();
53 
54     private:
55         std::mutex mutex_;
56         std::set<sptr<IRemoteObject>> callbacks_;
57     };
58 
59     PowerMode mode_;
60     uint32_t lastMode_;
61 
62     void Prepare();
63     void PublishPowerModeEvent();
64 
65     sptr<CallbackManager> callbackMgr_;
66     void UpdateModepolicy();
67     void RunAction(bool isBoot);
68     static void SetDisplayOffTime(bool isBoot);
69     static void SetSleepTime([[maybe_unused]] bool isBoot);
70     static void SetAutoAdjustBrightness(bool isBoot);
71     static void SetLcdBrightness(bool isBoot);
72     static void SetVibration(bool isBoot);
73     static void SetWindowRotation(bool isBoot);
74 
75     std::atomic<bool> started_;
76     std::map<uint32_t, int32_t> recoverValue;
77     std::map<uint32_t, int32_t>::iterator recoverValueiter;
78     std::mutex mutex_;
79 };
80 } // namespace PowerMgr
81 } // namespace OHOS
82 #endif // POWER_MODE_THREAD_H
83