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