• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "time_service_notify.h"
17 
18 #include "common_event_data.h"
19 #include "common_event_manager.h"
20 #include "common_event_support.h"
21 
22 using namespace OHOS::AAFwk;
23 using namespace OHOS::EventFwk;
24 
25 namespace OHOS {
26 namespace MiscServices {
TimeServiceNotify()27 TimeServiceNotify::TimeServiceNotify(){};
~TimeServiceNotify()28 TimeServiceNotify::~TimeServiceNotify(){};
29 
RepublishEvents()30 bool TimeServiceNotify::RepublishEvents()
31 {
32     TIME_HILOGI(TIME_MODULE_SERVICE, "start to Republish events");
33     auto currentTime = std::chrono::steady_clock::now().time_since_epoch().count();
34     return PublishTimeChangeEvents(currentTime) && PublishTimeZoneChangeEvents(currentTime) &&
35         PublishTimeTickEvents(currentTime);
36 }
37 
PublishEvents(int64_t eventTime,const IntentWant & want,const PublishInfo & publishInfo)38 bool TimeServiceNotify::PublishEvents(int64_t eventTime, const IntentWant &want, const PublishInfo &publishInfo)
39 {
40     TIME_HILOGD(TIME_MODULE_SERVICE, "Start to publish event %{public}s at %{public}lld", want.GetAction().c_str(),
41         static_cast<long long>(eventTime));
42     CommonEventData event(want);
43     if (!CommonEventManager::PublishCommonEvent(event, publishInfo, nullptr)) {
44         TIME_HILOGE(TIME_MODULE_SERVICE, "failed to Publish event %{public}s", want.GetAction().c_str());
45         return false;
46     }
47     TIME_HILOGI(TIME_MODULE_SERVICE, "Publish event %{public}s done", want.GetAction().c_str());
48     return true;
49 }
50 
PublishTimeChangeEvents(int64_t eventTime)51 bool TimeServiceNotify::PublishTimeChangeEvents(int64_t eventTime)
52 {
53     IntentWant timeChangeWant;
54     timeChangeWant.SetAction(CommonEventSupport::COMMON_EVENT_TIME_CHANGED);
55     return PublishEvents(eventTime, timeChangeWant, CommonEventPublishInfo());
56 }
57 
PublishTimeZoneChangeEvents(int64_t eventTime)58 bool TimeServiceNotify::PublishTimeZoneChangeEvents(int64_t eventTime)
59 {
60     IntentWant timeZoneChangeWant;
61     timeZoneChangeWant.SetAction(CommonEventSupport::COMMON_EVENT_TIMEZONE_CHANGED);
62     return PublishEvents(eventTime, timeZoneChangeWant, CommonEventPublishInfo());
63 }
64 
PublishTimeTickEvents(int64_t eventTime)65 bool TimeServiceNotify::PublishTimeTickEvents(int64_t eventTime)
66 {
67     IntentWant timeTickWant;
68     timeTickWant.SetAction(CommonEventSupport::COMMON_EVENT_TIME_TICK);
69     return PublishEvents(eventTime, timeTickWant, CommonEventPublishInfo());
70 }
71 } // namespace MiscServices
72 } // namespace OHOS