• 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 UpdateStatusOff();
35     void UpdateStatusOn();
36     void UpdateNITZSetTime();
37     void SetSystemTime();
38     void Stop();
39     void Init();
40     int32_t MonitorNetwork();
41 private:
42     bool GetAutoTimeInfoFromFile(autoTimeInfo &info);
43     bool SaveAutoTimeInfoToFile(autoTimeInfo &info);
44     void SubscriberNITZTimeChangeCommonEvent();
45     bool ThreadSetSystemTime();
46     void StartTimer();
47     void RefreshNextTriggerTime();
48     bool CheckStatus();
49     bool IsNITZTimeInvalid();
50     autoTimeInfo autoTimeInfo_;
51     uint64_t timerId_;
52     uint64_t nitzUpdateTimeMili_;
53     uint64_t nextTriggerTime_;
54 };
55 } // MiscServices
56 } // OHOS
57 #endif