1/** 2 * Copyright (c) 2022 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 { StringUtil } from '../../../../../common/src/main/ets/util/StringUtil'; 16import { HiLog } from '../../../../../common/src/main/ets/util/HiLog'; 17import call from '@ohos.telephony.call'; 18 19const TAG = 'TelecomService'; 20 21export default class TelecomService { 22 private static sInstance: TelecomService; 23 24 public static getInstance(): TelecomService { 25 HiLog.i(TAG, 'getInstance start !'); 26 if (TelecomService.sInstance == null) { 27 HiLog.i(TAG, 'getInstance init '); 28 TelecomService.sInstance = new TelecomService(); 29 } 30 return TelecomService.sInstance; 31 } 32 33 /** 34 * dial number 35 * 36 * @param phoneNum telephone number 37 * @param options DialOptions Look @ohos.telephony.call.d.ts 38 * @param callback dail callback data:is emergency err:failure value:result 39 */ 40 async dial(phoneNum: string, options: call.DialOptions, callback) { 41 HiLog.i(TAG, 'dial start '); 42 if (StringUtil.isEmpty(phoneNum)) { 43 HiLog.i(TAG, 'dial phoneNum is empty '); 44 return; 45 } 46 let num: string = StringUtil.removeSpace(phoneNum); 47 call.dial(num, options, (err, value) => { 48 callback(value); 49 if (err) { 50 HiLog.e(TAG, 'dial finish err: ' + JSON.stringify(err.message)); 51 return; 52 } 53 HiLog.i(TAG, 'dial finish value: ' + JSON.stringify(value)); 54 }); 55 } 56}