1 /*
2 * Copyright (c) 2021-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 "system_event_handler.h"
17 #include <cstring>
18 #include "ability_manager.h"
19 #include "libmmi_util.h"
20
21 namespace OHOS {
22 namespace MMI {
23 namespace {
24 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "SystemEventHandler" };
25 }
26 } // namespace MMI
27 } // namespace OHOS
28
29 using namespace OHOS::AAFwk;
30 using namespace OHOS::AppExecFwk;
SystemEventHandler()31 OHOS::MMI::SystemEventHandler::SystemEventHandler()
32 {
33 callbacks_ = {
34 {MmiMessageId::ON_SCREEN_SHOT, std::bind(&SystemEventHandler::OnScreenShot, this)},
35 {MmiMessageId::ON_SCREEN_SPLIT, std::bind(&SystemEventHandler::OnScreenSplit, this)},
36 {MmiMessageId::ON_START_SCREEN_RECORD, std::bind(&SystemEventHandler::OnStopScreenRecord, this)},
37 {MmiMessageId::ON_STOP_SCREEN_RECORD, std::bind(&SystemEventHandler::OnStartScreenRecord, this)},
38 {MmiMessageId::ON_GOTO_DESKTOP, std::bind(&SystemEventHandler::OnGotoDesktop, this)},
39 {MmiMessageId::ON_RECENT, std::bind(&SystemEventHandler::OnRecent, this)},
40 {MmiMessageId::ON_SHOW_NOTIFICATION, std::bind(&SystemEventHandler::OnShowNotification, this)},
41 {MmiMessageId::ON_LOCK_SCREEN, std::bind(&SystemEventHandler::OnLockScreen, this)},
42 {MmiMessageId::ON_SEARCH, std::bind(&SystemEventHandler::OnSearch, this)},
43 {MmiMessageId::ON_CLOSE_PAGE, std::bind(&SystemEventHandler::OnClosePage, this)},
44 {MmiMessageId::ON_LAUNCH_VOICE_ASSISTANT, std::bind(&SystemEventHandler::OnLaunchVoiceAssistant, this)},
45 {MmiMessageId::ON_MUTE, std::bind(&SystemEventHandler::OnMute, this)},
46 {MmiMessageId::ON_BACK, std::bind(&SystemEventHandler::OnBack, this)},
47 };
48 }
49
~SystemEventHandler()50 OHOS::MMI::SystemEventHandler::~SystemEventHandler() {}
51
OnSystemEventHandler(MmiMessageId idMsg)52 int32_t OHOS::MMI::SystemEventHandler::OnSystemEventHandler(MmiMessageId idMsg)
53 {
54 if (idMsg == MmiMessageId::INVALID) {
55 MMI_LOGE("Invalid parameter, errCode:%{public}d", PARAM_INPUT_INVALID);
56 return PARAM_INPUT_INVALID;
57 }
58 auto callback = GetMsgCallback(idMsg);
59 if (callback == nullptr) {
60 MMI_LOGE("Non system event return");
61 return UNKNOWN_MSG_ID; // non-system event return
62 }
63 (*callback)();
64 return RET_OK;
65 }
66
OnGotoDesktop()67 void OHOS::MMI::SystemEventHandler::OnGotoDesktop()
68 {
69 MMI_LOGD("enter");
70 Want want;
71 want.AddEntity(Want::FLAG_HOME_INTENT_FROM_SYSTEM);
72 AbilityManager::GetInstance().StartAbility(want, 0);
73 MMI_LOGD("leave");
74 }
75
OnScreenShot()76 void OHOS::MMI::SystemEventHandler::OnScreenShot()
77 {
78 MMI_LOGI("SystemEventHandler::OnScreenShot");
79 }
80
OnScreenSplit()81 void OHOS::MMI::SystemEventHandler::OnScreenSplit()
82 {
83 MMI_LOGI("SystemEventHandler::OnScreenSplit");
84 }
85
OnStopScreenRecord()86 void OHOS::MMI::SystemEventHandler::OnStopScreenRecord()
87 {
88 MMI_LOGI("SystemEventHandler::OnStopScreenRecord");
89 }
90
OnStartScreenRecord()91 void OHOS::MMI::SystemEventHandler::OnStartScreenRecord()
92 {
93 MMI_LOGI("SystemEventHandler::OnStartScreenRecord");
94 }
95
OnShowNotification()96 void OHOS::MMI::SystemEventHandler::OnShowNotification()
97 {
98 MMI_LOGI("SystemEventHandler::OnShowNotification");
99 }
100
OnRecent()101 void OHOS::MMI::SystemEventHandler::OnRecent()
102 {
103 MMI_LOGI("SystemEventHandler::OnRecent");
104 }
105
OnLockScreen()106 void OHOS::MMI::SystemEventHandler::OnLockScreen()
107 {
108 MMI_LOGI("SystemEventHandler::OnLockScreen");
109 }
110
OnSearch()111 void OHOS::MMI::SystemEventHandler::OnSearch()
112 {
113 MMI_LOGI("SystemEventHandler::OnSearch");
114 }
115
OnClosePage()116 void OHOS::MMI::SystemEventHandler::OnClosePage()
117 {
118 MMI_LOGI("SystemEventHandler::OnClosePage");
119 }
120
OnLaunchVoiceAssistant()121 void OHOS::MMI::SystemEventHandler::OnLaunchVoiceAssistant()
122 {
123 MMI_LOGI("SystemEventHandler::OnLaunchVoiceAssistant");
124 }
125
OnMute()126 void OHOS::MMI::SystemEventHandler::OnMute()
127 {
128 MMI_LOGI("SystemEventHandler::OnMute");
129 }
130
OnBack()131 void OHOS::MMI::SystemEventHandler::OnBack()
132 {
133 MMI_LOGI("SystemEventHandler::OnBack");
134 }
135