199da06d0Sopenharmony_ci/**
299da06d0Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd.
399da06d0Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
499da06d0Sopenharmony_ci * you may not use this file except in compliance with the License.
599da06d0Sopenharmony_ci * You may obtain a copy of the License at
699da06d0Sopenharmony_ci *
799da06d0Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
899da06d0Sopenharmony_ci *
999da06d0Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1099da06d0Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1199da06d0Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1299da06d0Sopenharmony_ci * See the License for the specific language governing permissions and
1399da06d0Sopenharmony_ci * limitations under the License.
1499da06d0Sopenharmony_ci */
1599da06d0Sopenharmony_ci
1699da06d0Sopenharmony_ciimport type Want from '@ohos.application.Want';
1799da06d0Sopenharmony_ciimport ServiceExtension from '@ohos.app.ability.ServiceExtensionAbility';
1899da06d0Sopenharmony_ciimport CallManagerService from './CallManagerService';
1999da06d0Sopenharmony_ciimport rpc from '@ohos.rpc';
2099da06d0Sopenharmony_ciimport LogUtils from '../common/utils/LogUtils';
2199da06d0Sopenharmony_ciimport DefaultCallData from '../common/struct/TypeUtils';
2299da06d0Sopenharmony_ciimport CallManager from '../model/CallManager';
2399da06d0Sopenharmony_ci
2499da06d0Sopenharmony_ciconst TAG = 'ServiceAbility';
2599da06d0Sopenharmony_ci
2699da06d0Sopenharmony_ciexport default class ServiceAbility extends ServiceExtension {
2799da06d0Sopenharmony_ci  callManagerService: CallManagerService;
2899da06d0Sopenharmony_ci
2999da06d0Sopenharmony_ci  onCreate(want): void {
3099da06d0Sopenharmony_ci    LogUtils.i(TAG, 'onCreate callUI service');
3199da06d0Sopenharmony_ci    this.callManagerService = CallManagerService.getInstance();
3299da06d0Sopenharmony_ci    this.callManagerService.init(this.context);
3399da06d0Sopenharmony_ci  }
3499da06d0Sopenharmony_ci
3599da06d0Sopenharmony_ci  onConnect(want: Want): Stub {
3699da06d0Sopenharmony_ci    LogUtils.i(TAG, 'onConnect callUI service');
3799da06d0Sopenharmony_ci    let callData: DefaultCallData = new DefaultCallData();
3899da06d0Sopenharmony_ci    callData.accountNumber = want.parameters?.accountNumber;
3999da06d0Sopenharmony_ci    callData.videoState = want.parameters?.videoState;
4099da06d0Sopenharmony_ci    callData.callType = want.parameters?.callType;
4199da06d0Sopenharmony_ci    callData.callState = want.parameters?.callState;
4299da06d0Sopenharmony_ci    callData.callId = want.parameters?.callId;
4399da06d0Sopenharmony_ci    callData.startTime = want.parameters?.startTime;
4499da06d0Sopenharmony_ci    callData.accountId = want.parameters?.accountId;
4599da06d0Sopenharmony_ci    callData.isEcc = want.parameters?.isEcc;
4699da06d0Sopenharmony_ci    callData.conferenceState = want.parameters?.conferenceState;
4799da06d0Sopenharmony_ci    this.callManagerService.getCallData(callData);
4899da06d0Sopenharmony_ci    CallManager.getInstance().setServiceConnected(true);
4999da06d0Sopenharmony_ci    return new Stub('ServiceAbility');
5099da06d0Sopenharmony_ci  }
5199da06d0Sopenharmony_ci
5299da06d0Sopenharmony_ci  onDisconnect(): void {
5399da06d0Sopenharmony_ci    LogUtils.i(TAG, 'onDisconnect callUI service');
5499da06d0Sopenharmony_ci    CallManager.getInstance().setServiceConnected(false);
5599da06d0Sopenharmony_ci    this.callManagerService.onDisconnected();
5699da06d0Sopenharmony_ci  }
5799da06d0Sopenharmony_ci
5899da06d0Sopenharmony_ci  onRequest(want: Want, startId: number): void {
5999da06d0Sopenharmony_ci    LogUtils.i(TAG, 'onRequest callUI service');
6099da06d0Sopenharmony_ci  }
6199da06d0Sopenharmony_ci
6299da06d0Sopenharmony_ci  onDestroy(): void {
6399da06d0Sopenharmony_ci    LogUtils.i(TAG, 'onDestroy callUI service');
6499da06d0Sopenharmony_ci    this.callManagerService.removeRegisterListener();
6599da06d0Sopenharmony_ci  }
6699da06d0Sopenharmony_ci}
6799da06d0Sopenharmony_ci
6899da06d0Sopenharmony_ciclass Stub extends rpc.RemoteObject {
6999da06d0Sopenharmony_ci  onRemoteRequest(code, date, reply, option): boolean {
7099da06d0Sopenharmony_ci    LogUtils.i(TAG, 'Stub onRemoteRequest code:' + code);
7199da06d0Sopenharmony_ci    return true;
7299da06d0Sopenharmony_ci  }
7399da06d0Sopenharmony_ci  
7499da06d0Sopenharmony_ci  constructor(descriptor) {
7599da06d0Sopenharmony_ci    super(descriptor);
7699da06d0Sopenharmony_ci  }
7799da06d0Sopenharmony_ci}