• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 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 */
15import ServiceExtensionAbility from '@ohos.app.ability.ServiceExtensionAbility'
16import rpc from '@ohos.rpc';
17import commonEvent from '@ohos.commonEvent'
18
19let message;
20let commonEventData = {
21  parameters: {
22    message: message,
23  }
24}
25
26class StubTest extends rpc.RemoteObject {
27  constructor(des) {
28    super(des)
29  }
30
31  onRemoteRequest(code, data, reply, option) {
32    console.info('ServiceAbilitySec onRemoteRequest');
33    if (code === 1) {
34      let op1 = data.readInt();
35      let op2 = data.readInt();
36      reply.writeInt(op1 + op2);
37      console.info('ServiceAbilitySec op1:' + op1 + ' op2:' + op2);
38    }
39    return true;
40  }
41}
42
43let strAction = '';
44let remoteOBJ = new StubTest("test");
45
46export default class ServiceAbilitySec extends ServiceExtensionAbility {
47  onCreate(want) {
48    strAction = want.action;
49    console.info('ServiceAbilitySec onCreate');
50    commonEventData.parameters.message = want;
51    if (strAction == "Acts_StopServiceExtension_0200" || strAction == "Acts_StopServiceExtension_0400" ||
52      strAction == "Acts_StopServiceExtension_0600") {
53      commonEvent.publish("ACTS_StopEvent_Second", commonEventData, (err) => {
54        console.info("====>" + strAction + " Second publish err: " + JSON.stringify(err));
55      })
56    }
57  }
58
59  onDestroy() {
60    console.info('ServiceAbilitySec onDestroy');
61  }
62
63  onRequest(want, startId) {
64    console.info('ServiceAbilitySec onRequest');
65  }
66
67  onConnect(want) {
68    console.info('ServiceAbilitySec onConnect');
69    return remoteOBJ;
70  }
71
72  onDisconnect(want) {
73    console.info('ServiceAbilitySec onDisconnect');
74  }
75
76  onReconnect(want) {
77    console.info('ServiceAbility onReconnect');
78  }
79
80  onConfigurationUpdate(newConfig) {
81    console.info('ServiceAbility onConfigurationUpdate');
82  }
83
84  onDump(params) {
85    console.info('ServiceAbility onDump');
86    return params;
87  }
88};