1 /* 2 * Copyright (c) 2024 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 UI_APPEARANCE_DARK_MODE_TEMP_STATE_MANAGER_H 17 #define UI_APPEARANCE_DARK_MODE_TEMP_STATE_MANAGER_H 18 19 #include "map" 20 #include "mutex" 21 22 namespace OHOS::ArkUi::UiAppearance { 23 class TemporaryColorModeManager { 24 public: 25 void InitData(const int32_t userId); 26 bool IsColorModeTemporary(const int32_t userId); 27 bool IsColorModeNormal(const int32_t userId); 28 bool SetColorModeTemporary(const int32_t userId); 29 bool SetColorModeNormal(const int32_t userId); 30 bool CheckTemporaryStateEffective(const int32_t userId); 31 32 private: 33 std::string TemporaryColorModeAssignUser(const int32_t userId); 34 std::string TemporaryStateStartTimeAssignUser(const int32_t userId); 35 std::string TemporaryStateEndTimeAssignUser(const int32_t userId); 36 static bool IsWithInPreInterval(const int32_t startTime, const int32_t endTime); 37 static void GetTempColorModeTimeInfo(const int32_t settingStartTime, const int32_t settingEndTime, 38 int64_t& tempStateStartTime, int64_t& tempStateEndTime); 39 void SaveTempColorModeInfo(const int32_t userId); 40 enum class TempColorModeType { 41 ColorModeNormal = 0, 42 ColorModeTemp, 43 }; 44 struct TempColorModeInfo { 45 TempColorModeType tempColorMode = TempColorModeType::ColorModeNormal; 46 int64_t keepTemporaryStateStartTime = 0; 47 int64_t keepTemporaryStateEndTime = 0; 48 }; 49 std::mutex multiUserTempColorModeMapMutex_; 50 std::map<int32_t, TempColorModeInfo> multiUserTempColorModeMap_; 51 }; 52 } // namespace OHOS::ArkUi::UiAppearance 53 54 #endif // UI_APPEARANCE_DARK_MODE_TEMP_STATE_MANAGER_H 55