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 #include "timer.h" 27 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 int32_t SetCurrentFunctionLabel(int32_t func); 52 int32_t RemoveCurrentFunctionLabel(); 53 private: 54 UsbFunctionSwitchWindow(); 55 DISALLOW_COPY_AND_MOVE(UsbFunctionSwitchWindow); 56 class UsbFuncAbilityConn : public OHOS::AAFwk::AbilityConnectionStub { 57 void OnAbilityConnectDone(const AppExecFwk::ElementName &element, const sptr<IRemoteObject> &remoteObject, 58 int32_t resultCode) override; 59 void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int32_t resultCode) override; 60 public: 61 void CloseDialog(); 62 private: 63 sptr<IRemoteObject> remoteObject_ = nullptr; 64 }; 65 bool ShowFunctionSwitchWindow(); 66 bool UnShowFunctionSwitchWindow(); 67 bool CheckDialogInstallStatus(); 68 static std::shared_ptr<UsbFunctionSwitchWindow> instance_; 69 sptr<UsbFuncAbilityConn> usbFuncAbilityConn = nullptr; 70 int32_t windowAction_ = UsbFunctionSwitchWindowAction::FUNCTION_SWITCH_WINDOW_ACTION_DEFAULT; 71 static std::mutex insMutex_; 72 std::mutex opMutex_; 73 const std::string functionSwitchBundleName_ = "com.usb.right"; 74 const std::string functionSwitchExtAbility_ = "UsbFunctionSwitchExtAbility"; 75 bool isDialogInstalled_ = false; 76 Utils::Timer checkDialogTimer_ {"checkDialogTimer"}; 77 uint32_t checkDialogTimerId_ {UINT32_MAX}; 78 }; 79 } // namespace USB 80 } // namespace OHOS 81 82 #endif 83