/* * Copyright (C) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "bluetooth_errorcode.h" #include "bluetooth_log.h" #include "bluetooth_utils_server.h" #include "bt_def.h" #include "interface_profile_manager.h" #include "interface_profile_socket.h" #include "permission_utils.h" #include "bluetooth_socket_server.h" using namespace OHOS::bluetooth; namespace OHOS { namespace Bluetooth { int BluetoothSocketServer::Connect(ConnectSocketParam ¶m, int &fd) { if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) { HILOGE("false, check permission failed"); return BT_ERR_INTERNAL_ERROR; } IProfileSocket *socket = (IProfileSocket *)IProfileManager::GetInstance()->GetProfileService(PROFILE_NAME_SPP); if (socket != nullptr) { fd = socket->Connect(param.addr, param.uuid, (int)param.securityFlag, (int)param.type); } return NO_ERROR; } int BluetoothSocketServer::Listen(ListenSocketParam ¶m, int &fd) { if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) { HILOGE("false, check permission failed"); return BT_ERR_PERMISSION_FAILED; } IProfileSocket *socket = (IProfileSocket *)IProfileManager::GetInstance()->GetProfileService(PROFILE_NAME_SPP); if (socket != nullptr) { fd = socket->Listen(param.name, param.uuid, (int)param.securityFlag, (int)param.type); } if (fd != -1 && param.observer != nullptr) { socketObserverList_->AddObserver(fd, param.observer->AsObject()); } return NO_ERROR; } int BluetoothSocketServer::DeregisterServerObserver(const sptr &observer) { socketObserverList_->RemoveObserver(observer->AsObject()); return NO_ERROR; } int BluetoothSocketServer::RegisterClientObserver(const BluetoothRawAddress &addr, const bluetooth::Uuid uuid, const sptr &observer) { return BT_ERR_API_NOT_SUPPORT; } int BluetoothSocketServer::DeregisterClientObserver(const BluetoothRawAddress &addr, const bluetooth::Uuid uuid, const sptr &observer) { return BT_ERR_API_NOT_SUPPORT; } int BluetoothSocketServer::UpdateCocConnectionParams(const BluetoothSocketCocInfo &info) { return BT_ERR_API_NOT_SUPPORT; } } // namespace Bluetooth } // namespace OHOS