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 16/** 17 * Call Util 18 * 19 * standard: 20 * 1. define TAG, recommend class name. 21 * 2. switch IS_DEBUG_ON as true, when debugging. 22 * 3. msg should be short and valuable. 23 * 4. choose appropriate function. 24 * 5. the function execute many times can not print. 25 * 6. uniqueness. 26 */ 27import call from '@ohos.telephony.call'; 28import sim from '@ohos.telephony.sim'; 29import LogUtils from './LogUtils'; 30 31const TAG = 'CallUtils'; 32 33/** 34 * calllog package tool class 35 */ 36export class CallUtils { 37 /** 38 * Judge whether there is a sim card. 39 * 40 * @param { accountId } accountId 41 * 42 * @return { boolean } - return success true fail false 43 */ 44 public hasSimeCard: Function = (accountId) => new Promise((resolve, reject) => { 45 sim.hasSimCard(accountId).then((res) => { 46 resolve(res); 47 if (accountId === 0) { 48 AppStorage.SetOrCreate('hasSimCard1', res); 49 } else if (accountId === 1) { 50 AppStorage.SetOrCreate('hasSimCard2', res); 51 } 52 }) 53 .catch((err) => { 54 reject(err); 55 LogUtils.i(TAG, 'catch:hasSimeCard :' + JSON.stringify(err)); 56 }); 57 }); 58 59 /** 60 * Determine whether the call is an emergency call. 61 * 62 * @param { phoneNumber } phoneNumber-number 63 * 64 * @return { boolean } - return success true fail false 65 */ 66 public isEmergencyPhoneNumber: Function = (phoneNumber) => new Promise((resolve, reject) => { 67 call.isEmergencyPhoneNumber(phoneNumber, { 68 slotId: 0 69 }).then((res) => { 70 resolve(res); 71 AppStorage.SetOrCreate('IsEmergencyPhoneNumber', res); 72 LogUtils.i(TAG, 'then:isEmergencyPhoneNumber :' + JSON.stringify(res)); 73 }).catch((err) => { 74 reject(err); 75 LogUtils.i(TAG, 'catch:isEmergencyPhoneNumber :' + JSON.stringify(err)); 76 }); 77 }); 78} 79 80let mCallUtil = new CallUtils(); 81 82export default mCallUtil as CallUtils; 83 84