15ccb8f90Sopenharmony_ci/* 25ccb8f90Sopenharmony_ci * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 35ccb8f90Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 45ccb8f90Sopenharmony_ci * you may not use this file except in compliance with the License. 55ccb8f90Sopenharmony_ci * You may obtain a copy of the License at 65ccb8f90Sopenharmony_ci * 75ccb8f90Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 85ccb8f90Sopenharmony_ci * 95ccb8f90Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 105ccb8f90Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 115ccb8f90Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 125ccb8f90Sopenharmony_ci * See the License for the specific language governing permissions and 135ccb8f90Sopenharmony_ci * limitations under the License. 145ccb8f90Sopenharmony_ci */ 155ccb8f90Sopenharmony_ci 165ccb8f90Sopenharmony_ci#include "power_mgr_notify.h" 175ccb8f90Sopenharmony_ci 185ccb8f90Sopenharmony_ci#include <common_event_data.h> 195ccb8f90Sopenharmony_ci#include <common_event_manager.h> 205ccb8f90Sopenharmony_ci#include <common_event_support.h> 215ccb8f90Sopenharmony_ci 225ccb8f90Sopenharmony_ci#include "power_log.h" 235ccb8f90Sopenharmony_ci 245ccb8f90Sopenharmony_ciusing namespace OHOS::AAFwk; 255ccb8f90Sopenharmony_ciusing namespace OHOS::EventFwk; 265ccb8f90Sopenharmony_ci 275ccb8f90Sopenharmony_cinamespace OHOS { 285ccb8f90Sopenharmony_cinamespace PowerMgr { 295ccb8f90Sopenharmony_civoid PowerMgrNotify::RegisterPublishEvents() 305ccb8f90Sopenharmony_ci{ 315ccb8f90Sopenharmony_ci if (publishInfo_ != nullptr) { 325ccb8f90Sopenharmony_ci return; 335ccb8f90Sopenharmony_ci } 345ccb8f90Sopenharmony_ci publishInfo_ = new (std::nothrow)CommonEventPublishInfo(); 355ccb8f90Sopenharmony_ci publishInfo_->SetOrdered(false); 365ccb8f90Sopenharmony_ci screenOffWant_ = new (std::nothrow)IntentWant(); 375ccb8f90Sopenharmony_ci screenOffWant_->SetAction(CommonEventSupport::COMMON_EVENT_SCREEN_OFF); 385ccb8f90Sopenharmony_ci screenOnWant_ = new (std::nothrow)IntentWant(); 395ccb8f90Sopenharmony_ci screenOnWant_->SetAction(CommonEventSupport::COMMON_EVENT_SCREEN_ON); 405ccb8f90Sopenharmony_ci#ifdef POWER_MANAGER_ENABLE_FORCE_SLEEP_BROADCAST 415ccb8f90Sopenharmony_ci enterForceSleepWant_ = new (std::nothrow)IntentWant(); 425ccb8f90Sopenharmony_ci enterForceSleepWant_->SetAction(CommonEventSupport::COMMON_EVENT_ENTER_FORCE_SLEEP); 435ccb8f90Sopenharmony_ci exitForceSleepWant_ = new (std::nothrow)IntentWant(); 445ccb8f90Sopenharmony_ci exitForceSleepWant_->SetAction(CommonEventSupport::COMMON_EVENT_EXIT_FORCE_SLEEP); 455ccb8f90Sopenharmony_ci#endif 465ccb8f90Sopenharmony_ci} 475ccb8f90Sopenharmony_ci 485ccb8f90Sopenharmony_civoid PowerMgrNotify::PublishEvents(int64_t eventTime, sptr<IntentWant> want) 495ccb8f90Sopenharmony_ci{ 505ccb8f90Sopenharmony_ci if ((want == nullptr) || (publishInfo_ == nullptr)) { 515ccb8f90Sopenharmony_ci POWER_HILOGE(COMP_SVC, "Invalid parameter"); 525ccb8f90Sopenharmony_ci return; 535ccb8f90Sopenharmony_ci } 545ccb8f90Sopenharmony_ci CommonEventData event(*want); 555ccb8f90Sopenharmony_ci CommonEventManager::PublishCommonEvent(event, *publishInfo_, nullptr); 565ccb8f90Sopenharmony_ci} 575ccb8f90Sopenharmony_ci 585ccb8f90Sopenharmony_civoid PowerMgrNotify::PublishScreenOffEvents(int64_t eventTime) 595ccb8f90Sopenharmony_ci{ 605ccb8f90Sopenharmony_ci POWER_HILOGI(FEATURE_SUSPEND, "[UL_POWER] Start to publish event %{public}s at %{public}lld", 615ccb8f90Sopenharmony_ci screenOffWant_->GetAction().c_str(), static_cast<long long>(eventTime)); 625ccb8f90Sopenharmony_ci PublishEvents(eventTime, screenOffWant_); 635ccb8f90Sopenharmony_ci POWER_HILOGI(FEATURE_SUSPEND, "[UL_POWER] Publish event %{public}s done", screenOffWant_->GetAction().c_str()); 645ccb8f90Sopenharmony_ci} 655ccb8f90Sopenharmony_ci 665ccb8f90Sopenharmony_civoid PowerMgrNotify::PublishScreenOnEvents(int64_t eventTime) 675ccb8f90Sopenharmony_ci{ 685ccb8f90Sopenharmony_ci POWER_HILOGI(FEATURE_WAKEUP, "[UL_POWER] Start to publish event %{public}s at %{public}lld", 695ccb8f90Sopenharmony_ci screenOnWant_->GetAction().c_str(), static_cast<long long>(eventTime)); 705ccb8f90Sopenharmony_ci PublishEvents(eventTime, screenOnWant_); 715ccb8f90Sopenharmony_ci POWER_HILOGI(FEATURE_WAKEUP, "[UL_POWER] Publish event %{public}s done", screenOnWant_->GetAction().c_str()); 725ccb8f90Sopenharmony_ci} 735ccb8f90Sopenharmony_ci 745ccb8f90Sopenharmony_ci#ifdef POWER_MANAGER_ENABLE_FORCE_SLEEP_BROADCAST 755ccb8f90Sopenharmony_civoid PowerMgrNotify::PublishEnterForceSleepEvents(int64_t eventTime) 765ccb8f90Sopenharmony_ci{ 775ccb8f90Sopenharmony_ci POWER_HILOGI(FEATURE_SUSPEND, "[UL_POWER] Start to publish event %{public}s at %{public}lld", 785ccb8f90Sopenharmony_ci enterForceSleepWant_->GetAction().c_str(), static_cast<long long>(eventTime)); 795ccb8f90Sopenharmony_ci PublishEvents(eventTime, enterForceSleepWant_); 805ccb8f90Sopenharmony_ci POWER_HILOGI( 815ccb8f90Sopenharmony_ci FEATURE_SUSPEND, "[UL_POWER] Publish event %{public}s done", enterForceSleepWant_->GetAction().c_str()); 825ccb8f90Sopenharmony_ci} 835ccb8f90Sopenharmony_ci 845ccb8f90Sopenharmony_civoid PowerMgrNotify::PublishExitForceSleepEvents(int64_t eventTime) 855ccb8f90Sopenharmony_ci{ 865ccb8f90Sopenharmony_ci POWER_HILOGI(FEATURE_WAKEUP, "[UL_POWER] Start to publish event %{public}s at %{public}lld", 875ccb8f90Sopenharmony_ci exitForceSleepWant_->GetAction().c_str(), static_cast<long long>(eventTime)); 885ccb8f90Sopenharmony_ci PublishEvents(eventTime, exitForceSleepWant_); 895ccb8f90Sopenharmony_ci POWER_HILOGI(FEATURE_WAKEUP, "[UL_POWER] Publish event %{public}s done", exitForceSleepWant_->GetAction().c_str()); 905ccb8f90Sopenharmony_ci} 915ccb8f90Sopenharmony_ci#endif 925ccb8f90Sopenharmony_ci} // namespace PowerMgr 935ccb8f90Sopenharmony_ci} // namespace OHOS 94