1/* 2 * Copyright (c) 2025 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 DistributedServiceKit 19 */ 20 21/** 22 * The proxy channel management module provides functions for opening and closing proxy channels, sending data, as well 23 * as functions for registering and unregistering, receiving data, and receiving channel status callback functions. 24 * 25 * @namespace proxyChannelManager 26 * @syscap SystemCapability.DistributedSched.AppCollaboration 27 * @since 20 28 */ 29declare namespace proxyChannelManager { 30 /** 31 * According to the parameters passed by the business, open the proxy channel and return the channel identifier. 32 * 33 * @permission ohos.permission.ACCESS_BLUETOOTH 34 * @param { ChannelInfo } channelInfo - Parameters for creating proxy channel 35 * @returns { Promise<number> } The Promise returned by this function. 36 * @throws { BusinessError } 201 - Permission denied. 37 * @throws { BusinessError } 32390001 - BR is disabled. 38 * @throws { BusinessError } 32390002 - Device not paired. 39 * @throws { BusinessError } 32390006 - Parameter error. 40 * @throws { BusinessError } 32390100 - Internal error. 41 * @throws { BusinessError } 32390101 - Call is restricted. 42 * @throws { BusinessError } 32390102 - Operation failed or Connection timed out. 43 * @syscap SystemCapability.DistributedSched.AppCollaboration 44 * @since 20 45 */ 46 function openProxyChannel(channelInfo: ChannelInfo): Promise<number>; 47 48 /** 49 * Close the proxy channel. 50 * 51 * @permission ohos.permission.ACCESS_BLUETOOTH 52 * @param { number } channelId - Indicates the unique channelId. 53 * @throws { BusinessError } 201 - Permission denied. 54 * @throws { BusinessError } 32390004 - ChannelId is invalid or unavailable. 55 * @throws { BusinessError } 32390006 - Parameter error. 56 * @throws { BusinessError } 32390100 - Internal error. 57 * @throws { BusinessError } 32390101 - Call is restricted. 58 * @syscap SystemCapability.DistributedSched.AppCollaboration 59 * @since 20 60 */ 61 function closeProxyChannel(channelId: number): void; 62 63 /** 64 * Send data to the peer device through proxy channel identification. 65 * 66 * @permission ohos.permission.ACCESS_BLUETOOTH 67 * @param { number } channelId - Indicates the the unique channelId. 68 * @param { ArrayBuffer } data - Indicatesthe message data to send. 69 * @returns { Promise<void> } The promise returned by the function. 70 * @throws { BusinessError } 201 - Permission denied. 71 * @throws { BusinessError } 32390004 - ChannelId is invalid or unavailable. 72 * @throws { BusinessError } 32390006 - Parameter error. 73 * @throws { BusinessError } 32390100 - Internal error. 74 * @throws { BusinessError } 32390101 - Call is restricted. 75 * @throws { BusinessError } 32390103 - Data too long. 76 * @throws { BusinessError } 32390104 - Send failed. 77 * @syscap SystemCapability.DistributedSched.AppCollaboration 78 * @since 20 79 */ 80 function sendData(channelId: number, data: ArrayBuffer): Promise<void>; 81 82 /** 83 * Register to receive data events. 84 * 85 * @permission ohos.permission.ACCESS_BLUETOOTH 86 * @param { 'receiveData' } type - Registration Type, 'receiveData'. 87 * @param { number } channelId - Indicates the unique channelId. 88 * @param { Callback<DataInfo> } callback - Used to handle ('receiveData') command. 89 * @throws { BusinessError } 201 - Permission denied. 90 * @throws { BusinessError } 32390004 - ChannelId is invalid or unavailable. 91 * @throws { BusinessError } 32390006 - Parameter error. 92 * @throws { BusinessError } 32390100 - Internal error. 93 * @throws { BusinessError } 32390101 - Call is restricted. 94 * @syscap SystemCapability.DistributedSched.AppCollaboration 95 * @since 20 96 */ 97 function on(type: 'receiveData', channelId: number, callback: Callback<DataInfo>): void; 98 99 /** 100 * Unregister and receive data events. 101 * 102 * @permission ohos.permission.ACCESS_BLUETOOTH 103 * @param { 'receiveData' } type - Registration Type, 'receiveData'. 104 * @param { number } channelId - Indicates the unique channelId. 105 * @param { Callback<DataInfo> } callback - Used to handle ('receiveData') command. 106 * @throws { BusinessError } 201 - Permission denied. 107 * @throws { BusinessError } 32390004 - ChannelId is invalid or unavailable. 108 * @throws { BusinessError } 32390006 - Parameter error. 109 * @throws { BusinessError } 32390100 - Internal error. 110 * @throws { BusinessError } 32390101 - Call is restricted. 111 * @syscap SystemCapability.DistributedSched.AppCollaboration 112 * @since 20 113 */ 114 function off(type: 'receiveData', channelId: number, callback?: Callback<DataInfo>): void; 115 116 /** 117 * Register to receive channel status events. 118 * 119 * @permission ohos.permission.ACCESS_BLUETOOTH 120 * @param { 'channelStateChange' } type - Registration Type, 'channelStateChange'. 121 * @param { number } channelId - Indicates the unique channelId. 122 * @param { Callback<ChannelStateInfo> } callback - Used to handle ('channelStateChange') command. 123 * @throws { BusinessError } 201 - Permission denied. 124 * @throws { BusinessError } 32390004 - ChannelId is invalid or unavailable. 125 * @throws { BusinessError } 32390006 - Parameter error. 126 * @throws { BusinessError } 32390100 - Internal error. 127 * @throws { BusinessError } 32390101 - Call is restricted. 128 * @syscap SystemCapability.DistributedSched.AppCollaboration 129 * @since 20 130 */ 131 function on(type: 'channelStateChange', channelId: number, callback: Callback<ChannelStateInfo>): void; 132 /** 133 * Unregister the receiving channel status event. 134 * 135 * @permission ohos.permission.ACCESS_BLUETOOTH 136 * @param { 'channelStateChange' } type - Registration Type, 'channelStateChange'. 137 * @param { number } channelId - Indicates the unique channelId. 138 * @param { Callback<ChannelStateInfo> } callback - Used to handle ('channelStateChange') command. 139 * @throws { BusinessError } 201 - Permission denied. 140 * @throws { BusinessError } 32390004 - ChannelId is invalid or unavailable. 141 * @throws { BusinessError } 32390006 - Parameter error. 142 * @throws { BusinessError } 32390100 - Internal error. 143 * @throws { BusinessError } 32390101 - Call is restricted. 144 * @syscap SystemCapability.DistributedSched.AppCollaboration 145 * @since 20 146 */ 147 function off(type: 'channelStateChange', channelId: number, callback?: Callback<ChannelStateInfo>): void; 148 149 /** 150 * Data information structure. 151 * 152 * @interface DataInfo 153 * @syscap SystemCapability.DistributedSched.AppCollaboration 154 * @since 20 155 */ 156 interface DataInfo { 157 /** 158 * Data channel ID. 159 * @type { number } 160 * @syscap SystemCapability.DistributedSched.AppCollaboration 161 * @since 20 162 */ 163 channelId: number; 164 165 /** 166 * Received Data. 167 * @type { ArrayBuffer } 168 * @syscap SystemCapability.DistributedSched.AppCollaboration 169 * @since 20 170 */ 171 data: ArrayBuffer; 172 } 173 /** 174 * Link type of proxy channel. 175 * 176 * @enum { number } 177 * @syscap SystemCapability.DistributedSched.AppCollaboration 178 * @since 20 179 */ 180 enum LinkType { 181 /** 182 * Link type is BR. 183 * 184 * @syscap SystemCapability.DistributedSched.AppCollaboration 185 * @since 20 186 */ 187 LINK_BR = 0, 188 } 189 /** 190 * Parameters for creating proxy channel. 191 * 192 * @interface ChannelInfo 193 * @syscap SystemCapability.DistributedSched.AppCollaboration 194 * @since 20 195 */ 196 interface ChannelInfo { 197 /** 198 * Link type of proxy channel. 199 * 200 * @type { LinkType } 201 * @syscap SystemCapability.DistributedSched.AppCollaboration 202 * @since 20 203 */ 204 linkType: LinkType; 205 /** 206 * The address of the peer device that needs to be connected. 207 * 208 * @type { string } 209 * @syscap SystemCapability.DistributedSched.AppCollaboration 210 * @since 20 211 */ 212 peerDevAddr: string; 213 214 /** 215 * The profile UUID of the peer device that needs to be connected. 216 * 217 * @type { string } 218 * @syscap SystemCapability.DistributedSched.AppCollaboration 219 * @since 20 220 */ 221 peerUuid: string; 222 } 223 /** 224 * Channel status of proxy channel. 225 * 226 * @enum { number } 227 * @syscap SystemCapability.DistributedSched.AppCollaboration 228 * @since 20 229 */ 230 enum ChannelState { 231 /** 232 * Proxy channel disconnected, if the channel is not closed by business, it can recovery. 233 * 234 * @syscap SystemCapability.DistributedSched.AppCollaboration 235 * @since 20 236 */ 237 CHANNEL_WAIT_RESUME = 0, 238 /** 239 * Proxy channel recovery. 240 * 241 * @syscap SystemCapability.DistributedSched.AppCollaboration 242 * @since 20 243 */ 244 CHANNEL_RESUME = 1, 245 /** 246 * Software failure causes channel exception. 247 * 248 * @syscap SystemCapability.DistributedSched.AppCollaboration 249 * @since 20 250 */ 251 CHANNEL_EXCEPTION_SOFTWARE_FAILED = 2, 252 /** 253 * BR unpairing causes proxy channel abnormal. 254 * 255 * @syscap SystemCapability.DistributedSched.AppCollaboration 256 * @since 20 257 */ 258 CHANNEL_BR_NO_PAIRED = 3, 259 } 260 /** 261 * Channel status information of proxy channel. 262 * 263 * @interface ChannelStateInfo 264 * @syscap SystemCapability.DistributedSched.AppCollaboration 265 * @since 20 266 */ 267 interface ChannelStateInfo { 268 /** 269 * channel ID. 270 * @type { number } 271 * @syscap SystemCapability.DistributedSched.AppCollaboration 272 * @since 20 273 */ 274 channelId: number; 275 /** 276 * channel status. 277 * 278 * @type { ChannelState } 279 * @syscap SystemCapability.DistributedSched.AppCollaboration 280 * @since 20 281 */ 282 state: ChannelState; 283 } 284 } 285 export default proxyChannelManager;