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