1 /*
2 * Copyright (c) 2022-2025 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 "event_controller.h"
17
18 #include "application_info.h"
19 #include "bundle_constants.h"
20 #include "bundle_mgr_interface.h"
21 #include "common_event_manager.h"
22 #include "common_event_support.h"
23 #include "hisysevent.h"
24 #include "if_system_ability_manager.h"
25 #include "ipc_skeleton.h"
26 #include "iservice_registry.h"
27 #include "oobe_datashare_utils.h"
28 #include "oobe_manager.h"
29 #include "system_ability_definition.h"
30
31 #include "res_sched_log.h"
32 #include "res_sched_mgr.h"
33 #include "res_type.h"
34
35 using namespace OHOS::EventFwk;
36 namespace OHOS {
37 namespace ResourceSchedule {
38 IMPLEMENT_SINGLE_INSTANCE(EventController);
39
40 static const char* COMMON_EVENT_CAMERA_STATUS = "usual.event.CAMERA_STATUS";
41 static const char* COMMON_EVENT_GAME_STATUS = "usual.event.gameservice.GAME_STATUS_CHANGE_UNI";
42 static const char* DATA_SHARE_READY = "usual.event.DATA_SHARE_READY";
43 static const char* CONFIG_UPDATE_ACTION = "usual.event.DUA_SA_CFG_UPDATED";
44 static const char* DEVICE_MODE_PAYMODE_NAME = "deviceMode";
45 static const char* DEVICE_MODE_TYPE_KEY = "deviceModeType";
46 static const char* SCENE_BOARD_NAME = "com.ohos.sceneboard";
47 static const char* CAMERA_STATE = "cameraState";
48 static const char* CAMERA_TYPE = "cameraType";
49 static const char* IS_SYSTEM_CAMERA = "isSystemCamera";
50 static const char* EVENT_INFO_TYPE = "type";
51 static const char* EVENT_INFO_SUBTYPE = "subtype";
52 static const char* CONFIG_TYPE = "RSSCONFIG";
53 static const char* GAME_UID = "uid";
54 static const char* GAME_STATUS = "type";
55 static const char* GAME_ENV = "env";
56 static const char* COMMON_EVENT_CAPACITY = "soc";
57 static const char* COMMON_EVENT_CHARGE_STATE = "chargeState";
58 static const char* COMMON_EVENT_USER_SLEEP_STATE_CHANGED = "common.event.USER_NOT_CARE_CHARGE_SLEEP";
59
Init()60 void EventController::Init()
61 {
62 if (sysAbilityListener_ != nullptr) {
63 return;
64 }
65 sysAbilityListener_ = new (std::nothrow) SystemAbilityStatusChangeListener();
66 if (sysAbilityListener_ == nullptr) {
67 RESSCHED_LOGE("Failed to create statusChangeListener due to no memory.");
68 HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::RSS, "INIT_FAULT", HiviewDFX::HiSysEvent::EventType::FAULT,
69 "COMPONENT_NAME", "MAIN",
70 "ERR_TYPE", "others",
71 "ERR_MSG", "EventController new statusChangeListener object failed!");
72 return;
73 }
74 sptr<ISystemAbilityManager> systemAbilityManager
75 = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
76 if (systemAbilityManager == nullptr) {
77 RESSCHED_LOGE("systemAbilityManager is null");
78 HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::RSS, "INIT_FAULT", HiviewDFX::HiSysEvent::EventType::FAULT,
79 "COMPONENT_NAME", "MAIN",
80 "ERR_TYPE", "register failure",
81 "ERR_MSG", "EventController get system ability manager failed!");
82 sysAbilityListener_ = nullptr;
83 return;
84 }
85 int32_t ret = systemAbilityManager->SubscribeSystemAbility(COMMON_EVENT_SERVICE_ID, sysAbilityListener_);
86 if (ret != ERR_OK) {
87 RESSCHED_LOGE("subscribe system ability id: %{public}d failed", COMMON_EVENT_SERVICE_ID);
88 HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::RSS, "INIT_FAULT", HiviewDFX::HiSysEvent::EventType::FAULT,
89 "COMPONENT_NAME", "MAIN",
90 "ERR_TYPE", "register failure",
91 "ERR_MSG", "EventController subscribe the event service SA failed!");
92 sysAbilityListener_ = nullptr;
93 } else {
94 RESSCHED_LOGI("subscribe system ability id: %{public}d succeed", COMMON_EVENT_SERVICE_ID);
95 }
96 }
97
HandlePkgAddRemove(const EventFwk::Want & want,nlohmann::json & payload) const98 void EventController::HandlePkgAddRemove(const EventFwk::Want &want, nlohmann::json &payload) const
99 {
100 AppExecFwk::ElementName ele = want.GetElement();
101 std::string bundleName = ele.GetBundleName();
102 int32_t uid = want.GetIntParam(AppExecFwk::Constants::UID, -1);
103 int32_t appIndex = want.GetIntParam("appIndex", -1);
104 payload["bundleName"] = bundleName;
105 payload["uid"] = uid;
106 payload["appIndex"] = appIndex;
107 }
108
GetUid(const int32_t & userId,const std::string & bundleName) const109 int32_t EventController::GetUid(const int32_t &userId, const std::string &bundleName) const
110 {
111 AppExecFwk::ApplicationInfo info;
112 sptr<ISystemAbilityManager> systemAbilityManager
113 = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
114 if (systemAbilityManager == nullptr) {
115 RESSCHED_LOGE("Failed to get uid due to get systemAbilityManager is null.");
116 return -1;
117 }
118 sptr<IRemoteObject> remoteObject = systemAbilityManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID);
119 if (remoteObject == nullptr) {
120 RESSCHED_LOGE("Failed to get uid due to get BMS is null.");
121 return -1;
122 }
123 sptr<AppExecFwk::IBundleMgr> bundleMgr = iface_cast<AppExecFwk::IBundleMgr>(remoteObject);
124 if (bundleMgr == nullptr) {
125 RESSCHED_LOGE("Failed to get uid due to get bundleMgr is null.");
126 return -1;
127 }
128 bundleMgr->GetApplicationInfo(bundleName, AppExecFwk::ApplicationFlag::GET_BASIC_APPLICATION_INFO, userId, info);
129 return static_cast<int32_t>(info.uid);
130 }
131
HandleConnectivityChange(const EventFwk::Want & want,const int32_t & code,nlohmann::json & payload)132 void EventController::HandleConnectivityChange(
133 const EventFwk::Want &want, const int32_t &code, nlohmann::json &payload)
134 {
135 int32_t netType = want.GetIntParam("NetType", -1);
136 if (netType != 1) {
137 return;
138 }
139 ReportDataInProcess(ResType::RES_TYPE_WIFI_CONNECT_STATE_CHANGE, code, payload);
140 }
141
ReportDataInProcess(const uint32_t & resType,const int64_t & value,const nlohmann::json & payload)142 void EventController::ReportDataInProcess(const uint32_t &resType, const int64_t &value, const nlohmann::json& payload)
143 {
144 ResSchedMgr::GetInstance().ReportData(resType, value, payload);
145 resType_ = resType;
146 value_ = value;
147 payload_ = payload;
148 }
149
Stop()150 void EventController::Stop()
151 {
152 if (sysAbilityListener_ == nullptr) {
153 return;
154 }
155 sysAbilityListener_->Stop();
156 }
157
DataShareIsReady()158 void EventController::DataShareIsReady()
159 {
160 RESSCHED_LOGI("Data_share is ready! Call back to create data_share helper");
161 ResourceSchedule::OOBEManager::GetInstance().OnReceiveDataShareReadyCallBack();
162 }
163
SubscribeCommonEvent(std::shared_ptr<EventController> subscriber)164 inline void SubscribeCommonEvent(std::shared_ptr<EventController> subscriber)
165 {
166 if (CommonEventManager::SubscribeCommonEvent(subscriber)) {
167 RESSCHED_LOGI("SubscribeCommonEvent ok");
168 } else {
169 RESSCHED_LOGW("SubscribeCommonEvent fail");
170 HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::RSS, "INIT_FAULT", HiviewDFX::HiSysEvent::EventType::FAULT,
171 "COMPONENT_NAME", "MAIN",
172 "ERR_TYPE", "register failure",
173 "ERR_MSG", "EventController subscribe common events failed!");
174 }
175 }
176
OnAddSystemAbility(int32_t systemAbilityId,const std::string & deviceId)177 void EventController::SystemAbilityStatusChangeListener::OnAddSystemAbility(
178 int32_t systemAbilityId, const std::string& deviceId)
179 {
180 RESSCHED_LOGI("common event service is added");
181 MatchingSkills matchingSkills;
182 matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_CONNECTIVITY_CHANGE);
183 matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_PACKAGE_INSTALLATION_STARTED);
184 matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_PACKAGE_ADDED);
185 matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED);
186 matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_PACKAGE_CHANGED);
187 matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_PACKAGE_REPLACED);
188 matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_SCREEN_ON);
189 matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_SCREEN_OFF);
190 matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_USER_SWITCHED);
191 matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_USER_REMOVED);
192 matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_TIMEZONE_CHANGED);
193 matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_BUNDLE_REMOVED);
194 matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_PACKAGE_FULLY_REMOVED);
195 matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_TIME_CHANGED);
196 matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_NITZ_TIME_CHANGED);
197 matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_NITZ_TIMEZONE_CHANGED);
198 matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_CHARGING);
199 matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_USB_DEVICE_ATTACHED);
200 matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_DISCHARGING);
201 matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_USB_DEVICE_DETACHED);
202 matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_CALL_STATE_CHANGED);
203 matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_WIFI_P2P_STATE_CHANGED);
204 matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_POWER_SAVE_MODE_CHANGED);
205 matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_BOOT_COMPLETED);
206 matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_POWER_CONNECTED);
207 matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_POWER_DISCONNECTED);
208 matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_WIFI_POWER_STATE);
209 matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_BATTERY_CHANGED);
210 matchingSkills.AddEvent(DATA_SHARE_READY);
211 matchingSkills.AddEvent(COMMON_EVENT_CAMERA_STATUS);
212 matchingSkills.AddEvent(CONFIG_UPDATE_ACTION);
213 matchingSkills.AddEvent(COMMON_EVENT_GAME_STATUS);
214 matchingSkills.AddEvent(COMMON_EVENT_USER_SLEEP_STATE_CHANGED);
215 CommonEventSubscribeInfo subscriberInfo(matchingSkills);
216 subscriber_ = std::make_shared<EventController>(subscriberInfo);
217 SubscribeCommonEvent(subscriber_);
218 SubscribeLockScreenCommonEvent();
219 }
220
SubscribeLockScreenCommonEvent()221 void EventController::SystemAbilityStatusChangeListener::SubscribeLockScreenCommonEvent()
222 {
223 MatchingSkills lockScreenSkills;
224 lockScreenSkills.AddEvent("common.event.UNLOCK_SCREEN");
225 lockScreenSkills.AddEvent("common.event.LOCK_SCREEN");
226 CommonEventSubscribeInfo subscriberInfo(lockScreenSkills);
227 subscriberInfo.SetPublisherBundleName(SCENE_BOARD_NAME);
228 lockScreenSubscriber_ = std::make_shared<EventController>(subscriberInfo);
229 SubscribeCommonEvent(lockScreenSubscriber_);
230 }
231
OnReceiveEvent(const EventFwk::CommonEventData & data)232 void EventController::OnReceiveEvent(const EventFwk::CommonEventData &data)
233 {
234 Want want = data.GetWant();
235 std::string action = want.GetAction();
236 RESSCHED_LOGD("Recieved common event:%{public}s", action.c_str());
237
238 nlohmann::json payload = nlohmann::json::object();
239 if (HandlePkgCommonEvent(action, want, payload)) {
240 return;
241 }
242 if (action == CommonEventSupport::COMMON_EVENT_SCREEN_ON) {
243 ReportDataInProcess(ResType::RES_TYPE_SCREEN_STATUS, ResType::ScreenStatus::SCREEN_ON, payload);
244 return;
245 }
246 if (action == CommonEventSupport::COMMON_EVENT_SCREEN_OFF) {
247 ReportDataInProcess(ResType::RES_TYPE_SCREEN_STATUS, ResType::ScreenStatus::SCREEN_OFF, payload);
248 return;
249 }
250 if (action == CommonEventSupport::COMMON_EVENT_CONNECTIVITY_CHANGE) {
251 int32_t code = data.GetCode();
252 HandleConnectivityChange(want, code, payload);
253 return;
254 }
255 if (action == CommonEventSupport::COMMON_EVENT_USER_SWITCHED) {
256 int32_t userId = data.GetCode();
257 ReportDataInProcess(ResType::RES_TYPE_USER_SWITCH, static_cast<int64_t>(userId), payload);
258 return;
259 }
260 if (action == CommonEventSupport::COMMON_EVENT_USER_REMOVED) {
261 int32_t userId = data.GetCode();
262 ReportDataInProcess(ResType::RES_TYPE_USER_REMOVE, static_cast<int64_t>(userId), payload);
263 return;
264 }
265 if (action == "common.event.UNLOCK_SCREEN") {
266 ReportDataInProcess(ResType::RES_TYPE_SCREEN_LOCK, ResType::ScreenLockStatus::SCREEN_UNLOCK, payload);
267 return;
268 }
269 if (action == "common.event.LOCK_SCREEN") {
270 ReportDataInProcess(ResType::RES_TYPE_SCREEN_LOCK, ResType::ScreenLockStatus::SCREEN_LOCK, payload);
271 return;
272 }
273 if (action == EventFwk::CommonEventSupport::COMMON_EVENT_CALL_STATE_CHANGED) {
274 payload["state"] = want.GetIntParam("state", -1);
275 ReportDataInProcess(ResType::RES_TYPE_CALL_STATE_CHANGED, static_cast<int64_t>(data.GetCode()), payload);
276 return;
277 }
278 if (action == DATA_SHARE_READY) {
279 DataShareIsReady();
280 return;
281 }
282
283 handleEvent(data.GetCode(), action, payload, want);
284 }
285
handleEvent(int32_t userId,const std::string & action,nlohmann::json & payload,Want & want)286 void EventController::handleEvent(int32_t userId, const std::string &action, nlohmann::json &payload, Want &want)
287 {
288 if (action == CommonEventSupport::COMMON_EVENT_TIMEZONE_CHANGED) {
289 ReportDataInProcess(ResType::RES_TYPE_TIMEZONE_CHANGED, ResType::RES_TYPE_TIMEZONE_CHANGED, payload);
290 return;
291 }
292 if (action == EventFwk::CommonEventSupport::COMMON_EVENT_TIME_CHANGED) {
293 ReportDataInProcess(ResType::RES_TYPE_TIME_CHANGED, static_cast<int64_t>(userId), payload);
294 return;
295 }
296 if (action == EventFwk::CommonEventSupport::COMMON_EVENT_NITZ_TIME_CHANGED) {
297 ReportDataInProcess(ResType::RES_TYPE_NITZ_TIME_CHANGED, static_cast<int64_t>(userId), payload);
298 return;
299 }
300 if (action == EventFwk::CommonEventSupport::COMMON_EVENT_NITZ_TIMEZONE_CHANGED) {
301 ReportDataInProcess(ResType::RES_TYPE_NITZ_TIMEZONE_CHANGED, static_cast<int64_t>(userId), payload);
302 return;
303 }
304 if (action == EventFwk::CommonEventSupport::COMMON_EVENT_CHARGING) {
305 ReportDataInProcess(ResType::RES_TYPE_CHARGING_DISCHARGING, ResType::ChargeStatus::EVENT_CHARGING, payload);
306 return;
307 }
308 if (action == EventFwk::CommonEventSupport::COMMON_EVENT_DISCHARGING) {
309 ReportDataInProcess(ResType::RES_TYPE_CHARGING_DISCHARGING, ResType::ChargeStatus::EVENT_DISCHARGING, payload);
310 return;
311 }
312 if (action == EventFwk::CommonEventSupport::COMMON_EVENT_USB_DEVICE_ATTACHED) {
313 ReportDataInProcess(ResType::RES_TYPE_USB_DEVICE, ResType::UsbDeviceStatus::USB_DEVICE_ATTACHED, payload);
314 return;
315 }
316 if (action == EventFwk::CommonEventSupport::COMMON_EVENT_USB_DEVICE_DETACHED) {
317 ReportDataInProcess(ResType::RES_TYPE_USB_DEVICE, ResType::UsbDeviceStatus::USB_DEVICE_DETACHED, payload);
318 return;
319 }
320 if (action == EventFwk::CommonEventSupport::COMMON_EVENT_WIFI_P2P_STATE_CHANGED) {
321 ReportDataInProcess(ResType::RES_TYPE_WIFI_P2P_STATE_CHANGED, static_cast<int64_t>(userId), payload);
322 return;
323 }
324 if (action == EventFwk::CommonEventSupport::COMMON_EVENT_POWER_SAVE_MODE_CHANGED) {
325 ReportDataInProcess(ResType::RES_TYPE_POWER_MODE_CHANGED, static_cast<int64_t>(userId), payload);
326 return;
327 }
328 if (action == EventFwk::CommonEventSupport::COMMON_EVENT_WIFI_POWER_STATE) {
329 payload["state"] = std::to_string(userId);
330 ReportDataInProcess(ResType::RES_TYPE_WIFI_POWER_STATE_CHANGE, static_cast<int64_t>(userId), payload);
331 return;
332 }
333 handleOtherEvent(userId, action, payload, want);
334 }
335
handleOtherEvent(int32_t userId,const std::string & action,nlohmann::json & payload,Want & want)336 void EventController::handleOtherEvent(int32_t userId, const std::string &action, nlohmann::json &payload, Want &want)
337 {
338 if (action == EventFwk::CommonEventSupport::COMMON_EVENT_BOOT_COMPLETED) {
339 RESSCHED_LOGD("report boot completed");
340 ReportDataInProcess(ResType::RES_TYPE_BOOT_COMPLETED,
341 ResType::BootCompletedStatus::START_BOOT_COMPLETED, payload);
342 return;
343 }
344 if (action == EventFwk::CommonEventSupport::COMMON_EVENT_POWER_CONNECTED) {
345 payload[DEVICE_MODE_TYPE_KEY] = "powerConnectStatus";
346 payload[DEVICE_MODE_PAYMODE_NAME] = "powerConnected";
347 ReportDataInProcess(ResType::RES_TYPE_DEVICE_MODE_STATUS,
348 ResType::DeviceModeStatus::MODE_ENTER, payload);
349 return;
350 }
351 if (action == EventFwk::CommonEventSupport::COMMON_EVENT_POWER_DISCONNECTED) {
352 payload[DEVICE_MODE_TYPE_KEY] = "powerConnectStatus";
353 payload[DEVICE_MODE_PAYMODE_NAME] = "powerDisConnected";
354 ReportDataInProcess(ResType::RES_TYPE_DEVICE_MODE_STATUS,
355 ResType::DeviceModeStatus::MODE_ENTER, payload);
356 return;
357 }
358 if (action == COMMON_EVENT_CAMERA_STATUS) {
359 RESSCHED_LOGD("report camera status completed");
360 payload[CAMERA_TYPE] = want.GetIntParam(IS_SYSTEM_CAMERA, 0);
361 ReportDataInProcess(ResType::RES_TYPE_REPORT_CAMERA_STATE,
362 static_cast<int64_t>(want.GetIntParam(CAMERA_STATE, 1)), payload);
363 return;
364 }
365 if (action == CONFIG_UPDATE_ACTION) {
366 RESSCHED_LOGD("report param update event");
367 payload["type"] = want.GetStringParam(EVENT_INFO_TYPE);
368 payload["subtype"] = want.GetStringParam(EVENT_INFO_SUBTYPE);
369 ReportDataInProcess(ResType::RES_TYPE_PARAM_UPADTE_EVENT, static_cast<int64_t>(userId), payload);
370 return;
371 }
372 if (action == COMMON_EVENT_GAME_STATUS) {
373 RESSCHED_LOGD("report game status event");
374 payload[GAME_UID] = want.GetIntParam(GAME_UID, -1);
375 payload[GAME_ENV] = want.GetIntParam(GAME_ENV, -1);
376 ReportDataInProcess(ResType::RES_TYPE_REPORT_GAME_STATE_CHANGE,
377 static_cast<int64_t>(want.GetIntParam(GAME_STATUS, -1)), payload);
378 return;
379 }
380 handleLeftEvent(userId, action, payload, want);
381 }
382
handleLeftEvent(int32_t userId,const std::string & action,nlohmann::json & payload,Want & want)383 void EventController::handleLeftEvent(int32_t userId, const std::string &action, nlohmann::json &payload, Want &want)
384 {
385 if (action == COMMON_EVENT_USER_SLEEP_STATE_CHANGED) {
386 RESSCHED_LOGD("report sleep state event");
387 ReportDataInProcess(ResType::RES_TYPE_USER_NOT_CARE_CHARGE_SLEEP,
388 static_cast<int64_t>(want.GetBoolParam("isSleep", false)), payload);
389 return;
390 }
391 if (action == EventFwk::CommonEventSupport::COMMON_EVENT_BATTERY_CHANGED) {
392 RESSCHED_LOGD("report battery status change event");
393 payload[COMMON_EVENT_CHARGE_STATE] = want.GetIntParam(COMMON_EVENT_CHARGE_STATE, -1);
394 ReportDataInProcess(ResType::RES_TYPE_REPORT_BATTERY_STATUS_CHANGE,
395 static_cast<int64_t>(want.GetIntParam(COMMON_EVENT_CAPACITY, -1)), payload);
396 }
397 }
398
HandlePkgCommonEvent(const std::string & action,Want & want,nlohmann::json & payload)399 bool EventController::HandlePkgCommonEvent(const std::string &action, Want &want, nlohmann::json &payload)
400 {
401 if (action == CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED) {
402 HandlePkgAddRemove(want, payload);
403 ReportDataInProcess(ResType::RES_TYPE_APP_INSTALL_UNINSTALL, ResType::AppInstallStatus::APP_UNINSTALL, payload);
404 return true;
405 }
406 if (action == CommonEventSupport::COMMON_EVENT_PACKAGE_INSTALLATION_STARTED) {
407 HandlePkgAddRemove(want, payload);
408 ReportDataInProcess(ResType::RES_TYPE_APP_INSTALL_UNINSTALL,
409 ResType::AppInstallStatus::APP_INSTALL_START, payload);
410 return true;
411 }
412 if (action == CommonEventSupport::COMMON_EVENT_PACKAGE_ADDED) {
413 HandlePkgAddRemove(want, payload);
414 ReportDataInProcess(ResType::RES_TYPE_APP_INSTALL_UNINSTALL,
415 ResType::AppInstallStatus::APP_INSTALL_END, payload);
416 return true;
417 }
418 if (action == CommonEventSupport::COMMON_EVENT_PACKAGE_CHANGED) {
419 HandlePkgAddRemove(want, payload);
420 ReportDataInProcess(ResType::RES_TYPE_APP_INSTALL_UNINSTALL, ResType::AppInstallStatus::APP_CHANGED, payload);
421 return true;
422 }
423 if (action == CommonEventSupport::COMMON_EVENT_PACKAGE_REPLACED) {
424 HandlePkgAddRemove(want, payload);
425 ReportDataInProcess(ResType::RES_TYPE_APP_INSTALL_UNINSTALL, ResType::AppInstallStatus::APP_REPLACED, payload);
426 return true;
427 }
428 if (action == CommonEventSupport::COMMON_EVENT_PACKAGE_FULLY_REMOVED) {
429 HandlePkgAddRemove(want, payload);
430 ReportDataInProcess(ResType::RES_TYPE_APP_INSTALL_UNINSTALL,
431 ResType::AppInstallStatus::APP_FULLY_REMOVED, payload);
432 return true;
433 }
434 if (action == CommonEventSupport::COMMON_EVENT_BUNDLE_REMOVED) {
435 HandlePkgAddRemove(want, payload);
436 ReportDataInProcess(ResType::RES_TYPE_APP_INSTALL_UNINSTALL,
437 ResType::AppInstallStatus::BUNDLE_REMOVED, payload);
438 return true;
439 }
440 return false;
441 }
442
OnRemoveSystemAbility(int32_t systemAbilityId,const std::string & deviceId)443 void EventController::SystemAbilityStatusChangeListener::OnRemoveSystemAbility(
444 int32_t systemAbilityId, const std::string& deviceId)
445 {
446 RESSCHED_LOGW("common event service is removed.");
447 subscriber_ = nullptr;
448 lockScreenSubscriber_ = nullptr;
449 }
450
Stop()451 void EventController::SystemAbilityStatusChangeListener::Stop()
452 {
453 if (subscriber_ == nullptr || lockScreenSubscriber_ == nullptr) {
454 return;
455 }
456 CommonEventManager::UnSubscribeCommonEvent(subscriber_);
457 CommonEventManager::UnSubscribeCommonEvent(lockScreenSubscriber_);
458 RESSCHED_LOGI("unsubscribe all common event.");
459 subscriber_ = nullptr;
460 lockScreenSubscriber_ = nullptr;
461 }
462
EventControllerInit()463 extern "C" void EventControllerInit()
464 {
465 EventController::GetInstance().Init();
466 }
467
EventControllerStop()468 extern "C" void EventControllerStop()
469 {
470 EventController::GetInstance().Stop();
471 }
472 }
473 }