/* * Copyright (c) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef UI_APPEARANCE_DARK_MODE_MANAGER_H #define UI_APPEARANCE_DARK_MODE_MANAGER_H #include #include #include "errors.h" #include "nocopyable.h" #include "alarm_timer_manager.h" namespace OHOS::ArkUi::UiAppearance { class DarkModeManager final : public NoCopyable { public: static DarkModeManager &GetInstance(); ErrCode Initialize(const std::function &updateCallback); ErrCode LoadUserSettingData(int32_t userId, bool needUpdateCallback, bool &isDarkMode); void NotifyDarkModeUpdate(int32_t userId, bool isDarkMode); ErrCode OnSwitchUser(int32_t userId); ErrCode RestartTimer(); void Dump(); private: enum DarkModeMode { DARK_MODE_INVALID = -1, DARK_MODE_ALWAYS_LIGHT = 0, DARK_MODE_ALWAYS_DARK = 1, DARK_MODE_CUSTOM_AUTO = 2, DARK_MODE_SIZE, }; struct DarkModeState { DarkModeMode settingMode = DARK_MODE_INVALID; int32_t settingStartTime = -1; int32_t settingEndTime = -1; }; void LoadSettingDataObserversCallback(); ErrCode RegisterSettingDataObserversLocked(int32_t userId) const; void UnregisterSettingDataObserversLocked(int32_t userId) const; void SettingDataDarkModeModeUpdateFunc(const std::string& key, int32_t userId); void SettingDataDarkModeStartTimeUpdateFunc(const std::string& key, int32_t userId); void SettingDataDarkModeEndTimeUpdateFunc(const std::string& key, int32_t userId); ErrCode OnStateChangeLocked(int32_t userId, bool needUpdateCallback, bool &isDarkMode); ErrCode OnStateChangeToAllDayMode(int32_t userId, DarkModeMode darkMode, bool needUpdateCallback, bool &isDarkMode); ErrCode OnStateChangeToCustomAutoMode( int32_t userId, const DarkModeState& state, bool needUpdateCallback, bool &isDarkMode); void OnChangeDarkMode(DarkModeMode mode, int32_t userId) const; ErrCode CreateOrUpdateTimers(int32_t startTime, int32_t endTime, int32_t userId); ErrCode CheckTimerCallbackParams(int32_t startTime, int32_t endTime, int32_t userId); std::mutex settingDataObserversMutex_; std::vector>> settingDataObservers_; int32_t settingDataObserversUserId_ = -1; AlarmTimerManager alarmTimerManager_; std::mutex darkModeStatesMutex_; std::map darkModeStates_; std::function updateCallback_; }; } // namespace OHOS::ArkUi::UiAppearance #endif // UI_APPEARANCE_DARK_MODE_MANAGER_H