1/* 2 * Copyright (c) 2021-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 AbilityKit 19 */ 20 21import { AsyncCallback } from './@ohos.base'; 22import { StartAbilityParameter } from './ability/startAbilityParameter'; 23import { DataAbilityHelper } from './ability/dataAbilityHelper'; 24import { NotificationRequest } from './notification/notificationRequest'; 25import { ConnectOptions } from './ability/connectOptions'; 26import Want from './@ohos.app.ability.Want'; 27 28/** 29 * A Particle Ability represents an ability with service. 30 * 31 * @namespace particleAbility 32 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 33 * @FAModelOnly 34 * @since 7 35 */ 36declare namespace particleAbility { 37 /** 38 * Service ability uses this method to start a specific ability. 39 * 40 * @param { StartAbilityParameter } parameter - Indicates the ability to start. 41 * @param { AsyncCallback<void> } callback - Returns the result of starting Ability in the form of callback. 42 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 43 * @FAModelOnly 44 * @since 7 45 */ 46 function startAbility(parameter: StartAbilityParameter, callback: AsyncCallback<void>): void; 47 48 /** 49 * Service ability uses this method to start a specific ability. 50 * 51 * @param { StartAbilityParameter } parameter - Indicates the ability to start. 52 * @returns { Promise<void> } the promise returned by the function. 53 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 54 * @FAModelOnly 55 * @since 7 56 */ 57 function startAbility(parameter: StartAbilityParameter): Promise<void>; 58 59 /** 60 * Destroys this service ability. 61 * 62 * @param { AsyncCallback<void> } callback - Return the result of stopping Ability in the form of callback. 63 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 64 * @FAModelOnly 65 * @since 7 66 */ 67 function terminateSelf(callback: AsyncCallback<void>): void; 68 69 /** 70 * Destroys this service ability. 71 * 72 * @returns { Promise<void> } the promise returned by the function. 73 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 74 * @FAModelOnly 75 * @since 7 76 */ 77 function terminateSelf(): Promise<void>; 78 79 /** 80 * Obtains the dataAbilityHelper. 81 * 82 * @param { string } uri - Indicates the path of the file to open. 83 * @returns { DataAbilityHelper } Returns the dataAbilityHelper. 84 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 85 * @FAModelOnly 86 * @since 7 87 */ 88 function acquireDataAbilityHelper(uri: string): DataAbilityHelper; 89 90 /** 91 * Keep this Service ability in the background and display a notification bar. 92 * 93 * @permission ohos.permission.KEEP_BACKGROUND_RUNNING 94 * @param { number } id - Identifies the notification bar information. 95 * @param { NotificationRequest } request - Indicates the notificationRequest instance containing information 96 * for displaying a notification bar. 97 * @param { AsyncCallback<void> } callback - returns the result of starting a long-term task in the form of callback. 98 * @syscap SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask 99 * @FAModelOnly 100 * @since 7 101 * @deprecated since 9 102 * @useinstead ohos.resourceschedule.backgroundTaskManager/backgroundTaskManager#startBackgroundRunning 103 */ 104 function startBackgroundRunning(id: number, request: NotificationRequest, callback: AsyncCallback<void>): void; 105 106 /** 107 * Keep this Service ability in the background and display a notification bar. 108 * 109 * @permission ohos.permission.KEEP_BACKGROUND_RUNNING 110 * @param { number } id - Identifies the notification bar information. 111 * @param { NotificationRequest } request - Indicates the notificationRequest instance containing information 112 * for displaying a notification bar. 113 * @returns { Promise<void> } the promise returned by the function. 114 * @syscap SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask 115 * @FAModelOnly 116 * @since 7 117 * @deprecated since 9 118 * @useinstead ohos.resourceschedule.backgroundTaskManager/backgroundTaskManager#startBackgroundRunning 119 */ 120 function startBackgroundRunning(id: number, request: NotificationRequest): Promise<void>; 121 122 /** 123 * Cancel background running of this ability to free up system memory. 124 * 125 * @param { AsyncCallback<void> } callback - Returns the result of canceling a long-term task in the form of callback. 126 * @syscap SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask 127 * @FAModelOnly 128 * @since 7 129 * @deprecated since 9 130 * @useinstead ohos.resourceschedule.backgroundTaskManager/backgroundTaskManager#stopBackgroundRunning 131 */ 132 function cancelBackgroundRunning(callback: AsyncCallback<void>): void; 133 134 /** 135 * Cancel background running of this ability to free up system memory. 136 * 137 * @returns { Promise<void> } the promise returned by the function. 138 * @syscap SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask 139 * @FAModelOnly 140 * @since 7 141 * @deprecated since 9 142 * @useinstead ohos.resourceschedule.backgroundTaskManager/backgroundTaskManager#stopBackgroundRunning 143 */ 144 function cancelBackgroundRunning(): Promise<void>; 145 146 /** 147 * Connects an ability to a Service ability. 148 * 149 * @param { Want } request - Indicates the Service ability to connect. 150 * @param { ConnectOptions } options - Callback object for the client. If this parameter is null, 151 * an exception is thrown. 152 * @returns { number } unique identifier of the connection between the client and the service side. 153 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 154 * @FAModelOnly 155 * @since 7 156 */ 157 function connectAbility(request: Want, options: ConnectOptions): number; 158 159 /** 160 * Disconnects ability to a Service ability. 161 * 162 * @param { number } connection - the connection id returned from connectAbility api. 163 * @param { AsyncCallback<void> } callback - Returns the disconnection result in the form of callback. 164 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 165 * @FAModelOnly 166 * @since 7 167 */ 168 function disconnectAbility(connection: number, callback: AsyncCallback<void>): void; 169 170 /** 171 * Disconnects ability to a Service ability. 172 * 173 * @param { number } connection - the connection id returned from connectAbility api. 174 * @returns { Promise<void> } the promise returned by the function. 175 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 176 * @FAModelOnly 177 * @since 7 178 */ 179 function disconnectAbility(connection: number): Promise<void>; 180 181 /** 182 * Obtain the errorCode. 183 * 184 * @enum { number } 185 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 186 * @FAModelOnly 187 * @since 7 188 */ 189 export enum ErrorCode { 190 /** 191 * Invalid parameter. 192 * 193 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 194 * @FAModelOnly 195 * @since 7 196 */ 197 INVALID_PARAMETER = -1 198 } 199} 200export default particleAbility; 201