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 */
15
16import type Want from '@ohos.application.Want';
17import ServiceExtension from '@ohos.app.ability.ServiceExtensionAbility';
18import CallManagerService from './CallManagerService';
19import rpc from '@ohos.rpc';
20import LogUtils from '../common/utils/LogUtils';
21import DefaultCallData from '../common/struct/TypeUtils';
22import CallManager from '../model/CallManager';
23
24const TAG = 'ServiceAbility';
25
26export default class ServiceAbility extends ServiceExtension {
27  callManagerService: CallManagerService;
28
29  onCreate(want): void {
30    LogUtils.i(TAG, 'onCreate callUI service');
31    this.callManagerService = CallManagerService.getInstance();
32    this.callManagerService.init(this.context);
33  }
34
35  onConnect(want: Want): Stub {
36    LogUtils.i(TAG, 'onConnect callUI service');
37    let callData: DefaultCallData = new DefaultCallData();
38    callData.accountNumber = want.parameters?.accountNumber;
39    callData.videoState = want.parameters?.videoState;
40    callData.callType = want.parameters?.callType;
41    callData.callState = want.parameters?.callState;
42    callData.callId = want.parameters?.callId;
43    callData.startTime = want.parameters?.startTime;
44    callData.accountId = want.parameters?.accountId;
45    callData.isEcc = want.parameters?.isEcc;
46    callData.conferenceState = want.parameters?.conferenceState;
47    this.callManagerService.getCallData(callData);
48    CallManager.getInstance().setServiceConnected(true);
49    return new Stub('ServiceAbility');
50  }
51
52  onDisconnect(): void {
53    LogUtils.i(TAG, 'onDisconnect callUI service');
54    CallManager.getInstance().setServiceConnected(false);
55    this.callManagerService.onDisconnected();
56  }
57
58  onRequest(want: Want, startId: number): void {
59    LogUtils.i(TAG, 'onRequest callUI service');
60  }
61
62  onDestroy(): void {
63    LogUtils.i(TAG, 'onDestroy callUI service');
64    this.callManagerService.removeRegisterListener();
65  }
66}
67
68class Stub extends rpc.RemoteObject {
69  onRemoteRequest(code, date, reply, option): boolean {
70    LogUtils.i(TAG, 'Stub onRemoteRequest code:' + code);
71    return true;
72  }
73  
74  constructor(descriptor) {
75    super(descriptor);
76  }
77}