1 /* 2 * Copyright (C) 2024-2024 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 TELEPHONY_DISTRIBUTED_COMMUNICATION_SINK_SWITCH_CONTROLLER_H 17 #define TELEPHONY_DISTRIBUTED_COMMUNICATION_SINK_SWITCH_CONTROLLER_H 18 19 #ifdef ABILITY_BLUETOOTH_SUPPORT 20 #include "bluetooth_hfp_ag.h" 21 #endif 22 #include "distributed_device_switch_controller.h" 23 24 namespace OHOS { 25 namespace Telephony { 26 #ifdef ABILITY_BLUETOOTH_SUPPORT 27 constexpr int32_t INVALID_BT_ACTION = -1; 28 class DcCallHfpListener : public Bluetooth::HandsFreeAudioGatewayObserver { 29 public: 30 DcCallHfpListener() = default; 31 ~DcCallHfpListener() override = default; 32 void OnHfpStackChanged(const Bluetooth::BluetoothRemoteDevice &device, int32_t action) override; 33 void SetPreAction(int32_t action); 34 35 private: 36 BLUETOOTH_DISALLOW_COPY_AND_ASSIGN(DcCallHfpListener); 37 void SwitchToBtHeadset(const Bluetooth::BluetoothRemoteDevice &device); 38 39 private: 40 int32_t preAction_{INVALID_BT_ACTION}; 41 }; 42 #endif 43 44 class DistributedSinkSwitchController : public DistributedDeviceSwitchController { 45 public: 46 DistributedSinkSwitchController() = default; 47 ~DistributedSinkSwitchController() override = default; 48 void OnDeviceOnline(const std::string &devId, const std::string &devName, AudioDeviceType devType) override; 49 void OnDeviceOffline(const std::string &devId, const std::string &devName, AudioDeviceType devType) override; 50 void OnDistributedAudioDeviceChange(const std::string &devId, const std::string &devName, 51 AudioDeviceType devType, int32_t devRole) override; 52 void OnRemoveSystemAbility() override; 53 static void TrySwitchToBtHeadset(); 54 55 private: 56 #ifdef ABILITY_BLUETOOTH_SUPPORT 57 std::shared_ptr<DcCallHfpListener> hfpListener_{nullptr}; 58 #endif 59 }; 60 } // namespace Telephony 61 } // namespace OHOS 62 63 #endif // TELEPHONY_DISTRIBUTED_COMMUNICATION_SINK_SWITCH_CONTROLLER_H 64