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 NTP_UPDATE_TIME_H 17 #define NTP_UPDATE_TIME_H 18 19 #include <string> 20 21 namespace OHOS { 22 namespace MiscServices { 23 struct AutoTimeInfo { 24 std::string NTP_SERVER; 25 std::string status; 26 int64_t lastUpdateTime; 27 }; 28 29 class NtpUpdateTime { 30 public: 31 static NtpUpdateTime &GetInstance(); 32 static void SetSystemTime(); 33 void RefreshNetworkTimeByTimer(uint64_t timerId); 34 void UpdateNITZSetTime(); 35 void Stop(); 36 void Init(); 37 int32_t MonitorNetwork(); 38 bool IsValidNITZTime(); 39 40 private: 41 NtpUpdateTime(); 42 static void ChangeNtpServerCallback(const char *key, const char *value, void *context); 43 static bool GetAutoTimeInfoFromFile(AutoTimeInfo &info); 44 static bool SaveAutoTimeInfoToFile(const AutoTimeInfo &info); 45 void SubscriberNITZTimeChangeCommonEvent(); 46 void StartTimer(); 47 void RefreshNextTriggerTime(); 48 bool CheckStatus(); 49 void RegisterNtpServerListener(); 50 51 static AutoTimeInfo autoTimeInfo_; 52 uint64_t timerId_; 53 uint64_t nitzUpdateTimeMilli_; 54 uint64_t nextTriggerTime_; 55 }; 56 } // namespace MiscServices 57 } // namespace OHOS 58 #endif