• 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 #include "nitz_subscriber.h"
17 #include "time_common.h"
18 #include "ntp_update_time.h"
19 namespace OHOS {
20 namespace MiscServices {
21 using namespace OHOS::EventFwk;
22 using namespace OHOS::AAFwk;
NITZSubscriber(const OHOS::EventFwk::CommonEventSubscribeInfo & subscriberInfo)23 NITZSubscriber::NITZSubscriber(
24     const OHOS::EventFwk::CommonEventSubscribeInfo &subscriberInfo)
25     : CommonEventSubscriber(subscriberInfo)
26 {
27     memberFuncMap_[UNKNOWN_BROADCAST_EVENT] = &NITZSubscriber::UnknownBroadcast;
28     memberFuncMap_[NITZ_TIME_CHANGED_BROADCAST_EVENT] = &NITZSubscriber::NITZTimeChangeBroadcast;
29     memberFuncMap_[NITZ_TIMEZONE_CHANGED_BROADCAST_EVENT] = &NITZSubscriber::NITZTimezoneChangeBroadcast;
30 }
31 
OnReceiveEvent(const CommonEventData & data)32 void NITZSubscriber::OnReceiveEvent(const CommonEventData &data)
33 {
34     uint32_t code = UNKNOWN_BROADCAST_EVENT;
35     OHOS::EventFwk::Want want = data.GetWant();
36     std::string action = data.GetWant().GetAction();
37     TIME_HILOGD(TIME_MODULE_SERVICE, "receive one broadcast:%{public}s", action.c_str());
38 
39     if (action == CommonEventSupport::COMMON_EVENT_NITZ_TIME_CHANGED) {
40         code = NITZ_TIME_CHANGED_BROADCAST_EVENT;
41     } else {
42         code = UNKNOWN_BROADCAST_EVENT;
43     }
44 
45     auto itFunc = memberFuncMap_.find(code);
46     if (itFunc != memberFuncMap_.end()) {
47         auto memberFunc = itFunc->second;
48         if (memberFunc != nullptr) {
49             return (this->*memberFunc)(data);
50         }
51     }
52 }
53 
UnknownBroadcast(const CommonEventData & data)54 void NITZSubscriber::UnknownBroadcast(const CommonEventData &data)
55 {
56     TIME_HILOGD(TIME_MODULE_SERVICE, "you receive one unknown broadcast!");
57 }
58 
NITZTimeChangeBroadcast(const CommonEventData & data)59 void NITZSubscriber::NITZTimeChangeBroadcast(const CommonEventData &data)
60 {
61     TIME_HILOGD(TIME_MODULE_SERVICE, "NITZ Timezone changed broadcast code:%{public}d", data.GetCode());
62     DelayedSingleton<NtpUpdateTime>::GetInstance()->UpdateNITZSetTime();
63 }
64 
NITZTimezoneChangeBroadcast(const CommonEventData & data)65 void NITZSubscriber::NITZTimezoneChangeBroadcast(const CommonEventData &data)
66 {
67     TIME_HILOGD(TIME_MODULE_SERVICE, "NITZ Time changed broadcast code:%{public}d", data.GetCode());
68 }
69 } // MiscServices
70 } // OHOS