1 /* 2 * Copyright (C) 2021 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 #include "bluetooth_device_class.h" 16 17 #include "bluetooth_device.h" 18 19 namespace OHOS { 20 namespace Bluetooth { BluetoothDeviceClass()21BluetoothDeviceClass::BluetoothDeviceClass() : class_(0) 22 {} 23 BluetoothDeviceClass(int deviceClass)24BluetoothDeviceClass::BluetoothDeviceClass(int deviceClass) : class_(deviceClass) 25 {} 26 ~BluetoothDeviceClass()27BluetoothDeviceClass::~BluetoothDeviceClass() 28 {} 29 GetMajorClass() const30int BluetoothDeviceClass::GetMajorClass() const 31 { 32 return (class_ & BluetoothDevice::MAJOR_BITMASK); 33 } 34 GetMajorMinorClass() const35int BluetoothDeviceClass::GetMajorMinorClass() const 36 { 37 return (class_ & BluetoothDevice::DEVICE_BITMASK); 38 } 39 GetClassOfDevice() const40int BluetoothDeviceClass::GetClassOfDevice() const 41 { 42 return class_; 43 } 44 IsProfileSupported(int profileId) const45bool BluetoothDeviceClass::IsProfileSupported(int profileId) const 46 { 47 if (profileId == BluetoothDevice::PROFILE_A2DP) { 48 return IsA2dpSupported(); 49 } else if (profileId == BluetoothDevice::PROFILE_A2DP_SINK) { 50 return IsA2dpSinkSupported(); 51 } else if (profileId == BluetoothDevice::PROFILE_HEADSET) { 52 return IsHeadSetSupported(); 53 } else if (profileId == BluetoothDevice::PROFILE_OPP) { 54 return IsOppSupported(); 55 } else if (profileId == BluetoothDevice::PROFILE_HID) { 56 return (GetMajorMinorClass() & BluetoothDevice::MAJOR_PERIPHERAL) == 57 BluetoothDevice::MAJOR_PERIPHERAL; 58 } else if (profileId == BluetoothDevice::PROFILE_PANU || 59 profileId == BluetoothDevice::PROFILE_NAP) { 60 if (IsServiceSupported(BluetoothDevice::SERVICE_NETWORKING)) { 61 return true; 62 } 63 return (GetMajorMinorClass() & BluetoothDevice::MAJOR_NETWORKING) == 64 BluetoothDevice::MAJOR_NETWORKING; 65 } else { 66 return false; 67 } 68 } 69 IsA2dpSupported() const70bool BluetoothDeviceClass::IsA2dpSupported() const 71 { 72 if (IsServiceSupported(BluetoothDevice::SERVICE_RENDER)) { 73 return true; 74 } 75 switch (GetMajorMinorClass()) { 76 case BluetoothDevice::AUDIO_VIDEO_HIFI_AUDIO: 77 case BluetoothDevice::AUDIO_VIDEO_HEADPHONES: 78 case BluetoothDevice::AUDIO_VIDEO_LOUDSPEAKER: 79 case BluetoothDevice::AUDIO_VIDEO_CAR_AUDIO: 80 return true; 81 default: 82 return false; 83 } 84 } 85 IsA2dpSinkSupported() const86bool BluetoothDeviceClass::IsA2dpSinkSupported() const 87 { 88 if (IsServiceSupported(BluetoothDevice::SERVICE_CAPTURE)) { 89 return true; 90 } 91 switch (GetMajorMinorClass()) { 92 case BluetoothDevice::AUDIO_VIDEO_HIFI_AUDIO: 93 case BluetoothDevice::AUDIO_VIDEO_SET_TOP_BOX: 94 case BluetoothDevice::AUDIO_VIDEO_VCR: 95 return true; 96 default: 97 return false; 98 } 99 } 100 IsHeadSetSupported() const101bool BluetoothDeviceClass::IsHeadSetSupported() const 102 { 103 if (IsServiceSupported(BluetoothDevice::SERVICE_RENDER)) { 104 return true; 105 } 106 switch (GetMajorMinorClass()) { 107 case BluetoothDevice::AUDIO_VIDEO_HANDSFREE: 108 case BluetoothDevice::AUDIO_VIDEO_WEARABLE_HEADSET: 109 case BluetoothDevice::AUDIO_VIDEO_CAR_AUDIO: 110 return true; 111 default: 112 return false; 113 } 114 } 115 IsOppSupported() const116bool BluetoothDeviceClass::IsOppSupported() const 117 { 118 if (IsServiceSupported(BluetoothDevice::SERVICE_OBJECT_TRANSFER)) { 119 return true; 120 } 121 122 switch (GetMajorMinorClass()) { 123 case BluetoothDevice::COMPUTER_UNCATEGORIZED: 124 case BluetoothDevice::COMPUTER_DESKTOP: 125 case BluetoothDevice::COMPUTER_SERVER: 126 case BluetoothDevice::COMPUTER_LAPTOP: 127 case BluetoothDevice::COMPUTER_HANDHELD_PC_PDA: 128 case BluetoothDevice::COMPUTER_PALM_SIZE_PC_PDA: 129 case BluetoothDevice::COMPUTER_WEARABLE: 130 case BluetoothDevice::PHONE_UNCATEGORIZED: 131 case BluetoothDevice::PHONE_CELLULAR: 132 case BluetoothDevice::PHONE_CORDLESS: 133 case BluetoothDevice::PHONE_SMART: 134 case BluetoothDevice::PHONE_MODEM_OR_GATEWAY: 135 case BluetoothDevice::PHONE_ISDN: 136 return true; 137 default: 138 return false; 139 } 140 } 141 IsServiceSupported(int service) const142bool BluetoothDeviceClass::IsServiceSupported(int service) const 143 { 144 return ((class_ & BluetoothDevice::SERVICE_BITMASK & service) != 0); 145 } 146 } // namespace Bluetooth 147 } // namespace OHOS