• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 "notification_decorator.h"
17 #include "battery_log.h"
18 #include "battery_srv_client.h"
19 
20 namespace {
21 static const std::string REVERSE_SUPER_CHARGE_OPEN = "notification.battery.reverse_super_charge_open";
22 static const std::string REVERSE_SUPER_CHARGE_CLOSE = "notification.battery.reverse_super_charge_close";
23 }
24 namespace OHOS {
25 namespace PowerMgr {
PublishNotification()26 bool NotificationDecorator::PublishNotification()
27 {
28     if (batteryNotification_ == nullptr) {
29         BATTERY_HILOGW(COMP_SVC, "batteryNotification_ is nullptr");
30         return false;
31     }
32     batteryNotification_->PublishNotification();
33     return true;
34 }
35 
CancelNotification()36 bool NotificationDecorator::CancelNotification()
37 {
38     if (batteryNotification_ == nullptr) {
39         BATTERY_HILOGW(COMP_SVC, "batteryNotification_ is nullptr");
40         return false;
41     }
42     batteryNotification_->CancelNotification();
43     return true;
44 }
45 
SetActionButton(const std::string & buttonName,const std::string & buttonAction)46 void ButtonDecorator::SetActionButton(const std::string& buttonName, const std::string& buttonAction)
47 {
48     if (batteryNotification_ == nullptr) {
49         BATTERY_HILOGW(COMP_SVC, "batteryNotification_ is nullptr");
50         return;
51     }
52     batteryNotification_->SetActionButton(buttonName, buttonAction);
53     if (buttonAction == REVERSE_SUPER_CHARGE_OPEN) {
54         button_ = std::make_shared<ReverseSuperChargeOpenButton>();
55     } else if (buttonAction == REVERSE_SUPER_CHARGE_CLOSE) {
56         button_ = std::make_shared<ReverseSuperChargeCloseButton>();
57     }
58     if (button_ == nullptr) {
59         BATTERY_HILOGW(COMP_SVC, "button_ is nullptr, buttonName[%{public}s] buttonAction[%{public}s]",
60             buttonName.c_str(), buttonAction.c_str());
61         return;
62     }
63     button_->RegisterButtonEvent(buttonAction);
64 }
65 
RegisterButtonEvent(const std::string & buttonAction)66 void ReverseSuperChargeOpenButton::RegisterButtonEvent(const std::string& buttonAction)
67 {
68     EventHandle onReceiveOpenModeEvent = [this](const OHOS::EventFwk::CommonEventData& data) {
69         this->OpenMode();
70     };
71     buttonCes_.AddEventHandle(buttonAction, onReceiveOpenModeEvent);
72     buttonCes_.RegisterCesEvent();
73 }
74 
OpenMode()75 void ReverseSuperChargeOpenButton::OpenMode()
76 {
77     BatterySrvClient::GetInstance().SetBatteryConfig("reverse_super_charge", "2");
78     BATTERY_HILOGI(COMP_SVC, "onReceiveOpenModeEvent end");
79 }
80 
RegisterButtonEvent(const std::string & buttonAction)81 void ReverseSuperChargeCloseButton::RegisterButtonEvent(const std::string& buttonAction)
82 {
83     EventHandle onReceiveCloseModeEvent = [this](const OHOS::EventFwk::CommonEventData& data) {
84         this->CloseMode();
85     };
86     buttonCes_.AddEventHandle(buttonAction, onReceiveCloseModeEvent);
87     buttonCes_.RegisterCesEvent();
88 }
89 
CloseMode()90 void ReverseSuperChargeCloseButton::CloseMode()
91 {
92     BatterySrvClient::GetInstance().SetBatteryConfig("reverse_super_charge", "1");
93     BATTERY_HILOGI(COMP_SVC, "onReceiveCloseModeEvent end");
94 }
95 }
96 }