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 POWERMGR_POWER_MANAGER_POWER_SETTING_HELPER_H
17#define POWERMGR_POWER_MANAGER_POWER_SETTING_HELPER_H
18
19#include "datashare_helper.h"
20#include "errors.h"
21#include "mutex"
22#include "setting_observer.h"
23
24namespace OHOS {
25namespace PowerMgr {
26class SettingProvider : public NoCopyable {
27public:
28    static SettingProvider& GetInstance(int32_t systemAbilityId);
29    ErrCode GetStringValue(const std::string& key, std::string& value);
30    ErrCode GetIntValue(const std::string& key, int32_t& value);
31    ErrCode GetLongValue(const std::string& key, int64_t& value);
32    ErrCode GetBoolValue(const std::string& key, bool& value);
33    ErrCode PutStringValue(const std::string& key, const std::string& value, bool needNotify = true);
34    ErrCode PutIntValue(const std::string& key, int32_t value, bool needNotify = true);
35    ErrCode PutLongValue(const std::string& key, int64_t value, bool needNotify = true);
36    ErrCode PutBoolValue(const std::string& key, bool value, bool needNotify = true);
37    bool IsValidKey(const std::string& key);
38    sptr<SettingObserver> CreateObserver(const std::string& key, SettingObserver::UpdateFunc& func);
39    static void ExecRegisterCb(const sptr<SettingObserver>& observer);
40    ErrCode RegisterObserver(const sptr<SettingObserver>& observer);
41    ErrCode UnregisterObserver(const sptr<SettingObserver>& observer);
42    void UpdateCurrentUserId();
43
44protected:
45    ~SettingProvider() override;
46
47private:
48#ifdef POWER_MANAGER_ENABLE_CHARGING_TYPE_SETTING
49    // AC for Alternating Current, means charing supply
50    // DC for Direct Current, means battery supply
51    static constexpr const char* SETTING_DISPLAY_AC_OFF_TIME_KEY {"settings.display.ac.screen_off_timeout"};
52    static constexpr const char* SETTING_DISPLAY_DC_OFF_TIME_KEY {"settings.display.dc.screen_off_timeout"};
53    static constexpr const char* SETTING_POWER_AC_SUSPEND_SOURCES_KEY {"settings.power.ac.suspend_sources"};
54    static constexpr const char* SETTING_POWER_DC_SUSPEND_SOURCES_KEY {"settings.power.dc.suspend_sources"};
55#else
56    static constexpr const char* SETTING_DISPLAY_OFF_TIME_KEY {"settings.display.screen_off_timeout"};
57    static constexpr const char* SETTING_POWER_SUSPEND_SOURCES_KEY {"settings.power.suspend_sources"};
58#endif
59    static constexpr const char* SETTING_AUTO_ADJUST_BRIGHTNESS_KEY {"settings.display.auto_screen_brightness"};
60    static constexpr const char* SETTING_BRIGHTNESS_KEY {"settings.display.screen_brightness_status"};
61    static constexpr const char* SETTING_VIBRATION_KEY {"physic_navi_haptic_feedback_enabled"};
62    static constexpr const char* SETTING_WINDOW_ROTATION_KEY {"settings.general.accelerometer_rotation_status"};
63    static constexpr const char* SETTING_POWER_WAKEUP_SOURCES_KEY {"settings.power.wakeup_sources"};
64    static constexpr const char* SETTING_INTELL_VOICE_KEY {"intell_voice_trigger_enabled"};
65    static constexpr const char* SETTING_POWER_WAKEUP_DOUBLE_KEY {"settings.power.wakeup_double_click"};
66    static constexpr const char* SETTING_POWER_WAKEUP_PICKUP_KEY {"settings.power.wakeup_pick_up"};
67    static constexpr const char* SETTING_POWER_MODE_KEY  {"settings.power.smart_mode_status"};
68    static constexpr const char* SETTING_POWER_MODE_BACKUP_KEY  {"settings.power.smart_mode_status.backup"};
69    static constexpr const char* SETTING_POWER_WAKEUP_LID_KEY {"settings.power.wakeup_lid"};
70    static SettingProvider* instance_;
71    static std::mutex settingMutex_;
72    static sptr<IRemoteObject> remoteObj_;
73    static int32_t currentUserId_;
74
75    static void Initialize(int32_t systemAbilityId);
76    static std::shared_ptr<DataShare::DataShareHelper> CreateDataShareHelper(const std::string& key);
77    static bool ReleaseDataShareHelper(std::shared_ptr<DataShare::DataShareHelper>& helper);
78    static Uri AssembleUri(const std::string& key);
79    static bool IsNeedMultiUser(const std::string& key);
80    static std::string ReplaceUserIdForUri(int32_t userId);
81};
82} // namespace PowerMgr
83} // namespace OHOS
84#endif // POWERMGR_POWER_MANAGER_POWER_SETTING_HELPER_H
85