• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <singleton.h>
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 : public DelayedSingleton<NtpUpdateTime> {
30     DECLARE_DELAYED_SINGLETON(NtpUpdateTime);
31 public:
32     DISALLOW_COPY_AND_MOVE(NtpUpdateTime);
33     void RefreshNetworkTimeByTimer(const uint64_t timerid);
34     void UpdateNITZSetTime();
35     void SetSystemTime();
36     void Stop();
37     void Init();
38     int32_t MonitorNetwork();
39 private:
40     bool GetAutoTimeInfoFromFile(autoTimeInfo &info);
41     bool SaveAutoTimeInfoToFile(autoTimeInfo &info);
42     void SubscriberNITZTimeChangeCommonEvent();
43     bool ThreadSetSystemTime();
44     void StartTimer();
45     void RefreshNextTriggerTime();
46     bool CheckStatus();
47     bool IsNITZTimeInvalid();
48     autoTimeInfo autoTimeInfo_;
49     uint64_t timerId_;
50     uint64_t nitzUpdateTimeMili_;
51     uint64_t nextTriggerTime_;
52 };
53 } // MiscServices
54 } // OHOS
55 #endif