• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022-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 rpc from './@ohos.rpc';
22import ServiceExtensionContext from './application/ServiceExtensionContext';
23import Want from './@ohos.app.ability.Want';
24import { Configuration } from './@ohos.app.ability.Configuration';
25
26/**
27 * class of service extension ability.
28 *
29 * @syscap SystemCapability.Ability.AbilityRuntime.Core
30 * @systemapi
31 * @StageModelOnly
32 * @since 9
33 */
34export default class ServiceExtensionAbility {
35  /**
36   * Indicates service extension ability context.
37   *
38   * @type { ServiceExtensionContext }
39   * @syscap SystemCapability.Ability.AbilityRuntime.Core
40   * @systemapi
41   * @StageModelOnly
42   * @since 9
43   */
44  context: ServiceExtensionContext;
45
46  /**
47   * Called back when a service extension is started for initialization.
48   *
49   * @param { Want } want - Indicates the want of created service extension.
50   * @syscap SystemCapability.Ability.AbilityRuntime.Core
51   * @systemapi
52   * @StageModelOnly
53   * @since 9
54   */
55  onCreate(want: Want): void;
56
57  /**
58   * Called back before a service extension is destroyed.
59   *
60   * @syscap SystemCapability.Ability.AbilityRuntime.Core
61   * @systemapi
62   * @StageModelOnly
63   * @since 9
64   */
65  onDestroy(): void;
66
67  /**
68   * Called back when a service extension is started.
69   *
70   * @param { Want } want - Indicates the want of service extension to start.
71   * @param { number } startId - Indicates the number of times the service extension has been started.
72   *                             The {@code startId} is incremented by 1 every time the service extension is started.
73   *                             For example, if the service extension has been started for six times.
74   * @syscap SystemCapability.Ability.AbilityRuntime.Core
75   * @systemapi
76   * @StageModelOnly
77   * @since 9
78   */
79  onRequest(want: Want, startId: number): void;
80
81  /**
82   * Called back when a service extension is first connected to an ability.
83   *
84   * @param { Want } want - Indicates connection information about the Service ability.
85   * @returns { rpc.RemoteObject | Promise<rpc.RemoteObject> } A RemoteObject for communication between the client
86   *                                                           and server.
87   * @syscap SystemCapability.Ability.AbilityRuntime.Core
88   * @systemapi
89   * @StageModelOnly
90   * @since 9
91   */
92  onConnect(want: Want): rpc.RemoteObject | Promise<rpc.RemoteObject>;
93
94  /**
95   * Called back when all abilities connected to a service extension are disconnected.
96   *
97   * @param { Want } want - Indicates disconnection information about the service extension.
98   * @returns { void | Promise<void> } the promise returned by the function.
99   * @syscap SystemCapability.Ability.AbilityRuntime.Core
100   * @systemapi
101   * @StageModelOnly
102   * @since 9
103   */
104  onDisconnect(want: Want): void | Promise<void>;
105
106  /**
107   * Called when a new client attempts to connect to a service extension after all previous client connections to it
108   * are disconnected.
109   *
110   * @param { Want } want - Indicates the want of the service extension being connected.
111   * @syscap SystemCapability.Ability.AbilityRuntime.Core
112   * @systemapi
113   * @StageModelOnly
114   * @since 9
115   */
116  onReconnect(want: Want): void;
117
118  /**
119   * Called when the system configuration is updated.
120   *
121   * @param { Configuration } newConfig - Indicates the updated configuration.
122   * @syscap SystemCapability.Ability.AbilityRuntime.Core
123   * @systemapi
124   * @StageModelOnly
125   * @since 9
126   */
127  onConfigurationUpdate(newConfig: Configuration): void;
128
129  /**
130   * Called when dump client information is required.
131   * It is recommended that developers don't DUMP sensitive information.
132   *
133   * @param { Array<string> } params - Indicates the params from command.
134   * @returns { Array<string> } The dump info array.
135   * @syscap SystemCapability.Ability.AbilityRuntime.Core
136   * @systemapi
137   * @StageModelOnly
138   * @since 9
139   */
140  onDump(params: Array<string>): Array<string>;
141}
142