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