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 "scan_event_subscriber.h" 17 #include "common_event_manager.h" 18 #include "common_event_support.h" 19 #include "scan_usb_manager.h" 20 #include "scan_log.h" 21 22 namespace OHOS { 23 namespace Scan { ScanEventSubscriber(const EventFwk::CommonEventSubscribeInfo & subscribeInfo)24ScanEventSubscriber::ScanEventSubscriber( 25 const EventFwk::CommonEventSubscribeInfo &subscribeInfo) : EventFwk::CommonEventSubscriber(subscribeInfo) 26 {} 27 ~ScanEventSubscriber()28ScanEventSubscriber::~ScanEventSubscriber() 29 {} 30 OnReceiveEvent(const EventFwk::CommonEventData & data)31void ScanEventSubscriber::OnReceiveEvent(const EventFwk::CommonEventData &data) 32 { 33 std::string action = data.GetWant().GetAction(); 34 if (action == EventFwk::CommonEventSupport::COMMON_EVENT_USB_DEVICE_ATTACHED) { 35 SCAN_HILOGI("OnReceiveEvent attached start"); 36 std::string devStr = data.GetData(); 37 SCAN_HILOGD("OnReceiveEvent attached devStr = %{public}s", devStr.c_str()); 38 DelayedSingleton<ScanUsbManager>::GetInstance()->DealUsbDevStatusChange(devStr, true); 39 } else if (action == EventFwk::CommonEventSupport::COMMON_EVENT_USB_DEVICE_DETACHED) { 40 SCAN_HILOGI("OnReceiveEvent detached start"); 41 std::string devStr = data.GetData(); 42 DelayedSingleton<ScanUsbManager>::GetInstance()->DealUsbDevStatusChange(devStr, false); 43 SCAN_HILOGD("OnReceiveEvent detached devStr = %{public}s end", devStr.c_str()); 44 } 45 } 46 47 } // namespace Scan 48 } // namespace OHOS