1/* 2 * Copyright (c) 2023-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/** 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 */ 31/** 32 * Provides basic profile methods. 33 * 34 * @namespace baseProfile 35 * @syscap SystemCapability.Communication.Bluetooth.Core 36 * @crossplatform 37 * @since 13 38 */ 39declare namespace baseProfile { 40 /** 41 * Indicate the profile connection state. 42 * 43 * @typedef { constant.ProfileConnectionState } ProfileConnectionState 44 * @syscap SystemCapability.Communication.Bluetooth.Core 45 * @since 10 46 */ 47 /** 48 * Indicate the profile connection state. 49 * 50 * @typedef { constant.ProfileConnectionState } ProfileConnectionState 51 * @syscap SystemCapability.Communication.Bluetooth.Core 52 * @crossplatform 53 * @since 13 54 */ 55 type ProfileConnectionState = constant.ProfileConnectionState; 56 57 /** 58 * Enum for connection strategy of the profile 59 * 60 * @enum { number } 61 * @syscap SystemCapability.Communication.Bluetooth.Core 62 * @systemapi 63 * @since 10 64 */ 65 export enum ConnectionStrategy { 66 /** 67 * The value of connection strategy unsupported. 68 * 69 * @syscap SystemCapability.Communication.Bluetooth.Core 70 * @systemapi 71 * @since 10 72 */ 73 CONNECTION_STRATEGY_UNSUPPORTED = 0, 74 /** 75 * The value of connection strategy allowed. 76 * 77 * @syscap SystemCapability.Communication.Bluetooth.Core 78 * @systemapi 79 * @since 10 80 */ 81 CONNECTION_STRATEGY_ALLOWED = 1, 82 /** 83 * The value of connection strategy forbidden. 84 * 85 * @syscap SystemCapability.Communication.Bluetooth.Core 86 * @systemapi 87 * @since 10 88 */ 89 CONNECTION_STRATEGY_FORBIDDEN = 2 90 } 91 92 /** 93 * Enum for cause of disconnect. 94 * 95 * @enum { number } 96 * @syscap SystemCapability.Communication.Bluetooth.Core 97 * @since 12 98 */ 99 /** 100 * Enum for cause of disconnect. 101 * 102 * @enum { number } 103 * @syscap SystemCapability.Communication.Bluetooth.Core 104 * @crossplatform 105 * @since 13 106 */ 107 enum DisconnectCause { 108 /** 109 * User disconnect device. 110 * 111 * @syscap SystemCapability.Communication.Bluetooth.Core 112 * @since 12 113 */ 114 /** 115 * User disconnect device. 116 * 117 * @syscap SystemCapability.Communication.Bluetooth.Core 118 * @crossplatform 119 * @since 13 120 */ 121 USER_DISCONNECT = 0, 122 /** 123 * The connection needs to be initiated from the keyboard side. 124 * 125 * @syscap SystemCapability.Communication.Bluetooth.Core 126 * @since 12 127 */ 128 CONNECT_FROM_KEYBOARD = 1, 129 /** 130 * The connection needs to be initiated from the mouse side. 131 * 132 * @syscap SystemCapability.Communication.Bluetooth.Core 133 * @since 12 134 */ 135 CONNECT_FROM_MOUSE = 2, 136 /** 137 * The connection needs to be initiated from the car side. 138 * 139 * @syscap SystemCapability.Communication.Bluetooth.Core 140 * @since 12 141 */ 142 CONNECT_FROM_CAR = 3, 143 /** 144 * Too many devices are currently connected. 145 * 146 * @syscap SystemCapability.Communication.Bluetooth.Core 147 * @since 12 148 */ 149 TOO_MANY_CONNECTED_DEVICES = 4, 150 /** 151 * Connection failed due to an internal error. 152 * 153 * @syscap SystemCapability.Communication.Bluetooth.Core 154 * @since 12 155 */ 156 CONNECT_FAIL_INTERNAL = 5 157 } 158 159 /** 160 * Profile state change parameters. 161 * 162 * @typedef StateChangeParam 163 * @syscap SystemCapability.Communication.Bluetooth.Core 164 * @since 10 165 */ 166 /** 167 * Profile state change parameters. 168 * 169 * @typedef StateChangeParam 170 * @syscap SystemCapability.Communication.Bluetooth.Core 171 * @crossplatform 172 * @since 13 173 */ 174 export interface StateChangeParam { 175 /** 176 * The address of device 177 * 178 * @type { string } 179 * @syscap SystemCapability.Communication.Bluetooth.Core 180 * @since 10 181 */ 182 /** 183 * The address of device 184 * 185 * @type { string } 186 * @syscap SystemCapability.Communication.Bluetooth.Core 187 * @crossplatform 188 * @since 13 189 */ 190 deviceId: string; 191 192 /** 193 * Profile state value 194 * 195 * @type { ProfileConnectionState } 196 * @syscap SystemCapability.Communication.Bluetooth.Core 197 * @since 10 198 */ 199 /** 200 * Profile state value 201 * 202 * @type { ProfileConnectionState } 203 * @syscap SystemCapability.Communication.Bluetooth.Core 204 * @crossplatform 205 * @since 13 206 */ 207 state: ProfileConnectionState; 208 209 /** 210 * Cause of disconnect 211 * 212 * @type { DisconnectCause } 213 * @syscap SystemCapability.Communication.Bluetooth.Core 214 * @since 12 215 */ 216 /** 217 * Cause of disconnect 218 * 219 * @type { DisconnectCause } 220 * @syscap SystemCapability.Communication.Bluetooth.Core 221 * @crossplatform 222 * @since 13 223 */ 224 cause: DisconnectCause; 225 } 226 227 /** 228 * Base interface of profile. 229 * 230 * @typedef BaseProfile 231 * @syscap SystemCapability.Communication.Bluetooth.Core 232 * @since 10 233 */ 234 /** 235 * Base interface of profile. 236 * 237 * @typedef BaseProfile 238 * @syscap SystemCapability.Communication.Bluetooth.Core 239 * @crossplatform 240 * @since 13 241 */ 242 export interface BaseProfile { 243 /** 244 * Set connection strategy of this profile. 245 * 246 * @permission ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH 247 * @param { string } deviceId - Indicates device ID. For example, "11:22:33:AA:BB:FF". 248 * @param { ConnectionStrategy } strategy - the connection strategy of this profile. 249 * @returns { Promise<void> } Returns the promise object. 250 * @throws { BusinessError } 201 - Permission denied. 251 * @throws { BusinessError } 202 - Non-system applications are not allowed to use system APIs. 252 * @throws { BusinessError } 401 - Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 253 * <br>2. Incorrect parameter types. 3. Parameter verification failed. 254 * @throws { BusinessError } 801 - Capability not supported. 255 * @throws { BusinessError } 2900001 - Service stopped. 256 * @throws { BusinessError } 2900003 - Bluetooth disabled. 257 * @throws { BusinessError } 2900004 - Profile not supported. 258 * @throws { BusinessError } 2900099 - Operation failed. 259 * @syscap SystemCapability.Communication.Bluetooth.Core 260 * @systemapi 261 * @since 10 262 */ 263 setConnectionStrategy(deviceId: string, strategy: ConnectionStrategy): Promise<void>; 264 265 /** 266 * Set connection strategy of this profile. 267 * 268 * @permission ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH 269 * @param { string } deviceId - Indicates device ID. For example, "11:22:33:AA:BB:FF". 270 * @param { ConnectionStrategy } strategy - the connection strategy of this profile. 271 * @param { AsyncCallback<void> } callback - the callback of setConnectionStrategy. 272 * @throws { BusinessError } 201 - Permission denied. 273 * @throws { BusinessError } 202 - Non-system applications are not allowed to use system APIs. 274 * @throws { BusinessError } 401 - Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 275 * <br>2. Incorrect parameter types. 3. Parameter verification failed. 276 * @throws { BusinessError } 801 - Capability not supported. 277 * @throws { BusinessError } 2900001 - Service stopped. 278 * @throws { BusinessError } 2900003 - Bluetooth disabled. 279 * @throws { BusinessError } 2900004 - Profile not supported. 280 * @throws { BusinessError } 2900099 - Operation failed. 281 * @syscap SystemCapability.Communication.Bluetooth.Core 282 * @systemapi 283 * @since 10 284 */ 285 setConnectionStrategy(deviceId: string, strategy: ConnectionStrategy, callback: AsyncCallback<void>): void; 286 287 /** 288 * Get connection strategy of this profile. 289 * 290 * @permission ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH 291 * @param { string } deviceId - Indicates device ID. For example, "11:22:33:AA:BB:FF". 292 * @param { AsyncCallback<ConnectionStrategy> } callback - the callback of getConnectionStrategy. 293 * @throws { BusinessError } 201 - Permission denied. 294 * @throws { BusinessError } 202 - Non-system applications are not allowed to use system APIs. 295 * @throws { BusinessError } 401 - Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 296 * <br>2. Incorrect parameter types. 3. Parameter verification failed. 297 * @throws { BusinessError } 801 - Capability not supported. 298 * @throws { BusinessError } 2900001 - Service stopped. 299 * @throws { BusinessError } 2900003 - Bluetooth disabled. 300 * @throws { BusinessError } 2900004 - Profile not supported. 301 * @throws { BusinessError } 2900099 - Operation failed. 302 * @syscap SystemCapability.Communication.Bluetooth.Core 303 * @systemapi 304 * @since 10 305 */ 306 getConnectionStrategy(deviceId: string, callback: AsyncCallback<ConnectionStrategy>): void; 307 308 /** 309 * Get connection strategy of this profile. 310 * 311 * @permission ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH 312 * @param { string } deviceId - Indicates device ID. For example, "11:22:33:AA:BB:FF". 313 * @returns { Promise<ConnectionStrategy> } Returns the promise object. 314 * @throws { BusinessError } 201 - Permission denied. 315 * @throws { BusinessError } 202 - Non-system applications are not allowed to use system APIs. 316 * @throws { BusinessError } 401 - Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 317 * <br>2. Incorrect parameter types. 3. Parameter verification failed. 318 * @throws { BusinessError } 801 - Capability not supported. 319 * @throws { BusinessError } 2900001 - Service stopped. 320 * @throws { BusinessError } 2900003 - Bluetooth disabled. 321 * @throws { BusinessError } 2900004 - Profile not supported. 322 * @throws { BusinessError } 2900099 - Operation failed. 323 * @syscap SystemCapability.Communication.Bluetooth.Core 324 * @systemapi 325 * @since 10 326 */ 327 getConnectionStrategy(deviceId: string): Promise<ConnectionStrategy>; 328 329 /** 330 * Obtains the connected devices list of profile. 331 * 332 * @permission ohos.permission.ACCESS_BLUETOOTH 333 * @returns { Array<string> } Returns the address of connected devices list. 334 * @throws { BusinessError } 201 - Permission denied. 335 * @throws { BusinessError } 801 - Capability not supported. 336 * @throws { BusinessError } 2900001 - Service stopped. 337 * @throws { BusinessError } 2900003 - Bluetooth disabled. 338 * @throws { BusinessError } 2900004 - Profile not supported. 339 * @throws { BusinessError } 2900099 - Operation failed. 340 * @syscap SystemCapability.Communication.Bluetooth.Core 341 * @since 10 342 */ 343 /** 344 * Obtains the connected devices list of profile. 345 * 346 * @permission ohos.permission.ACCESS_BLUETOOTH 347 * @returns { Array<string> } Returns the address of connected devices list. 348 * @throws { BusinessError } 201 - Permission denied. 349 * @throws { BusinessError } 801 - Capability not supported. 350 * @throws { BusinessError } 2900001 - Service stopped. 351 * @throws { BusinessError } 2900003 - Bluetooth disabled. 352 * @throws { BusinessError } 2900004 - Profile not supported. 353 * @throws { BusinessError } 2900099 - Operation failed. 354 * @syscap SystemCapability.Communication.Bluetooth.Core 355 * @crossplatform 356 * @since 13 357 */ 358 getConnectedDevices(): Array<string>; 359 360 /** 361 * Obtains the profile connection state. 362 * 363 * @permission ohos.permission.ACCESS_BLUETOOTH 364 * @param { string } deviceId - Indicates device ID. For example, "11:22:33:AA:BB:FF". 365 * @returns { ProfileConnectionState } Returns the connection state. 366 * @throws { BusinessError } 201 - Permission denied. 367 * @throws { BusinessError } 401 - Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 368 * <br>2. Incorrect parameter types. 3. Parameter verification failed. 369 * @throws { BusinessError } 801 - Capability not supported. 370 * @throws { BusinessError } 2900001 - Service stopped. 371 * @throws { BusinessError } 2900003 - Bluetooth disabled. 372 * @throws { BusinessError } 2900004 - Profile not supported. 373 * @throws { BusinessError } 2900099 - Operation failed. 374 * @syscap SystemCapability.Communication.Bluetooth.Core 375 * @since 10 376 */ 377 /** 378 * Obtains the profile connection state. 379 * 380 * @permission ohos.permission.ACCESS_BLUETOOTH 381 * @param { string } deviceId - Indicates device ID. For example, "11:22:33:AA:BB:FF". 382 * @returns { ProfileConnectionState } Returns the connection state. 383 * @throws { BusinessError } 201 - Permission denied. 384 * @throws { BusinessError } 401 - Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 385 * <br>2. Incorrect parameter types. 3. Parameter verification failed. 386 * @throws { BusinessError } 801 - Capability not supported. 387 * @throws { BusinessError } 2900001 - Service stopped. 388 * @throws { BusinessError } 2900003 - Bluetooth disabled. 389 * @throws { BusinessError } 2900004 - Profile not supported. 390 * @throws { BusinessError } 2900099 - Operation failed. 391 * @syscap SystemCapability.Communication.Bluetooth.Core 392 * @crossplatform 393 * @since 13 394 */ 395 getConnectionState(deviceId: string): ProfileConnectionState; 396 397 /** 398 * Subscribe the event reported when the profile connection state changes . 399 * 400 * @permission ohos.permission.ACCESS_BLUETOOTH 401 * @param { 'connectionStateChange' } type - Type of the profile connection state changes event to listen for. 402 * @param { Callback<StateChangeParam> } callback - Callback used to listen for event. 403 * @throws { BusinessError } 201 - Permission denied. 404 * @throws { BusinessError } 401 - Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 405 * <br>2. Incorrect parameter types. 3. Parameter verification failed. 406 * @throws { BusinessError } 801 - Capability not supported. 407 * @syscap SystemCapability.Communication.Bluetooth.Core 408 * @since 10 409 */ 410 /** 411 * Subscribe the event reported when the profile connection state changes . 412 * 413 * @permission ohos.permission.ACCESS_BLUETOOTH 414 * @param { 'connectionStateChange' } type - Type of the profile connection state changes event to listen for. 415 * @param { Callback<StateChangeParam> } callback - Callback used to listen for event. 416 * @throws { BusinessError } 201 - Permission denied. 417 * @throws { BusinessError } 401 - Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 418 * <br>2. Incorrect parameter types. 3. Parameter verification failed. 419 * @throws { BusinessError } 801 - Capability not supported. 420 * @syscap SystemCapability.Communication.Bluetooth.Core 421 * @crossplatform 422 * @since 13 423 */ 424 on(type: 'connectionStateChange', callback: Callback<StateChangeParam>): void; 425 426 /** 427 * Unsubscribe the event reported when the profile connection state changes . 428 * 429 * @permission ohos.permission.ACCESS_BLUETOOTH 430 * @param { 'connectionStateChange' } type - Type of the profile connection state changes event to listen for. 431 * @param { Callback<StateChangeParam> } callback - Callback used to listen for event. 432 * @throws { BusinessError } 201 - Permission denied. 433 * @throws { BusinessError } 401 - Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 434 * <br>2. Incorrect parameter types. 3. Parameter verification failed. 435 * @throws { BusinessError } 801 - Capability not supported. 436 * @syscap SystemCapability.Communication.Bluetooth.Core 437 * @since 10 438 */ 439 /** 440 * Unsubscribe the event reported when the profile connection state changes . 441 * 442 * @permission ohos.permission.ACCESS_BLUETOOTH 443 * @param { 'connectionStateChange' } type - Type of the profile connection state changes event to listen for. 444 * @param { Callback<StateChangeParam> } callback - Callback used to listen for event. 445 * @throws { BusinessError } 201 - Permission denied. 446 * @throws { BusinessError } 401 - Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 447 * <br>2. Incorrect parameter types. 3. Parameter verification failed. 448 * @throws { BusinessError } 801 - Capability not supported. 449 * @syscap SystemCapability.Communication.Bluetooth.Core 450 * @crossplatform 451 * @since 13 452 */ 453 off(type: 'connectionStateChange', callback?: Callback<StateChangeParam>): void; 454 } 455} 456 457export default baseProfile;