• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 const std::string USB_FUNC_REVERSE_CHARGE = "USB_func_charge_connected_notifier";
38 
39 class UsbConnectionNotifier {
40 public:
41     static std::shared_ptr<UsbConnectionNotifier> GetInstance();
42     ~UsbConnectionNotifier();
43     void SendNotification(std::string func);
44     void CancelNotification();
45     void SendHdcNotification();
46     void CancelHdcNotification();
47 
48     std::unordered_map<std::string, std::string> notifierMap = {
49         {USB_FUNC_CHARGE, ""},
50         {USB_FUNC_MTP, ""},
51         {USB_FUNC_PTP, ""},
52         {USB_FUNC_MORE, ""},
53         {USB_HDC_NOTIFIER_TITLE, ""},
54         {USB_HDC_NOTIFIER_CONTENT, ""},
55         {USB_FUNC_REVERSE_CHARGE, ""}
56     };
57 
58 private:
59     UsbConnectionNotifier();
60     void SetWantAgent(OHOS::Notification::NotificationRequest &request);
61     void SetWantAgentHdc(OHOS::Notification::NotificationRequest &request);
62     static std::mutex insMutex_;
63     void GetHapString();
64     void GetHapIcon();
65     void GetSetUid();
66     int32_t GetSupportedFunctions();
67     int32_t usbSupportedFunctions_ = 0;
68     sptr<AppExecFwk::IBundleMgr> GetBundleMgr(void);
69 
70     static std::shared_ptr<UsbConnectionNotifier> instance_;
71     OHOS::Notification::NotificationRequest request_;
72     OHOS::Notification::NotificationRequest requestHdc_;
73     OptionalPixelMap icon_;
74 };
75 } // namespace USB
76 } // namespace OHOS
77 #endif // USB_CONNECTION_NOTIFIER_H
78