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