1/* 2 * Copyright (c) 2022 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 */ 15import { Callback } from './basic'; 16import { AsyncCallback } from './basic'; 17import { ContinuationResult } from './continuation/continuationResult' 18import { ContinuationExtraParams } from './continuation/continuationExtraParams' 19 20/** 21 * Provides methods for interacting with the continuation manager service, including methods for registering and 22 * Unregister the ability to hop, updating the device connection state, and showing the list of devices 23 * that can be selected for hopping. 24 * @namespace continuationManager 25 * @syscap SystemCapability.Ability.DistributedAbilityManager 26 * @since 8 27 */ 28declare namespace continuationManager { 29 /** 30 * Called when the user selects devices from the candidate device list. 31 * You can implement your own processing logic in this callback to initiate the hop process. 32 * 33 * @permission ohos.permission.DISTRIBUTED_DATASYNC 34 * @param type deviceSelected. 35 * @returns callback Indicates the information about the selected devices. 36 * @throws { BusinessError } 201 - Permission denied. 37 * @throws { BusinessError } 401 - The parameter check failed. 38 * @throws { BusinessError } 16600001 - The system ability works abnormally. 39 * @throws { BusinessError } 16600002 - The specified token or callback is not registered. 40 * @throws { BusinessError } 16600004 - The specified callback has been registered. 41 * @syscap SystemCapability.Ability.DistributedAbilityManager 42 * @since 9 43 */ 44 function on(type: "deviceSelected", token: number, callback: Callback<Array<ContinuationResult>>): void; 45 function off(type: "deviceSelected", token: number): void; 46 47 /** 48 * Called when devices are disconnected from the continuation manager service. 49 * You can implement your own processing logic in this callback, such as notifying the user of the disconnection. 50 * 51 * @permission ohos.permission.DISTRIBUTED_DATASYNC 52 * @param type deviceUnselected. 53 * @returns callback Indicates the information about the unselected devices. 54 * @throws { BusinessError } 201 - Permission denied. 55 * @throws { BusinessError } 401 - The parameter check failed. 56 * @throws { BusinessError } 16600001 - The system ability works abnormally. 57 * @throws { BusinessError } 16600002 - The specified token or callback is not registered. 58 * @throws { BusinessError } 16600004 - The specified callback has been registered. 59 * @syscap SystemCapability.Ability.DistributedAbilityManager 60 * @since 9 61 */ 62 function on(type: "deviceUnselected", token: number, callback: Callback<Array<ContinuationResult>>): void; 63 function off(type: "deviceUnselected", token: number): void; 64 65 /** 66 * Called when the user selects a device from the candidate device list. 67 * You can implement your own processing logic in this callback to initiate the hop process. 68 * 69 * @param type deviceConnect. 70 * @returns callback Indicates the information about the selected device. 71 * @syscap SystemCapability.Ability.DistributedAbilityManager 72 * @since 8 73 * @deprecated since 9 74 * @useinstead ohos.continuation.continuationManager.continuationManager#on/off(type: "deviceSelected") 75 */ 76 function on(type: "deviceConnect", callback: Callback<ContinuationResult>): void; 77 function off(type: "deviceConnect", callback?: Callback<ContinuationResult>): void; 78 79 /** 80 * Called when a device is disconnected from the continuation manager service. 81 * You can implement your own processing logic in this callback, such as notifying the user of the disconnection. 82 * 83 * @param type deviceDisconnect. 84 * @returns callback Indicates the ID of the disconnected device. 85 * @syscap SystemCapability.Ability.DistributedAbilityManager 86 * @since 8 87 * @deprecated since 9 88 * @useinstead ohos.continuation.continuationManager.continuationManager#on/off(type: "deviceUnSelected") 89 */ 90 function on(type: "deviceDisconnect", callback: Callback<string>): void; 91 function off(type: "deviceDisconnect", callback?: Callback<string>): void; 92 93 /** 94 * Registers an ability to be hopped with the continuation manager service and obtains the registration token 95 * assigned to the ability. 96 * 97 * @param options Indicates the {@link ExtraParams} object containing the extra parameters used to filter 98 * the list of available devices. 99 * @returns callback Indicates the callback to be invoked when the continuation manager service is connected. 100 * @syscap SystemCapability.Ability.DistributedAbilityManager 101 * @since 8 102 * @deprecated since 9 103 * @useinstead ohos.continuation.continuationManager.continuationManager#registerContinuation 104 */ 105 function register(callback: AsyncCallback<number>): void; 106 function register(options: ContinuationExtraParams, callback: AsyncCallback<number>): void; 107 function register(options?: ContinuationExtraParams): Promise<number>; 108 109 /** 110 * Unregisters a specified ability from the continuation manager service based on the token obtained during ability 111 * registration. 112 * 113 * @param token Indicates the registration token of the ability. 114 * @returns callback Indicates the callback to be invoked when the continuation manager service is connected. 115 * @syscap SystemCapability.Ability.DistributedAbilityManager 116 * @since 8 117 * @deprecated since 9 118 * @useinstead ohos.continuation.continuationManager.continuationManager#unregisterContinuation 119 */ 120 function unregister(token: number, callback: AsyncCallback<void>): void; 121 function unregister(token: number): Promise<void>; 122 123 /** 124 * Updates the connection state of the device where the specified ability is successfully hopped. 125 * 126 * @param token Indicates the registration token of the ability. 127 * @param deviceId Indicates the ID of the device whose connection state is to be updated. 128 * @param status Indicates the connection state to update. 129 * @returns callback Indicates the callback to be invoked when the continuation manager service is connected. 130 * @syscap SystemCapability.Ability.DistributedAbilityManager 131 * @since 8 132 * @deprecated since 9 133 * @useinstead ohos.continuation.continuationManager.continuationManager#updateContinuationState 134 */ 135 function updateConnectStatus(token: number, deviceId: string, status: DeviceConnectState, callback: AsyncCallback<void>): void; 136 function updateConnectStatus(token: number, deviceId: string, status: DeviceConnectState): Promise<void>; 137 138 /** 139 * Start to manage the devices that can be selected for continuation. 140 * 141 * @param token Indicates the registration token of the ability. 142 * @param options Indicates the extraParams object containing the extra parameters used to filter 143 * the list of available devices. This parameter can be null. 144 * @returns callback Indicates the callback to be invoked when the continuation manager service is connected. 145 * @syscap SystemCapability.Ability.DistributedAbilityManager 146 * @since 8 147 * @deprecated since 9 148 * @useinstead ohos.continuation.continuationManager.continuationManager#startContinuationDeviceManager 149 */ 150 function startDeviceManager(token: number, callback: AsyncCallback<void>): void; 151 function startDeviceManager(token: number, options: ContinuationExtraParams, callback: AsyncCallback<void>): void; 152 function startDeviceManager(token: number, options?: ContinuationExtraParams): Promise<void>; 153 154 /** 155 * Registers an ability to be hopped with the continuation manager service and obtains the registration token 156 * assigned to the ability. 157 * 158 * @permission ohos.permission.DISTRIBUTED_DATASYNC 159 * @param options Indicates the {@link ExtraParams} object containing the extra parameters used to filter 160 * the list of available devices. 161 * @returns callback Indicates the callback to be invoked when the continuation manager service is connected. 162 * @throws { BusinessError } 201 - Permission denied. 163 * @throws { BusinessError } 401 - The parameter check failed. 164 * @throws { BusinessError } 16600001 - The system ability works abnormally. 165 * @throws { BusinessError } 16600003 - The number of token registration times has reached the upper limit. 166 * @syscap SystemCapability.Ability.DistributedAbilityManager 167 * @since 9 168 */ 169 function registerContinuation(callback: AsyncCallback<number>): void; 170 function registerContinuation(options: ContinuationExtraParams, callback: AsyncCallback<number>): void; 171 function registerContinuation(options?: ContinuationExtraParams): Promise<number>; 172 173 /** 174 * Unregisters a specified ability from the continuation manager service based on the token obtained during ability 175 * registration. 176 * 177 * @permission ohos.permission.DISTRIBUTED_DATASYNC 178 * @param token Indicates the registration token of the ability. 179 * @returns callback Indicates the callback to be invoked when the continuation manager service is connected. 180 * @throws { BusinessError } 201 - Permission denied. 181 * @throws { BusinessError } 401 - The parameter check failed. 182 * @throws { BusinessError } 16600001 - The system ability works abnormally. 183 * @throws { BusinessError } 16600002 - The specified token or callback is not registered. 184 * @syscap SystemCapability.Ability.DistributedAbilityManager 185 * @since 9 186 */ 187 function unregisterContinuation(token: number, callback: AsyncCallback<void>): void; 188 function unregisterContinuation(token: number): Promise<void>; 189 190 /** 191 * Updates the connection state of the device where the specified ability is successfully hopped. 192 * 193 * @permission ohos.permission.DISTRIBUTED_DATASYNC 194 * @param token Indicates the registration token of the ability. 195 * @param deviceId Indicates the ID of the device whose connection state is to be updated. 196 * @param status Indicates the connection state to update. 197 * @returns callback Indicates the callback to be invoked when the continuation manager service is connected. 198 * @throws { BusinessError } 201 - Permission denied. 199 * @throws { BusinessError } 401 - The parameter check failed. 200 * @throws { BusinessError } 16600001 - The system ability works abnormally. 201 * @throws { BusinessError } 16600002 - The specified token or callback is not registered. 202 * @syscap SystemCapability.Ability.DistributedAbilityManager 203 * @since 9 204 */ 205 function updateContinuationState(token: number, deviceId: string, status: DeviceConnectState, callback: AsyncCallback<void>): void; 206 function updateContinuationState(token: number, deviceId: string, status: DeviceConnectState): Promise<void>; 207 208 /** 209 * Start to manage the devices that can be selected for continuation. 210 * 211 * @permission ohos.permission.DISTRIBUTED_DATASYNC 212 * @param token Indicates the registration token of the ability. 213 * @param options Indicates the extraParams object containing the extra parameters used to filter 214 * the list of available devices. This parameter can be null. 215 * @returns callback Indicates the callback to be invoked when the continuation manager service is connected. 216 * @throws { BusinessError } 201 - Permission denied. 217 * @throws { BusinessError } 401 - The parameter check failed. 218 * @throws { BusinessError } 16600001 - The system ability works abnormally. 219 * @throws { BusinessError } 16600002 - The specified token or callback is not registered. 220 * @syscap SystemCapability.Ability.DistributedAbilityManager 221 * @since 9 222 */ 223 function startContinuationDeviceManager(token: number, callback: AsyncCallback<void>): void; 224 function startContinuationDeviceManager(token: number, options: ContinuationExtraParams, callback: AsyncCallback<void>): void; 225 function startContinuationDeviceManager(token: number, options?: ContinuationExtraParams): Promise<void>; 226 227 /** 228 * Device connection status data structure. 229 * 230 * @syscap SystemCapability.Ability.DistributedAbilityManager 231 * @since 8 232 */ 233 export enum DeviceConnectState { 234 IDLE = 0, 235 CONNECTING = 1, 236 CONNECTED = 2, 237 DISCONNECTING = 3 238 } 239 240 /** 241 * Indicates the description of additional parameters for continuation. 242 * 243 * @syscap SystemCapability.Ability.DistributedAbilityManager 244 * @since 8 245 */ 246 export enum ContinuationMode { 247 248 /** 249 * Collaboration with a single device. 250 */ 251 COLLABORATION_SINGLE = 0, 252 253 /** 254 * Collaboration with multiple devices. 255 */ 256 COLLABORATION_MULTIPLE = 1, 257 } 258 259} 260export default continuationManager;