18779efd5Sopenharmony_ci/**
28779efd5Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd.
38779efd5Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
48779efd5Sopenharmony_ci * you may not use this file except in compliance with the License.
58779efd5Sopenharmony_ci * You may obtain a copy of the License at
68779efd5Sopenharmony_ci *
78779efd5Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
88779efd5Sopenharmony_ci *
98779efd5Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
108779efd5Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
118779efd5Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
128779efd5Sopenharmony_ci * See the License for the specific language governing permissions and
138779efd5Sopenharmony_ci * limitations under the License.
148779efd5Sopenharmony_ci */
158779efd5Sopenharmony_ciimport { StringUtil } from '../../../../../common/src/main/ets/util/StringUtil';
168779efd5Sopenharmony_ciimport { HiLog } from '../../../../../common/src/main/ets/util/HiLog';
178779efd5Sopenharmony_ciimport call from '@ohos.telephony.call';
188779efd5Sopenharmony_ci
198779efd5Sopenharmony_ciconst TAG = 'TelecomService';
208779efd5Sopenharmony_ci
218779efd5Sopenharmony_ciexport default class TelecomService {
228779efd5Sopenharmony_ci  private static sInstance: TelecomService;
238779efd5Sopenharmony_ci
248779efd5Sopenharmony_ci  public static getInstance(): TelecomService {
258779efd5Sopenharmony_ci    HiLog.i(TAG, 'getInstance start !');
268779efd5Sopenharmony_ci    if (TelecomService.sInstance == null) {
278779efd5Sopenharmony_ci      HiLog.i(TAG, 'getInstance init ');
288779efd5Sopenharmony_ci      TelecomService.sInstance = new TelecomService();
298779efd5Sopenharmony_ci    }
308779efd5Sopenharmony_ci    return TelecomService.sInstance;
318779efd5Sopenharmony_ci  }
328779efd5Sopenharmony_ci
338779efd5Sopenharmony_ci  /**
348779efd5Sopenharmony_ci   * dial number
358779efd5Sopenharmony_ci   *
368779efd5Sopenharmony_ci   * @param phoneNum telephone number
378779efd5Sopenharmony_ci   * @param options DialOptions Look @ohos.telephony.call.d.ts
388779efd5Sopenharmony_ci   * @param callback dail callback data:is emergency   err:failure  value:result
398779efd5Sopenharmony_ci   */
408779efd5Sopenharmony_ci  async dial(phoneNum: string, options: call.DialOptions, callback) {
418779efd5Sopenharmony_ci    HiLog.i(TAG, 'dial start ');
428779efd5Sopenharmony_ci    if (StringUtil.isEmpty(phoneNum)) {
438779efd5Sopenharmony_ci      HiLog.i(TAG, 'dial phoneNum is empty ');
448779efd5Sopenharmony_ci      return;
458779efd5Sopenharmony_ci    }
468779efd5Sopenharmony_ci    let num: string = StringUtil.removeSpace(phoneNum);
478779efd5Sopenharmony_ci    call.dial(num, options, (err, value) => {
488779efd5Sopenharmony_ci      callback(value);
498779efd5Sopenharmony_ci      if (err) {
508779efd5Sopenharmony_ci        HiLog.e(TAG, 'dial finish err: ' + JSON.stringify(err.message));
518779efd5Sopenharmony_ci        return;
528779efd5Sopenharmony_ci      }
538779efd5Sopenharmony_ci      HiLog.i(TAG, 'dial finish value: ' + JSON.stringify(value));
548779efd5Sopenharmony_ci    });
558779efd5Sopenharmony_ci  }
568779efd5Sopenharmony_ci}