1 /* 2 * Copyright (c) 2023 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 "print_event_subscriber.h" 17 #include "common_event_manager.h" 18 #include "common_event_support.h" 19 #include "print_log.h" 20 #include "print_service_ability.h" 21 22 namespace OHOS { 23 namespace Print { PrintEventSubscriber(const EventFwk::CommonEventSubscribeInfo & subscribeInfo)24PrintEventSubscriber::PrintEventSubscriber( 25 const EventFwk::CommonEventSubscribeInfo &subscribeInfo) : EventFwk::CommonEventSubscriber(subscribeInfo) 26 {} 27 ~PrintEventSubscriber()28PrintEventSubscriber::~PrintEventSubscriber() 29 {} 30 OnReceiveEvent(const EventFwk::CommonEventData & data)31void PrintEventSubscriber::OnReceiveEvent(const EventFwk::CommonEventData &data) 32 { 33 std::string action = data.GetWant().GetAction(); 34 if (action == EventFwk::CommonEventSupport::COMMON_EVENT_USER_SWITCHED) { 35 int32_t userId = data.GetCode(); 36 PRINT_HILOGI("user switched, current userId: %{public}d", userId); 37 PrintServiceAbility::GetInstance()->NotifyCurrentUserChanged(userId); 38 } else if (action == EventFwk::CommonEventSupport::COMMON_EVENT_USER_REMOVED) { 39 int32_t userId = data.GetCode(); 40 PRINT_HILOGI("user removed, removed userId: %{public}d", userId); 41 PrintServiceAbility::GetInstance()->CancelUserPrintJobs(userId); 42 } 43 } 44 45 } // namespace Print 46 } // namespace OHOS