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 #ifndef USB_FUNCTION_SWITCH_WINDOW_H 17 #define USB_FUNCTION_SWITCH_WINDOW_H 18 19 #include <mutex> 20 21 #include "ability_connect_callback_stub.h" 22 #include "bundle_mgr_interface.h" 23 #include "parameter.h" 24 #include "usb_common.h" 25 #include "usb_srv_support.h" 26 27 #define PARAM_BUF_LEN 128 28 namespace OHOS { 29 namespace USB { 30 31 enum UsbFunctionChoose : int32_t { 32 FUNCTION_CHOOSE_CHARGE_ONLY = -1, 33 FUNCTION_CHOOSE_TRANSFER_FILE = UsbSrvSupport::FUNCTION_MTP, 34 FUNCTION_CHOOSE_TRANSFER_PIC = UsbSrvSupport::FUNCTION_PTP, 35 }; 36 37 enum UsbFunctionSwitchWindowAction : int32_t { 38 FUNCTION_SWITCH_WINDOW_ACTION_DEFAULT = 0, 39 FUNCTION_SWITCH_WINDOW_ACTION_SHOW, 40 FUNCTION_SWITCH_WINDOW_ACTION_DISMISS, 41 FUNCTION_SWITCH_WINDOW_ACTION_FORBID, 42 }; 43 44 class UsbFunctionSwitchWindow { 45 public: 46 static std::shared_ptr<UsbFunctionSwitchWindow> GetInstance(); 47 ~UsbFunctionSwitchWindow(); 48 int32_t Init(); 49 bool PopUpFunctionSwitchWindow(); 50 bool DismissFunctionSwitchWindow(); 51 52 private: 53 UsbFunctionSwitchWindow(); 54 DISALLOW_COPY_AND_MOVE(UsbFunctionSwitchWindow); 55 56 bool GetDefaultChooseFunction(int32_t &defaultChoose); 57 bool ShowFunctionSwitchWindow(int32_t defaultChoose); 58 bool UnShowFunctionSwitchWindow(); 59 60 static std::shared_ptr<UsbFunctionSwitchWindow> instance_; 61 int32_t windowAction_ = UsbFunctionSwitchWindowAction::FUNCTION_SWITCH_WINDOW_ACTION_FORBID; 62 std::mutex opMutex_; 63 const std::string functionSwitchBundleName_ = "com.ohos.usbfunctiondialog"; 64 const std::string functionSwitchExtAbility_ = "UsbFunctionSwitchExtAbility"; 65 }; 66 } // namespace USB 67 } // namespace OHOS 68 69 #endif 70