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