15ccb8f90Sopenharmony_ci/* 25ccb8f90Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 35ccb8f90Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 45ccb8f90Sopenharmony_ci * you may not use this file except in compliance with the License. 55ccb8f90Sopenharmony_ci * You may obtain a copy of the License at 65ccb8f90Sopenharmony_ci * 75ccb8f90Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 85ccb8f90Sopenharmony_ci * 95ccb8f90Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 105ccb8f90Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 115ccb8f90Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 125ccb8f90Sopenharmony_ci * See the License for the specific language governing permissions and 135ccb8f90Sopenharmony_ci * limitations under the License. 145ccb8f90Sopenharmony_ci */ 155ccb8f90Sopenharmony_ci 165ccb8f90Sopenharmony_ci#ifndef POWERMGR_POWER_MANAGER_POWER_SETTING_HELPER_H 175ccb8f90Sopenharmony_ci#define POWERMGR_POWER_MANAGER_POWER_SETTING_HELPER_H 185ccb8f90Sopenharmony_ci 195ccb8f90Sopenharmony_ci#include "datashare_helper.h" 205ccb8f90Sopenharmony_ci#include "errors.h" 215ccb8f90Sopenharmony_ci#include "mutex" 225ccb8f90Sopenharmony_ci#include "setting_observer.h" 235ccb8f90Sopenharmony_ci 245ccb8f90Sopenharmony_cinamespace OHOS { 255ccb8f90Sopenharmony_cinamespace PowerMgr { 265ccb8f90Sopenharmony_ciclass SettingProvider : public NoCopyable { 275ccb8f90Sopenharmony_cipublic: 285ccb8f90Sopenharmony_ci static SettingProvider& GetInstance(int32_t systemAbilityId); 295ccb8f90Sopenharmony_ci ErrCode GetStringValue(const std::string& key, std::string& value); 305ccb8f90Sopenharmony_ci ErrCode GetIntValue(const std::string& key, int32_t& value); 315ccb8f90Sopenharmony_ci ErrCode GetLongValue(const std::string& key, int64_t& value); 325ccb8f90Sopenharmony_ci ErrCode GetBoolValue(const std::string& key, bool& value); 335ccb8f90Sopenharmony_ci ErrCode PutStringValue(const std::string& key, const std::string& value, bool needNotify = true); 345ccb8f90Sopenharmony_ci ErrCode PutIntValue(const std::string& key, int32_t value, bool needNotify = true); 355ccb8f90Sopenharmony_ci ErrCode PutLongValue(const std::string& key, int64_t value, bool needNotify = true); 365ccb8f90Sopenharmony_ci ErrCode PutBoolValue(const std::string& key, bool value, bool needNotify = true); 375ccb8f90Sopenharmony_ci bool IsValidKey(const std::string& key); 385ccb8f90Sopenharmony_ci sptr<SettingObserver> CreateObserver(const std::string& key, SettingObserver::UpdateFunc& func); 395ccb8f90Sopenharmony_ci static void ExecRegisterCb(const sptr<SettingObserver>& observer); 405ccb8f90Sopenharmony_ci ErrCode RegisterObserver(const sptr<SettingObserver>& observer); 415ccb8f90Sopenharmony_ci ErrCode UnregisterObserver(const sptr<SettingObserver>& observer); 425ccb8f90Sopenharmony_ci void UpdateCurrentUserId(); 435ccb8f90Sopenharmony_ci 445ccb8f90Sopenharmony_ciprotected: 455ccb8f90Sopenharmony_ci ~SettingProvider() override; 465ccb8f90Sopenharmony_ci 475ccb8f90Sopenharmony_ciprivate: 485ccb8f90Sopenharmony_ci#ifdef POWER_MANAGER_ENABLE_CHARGING_TYPE_SETTING 495ccb8f90Sopenharmony_ci // AC for Alternating Current, means charing supply 505ccb8f90Sopenharmony_ci // DC for Direct Current, means battery supply 515ccb8f90Sopenharmony_ci static constexpr const char* SETTING_DISPLAY_AC_OFF_TIME_KEY {"settings.display.ac.screen_off_timeout"}; 525ccb8f90Sopenharmony_ci static constexpr const char* SETTING_DISPLAY_DC_OFF_TIME_KEY {"settings.display.dc.screen_off_timeout"}; 535ccb8f90Sopenharmony_ci static constexpr const char* SETTING_POWER_AC_SUSPEND_SOURCES_KEY {"settings.power.ac.suspend_sources"}; 545ccb8f90Sopenharmony_ci static constexpr const char* SETTING_POWER_DC_SUSPEND_SOURCES_KEY {"settings.power.dc.suspend_sources"}; 555ccb8f90Sopenharmony_ci#else 565ccb8f90Sopenharmony_ci static constexpr const char* SETTING_DISPLAY_OFF_TIME_KEY {"settings.display.screen_off_timeout"}; 575ccb8f90Sopenharmony_ci static constexpr const char* SETTING_POWER_SUSPEND_SOURCES_KEY {"settings.power.suspend_sources"}; 585ccb8f90Sopenharmony_ci#endif 595ccb8f90Sopenharmony_ci static constexpr const char* SETTING_AUTO_ADJUST_BRIGHTNESS_KEY {"settings.display.auto_screen_brightness"}; 605ccb8f90Sopenharmony_ci static constexpr const char* SETTING_BRIGHTNESS_KEY {"settings.display.screen_brightness_status"}; 615ccb8f90Sopenharmony_ci static constexpr const char* SETTING_VIBRATION_KEY {"physic_navi_haptic_feedback_enabled"}; 625ccb8f90Sopenharmony_ci static constexpr const char* SETTING_WINDOW_ROTATION_KEY {"settings.general.accelerometer_rotation_status"}; 635ccb8f90Sopenharmony_ci static constexpr const char* SETTING_POWER_WAKEUP_SOURCES_KEY {"settings.power.wakeup_sources"}; 645ccb8f90Sopenharmony_ci static constexpr const char* SETTING_INTELL_VOICE_KEY {"intell_voice_trigger_enabled"}; 655ccb8f90Sopenharmony_ci static constexpr const char* SETTING_POWER_WAKEUP_DOUBLE_KEY {"settings.power.wakeup_double_click"}; 665ccb8f90Sopenharmony_ci static constexpr const char* SETTING_POWER_WAKEUP_PICKUP_KEY {"settings.power.wakeup_pick_up"}; 675ccb8f90Sopenharmony_ci static constexpr const char* SETTING_POWER_MODE_KEY {"settings.power.smart_mode_status"}; 685ccb8f90Sopenharmony_ci static constexpr const char* SETTING_POWER_MODE_BACKUP_KEY {"settings.power.smart_mode_status.backup"}; 695ccb8f90Sopenharmony_ci static constexpr const char* SETTING_POWER_WAKEUP_LID_KEY {"settings.power.wakeup_lid"}; 705ccb8f90Sopenharmony_ci static SettingProvider* instance_; 715ccb8f90Sopenharmony_ci static std::mutex settingMutex_; 725ccb8f90Sopenharmony_ci static sptr<IRemoteObject> remoteObj_; 735ccb8f90Sopenharmony_ci static int32_t currentUserId_; 745ccb8f90Sopenharmony_ci 755ccb8f90Sopenharmony_ci static void Initialize(int32_t systemAbilityId); 765ccb8f90Sopenharmony_ci static std::shared_ptr<DataShare::DataShareHelper> CreateDataShareHelper(const std::string& key); 775ccb8f90Sopenharmony_ci static bool ReleaseDataShareHelper(std::shared_ptr<DataShare::DataShareHelper>& helper); 785ccb8f90Sopenharmony_ci static Uri AssembleUri(const std::string& key); 795ccb8f90Sopenharmony_ci static bool IsNeedMultiUser(const std::string& key); 805ccb8f90Sopenharmony_ci static std::string ReplaceUserIdForUri(int32_t userId); 815ccb8f90Sopenharmony_ci}; 825ccb8f90Sopenharmony_ci} // namespace PowerMgr 835ccb8f90Sopenharmony_ci} // namespace OHOS 845ccb8f90Sopenharmony_ci#endif // POWERMGR_POWER_MANAGER_POWER_SETTING_HELPER_H 85