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/** 17 * @file 18 * @kit ConnectivityKit 19 */ 20 21import type { AsyncCallback, Callback } from './@ohos.base'; 22import type constant from './@ohos.bluetooth.constant'; 23 24/** 25 * Provides basic profile methods. 26 * 27 * @namespace baseProfile 28 * @syscap SystemCapability.Communication.Bluetooth.Core 29 * @since 10 30 */ 31declare namespace baseProfile { 32 /** 33 * Indicate the profile connection state. 34 * 35 * @syscap SystemCapability.Communication.Bluetooth.Core 36 * @since 10 37 */ 38 type ProfileConnectionState = constant.ProfileConnectionState; 39 40 /** 41 * Enum for connection strategy of the profile 42 * 43 * @enum { number } 44 * @syscap SystemCapability.Communication.Bluetooth.Core 45 * @systemapi 46 * @since 10 47 */ 48 export enum ConnectionStrategy { 49 /** 50 * The value of connection strategy unsupported. 51 * 52 * @syscap SystemCapability.Communication.Bluetooth.Core 53 * @systemapi 54 * @since 10 55 */ 56 CONNECTION_STRATEGY_UNSUPPORTED = 0, 57 /** 58 * The value of connection strategy allowed. 59 * 60 * @syscap SystemCapability.Communication.Bluetooth.Core 61 * @systemapi 62 * @since 10 63 */ 64 CONNECTION_STRATEGY_ALLOWED = 1, 65 /** 66 * The value of connection strategy forbidden. 67 * 68 * @syscap SystemCapability.Communication.Bluetooth.Core 69 * @systemapi 70 * @since 10 71 */ 72 CONNECTION_STRATEGY_FORBIDDEN = 2 73 } 74 75 /** 76 * Profile state change parameters. 77 * 78 * @typedef StateChangeParam 79 * @syscap SystemCapability.Communication.Bluetooth.Core 80 * @since 10 81 */ 82 export interface StateChangeParam { 83 /** 84 * The address of device 85 * 86 * @syscap SystemCapability.Communication.Bluetooth.Core 87 * @since 10 88 */ 89 deviceId: string; 90 91 /** 92 * Profile state value 93 * 94 * @syscap SystemCapability.Communication.Bluetooth.Core 95 * @since 10 96 */ 97 state: ProfileConnectionState; 98 } 99 100 /** 101 * Base interface of profile. 102 * 103 * @typedef BaseProfile 104 * @syscap SystemCapability.Communication.Bluetooth.Core 105 * @since 10 106 */ 107 export interface BaseProfile { 108 /** 109 * Set connection strategy of this profile. 110 * 111 * @permission ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH 112 * @param { string } deviceId - Indicates device ID. For example, "11:22:33:AA:BB:FF". 113 * @param { ConnectionStrategy } strategy - the connection strategy of this profile. 114 * @returns { Promise<void> } Returns the promise object. 115 * @throws { BusinessError } 201 - Permission denied. 116 * @throws { BusinessError } 202 - Non-system applications are not allowed to use system APIs. 117 * @throws { BusinessError } 401 - Invalid parameter. 118 * @throws { BusinessError } 801 - Capability not supported. 119 * @throws { BusinessError } 2900001 - Service stopped. 120 * @throws { BusinessError } 2900003 - Bluetooth switch is off. 121 * @throws { BusinessError } 2900004 - Profile is not supported. 122 * @throws { BusinessError } 2900099 - Operation failed. 123 * @syscap SystemCapability.Communication.Bluetooth.Core 124 * @systemapi 125 * @since 10 126 */ 127 setConnectionStrategy(deviceId: string, strategy: ConnectionStrategy): Promise<void>; 128 129 /** 130 * Set connection strategy of this profile. 131 * 132 * @permission ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH 133 * @param { string } deviceId - Indicates device ID. For example, "11:22:33:AA:BB:FF". 134 * @param { ConnectionStrategy } strategy - the connection strategy of this profile. 135 * @param { AsyncCallback<void> } callback - the callback of setConnectionStrategy. 136 * @throws { BusinessError } 201 - Permission denied. 137 * @throws { BusinessError } 202 - Non-system applications are not allowed to use system APIs. 138 * @throws { BusinessError } 401 - Invalid parameter. 139 * @throws { BusinessError } 801 - Capability not supported. 140 * @throws { BusinessError } 2900001 - Service stopped. 141 * @throws { BusinessError } 2900003 - Bluetooth switch is off. 142 * @throws { BusinessError } 2900004 - Profile is not supported. 143 * @throws { BusinessError } 2900099 - Operation failed. 144 * @syscap SystemCapability.Communication.Bluetooth.Core 145 * @systemapi 146 * @since 10 147 */ 148 setConnectionStrategy(deviceId: string, strategy: ConnectionStrategy, callback: AsyncCallback<void>): void; 149 150 /** 151 * Get connection strategy of this profile. 152 * 153 * @permission ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH 154 * @param { string } deviceId - Indicates device ID. For example, "11:22:33:AA:BB:FF". 155 * @param { AsyncCallback<ConnectionStrategy> } callback - the callback of getConnectionStrategy. 156 * @throws { BusinessError } 201 - Permission denied. 157 * @throws { BusinessError } 202 - Non-system applications are not allowed to use system APIs. 158 * @throws { BusinessError } 401 - Invalid parameter. 159 * @throws { BusinessError } 801 - Capability not supported. 160 * @throws { BusinessError } 2900001 - Service stopped. 161 * @throws { BusinessError } 2900003 - Bluetooth switch is off. 162 * @throws { BusinessError } 2900004 - Profile is not supported. 163 * @throws { BusinessError } 2900099 - Operation failed. 164 * @syscap SystemCapability.Communication.Bluetooth.Core 165 * @systemapi 166 * @since 10 167 */ 168 getConnectionStrategy(deviceId: string, callback: AsyncCallback<ConnectionStrategy>): void; 169 170 /** 171 * Get connection strategy of this profile. 172 * 173 * @permission ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH 174 * @param { string } deviceId - Indicates device ID. For example, "11:22:33:AA:BB:FF". 175 * @returns { Promise<ConnectionStrategy> } Returns the promise object. 176 * @throws { BusinessError } 201 - Permission denied. 177 * @throws { BusinessError } 202 - Non-system applications are not allowed to use system APIs. 178 * @throws { BusinessError } 401 - Invalid parameter. 179 * @throws { BusinessError } 801 - Capability not supported. 180 * @throws { BusinessError } 2900001 - Service stopped. 181 * @throws { BusinessError } 2900003 - Bluetooth switch is off. 182 * @throws { BusinessError } 2900004 - Profile is not supported. 183 * @throws { BusinessError } 2900099 - Operation failed. 184 * @syscap SystemCapability.Communication.Bluetooth.Core 185 * @systemapi 186 * @since 10 187 */ 188 getConnectionStrategy(deviceId: string): Promise<ConnectionStrategy>; 189 190 /** 191 * Obtains the connected devices list of profile. 192 * 193 * @permission ohos.permission.ACCESS_BLUETOOTH 194 * @returns { Array<string> } Returns the address of connected devices list. 195 * @throws { BusinessError } 201 - Permission denied. 196 * @throws { BusinessError } 801 - Capability not supported. 197 * @throws { BusinessError } 2900001 - Service stopped. 198 * @throws { BusinessError } 2900003 - Bluetooth switch is off. 199 * @throws { BusinessError } 2900004 - Profile is not supported. 200 * @throws { BusinessError } 2900099 - Operation failed. 201 * @syscap SystemCapability.Communication.Bluetooth.Core 202 * @since 10 203 */ 204 getConnectedDevices(): Array<string>; 205 206 /** 207 * Obtains the profile connection state. 208 * 209 * @permission ohos.permission.ACCESS_BLUETOOTH 210 * @param { string } deviceId - Indicates device ID. For example, "11:22:33:AA:BB:FF". 211 * @returns { ProfileConnectionState } Returns the connection state. 212 * @throws { BusinessError } 201 - Permission denied. 213 * @throws { BusinessError } 401 - Invalid parameter. 214 * @throws { BusinessError } 801 - Capability not supported. 215 * @throws { BusinessError } 2900001 - Service stopped. 216 * @throws { BusinessError } 2900003 - Bluetooth switch is off. 217 * @throws { BusinessError } 2900004 - Profile is not supported. 218 * @throws { BusinessError } 2900099 - Operation failed. 219 * @syscap SystemCapability.Communication.Bluetooth.Core 220 * @since 10 221 */ 222 getConnectionState(deviceId: string): ProfileConnectionState; 223 224 /** 225 * Subscribe the event reported when the profile connection state changes . 226 * 227 * @permission ohos.permission.ACCESS_BLUETOOTH 228 * @param { 'connectionStateChange' } type - Type of the profile connection state changes event to listen for. 229 * @param { Callback<StateChangeParam> } callback - Callback used to listen for event. 230 * @throws { BusinessError } 201 - Permission denied. 231 * @throws { BusinessError } 401 - Invalid parameter. 232 * @throws { BusinessError } 801 - Capability not supported. 233 * @syscap SystemCapability.Communication.Bluetooth.Core 234 * @since 10 235 */ 236 on(type: 'connectionStateChange', callback: Callback<StateChangeParam>): void; 237 238 /** 239 * Unsubscribe the event reported when the profile connection state changes . 240 * 241 * @permission ohos.permission.ACCESS_BLUETOOTH 242 * @param { 'connectionStateChange' } type - Type of the profile connection state changes event to listen for. 243 * @param { Callback<StateChangeParam> } callback - Callback used to listen for event. 244 * @throws { BusinessError } 201 - Permission denied. 245 * @throws { BusinessError } 401 - Invalid parameter. 246 * @throws { BusinessError } 801 - Capability not supported. 247 * @syscap SystemCapability.Communication.Bluetooth.Core 248 * @since 10 249 */ 250 off(type: 'connectionStateChange', callback?: Callback<StateChangeParam>): void; 251 } 252} 253 254export default baseProfile;