1e1c44949Sopenharmony_ci/* 2e1c44949Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 3e1c44949Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4e1c44949Sopenharmony_ci * you may not use this file except in compliance with the License. 5e1c44949Sopenharmony_ci * You may obtain a copy of the License at 6e1c44949Sopenharmony_ci * 7e1c44949Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8e1c44949Sopenharmony_ci * 9e1c44949Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10e1c44949Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11e1c44949Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12e1c44949Sopenharmony_ci * See the License for the specific language governing permissions and 13e1c44949Sopenharmony_ci * limitations under the License. 14e1c44949Sopenharmony_ci */ 15e1c44949Sopenharmony_ciconst call = requireInternal('telephony.call'); 16e1c44949Sopenharmony_ciconst ARGUMENTS_LEN_TWO = 2; 17e1c44949Sopenharmony_ciconst ARGUMENTS_LEN_ONE = 1; 18e1c44949Sopenharmony_ciasync function makeCallFunc(...args) { 19e1c44949Sopenharmony_ci if ((arguments.length === ARGUMENTS_LEN_TWO && typeof arguments[1] === 'function') || 20e1c44949Sopenharmony_ci (arguments.length === ARGUMENTS_LEN_ONE)) { 21e1c44949Sopenharmony_ci try { 22e1c44949Sopenharmony_ci let context = getContext(this); 23e1c44949Sopenharmony_ci await startAbility(arguments, context); 24e1c44949Sopenharmony_ci if (arguments.length === ARGUMENTS_LEN_TWO && typeof arguments[1] === 'function') { 25e1c44949Sopenharmony_ci return arguments[1](undefined, undefined); 26e1c44949Sopenharmony_ci } 27e1c44949Sopenharmony_ci return new Promise((resolve, reject) => { 28e1c44949Sopenharmony_ci resolve(); 29e1c44949Sopenharmony_ci }); 30e1c44949Sopenharmony_ci } catch (error) { 31e1c44949Sopenharmony_ci console.log('[call] makeCall error: ' + error); 32e1c44949Sopenharmony_ci if (arguments.length === ARGUMENTS_LEN_TWO && typeof arguments[1] === 'function') { 33e1c44949Sopenharmony_ci return arguments[1](error, undefined); 34e1c44949Sopenharmony_ci } 35e1c44949Sopenharmony_ci return new Promise((resolve, reject) => { 36e1c44949Sopenharmony_ci reject(error); 37e1c44949Sopenharmony_ci }); 38e1c44949Sopenharmony_ci } 39e1c44949Sopenharmony_ci } else if (arguments.length === ARGUMENTS_LEN_TWO && typeof arguments[1] === 'string') { 40e1c44949Sopenharmony_ci try { 41e1c44949Sopenharmony_ci let context = arguments[0]; 42e1c44949Sopenharmony_ci await startAbility(arguments, context); 43e1c44949Sopenharmony_ci return new Promise((resolve, reject) => { 44e1c44949Sopenharmony_ci resolve(); 45e1c44949Sopenharmony_ci }); 46e1c44949Sopenharmony_ci } catch (error) { 47e1c44949Sopenharmony_ci console.log("[call] makeCall error: " + error); 48e1c44949Sopenharmony_ci return new Promise((resolve, reject) => { 49e1c44949Sopenharmony_ci reject(error); 50e1c44949Sopenharmony_ci }); 51e1c44949Sopenharmony_ci } 52e1c44949Sopenharmony_ci } else { 53e1c44949Sopenharmony_ci console.log('[call] makeCall callback invalid'); 54e1c44949Sopenharmony_ci throw Error('invalid callback'); 55e1c44949Sopenharmony_ci } 56e1c44949Sopenharmony_ci 57e1c44949Sopenharmony_ci} 58e1c44949Sopenharmony_ci 59e1c44949Sopenharmony_ciasync function startAbility(args, context) { 60e1c44949Sopenharmony_ci let config = { 61e1c44949Sopenharmony_ci parameters: { 62e1c44949Sopenharmony_ci 'phoneNumber': '', 63e1c44949Sopenharmony_ci 'pageFlag': 'page_flag_edit_before_calling' 64e1c44949Sopenharmony_ci }, 65e1c44949Sopenharmony_ci bundleName: 'com.ohos.contacts', 66e1c44949Sopenharmony_ci abilityName: 'com.ohos.contacts.MainAbility' 67e1c44949Sopenharmony_ci }; 68e1c44949Sopenharmony_ci if (args.length > 0 && typeof args[0] === 'string') { 69e1c44949Sopenharmony_ci config.parameters.phoneNumber = args[0]; 70e1c44949Sopenharmony_ci } else if (args.length > 1 && typeof args[1] === 'string') { 71e1c44949Sopenharmony_ci config.parameters.phoneNumber = args[1]; 72e1c44949Sopenharmony_ci } 73e1c44949Sopenharmony_ci if (context) { 74e1c44949Sopenharmony_ci await context.startAbility(config); 75e1c44949Sopenharmony_ci } else { 76e1c44949Sopenharmony_ci call.makeCall(config.parameters.phoneNumber); 77e1c44949Sopenharmony_ci } 78e1c44949Sopenharmony_ci} 79e1c44949Sopenharmony_ci 80e1c44949Sopenharmony_ciexport default { 81e1c44949Sopenharmony_ci makeCall: makeCallFunc, 82e1c44949Sopenharmony_ci dialCall: call.dialCall, 83e1c44949Sopenharmony_ci muteRinger: call.muteRinger, 84e1c44949Sopenharmony_ci answerCall: call.answerCall, 85e1c44949Sopenharmony_ci hangUpCall: call.hangUpCall, 86e1c44949Sopenharmony_ci hangup: call.hangup, 87e1c44949Sopenharmony_ci rejectCall: call.rejectCall, 88e1c44949Sopenharmony_ci reject: call.reject, 89e1c44949Sopenharmony_ci holdCall: call.holdCall, 90e1c44949Sopenharmony_ci unHoldCall: call.unHoldCall, 91e1c44949Sopenharmony_ci switchCall: call.switchCall, 92e1c44949Sopenharmony_ci setCallPreferenceMode: call.setCallPreferenceMode, 93e1c44949Sopenharmony_ci combineConference: call.combineConference, 94e1c44949Sopenharmony_ci kickOutFromConference: call.kickOutFromConference, 95e1c44949Sopenharmony_ci getMainCallId: call.getMainCallId, 96e1c44949Sopenharmony_ci getSubCallIdList: call.getSubCallIdList, 97e1c44949Sopenharmony_ci getCallIdListForConference: call.getCallIdListForConference, 98e1c44949Sopenharmony_ci getCallWaitingStatus: call.getCallWaitingStatus, 99e1c44949Sopenharmony_ci setCallWaiting: call.setCallWaiting, 100e1c44949Sopenharmony_ci startDTMF: call.startDTMF, 101e1c44949Sopenharmony_ci stopDTMF: call.stopDTMF, 102e1c44949Sopenharmony_ci postDialProceed: call.postDialProceed, 103e1c44949Sopenharmony_ci isInEmergencyCall: call.isInEmergencyCall, 104e1c44949Sopenharmony_ci on: call.on, 105e1c44949Sopenharmony_ci off: call.off, 106e1c44949Sopenharmony_ci isNewCallAllowed: call.isNewCallAllowed, 107e1c44949Sopenharmony_ci separateConference: call.separateConference, 108e1c44949Sopenharmony_ci getCallRestrictionStatus: call.getCallRestrictionStatus, 109e1c44949Sopenharmony_ci setCallRestriction: call.setCallRestriction, 110e1c44949Sopenharmony_ci setCallRestrictionPassword: call.setCallRestrictionPassword, 111e1c44949Sopenharmony_ci getCallTransferInfo: call.getCallTransferInfo, 112e1c44949Sopenharmony_ci setCallTransfer: call.setCallTransfer, 113e1c44949Sopenharmony_ci isRinging: call.isRinging, 114e1c44949Sopenharmony_ci setMuted: call.setMuted, 115e1c44949Sopenharmony_ci cancelMuted: call.cancelMuted, 116e1c44949Sopenharmony_ci setAudioDevice: call.setAudioDevice, 117e1c44949Sopenharmony_ci joinConference: call.joinConference, 118e1c44949Sopenharmony_ci updateImsCallMode: call.updateImsCallMode, 119e1c44949Sopenharmony_ci enableImsSwitch: call.enableImsSwitch, 120e1c44949Sopenharmony_ci disableImsSwitch: call.disableImsSwitch, 121e1c44949Sopenharmony_ci isImsSwitchEnabled: call.isImsSwitchEnabled, 122e1c44949Sopenharmony_ci isImsSwitchEnabledSync: call.isImsSwitchEnabledSync, 123e1c44949Sopenharmony_ci closeUnfinishedUssd: call.closeUnfinishedUssd, 124e1c44949Sopenharmony_ci setVoNRState: call.setVoNRState, 125e1c44949Sopenharmony_ci getVoNRState: call.getVoNRState, 126e1c44949Sopenharmony_ci canSetCallTransferTime: call.canSetCallTransferTime, 127e1c44949Sopenharmony_ci inputDialerSpecialCode: call.inputDialerSpecialCode, 128e1c44949Sopenharmony_ci reportOttCallDetailsInfo: call.reportOttCallDetailsInfo, 129e1c44949Sopenharmony_ci reportOttCallEventInfo: call.reportOttCallEventInfo, 130e1c44949Sopenharmony_ci removeMissedIncomingCallNotification: call.removeMissedIncomingCallNotification, 131e1c44949Sopenharmony_ci setVoIPCallState: call.setVoIPCallState, 132e1c44949Sopenharmony_ci sendCallUiEvent: call.sendCallUiEvent, 133e1c44949Sopenharmony_ci DialOptions: call.DialOptions, 134e1c44949Sopenharmony_ci DialCallOptions: call.DialCallOptions, 135e1c44949Sopenharmony_ci ImsCallMode: call.ImsCallMode, 136e1c44949Sopenharmony_ci VoNRState: call.VoNRState, 137e1c44949Sopenharmony_ci AudioDevice: call.AudioDevice, 138e1c44949Sopenharmony_ci AudioDeviceType: call.AudioDeviceType, 139e1c44949Sopenharmony_ci AudioDeviceCallbackInfo: call.AudioDeviceCallbackInfo, 140e1c44949Sopenharmony_ci CallRestrictionType: call.CallRestrictionType, 141e1c44949Sopenharmony_ci CallTransferInfo: call.CallTransferInfo, 142e1c44949Sopenharmony_ci CallTransferType: call.CallTransferType, 143e1c44949Sopenharmony_ci CallTransferSettingType: call.CallTransferSettingType, 144e1c44949Sopenharmony_ci CallAttributeOptions: call.CallAttributeOptions, 145e1c44949Sopenharmony_ci VoipCallAttribute: call.VoipCallAttribute, 146e1c44949Sopenharmony_ci ConferenceState: call.ConferenceState, 147e1c44949Sopenharmony_ci CallType: call.CallType, 148e1c44949Sopenharmony_ci VideoStateType: call.VideoStateType, 149e1c44949Sopenharmony_ci DetailedCallState: call.DetailedCallState, 150e1c44949Sopenharmony_ci CallRestrictionInfo: call.CallRestrictionInfo, 151e1c44949Sopenharmony_ci CallRestrictionMode: call.CallRestrictionMode, 152e1c44949Sopenharmony_ci CallEventOptions: call.CallEventOptions, 153e1c44949Sopenharmony_ci CallAbilityEventId: call.CallAbilityEventId, 154e1c44949Sopenharmony_ci DialScene: call.DialScene, 155e1c44949Sopenharmony_ci DialType: call.DialType, 156e1c44949Sopenharmony_ci RejectMessageOptions: call.RejectMessageOptions, 157e1c44949Sopenharmony_ci CallTransferResult: call.CallTransferResult, 158e1c44949Sopenharmony_ci CallWaitingStatus: call.CallWaitingStatus, 159e1c44949Sopenharmony_ci RestrictionStatus: call.RestrictionStatus, 160e1c44949Sopenharmony_ci TransferStatus: call.TransferStatus, 161e1c44949Sopenharmony_ci DisconnectedDetails: call.DisconnectedDetails, 162e1c44949Sopenharmony_ci DisconnectedReason: call.DisconnectedReason, 163e1c44949Sopenharmony_ci MmiCodeResults: call.MmiCodeResults, 164e1c44949Sopenharmony_ci MmiCodeResult: call.MmiCodeResult, 165e1c44949Sopenharmony_ci answer: call.answer, 166e1c44949Sopenharmony_ci cancelCallUpgrade: call.cancelCallUpgrade, 167e1c44949Sopenharmony_ci controlCamera: call.controlCamera, 168e1c44949Sopenharmony_ci setPreviewSurface: call.setPreviewSurface, 169e1c44949Sopenharmony_ci setCameraZoom: call.setCameraZoom, 170e1c44949Sopenharmony_ci setDisplaySurface: call.setDisplaySurface, 171e1c44949Sopenharmony_ci setDeviceDirection: call.setDeviceDirection, 172e1c44949Sopenharmony_ci VideoRequestResultType: call.VideoRequestResultType, 173e1c44949Sopenharmony_ci DeviceDirection: call.DeviceDirection, 174e1c44949Sopenharmony_ci CallSessionEventId: call.CallSessionEventId, 175e1c44949Sopenharmony_ci ImsCallModeInfo: call.ImsCallModeInfo, 176e1c44949Sopenharmony_ci CallSessionEvent: call.CallSessionEvent, 177e1c44949Sopenharmony_ci PeerDimensionsDetail: call.PeerDimensionsDetail, 178e1c44949Sopenharmony_ci CameraCapabilities: call.CameraCapabilities, 179e1c44949Sopenharmony_ci NumberMarkInfo: call.NumberMarkInfo, 180e1c44949Sopenharmony_ci MarkType: call.MarkType, 181e1c44949Sopenharmony_ci dial: call.dial, 182e1c44949Sopenharmony_ci hasCall: call.hasCall, 183e1c44949Sopenharmony_ci hasCallSync: call.hasCallSync, 184e1c44949Sopenharmony_ci getCallState: call.getCallState, 185e1c44949Sopenharmony_ci getCallStateSync: call.getCallStateSync, 186e1c44949Sopenharmony_ci hasVoiceCapability: call.hasVoiceCapability, 187e1c44949Sopenharmony_ci isEmergencyPhoneNumber: call.isEmergencyPhoneNumber, 188e1c44949Sopenharmony_ci formatPhoneNumber: call.formatPhoneNumber, 189e1c44949Sopenharmony_ci formatPhoneNumberToE164: call.formatPhoneNumberToE164, 190e1c44949Sopenharmony_ci CallState: call.CallState, 191e1c44949Sopenharmony_ci EmergencyNumberOptions: call.EmergencyNumberOptions, 192e1c44949Sopenharmony_ci NumberFormatOptions: call.NumberFormatOptions, 193e1c44949Sopenharmony_ci startRTT: call.startRTT, 194e1c44949Sopenharmony_ci stopRTT: call.stopRTT 195e1c44949Sopenharmony_ci};