1 /*
2  * Copyright (C) 2021-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 NETWORK_SEARCH_INCLUDE_NITZ_UPDATE_H
17 #define NETWORK_SEARCH_INCLUDE_NITZ_UPDATE_H
18 
19 #include <memory>
20 
21 #include "event_handler.h"
22 #include "want.h"
23 
24 namespace OHOS {
25 namespace Telephony {
26 class NetworkSearchManager;
27 class NitzUpdate {
28 public:
29     NitzUpdate(const std::weak_ptr<NetworkSearchManager> &networkSearchManager, int32_t slotId);
30     virtual ~NitzUpdate() = default;
31     void ProcessNitzUpdate(const AppExecFwk::InnerEvent::Pointer &event);
32     void ProcessTimeZone();
33     void AutoTimeChange();
34     void AutoTimeZoneChange();
35     void UpdateCountryCode(std::string &countryCode);
36     struct NetworkTime {
37         int32_t year = 0;
38         int32_t month = 0;
39         int32_t day = 0;
40         int32_t hour = 0;
41         int32_t minute = 0;
42         int32_t second = 0;
43         int32_t offset = 0;
44     };
45 
46 private:
47     void ProcessTime(NetworkTime &networkTime);
48     bool IsValidTime(int64_t networkTime);
49     void SaveTimeZone(std::string &timeZone);
50     void SaveTime(int64_t networkTime);
51     bool IsAutoTimeZone();
52     bool IsAutoTime();
53     bool NitzParse(std::string &nitzStr, NetworkTime &networkTime);
54     bool NitzTimeParse(std::string &strTimeSubs, NetworkTime &networkTime);
55     void PublishCommonEvent(AAFwk::Want &want);
56 
57 private:
58     std::weak_ptr<NetworkSearchManager> networkSearchManager_;
59     static int64_t lastSystemTime_;
60     int32_t slotId_ = 0;
61     static int32_t offset_;
62     static int64_t lastNetworkTime_;
63     static std::string timeZone_;
64 };
65 } // namespace Telephony
66 } // namespace OHOS
67 #endif // NETWORK_SEARCH_INCLUDE_NITZ_UPDATE_H
68