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 21 import type { AsyncCallback, Callback } from './@ohos.base'; 22 import 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 declare namespace baseProfile { 32 /** 33 * Indicate the profile connection state. 34 * 35 * @typedef { constant.ProfileConnectionState } ProfileConnectionState 36 * @syscap SystemCapability.Communication.Bluetooth.Core 37 * @since 10 38 */ 39 type ProfileConnectionState = constant.ProfileConnectionState; 40 41 /** 42 * Enum for connection strategy of the profile 43 * 44 * @enum { number } 45 * @syscap SystemCapability.Communication.Bluetooth.Core 46 * @systemapi 47 * @since 10 48 */ 49 export enum ConnectionStrategy { 50 /** 51 * The value of connection strategy unsupported. 52 * 53 * @syscap SystemCapability.Communication.Bluetooth.Core 54 * @systemapi 55 * @since 10 56 */ 57 CONNECTION_STRATEGY_UNSUPPORTED = 0, 58 /** 59 * The value of connection strategy allowed. 60 * 61 * @syscap SystemCapability.Communication.Bluetooth.Core 62 * @systemapi 63 * @since 10 64 */ 65 CONNECTION_STRATEGY_ALLOWED = 1, 66 /** 67 * The value of connection strategy forbidden. 68 * 69 * @syscap SystemCapability.Communication.Bluetooth.Core 70 * @systemapi 71 * @since 10 72 */ 73 CONNECTION_STRATEGY_FORBIDDEN = 2 74 } 75 76 /** 77 * Enum for cause of disconnect. 78 * 79 * @enum { number } 80 * @syscap SystemCapability.Communication.Bluetooth.Core 81 * @since 12 82 */ 83 enum DisconnectCause { 84 /** 85 * User disconnect device. 86 * 87 * @syscap SystemCapability.Communication.Bluetooth.Core 88 * @since 12 89 */ 90 USER_DISCONNECT = 0, 91 /** 92 * The connection needs to be initiated from the keyboard side. 93 * 94 * @syscap SystemCapability.Communication.Bluetooth.Core 95 * @since 12 96 */ 97 CONNECT_FROM_KEYBOARD = 1, 98 /** 99 * The connection needs to be initiated from the mouse side. 100 * 101 * @syscap SystemCapability.Communication.Bluetooth.Core 102 * @since 12 103 */ 104 CONNECT_FROM_MOUSE = 2, 105 /** 106 * The connection needs to be initiated from the car side. 107 * 108 * @syscap SystemCapability.Communication.Bluetooth.Core 109 * @since 12 110 */ 111 CONNECT_FROM_CAR = 3, 112 /** 113 * Too many devices are currently connected. 114 * 115 * @syscap SystemCapability.Communication.Bluetooth.Core 116 * @since 12 117 */ 118 TOO_MANY_CONNECTED_DEVICES = 4, 119 /** 120 * Connection failed due to an internal error. 121 * 122 * @syscap SystemCapability.Communication.Bluetooth.Core 123 * @since 12 124 */ 125 CONNECT_FAIL_INTERNAL = 5 126 } 127 128 /** 129 * Profile state change parameters. 130 * 131 * @typedef StateChangeParam 132 * @syscap SystemCapability.Communication.Bluetooth.Core 133 * @since 10 134 */ 135 export interface StateChangeParam { 136 /** 137 * The address of device 138 * 139 * @syscap SystemCapability.Communication.Bluetooth.Core 140 * @since 10 141 */ 142 deviceId: string; 143 144 /** 145 * Profile state value 146 * 147 * @syscap SystemCapability.Communication.Bluetooth.Core 148 * @since 10 149 */ 150 state: ProfileConnectionState; 151 152 /** 153 * Cause of disconnect 154 * 155 * @type { DisconnectCause } 156 * @syscap SystemCapability.Communication.Bluetooth.Core 157 * @since 12 158 */ 159 cause: DisconnectCause; 160 } 161 162 /** 163 * Base interface of profile. 164 * 165 * @typedef BaseProfile 166 * @syscap SystemCapability.Communication.Bluetooth.Core 167 * @since 10 168 */ 169 export interface BaseProfile { 170 /** 171 * Set 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 * @param { ConnectionStrategy } strategy - the connection strategy of this profile. 176 * @returns { Promise<void> } Returns the promise object. 177 * @throws { BusinessError } 201 - Permission denied. 178 * @throws { BusinessError } 202 - Non-system applications are not allowed to use system APIs. 179 * @throws { BusinessError } 401 - Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 180 * <br>2. Incorrect parameter types. 3. Parameter verification failed. 181 * @throws { BusinessError } 801 - Capability not supported. 182 * @throws { BusinessError } 2900001 - Service stopped. 183 * @throws { BusinessError } 2900003 - Bluetooth switch is off. 184 * @throws { BusinessError } 2900004 - Profile is not supported. 185 * @throws { BusinessError } 2900099 - Operation failed. 186 * @syscap SystemCapability.Communication.Bluetooth.Core 187 * @systemapi 188 * @since 10 189 */ 190 setConnectionStrategy(deviceId: string, strategy: ConnectionStrategy): Promise<void>; 191 192 /** 193 * Set connection strategy of this profile. 194 * 195 * @permission ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH 196 * @param { string } deviceId - Indicates device ID. For example, "11:22:33:AA:BB:FF". 197 * @param { ConnectionStrategy } strategy - the connection strategy of this profile. 198 * @param { AsyncCallback<void> } callback - the callback of setConnectionStrategy. 199 * @throws { BusinessError } 201 - Permission denied. 200 * @throws { BusinessError } 202 - Non-system applications are not allowed to use system APIs. 201 * @throws { BusinessError } 401 - Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 202 * <br>2. Incorrect parameter types. 3. Parameter verification failed. 203 * @throws { BusinessError } 801 - Capability not supported. 204 * @throws { BusinessError } 2900001 - Service stopped. 205 * @throws { BusinessError } 2900003 - Bluetooth switch is off. 206 * @throws { BusinessError } 2900004 - Profile is not supported. 207 * @throws { BusinessError } 2900099 - Operation failed. 208 * @syscap SystemCapability.Communication.Bluetooth.Core 209 * @systemapi 210 * @since 10 211 */ 212 setConnectionStrategy(deviceId: string, strategy: ConnectionStrategy, callback: AsyncCallback<void>): void; 213 214 /** 215 * Get connection strategy of this profile. 216 * 217 * @permission ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH 218 * @param { string } deviceId - Indicates device ID. For example, "11:22:33:AA:BB:FF". 219 * @param { AsyncCallback<ConnectionStrategy> } callback - the callback of getConnectionStrategy. 220 * @throws { BusinessError } 201 - Permission denied. 221 * @throws { BusinessError } 202 - Non-system applications are not allowed to use system APIs. 222 * @throws { BusinessError } 401 - Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 223 * <br>2. Incorrect parameter types. 3. Parameter verification failed. 224 * @throws { BusinessError } 801 - Capability not supported. 225 * @throws { BusinessError } 2900001 - Service stopped. 226 * @throws { BusinessError } 2900003 - Bluetooth switch is off. 227 * @throws { BusinessError } 2900004 - Profile is not supported. 228 * @throws { BusinessError } 2900099 - Operation failed. 229 * @syscap SystemCapability.Communication.Bluetooth.Core 230 * @systemapi 231 * @since 10 232 */ 233 getConnectionStrategy(deviceId: string, callback: AsyncCallback<ConnectionStrategy>): void; 234 235 /** 236 * Get connection strategy of this profile. 237 * 238 * @permission ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH 239 * @param { string } deviceId - Indicates device ID. For example, "11:22:33:AA:BB:FF". 240 * @returns { Promise<ConnectionStrategy> } Returns the promise object. 241 * @throws { BusinessError } 201 - Permission denied. 242 * @throws { BusinessError } 202 - Non-system applications are not allowed to use system APIs. 243 * @throws { BusinessError } 401 - Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 244 * <br>2. Incorrect parameter types. 3. Parameter verification failed. 245 * @throws { BusinessError } 801 - Capability not supported. 246 * @throws { BusinessError } 2900001 - Service stopped. 247 * @throws { BusinessError } 2900003 - Bluetooth switch is off. 248 * @throws { BusinessError } 2900004 - Profile is not supported. 249 * @throws { BusinessError } 2900099 - Operation failed. 250 * @syscap SystemCapability.Communication.Bluetooth.Core 251 * @systemapi 252 * @since 10 253 */ 254 getConnectionStrategy(deviceId: string): Promise<ConnectionStrategy>; 255 256 /** 257 * Obtains the connected devices list of profile. 258 * 259 * @permission ohos.permission.ACCESS_BLUETOOTH 260 * @returns { Array<string> } Returns the address of connected devices list. 261 * @throws { BusinessError } 201 - Permission denied. 262 * @throws { BusinessError } 801 - Capability not supported. 263 * @throws { BusinessError } 2900001 - Service stopped. 264 * @throws { BusinessError } 2900003 - Bluetooth switch is off. 265 * @throws { BusinessError } 2900004 - Profile is not supported. 266 * @throws { BusinessError } 2900099 - Operation failed. 267 * @syscap SystemCapability.Communication.Bluetooth.Core 268 * @since 10 269 */ 270 getConnectedDevices(): Array<string>; 271 272 /** 273 * Obtains the profile connection state. 274 * 275 * @permission ohos.permission.ACCESS_BLUETOOTH 276 * @param { string } deviceId - Indicates device ID. For example, "11:22:33:AA:BB:FF". 277 * @returns { ProfileConnectionState } Returns the connection state. 278 * @throws { BusinessError } 201 - Permission denied. 279 * @throws { BusinessError } 401 - Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 280 * <br>2. Incorrect parameter types. 3. Parameter verification failed. 281 * @throws { BusinessError } 801 - Capability not supported. 282 * @throws { BusinessError } 2900001 - Service stopped. 283 * @throws { BusinessError } 2900003 - Bluetooth switch is off. 284 * @throws { BusinessError } 2900004 - Profile is not supported. 285 * @throws { BusinessError } 2900099 - Operation failed. 286 * @syscap SystemCapability.Communication.Bluetooth.Core 287 * @since 10 288 */ 289 getConnectionState(deviceId: string): ProfileConnectionState; 290 291 /** 292 * Subscribe the event reported when the profile connection state changes . 293 * 294 * @permission ohos.permission.ACCESS_BLUETOOTH 295 * @param { 'connectionStateChange' } type - Type of the profile connection state changes event to listen for. 296 * @param { Callback<StateChangeParam> } callback - Callback used to listen for event. 297 * @throws { BusinessError } 201 - Permission denied. 298 * @throws { BusinessError } 401 - Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 299 * <br>2. Incorrect parameter types. 3. Parameter verification failed. 300 * @throws { BusinessError } 801 - Capability not supported. 301 * @syscap SystemCapability.Communication.Bluetooth.Core 302 * @since 10 303 */ 304 on(type: 'connectionStateChange', callback: Callback<StateChangeParam>): void; 305 306 /** 307 * Unsubscribe the event reported when the profile connection state changes . 308 * 309 * @permission ohos.permission.ACCESS_BLUETOOTH 310 * @param { 'connectionStateChange' } type - Type of the profile connection state changes event to listen for. 311 * @param { Callback<StateChangeParam> } callback - Callback used to listen for event. 312 * @throws { BusinessError } 201 - Permission denied. 313 * @throws { BusinessError } 401 - Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 314 * <br>2. Incorrect parameter types. 3. Parameter verification failed. 315 * @throws { BusinessError } 801 - Capability not supported. 316 * @syscap SystemCapability.Communication.Bluetooth.Core 317 * @since 10 318 */ 319 off(type: 'connectionStateChange', callback?: Callback<StateChangeParam>): void; 320 } 321 } 322 323 export default baseProfile;