1/* 2 * Copyright (c) 2021 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 { Want } from "../../ability/want"; 17import { ResultSet } from "../../data/rdb/resultSet"; 18import { AbilityInfo } from "../../bundle/abilityInfo"; 19import { DataAbilityResult } from "../../ability/dataAbilityResult"; 20import { DataAbilityOperation } from "../../ability/dataAbilityOperation"; 21import dataAbility from "../../@ohos.data.dataAbility"; 22import formBindingData from "../../@ohos.application.formBindingData"; 23import formInfo from "../../@ohos.application.formInfo"; 24import rdb from "../../@ohos.data.rdb"; 25import rpc from "../../@ohos.rpc"; 26import resourceManager from "../../@ohos.resourceManager"; 27import { PacMap } from "../../ability/dataAbilityHelper"; 28import { AsyncCallback } from "../../basic"; 29 30/** 31 * interface of form lifecycle. 32 * 33 * @name LifecycleForm 34 * @since 7 35 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 36 * @FAModelOnly 37 */ 38export declare interface LifecycleForm { 39 /** 40 * Called to return a {@link formBindingData.FormBindingData} object. 41 * 42 * @since 8 43 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 44 * @param want Indicates the detailed information for creating a {@link formBindingData#FormBindingData}. 45 * The {@code Want} object must include the form ID, form name, and grid style of the form, 46 * which can be obtained from {@link formInfo#FormParam#IDENTITY_KEY}, 47 * {@link formInfo#FormParam#NAME_KEY}, and {@link formInfo#FormParam#DIMENSION_KEY}, 48 * respectively. Such form information must be managed as persistent data for further form 49 * acquisition, update, and deletion. 50 * @return Returns the created {@link formBindingData#FormBindingData} object. 51 * @FAModelOnly 52 */ 53 onCreate?(want: Want): formBindingData.FormBindingData; 54 55 /** 56 * Called when the form provider is notified that a temporary form is successfully converted to a normal form. 57 * 58 * @since 8 59 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 60 * @param formId Indicates the ID of the form. 61 * @return - 62 * @FAModelOnly 63 */ 64 onCastToNormal?(formId: string): void; 65 66 /** 67 * Called to notify the form provider to update a specified form. 68 * 69 * @since 8 70 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 71 * @param formId Indicates the ID of the form to update. 72 * @return - 73 * @FAModelOnly 74 */ 75 onUpdate?(formId: string): void; 76 77 /** 78 * Called when the form provider receives form events from the system. 79 * 80 * @since 8 81 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 82 * @param newStatus Indicates the form events occurred. The key in the {@code Map} object indicates the form ID, 83 * and the value indicates the event type, which can be either {@link formInfo#VisibilityType#FORM_VISIBLE} 84 * or {@link formInfo#VisibilityType#FORM_INVISIBLE}. {@link formInfo#VisibilityType#FORM_VISIBLE} 85 * means that the form becomes visible, and {@link formInfo#VisibilityType#FORM_INVISIBLE} 86 * means that the form becomes invisible. 87 * @return - 88 * @FAModelOnly 89 */ 90 onVisibilityChange?(newStatus: { [key: string]: number }): void; 91 92 /** 93 * Called when a specified message event defined by the form provider is triggered. This method is valid only for 94 * JS forms. 95 * 96 * @since 8 97 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 98 * @param formId Indicates the ID of the form on which the message event is triggered, which is provided by 99 * the client to the form provider. 100 * @param message Indicates the value of the {@code params} field of the message event. This parameter is 101 * used to identify the specific component on which the event is triggered. 102 * @return - 103 * @FAModelOnly 104 */ 105 onEvent?(formId: string, message: string): void; 106 107 /** 108 * Called to notify the form provider that a specified form has been deleted. Override this method if 109 * you want your application, as the form provider, to be notified of form deletion. 110 * 111 * @since 8 112 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 113 * @param formId Indicates the ID of the deleted form. 114 * @return - 115 * @FAModelOnly 116 */ 117 onDestroy?(formId: string): void; 118 119 /** 120 * Called to return a {@link FormState} object. 121 * 122 * <p>You must override this callback if you want this ability to return the actual form state. Otherwise, 123 * this method returns {@link FormState#DEFAULT} by default.</p> 124 * 125 * @since 8 126 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 127 * @param want Indicates the description of the form for which the {@link formInfo#FormState} is obtained. 128 * The description covers the bundle name, ability name, module name, form name, and form dimensions. 129 * @return Returns the {@link formInfo#FormState} object. 130 * @FAModelOnly 131 */ 132 onAcquireFormState?(want: Want): formInfo.FormState; 133} 134 135/** 136 * interface of app lifecycle. 137 * 138 * @name LifecycleApp 139 * @since 7 140 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 141 * @FAModelOnly 142 */ 143export declare interface LifecycleApp { 144 /** 145 * Called back when the state of an ability changes from <b>BACKGROUND</b> to <b>INACTIVE</b>. 146 * 147 * @since 7 148 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 149 * @return - 150 * @FAModelOnly 151 */ 152 onShow?(): void; 153 154 /** 155 * Called back when an ability enters the <b>BACKGROUND</b> state. 156 * 157 * @since 7 158 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 159 * @return - 160 * @FAModelOnly 161 */ 162 onHide?(): void; 163 164 /** 165 * Called back before an ability is destroyed. 166 * 167 * @since 7 168 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 169 * @return - 170 * @FAModelOnly 171 */ 172 onDestroy?(): void; 173 174 /** 175 * Called back when an ability is started for initialization. 176 * 177 * @since 7 178 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 179 * @return - 180 * @FAModelOnly 181 */ 182 onCreate?(): void; 183 184 /** 185 * Called when the window display mode of this ability changes, for example, from fullscreen mode 186 * to multi-window mode or from multi-window mode to fullscreen mode. 187 * 188 * @since 7 189 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 190 * @param isShownInMultiWindow Specifies whether this ability is currently in multi-window mode. 191 * The value {@code true} indicates the multi-window mode, and {@code false} indicates another mode. 192 * @param newConfig Indicates the new configuration information about this Page ability. 193 * @return - 194 * @systemapi hide for inner use. 195 * @FAModelOnly 196 */ 197 onWindowDisplayModeChanged?(isShownInMultiWindow: boolean, newConfig: resourceManager.Configuration): void; 198 199 /** 200 * Asks a user whether to start the migration. 201 * 202 * @since 7 203 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 204 * @return Returns {@code true} if the user allows the migration; returns {@code false} otherwise. 205 * @FAModelOnly 206 */ 207 onStartContinuation?(): boolean; 208 209 /** 210 * Saves the user data of a local ability generated during runtime. 211 * After the migration is triggered and the local ability is ready, this method is called when the Distributed 212 * Scheduler Service requests data from the local ability. 213 * 214 * @since 7 215 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 216 * @param data Indicates the user data to save. 217 * @return Returns {@code true} if the data is successfully saved; returns {@code false} otherwise. 218 * @FAModelOnly 219 */ 220 onSaveData?(data: Object): boolean; 221 222 /** 223 * Called back when a local ability migration is complete. 224 * 225 * <p>You can define the processing logic after the migration is complete. For example, you can display a prompt to 226 * notify the user of the successful migration and then exit the local ability.</p> 227 * 228 * @since 7 229 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 230 * @param result Indicates the migration result code. The value {@code 0} indicates that the migration is 231 * successful, and {@code -1} indicates that the migration fails. 232 * @return - 233 * @FAModelOnly 234 */ 235 onCompleteContinuation?(result: number): void; 236 237 /** 238 * Restores the user data saved during the migration for an ability on the remote device immediately after the 239 * ability is created on the remote device. Lifecycle scheduling for the ability starts only after the user data 240 * is restored. 241 * 242 * @since 7 243 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 244 * @param data Indicates the user data to restore. 245 * @return - 246 * @FAModelOnly 247 */ 248 onRestoreData?(data: Object): void; 249 250 /** 251 * Called to notify the local device when a running ability on the remote device is destroyed after a reversible 252 * migration is performed for the ability from the local device to the remote device. 253 * 254 * @since 7 255 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 256 * @return - 257 * @FAModelOnly 258 */ 259 onRemoteTerminated?(): void; 260 261 /** 262 * This method is called when the system determines that the ability may be destroyed in an unexpected 263 * situation, for example, when the screen orientation changes or the user touches the Home key. Generally, 264 * this method is used only to save temporary states. 265 * 266 * @since 7 267 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 268 * @param outState Indicates the {@code PacMap} object used for storing user data and states. This 269 * parameter cannot be null. 270 * @return - 271 * @FAModelOnly 272 */ 273 onSaveAbilityState?(outState: PacMap): void; 274 275 /** 276 * This method is called if an ability was destroyed at a certain time due to resource reclaim or was 277 * unexpectedly destroyed and the {@link #onSaveAbilityState(PacMap)} method was called to save its user data and 278 * states. Generally, this method is called after the {@link #onStart(Want)} method. 279 * 280 * @since 7 281 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 282 * @param inState Indicates the {@code PacMap} object used for storing data and states. This 283 * parameter can not be null. 284 * @return - 285 * @FAModelOnly 286 */ 287 onRestoreAbilityState?(inState: PacMap): void; 288 289 /** 290 * Called back when an ability enters the <b>INACTIVE</b> state (an ability in this state is not interactive and may 291 * change to the <b>BACKGROUND</b> or <b>ACTIVE</b> state). 292 * 293 * @since 7 294 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 295 * @return - 296 * @FAModelOnly 297 */ 298 onInactive?(): void; 299 300 /** 301 * Called back when an ability enters the <b>ACTIVE</b> state. 302 * 303 * @since 7 304 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 305 * @return - 306 * @FAModelOnly 307 */ 308 onActive?(): void; 309 310 /** 311 * Called when the launch mode of an ability is set to singleton. 312 * 313 * @since 7 314 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 315 * @param want Indicates the new {@code want} containing information about the ability. 316 * @return - 317 * @FAModelOnly 318 */ 319 onNewWant?(want: Want): void; 320 321 /** 322 * Called when the system has determined to trim the memory, for example, when the ability is running in the 323 * background and there is no enough memory for running as many background processes as possible. 324 * 325 * @since 7 326 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 327 * @param level Indicates the memory trim level, which shows the current memory usage status. 328 * @return - 329 * @FAModelOnly 330 */ 331 onMemoryLevel?(level: number): void; 332} 333 334/** 335 * interface of service lifecycle. 336 * 337 * @name LifecycleService 338 * @since 7 339 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 340 * @FAModelOnly 341 */ 342export declare interface LifecycleService { 343 /** 344 * Called back when an ability is started for initialization (it can be called only once in the entire lifecycle of 345 * an ability). 346 * 347 * @since 7 348 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 349 * @return - 350 * @FAModelOnly 351 */ 352 onStart?(): void; 353 354 /** 355 * Called back when Service is started. 356 * 357 * @since 7 358 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 359 * @param want Indicates the want of Service to start. 360 * @param startId Indicates the number of times the Service ability has been started. The {@code startId} is 361 * incremented by 1 every time the ability is started. For example, if the ability has been started 362 * for six times. 363 * @return - 364 * @FAModelOnly 365 */ 366 onCommand?(want: Want, startId: number): void; 367 368 /** 369 * Called back before an ability is destroyed. 370 * 371 * @since 7 372 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 373 * @return - 374 * @FAModelOnly 375 */ 376 onStop?(): void; 377 378 /** 379 * Called back when a Service ability is first connected to an ability. 380 * 381 * @since 7 382 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 383 * @param want Indicates connection information about the Service ability. 384 * @return Returns the proxy of the Service ability. 385 * @FAModelOnly 386 */ 387 onConnect?(want: Want): rpc.RemoteObject; 388 389 /** 390 * Called back when all abilities connected to a Service ability are disconnected. 391 * 392 * @since 7 393 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 394 * @param want Indicates disconnection information about the Service ability. 395 * @return - 396 * @FAModelOnly 397 */ 398 onDisconnect?(want: Want): void; 399 400 /** 401 * Called when a new client attempts to connect to a Service ability after all previous client connections to it 402 * are disconnected. 403 * 404 * <p>The Service ability must have been started but not been destroyed, that is, {@link #startAbility} has been 405 * called but {@link #terminateSelf} has not.</p> 406 * 407 * @since 7 408 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 409 * @param want Indicates the want of the Service ability being connected. 410 * @return - 411 * @FAModelOnly 412 */ 413 onReconnect?(want: Want): void; 414} 415 416/** 417 * interface of data lifecycle. 418 * 419 * @name LifecycleData 420 * @since 7 421 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 422 * @FAModelOnly 423 */ 424export declare interface LifecycleData { 425 /** 426 * Updates one or more data records in the database. This method should be implemented by a Data ability. 427 * 428 * @since 7 429 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 430 * @param uri Indicates the database table storing the data to update. 431 * @param valueBucket Indicates the data to update. This parameter can be null. 432 * @param predicates Indicates filter criteria. If this parameter is null, all data records will be updated by 433 * default. 434 * @param callback function specified by framework to receive the result, developer should call this function to 435 * return the result to framework. 436 * @return - 437 * @FAModelOnly 438 */ 439 update?(uri: string, valueBucket: rdb.ValuesBucket, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback<number>): void; 440 441 /** 442 * Queries one or more data records in the database. This method should be implemented by a Data ability. 443 * 444 * @since 7 445 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 446 * @param uri Indicates the database table storing the data to query. 447 * @param columns Indicates the columns to be queried, in array, for example, {"name","age"}. You should define 448 * the processing logic when this parameter is null. 449 * @param predicates Indicates filter criteria. If this parameter is null, all data records will be queried by 450 * default. 451 * @param callback function specified by framework to receive the result, developer should call this function to 452 * return the result to framework. 453 * @return - 454 * @FAModelOnly 455 */ 456 query?(uri: string, columns: Array<string>, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback<ResultSet>): void; 457 458 /** 459 * Deletes one or more data records. This method should be implemented by a Data ability. 460 * 461 * @since 7 462 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 463 * @param uri Indicates the database table storing the data to delete. 464 * @param predicates Indicates filter criteria. If this parameter is null, all data records will be deleted by 465 * default. 466 * @param callback function specified by framework to receive the result, developer should call this function to 467 * return the result to framework. 468 * @return - 469 * @FAModelOnly 470 */ 471 delete?(uri: string, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback<number>): void; 472 473 /** 474 * Converts the given {@code uri} that refer to the Data ability into a normalized URI. A normalized URI can be 475 * used across devices, persisted, backed up, and restored. It can refer to the same item in the Data ability 476 * even if the context has changed. 477 * 478 * @since 7 479 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 480 * @param uri Indicates the uri to normalize. 481 * @param callback function specified by framework to receive the result, developer should call this function to 482 * return the result to framework. 483 * @return - 484 * @FAModelOnly 485 */ 486 normalizeUri?(uri: string, callback: AsyncCallback<string>): void; 487 488 /** 489 * Inserts multiple data records into the database. This method should be implemented by a Data ability. 490 * 491 * @since 7 492 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 493 * @param uri Indicates the position where the data is to insert. 494 * @param valueBuckets Indicates the data to insert. 495 * @param callback function specified by framework to receive the result, developer should call this function to 496 * return the result to framework. 497 * @return - 498 * @FAModelOnly 499 */ 500 batchInsert?(uri: string, valueBuckets: Array<rdb.ValuesBucket>, callback: AsyncCallback<number>): void; 501 502 /** 503 * Converts the given normalized {@code uri} generated by {@link #normalizeUri(uri)} into a denormalized one. 504 * The default implementation of this method returns the original uri passed to it. 505 * 506 * @since 7 507 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 508 * @param uri Indicates the uri to denormalize. 509 * @param callback function specified by framework to receive the result, developer should call this function to 510 * return the result to framework. 511 * @return - 512 * @FAModelOnly 513 */ 514 denormalizeUri?(uri: string, callback: AsyncCallback<string>): void; 515 516 /** 517 * Inserts a data record into the database. This method should be implemented by a Data ability. 518 * 519 * @since 7 520 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 521 * @param uri Indicates the position where the data is to insert. 522 * @param valueBucket Indicates the data to insert. 523 * @param callback function specified by framework to receive the result, developer should call this function to 524 * return the result to framework. 525 * @return - 526 * @FAModelOnly 527 */ 528 insert?(uri: string, valueBucket: rdb.ValuesBucket, callback: AsyncCallback<number>): void; 529 530 /** 531 * Opens a file. This method should be implemented by a Data ability. 532 * 533 * @since 7 534 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 535 * @param uri Indicates the path of the file to open. 536 * @param mode Indicates the open mode, which can be "r" for read-only access, "w" for write-only access (erasing 537 * whatever data is currently in the file), "wt" for write access that truncates any existing file, 538 * "wa" for write-only access to append to any existing data, "rw" for read and write access on any 539 * existing data, or "rwt" for read and write access that truncates any existing file. 540 * @param callback function specified by framework to receive the result, developer should call this function to 541 * return the result to framework. 542 * @return - 543 * @FAModelOnly 544 */ 545 openFile?(uri: string, mode: string, callback: AsyncCallback<number>): void; 546 547 /** 548 * Obtains the MIME type of files. This method should be implemented by a Data ability. 549 * 550 * @since 7 551 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 552 * @param uri Indicates the path of the files to obtain. 553 * @param mimeTypeFilter Indicates the MIME type of the files to obtain. This parameter cannot be set to {@code 554 * null}. 555 * <p>1. "*/*": Obtains all types supported by a Data ability. 556 * <p>2. "image/*": Obtains files whose main type is image of any subtype. 557 * <p>3. "*/jpg": Obtains files whose subtype is JPG of any main type. 558 * @param callback function specified by framework to receive the result, developer should call this function to 559 * return the result to framework. 560 * @return - 561 * @FAModelOnly 562 */ 563 getFileTypes?(uri: string, mimeTypeFilter: string, callback: AsyncCallback<Array<string>>): void; 564 565 /** 566 * Called to carry {@code AbilityInfo} to this ability after the ability is initialized. 567 * 568 * @since 7 569 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 570 * @param info Indicates the {@code AbilityInfo} object containing information about this ability. 571 * @return - 572 * @FAModelOnly 573 */ 574 onInitialized?(info: AbilityInfo): void; 575 576 /** 577 * Obtains the MIME type matching the data specified by the URI of the Data ability. This method should be 578 * implemented by a Data ability. 579 * 580 * <p>Data abilities supports general data types, including text, HTML, and JPEG.</p> 581 * 582 * @since 7 583 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 584 * @param uri Indicates the uri of the data. 585 * @param callback function specified by framework to receive the result, developer should call this function to 586 * return the result to framework. 587 * @return - 588 * @FAModelOnly 589 */ 590 getType?(uri: string, callback: AsyncCallback<string>): void; 591 592 /** 593 * Performs batch operations on the database. This method should be implemented by a Data ability. 594 * 595 * @since 7 596 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 597 * @param ops Indicates the data operation list, which can contain multiple operations on the database. 598 * @param callback function specified by framework to receive the result, developer should call this function to 599 * return the result to framework. 600 * @return - 601 * @FAModelOnly 602 */ 603 executeBatch?(ops: Array<DataAbilityOperation>, callback: AsyncCallback<Array<DataAbilityResult>>): void; 604 605 /** 606 * Defines a method in this Data ability (implementation depending on child classes). 607 * 608 * @since 7 609 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel 610 * @param method Indicates the method name. 611 * @param arg Indicates the parameter transferred by the method. 612 * @param extras Indicates the parameter transferred by the method. 613 * @param callback function specified by framework to receive the result, developer should call this function to 614 * return the result to framework. 615 * @return - 616 * @FAModelOnly 617 */ 618 call?(method: string, arg: string, extras: PacMap, callback: AsyncCallback<PacMap>): void; 619} 620