1 /* 2 * Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved. 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 #ifndef USB_CONNECTION_NOTIFIER_H 17 #define USB_CONNECTION_NOTIFIER_H 18 #include <optional> 19 #include <string> 20 #include "usb_device.h" 21 #include "pixel_map.h" 22 #include "notification_helper.h" 23 #include "notification_content.h" 24 #include "notification_request.h" 25 26 namespace OHOS { 27 namespace USB { 28 29 using OptionalPixelMap = std::optional<std::shared_ptr<Media::PixelMap>>; 30 31 const std::string USB_FUNC_CHARGE = "USB_func_charge_notifier"; 32 const std::string USB_FUNC_MTP = "USB_func_mtp_notifier"; 33 const std::string USB_FUNC_PTP = "USB_func_ptp_notifier"; 34 const std::string USB_FUNC_MORE = "USB_func_more_notifier"; 35 const std::string USB_HDC_NOTIFIER_TITLE = "USB_hdc_notifier_title"; 36 const std::string USB_HDC_NOTIFIER_CONTENT = "USB_hdc_notifier_content"; 37 38 class UsbConnectionNotifier { 39 public: 40 static std::shared_ptr<UsbConnectionNotifier> GetInstance(); 41 ~UsbConnectionNotifier(); 42 void SendNotification(std::string func); 43 void CancelNotification(); 44 void SendHdcNotification(); 45 void CancelHdcNotification(); 46 47 std::unordered_map<std::string, std::string> notifierMap = { 48 {USB_FUNC_CHARGE, ""}, 49 {USB_FUNC_MTP, ""}, 50 {USB_FUNC_PTP, ""}, 51 {USB_FUNC_MORE, ""}, 52 {USB_HDC_NOTIFIER_TITLE, ""}, 53 {USB_HDC_NOTIFIER_CONTENT, ""} 54 }; 55 56 private: 57 UsbConnectionNotifier(); 58 void SetWantAgent(OHOS::Notification::NotificationRequest &request); 59 void SetWantAgentHdc(OHOS::Notification::NotificationRequest &request); 60 static std::mutex insMutex_; 61 void GetHapString(); 62 void GetHapIcon(); 63 void GetSetUid(); 64 int32_t GetSupportedFunctions(); 65 int32_t usbSupportedFunctions_ = 0; 66 sptr<AppExecFwk::IBundleMgr> GetBundleMgr(void); 67 68 static std::shared_ptr<UsbConnectionNotifier> instance_; 69 OHOS::Notification::NotificationRequest request_; 70 OHOS::Notification::NotificationRequest requestHdc_; 71 OptionalPixelMap icon_; 72 }; 73 } // namespace USB 74 } // namespace OHOS 75 #endif // USB_CONNECTION_NOTIFIER_H 76