package kr.co.icontrols.callengine.sip; import android.app.ActivityManager; import android.app.Service; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.SharedPreferences; import android.media.AudioManager; import android.media.MediaPlayer; import android.media.audiofx.Equalizer; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.os.IBinder; import android.os.Looper; import android.os.Message; import android.os.Messenger; import android.os.RemoteException; import android.util.Log; import com.artncore.WallPadDataMgr.WallpadDeviceSet; import com.artncore.WallPadDataMgr.WallpadStatusData; import com.artncore.WallPadDataMgr.wallpaddbmgr; import com.artncore.WallPadDataMgr.wallpaddbmgr.AddressSet; import com.artncore.commons.define; import com.util.LogUtil; import java.io.IOException; import java.net.DatagramPacket; import java.net.DatagramSocket; import java.net.InetAddress; import java.net.NetworkInterface; import java.net.SocketException; import java.net.SocketTimeoutException; import java.net.UnknownHostException; import java.util.ArrayList; import java.util.Collections; import java.util.Date; import java.util.List; import java.util.StringTokenizer; import java.util.TimerTask; import java.util.regex.Pattern; import bssoft.stack.sip.BSSVideo; import bssoft.stack.sip.CMCore; import bssoft.stack.sip.SIPCONTACTHeader; import bssoft.stack.sip.SIPCall; import bssoft.stack.sip.SIPHeader; import bssoft.stack.sip.SIPRequestLine; import bssoft.stack.sip.SIPStack; import kr.co.icontrols.callengine.engine.CallManager; import kr.co.icontrols.callengine.remotecall.AVPacket; import kr.co.icontrols.callengine.engine.CallManager.CALLEVENTTYPE; import kr.co.icontrols.callengine.engine.CallManager.CALLTYPE; import kr.co.icontrols.wallpadcall.MainActivity; import kr.co.icontrols.wallpadcall.declare.Common; import kr.co.icontrols.wallpadcall.declare.Declare; import kr.co.icontrols.wallpadcall.declare.Declare.CALLTRIGGER; public class SIPStun extends Service { static final String TAG = "SIPStun"; boolean bLOG = true; private void LOG(String log) { if (bLOG) Log.v(TAG, log); } boolean bLOG_DEBUG = true; private void LOG_DEBUG(String log) { if (bLOG_DEBUG) Log.d(TAG, log); } boolean bLOG_INFO = true; private void LOG_INFO(String log) { if (bLOG_INFO) Log.i(TAG, log); } boolean bLOG_WARN = true; private void LOG_WARN(String log) { if (bLOG_WARN) Log.w(TAG, log); } boolean bLOG_ERROR = true; private void LOG_ERROR(String log) { if (bLOG_ERROR) Log.e(TAG, log); } public SIPSignalReceiver mSIPSignalReceiver = null; android.media.Ringtone oRingTone = null; MediaPlayer oRingbackTone = null; CMCore cmcore = null; ConnectivityManager connectivityManager = null; protected static String padNumber = ""; protected static int officeNumber = 0; // 1:정문 2:후문 3:관할 4:관리사무소 protected int latestMenu = 0; private static boolean isRunning = false; ArrayList mClients = new ArrayList(); final Messenger mMessenger = new Messenger(new CmPiper()); public static boolean bBlackCall = false; public static boolean bBlackCallSupport = true; public static boolean bBlackcallBackgroundMode = true; boolean bBLOCK_INVITE_MSG = false; static AVPacket avPacket = null; // 방문객 원격통화 모바일 오디오 데이터 private boolean bLobbyCallUse = false, bGuardCallUse = false, bResiCallUse = false; @Override public IBinder onBind(Intent intent) { return mMessenger.getBinder(); } class CmPiper extends Handler { // Handler of incoming messages from UI. @Override public void handleMessage(Message msg) { String value = "null"; switch (msg.what) { case CMCore.BSSSIPStun_ICONTROLS_REGISTER: mClients.add(msg.replyTo); Log.i(TAG, "SIPStun CmPiper DIALER_REGISTER : " + msg.toString()); updateBlockStatus(); if (SIPStack.bDirectCall == true) { if (padNumber == null || padNumber.length() == 0) { boolean bValidroom = getMyroomname(); if (bValidroom == false) { Log.i(TAG, "Invalid room"); dialerPadNumber(""); } else dialerPadNumber(padNumber); } else dialerPadNumber(padNumber); if (SIPStun.bBlackcallBackgroundMode == true) { if (SIPStun.bBlackCall == true && SIPController.sipCall.flag == true && SIPController.sipCall.bResponsebackgroundcall == true && SIPController.sipCall.bResponsebackgroundcallReady == false) { SIPController.sipCall.bResponsebackgroundcallReady = true; SIPController.sipCall.responsebackgroundcallTimer = new Date(); } else { dialerPadType(BSSVideo.HNS_SERVICE_ORIGINATOR_SELECTED, officeNumber); } } else { dialerPadType(BSSVideo.HNS_SERVICE_ORIGINATOR_SELECTED, officeNumber); } } break; case CMCore.BSSSIPStun_ICONTROLS_UNREGISTER: mClients.remove(msg.replyTo); Log.i(TAG, "SIPStun CmPiper CMCore.BSSSIPStun_ICONTROLS_UNREGISTER : " + msg.toString()); callTerminate(); break; case CMCore.BSSSIPStun_ICONTROLS_DIALER_COMMAND: Log.i(TAG, "SIPStun CmPiper CMCore.BSSSIPStun_ICONTROLS_DIALER_COMMAND : " + msg.toString()); break; case CMCore.BSSSIPStun_ICONTROLS_CONTACT_CALLNEIGHBOR: value = msg.getData().getString("CALLNEIGHBOR"); Log.i(TAG, ">>>SIPStun CmPiper BSSSIPStun_ICONTROLS_CONTACT_CALLNEIGHBOR : " + value); break; case CMCore.BSSSIPStun_ICONTROLS_CONTACT_CALLGUARD: value = msg.getData().getString("CALLGUARD"); Log.i(TAG, ">>>SIPStun CmPiper BSSSIPStun_ICONTROLS_CONTACT_CALLGUARD : " + value); break; case CMCore.BSSSIPStun_ICONTROLS_DIALER_ACCEPTMULTICALL: value = msg.getData().getString("ACCEPTMULTICALL"); if (SIPController.pendingCall != null && SIPController.pendingCall.flag == true) { SIPController.pendingCall.bAsMaster = true; } Log.i(TAG, ">>>SIPStun CmPiper BSSSIPStun_ICONTROLS_DIALER_ACCEPTMULTICALL"); break; case CMCore.BSSSIPStun_ICONTROLS_DIALER_REJECTMULTICALL: value = msg.getData().getString("REJECTMULTICALL"); if (SIPController.pendingCall != null && SIPController.pendingCall.flag == true) { SIPController.pendingCall.bRejectRequest = true; } Log.i(TAG, ">>>SIPStun CmPiper BSSSIPStun_ICONTROLS_DIALER_REJECTMULTICALL"); break; case CMCore.BSSSIPStun_ICONTROLS_DIALER_FORWARD: value = msg.getData().getString("FORWARD"); if (SIPController.sipCall != null && SIPController.sipCall.flag == true) { Log.i(TAG, ">>>SIPStun CmPiper BSSSIPStun_ICONTROLS_DIALER_FORWARD : " + value); SIPController.forward.contact = new String(value); SIPController.sipCall.bForwardRequest = true; } Log.i(TAG, ">>>SIPStun CmPiper BSSSIPStun_ICONTROLS_DIALER_FORWARD"); Log.d(TAG, "FORWARD : " + value); break; case CMCore.BSSSIPStun_ICONTROLS_SET_INT_VALUE: String strEQCtrl = msg.getData().getString("cmd"); Log.w(TAG, "strEQCtrl [" + strEQCtrl + "]"); if (strEQCtrl.equals("get_eq_values")) { replyEQValue(); } else if (strEQCtrl.equals("set_eq_value")) { String strEQ = msg.getData().getString("eq"); short sValue = msg.getData().getShort("value"); setEQValue(strEQ, sValue); } break; case CMCore.BSSSIPStun_ICONTROLS_BLOCK_INVITE_MSG: Log.e(TAG, "[CmPiper] BSSSIPStun_ICONTROLS_BLOCK_INVITE_MSG"); // BR을 수신하여 처리하는 것으로 변경하였으나, 혹시몰라 여기도 남겨둠 bBLOCK_INVITE_MSG = true; StunHandler.removeMessages(HANDLERMSG.RELEASE_BLOCK_INVITE_MSG); sendHandlerMsgDelayed(HANDLERMSG.RELEASE_BLOCK_INVITE_MSG, 0, 0, 3000); break; case Declare.VISITORREMOTECALL.BSSSIPStun_ICONTROLS_RECEIVE_MOBILE_AUDIO_LOBBY: avPacket = (AVPacket) msg.getData().getSerializable(Declare.VISITORREMOTECALL.MOBILE_AUDIO_TO_LOBBY); SIPSound.bufferringMobileAudio(avPacket.data, avPacket.length); break; case Declare.VISITORREMOTECALL.BSSSIPStun_ICONTROLS_RECEIVE_MOBILE_AUDIO_GUARD: avPacket = (AVPacket) msg.getData().getSerializable(Declare.VISITORREMOTECALL.MOBILE_AUDIO_TO_GUARD); SIPSound.bufferringMobileAudio(avPacket.data, avPacket.length); break; default: Log.i(TAG, "SIPStun CmPiper default:" + msg.toString()); super.handleMessage(msg); } } } public final class HANDLERMSG { public final static int RELEASE_BLOCK_INVITE_MSG = 100; public final static int NEWCALL_TRY_01 = 200; public final static int NEWCALL_TRY_02 = 300; public final static int NEWCALL_TRY_03 = 400; public final static int NEWCALL_TRY_04 = 500; public final static int NEWCALL_TRY_05 = 600; } boolean bRECEIVE_REMOTE_AUDIO = false; public Handler StunHandler = new Handler(Looper.getMainLooper()) { public void handleMessage(Message msg) { LOG("[StunHandler] StunHandler : what [" + msg.what + "], arg1 [" + msg.arg1 + "], arg2 [" + msg.arg2 + "]"); switch (msg.what) { case HANDLERMSG.RELEASE_BLOCK_INVITE_MSG: bBLOCK_INVITE_MSG = false; updateBlockStatus(); break; case HANDLERMSG.NEWCALL_TRY_01: break; case HANDLERMSG.NEWCALL_TRY_02: break; case HANDLERMSG.NEWCALL_TRY_03: break; case HANDLERMSG.NEWCALL_TRY_04: break; case HANDLERMSG.NEWCALL_TRY_05: break; default: LOG("StunHandler : " + msg.what); break; } } }; public void sendHandlerMsg(int what, int arg1, int arg2) { try { LOG("[sendHandlerMsg] what [" + what + "], arg1 [" + arg1 + "], arg2 [" + arg2 + "]"); Message HandleMsg = StunHandler.obtainMessage(); HandleMsg.what = what; HandleMsg.arg1 = arg1; HandleMsg.arg2 = arg2; StunHandler.sendMessage(HandleMsg); } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); } catch (Exception e) { Log.e(TAG, "[Exception] sendHandlerMsg(msg)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } } public void sendHandlerMsg(int what, int arg1, int arg2, Object obj) { try { LOG("[sendHandlerMsg] what [" + what + "], arg1 [" + arg1 + "], arg2 [" + arg2 + "]"); Message HandleMsg = StunHandler.obtainMessage(); HandleMsg.what = what; HandleMsg.arg1 = arg1; HandleMsg.arg2 = arg2; HandleMsg.obj= obj; StunHandler.sendMessage(HandleMsg); } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); } catch (Exception e) { Log.e(TAG, "[Exception] sendHandlerMsg(msg)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } } public void sendHandlerMsgDelayed(int what, int arg1, int arg2, long delay) { try { LOG("[sendHandlerMsgDelayed] what [" + what + "], arg1 [" + arg1 + "], arg2 [" + arg2 + "], delay [" + delay + "]"); Message HandleMsg = StunHandler.obtainMessage(); HandleMsg.what = what; HandleMsg.arg1 = arg1; HandleMsg.arg2 = arg2; StunHandler.sendMessageDelayed(HandleMsg, delay); } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); } catch (Exception e) { Log.e(TAG, "[Exception] sendHandlerMsgDelayed(msg)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } } @Override public void onCreate() { SIPStack.SIP_MESSAGE_DEBUG = true; Log.i(TAG, " SIPStun onCreate called newly"); super.onCreate(); SIPStack.setLicense("주식회사아이콘트롤스 200701243005451"); SIPStack.bootTime = new Date(); BSSVideo.bService = false; BSSVideo.bViewme = false; SIPStack.ventureCall = true; // 서비스폰 타입설정 //////////////////////////////////////////////////////////// BSSVideo.HNS_SERVICE_ORIGINATOR_SELECTED = BSSVideo.HNS_SERVICE_NEIGHBOR; //세대기:HNS_SERVICE_NEIGHBOR, //로비폰:HNS_SERVICE_LOBBY, //경비실폰:HNS_SERVICE_GUARD BSSVideo.HNS_SERVICE_RECEIVER_SELECTED = BSSVideo.HNS_SERVICE_NONE; latestMenu = BSSVideo.HNS_SERVICE_ORIGINATOR_SELECTED; if (BSSVideo.HNS_SERVICE_ORIGINATOR_SELECTED == BSSVideo.HNS_SERVICE_GUARD) { officeNumber = 1; //1:정문 2:후문 3:관할 4:관리사무소 } else officeNumber = 0; //not assign if (SIPStack.bActive == false) { if (SIPController.BACKGROUNDTimer != null) SIPController.BACKGROUNDTimer.cancel(); Log.i(TAG, "===================== SIPStack.init!! ====================="); SIPController.init(); SIPStack.bNetworkActive = false; } SIPStack.bBackgroundRunning = false; SIPStack.bGeneralPhoneDetected = false; getStackKey(); WallpadDeviceSet deviceSet = new WallpadDeviceSet(this); bLobbyCallUse = deviceSet.Get_LobbyCallUse(); bGuardCallUse = deviceSet.Get_GuardCallUse(); bResiCallUse = deviceSet.Get_ResidenceCallUse(); deviceSet.closeDB(); LOG("[onCreate] bLobbyCallUse [" + bLobbyCallUse + "], bGuardCallUse [" + bGuardCallUse + "], bResiCallUse [" + bResiCallUse + "]"); try { String host = SIPController.getSHVE140SLocalIpAddress(); Log.i(TAG, "Host : " + host); InetAddress thisComputer = null; if (host != null && host.length() > 0) thisComputer = InetAddress.getByName(host); else thisComputer = InetAddress.getByName("127.0.0.1"); byte[] address = thisComputer.getAddress(); if (address.length == 4) { int unsignedByte1 = address[0] < 0 ? address[0] + 256 : address[0]; int unsignedByte2 = address[1] < 0 ? address[1] + 256 : address[1]; int unsignedByte3 = address[2] < 0 ? address[2] + 256 : address[2]; int unsignedByte4 = address[3] < 0 ? address[3] + 256 : address[3]; SIPStack.strLocalip = unsignedByte1 + "." + unsignedByte2 + "." + unsignedByte3 + "." + unsignedByte4; } else if (SIPStack.SIP_MESSAGE_DEBUG == true) { Log.i(TAG, "no ipv4."); } if (SIPStack.SIP_MESSAGE_DEBUG == true) { Log.i(TAG, SIPStack.strLocalip + " founded."); } if (SIPStack.stackkey.strServerDomain == null) { SIPStack.stackkey.strServerDomain = ""; } if (SIPStack.bDirectCall == true) { boolean bValidroom = getMyroomname(); if (bValidroom == false) { Log.i("SIPStun", "Invalid room"); dialerPadNumber(""); } else { dialerPadNumber(padNumber); } } if (SIPStack.bActive == false) SIPController.initSound(SIPController.bMobileCall); if (SIPStack.bActive == false) { mSIPSignalReceiver = new SIPSignalReceiver(thisComputer, SIPStack.localPort); if (mSIPSignalReceiver != null) { mSIPSignalReceiver.start(); SIPStack.localPort = SIPStack.SIP_SIGNAL_PORT; SIPStack.ipdns.bSipAddressResolved = false; cmcore = new CMCore(); connectivityManager = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE); initializeCm(address, SIPStack.strLocalip.getBytes(), SIPStack.localPort, SIPStack.stackkey.strServerHost, SIPStack.stackkey.serverPort, SIPStack.stackkey.strServerDomain, SIPStack.stackkey.strId.getBytes(), SIPStack.stackkey.strCid.getBytes(), SIPStack.stackkey.strAuthid.getBytes(), SIPStack.stackkey.strAuthpassword.getBytes()); SIPController.audioRTPManager = new RTPManager(this, SIPStack.SIP_MEDIATYPE_AUDIO); SIPSound.amAudioManager = (AudioManager) this.getSystemService(AUDIO_SERVICE); SIPSound.initRoute(); if (SIPController.sipCall == null) { Log.i(TAG, "sipCall is null"); } SIPStack.bActive = true; } } registerWallPadCallLiveBRReceiver(); } catch (UnknownHostException uhe) { Log.e(TAG, "[UnknownHostException] onCreate()"); //uhe.printStackTrace(); LogUtil.errorLogInfo("", TAG, uhe); } catch (Exception e) { Log.e(TAG, "[Exception] onCreate()"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } Log.i(TAG, "===================== Service Started!! ====================="); CMCore.bPausing = false; isRunning = true; } public boolean getMyroomname() { try { padNumber = ""; boolean bJeffreyWay = true; // Log.i(TAG, "[getMyroomname] bJeffreyWay : " + bJeffreyWay); if (bJeffreyWay) { SIPStack.strLocalip = getDeviceIPAddress(); Log.i(TAG, "[getMyroomname] SIPStack.strLocalip [" + SIPStack.strLocalip + "]"); int nMaxTryCnt = 10; int nCnt = 0; while ((!validateIPAddress(SIPStack.strLocalip)) && (nCnt < nMaxTryCnt)) { Thread.sleep(1000); SIPStack.strLocalip = getDeviceIPAddress(); nCnt++; } Log.i(TAG, "[getMyroomname] After while loof!! SIPStack.strLocalip [" + SIPStack.strLocalip + "], nCnt [" + nCnt + "]"); // System.out.print(unsignedByte + "."); String[] aDeviceName = makeDeviceName(SIPStack.strLocalip); if (aDeviceName[0] == DeviceString.strType_Lobby) { // 로비폰 padNumber = aDeviceName[1] + "동 " + aDeviceName[2] + "번 로비"; } else if (aDeviceName[0] == DeviceString.strType_Guard) { // 경비실기 padNumber = aDeviceName[1] + "동 " + aDeviceName[2] + "번 경비실"; } else if (aDeviceName[0] == DeviceString.strType_RentResi) { // 분리 세대 단말기 padNumber = aDeviceName[1] + "동 " + aDeviceName[2] + "-1호"; } else { // 세대단말기 padNumber = aDeviceName[1] + "동 " + aDeviceName[2] + "호"; } SIPStack.stackkey.strId = makeSIPID(SIPStack.strLocalip); SIPStack.stackkey.strAuthid = makeSIPID(SIPStack.strLocalip); return true; } else { String host = SIPController.getSHVE140SLocalIpAddress(); InetAddress thisComputer = null; if (host != null && host.length() > 0) thisComputer = InetAddress.getByName(host); else thisComputer = InetAddress.getByName("127.0.0.1"); byte[] address = thisComputer.getAddress(); if (address.length == 4) { int unsignedByte1 = address[0] < 0 ? address[0] + 256 : address[0]; int unsignedByte2 = address[1] < 0 ? address[1] + 256 : address[1]; int unsignedByte3 = address[2] < 0 ? address[2] + 256 : address[2]; int unsignedByte4 = address[3] < 0 ? address[3] + 256 : address[3]; SIPStack.strLocalip = unsignedByte1 + "." + unsignedByte2 + "." + unsignedByte3 + "." + unsignedByte4; Log.i(TAG, "[getMyroomname] SIPStack.strLocalip : " + SIPStack.strLocalip); // System.out.print(unsignedByte + "."); String[] aDeviceName = makeDeviceName(SIPStack.strLocalip); if (aDeviceName[0] == DeviceString.strType_Lobby) { // 로비폰 padNumber = aDeviceName[1] + "동 " + aDeviceName[2] + "번 로비"; } else if (aDeviceName[0] == DeviceString.strType_Guard) { // 경비실기 padNumber = aDeviceName[1] + "동 " + aDeviceName[2] + "번 경비실"; } else { // 세대단말기 padNumber = aDeviceName[1] + "동 " + aDeviceName[2] + "호"; } SIPStack.stackkey.strId = makeSIPID(SIPStack.strLocalip); SIPStack.stackkey.strAuthid = makeSIPID(SIPStack.strLocalip); return true; } else return false; } } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); } catch (Exception e) { Log.e(TAG, "[Exception] getMyroomname()"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } return false; } private Pattern mPattern = Pattern.compile("^(([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.){3}([01]?\\d\\d?|2[0-4]\\d|25[0-5])$"); private boolean validateIPAddress(String IPAddress) { Log.i(TAG, "[validateIPAddress] IPAddress [" + IPAddress + "]"); if (IPAddress == null) return false; return mPattern.matcher(IPAddress).matches(); } public String getDeviceIPAddress() { try { LOG("[getDeviceIPAddress] START!"); if (Integer.parseInt(Build.VERSION.RELEASE.substring(0, 1)) >= 7) { // // 메이드인랩 김수진 선임 (A0S 7.0) List interfaces = Collections.list(NetworkInterface.getNetworkInterfaces()); for (NetworkInterface intf : interfaces) { List addrs = Collections.list(intf.getInetAddresses()); for (InetAddress addr : addrs) { if (!addr.isLoopbackAddress()) { String sAddr = addr.getHostAddress(); boolean isIPv4 = sAddr.indexOf(':') < 0; if (isIPv4) return sAddr; } } } } else { // 기존코드 (AOS 6.0) String strResult = ""; String strNetInfo =""; if(NetworkInterface.getByName("eth0")!=null) strNetInfo = NetworkInterface.getByName("eth0").toString(); LOG_DEBUG("strNetInfo " + strNetInfo); LOG("[getDeviceIPAddress] strNetInfo : " + strNetInfo + "]"); strNetInfo.trim(); String[] Parse_01 = strNetInfo.split("\\]"); String[] Parse_02 = Parse_01[Parse_01.length - 1].split("\\/"); strResult = Parse_02[1]; LOG("[getDeviceIPAddress] DONE! [IP Address : " + strResult + "]"); return strResult; } } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); } catch (Exception e) { Log.e(TAG, "[Exception] getDeviceIPAddress()"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } return ""; } private void getStackKey() { SharedPreferences prefs = getSharedPreferences("PrefName", MODE_PRIVATE); String textId = prefs.getString(SIPStack.stackkey.KEY_BSS_ID, ""); String textAuthid = prefs.getString(SIPStack.stackkey.KEY_BSS_AUTHID, ""); String textPassword = prefs.getString(SIPStack.stackkey.KEY_BSS_PASSWORD, ""); String textCid = prefs.getString(SIPStack.stackkey.KEY_BSS_CID, ""); String textServerip = prefs.getString(SIPStack.stackkey.KEY_BSS_SERVERIP, ""); String textDomain = prefs.getString(SIPStack.stackkey.KEY_BSS_SERVERDOMAIN, ""); String textPort = prefs.getString(SIPStack.stackkey.KEY_BSS_SERVERPORT, ""); String textImsi = prefs.getString(SIPStack.stackkey.KEY_BSS_IMSI, ""); String textGeneralPhone = prefs.getString(SIPStack.stackkey.KEY_BSS_GENERALPHONE, ""); String textWebid = prefs.getString(SIPStack.stackkey.KEY_BSS_WEBID, ""); String textWebpwd = prefs.getString(SIPStack.stackkey.KEY_BSS_WEBPWD, ""); String textLatestdial = prefs.getString(SIPStack.stackkey.KEY_BSS_LATESTDIAL, ""); String textForward = prefs.getString(SIPStack.stackkey.KEY_BSS_FORWARD, ""); SIPStack.stackkey.strImsi = textImsi.trim(); SIPStack.stackkey.strGeneralPhone = textGeneralPhone.trim(); SIPStack.stackkey.strWebId = textWebid.trim(); SIPStack.stackkey.strWebPwd = textWebpwd.trim(); SIPStack.userDial.latestDial = textLatestdial.trim(); Log.i(TAG, "[getStackKey] >>>>>WEB ID : " + SIPStack.stackkey.strWebId + " WEB PWD : " + SIPStack.stackkey.strWebPwd); SIPStack.stackkey.strId = textId.trim(); SIPStack.stackkey.strCid = textCid.trim(); SIPStack.stackkey.strAuthid = textAuthid.trim(); SIPStack.stackkey.strAuthpassword = textPassword.trim(); SIPStack.stackkey.strServerHost = textServerip.trim(); SIPStack.stackkey.strServerDomain = textDomain.trim(); if (textPort.trim().length() > 0) SIPStack.stackkey.serverPort = Integer.parseInt(textPort.trim()); else SIPStack.stackkey.serverPort = 5060; // 192.168.10.21 SIPStack.stackkey.strId = "07077392005"; SIPStack.stackkey.strAuthid = "07077392005"; SIPStack.stackkey.strAuthpassword = "002005"; SIPStack.stackkey.strServerHost = "192.168.10.2"; SIPStack.stackkey.serverPort = 5060; SIPController.forward.setValue(textForward.trim()); if (SIPStack.SIP_MESSAGE_DEBUG == true) { Log.i(TAG, "ID : " + SIPStack.stackkey.strId); Log.i(TAG, "CID : " + SIPStack.stackkey.strCid); Log.i(TAG, "AUTHID : " + SIPStack.stackkey.strAuthid); Log.i(TAG, "AUTHPASSWORD : " + SIPStack.stackkey.strAuthpassword); Log.i(TAG, "SERVERHOST : " + SIPStack.stackkey.strServerHost); Log.i(TAG, "SERVERDOMAIN : " + SIPStack.stackkey.strServerDomain); Log.i(TAG, "SERVERPORT : " + SIPStack.stackkey.serverPort); Log.i(TAG, "FORWARD set : " + SIPController.forward.bForward + " type : " + SIPController.forward.iForwardTarget + " number : " + SIPController.forward.number); } return; } @Override public int onStartCommand(Intent intent, int flags, int startId) { LOG_WARN("[onStartCommand] flags [" + flags + "], startId [" + startId + "]"); return START_STICKY; // run until explicitly stopped. } public static boolean isRunning() { return isRunning; } @Override public void onDestroy() { super.onDestroy(); unregisterWallPadCallLiveBRReceiver(); if (SIPStack.bUseCtrlTimer == true) { if (cmcore.SIGNALCTRLTimer != null) { cmcore.SIGNALCTRLTimer.cancel(); } cmcore.SIGNALCTRLTimer = null; } else { if (cmcore.SIGNALCTRLThread != null && cmcore.SIGNALCTRLThread.isAlive() == true) { cmcore.SIGNALCTRLThread.interrupt(); cmcore.SIGNALCTRLRunning = false; } } mSIPSignalReceiver.interrupt(); SIPStack.bActive = false; Log.i(TAG, "===================== Service Stopped!! ====================="); isRunning = false; } // SignalReceiver class SIPSignalReceiver extends Thread { InetAddress thisComputer; protected DatagramSocket theSocket; protected DatagramPacket dp; protected boolean bFlag = false; boolean bReady = false; byte[] buffer; public SIPSignalReceiver(InetAddress thisComputer, int port) { bReady = false; try { if (port > 0 && port <= 65556) { SIPStack.SIP_SIGNAL_PORT = port; for (int i = 0; i < SIPStack.MAX_SIGNAL_PORTS; i++) { SIPStack.SIP_SIGNAL_PORT = port + i; Log.i(TAG, "try SIP Signal socket create on " + SIPStack.SIP_SIGNAL_PORT); try { theSocket = new DatagramSocket(SIPStack.SIP_SIGNAL_PORT); } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); } catch (Exception e) { Log.e(TAG, "[Exception] SipSignalReceiver -> SipSignalReceiver (InetAddress thisComputer, int port)"); } if (theSocket != null) { bFlag = true; break; } } if (theSocket == null) { Log.i(TAG, "[SipSignalReceiver] theSocket is null!!!"); bFlag = false; return; } theSocket.setReuseAddress(true); this.thisComputer = thisComputer; } buffer = new byte[SIPStack.SIP_MAXMESSAGE_SIZE]; } catch (SocketException se) { Log.e(TAG, "[SocketException] ERROR SipSignalReceiver Construct"); //System.err.println(se); LogUtil.errorLogInfo("", TAG, se); SIPStack.exceptionCountAtCurrentCall++; } catch (Exception e) { Log.e(TAG, "[Exception] SipSignalReceiver construct exception occurred."); } } public void run() { Log.i(TAG, "[SipSignalReceiver] run() >>>> Signal Thread receive ready."); try { dp = new DatagramPacket(buffer, buffer.length); } catch (NullPointerException ne) { //System.err.println(ne); LogUtil.errorLogInfo("", TAG, ne); SIPStack.exceptionCountAtCurrentCall++; return; } bReady = true; this.setPriority(1); while (bReady && theSocket != null && dp != null) { try { Log.i(TAG, "[SipSignalReceiver] >>>> SOCKET SoTimeout : " + theSocket.getSoTimeout()); dp.setLength(SIPStack.SIP_MAXMESSAGE_SIZE); dp.setData(buffer); theSocket.receive(dp); if (CMCore.bPausing == true) { Date currentTime = new Date(); int milli = (int) (currentTime.getTime() - CMCore.pauseTime.getTime()); if (milli < CMCore.BSSSIPStun_ICONTROLS_PAUSING_DURATION) { Log.e(TAG, "CMCore.bPausing [" + CMCore.bPausing + "], pause duration [" + milli + "]. signal is ignored!!!"); continue; } } if (0 != BSSSipParser(dp)) { if (SIPStack.SIP_MESSAGE_DEBUG == true) Log.i(TAG, "SIP MESSAGE PARSER ERROR"); Thread.yield(); } SIPStack.bIntraffic = true; } catch (SocketTimeoutException se) { Log.e(TAG, "[SocketTimeoutException] Socket time out..."); //se.printStackTrace(); LogUtil.errorLogInfo("", TAG, se); } catch (IOException e) { Log.e(TAG, "[IOException] IOException"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); //System.err.println(e); SIPStack.exceptionCountAtCurrentCall++; } catch (Exception e1) { Log.e(TAG, "[Exception] +++ SipSignalReceiver receive thread exception occurred."); //e1.printStackTrace(); //System.err.println(e1); LogUtil.errorLogInfo("", TAG, e1); } } Log.e(TAG, "Signal Thread terminated"); } public int BSSSipParser(DatagramPacket dp) { if (dp == null) return -1; String remoteIp = null; byte[] address = dp.getAddress().getAddress(); if (address == null || address.length <= 0) return -1; if (address.length == 4) { int unsignedByte1 = address[0] < 0 ? address[0] + 256 : address[0]; int unsignedByte2 = address[1] < 0 ? address[1] + 256 : address[1]; int unsignedByte3 = address[2] < 0 ? address[2] + 256 : address[2]; int unsignedByte4 = address[3] < 0 ? address[3] + 256 : address[3]; remoteIp = unsignedByte1 + "." + unsignedByte2 + "." + unsignedByte3 + "." + unsignedByte4; } else return -1; int remotePort = dp.getPort(); if (remotePort <= 0) return -1; int iMessageType = 0; int iMethodType = 0; String s = new String(dp.getData(), 0, 0, dp.getLength()); if (s == null || s.length() <= 0) return -1; // SIP PARSE StringTokenizer st = new StringTokenizer(s, "\n", true); // int headerCount = 0; if (st.hasMoreTokens()) { String str = st.nextToken(); if (str.length() > 0) { iMethodType = SIPStack.getRequestlineMethod(str); // Log.d(TAG, "[BSSSipParser] iMethodType [" + iMethodType + "]"); if (iMethodType == SIPStack.SIP_METHODTYPE_NONE) { return 0; } else if (iMethodType == SIPStack.SIP_METHODTYPE_RESPONSE) { iMethodType = SIPStack.getCSeqMethod(s); // Log.i(TAG, ">>>>>>>>>> RESPONSE iMethodType : " + iMethodType); if (iMethodType == SIPStack.SIP_METHODTYPE_NONE) return 0; iMessageType = SIPStack.SIP_MSGTYPE_RESPONSE; if (iMethodType == SIPStack.SIP_METHODTYPE_REGISTER) SIPParser(s, iMessageType, iMethodType); else if (iMethodType != SIPStack.SIP_METHODTYPE_NONE) SIPParser(s, iMessageType, iMethodType, remoteIp, remotePort); return 0; } else { iMessageType = SIPStack.SIP_MSGTYPE_REQUEST; SIPParser(s, iMessageType, iMethodType, remoteIp, remotePort); } } } return 0; // normal } // BSSSipParser() public int BSSSipSendUdpPacket(String sIp, int iPort, byte[] data, int dataSize) { int sent = 0; if (sIp == null || sIp.length() == 0) return 0; if (iPort <= 0) return 0; if (dataSize <= 0) return 0; try { InetAddress ia = InetAddress.getByName(sIp); if (ia != null) { DatagramPacket dp = new DatagramPacket(data, dataSize, ia, iPort); if (dp != null && theSocket!=null ) theSocket.send(dp); sent = dataSize; SIPStack.bOuttraffic = true; if (bPrintSIPMsgIO) printSIPMessage(MESSAGE.SEND, new String(data)); } } catch (UnknownHostException uhe) { Log.e(TAG, "[UnknownHostException] BSSSipSendUdpPacket(String sIp, int iPort, byte[] data, int dataSize)"); //System.err.println(uhe); LogUtil.errorLogInfo("", TAG, uhe); SIPStack.exceptionCountAtCurrentCall++; } catch (java.net.SocketException she) { Log.e(TAG, "[SocketException] Cause: " + she.getCause()); Log.e(TAG, "[SocketException] Reason: " + she.getMessage()); if (she.getMessage().indexOf("ENETUNREACH") >= 0 || she.getMessage().indexOf("Network is unreachable") >= 0) { SIPStack.networkStatus = SIPStack.SIP_NETIF_UNREACHABLE; Log.e(TAG, "[BSSSipSendUdpPacket] networkStatus was set to SIP_NETIF_UNREACHABLE"); } //System.err.println(she); LogUtil.errorLogInfo("", TAG, she); try { Log.e(TAG, "!!! Socket is invalid, renew."); theSocket = new DatagramSocket(SIPStack.SIP_SIGNAL_PORT); } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); } catch (Exception e) { Log.e(TAG, "[Exception] !!! Socket is invalid, renew."); } SIPStack.exceptionCountAtCurrentCall++; } catch (IOException ie) { Log.e(TAG, "[IOException] BSSSipSendUdpPacket(String sIp, int iPort, byte[] data, int dataSize)"); //System.err.println(ie); LogUtil.errorLogInfo("", TAG, ie); SIPStack.exceptionCountAtCurrentCall++; } catch (Exception e) { // when call OnNetworkException error processing Log.e(TAG, "[Exception] BSSSipSendUdpPacket(String sIp, int iPort, byte[] data, int dataSize)"); Log.e(TAG, "!!!BSSSipSendUdpPacket Exception occurred. : " + sent); //System.err.println(e); LogUtil.errorLogInfo("", TAG, e); return -1; } return sent; } } class SIGNALCTRLThread extends Thread { @Override public void run() { Log.d(TAG, "[SIGNALCTRLThread.run]"); while (cmcore.SIGNALCTRLRunning == true) { try { Thread.sleep(SIPStack.SIPCTRL_INTERVAL); if (cmcore.SIGNALCTRLThread == null) { break; } if (cmcore.SIGNALCTRLThread.isInterrupted()) { break; } if (SIPStack.networkStatus != SIPStack.SIP_NETIF_AVAILABLE) { if (SIPStack.networkStatus == SIPStack.SIP_NETIF_UNREACHABLE) { // SERVICE MESSAGE NEEDED updateDialerStatus("NETWORK UNREACHABLE.", true); } else if (SIPStack.networkStatus == SIPStack.SIP_NETIF_UNAVAILABLE) { // SERVICE MESSAGE NEEDED updateDialerStatus("NETWORK not ready.", true); } if (SIPStack.networkStatus == SIPStack.SIP_NETIF_UNAVAILABLE || SIPStack.networkStatus == SIPStack.SIP_NETIF_UNREACHABLE) { if (connectivityManager != null && connectivityManager.getActiveNetworkInfo() != null) { NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo(); switch (activeNetwork.getType()) { case ConnectivityManager.TYPE_WIMAX: // 4g 망 체크 if (SIPStack.isInternetWiMax == false && SIPStack.bBackgroundRunning) SIPStack.bShutdownApplication = true; SIPStack.isInternetWiMax = true; SIPStack.isInternetWiFi = false; SIPStack.isInternetMobile = false; SIPStack.PRIMARY_CODEC_AUDIO = SIPStack.SIP_CODEC_G711U; break; case ConnectivityManager.TYPE_WIFI: // wifi망 체크 if (SIPStack.isInternetWiFi == false && SIPStack.bBackgroundRunning) SIPStack.bShutdownApplication = true; SIPStack.isInternetWiMax = false; SIPStack.isInternetWiFi = true; SIPStack.isInternetMobile = false; SIPStack.PRIMARY_CODEC_AUDIO = SIPStack.SIP_CODEC_G711U; break; case ConnectivityManager.TYPE_MOBILE: // 3g 망 체크 if (SIPStack.isInternetMobile == false && SIPStack.bBackgroundRunning) SIPStack.bShutdownApplication = true; SIPStack.isInternetWiMax = false; //false; SIPStack.isInternetWiFi = false; SIPStack.isInternetMobile = true; SIPStack.PRIMARY_CODEC_AUDIO = SIPStack.SIP_CODEC_G711U; break; } } cmcore.netcheckIntervalTimer = new Date(); try { String host = SIPController.getSHVE140SLocalIpAddress(); cmcore.action_net_1(host); } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); } catch (Exception e) { Log.e(TAG, "[Exception] String host = SIPController.getSHVE140SLocalIpAddress();"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } } continue; } if (SIPStack.bDirectCall == false && cmcore.regState != SIPStack.SIP_REGSTATE_REGISTERED) { if (true == cmcore.action_net_0()) sendRegister(); } // REGIST CONTROL if (cmcore.ctrlIndex == 0) { if (SIPStack.bShutdownApplication) { if (SIPStack.bDirectCall == false) { sendUNRegister(); } SIPStack.bShutdownApplication = false; // SERVICE MESSAGE NEEDED dialerShutdownApplication(); } if (SIPStack.bDirectCall == false) { SIPCTRLRegister(); } } else if (cmcore.ctrlIndex == 1) { // CALL CONTROL if (SIPStack.bVibrating == true) { if (!(SIPController.sipCall != null && SIPController.sipCall.flag == true && SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_OFFERRED)) { // SERVICE MESSAGE NEEDED dialerVibrator(false); } } if (SIPController.sipCall != null && SIPController.sipCall.flag == true && SIPController.sipCall.bResponsebackgroundcall == true && SIPController.sipCall.bResponsebackgroundcallReady == true && SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_OFFERRED) { if (SIPStun.bBlackcallBackgroundMode == true) { if (SIPController.sipCall.bResponsebackgroundcallReady == true) { Date currentTime = new Date(); long durationMilliSeconds = Math.abs(currentTime.getTime() - SIPController.sipCall.responsebackgroundcallTimer.getTime()); if (durationMilliSeconds > 1000) { Log.i(TAG, "MILL TIME : " + durationMilliSeconds); SIPController.sipCall.responsebackgroundcallTimer = new Date(); SIPController.sipCall.bResponsebackgroundcall = false; SIPController.sipCall.bResponsebackgroundcallReady = false; // SERVICE MESSAGE NEEDED dialerNotifyIncomingCall(SIPController.sipCall.dnis, SIPController.sipCall.dnis + "@" + SIPController.sipCall.remoteIp + ":" + SIPController.sipCall.remotePort); if (SIPStack.bDirectCall == true) { dialerVideoSet(true); } } } } else { Date currentTime = new Date(); long durationSeconds = Math.abs((currentTime.getTime() - SIPController.sipCall.responsebackgroundcallTimer.getTime()) / 1000); if (durationSeconds > 0) { SIPController.sipCall.bResponsebackgroundcall = false; // SERVICE MESSAGE NEEDED dialerNotifyIncomingCall(SIPController.sipCall.dnis, SIPController.sipCall.dnis + "@" + SIPController.sipCall.remoteIp + ":" + SIPController.sipCall.remotePort); } } } if (SIPController.sipCall != null && SIPController.sipCall.flag == true && SIPController.sipCall.bCancelRequest) { callTerminate(); SIPController.sipCall.bCancelRequest = false; } else if (SIPController.sipCall != null && SIPController.sipCall.flag == true && SIPController.sipCall.bRejectRequest) { if (SIPController.sipCall.remoteSdp != null && SIPController.sipCall.remoteSdp.flag == true && SIPController.audioRTPManager != null) { if (SIPController.sipCall.remoteSdp.audioM != null && SIPController.sipCall.remoteSdp.audioM.flag == true) { if (SIPController.sipCall.sdp != null && SIPController.sipCall.sdp.audioM != null && SIPController.audioRTPManager != null) { SIPController.audioRTPManager.RTPEnd(1); // SERVICE MESSAGE NEEDED if (SIPStack.bDirectCall == true) { dialerVideoSet(false); } } } } SIPController.sipCall.bRejectRequest = false; SIPController.sipCall.bCancelRequest = true; } else if (SIPController.sipCall != null && SIPController.sipCall.bNewcallRequest) { if (SIPController.sipCall.bDirectcall == true) { SIPController.sipCall.bNewcallRequest = false; // Log.d(TAG, "[SIGNALCTRLThread] SIPController.bMobileCall [" + SIPController.bMobileCall + "]"); directcallActivate(SIPController.sipCall.number, SIPController.bMobileCall); } else if (cmcore.regState == SIPStack.SIP_REGSTATE_REGISTERED) { SIPController.sipCall.bNewcallRequest = false; callActivate(SIPController.sipCall.number); } } else if (SIPController.sipCall != null && SIPController.sipCall.bUpdateRequest) { if (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_CONNECTED) { sendHold(); } SIPController.sipCall.bUpdateRequest = false; } else if (SIPController.sipCall != null && SIPController.sipCall.flag == true && SIPController.forward.bForward == true && SIPController.sipCall.bForwardRequest == true) { SIPController.sipCall.bForwardRequest = false; if (SIPController.sipCall.remoteSdp != null && SIPController.sipCall.remoteSdp.flag == true && SIPController.audioRTPManager != null) { if (SIPController.sipCall.remoteSdp.audioM != null && SIPController.sipCall.remoteSdp.audioM.flag == true) { if (SIPController.sipCall.sdp != null && SIPController.sipCall.sdp.audioM != null && SIPController.audioRTPManager != null) { SIPController.audioRTPManager.RTPEnd(2); // SERVICE MESSAGE NEEDED if (SIPStack.bDirectCall == true) { dialerVideoSet(false); } } } } redirectTerminate(SIPController.forward.contact); cancelCallForwardToStun(); } else { SIPCTRLCall(); } } if (cmcore.ctrlIndex == 0) cmcore.ctrlIndex = 1; else cmcore.ctrlIndex = 0; } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); } catch (Exception e) { Log.e(TAG, "[Exception] SIGNALCTRLThread.while(cmcore.SIGNALCTRLRunning)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } } cmcore.SIGNALCTRLRunning = false; cmcore.SIGNALCTRLThread = null; } // run() } class CTRLTimerTask extends TimerTask { public void run() { if (cmcore.SIGNALCTRLTimer == null) { Log.e(TAG, "cmcore.SIGNALCTRLTimer is null!! "); return; } Log.w(TAG, "[CTRLTimerTask]"); if (SIPStack.networkStatus != SIPStack.SIP_NETIF_AVAILABLE) { if (SIPStack.networkStatus == SIPStack.SIP_NETIF_UNREACHABLE) { // SERVICE MESSAGE NEEDED updateDialerStatus("NETWORK UNREACHABLE.", true); } else if (SIPStack.networkStatus == SIPStack.SIP_NETIF_UNAVAILABLE) { //SERVICE MESSAGE NEEDED updateDialerStatus("NETWORK not ready.", true); } if (SIPStack.networkStatus == SIPStack.SIP_NETIF_UNAVAILABLE || SIPStack.networkStatus == SIPStack.SIP_NETIF_UNREACHABLE) { if (connectivityManager != null && connectivityManager.getActiveNetworkInfo() != null) { NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo(); switch (activeNetwork.getType()) { case ConnectivityManager.TYPE_WIMAX: // 4g 망 체크 if (SIPStack.isInternetWiMax == false && SIPStack.bBackgroundRunning) SIPStack.bShutdownApplication = true; SIPStack.isInternetWiMax = true; SIPStack.isInternetWiFi = false; SIPStack.isInternetMobile = false; SIPStack.PRIMARY_CODEC_AUDIO = SIPStack.SIP_CODEC_G711U; break; case ConnectivityManager.TYPE_WIFI: // wifi망 체크 if (SIPStack.isInternetWiFi == false && SIPStack.bBackgroundRunning) SIPStack.bShutdownApplication = true; SIPStack.isInternetWiMax = false; SIPStack.isInternetWiFi = true; SIPStack.isInternetMobile = false; SIPStack.PRIMARY_CODEC_AUDIO = SIPStack.SIP_CODEC_G711U; break; case ConnectivityManager.TYPE_MOBILE: // 3g 망 체크 if (SIPStack.isInternetMobile == false && SIPStack.bBackgroundRunning) SIPStack.bShutdownApplication = true; SIPStack.isInternetWiMax = false; // false; SIPStack.isInternetWiFi = false; SIPStack.isInternetMobile = true; SIPStack.PRIMARY_CODEC_AUDIO = SIPStack.SIP_CODEC_G711U; break; } } cmcore.netcheckIntervalTimer = new Date(); try { String host = SIPController.getSHVE140SLocalIpAddress(); cmcore.action_net_1(host); } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); } catch (Exception e) { Log.e(TAG, "[Exception] String host = SIPController.getSHVE140SLocalIpAddress()"); } } return; } if (SIPStack.bDirectCall == false && cmcore.regState != SIPStack.SIP_REGSTATE_REGISTERED) { if (true == cmcore.action_net_0()) sendRegister(); } // REGIST CONTROL if (cmcore.ctrlIndex == 0) { if (SIPStack.bShutdownApplication) { if (SIPStack.bDirectCall == false) sendUNRegister(); SIPStack.bShutdownApplication = false; // SERVICE MESSAGE NEEDED dialerShutdownApplication(); } if (SIPStack.bDirectCall == false) SIPCTRLRegister(); } else if (cmcore.ctrlIndex == 1) { // CALL CONTROL if (SIPStack.bVibrating == true) { if (!(SIPController.sipCall != null && SIPController.sipCall.flag == true && SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_OFFERRED)) { // SERVICE MESSAGE NEEDED dialerVibrator(false); } } if (SIPController.sipCall != null && SIPController.sipCall.flag == true && SIPController.sipCall.bResponsebackgroundcall == true && SIPController.sipCall.bResponsebackgroundcallReady == true && SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_OFFERRED) { if (SIPStun.bBlackcallBackgroundMode == true) { if (SIPController.sipCall.bResponsebackgroundcallReady == true) { Date currentTime = new Date(); int durationMilliSeconds = (int) (currentTime.getTime() - SIPController.sipCall.responsebackgroundcallTimer.getTime()); if (durationMilliSeconds > 1000) { Log.i(TAG, "MILL TIME : " + durationMilliSeconds); SIPController.sipCall.responsebackgroundcallTimer = new Date(); SIPController.sipCall.bResponsebackgroundcall = false; SIPController.sipCall.bResponsebackgroundcallReady = false; // SERVICE MESSAGE NEEDED dialerNotifyIncomingCall(SIPController.sipCall.dnis, SIPController.sipCall.dnis + "@" + SIPController.sipCall.remoteIp + ":" + SIPController.sipCall.remotePort); if (SIPStack.bDirectCall == true) { dialerVideoSet(true); } } } } else { Date currentTime = new Date(); int durationSeconds = (int) (currentTime.getTime() - SIPController.sipCall.responsebackgroundcallTimer.getTime()) / 1000; if (durationSeconds > 0) { SIPController.sipCall.bResponsebackgroundcall = false; // SERVICE MESSAGE NEEDED dialerNotifyIncomingCall(SIPController.sipCall.dnis, SIPController.sipCall.dnis + "@" + SIPController.sipCall.remoteIp + ":" + SIPController.sipCall.remotePort); } } } if (SIPController.sipCall != null && SIPController.sipCall.flag == true && SIPController.sipCall.bCancelRequest) { callTerminate(); SIPController.sipCall.bCancelRequest = false; } else if (SIPController.sipCall != null && SIPController.sipCall.flag == true && SIPController.sipCall.bRejectRequest) { if (SIPController.sipCall.remoteSdp != null && SIPController.sipCall.remoteSdp.flag == true && SIPController.audioRTPManager != null) { if (SIPController.sipCall.remoteSdp.audioM != null && SIPController.sipCall.remoteSdp.audioM.flag == true) { if (SIPController.sipCall.sdp != null && SIPController.sipCall.sdp.audioM != null && SIPController.audioRTPManager != null) { SIPController.audioRTPManager.RTPEnd(3); // SERVICE MESSAGE NEEDED if (SIPStack.bDirectCall == true) dialerVideoSet(false); } } } SIPController.sipCall.bRejectRequest = false; SIPController.sipCall.bCancelRequest = true; } else if (SIPController.sipCall != null && SIPController.sipCall.bNewcallRequest) { if (SIPController.sipCall.bDirectcall == true) { SIPController.sipCall.bNewcallRequest = false; // Log.d(TAG, "[CTRLTimerTask] SIPController.bMobileCall [" + SIPController.bMobileCall + "]"); directcallActivate(SIPController.sipCall.number, SIPController.bMobileCall); } else if (cmcore.regState == SIPStack.SIP_REGSTATE_REGISTERED) { SIPController.sipCall.bNewcallRequest = false; callActivate(SIPController.sipCall.number); } } else if (SIPController.sipCall != null && SIPController.sipCall.bUpdateRequest) { if (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_CONNECTED) { sendHold(); } SIPController.sipCall.bUpdateRequest = false; } else if (SIPController.sipCall != null && SIPController.sipCall.flag == true && SIPController.forward.bForward == true && SIPController.sipCall.bForwardRequest == true) { SIPController.sipCall.bForwardRequest = false; if (SIPController.sipCall.remoteSdp != null && SIPController.sipCall.remoteSdp.flag == true && SIPController.audioRTPManager != null) { if (SIPController.sipCall.remoteSdp.audioM != null && SIPController.sipCall.remoteSdp.audioM.flag == true) { if (SIPController.sipCall.sdp != null && SIPController.sipCall.sdp.audioM != null && SIPController.audioRTPManager != null) { SIPController.audioRTPManager.RTPEnd(4); // SERVICE MESSAGE NEEDED if (SIPStack.bDirectCall == true) dialerVideoSet(false); } } } redirectTerminate(SIPController.forward.contact); SIPController.forward.contact = ""; } else { SIPCTRLCall(); } } if (cmcore.ctrlIndex == 0) cmcore.ctrlIndex = 1; else cmcore.ctrlIndex = 0; } } public void initializeCm(byte[] byteAddress, byte[] byteLocalip, int localport, byte[] byteServerip, int serverport, byte[] byteServerdomain, byte[] byteId, byte[] byteCid, byte[] byteAuthid, byte[] byteAuthpassword) { SIPController.sipCall = new SIPCall(); // Multicall part SIPController.pendingCall = new SIPCall(true); if (connectivityManager != null && connectivityManager.getActiveNetworkInfo() != null) { NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo(); switch (activeNetwork.getType()) { case ConnectivityManager.TYPE_WIMAX: // 4g 망 체크 SIPStack.isInternetWiMax = true; SIPStack.isInternetWiFi = false; SIPStack.isInternetMobile = false; SIPStack.PRIMARY_CODEC_AUDIO = SIPStack.SIP_CODEC_G711U; break; case ConnectivityManager.TYPE_WIFI: // wifi망 체크 SIPStack.isInternetWiMax = false; SIPStack.isInternetWiFi = true; SIPStack.isInternetMobile = false; SIPStack.PRIMARY_CODEC_AUDIO = SIPStack.SIP_CODEC_G711U; break; case ConnectivityManager.TYPE_MOBILE: // 3g 망 체크 SIPStack.isInternetWiMax = false;//false; SIPStack.isInternetWiFi = false; SIPStack.isInternetMobile = true; SIPStack.PRIMARY_CODEC_AUDIO = SIPStack.SIP_CODEC_G711U; break; } } cmcore.action_0(byteLocalip, localport, byteServerip, serverport, byteServerdomain, byteId, byteCid, byteAuthid, byteAuthpassword); if (SIPStack.bUseCtrlTimer == true) { cmcore.SIGNALCTRLTimer.scheduleAtFixedRate(new CTRLTimerTask(), 0, SIPStack.SIPCTRL_INTERVAL); } else { cmcore.SIGNALCTRLThread = new SIGNALCTRLThread(); if (cmcore.SIGNALCTRLThread != null) { cmcore.SIGNALCTRLRunning = true; cmcore.SIGNALCTRLThread.start(); } } if (connectivityManager != null && connectivityManager.getActiveNetworkInfo() != null) { NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo(); switch (activeNetwork.getType()) { case ConnectivityManager.TYPE_WIMAX: // 4g 망 체크 SIPStack.isInternetWiMax = true; SIPStack.isInternetWiFi = false; SIPStack.isInternetMobile = false; SIPStack.PRIMARY_CODEC_AUDIO = SIPStack.SIP_CODEC_G711U; break; case ConnectivityManager.TYPE_WIFI: // wifi망 체크 SIPStack.isInternetWiMax = false; SIPStack.isInternetWiFi = true; SIPStack.isInternetMobile = false; SIPStack.PRIMARY_CODEC_AUDIO = SIPStack.SIP_CODEC_G711U; break; case ConnectivityManager.TYPE_MOBILE: // 3g 망 체크 SIPStack.isInternetWiMax = false;//false; SIPStack.isInternetWiFi = false; SIPStack.isInternetMobile = true; SIPStack.PRIMARY_CODEC_AUDIO = SIPStack.SIP_CODEC_G711U; break; } } cmcore.netcheckIntervalTimer = new Date(); try { String host = SIPController.getSHVE140SLocalIpAddress(); if (true == cmcore.action_net_2(host)) { sendRegister(); } } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); } catch (Exception e) { Log.e(TAG, "[Exception] String host = SIPController.getSHVE140SLocalIpAddress()"); } } // SipSignalReceiver() public void initializeCm(byte[] byteAddress, byte[] byteLocalip, int localport, String strServerHost, int serverport, String strServerDomain, byte[] byteId, byte[] byteCid, byte[] byteAuthid, byte[] byteAuthpassword) { SIPController.sipCall = new SIPCall(); // Multicall part SIPController.pendingCall = new SIPCall(true); cmcore.action_1(byteAddress, byteLocalip, localport, strServerHost, serverport, strServerDomain, byteId, byteCid, byteAuthid, byteAuthpassword); if (SIPStack.bUseCtrlTimer == true) { cmcore.SIGNALCTRLTimer.scheduleAtFixedRate(new CTRLTimerTask(), 0, SIPStack.SIPCTRL_INTERVAL); } else { cmcore.SIGNALCTRLThread = new SIGNALCTRLThread(); if (cmcore.SIGNALCTRLThread != null) { cmcore.SIGNALCTRLRunning = true; cmcore.SIGNALCTRLThread.start(); } } } public void resumeCm(byte[] byteAddress, byte[] byteLocalip, int localport, String strServerHost, int serverport, String strServerDomain, byte[] byteId, byte[] byteCid, byte[] byteAuthid, byte[] byteAuthpassword) { SIPStack.ipdns.bSipAddressResolved = true; SIPStack.ipdns.sipTry = 0; // SERVICE MESSAGE NEEDED if (SIPStack.bDirectCall == false) dialerRegistStatus(SIPStack.bNetworkActive); }//SipSignalReceiver() public void resetConfiguration(String strId, String strCid, String strAuthid, String strAuthpassword, String strServerHost, String strServerDomain, int serverport) { // Set server information cmcore.action_2(strId, strCid, strAuthid, strAuthpassword, strServerHost, strServerDomain, serverport); sendRegister(); } public void SIPCTRLRegister() { if (SIPStack.ipdns.bSipAddressResolved == false) { return; } Date currentTime = new Date(); int duration = (int) (currentTime.getTime() - cmcore.regTime.getTime()) / 1000; int startduration = (int) (currentTime.getTime() - SIPStack.bootTime.getTime()) / 1000; if (cmcore.regState == SIPStack.SIP_REGSTATE_IDLE && startduration > 0 && startduration < 10 && mSIPSignalReceiver != null && mSIPSignalReceiver.bReady == true) { byte[] buffer = cmcore.message.getBytes(); if (cmcore.message.length() > 0) { if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, cmcore.message); cmcore.regState = SIPStack.SIP_REGSTATE_REGISTERING; int repeatSendCount = 0; while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) { if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(cmcore.serverIp, cmcore.serverPort, buffer, buffer.length)) { break; } repeatSendCount++; } cmcore.regTime = new Date(); } } else if (decideRegister() == true && cmcore.regState != SIPStack.SIP_REGSTATE_REGISTERING && cmcore.regState != SIPStack.SIP_REGSTATE_AUTHORIZING && cmcore.regState != SIPStack.SIP_REGSTATE_UNAVAILABLE) { cmcore.regState = SIPStack.SIP_REGSTATE_REGISTERING; sendRegister(); } else if (duration >= SIPStack.CS_TIMEOUT_RESPONSE && cmcore.regState == SIPStack.SIP_REGSTATE_REGISTERING) { // 30 cmcore.regState = SIPStack.SIP_REGSTATE_REGISTERING; sendRegister(); } return; } public void SIPCTRLCall() { Date currentTime = new Date(); long durationMilli = Math.abs(currentTime.getTime() - cmcore.ctrlIntervalTimer.getTime()); long durationRegistStatus = Math.abs((currentTime.getTime() - cmcore.registStatusTimer.getTime()) / 1000); if (durationMilli < 500) { return; } else { cmcore.ctrlIntervalTimer = new Date(); durationMilli = Math.abs((currentTime.getTime() - cmcore.netcheckIntervalTimer.getTime()) / 1000); if (durationMilli > SIPStack.NETWORKIF_CHECK_TIME) { if (connectivityManager != null && connectivityManager.getActiveNetworkInfo() != null) { NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo(); switch (activeNetwork.getType()) { case ConnectivityManager.TYPE_WIMAX: // 4g 망 체크 if (SIPStack.isInternetWiMax == false && SIPStack.bBackgroundRunning) SIPStack.bShutdownApplication = true; SIPStack.isInternetWiMax = true; SIPStack.isInternetWiFi = false; SIPStack.isInternetMobile = false; SIPStack.PRIMARY_CODEC_AUDIO = SIPStack.SIP_CODEC_G711U; break; case ConnectivityManager.TYPE_WIFI: // wifi망 체크 if (SIPStack.isInternetWiFi == false && SIPStack.bBackgroundRunning) SIPStack.bShutdownApplication = true; SIPStack.isInternetWiMax = false; SIPStack.isInternetWiFi = true; SIPStack.isInternetMobile = false; SIPStack.PRIMARY_CODEC_AUDIO = SIPStack.SIP_CODEC_G711U; break; case ConnectivityManager.TYPE_MOBILE: // 3g 망 체크 if (SIPStack.isInternetMobile == false && SIPStack.bBackgroundRunning) SIPStack.bShutdownApplication = true; SIPStack.isInternetWiMax = false; // false; SIPStack.isInternetWiFi = false; SIPStack.isInternetMobile = true; SIPStack.PRIMARY_CODEC_AUDIO = SIPStack.SIP_CODEC_G711U; break; } } cmcore.netcheckIntervalTimer = new Date(); try { String host = SIPController.getSHVE140SLocalIpAddress(); if (true == cmcore.action_net_3(host)) { sendUNRegister(cmcore.previfIp, cmcore.previfPort); cmcore.regState = SIPStack.SIP_REGSTATE_UNREGISTERING; } } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); } catch (Exception e) { Log.e(TAG, "[Exception] String host = SIPController.getSHVE140SLocalIpAddress()"); } } } if (durationRegistStatus > 0) { if ((SIPStack.bIntraffic || SIPStack.bOuttraffic) && SIPController.sipCall != null && SIPController.sipCall.flag == false) { if (cmcore.regState == SIPStack.SIP_REGSTATE_REGISTERED) { // SERVICE MESSAGE NEEDED if (SIPStack.bDirectCall == false) dialerRegistStatus(true); } else { // SERVICE MESSAGE NEEDED if (SIPStack.bDirectCall == false) dialerRegistStatus(false); } cmcore.registStatusTimer = new Date(); } else if (durationRegistStatus > 3) { if (cmcore.regState == SIPStack.SIP_REGSTATE_REGISTERED) { // SERVICE MESSAGE NEEDED if (SIPStack.bDirectCall == false) dialerRegistStatus(true); } else { // SERVICE MESSAGE NEEDED if (SIPStack.bDirectCall == false) dialerRegistStatus(false); } cmcore.registStatusTimer = new Date(); } } // Multicall call state processing if (SIPController.pendingCall != null && SIPController.pendingCall.flag == true) { // Log.d(TAG, "[SIPCTRLCall]"); if (SIPController.pendingCall.callTime_TI != null) SIPController.pendingCall.expiresTI = (int) (currentTime.getTime() - SIPController.pendingCall.callTime_TI.getTime()) / 1000; if (SIPController.pendingCall.callTime_T0 != null) SIPController.pendingCall.expiresT0 = (int) (currentTime.getTime() - SIPController.pendingCall.callTime_T0.getTime()) / 1000; if (SIPController.pendingCall.callTime_T00 != null) SIPController.pendingCall.expiresT00 = (int) (currentTime.getTime() - SIPController.pendingCall.callTime_T00.getTime()) / 1000; if (SIPController.pendingCall.callTime_T1 != null) SIPController.pendingCall.expiresT1 = (int) (currentTime.getTime() - SIPController.pendingCall.callTime_T1.getTime()) / 1000; if (SIPController.pendingCall.callTime_T2 != null) SIPController.pendingCall.expiresT2 = (int) (currentTime.getTime() - SIPController.pendingCall.callTime_T2.getTime()) / 1000; if (SIPController.pendingCall.callTime_T3 != null) SIPController.pendingCall.expiresT3 = (int) (currentTime.getTime() - SIPController.pendingCall.callTime_T3.getTime()) / 1000; if (SIPController.pendingCall.callTime_T4 != null) SIPController.pendingCall.expiresT4 = (int) (currentTime.getTime() - SIPController.pendingCall.callTime_T4.getTime()) / 1000; if (SIPController.pendingCall.callTime_T5 != null) SIPController.pendingCall.expiresT5 = (int) (currentTime.getTime() - SIPController.pendingCall.callTime_T5.getTime()) / 1000; if (SIPController.pendingCall.callTime_T6 != null) SIPController.pendingCall.expiresT6 = (int) (currentTime.getTime() - SIPController.pendingCall.callTime_T6.getTime()) / 1000; if (SIPController.pendingCall.callTime_T7 != null) SIPController.pendingCall.expiresT7 = (int) (currentTime.getTime() - SIPController.pendingCall.callTime_T7.getTime()) / 1000; if (SIPController.pendingCall.callTime_T8 != null) SIPController.pendingCall.expiresT8 = (int) (currentTime.getTime() - SIPController.pendingCall.callTime_T8.getTime()) / 1000; if (SIPController.pendingCall.callTime_T9 != null) SIPController.pendingCall.expiresT9 = (int) (currentTime.getTime() - SIPController.pendingCall.callTime_T9.getTime());//milli seconds // Log.d(TAG, "[SIPCTRLCall] SIPController.sipCall.callState [" + SIPController.sipCall.callState + "]"); if (SIPController.pendingCall.bAsMaster == true) { // CONNECTED TIMEOUT PROCESSING SIPController.sipCall.exceptionT4(); // CONFERENCE CALL CHECK NEEDED if (SIPController.audioRTPManager != null) SIPController.audioRTPManager.RTPEnd(5); if (SIPStack.bDirectCall == true) { // SERVICE MESSAGE NEEDED dialerVideoSet(false); } sendBye(); SIPController.sipCall.resetCall(); SIPController.sipCall = SIPController.pendingCall; SIPController.pendingCall = new SIPCall(); // for temporary if (SIPController.sipCall.callDirection == SIPStack.SIP_CALLDIRECTION_IN && SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_OFFERRED) { Log.i(TAG, "call exchange : " + SIPController.sipCall.remoteIp); BSSVideo.bProgressvideooffer = true; sendProgressingwithbody(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort); if (SIPController.sipCall.callDirection == SIPStack.SIP_CALLDIRECTION_IN && SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_OFFERRED) { // Phone status set // SERVICE MESSAGE NEEDED updateDialerStatus("Incoming call accept.", false); directsendAccept(false); // 방문객 원격통화로 인하여 CallOwner (boolean) 파라미터 추가 return; } } return; } else { if (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_TERMINATING || SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_DISCONNECTING || SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_IDLE) { // CONNECTED TIMEOUT PROCESSING SIPController.sipCall.exceptionT4(); // CONFERENCE CALL CHECK NEEDED if (SIPController.audioRTPManager != null) SIPController.audioRTPManager.RTPEnd(6); if (SIPStack.bDirectCall == true) { // SERVICE MESSAGE NEEDED dialerVideoSet(false); } sendBye(); SIPController.sipCall.resetCall(); SIPController.sipCall = SIPController.pendingCall; SIPController.pendingCall = new SIPCall(); // for temporary if (SIPController.sipCall.callDirection == SIPStack.SIP_CALLDIRECTION_IN && SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_OFFERRED) { Log.i(TAG, "call exchange : " + SIPController.sipCall.remoteIp); BSSVideo.bProgressvideooffer = true; sendProgressingwithbody(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort); } return; } } if (SIPController.pendingCall.bRejectRequest == true) { if (SIPController.bMulticallBusyResponse == true) rejectPendingCall(486); else rejectPendingCall(480); } else if (SIPController.pendingCall.callState == SIPStack.SIP_CALLSTATE_IDLE) { if (SIPController.pendingCall.expiresTI > SIPStack.CS_TIMEOUT_TI) { SIPController.pendingCall.resetCall(); } } else if (SIPController.pendingCall.callState == SIPStack.SIP_CALLSTATE_DISCONNECTING) { if (SIPController.pendingCall.expiresT5 > SIPStack.CS_TIMEOUT_T5) { // DISCONNECTING TIMEOUT PROCESSING SIPController.pendingCall.resetCall(); } } else if (SIPController.pendingCall.callState == SIPStack.SIP_CALLSTATE_TERMINATING) { if (SIPController.pendingCall.expiresT6 > SIPStack.CS_TIMEOUT_T6) { SIPController.pendingCall.resetCall(); } } else if (SIPController.pendingCall.callState == SIPStack.SIP_CALLSTATE_OFFERRED) { if (SIPController.pendingCall.expiresT7 > SIPStack.CS_TIMEOUT_T7) { SIPController.pendingCall.exceptionT7(); rejectPendingCall(408); } } else if (SIPController.pendingCall.callState == SIPStack.SIP_CALLSTATE_CANCELLING) { if (SIPController.pendingCall.expiresT8 > SIPStack.CS_TIMEOUT_T8) { SIPController.pendingCall.resetCall(); } } else if (SIPController.pendingCall.callState == SIPStack.SIP_CALLSTATE_RECANCELLING) { if (SIPController.pendingCall.expiresT8 > SIPStack.CS_TIMEOUT_T8) { SIPController.pendingCall.resetCall(); } } else if (SIPController.pendingCall.callState == SIPStack.SIP_CALLSTATE_CANCELREMOTEACCEPTED) { if (SIPController.pendingCall.expiresT8 > SIPStack.CS_TIMEOUT_T8) { SIPController.pendingCall.resetCall(); } } else if (SIPController.pendingCall.callState == SIPStack.SIP_CALLSTATE_CANCELLED) { if (SIPController.pendingCall.expiresT8 > SIPStack.CS_TIMEOUT_T8) { SIPController.pendingCall.resetCall(); } } } if (SIPController.sipCall == null || SIPController.sipCall.flag == false) { if (cmcore.regState == SIPStack.SIP_REGSTATE_REGISTERED) { // SERVICE MESSAGE NEEDED updateDialerStatus("Ready.", cmcore.bRequestReadySet); } else { // SERVICE MESSAGE NEEDED if (SIPStack.bDirectCall == false) updateDialerStatus("Not registered.", cmcore.bRequestReadySet); } if (cmcore.bRequestReadySet == true) { cmcore.bRequestReadySet = false; } return; } if (SIPController.sipCall != null && SIPController.sipCall.flag == true) { if (SIPController.sipCall.callTime_TI != null) SIPController.sipCall.expiresTI = (int) (currentTime.getTime() - SIPController.sipCall.callTime_TI.getTime()) / 1000; if (SIPController.sipCall.callTime_T0 != null) SIPController.sipCall.expiresT0 = (int) (currentTime.getTime() - SIPController.sipCall.callTime_T0.getTime()) / 1000; if (SIPController.sipCall.callTime_T00 != null) SIPController.sipCall.expiresT00 = (int) (currentTime.getTime() - SIPController.sipCall.callTime_T00.getTime()) / 1000; if (SIPController.sipCall.callTime_T1 != null) SIPController.sipCall.expiresT1 = (int) (currentTime.getTime() - SIPController.sipCall.callTime_T1.getTime()) / 1000; if (SIPController.sipCall.callTime_T2 != null) SIPController.sipCall.expiresT2 = (int) (currentTime.getTime() - SIPController.sipCall.callTime_T2.getTime()) / 1000; if (SIPController.sipCall.callTime_T3 != null) SIPController.sipCall.expiresT3 = (int) (currentTime.getTime() - SIPController.sipCall.callTime_T3.getTime()) / 1000; if (SIPController.sipCall.callTime_T4 != null) SIPController.sipCall.expiresT4 = (int) (currentTime.getTime() - SIPController.sipCall.callTime_T4.getTime()) / 1000; if (SIPController.sipCall.callTime_T5 != null) SIPController.sipCall.expiresT5 = (int) (currentTime.getTime() - SIPController.sipCall.callTime_T5.getTime()) / 1000; if (SIPController.sipCall.callTime_T6 != null) SIPController.sipCall.expiresT6 = (int) (currentTime.getTime() - SIPController.sipCall.callTime_T6.getTime()) / 1000; if (SIPController.sipCall.callTime_T7 != null) SIPController.sipCall.expiresT7 = (int) (currentTime.getTime() - SIPController.sipCall.callTime_T7.getTime()) / 1000; if (SIPController.sipCall.callTime_T8 != null) SIPController.sipCall.expiresT8 = (int) (currentTime.getTime() - SIPController.sipCall.callTime_T8.getTime()) / 1000; if (SIPController.sipCall.callTime_T9 != null) SIPController.sipCall.expiresT9 = (int) (currentTime.getTime() - SIPController.sipCall.callTime_T9.getTime()); if (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_IDLE) { if (SIPController.sipCall.expiresTI > SIPStack.CS_TIMEOUT_TI) { // IDLE TIMEOUT PROCESSING SIPController.sipCall.exceptionTI(); //SERVICE MESSAGE NEEDED updateDialerStatus("Ready.", true); } } else if (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_INVITING) { if ((SIPStack.ventureCall == true || SIPStack.bDirectCall == true) && SIPController.sipCall.expiresT00 > 3) { sendReInvite(); SIPStack.ventureCall = false; } else if (SIPController.sipCall.expiresT00 > SIPStack.CS_TIMEOUT_T00) { //INVITING REPEAT TIMEOUT PROCESSING sendReInvite(); SIPStack.ventureCall = false; } if (SIPController.sipCall.expiresT0 > SIPStack.CS_TIMEOUT_T000) { Log.i(TAG, " " + SIPController.sipCall.expiresT0); sendCancel(); } } else if (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_PROCEEDING) { if (SIPController.sipCall.expiresT1 > SIPStack.CS_TIMEOUT_T1) { //PROCEEDING TIMEOUT PROCESSING SIPController.sipCall.exceptionT1(); // CONFERENCE CALL CHECK NEEDED if (SIPController.audioRTPManager != null) SIPController.audioRTPManager.RTPEnd(7); if (SIPStack.bDirectCall == true) { //SERVICE MESSAGE NEEDED dialerVideoSet(false); } sendCancel(); } } else if (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_PROGRESSING) { if (SIPController.sipCall.expiresT2 > SIPStack.CS_TIMEOUT_T2) { //PROGRESSING TIMEOUT PROCESSING SIPController.sipCall.exceptionT2(); // CONFERENCE CALL CHECK NEEDED if (SIPController.audioRTPManager != null) SIPController.audioRTPManager.RTPEnd(8); if (SIPStack.bDirectCall == true) { //SERVICE MESSAGE NEEDED dialerVideoSet(false); } sendCancel(); } } else if (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_ACCEPTED || SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_REMOTEACCEPTED) { if (SIPController.sipCall.expiresT3 > SIPStack.CS_TIMEOUT_T3) { //ACCEPTED TIMEOUT PROCESSING SIPController.sipCall.exceptionT3(); // CONFERENCE CALL CHECK NEEDED if (SIPController.audioRTPManager != null) SIPController.audioRTPManager.RTPEnd(9); if (SIPStack.bDirectCall == true) { //SERVICE MESSAGE NEEDED dialerVideoSet(false); } sendBye(); } } else if (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_CONNECTED) { if (SIPController.sipCall.expiresT4 > SIPStack.CS_TIMEOUT_T4) { //CONNECTED TIMEOUT PROCESSING SIPController.sipCall.exceptionT4(); // CONFERENCE CALL CHECK NEEDED if (SIPController.audioRTPManager != null) SIPController.audioRTPManager.RTPEnd(10); if (SIPStack.bDirectCall == true) { //SERVICE MESSAGE NEEDED dialerVideoSet(false); } sendBye(); } else { int expiresT40 = 0; if (SIPController.sipCall.callTime_T40 != null) { expiresT40 = (int) (currentTime.getTime() - SIPController.sipCall.callTime_T40.getTime()) / 1000; if (expiresT40 > 0) { SIPController.sipCall.callTime_T40 = new Date(); } } // try { // if (SIPController.audioRTPManager != null && SIPController.sipCall.expiresT4 > 1 && SIPController.audioRTPManager.bDisableVoice == false) { // int muteDuration = (int) (currentTime.getTime() - SIPController.audioRTPManager.rtpCore.rtpArrivalTime.getTime()); // Log.e(TAG, "[SIPStun] ========== RTP END ========== muteDuration [" + muteDuration + "]"); // if (muteDuration > 5000) { // // milliseconds // // CONFERENCE CALL CHECK NEEDED // if (SIPController.audioRTPManager != null) // SIPController.audioRTPManager.RTPEnd(11); // if (SIPStack.bDirectCall == true) { // //SERVICE MESSAGE NEEDED // dialerVideoSet(false); // } // sendBye(); // //SERVICE MESSAGE NEEDED // updateDialerStatus("No Audio Packet Received for 3Sec!", false); // //SERVICE MESSAGE NEEDED // dialerNotifyCallEnd("No Audio Packet Received for 3Sec!", SIPController.sipCall.dnis, SIPController.sipCall.dnis + "@" + SIPController.sipCall.remoteIp + ":" + SIPController.sipCall.remotePort, false); // } // } // } catch (RuntimeException re) { // LogUtil.errorLogInfo("", TAG, re); // } catch (Exception e) { // Log.e(TAG, "[Exception] dialerVideoSet(false)"); // } } } else if (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_DISCONNECTING) { if (SIPController.sipCall.bByedisconnected == true && SIPController.sipCall.expiresT9 > 500) { //resend bye resendBye(); } if (SIPController.sipCall.expiresT5 > SIPStack.CS_TIMEOUT_T5) { //DISCONNECTING TIMEOUT PROCESSING SIPController.sipCall.exceptionT5(); SIPController.sipCall.resetCall(); } } else if (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_TERMINATING) { if (SIPController.sipCall.expiresT6 > SIPStack.CS_TIMEOUT_T6) { dialerNotifyCallEnd("Call Terminating.", SIPController.sipCall.dnis, SIPController.sipCall.dnis + "@" + SIPController.sipCall.remoteIp + ":" + SIPController.sipCall.remotePort, false); SIPController.sipCall.exceptionT6(); cmcore.ctrlIntervalTimer = new Date(); cmcore.bRequestReadySet = true; } } else if (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_OFFERRED) { if (SIPController.sipCall.expiresT7 > SIPStack.CS_TIMEOUT_T7) { //OFFERRED TIMEOUT PROCESSING SIPController.sipCall.exceptionT7(); //CONFERENCE CALL CHECK NEEDED if (SIPController.audioRTPManager != null) SIPController.audioRTPManager.RTPEnd(12); if (SIPStack.bDirectCall == true) { //SERVICE MESSAGE NEEDED dialerVideoSet(false); } rejectCall(408); } } else if (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_CANCELLING) { //more code needed !!!! if (SIPController.sipCall.expiresT8 > SIPStack.CS_TIMEOUT_T80) { //CANCELLING TIMEOUT PROCESSING sendRecancel(); } } else if (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_RECANCELLING) { //more code needed !!!! if (SIPController.sipCall.expiresT8 > SIPStack.CS_TIMEOUT_T8) { //CANCELLING TIMEOUT PROCESSING SIPController.sipCall.exceptionT8(); //SERVICE MESSAGE NEEDED dialerNotifyCallEnd("전화를 받지 않습니다.", SIPController.sipCall.dnis, SIPController.sipCall.dnis + "@" + SIPController.sipCall.remoteIp + ":" + SIPController.sipCall.remotePort, false); SIPController.sipCall.resetCall(); } } else if (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_CANCELREMOTEACCEPTED) { if (SIPController.sipCall.expiresT8 > SIPStack.CS_TIMEOUT_T8) { dialerNotifyCallFail(487, SIPController.sipCall.remoteIp, makeSIPID(SIPController.sipCall.remoteIp)); // CANCELLING TIMEOUT PROCESSING SIPController.sipCall.exceptionT8(); SIPController.sipCall.resetCall(); } } } else if (SIPController.sipCall.callMode == SIPStack.SIP_CALLMODE_HOLD) { // more job } return; } public int SIPParser(String strMessage, int nMSGType, int nMethodType) { if (strMessage == null || strMessage.length() <= 0) return 0; boolean bSendRegister = false; if (bPrintSIPMsgIO) { Log.i(TAG, "[SIPParser] nMSGType [" + nMSGType + "], nMethodType [" + nMethodType + "]"); printSIPMessage(MESSAGE.RECEIVE, strMessage); } if (nMSGType != SIPStack.SIP_MSGTYPE_RESPONSE || nMethodType != SIPStack.SIP_METHODTYPE_REGISTER) return -1; SIPRequestLine requestLine = new SIPRequestLine(strMessage); if (requestLine == null || requestLine.flag == false) return 0; switch (requestLine.code) { case 200: cmcore.repeatRegisterCount = 0; if (cmcore.regState == SIPStack.SIP_REGSTATE_REGISTERING || cmcore.regState == SIPStack.SIP_REGSTATE_AUTHORIZING || cmcore.regState == SIPStack.SIP_REGSTATE_UNREGISTERING) { SIPCONTACTHeader contactHeader = cmcore.action_reg_0(strMessage); if (contactHeader != null && contactHeader.flag == false) { contactHeader = new SIPCONTACTHeader(strMessage); } if (contactHeader == null || contactHeader.flag == false || contactHeader.expires == 0 || cmcore.regState == SIPStack.SIP_REGSTATE_UNREGISTERING) { if (cmcore.bInterfaceChanged == true) { cmcore.bInterfaceChanged = false; cmcore.regState = SIPStack.SIP_REGSTATE_REGISTERING; sendRegister(); } else { cmcore.regState = SIPStack.SIP_REGSTATE_IDLE; } break; } if (contactHeader.expires > 0) { cmcore.expiresSeconds = contactHeader.getExpires(); } else if (contactHeader.expires < 0) { SIPHeader expiresHeader = new SIPHeader(strMessage, SIPStack.SIP_HEADERTYPE_EXPIRES); if (expiresHeader != null && expiresHeader.flag == true && expiresHeader.headerValue != null && expiresHeader.headerValue.length() > 0) { cmcore.expiresSeconds = Integer.parseInt(expiresHeader.headerValue.trim()); } } // SET REGISTERSTATE AS REGISTERED if (cmcore.expiresSeconds > 0) { cmcore.regTime = new Date(); cmcore.regState = SIPStack.SIP_REGSTATE_REGISTERED; // Phone status set if (SIPController.sipCall == null || SIPController.sipCall.flag == false) { // SERVICE MESSAGE NEEDED updateDialerStatus("Ready.", false); } if (true == cmcore.action_reg_1(strMessage)) { cmcore.regState = SIPStack.SIP_REGSTATE_UNREGISTERING; sendUNRegister(cmcore.previfIp, cmcore.previfPort); } } else if (cmcore.expiresSeconds == 0) { cmcore.regTime = new Date(); cmcore.regState = SIPStack.SIP_REGSTATE_IDLE; // SERVICE MESSAGE NEEDED updateDialerStatus("Service Off mode", false); } } break; case 401: if (cmcore.repeatRegisterCount > 3) { cmcore.regState = SIPStack.SIP_REGSTATE_UNAVAILABLE; cmcore.repeatRegisterCount = 0; // Phone status set // SERVICE MESSAGE NEEDED updateDialerStatus("Server 인증 실패하였습니다.", false); break; } cmcore.regState = SIPStack.SIP_REGSTATE_UNAUTHORIZED; // Phone status set if (SIPController.sipCall.flag == false) { // SERVICE MESSAGE NEEDED updateDialerStatus("Regist Unauthorized.", false); } if (true == cmcore.action_reg_2(strMessage)) { bSendRegister = true; cmcore.repeatRegisterCount++; } break; case 407: if (cmcore.repeatRegisterCount > 3) { cmcore.regState = SIPStack.SIP_REGSTATE_UNAVAILABLE; cmcore.repeatRegisterCount = 0; // Phone status set // SERVICE MESSAGE NEEDED updateDialerStatus("Server 인증 실패하였습니다.", false); break; } // Phone status set // SERVICE MESSAGE NEEDED updateDialerStatus("Regist Unauthorized.", false); if (true == cmcore.action_reg_3(strMessage)) { bSendRegister = true; } break; case 423: cmcore.action_reg_4(strMessage); sendRegister(); break; default: if (requestLine.code >= 400) cmcore.regState = SIPStack.SIP_REGSTATE_UNAVAILABLE; break; } if (bSendRegister) { cmcore.regState = SIPStack.SIP_REGSTATE_AUTHORIZING; if (cmcore.authorizationH != null && cmcore.authorizationH.length() > 0) sendRegister(); } return 0; // normal } // SIPParser() public void UPDATEParser(String message, int msgType, String remoteIp, int remotePort) { Log.d(TAG, "[UPDATEParser]"); if (SIPController.sipCall == null || SIPController.sipCall.flag == false || (SIPController.sipCall.callMode != SIPStack.SIP_CALLMODE_BASIC && SIPController.sipCall.callMode != SIPStack.SIP_CALLMODE_HOLD)) { if (msgType == SIPStack.SIP_MSGTYPE_RESPONSE) { SIPRequestLine requestLine = new SIPRequestLine(message); if (requestLine != null && requestLine.flag == true && requestLine.code >= 300) { sendFinalAck(message, remoteIp, remotePort); } } return; } if (msgType == SIPStack.SIP_MSGTYPE_REQUEST) { if (SIPController.sipCall != null) { if (SIPController.sipCall.flag == true) { // busy // validate call SIPHeader sipHeader = new SIPHeader(message, SIPStack.SIP_HEADERTYPE_CALLID); boolean bValidCall = false; if (sipHeader != null && sipHeader.flag == true) { if (sipHeader.headerValue != null && sipHeader.headerValue.length() > 0 && SIPController.sipCall.callId != null && sipHeader.headerValue.compareTo(SIPController.sipCall.callId) == 0) { bValidCall = true; } } if (bValidCall == true) { // EXIST CALL // IF HOLDMODE if (SIPController.sipCall.callMode == SIPStack.SIP_CALLMODE_HOLD) { if (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_UPDATEOFFERRED) { // ACCEPT } return; } else if (SIPController.sipCall.callMode == SIPStack.SIP_CALLMODE_BASIC && SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_CONNECTED) { // IF CONNECTED // SET CALLMODE AS UPDATE SIPController.sipCall.callMode = SIPStack.SIP_CALLMODE_HOLD; SIPController.sipCall.callState = SIPStack.SIP_CALLSTATE_UPDATEOFFERRED; SIPController.sipCall.callDirection = SIPStack.SIP_CALLDIRECTION_IN; //parse message + construct local and remote sdp +negotiate codec if (true == SIPController.sipCall.constructUPDATEHeaders(message, remoteIp, remotePort)) { // response trying sendProceeding(remoteIp, remotePort); if (false == sendUpdateAccept()) { rejectCall(message, 480, remoteIp, remotePort); return; } } else { rejectCall(message, 480, remoteIp, remotePort); return; } // ACCEPT return; } else { // DISCARD return; } } else { // invalid update call rejectCall(message, 400, remoteIp, remotePort); return; } } else { // invalid update call rejectCall(message, 400, remoteIp, remotePort); return; } } else { // response 400 // no sip call handle // response only rejectCall(message, 400, remoteIp, remotePort); return; } } else if (msgType == SIPStack.SIP_MSGTYPE_RESPONSE && SIPController.sipCall.flag == true && SIPController.sipCall.callDirection == SIPStack.SIP_CALLDIRECTION_OUT) { if (SIPController.sipCall.callMode != SIPStack.SIP_CALLMODE_HOLD) return; SIPRequestLine requestLine = new SIPRequestLine(message); if (requestLine != null) { // validate call SIPHeader sipHeader = new SIPHeader(message, SIPStack.SIP_HEADERTYPE_CALLID); boolean bValidCall = false; if (sipHeader != null && sipHeader.flag == true) { if (sipHeader.headerValue != null && sipHeader.headerValue.length() > 0 && SIPController.sipCall.callId != null && sipHeader.headerValue.compareTo(SIPController.sipCall.callId) == 0) { SIPHeader seqHeader = new SIPHeader(message, SIPStack.SIP_HEADERTYPE_CSEQ); if (seqHeader != null && seqHeader.callSequenceNumber() == SIPController.sipCall.CSEQ_NUMBER) { bValidCall = true; } else if (requestLine.code < 200) { return; } } } if (bValidCall == true) { sipHeader = null; sipHeader = new SIPHeader(message, SIPStack.SIP_HEADERTYPE_TO); if (sipHeader != null) { SIPController.sipCall.toH = sipHeader.header; SIPController.sipCall.toTag = sipHeader.getTag(); } } sipHeader = new SIPHeader(message, SIPStack.SIP_HEADERTYPE_CSEQ); if (bValidCall == true) { SIPController.sipCall.remoteIp = remoteIp; SIPController.sipCall.remotePort = remotePort; if (requestLine.code >= 200 && sipHeader != null && sipHeader.flag == true) { SIPController.sipCall.CSEQ_NUMBER = sipHeader.callSequenceNumber(); } if (requestLine.code == 100) { // trying SIPController.sipCall.callState = SIPStack.SIP_CALLSTATE_UPDATEPROCEEDING; SIPController.sipCall.callTime_T1 = new Date(); } else if (requestLine.code >= 180 && requestLine.code <= 183) { // progressing SIPController.sipCall.callState = SIPStack.SIP_CALLSTATE_UPDATEPROGRESSING; SIPController.sipCall.callTime_T2 = new Date(); if (true == SIPController.sipCall.parseRemoteSdp(message)) { if (SIPController.sipCall.sdp != null && SIPController.sipCall.sdp.flag == true) { SIPController.sipCall.negotiateAudioCodec(); } if (SIPController.sipCall.remoteSdp != null && SIPController.sipCall.remoteSdp.flag == true && SIPController.audioRTPManager != null) { if (SIPController.sipCall.remoteSdp.audioM.flag == true) { if (SIPController.audioRTPManager != null) { SIPController.audioRTPManager.setRemoteMediaInfo(SIPController.sipCall.remoteSdp.audioM.commonCodec, SIPController.sipCall.remoteSdp.audioM.mediaIp, SIPController.sipCall.remoteSdp.audioM.mediaPort); if (SIPController.sipCall.sdp != null && SIPController.sipCall.sdp.audioM != null && SIPController.audioRTPManager.rtpCore.bActive == false) { SIPController.audioRTPManager.RTPInit(SIPController.sipCall.sdp.audioM.mediaPort, 1); } } } } } } else if (requestLine.code == 200 && SIPController.sipCall.CSEQ_NUMBER == sipHeader.callSequenceNumber() && (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_UPDATING || SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_UPDATEPROCEEDING || SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_UPDATEPROGRESSING)) { // connected SIPController.sipCall.callState = SIPStack.SIP_CALLSTATE_UPDATEREMOTEACCEPTED; SIPController.sipCall.callTime_T3 = new Date(); boolean ret = sendAck(message); if (ret == true) { SIPController.sipCall.callState = SIPStack.SIP_CALLSTATE_CONNECTED; SIPController.sipCall.callMode = SIPStack.SIP_CALLMODE_BASIC; SIPSound.resetBufferInfo(); // SERVICE MESSAGE NEEDED dialerNotifyCallConnected(SIPController.sipCall.dnis, SIPController.sipCall.dnis + "@" + SIPController.sipCall.remoteIp + ":" + SIPController.sipCall.remotePort); } // remote body analysis // MUST BE CHANGE if (true == SIPController.sipCall.parseRemoteSdp(message)) { if (SIPController.sipCall.sdp != null && SIPController.sipCall.sdp.flag == true) { SIPController.sipCall.negotiateAudioCodec(); } if (SIPController.sipCall.remoteSdp != null && SIPController.sipCall.remoteSdp.flag == true && SIPController.audioRTPManager != null) { if (SIPController.sipCall.remoteSdp.audioM != null && SIPController.sipCall.remoteSdp.audioM.flag == true) { if (SIPController.audioRTPManager != null) { SIPController.audioRTPManager.setRemoteMediaInfo(SIPController.sipCall.remoteSdp.audioM.commonCodec, SIPController.sipCall.remoteSdp.audioM.mediaIp, SIPController.sipCall.remoteSdp.audioM.mediaPort); if (SIPController.sipCall.sdp != null && SIPController.sipCall.sdp.audioM != null && SIPController.audioRTPManager.rtpCore.bActive == false) { SIPController.audioRTPManager.RTPInit(SIPController.sipCall.sdp.audioM.mediaPort, 2); } } } } } } else if (requestLine.code == 401 && (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_UPDATING || SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_UPDATEPROCEEDING || SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_UPDATEPROGRESSING)) { SIPController.sipCall.callState = SIPStack.SIP_CALLSTATE_UPDATEUNAUTHORIZED; sendFinalAck(message); if (reactionForWWWAUTHENTICATE(message) == false) { if (SIPController.audioRTPManager != null) SIPController.audioRTPManager.RTPEnd(13); SIPController.sipCall.resetCall(); } } else if (requestLine.code == 407 && (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_UPDATING || SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_UPDATEPROCEEDING || SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_UPDATEPROGRESSING)) { // Proxy-Athenticate SIPController.sipCall.callState = SIPStack.SIP_CALLSTATE_UPDATEUNAUTHORIZED; sendFinalAck(message); if (reactionForPROXYAUTHENTICATE(message) == false) { if (SIPController.audioRTPManager != null) SIPController.audioRTPManager.RTPEnd(14); SIPController.sipCall.resetCall(); } } else if (requestLine.code == 302 && (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_UPDATING || SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_UPDATEPROCEEDING || SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_UPDATEPROGRESSING)) { // terminating // FORWARD - MUST BE PROCESSED MORE SIPController.sipCall.callState = SIPStack.SIP_CALLSTATE_TERMINATING; sendFinalAck(message); if (SIPController.audioRTPManager != null) SIPController.audioRTPManager.RTPEnd(15); SIPController.sipCall.resetCall(); } else if (requestLine.code >= 300 && (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_UPDATING || SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_UPDATEPROCEEDING || SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_UPDATEPROGRESSING || SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_UPDATEUNAUTHORIZED)) { // terminating SIPController.sipCall.callState = SIPStack.SIP_CALLSTATE_TERMINATING; sendFinalAck(message); if (SIPController.audioRTPManager != null) SIPController.audioRTPManager.RTPEnd(16); SIPController.sipCall.resetCall(); } } else { sendFinalAck(message, remoteIp, remotePort); } } } return; } String m_strMessage = "", m_strRemoteIP = ""; int m_strRemotePort = 0; public void INVITEParser(String strMessage, int nMSGType, String strRemoteIP, int strRemotePort) { try { Log.w(TAG, "[INVITEParser] bBLOCK_INVITE_MSG [" + bBLOCK_INVITE_MSG + "]"); Log.w(TAG, "[INVITEParser] strMessage [" + strMessage + "]"); //m_strMessage = strMessage; //m_strRemoteIP = strRemoteIP; //m_strRemotePort = strRemotePort; if (bBLOCK_INVITE_MSG) { rejectCall(strMessage, 486, strRemoteIP, strRemotePort); return; } if (nMSGType == SIPStack.SIP_MSGTYPE_REQUEST) { if (SIPController.sipCall != null) { Log.d(TAG, "[INVITEParser] [SIPController.sipCall.flag = " + SIPController.sipCall.flag + "]"); if (SIPController.sipCall.flag == true) { // busy boolean bValidCall = SIPController.sipCall.isCurrentCall(strMessage); Log.d(TAG, "[INVITEParser] bValidCall = " + bValidCall); if (bValidCall == true) { //EXIST CALL //IF HOLDEMODE if (SIPController.sipCall.callMode == SIPStack.SIP_CALLMODE_HOLD) { UPDATEParser(strMessage, nMSGType, strRemoteIP, strRemotePort); return; } else if (SIPController.sipCall.callMode == SIPStack.SIP_CALLMODE_BASIC && SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_CONNECTED) { // IF CONNECTED // UPDATE PROCESSING UPDATEParser(strMessage, nMSGType, strRemoteIP, strRemotePort); return; } else { // DISCARD return; } } else { Log.i(TAG, "BUSY CHECK : callState : " + SIPController.sipCall.callState); if (SIPController.sipCall.callState != SIPStack.SIP_CALLSTATE_CONNECTED) { rejectCall(strMessage, 486, strRemoteIP, strRemotePort); return; } if (SIPController.bMulticallSupport == true) { if (SIPController.pendingCall != null) { if (SIPController.pendingCall.flag == true) { if (SIPController.pendingCall.isCurrentCall(strMessage) == true) { // pendingCall self // no action } else { /* KSJ 2022.06.16 invite 두번 들어오는 경우가 발생 하여 먼저 들어온 remoteIP 를 저장 하여, 통화 중인 같은 IP 에서 call 발생할 경우 multi call 처리를 하지 않고 내용 버리기 위한 코드. */ if(m_strRemoteIP != strRemoteIP) { // pendingCall exist and another pending call incoming rejectCall(strMessage, 486, strRemoteIP, strRemotePort); } } return; } else { // New incoming pending call CMCore.bDialerActive = true; if (CMCore.bDialerActive == false) { rejectCall(strMessage, 486, strRemoteIP, strRemotePort); return; } // pending call construct String fromId = null; String toId = null; SIPHeader sipHeader = new SIPHeader(strMessage, SIPStack.SIP_HEADERTYPE_TO); if (sipHeader != null && sipHeader.flag == true) { toId = sipHeader.getId().trim(); if (toId != null && toId.length() > 0) { sipHeader = new SIPHeader(strMessage, SIPStack.SIP_HEADERTYPE_FROM); if (sipHeader != null && sipHeader.flag == true) { fromId = sipHeader.getId().trim(); } } toId = makeSIPID(toId); fromId = makeSIPID(fromId); Log.d(TAG, "[INVITEParser111] cmcore.id [" + cmcore.id + "], toId [" + toId + "]"); if (cmcore.id != null && toId.compareTo(cmcore.id) == 0) { // activate call handler boolean ret = false; if (SIPStack.bDirectCall == false) { if (strRemoteIP.compareTo(cmcore.serverIp) == 0) { ret = SIPController.pendingCall.activeCallHandle(cmcore.id, cmcore.cid, cmcore.authid, cmcore.authpassword, fromId, strRemoteIP, strRemotePort, cmcore.serverDomain, cmcore.localIp, cmcore.localPort); } else { ret = SIPController.pendingCall.activeCallHandle(cmcore.id, cmcore.cid, cmcore.authid, cmcore.authpassword, fromId, strRemoteIP, strRemotePort, strRemoteIP, cmcore.localIp, cmcore.localPort); } } else { ret = SIPController.pendingCall.activeCallHandle(cmcore.id, cmcore.cid, cmcore.authid, cmcore.authpassword, fromId, strRemoteIP, strRemotePort, strRemoteIP, cmcore.localIp, cmcore.localPort); } if (ret == true) { SIPController.pendingCall.callState = SIPStack.SIP_CALLSTATE_OFFERRED; SIPController.pendingCall.callDirection = SIPStack.SIP_CALLDIRECTION_IN; SIPController.pendingCall.callTime_T7 = new Date();//offerred timer if (true == SIPController.pendingCall.constructHeaders(strMessage, strRemoteIP, strRemotePort)) { if (SIPController.sipCall.remoteContactUri.contains("Lobby") && SIPController.pendingCall.remoteContactUri.contains("Lobby")) { rejectPendingCall(486); return; } else if (SIPController.sipCall.remoteContactUri.contains("Guard") && SIPController.pendingCall.remoteContactUri.contains("Guard")) { rejectPendingCall(486); return; } else if (SIPController.sipCall.remoteContactUri.contains("Resi") && SIPController.pendingCall.remoteContactUri.contains("Resi")) { rejectPendingCall(486); return; } sendPendingProceeding(strRemoteIP, strRemotePort); dialerNotifyIncomingMultiCall(SIPController.pendingCall.dnis, SIPController.pendingCall.dnis + "@" + SIPController.pendingCall.remoteIp + ":" + SIPController.pendingCall.remotePort); } else { rejectCall(strMessage, 480, strRemoteIP, strRemotePort); return; } } else { rejectCall(strMessage, 480, strRemoteIP, strRemotePort); return; } sendPendingProgressing(strRemoteIP, strRemotePort); return; } else { rejectCall(strMessage, 404, strRemoteIP, strRemotePort); return; } } else { rejectCall(strMessage, 486, strRemoteIP, strRemotePort); } } } else { rejectCall(strMessage, 486, strRemoteIP, strRemotePort); } } else { // BUSY rejectCall(strMessage, 486, strRemoteIP, strRemotePort); } } } else { // BUSY UPDATE END // processing inviting call SIPStun.bBlackCall = false; boolean bCallPopup = false; String fromId = null; String toId = null; SIPHeader sipHeader = new SIPHeader(strMessage, SIPStack.SIP_HEADERTYPE_TO); if (sipHeader != null && sipHeader.flag == true) { toId = sipHeader.getId().trim(); if (toId != null && toId.length() > 0) { sipHeader = new SIPHeader(strMessage, SIPStack.SIP_HEADERTYPE_FROM); if (sipHeader != null && sipHeader.flag == true) { fromId = sipHeader.getId().trim(); } } sipHeader = new SIPHeader(strMessage, SIPStack.SIP_HEADERTYPE_CONTACT); Log.d(TAG, "[INVITEParser22222] SIP_HEADERTYPE_CONTACT [" + sipHeader.header + "]"); if(!sipHeader.header.contains("Lobby") && !sipHeader.header.contains("Resi")) { sipHeader = new SIPHeader(strMessage, SIPStack.SIP_HEADERTYPE_CALLID); if(sipHeader.header.contains("HNSLOBBY")) { bCallPopup = true; } else if(sipHeader.header.contains("CNSTEC")) { bCallPopup = true; } } toId = makeSIPID(toId); fromId = makeSIPID(fromId); Log.d(TAG, "[INVITEParser22222] cmcore.id [" + cmcore.id + "], toId [" + toId + "]"); // KSJ 호출이 온 IP를 저장 하고 이후 사용 하기 위한 코드 2022.06.16 m_strMessage = strMessage; m_strRemoteIP = strRemoteIP; m_strRemotePort = strRemotePort; if (cmcore.id != null && toId.compareTo(cmcore.id) == 0) { // activate call handler boolean ret = false; if (SIPStack.bDirectCall == false) { if (strRemoteIP.compareTo(cmcore.serverIp) == 0) { ret = SIPController.sipCall.activeCallHandle(cmcore.id, cmcore.cid, cmcore.authid, cmcore.authpassword, fromId, strRemoteIP, strRemotePort, cmcore.serverDomain, cmcore.localIp, cmcore.localPort); } else { ret = SIPController.sipCall.activeCallHandle(cmcore.id, cmcore.cid, cmcore.authid, cmcore.authpassword, fromId, strRemoteIP, strRemotePort, strRemoteIP, cmcore.localIp, cmcore.localPort); } } else { Log.i(TAG, "[INVITEParser] New call. Dialer awaken."); Log.i(TAG, "[INVITEParser] strRemoteIP [" + strRemoteIP + "], fromId [" + fromId + "]"); receiveNewCall(strRemoteIP, fromId, bCallPopup); Log.d(TAG, "[INVITEParser] CMCore.bDialerActive [" + CMCore.bDialerActive + "]"); // CMCore.bDialerActive는 GUI의 foreground 여부를 의미한다. (true: foreground) // 통화어플 적용시에는 상관없으므로 주석처리한다. // GUI는 receiveNewCall(String strRemoteIP, String strRemoteSIPID) 함수에서 실행한다. if (CMCore.bDialerActive == false) { Log.e(TAG, "[INVITEParser] ============ SEULKI 2 ============"); SIPStun.bBlackCall = true; Log.d(TAG, "[INVITEParser] SIPStun.bBlackcallBackgroundMode [" + SIPStun.bBlackcallBackgroundMode + "]"); if (SIPStun.bBlackcallBackgroundMode == true) { Log.e(TAG, "[INVITEParser] ============ SEULKI 3 ============"); ret = SIPController.sipCall.activeCallHandle(cmcore.id, cmcore.cid, cmcore.authid, cmcore.authpassword, fromId, strRemoteIP, strRemotePort, strRemoteIP, cmcore.localIp, cmcore.localPort); if (ret == true) { Log.e(TAG, "[INVITEParser] ============ SEULKI 4 ============"); SIPController.sipCall.callState = SIPStack.SIP_CALLSTATE_OFFERRED; SIPController.sipCall.callDirection = SIPStack.SIP_CALLDIRECTION_IN; SIPController.sipCall.callTime_T7 = new Date(); // offerred timer // parse message + construct local and remote sdp +negotiate codec if (true == SIPController.sipCall.constructHeaders(strMessage, strRemoteIP, strRemotePort)) { Log.e(TAG, "[INVITEParser] ============ SEULKI 5 ============"); // response trying sendProceeding(strRemoteIP, strRemotePort); SIPController.sipCall.bResponsebackgroundcall = true; SIPController.sipCall.bResponsebackgroundcallReady = false; if (SIPController.sipCall.hnsOriginatorServiceType == BSSVideo.HNS_SERVICE_LOBBY) { SIPController.latestMenu = 1; } else if (SIPController.sipCall.hnsOriginatorServiceType == BSSVideo.HNS_SERVICE_GUARD) { SIPController.latestMenu = 2; } else if (SIPController.sipCall.hnsOriginatorServiceType == BSSVideo.HNS_SERVICE_NEIGHBOR) { SIPController.latestMenu = 3; } if ((BSSVideo.bProgressvideooffer == true) || (SIPController.forward.bForward == true)) { Log.e(TAG, "[INVITEParser] ============ SEULKI 6 ============"); sendProgressingBlackcallwithbody(strRemoteIP, strRemotePort); } else { Log.e(TAG, "[INVITEParser] ============ SEULKI 7 ============"); sendProgressing(strRemoteIP, strRemotePort); } } } } return; } ret = SIPController.sipCall.activeCallHandle(cmcore.id, cmcore.cid, cmcore.authid, cmcore.authpassword, fromId, strRemoteIP, strRemotePort, strRemoteIP, cmcore.localIp, cmcore.localPort); } if (ret == true) { Log.e(TAG, "[INVITEParser] ============ SEULKI 8 ============"); SIPController.sipCall.callState = SIPStack.SIP_CALLSTATE_OFFERRED; SIPController.sipCall.callDirection = SIPStack.SIP_CALLDIRECTION_IN; SIPController.sipCall.callTime_T7 = new Date();//offerred timer //parse message + construct local and remote sdp +negotiate codec if (true == SIPController.sipCall.constructHeaders(strMessage, strRemoteIP, strRemotePort)) { Log.e(TAG, "[INVITEParser] ============ SEULKI 9 ============"); // response trying sendProceeding(strRemoteIP, strRemotePort); updateDialerStatus("전화가 왔습니다.", false); dialerNotifyIncomingCall(SIPController.sipCall.dnis, SIPController.sipCall.dnis + "@" + SIPController.sipCall.remoteIp + ":" + SIPController.sipCall.remotePort); } else { Log.e(TAG, "[INVITEParser] ============ SEULKI 10 ============"); rejectCall(strMessage, 480, strRemoteIP, strRemotePort); updateDialerStatus("전화를 종료했습니다.", false); return; } } else { Log.e(TAG, "[INVITEParser] ============ SEULKI 11 ============"); rejectCall(strMessage, 480, strRemoteIP, strRemotePort); return; } if (BSSVideo.bProgressvideooffer == true || SIPController.forward.bForward == true) { Log.e(TAG, "[INVITEParser] ============ SEULKI 12 ============"); //KSJ 2443 1세대 버전 호환을 위해 주석 //sendProgressingwithbody(strRemoteIP, strRemotePort); } else { Log.e(TAG, "[INVITEParser] ============ SEULKI 13 ============"); sendProgressing(strRemoteIP, strRemotePort); } } else { Log.e(TAG, "[INVITEParser] ============ SEULKI 14 ============"); rejectCall(strMessage, 404, strRemoteIP, strRemotePort); return; } } } } else { // response 480 // no sip call handle // response only Log.e(TAG, "[INVITEParser] ============ SEULKI 15 ============"); rejectCall(strMessage, 480, strRemoteIP, strRemotePort); } } else if (nMSGType == SIPStack.SIP_MSGTYPE_RESPONSE) { if (true == cmcore.INVITEParser_action_0(SIPController.sipCall, strMessage)) { SIPHeader sipHeader = null; sipHeader = new SIPHeader(strMessage, SIPStack.SIP_HEADERTYPE_TO); if (sipHeader != null) { SIPController.sipCall.toH = sipHeader.header; SIPController.sipCall.toTag = sipHeader.getTag(); } sipHeader = new SIPHeader(strMessage, SIPStack.SIP_HEADERTYPE_CSEQ); if (SIPController.sipCall.callMode == SIPStack.SIP_CALLMODE_HOLD) { UPDATEParser(strMessage, nMSGType, strRemoteIP, strRemotePort); return; } SIPController.sipCall.remoteIp = strRemoteIP; SIPController.sipCall.remotePort = strRemotePort; if ((SIPController.sipCall.responseCode >= 200) && (sipHeader != null) && (sipHeader.flag == true)) { SIPController.sipCall.CSEQ_NUMBER = sipHeader.callSequenceNumber(); } if (SIPController.sipCall.responseCode == 100) { // trying SIPController.sipCall.callState = SIPStack.SIP_CALLSTATE_PROCEEDING; SIPController.sipCall.callTime_T1 = new Date(); // Phone status set // SERVICE MESSAGE NEEDED updateDialerStatus("Call proceeding.", false); } else if ((SIPController.sipCall.responseCode >= 180) && (SIPController.sipCall.responseCode <= 183)) { // progressing // SERVICE MESSAGE NEEDED dialerNotifyRingbackTone(true); // Phone status set // SERVICE MESSAGE NEEDED updateDialerStatus("Call progressing.", false); SIPController.sipCall.callState = SIPStack.SIP_CALLSTATE_PROGRESSING; SIPController.sipCall.callTime_T2 = new Date(); if (true == SIPController.sipCall.parseRemoteSdp(strMessage)) { if ((SIPController.sipCall.sdp != null) && (SIPController.sipCall.sdp.flag == true)) { SIPController.sipCall.negotiateAudioCodec(); } if ((SIPController.sipCall.remoteSdp != null) && (SIPController.sipCall.remoteSdp.flag == true) && (SIPController.audioRTPManager != null)) { if ((SIPController.sipCall.remoteSdp.audioM != null) && (SIPController.sipCall.remoteSdp.audioM.flag == true)) { if (SIPController.audioRTPManager != null) { SIPController.audioRTPManager.setRemoteMediaInfo(SIPController.sipCall.remoteSdp.audioM.commonCodec, SIPController.sipCall.remoteSdp.audioM.mediaIp, SIPController.sipCall.remoteSdp.audioM.mediaPort); if ((SIPController.sipCall.sdp != null) && (SIPController.sipCall.sdp.audioM != null) && (SIPController.audioRTPManager.rtpCore.bActive == false)) { if ((SIPStack.bDirectCall == true) && (BSSVideo.bProgressvideooffer == true)) { // SERVICE MESSAGE NEEDED dialerVideoSet(true); } else { SIPController.audioRTPManager.RTPInit(SIPController.sipCall.sdp.audioM.mediaPort, 3); } } } } } } else { // local ringbacktone play // SERVICE MESSAGE NEEDED dialerNotifyRingbackTone(true); } } else if ((SIPController.sipCall.responseCode == 200) && (SIPController.sipCall.CSEQ_NUMBER == sipHeader.callSequenceNumber()) && ((SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_INVITING) || (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_PROCEEDING) || (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_PROGRESSING))) { // connected // Phone status set // SERVICE MESSAGE NEEDED updateDialerStatus("Connected.", false); SIPController.sipCall.callState = SIPStack.SIP_CALLSTATE_REMOTEACCEPTED; SIPController.sipCall.callTime_T3 = new Date(); boolean ret = sendAck(strMessage); if (ret == true) { SIPController.sipCall.callState = SIPStack.SIP_CALLSTATE_CONNECTED; SIPController.sipCall.callTime_T4 = new Date(); SIPController.sipCall.callTime_T40 = new Date(); SIPSound.resetBufferInfo(); // SERVICE MESSAGE NEEDED dialerNotifyCallConnected(SIPController.sipCall.dnis, SIPController.sipCall.dnis + "@" + SIPController.sipCall.remoteIp + ":" + SIPController.sipCall.remotePort); } if (true == SIPController.sipCall.parseRemoteSdp(strMessage)) { if ((SIPController.sipCall.sdp != null) && (SIPController.sipCall.sdp.flag == true)) { SIPController.sipCall.negotiateAudioCodec(); } if ((SIPController.sipCall.remoteSdp != null) && (SIPController.sipCall.remoteSdp.flag == true) && (SIPController.audioRTPManager != null)) { if ((SIPController.sipCall.remoteSdp.audioM != null) && (SIPController.sipCall.remoteSdp.audioM.flag == true)) { if (SIPController.audioRTPManager != null) { SIPController.audioRTPManager.setRemoteMediaInfo(SIPController.sipCall.remoteSdp.audioM.commonCodec, SIPController.sipCall.remoteSdp.audioM.mediaIp, SIPController.sipCall.remoteSdp.audioM.mediaPort); if ((SIPController.sipCall.sdp != null) && (SIPController.sipCall.sdp.audioM != null) && (SIPController.audioRTPManager.rtpCore.bActive == false)) { if (SIPStack.bDirectCall == true) { if (SIPController.bMobileCall) SIPController.audioRTPManager.RTPRemoteCallInit(SIPController.sipCall.sdp.audioM.mediaPort); else SIPController.audioRTPManager.RTPInit(SIPController.sipCall.sdp.audioM.mediaPort, 4); // SIPController.audioRTPManager.RTPInit(SIPController.sipCall.sdp.audioM.mediaPort, 4); // SERVICE MESSAGE NEEDED dialerVideoSet(true); } else { SIPController.audioRTPManager.RTPInit(SIPController.sipCall.sdp.audioM.mediaPort, 5); } } } } } } } else if ((SIPController.sipCall.responseCode == 401) && ((SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_INVITING) || (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_PROCEEDING) || (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_PROGRESSING))) { // Athenticate // Phone status set // SERVICE MESSAGE NEEDED updateDialerStatus("Call Unauthorized(401).", false); SIPController.sipCall.callState = SIPStack.SIP_CALLSTATE_UNAUTHORIZED; SIPController.sipCall.authorizationACKH = ""; sendFinalAck(strMessage); if (reactionForWWWAUTHENTICATE(strMessage) == false) { if (SIPController.audioRTPManager != null) SIPController.audioRTPManager.RTPEnd(17); if (SIPStack.bDirectCall == true) { // SERVICE MESSAGE NEEDED dialerVideoSet(false); } dialerNotifyCallFail(SIPController.sipCall.responseCode, SIPController.sipCall.remoteIp, makeSIPID(SIPController.sipCall.remoteIp)); //SERVICE MESSAGE NEEDED dialerNotifyCallEnd("Call Unauthorized(401).", SIPController.sipCall.dnis, SIPController.sipCall.dnis + "@" + SIPController.sipCall.remoteIp + ":" + SIPController.sipCall.remotePort, false); SIPController.sipCall.resetCall(); } } else if ((SIPController.sipCall.responseCode == 407) && ((SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_INVITING) || (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_PROCEEDING) || (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_PROGRESSING))) { // Proxy-Athenticate // Phone status set // SERVICE MESSAGE NEEDED updateDialerStatus("Call Unauthorized(407).", false); SIPController.sipCall.callState = SIPStack.SIP_CALLSTATE_UNAUTHORIZED; SIPController.sipCall.authorizationACKH = ""; sendFinalAck(strMessage); if (reactionForPROXYAUTHENTICATE(strMessage) == false) { if (SIPController.audioRTPManager != null) SIPController.audioRTPManager.RTPEnd(18); if (SIPStack.bDirectCall == true) { //SERVICE MESSAGE NEEDED dialerVideoSet(false); } dialerNotifyCallFail(SIPController.sipCall.responseCode, SIPController.sipCall.remoteIp, makeSIPID(SIPController.sipCall.remoteIp)); // SERVICE MESSAGE NEEDED dialerNotifyCallEnd("Call Unauthorized(407).", SIPController.sipCall.dnis, SIPController.sipCall.dnis + "@" + SIPController.sipCall.remoteIp + ":" + SIPController.sipCall.remotePort, false); SIPController.sipCall.resetCall(); } } else if ((SIPController.sipCall.responseCode == 302) && ((SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_INVITING) || (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_PROCEEDING) || (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_PROGRESSING))) { // terminating // SERVICE MESSAGE NEEDED LOG_INFO("[INVITEParser] BSSVideo.HNS_SERVICE_RECEIVER_SELECTED [" + BSSVideo.HNS_SERVICE_RECEIVER_SELECTED + "]"); LOG_INFO("[INVITEParser] SIPController.sipCall.remoteIp : " + SIPController.sipCall.remoteIp); LOG_INFO("[INVITEParser] SIPController.sipCall.number : " + SIPController.sipCall.number); LOG_INFO("[INVITEParser] SIPController.sipCall.cid : " + SIPController.sipCall.cid); LOG_INFO("[INVITEParser] SIPController.sipCall.dnis : " + SIPController.sipCall.dnis); LOG_INFO("[INVITEParser] SIPController.sipCall.dong_number : " + SIPController.sipCall.dong_number); LOG_INFO("[INVITEParser] SIPController.sipCall.ho_number : " + SIPController.sipCall.ho_number); LOG_INFO("[INVITEParser] SIPController.sipCall.id : " + SIPController.sipCall.id); SIPCONTACTHeader contactHeader = new SIPCONTACTHeader(strMessage); updateDialerStatus("Call forwarded./" + contactHeader.getSipuri(), true); SIPController.sipCall.callState = SIPStack.SIP_CALLSTATE_REDIRECTED; sendRedirectFinalAck(strMessage); if (SIPController.audioRTPManager != null) SIPController.audioRTPManager.RTPEnd(19); if (SIPStack.bDirectCall == true) { dialerVideoSet(false); } SIPController.sipCall.resetCall(); } else if ((SIPController.sipCall.responseCode >= 300) && ((SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_INVITING) || (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_PROCEEDING) || (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_PROGRESSING) || (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_UNAUTHORIZED) || (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_CANCELLING) || (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_RECANCELLING) || (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_CANCELREMOTEACCEPTED))) { // terminating // Phone status set // SERVICE MESSAGE NEEDED updateDialerStatus("Call rejected by remoter.", true); SIPController.sipCall.callState = SIPStack.SIP_CALLSTATE_TERMINATING; sendFinalAck(strMessage); if (SIPController.audioRTPManager != null) SIPController.audioRTPManager.RTPEnd(20); if (SIPStack.bDirectCall == true) { // SERVICE MESSAGE NEEDED dialerVideoSet(false); } dialerNotifyCallFail(SIPController.sipCall.responseCode, SIPController.sipCall.remoteIp, makeSIPID(SIPController.sipCall.remoteIp)); // SERVICE MESSAGE NEEDED dialerNotifyCallEnd("Call rejected by remoter.", SIPController.sipCall.dnis, SIPController.sipCall.dnis + "@" + SIPController.sipCall.remoteIp + ":" + SIPController.sipCall.remotePort, false); SIPController.sipCall.resetCall(); } else { } } else { } } else { } } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); } catch (Exception e) { Log.e(TAG, "[Exception] INVITEParser(String message, int msgType, String remoteIp, int remotePort)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } } public void ACKParser(String message, int msgType, String remoteIp, int remotePort) { boolean bValid = false; if (SIPController.sipCall != null && SIPController.sipCall.flag == true) { bValid = SIPController.sipCall.isCurrentCall(message); } if (bValid == true) { if (msgType == SIPStack.SIP_MSGTYPE_REQUEST && SIPController.sipCall.flag == true && SIPController.sipCall.callMode == SIPStack.SIP_CALLMODE_HOLD) { if (true == cmcore.ACKParser_action_0(SIPController.sipCall, message)) { SIPSound.resetBufferInfo(); // SERVICE MESSAGE NEEDED dialerNotifyCallConnected(SIPController.sipCall.dnis, SIPController.sipCall.dnis + "@" + SIPController.sipCall.remoteIp + ":" + SIPController.sipCall.remotePort); } } else if (msgType == SIPStack.SIP_MSGTYPE_REQUEST && SIPController.sipCall.flag == true && SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_ACCEPTED) { if (true == cmcore.ACKParser_action_1(SIPController.sipCall, message)) { // SERVICE MESSAGE NEEDED updateDialerStatus("Connected.", false); SIPSound.resetBufferInfo(); // SERVICE MESSAGE NEEDED dialerNotifyCallConnected(SIPController.sipCall.dnis, SIPController.sipCall.dnis + "@" + SIPController.sipCall.remoteIp + ":" + SIPController.sipCall.remotePort); } } else if (msgType == SIPStack.SIP_MSGTYPE_REQUEST && SIPController.sipCall.flag == true && (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_CANCELLED || SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_TERMINATING)) { //Log.i(TAG, "ACK arrived."); if (true == cmcore.ACKParser_action_2(SIPController.sipCall, message)) { if (SIPController.audioRTPManager != null) SIPController.audioRTPManager.RTPEnd(21); if (SIPStack.bDirectCall == true) { // SERVICE MESSAGE NEEDED dialerVideoSet(false); } // SERVICE MESSAGE NEEDED dialerNotifyCallEnd("", SIPController.sipCall.dnis, SIPController.sipCall.dnis + "@" + SIPController.sipCall.remoteIp + ":" + SIPController.sipCall.remotePort, false); SIPController.sipCall.resetCall(); } } return; } if (SIPController.pendingCall != null && SIPController.pendingCall.flag == true) { bValid = SIPController.pendingCall.isCurrentCall(message); } if (bValid == true) { if (msgType == SIPStack.SIP_MSGTYPE_REQUEST && SIPController.pendingCall.flag == true && (SIPController.pendingCall.callState == SIPStack.SIP_CALLSTATE_CANCELLED || SIPController.pendingCall.callState == SIPStack.SIP_CALLSTATE_TERMINATING)) { SIPController.pendingCall.resetCall(); } } return; } public void CANCELParser(String message, int msgType, String remoteIp, int remotePort) { boolean bValid = false; if (SIPController.sipCall != null && SIPController.sipCall.flag == true) { bValid = SIPController.sipCall.isCurrentCall(message); } if (bValid == true) { if (msgType == SIPStack.SIP_MSGTYPE_REQUEST && SIPController.sipCall.flag == true && SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_OFFERRED) { if (true == cmcore.CANCELParser_action_0(SIPController.sipCall, message)) { acceptCancelRequest(message, remoteIp, remotePort); if (SIPController.sipCall.remoteSdp != null && SIPController.sipCall.remoteSdp.flag == true && SIPController.audioRTPManager != null) { if (SIPController.sipCall.remoteSdp.audioM != null && SIPController.sipCall.remoteSdp.audioM.flag == true) { if (SIPController.sipCall.sdp != null && SIPController.sipCall.sdp.audioM != null && SIPController.audioRTPManager != null) { SIPController.audioRTPManager.RTPEnd(22); if (SIPStack.bDirectCall == true) { // SERVICE MESSAGE NEEDED dialerVideoSet(false); } } } } rejectCall(487); } } else if (msgType == SIPStack.SIP_MSGTYPE_RESPONSE && SIPController.sipCall.flag == true && (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_CANCELLING || SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_RECANCELLING)) { if (true == cmcore.CANCELParser_action_1(SIPController.sipCall, message)) { SIPController.sipCall.callState = SIPStack.SIP_CALLSTATE_CANCELREMOTEACCEPTED; // none action } } return; } // Multicall if (SIPController.pendingCall != null && SIPController.pendingCall.flag == true) { bValid = SIPController.pendingCall.isCurrentCall(message); } if (bValid == true) { if (msgType == SIPStack.SIP_MSGTYPE_REQUEST && SIPController.pendingCall.flag == true && SIPController.pendingCall.callState == SIPStack.SIP_CALLSTATE_OFFERRED) { if (true == cmcore.CANCELParser_action_0(SIPController.pendingCall, message)) { acceptPendingCancelRequest(message, remoteIp, remotePort); rejectPendingCall(487); dialerNotifyMulticallCancel(getSIPIDfromMessage(message), remoteIp); } } return; } } private String getSIPIDfromMessage(String strMessage) { try { String[] strParsed_01 = strMessage.split("Contact: 0 && mSIPSignalReceiver != null) { byte[] buffer = cmcore.message.getBytes(); if (cmcore.message.length() > 0) { if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, cmcore.message); int repeatSendCount = 0; while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) { if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(cmcore.serverIp, cmcore.serverPort, buffer, buffer.length)) { break; } repeatSendCount++; } cmcore.regTime = new Date(); } } return true; } return false; } public boolean sendUNRegister() { if (cmcore.makeUNRegister() == true) { if (cmcore.message.length() > 0 && mSIPSignalReceiver != null) { byte[] buffer = cmcore.message.getBytes(); if (cmcore.message.length() > 0) { if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, cmcore.message); int repeatSendCount = 0; while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) { if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(cmcore.serverIp, cmcore.serverPort, buffer, buffer.length)) { break; } repeatSendCount++; } cmcore.regTime = new Date(); } } return true; } return false; } public boolean sendUNRegister(String contactip, int contactport) { if (cmcore.makeUNRegister(contactip, contactport) == true) { if (cmcore.message.length() > 0 && mSIPSignalReceiver != null) { byte[] buffer = cmcore.message.getBytes(); if (cmcore.message.length() > 0) { if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, cmcore.message); int repeatSendCount = 0; while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) { if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(cmcore.serverIp, cmcore.serverPort, buffer, buffer.length)) { break; } repeatSendCount++; } cmcore.regTime = new Date(); } } return true; } return false; } public boolean decideRegister() { Date currentDate = new Date(); int seconds = (int) (currentDate.getTime() - cmcore.regTime.getTime()) / 1000; if (seconds > cmcore.expiresSeconds - 10) return true; else return false; } public boolean callActivate(String number) { if (SIPController.sipCall == null) return false; String dial = ""; if (SIPController.sipCall.flag == false) { // Phone status set // SERVICE MESSAGE NEEDED updateDialerStatus("Calling to " + number, false); if (number.length() > 32) { dial = number.substring(0, 32); } else { dial = new String(number); } return callMake(dial); } else if (SIPController.sipCall.callDirection == SIPStack.SIP_CALLDIRECTION_IN && SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_OFFERRED) { // Phone status set // SERVICE MESSAGE NEEDED updateDialerStatus("Incoming call accept.", false); return sendAccept(); } return false; } public boolean directcallActivate(String strNumber, boolean bMobile) { try { LOG_DEBUG("[directcallActivate] strNumber [" + strNumber + "], bMobile [" + bMobile + "]"); if (SIPController.sipCall == null) { LOG("[directcallActivate] SIPController.sipCall is null!!"); return false; } String dial = ""; LOG_DEBUG("[directcallActivate] SIPController.sipCall.flag = " + SIPController.sipCall.flag); if (SIPController.sipCall.flag == false) { // Phone status set // SERVICE MESSAGE NEEDED updateDialerStatus("Calling to " + strNumber, false); if (strNumber.length() > 32) { dial = strNumber.substring(0, 32); } else { dial = new String(strNumber); } return directcallMake(dial); } else if (SIPController.sipCall.callDirection == SIPStack.SIP_CALLDIRECTION_IN && SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_OFFERRED) { // Phone status set // SERVICE MESSAGE NEEDED updateDialerStatus("Incoming call accept.", false); return directsendAccept(bMobile); } return false; } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); return false; } catch (Exception e) { Log.e(TAG, "[Exception] directcallActivate(String strNumber)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); return false; } } public boolean callMake(String number) { if (cmcore.regState != SIPStack.SIP_REGSTATE_REGISTERED) { // SERVICE MESSAGE NEEDED dialerNotifyCallEnd("Not registered.", "", "", true); return false; } if (true == cmcore.makeCallMake(SIPController.sipCall, number)) { if (SIPController.sipCall.message.length() > 0 && mSIPSignalReceiver != null) { byte[] buffer = SIPController.sipCall.message.getBytes(); if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, SIPController.sipCall.message); int repeatSendCount = 0; while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) { if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort, buffer, buffer.length)) { break; } repeatSendCount++; } SIPController.sipCall.callTime_T0 = new Date(); SIPController.sipCall.callTime_T00 = new Date(); SIPController.sipCall.invitingTimes++; return true; } } return false; } public boolean directcallMake(String number) { if (SIPController.sipCall == null || SIPController.sipCall.flag == true) return false; if (true == cmcore.makeDirectcallMake(SIPController.sipCall, number)) { if (SIPController.sipCall.message.length() > 0 && mSIPSignalReceiver != null) { byte[] buffer = SIPController.sipCall.message.getBytes(); if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, SIPController.sipCall.message); int repeatSendCount = 0; while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) { if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort, buffer, buffer.length)) { // INVITING break; } repeatSendCount++; } SIPController.sipCall.callTime_T0 = new Date(); SIPController.sipCall.callTime_T00 = new Date(); SIPController.sipCall.invitingTimes++; } return true; } return false; } public boolean sendReInvite() { if (true == cmcore.makeSendReInvite(SIPController.sipCall)) { if (SIPController.sipCall.message.length() > 0 && mSIPSignalReceiver != null) { byte[] buffer = SIPController.sipCall.message.getBytes(); if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, SIPController.sipCall.message); int repeatSendCount = 0; while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) { if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort, buffer, buffer.length)) { break; } repeatSendCount++; } SIPController.sipCall.callTime_T00 = new Date(); SIPController.sipCall.invitingTimes++; return true; } } return false; } public boolean sendRepeatInvite() { if (SIPController.sipCall == null || SIPController.sipCall.flag == false) return false; if (SIPController.sipCall.message == null || SIPController.sipCall.message.length() == 0) return false; if (SIPController.sipCall.message.length() > 0 && mSIPSignalReceiver != null) { byte[] buffer = SIPController.sipCall.message.getBytes(); if (SIPController.sipCall.message.length() > 0) { if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, SIPController.sipCall.message); int repeatSendCount = 0; while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) { if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort, buffer, buffer.length)) { break; } repeatSendCount++; } SIPController.sipCall.callTime_T00 = new Date(); SIPController.sipCall.invitingTimes++; } } return true; } public boolean sendRedirectCall(String message) { if (true == cmcore.makeSendRedirectCall(SIPController.sipCall, message)) { if (SIPController.sipCall.message.length() > 0 && mSIPSignalReceiver != null) { byte[] buffer = new byte[SIPController.sipCall.message.length()]; SIPController.sipCall.message.getBytes(0, SIPController.sipCall.message.length(), buffer, 0); if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, SIPController.sipCall.message); int repeatSendCount = 0; while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) { if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort, buffer, buffer.length)) { break; } repeatSendCount++; } SIPController.sipCall.callState = SIPStack.SIP_CALLSTATE_INVITING; SIPController.sipCall.callDirection = SIPStack.SIP_CALLDIRECTION_OUT; SIPController.sipCall.callTime_T0 = new Date(); SIPController.sipCall.invitingTimes++; return true; } } else { SIPController.sipCall.resetCall(); } return false; } public boolean reactionForWWWAUTHENTICATE(String message) { if (true == cmcore.makeReactionForWWWAUTHENTICATE(SIPController.sipCall, message)) { if (SIPController.sipCall.message.length() > 0 && mSIPSignalReceiver != null) { byte[] buffer = SIPController.sipCall.message.getBytes(); if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, SIPController.sipCall.message); int repeatSendCount = 0; while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) { if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort, buffer, buffer.length)) { mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort, buffer, buffer.length); break; } repeatSendCount++; } SIPController.sipCall.callTime_T0 = new Date(); SIPController.sipCall.callTime_T00 = new Date(); return true; } } return false; } public boolean reactionForPROXYAUTHENTICATE(String message) { if (true == cmcore.makeReactionForPROXYAUTHENTICATE(SIPController.sipCall, message)) { if (SIPController.sipCall.message.length() > 0 && mSIPSignalReceiver != null) { byte[] buffer = SIPController.sipCall.message.getBytes(); if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, SIPController.sipCall.message); int repeatSendCount = 0; while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) { if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort, buffer, buffer.length)) { mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort, buffer, buffer.length); break; } repeatSendCount++; } SIPController.sipCall.callTime_T0 = new Date(); SIPController.sipCall.callTime_T00 = new Date(); return true; } } return false; } public boolean sendProceeding(String remoteIp, int remotePort) { String sendmessage = cmcore.makeSendProceeding(SIPController.sipCall); if (sendmessage.length() > 0 && mSIPSignalReceiver != null) { byte[] buffer = sendmessage.getBytes(); if (sendmessage.length() > 0) { if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, sendmessage); SIPController.sipCall.callTime_T6 = new Date(); int repeatSendCount = 0; while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) { if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(remoteIp, remotePort, buffer, buffer.length)) { break; } repeatSendCount++; } } } return true; } //MultiCall Proceeding public boolean sendPendingProceeding(String remoteIp, int remotePort) { String sendmessage = cmcore.makeSendProceeding(SIPController.pendingCall); if (sendmessage.length() > 0 && mSIPSignalReceiver != null) { byte[] buffer = sendmessage.getBytes(); if (sendmessage.length() > 0) { if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, sendmessage); SIPController.pendingCall.callTime_T6 = new Date(); int repeatSendCount = 0; while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) { if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(remoteIp, remotePort, buffer, buffer.length)) { break; } repeatSendCount++; } } } return true; } public boolean sendProgressing(String remoteIp, int remotePort) { if (SIPController.sipCall == null || SIPController.sipCall.flag == false) return false; String sendmessage = cmcore.makeSendProgressing(SIPController.sipCall); if (sendmessage.length() > 0 && mSIPSignalReceiver != null) { byte[] buffer = sendmessage.getBytes(); if (sendmessage.length() > 0) { if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, sendmessage); SIPController.sipCall.callTime_T6 = new Date(); int repeatSendCount = 0; while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) { if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(remoteIp, remotePort, buffer, buffer.length)) { break; } repeatSendCount++; } } } return true; } //Multicall Progressing public boolean sendPendingProgressing(String remoteIp, int remotePort) { if (SIPController.pendingCall == null || SIPController.pendingCall.flag == false) return false; String sendmessage = cmcore.makeSendProgressing(SIPController.pendingCall); if (sendmessage.length() > 0 && mSIPSignalReceiver != null) { byte[] buffer = sendmessage.getBytes(); if (sendmessage.length() > 0) { if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, sendmessage); SIPController.pendingCall.callTime_T6 = new Date(); int repeatSendCount = 0; while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) { if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(remoteIp, remotePort, buffer, buffer.length)) { break; } repeatSendCount++; } } } return true; } public boolean sendProgressingwithbody(String remoteIp, int remotePort) { Log.d(TAG, "[sendProgressingwithbody] remoteIp [" + remoteIp + "], remotePort [" + remotePort + "]"); if (SIPController.sipCall == null || SIPController.sipCall.flag == false) return false; if (SIPController.sipCall.callDirection == SIPStack.SIP_CALLDIRECTION_IN && SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_OFFERRED) { String sendmessage = cmcore.makeSendProgressingwithbody(SIPController.sipCall); if (sendmessage.length() > 0 && mSIPSignalReceiver != null) { byte[] buffer = sendmessage.getBytes(); if (sendmessage.length() > 0) { if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, sendmessage); SIPController.sipCall.callTime_T6 = new Date(); int repeatSendCount = 0; while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) { if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort, buffer, buffer.length)) { break; } repeatSendCount++; } if (SIPController.sipCall.remoteSdp != null && SIPController.sipCall.remoteSdp.flag == true && SIPController.audioRTPManager != null) { if (SIPController.sipCall.remoteSdp.audioM != null && SIPController.sipCall.remoteSdp.audioM.flag == true) { if (SIPController.sipCall.sdp != null && SIPController.sipCall.sdp.audioM != null && SIPController.audioRTPManager != null) { SIPController.audioRTPManager.setRemoteMediaInfo(SIPController.sipCall.remoteSdp.audioM.commonCodec, SIPController.sipCall.remoteSdp.audioM.mediaIp, SIPController.sipCall.remoteSdp.audioM.mediaPort); if (SIPStack.bDirectCall == true) { // SERVICE MESSAGE NEEDED dialerVideoSet(true); } } } } } } } return true; } public boolean sendProgressingBlackcallwithbody(String remoteIp, int remotePort) { if (SIPController.sipCall == null || SIPController.sipCall.flag == false) return false; if (SIPController.sipCall.callDirection == SIPStack.SIP_CALLDIRECTION_IN && SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_OFFERRED) { String sendmessage = cmcore.makeSendProgressingwithbody(SIPController.sipCall); if (sendmessage.length() > 0 && mSIPSignalReceiver != null) { byte[] buffer = sendmessage.getBytes(); if (sendmessage.length() > 0) { if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, sendmessage); SIPController.sipCall.callTime_T6 = new Date(); int repeatSendCount = 0; while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) { if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort, buffer, buffer.length)) { break; } repeatSendCount++; } if (SIPController.sipCall.remoteSdp != null && SIPController.sipCall.remoteSdp.flag == true && SIPController.audioRTPManager != null) { if (SIPController.sipCall.remoteSdp.audioM != null && SIPController.sipCall.remoteSdp.audioM.flag == true) { if (SIPController.sipCall.sdp != null && SIPController.sipCall.sdp.audioM != null && SIPController.audioRTPManager != null) { SIPController.audioRTPManager.setRemoteMediaInfo(SIPController.sipCall.remoteSdp.audioM.commonCodec, SIPController.sipCall.remoteSdp.audioM.mediaIp, SIPController.sipCall.remoteSdp.audioM.mediaPort); //if(SIPStack.bDirectCall==true) { //SERVICE MESSAGE NEEDED // dialerVideoSet(true); //} } } } } } } return true; } public boolean acceptCancelRequest(String strMessage, String strRemoteIP, int strRemotePort) { try { LOG("[acceptCancelRequest] strMessage [" + strMessage + "], strRemoteIP [" + strRemoteIP + "], strRemotePort [" + strRemotePort + "]"); String strSendMessage = cmcore.makeAcceptCancelRequest(SIPController.sipCall, strMessage); if (strSendMessage.length() > 0 && mSIPSignalReceiver != null) { byte[] buffer = strSendMessage.getBytes(); if (strSendMessage.length() > 0) { if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, strMessage); SIPController.sipCall.callTime_T8 = new Date(); int repeatSendCount = 0; while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) { if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(strRemoteIP, strRemotePort, buffer, buffer.length)) { break; } repeatSendCount++; } } return true; } return false; } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); return false; } catch (Exception e) { Log.e(TAG, "acceptCancelRequest(String strMessage, String strRemoteIP, int strRemotePort)"); return false; } } public boolean acceptPendingCancelRequest(String message, String remoteIp, int remotePort) { String sendmessage = cmcore.makeAcceptCancelRequest(SIPController.pendingCall, message); if (sendmessage.length() > 0 && mSIPSignalReceiver != null) { byte[] buffer = sendmessage.getBytes(); if (sendmessage.length() > 0) { if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, sendmessage); // if (SIPStack.SIP_MESSAGE_DEBUG == true) Log.i(TAG, "SENT\n" + sendmessage); SIPController.pendingCall.callTime_T8 = new Date(); int repeatSendCount = 0; while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) { if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(remoteIp, remotePort, buffer, buffer.length)) { break; } repeatSendCount++; } } return true; } return false; } public boolean sendAccept() { Log.d(TAG, "[sendAccept]"); String sendmessage = cmcore.makeSendAccept(SIPController.sipCall); if (sendmessage.length() > 0 && mSIPSignalReceiver != null) { byte[] buffer = sendmessage.getBytes(); if (sendmessage.length() > 0) { if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, sendmessage); SIPController.sipCall.callTime_T3 = new Date(); int repeatSendCount = 0; while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) { if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort, buffer, buffer.length)) { break; } repeatSendCount++; } SIPController.sipCall.callState = SIPStack.SIP_CALLSTATE_ACCEPTED; if (SIPController.sipCall.remoteSdp != null && SIPController.sipCall.remoteSdp.flag == true && SIPController.audioRTPManager != null) { if (SIPController.sipCall.remoteSdp.audioM != null && SIPController.sipCall.remoteSdp.audioM.flag == true) { if (SIPController.sipCall.sdp != null && SIPController.sipCall.sdp.audioM != null && SIPController.audioRTPManager != null) { SIPController.audioRTPManager.setRemoteMediaInfo(SIPController.sipCall.remoteSdp.audioM.commonCodec, SIPController.sipCall.remoteSdp.audioM.mediaIp, SIPController.sipCall.remoteSdp.audioM.mediaPort); SIPController.audioRTPManager.RTPInit(SIPController.sipCall.sdp.audioM.mediaPort, 6); if (SIPStack.bDirectCall == true) { // SERVICE MESSAGE NEEDED dialerVideoSet(true); } } } } } return true; } else return false; } public boolean directsendAccept(boolean bMobile) { try { LOG_INFO("[directsendAccept] bMobile [" + bMobile + "]"); String sendmessage = cmcore.makeDirectsendAccept(SIPController.sipCall); if (sendmessage.length() > 0 && mSIPSignalReceiver != null) { byte[] buffer = sendmessage.getBytes(); if (sendmessage.length() > 0) { if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, sendmessage); SIPController.sipCall.callTime_T3 = new Date(); int repeatSendCount = 0; while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) { if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort, buffer, buffer.length)) { break; } repeatSendCount++; } SIPController.sipCall.callState = SIPStack.SIP_CALLSTATE_ACCEPTED; if (SIPController.sipCall.remoteSdp != null && SIPController.sipCall.remoteSdp.flag == true && SIPController.audioRTPManager != null) { if (SIPController.sipCall.remoteSdp.audioM != null && SIPController.sipCall.remoteSdp.audioM.flag == true) { if (SIPController.sipCall.sdp != null && SIPController.sipCall.sdp.audioM != null && SIPController.audioRTPManager != null) { SIPController.audioRTPManager.setRemoteMediaInfo(SIPController.sipCall.remoteSdp.audioM.commonCodec, SIPController.sipCall.remoteSdp.audioM.mediaIp, SIPController.sipCall.remoteSdp.audioM.mediaPort); LOG_INFO("[directsendAccept] SIPController.audioRTPManager.rtpCore.bActive [" + SIPController.audioRTPManager.rtpCore.bActive + "]"); if (SIPController.audioRTPManager.rtpCore.bActive == false) { if (bMobile) SIPController.audioRTPManager.RTPRemoteCallInit(SIPController.sipCall.sdp.audioM.mediaPort); else SIPController.audioRTPManager.RTPInit(SIPController.sipCall.sdp.audioM.mediaPort, 7); } if (SIPStack.bDirectCall == true) { // SERVICE MESSAGE NEEDED dialerVideoSet(true); } } } } } return true; } return false; } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); return false; } catch (Exception e) { Log.e(TAG, "[Exception] directsendAccept()"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); return false; } } public boolean sendUpdateAccept() { Log.d(TAG, "[sendUpdateAccept]"); String sendmessage = cmcore.makeSendUpdateAccept(SIPController.sipCall); if (sendmessage.length() > 0 && mSIPSignalReceiver != null) { byte[] buffer = sendmessage.getBytes(); if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, sendmessage); SIPController.sipCall.callTime_T6 = new Date(); int repeatSendCount = 0; while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) { if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort, buffer, buffer.length)) { break; } repeatSendCount++; } SIPController.sipCall.callState = SIPStack.SIP_CALLSTATE_UPDATEACCEPTED; if (SIPController.sipCall.remoteSdp != null && SIPController.sipCall.remoteSdp.flag == true && SIPController.audioRTPManager != null) { if (SIPController.sipCall.remoteSdp.audioM != null && SIPController.sipCall.remoteSdp.audioM.flag == true) { if (SIPController.audioRTPManager != null) { SIPController.audioRTPManager.setRemoteMediaInfo(SIPController.sipCall.remoteSdp.audioM.commonCodec, SIPController.sipCall.remoteSdp.audioM.mediaIp, SIPController.sipCall.remoteSdp.audioM.mediaPort); if (SIPController.sipCall.sdp != null && SIPController.sipCall.sdp.audioM != null && SIPController.audioRTPManager.rtpCore.bActive == false) { SIPController.audioRTPManager.RTPInit(SIPController.sipCall.sdp.audioM.mediaPort, 8); } } } } return true; } return false; } public boolean rejectCall(int code) { String sendmessage = cmcore.makeRejectCall(SIPController.sipCall, code); if (sendmessage.length() > 0 && mSIPSignalReceiver != null) { byte[] buffer = sendmessage.getBytes(); if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, sendmessage); SIPController.sipCall.callTime_T6 = new Date(); int repeatSendCount = 0; while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) { if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort, buffer, buffer.length)) { break; } repeatSendCount++; } SIPController.sipCall.callState = SIPStack.SIP_CALLSTATE_TERMINATING; Log.i(TAG, "rejectCall code : " + code); // Phone status set // SERVICE MESSAGE NEEDED updateDialerStatus("Call reject.", true); return true; } return false; } public boolean redirectResponse(String contact) { String sendmessage = cmcore.makeRejectCall(SIPController.sipCall, 302, contact); if (sendmessage.length() > 0 && mSIPSignalReceiver != null) { byte[] buffer = sendmessage.getBytes(); if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, sendmessage); SIPController.sipCall.callTime_T6 = new Date(); int repeatSendCount = 0; while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) { if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort, buffer, buffer.length)) { break; } repeatSendCount++; } SIPController.sipCall.callState = SIPStack.SIP_CALLSTATE_TERMINATING; // Phone status set // SERVICE MESSAGE NEEDED updateDialerStatus("Call reject.", true); return true; } return false; } public boolean rejectPendingCall(int code) { Log.i("SIPStun", ">>>rejectPendingCall debug 1 " + SIPController.pendingCall.remoteIp + " port:" + SIPController.pendingCall.remotePort); String sendmessage = cmcore.makeRejectCall(SIPController.pendingCall, code); if (sendmessage.length() > 0 && mSIPSignalReceiver != null) { byte[] buffer = sendmessage.getBytes(); if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, sendmessage); SIPController.pendingCall.callTime_T6 = new Date(); int repeatSendCount = 0; while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) { if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.pendingCall.remoteIp, SIPController.pendingCall.remotePort, buffer, buffer.length)) { break; } repeatSendCount++; } SIPController.pendingCall.callState = SIPStack.SIP_CALLSTATE_TERMINATING; } return true; } public boolean rejectCall(String message, int code, String remoteIp, int remotePort) { String sendmessage = cmcore.makeRejectCall(message, code, cmcore.localIp, cmcore.localPort, remoteIp, remotePort); if (sendmessage.length() > 0 && mSIPSignalReceiver != null) { byte[] buffer = sendmessage.getBytes(); if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, sendmessage); int repeatSendCount = 0; while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) { if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(remoteIp, remotePort, buffer, buffer.length)) { break; } repeatSendCount++; } } return true; } public boolean redirectIncomingCall(String redirectId) { String sendmessage = cmcore.makeRedirectIncomingCall(SIPController.sipCall, redirectId); if (sendmessage.length() > 0 && mSIPSignalReceiver != null) { // Phone status set // SERVICE MESSAGE NEEDED updateDialerStatus("Call forwarding to " + redirectId, true); byte[] buffer = sendmessage.getBytes(); if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, sendmessage); SIPController.sipCall.callTime_T6 = new Date(); int repeatSendCount = 0; while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) { if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort, buffer, buffer.length)) { break; } repeatSendCount++; } SIPController.sipCall.callState = SIPStack.SIP_CALLSTATE_TERMINATING; return true; } return false; } public boolean sendProgressing(String body, String remoteIp, int remotePort) { String sendmessage = cmcore.makeSendProgressing(SIPController.sipCall, body); if (sendmessage.length() > 0 && mSIPSignalReceiver != null) { byte[] buffer = sendmessage.getBytes(); if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, sendmessage); SIPController.sipCall.callTime_T6 = new Date(); int repeatSendCount = 0; while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) { if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(remoteIp, remotePort, buffer, buffer.length)) { break; } repeatSendCount++; } } return true; } public boolean sendAck(String message) { if (true == cmcore.makeSendAck(SIPController.sipCall, message)) { if (SIPController.sipCall.message.length() > 0 && mSIPSignalReceiver != null) { byte[] buffer = SIPController.sipCall.message.getBytes(); if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, SIPController.sipCall.message); SIPController.sipCall.callTime_T4 = new Date(); SIPController.sipCall.callTime_T40 = new Date(); if (SIPController.sipCall.routeIp != null && SIPController.sipCall.routeIp.length() > 0 && SIPController.sipCall.routePort > 0) { int repeatSendCount = 0; while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) { if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.routeIp, SIPController.sipCall.routePort, buffer, buffer.length)) { break; } repeatSendCount++; } } else { int repeatSendCount = 0; while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) { if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort, buffer, buffer.length)) { break; } repeatSendCount++; } } return true; } } return false; } public boolean sendFinalAck(String message) { if (true == cmcore.makeSendFinalAck(SIPController.sipCall, message)) { if (SIPController.sipCall.message.length() > 0 && mSIPSignalReceiver != null) { byte[] buffer = SIPController.sipCall.message.getBytes(); if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, SIPController.sipCall.message); // if (SIPStack.SIP_MESSAGE_DEBUG == true) Log.i(TAG, "SEND\n" + SIPController.sipCall.message); if (SIPController.sipCall.routeIp != null && SIPController.sipCall.routeIp.length() > 0 && SIPController.sipCall.routePort > 0) { int repeatSendCount = 0; while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) { if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.routeIp, SIPController.sipCall.routePort, buffer, buffer.length)) { mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.routeIp, SIPController.sipCall.routePort, buffer, buffer.length); mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.routeIp, SIPController.sipCall.routePort, buffer, buffer.length); break; } repeatSendCount++; } } else { int repeatSendCount = 0; while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) { if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort, buffer, buffer.length)) { mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort, buffer, buffer.length); mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort, buffer, buffer.length); break; } repeatSendCount++; } } return true; } } return false; } public boolean sendFinalAck(String message, String remoteIp, int remotePort) { String sendmessage = cmcore.makeSendFinalAck(SIPController.sipCall, message, remoteIp, remotePort); if (sendmessage.length() > 0 && mSIPSignalReceiver != null) { byte[] buffer = sendmessage.getBytes(); if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, sendmessage); if (remoteIp != null && remoteIp.length() > 0 && remotePort > 0) { int repeatSendCount = 0; while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) { if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(remoteIp, remotePort, buffer, buffer.length)) { mSIPSignalReceiver.BSSSipSendUdpPacket(remoteIp, remotePort, buffer, buffer.length); mSIPSignalReceiver.BSSSipSendUdpPacket(remoteIp, remotePort, buffer, buffer.length); break; } } return true; } } return false; } public boolean sendRedirectFinalAck(String message) { if (true == cmcore.makeSendRedirectFinalAck(SIPController.sipCall, message)) { if (SIPController.sipCall.message.length() > 0 && mSIPSignalReceiver != null) { byte[] buffer = SIPController.sipCall.message.getBytes(); if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, SIPController.sipCall.message); if (SIPController.sipCall.routeIp != null && SIPController.sipCall.routeIp.length() > 0 && SIPController.sipCall.routePort > 0) { int repeatSendCount = 0; while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) { if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.routeIp, SIPController.sipCall.routePort, buffer, buffer.length)) { break; } repeatSendCount++; } } else { int repeatSendCount = 0; while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) { if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort, buffer, buffer.length)) { break; } repeatSendCount++; } } return true; } } return false; } // REJECT OR BYE OR CANCEL public boolean callTerminate() { if (SIPController.sipCall == null || SIPController.sipCall.flag == false) { return false; } SIPController.sipCall.bCancelRequest = false; if (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_CONNECTED || SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_ACCEPTED || SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_REMOTEACCEPTED) { // Phone status set // SERVICE MESSAGE NEEDED updateDialerStatus("Call disconnecting./" + SIPController.sipCall.dnis, false); int duration = 0; Date currentTime = new Date(); if (SIPController.sipCall.callTime_T4 != null) { duration = (int) (currentTime.getTime() - SIPController.sipCall.callTime_T4.getTime()) / 1000; if (SIPController.sipCall.callDirection == SIPStack.SIP_CALLDIRECTION_IN) duration -= 1; if (duration < 0) duration = 0; } if (SIPController.audioRTPManager != null) SIPController.audioRTPManager.RTPEnd(25); if (SIPStack.bDirectCall == true) { // SERVICE MESSAGE NEEDED dialerVideoSet(false); } return sendBye(); } else if (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_INVITING || SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_PROCEEDING || SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_PROGRESSING) { // Phone status set // SERVICE MESSAGE NEEDED updateDialerStatus("Call cancelling./" + SIPController.sipCall.dnis, false); rejectPendingCall(480); //rejectCall(486); if (SIPController.audioRTPManager != null) SIPController.audioRTPManager.RTPEnd(26); if (SIPStack.bDirectCall == true) { // SERVICE MESSAGE NEEDED dialerVideoSet(false); } return sendCancel(); } else if (SIPController.sipCall.callDirection == SIPStack.SIP_CALLDIRECTION_IN && (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_OFFERRED || SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_CANCELLED)) { // Phone status set // SERVICE MESSAGE NEEDED if (SIPController.bSinglecallBusyResponse == true) { SIPController.bSinglecallBusyResponse = false; updateDialerStatus("Busy Call reject./" + SIPController.sipCall.dnis, false); return rejectCall(486); } else { updateDialerStatus("Call reject./" + SIPController.sipCall.dnis, false); return rejectCall(480); } } else if (SIPController.sipCall.flag == true && SIPController.sipCall.callState != SIPStack.SIP_CALLSTATE_TERMINATING) { if (SIPController.audioRTPManager != null) SIPController.audioRTPManager.RTPEnd(27); if (SIPStack.bDirectCall == true) { // SERVICE MESSAGE NEEDED dialerVideoSet(false); } // SERVICE MESSAGE NEEDED dialerNotifyCallEnd("", SIPController.sipCall.dnis, SIPController.sipCall.dnis + "@" + SIPController.sipCall.remoteIp + ":" + SIPController.sipCall.remotePort, false); SIPController.sipCall.resetCall(); } else { Log.e(TAG, "[callTerminate] NO IF"); } return true; } // Redirect response public boolean redirectTerminate(String contact) { if (SIPController.sipCall == null || SIPController.sipCall.flag == false) { return false; } LOG_INFO("[redirectTerminate] contact [" + contact + "]"); SIPController.sipCall.bForwardRequest = false; if (SIPController.sipCall.callDirection == SIPStack.SIP_CALLDIRECTION_IN && (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_OFFERRED)) { // Phone status set // SERVICE MESSAGE NEEDED LOG_INFO("[redirectTerminate] BSSVideo.HNS_SERVICE_RECEIVER_SELECTED [" + BSSVideo.HNS_SERVICE_RECEIVER_SELECTED + "]"); LOG_INFO("[redirectTerminate] SIPController.sipCall.remoteIp : " + SIPController.sipCall.remoteIp); LOG_INFO("[redirectTerminate] SIPController.sipCall.number : " + SIPController.sipCall.number); LOG_INFO("[redirectTerminate] SIPController.sipCall.cid : " + SIPController.sipCall.cid); LOG_INFO("[redirectTerminate] SIPController.sipCall.dnis : " + SIPController.sipCall.dnis); LOG_INFO("[redirectTerminate] SIPController.sipCall.dong_number : " + SIPController.sipCall.dong_number); LOG_INFO("[redirectTerminate] SIPController.sipCall.ho_number : " + SIPController.sipCall.ho_number); LOG_INFO("[redirectTerminate] SIPController.sipCall.id : " + SIPController.sipCall.id); updateDialerStatus("Call forwarded.", false); return redirectResponse(contact); } else if (SIPController.sipCall.flag == true && SIPController.sipCall.callState != SIPStack.SIP_CALLSTATE_TERMINATING) { if (SIPController.audioRTPManager != null) SIPController.audioRTPManager.RTPEnd(28); if (SIPStack.bDirectCall == true) { // SERVICE MESSAGE NEEDED dialerVideoSet(false); } // SERVICE MESSAGE NEEDED dialerNotifyCallEnd("", SIPController.sipCall.dnis, SIPController.sipCall.dnis + "@" + SIPController.sipCall.remoteIp + ":" + SIPController.sipCall.remotePort, false); SIPController.sipCall.resetCall(); } return true; } // BYE public boolean sendBye() { if (SIPController.sipCall == null || SIPController.sipCall.flag == false) return false; if (true == cmcore.makeBye(SIPController.sipCall)) { if (SIPController.sipCall.message.length() > 0 && mSIPSignalReceiver != null) { byte[] buffer = SIPController.sipCall.message.getBytes(); if (SIPController.sipCall.message.length() > 0) { if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, SIPController.sipCall.message); SIPController.sipCall.callTime_T5 = new Date(); SIPController.sipCall.callTime_T6 = new Date(); SIPController.sipCall.callTime_T9 = new Date(); SIPController.sipCall.bByedisconnected = true; SIPController.sipCall.callState = SIPStack.SIP_CALLSTATE_DISCONNECTING; int repeatSendCount = 0; while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) { if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort, buffer, buffer.length)) { mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort, buffer, buffer.length); mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort, buffer, buffer.length); break; } repeatSendCount++; } } } return true; } return false; } public boolean resendBye() { if (SIPController.sipCall == null || SIPController.sipCall.flag == false) return false; if (SIPController.sipCall.callState != SIPStack.SIP_CALLSTATE_DISCONNECTING) return false; if (true == cmcore.makeReBye(SIPController.sipCall)) { if (SIPController.sipCall.message.length() > 0 && mSIPSignalReceiver != null) { byte[] buffer = SIPController.sipCall.message.getBytes(); if (SIPController.sipCall.message.length() > 0) { if (bPrintSIPMsg) printSIPMessage(MESSAGE.RESEND, SIPController.sipCall.message); SIPController.sipCall.callTime_T9 = new Date(); SIPController.sipCall.bByedisconnected = true; int repeatSendCount = 0; while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) { if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort, buffer, buffer.length)) { mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort, buffer, buffer.length); mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort, buffer, buffer.length); break; } repeatSendCount++; } } } return true; } return false; } public boolean sendByeResponse(String message, String remoteIp, int remotePort) { String sendmessage = cmcore.makeSendByeResponse(SIPController.sipCall, message); if (sendmessage.length() > 0 && mSIPSignalReceiver != null) { byte[] buffer = sendmessage.getBytes(); if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, sendmessage); // if (SIPStack.SIP_MESSAGE_DEBUG == true) Log.i(TAG, "SENT\n" + sendmessage); SIPController.sipCall.callTime_T6 = new Date(); int repeatSendCount = 0; while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) { if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(remoteIp, remotePort, buffer, buffer.length)) { mSIPSignalReceiver.BSSSipSendUdpPacket(remoteIp, remotePort, buffer, buffer.length); mSIPSignalReceiver.BSSSipSendUdpPacket(remoteIp, remotePort, buffer, buffer.length); break; } repeatSendCount++; } } return true; } // CANCEL public boolean sendCancel() { if (SIPController.sipCall == null || SIPController.sipCall.flag == false) return false; if (true == cmcore.makeCancel(SIPController.sipCall)) { if (SIPController.sipCall.message.length() > 0 && mSIPSignalReceiver != null) { byte[] buffer = SIPController.sipCall.message.getBytes(); if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, SIPController.sipCall.message); // if (SIPStack.SIP_MESSAGE_DEBUG == true) Log.i(TAG, "SEND\n" + SIPController.sipCall.message); SIPController.sipCall.callTime_T8 = new Date(); SIPController.sipCall.callState = SIPStack.SIP_CALLSTATE_CANCELLING; int repeatSendCount = 0; while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) { if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort, buffer, buffer.length)) { break; } repeatSendCount++; } return true; } } return false; } public boolean sendRecancel() { //Log.i(TAG, "RECANCELLING"); if (SIPController.sipCall == null || SIPController.sipCall.flag == false) return false; if (true == cmcore.makeRecancel(SIPController.sipCall)) { if (SIPController.sipCall.message.length() > 0 && mSIPSignalReceiver != null) { byte[] buffer = SIPController.sipCall.message.getBytes(); if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, SIPController.sipCall.message); // if (SIPStack.SIP_MESSAGE_DEBUG == true) Log.i(TAG, "SEND\n" + SIPController.sipCall.message); SIPController.sipCall.callTime_T8 = new Date(); SIPController.sipCall.callState = SIPStack.SIP_CALLSTATE_RECANCELLING; int repeatSendCount = 0; while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) { if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort, buffer, buffer.length)) { break; } repeatSendCount++; } return true; } } return false; } // OPTIONS public boolean sendOptionsResponse(String message, String remoteIp, int remotePort, int code) { String sendmessage = cmcore.makeSendOptionsResponse(SIPController.sipCall, message, code); if (sendmessage.length() > 0 && mSIPSignalReceiver != null) { byte[] buffer = sendmessage.getBytes(); if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, sendmessage); int repeatSendCount = 0; while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) { if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(remoteIp, remotePort, buffer, buffer.length)) { break; } repeatSendCount++; } return true; } return false; } //INFO public boolean sendInfoResponse(String message, String remoteIp, int remotePort, int code) { String sendmessage = cmcore.makeSendInfoResponse(SIPController.sipCall, message, code); if (sendmessage.length() > 0 && mSIPSignalReceiver != null) { byte[] buffer = sendmessage.getBytes(); if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, sendmessage); int repeatSendCount = 0; while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) { if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(remoteIp, remotePort, buffer, buffer.length)) { break; } repeatSendCount++; } } else return false; // DTMF PARSE SIPHeader sipHeader = new SIPHeader(message, SIPStack.SIP_HEADERTYPE_CONTENTTYPE); if (sipHeader != null && sipHeader.flag == true && sipHeader.headerValue != null && sipHeader.headerValue.length() > 0) { if (sipHeader.headerValue.compareTo("application/dtmf-relay") == 0) { // DTMF-RELAY TYPE if (SIPController.sipCall != null && SIPController.sipCall.flag == true && SIPController.sipCall.parseDtmfSdp(message, SIPStack.SIP_DTMFINFO_DTMFRELAY) == true) { // SERVICE MESSAGE NEEDED dialerNotifyDtmf(SIPController.sipCall.detectedDtmf); } } else if (sipHeader.headerValue.compareTo("application/dtmf") == 0) { // DTMF TYPE if (SIPController.sipCall != null && SIPController.sipCall.flag == true && SIPController.sipCall.parseDtmfSdp(message, SIPStack.SIP_DTMFINFO_DTMF) == true) { // SERVICE MESSAGE NEEDED dialerNotifyDtmf(SIPController.sipCall.detectedDtmf); } } } return true; } // OPTIONS public boolean sendMessageResponse(String message, String remoteIp, int remotePort, int code) { String sendmessage = cmcore.makeSendInfoResponse(SIPController.sipCall, message, code); if (sendmessage.length() > 0 && mSIPSignalReceiver != null) { byte[] buffer = sendmessage.getBytes(); if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, sendmessage); int repeatSendCount = 0; while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) { if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(remoteIp, remotePort, buffer, buffer.length)) { break; } repeatSendCount++; } return true; } return false; } public boolean sendUpdate() { if (true == cmcore.makeSendUpdate(SIPController.sipCall)) { if (SIPController.sipCall.message.length() > 0 && mSIPSignalReceiver != null) { byte[] buffer = SIPController.sipCall.message.getBytes(); if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, SIPController.sipCall.message); int repeatSendCount = 0; while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) { if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort, buffer, buffer.length)) { break; } repeatSendCount++; } SIPController.sipCall.callTime_T0 = new Date(); return true; } } return false; } public boolean sendUpdate(String flow) { if (true == cmcore.makeSendUpdate(SIPController.sipCall, flow)) { if (SIPController.sipCall.message.length() > 0 && mSIPSignalReceiver != null) { byte[] buffer = SIPController.sipCall.message.getBytes(); if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, SIPController.sipCall.message); int repeatSendCount = 0; while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) { if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort, buffer, buffer.length)) { break; } repeatSendCount++; } SIPController.sipCall.callTime_T0 = new Date(); return true; } } return false; } public void sendHold() { if (SIPController.sipCall != null && SIPController.sipCall.flag == true && SIPController.sipCall.callMode == SIPStack.SIP_CALLMODE_BASIC && SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_CONNECTED) { if (SIPController.sipCall.bHolding == true) { SIPController.sipCall.bHolding = false; sendUpdate("sendrecv"); if (SIPController.sipSound != null) SIPController.sipSound.flowIndicator = SIPStack.SIP_MEDIAFLOW_SENDRECV; } else { SIPController.sipCall.bHolding = true; sendUpdate(); if (SIPController.sipSound != null) SIPController.sipSound.flowIndicator = SIPStack.SIP_MEDIAFLOW_SENDONLY; } } } public void updateDialerStatus(String arg1, boolean bSet) { Log.d(TAG, "[updateDialerStatus] arg1 [" + arg1 + "], bSet [" + bSet + "]"); for (int i = mClients.size() - 1; i >= 0; i--) { try { // Send data as a String Bundle b = new Bundle(); b.putString("UPDATESTATUS", arg1); Message msg = null; if (bSet == true) msg = Message.obtain(null, CMCore.BSSSIPStun_ICONTROLS_CM_UPDATESTATUS_TRUE); else msg = Message.obtain(null, CMCore.BSSSIPStun_ICONTROLS_CM_UPDATESTATUS_FALSE); msg.setData(b); mClients.get(i).send(msg); // Log.d(TAG, "[updateDialerStatus]" + MainActivity.mCallController.mCallInfo.getRESI().toString()); // if(MainActivity.mCallController.mCallInfo.getRESI() == CallManager.CALLSTATUS.IDLE) { // Log.d(TAG, "[updateDialerStatus]" + MainActivity.mCallController.mCallInfo.getRESI().toString()); //rejectPendingCall(480); //rejectCall(m_strMessage, 487, m_strRemoteIP, m_strRemotePort); //Thread.sleep(1000); // } } catch (RemoteException e) { Log.e(TAG, "[RemoteException] updateDialerStatus(String arg1, boolean bSet)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); mClients.remove(i); } catch (Exception e) { Log.e(TAG, "[Exception] updateDialerStatus(String arg1, boolean bSet)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } } } public void dialerVideoSet(boolean bSet) { for (int i = mClients.size() - 1; i >= 0; i--) { try { // Send data as a String Bundle b = new Bundle(); b.putString("VIDEOSET", SIPController.sipCall.dnis); Message msg = null; if (bSet == true) msg = Message.obtain(null, CMCore.BSSSIPStun_ICONTROLS_CM_VIDEOSET_TRUE); else msg = Message.obtain(null, CMCore.BSSSIPStun_ICONTROLS_CM_VIDEOSET_FALSE); msg.setData(b); mClients.get(i).send(msg); } catch (RemoteException e) { Log.e(TAG, "[RemoteException] dialerVideoSet(boolean bSet)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); mClients.remove(i); } catch (Exception e) { Log.e(TAG, "[Exception] dialerVideoSet(boolean bSet)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } } } public void dialerNotifyIncomingCall(String dn, String uri) { Log.i(TAG, "[dialerNotifyIncomingCall] dn [" + dn + "], uri [" + uri + "], mClients.size() [" + mClients.size() + "]"); int nCnt = 0; while (mClients.size() == 0) { if (nCnt == 5) continue; nCnt++; try { Thread.sleep(100); } catch (InterruptedException e) { Log.e(TAG, "[InterruptedException] dialerNotifyIncomingCall(String dn, String uri)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } } for (int i = mClients.size() - 1; i >= 0; i--) { try { // Send data as a String Bundle b = new Bundle(); b.putString("INCOMINGCALL", dn + ";" + uri); Message msg = null; msg = Message.obtain(null, CMCore.BSSSIPStun_ICONTROLS_CM_INCOMINGCALL); msg.setData(b); mClients.get(i).send(msg); } catch (RemoteException e) { Log.e(TAG, "[RemoteException] dialerNotifyIncomingCall(String dn, String uri)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); mClients.remove(i); } catch (Exception e) { Log.e(TAG, "[Exception] dialerNotifyIncomingCall(String dn, String uri)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } } } public void dialerNotifyIncomingMultiCall(String dn, String uri) { // 멀티콜 사용을 위해 콜 정보를 임시로 저장한다. getMultiCallInfo(); for (int i = mClients.size() - 1; i >= 0; i--) { try { // Send data as a String Bundle b = new Bundle(); b.putString("INCOMINGMULTICALL", dn + ";" + uri); Message msg = null; msg = Message.obtain(null, CMCore.BSSSIPStun_ICONTROLS_CM_INCOMINGMULTICALL); msg.setData(b); mClients.get(i).send(msg); } catch (RemoteException e) { Log.e(TAG, "[RemoteException] dialerNotifyIncomingMultiCall(String dn,String uri)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); mClients.remove(i); } catch (Exception e) { Log.e(TAG, "[Exception] dialerNotifyIncomingMultiCall(String dn,String uri)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } } } private void getMultiCallInfo() { try { Log.d(TAG, "[getMultiCallInfo] SIPController.sipCall.bPending = " + SIPController.sipCall.bPending); Log.d(TAG, "[getMultiCallInfo] SIPController.sipCall.remoteIp = " + SIPController.sipCall.remoteIp); Log.d(TAG, "[getMultiCallInfo] SIPController.sipCall.remoteContactUri = " + SIPController.sipCall.remoteContactUri); Log.d(TAG, "[getMultiCallInfo] SIPController.sipCall.remoteContactIp = " + SIPController.sipCall.remoteContactIp); Log.d(TAG, "[getMultiCallInfo] SIPController.sipCall.cid = " + SIPController.sipCall.cid); Log.d(TAG, "[getMultiCallInfo] SIPController.sipCall.dnis = " + SIPController.sipCall.dnis); Log.d(TAG, "[getMultiCallInfo] SIPController.pendingCall.bPending = " + SIPController.pendingCall.bPending); Log.d(TAG, "[getMultiCallInfo] SIPController.pendingCall.remoteIp = " + SIPController.pendingCall.remoteIp); Log.d(TAG, "[getMultiCallInfo] SIPController.pendingCall.remoteContactUri = " + SIPController.pendingCall.remoteContactUri); Log.d(TAG, "[getMultiCallInfo] SIPController.pendingCall.remoteContactIp = " + SIPController.pendingCall.remoteContactIp); Log.d(TAG, "[getMultiCallInfo] SIPController.pendingCall.cid = " + SIPController.pendingCall.cid); Log.d(TAG, "[getMultiCallInfo] SIPController.pendingCall.dnis = " + SIPController.pendingCall.dnis); SIPController.MultiCall = new SIPCall(); SIPController.MultiCall = SIPController.pendingCall; Log.d(TAG, "[getMultiCallInfo] SIPController.MultiCall.bPending = " + SIPController.MultiCall.bPending); Log.d(TAG, "[getMultiCallInfo] SIPController.MultiCall.remoteIp = " + SIPController.MultiCall.remoteIp); Log.d(TAG, "[getMultiCallInfo] SIPController.MultiCall.remoteContactUri = " + SIPController.MultiCall.remoteContactUri); Log.d(TAG, "[getMultiCallInfo] SIPController.MultiCall.remoteContactIp = " + SIPController.MultiCall.remoteContactIp); Log.d(TAG, "[getMultiCallInfo] SIPController.MultiCall.cid = " + SIPController.MultiCall.cid); Log.d(TAG, "[getMultiCallInfo] SIPController.MultiCall.dnis = " + SIPController.MultiCall.dnis); } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); } catch (Exception e) { Log.e(TAG, "[Exception] getMultiCallInfo()"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } } public void dialerNotifyCallConnected(String dn, String uri) { for (int i = mClients.size() - 1; i >= 0; i--) { try { // Send data as a String Bundle b = new Bundle(); b.putString("CALLCONNECTED", dn + ";" + uri); Message msg = null; msg = Message.obtain(null, CMCore.BSSSIPStun_ICONTROLS_CM_CALLCONNECTED); msg.setData(b); mClients.get(i).send(msg); } catch (RemoteException e) { Log.e(TAG, "[RemoteException] dialerNotifyCallConnected(String dn, String uri)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); mClients.remove(i); } catch (Exception e) { Log.e(TAG, "[Exception] dialerNotifyCallConnected(String dn, String uri)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } } } public void dialerNotifyBackgroundIncomingCall(String dn, String uri) { for (int i = mClients.size() - 1; i >= 0; i--) { try { // Send data as a String Bundle b = new Bundle(); b.putString("BACKGROUNDINCOMINGCALL", dn + ";" + uri); Message msg = null; msg = Message.obtain(null, CMCore.BSSSIPStun_ICONTROLS_CM_BACKGROUNDINCOMINGCALL); msg.setData(b); mClients.get(i).send(msg); } catch (RemoteException e) { Log.e(TAG, "[RemoteException] dialerNotifyBackgroundIncomingCall(String dn, String uri)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); mClients.remove(i); } catch (Exception e) { Log.e(TAG, "[Exception] dialerNotifyBackgroundIncomingCall(String dn, String uri)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } } } // shutdownApplication() public void dialerShutdownApplication() { for (int i = mClients.size() - 1; i >= 0; i--) { try { // Send data as a String Bundle b = new Bundle(); b.putString("SHUTDOWNAPPLICATION", ""); Message msg = null; msg = Message.obtain(null, CMCore.BSSSIPStun_ICONTROLS_CM_SHUTDOWNAPPLICATION); msg.setData(b); mClients.get(i).send(msg); } catch (RemoteException e) { Log.e(TAG, "[RemoteException] dialerShutdownApplication()"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); mClients.remove(i); } catch (Exception e) { Log.e(TAG, "[Exception] dialerShutdownApplication()"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } } } // vibrator(boolean bSet) public void dialerVibrator(boolean bSet) { for (int i = mClients.size() - 1; i >= 0; i--) { try { // Send data as a String Bundle b = new Bundle(); b.putString("VIBRATOR", "null"); Message msg = null; if (bSet == true) msg = Message.obtain(null, CMCore.BSSSIPStun_ICONTROLS_CM_VIBRATOR_TRUE); else msg = Message.obtain(null, CMCore.BSSSIPStun_ICONTROLS_CM_VIBRATOR_FALSE); msg.setData(b); mClients.get(i).send(msg); } catch (RemoteException e) { Log.e(TAG, "[RemoteException] dialerVibrator(boolean bSet)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); mClients.remove(i); } catch (Exception e) { Log.e(TAG, "[Exception] dialerVibrator(boolean bSet)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } } } // registStatus(SIPStack.bNetworkActive); public void dialerRegistStatus(boolean bSet) { for (int i = mClients.size() - 1; i >= 0; i--) { try { // Send data as a String Bundle b = new Bundle(); b.putString("REGISTSTATUS", "null"); Message msg = null; if (bSet == true) msg = Message.obtain(null, CMCore.BSSSIPStun_ICONTROLS_CM_REGISTSTATUS_TRUE); else msg = Message.obtain(null, CMCore.BSSSIPStun_ICONTROLS_CM_REGISTSTATUS_FALSE); msg.setData(b); mClients.get(i).send(msg); } catch (RemoteException e) { Log.e(TAG, "[RemoteException] dialerRegistStatus(boolean bSet)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); mClients.remove(i); } catch (Exception e) { Log.e(TAG, "[Exception] dialerRegistStatus(boolean bSet)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } } } // notifyRingbackTone(false) public void dialerNotifyRingbackTone(boolean bSet) { for (int i = mClients.size() - 1; i >= 0; i--) { try { // Send data as a String Bundle b = new Bundle(); b.putString("RINGBACKTONE", SIPController.sipCall.dnis); Message msg = null; if (bSet == true) msg = Message.obtain(null, CMCore.BSSSIPStun_ICONTROLS_CM_RINGBACKTONE_TRUE); else msg = Message.obtain(null, CMCore.BSSSIPStun_ICONTROLS_CM_RINGBACKTONE_FALSE); msg.setData(b); mClients.get(i).send(msg); } catch (RemoteException e) { Log.e(TAG, "[RemoteException] dialerNotifyRingbackTone(boolean bSet)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); mClients.remove(i); } catch (Exception e) { Log.e(TAG, "[Exception] dialerNotifyRingbackTone(boolean bSet)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } } } // notifyCallEnd(value, false); public void dialerNotifyCallEnd(String status, String dn, String uri, boolean bSet) { Log.d(TAG, "[dialerNotifyCallEnd] status: " + status); for (int i = mClients.size() - 1; i >= 0; i--) { try { // Send data as a String Bundle b = new Bundle(); b.putString("CALLEND", status + ";" + dn + ";" + uri); Message msg = null; if (bSet == true) msg = Message.obtain(null, CMCore.BSSSIPStun_ICONTROLS_CM_CALLEND_TRUE); else msg = Message.obtain(null, CMCore.BSSSIPStun_ICONTROLS_CM_CALLEND_FALSE); msg.setData(b); mClients.get(i).send(msg); } catch (RemoteException e) { Log.e(TAG, "[RemoteException] dialerNotifyCallEnd(String status, String dn, String uri, boolean bSet)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); mClients.remove(i); } catch (Exception e) { Log.e(TAG, "[Exception] dialerNotifyCallEnd(String status, String dn, String uri, boolean bSet)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } } if (SIPStun.bBlackCall == true) { SIPStun.bBlackCall = false; if (SIPStun.bBlackCallSupport == true) SIPStack.bShutdownApplication = true; } } // dialerNotifyCallFail(SIPController.sipCall.responseCode,SIPController.sipCall.remoteIp); public void dialerNotifyCallFail(int finalCode, String remoteip, String uri) { for (int i = mClients.size() - 1; i >= 0; i--) { try { // Send data as a String Bundle b = new Bundle(); b.putString("CALLFAIL", finalCode + "|" + remoteip + "|" + uri); Message msg = null; msg = Message.obtain(null, CMCore.BSSSIPStun_ICONTROLS_CM_OUTCALLFAIL); msg.setData(b); mClients.get(i).send(msg); } catch (RemoteException e) { Log.e(TAG, "[RemoteException] dialerNotifyCallFail(int finalCode, String remoteip)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); mClients.remove(i); } catch (Exception e) { Log.e(TAG, "[Exception] dialerNotifyCallFail(int finalCode, String remoteip)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } } } //notifyDtmf(SIPController.sipCall.detectedDtmf); public void dialerNotifyDtmf(int dtmf) { for (int i = mClients.size() - 1; i >= 0; i--) { try { // Send data as a String Bundle b = new Bundle(); b.putString("OUTBANDDTMF", dtmf + ""); Message msg = null; msg = Message.obtain(null, CMCore.BSSSIPStun_ICONTROLS_CM_OUTBANDDTMF); msg.setData(b); mClients.get(i).send(msg); } catch (RemoteException e) { Log.e(TAG, "[RemoteException] dialerNotifyDtmf(int dtmf)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); mClients.remove(i); } catch (Exception e) { Log.e(TAG, "[Exception] dialerNotifyDtmf(int dtmf)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } } } public void dialerPadNumber(String number) { for (int i = mClients.size() - 1; i >= 0; i--) { try { // Send data as a String Bundle b = new Bundle(); b.putString("PADNUMBER", number); Message msg = null; msg = Message.obtain(null, CMCore.BSSSIPStun_ICONTROLS_CM_PADNUMBER); msg.setData(b); mClients.get(i).send(msg); } catch (RemoteException e) { Log.e(TAG, "[RemoteException] dialerPadNumber(String number)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); mClients.remove(i); } catch (Exception e) { Log.e(TAG, "[Exception] dialerPadNumber(String number)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } } } public void dialerPadType(int padType, int officeNumber) { for (int i = mClients.size() - 1; i >= 0; i--) { try { // Send data as a String Bundle b = new Bundle(); String value = padType + "." + officeNumber; b.putString("PADTYPE", value); Message msg = null; msg = Message.obtain(null, CMCore.BSSSIPStun_ICONTROLS_CM_PADTYPE); msg.setData(b); mClients.get(i).send(msg); } catch (RemoteException e) { Log.e(TAG, "[RemoteException] dialerPadType(int padType, int officeNumber)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); mClients.remove(i); } catch (Exception e) { Log.e(TAG, "[Exception] dialerPadType(int padType, int officeNumber)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } } } // BSSSIPStun_ICONTROLS_CM_CANCELMULTICALL public void dialerNotifyMulticallCancel(String dn, String uri) { for (int i = mClients.size() - 1; i >= 0; i--) { try { // Send data as a String Bundle b = new Bundle(); b.putString("CANCELMULTICALL", dn + ";" + uri); Message msg = null; msg = Message.obtain(null, CMCore.BSSSIPStun_ICONTROLS_CM_CANCELMULTICALL); msg.setData(b); mClients.get(i).send(msg); } catch (RemoteException e) { Log.e(TAG, "[RemoteException] dialerNotifyMulticallCancel()"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); mClients.remove(i); } catch (Exception e) { Log.e(TAG, "[Exception] dialerNotifyMulticallCancel()"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } } } enum MESSAGE { SEND, // 전송 RESEND, // 재전송 RECEIVE, // 수신 } boolean bPrintSIPMsg = true; boolean bPrintSIPMsgIO = false; private void printSIPMessage(MESSAGE eType, String strMessage) { try { Log.w(TAG, "[printSIPMessage] eType [" + eType + "]"); Log.d(TAG, strMessage); Log.w(TAG, "[printSIPMessage] End of SIP message"); } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); } catch (Exception e) { Log.e(TAG, "[Exception] printSIPMessage(MESSAGE eType, String strMessage)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } } public static class DeviceString { public static String strType_Resi = "Resi"; public static String strType_RentResi = "RentResi"; public static String strType_Lobby = "Lobby"; public static String strType_Guard = "Guard"; public static String strType_Ihub = "Ihub"; } public String[] makeDeviceName(String ipaddress) { String[] aDeviceName = new String[3]; try { String dong = "101"; String ho = "101"; String type = DeviceString.strType_Resi; String[] IP_Parse = ipaddress.split("\\."); dong = Integer.toString((((Integer.parseInt(getDongString()) / 100) * 100) + Integer.parseInt(IP_Parse[1]))); if (IP_Parse[2] == "128") { // 경비실폰 type = DeviceString.strType_Guard; ho = IP_Parse[3]; } else if (IP_Parse[2] == "0") { // 로비폰 type = DeviceString.strType_Lobby; ho = IP_Parse[3]; } else { int nIP_DClass = Integer.parseInt(IP_Parse[3]); if (nIP_DClass < 200) { // 메인 세대 월패드 type = DeviceString.strType_Resi; } else { // 분리 세대 월패드 type = DeviceString.strType_RentResi; nIP_DClass = nIP_DClass - 200; } ho = IP_Parse[2] + ZeroPadding_Head(2, Integer.toString(nIP_DClass)); } aDeviceName[0] = type; aDeviceName[1] = dong; aDeviceName[2] = ho; return aDeviceName; } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); return aDeviceName; } catch (Exception e) { Log.e(TAG, "[Exception] makeDeviceName(String ipaddress)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); return aDeviceName; } } public String makeSIPID(String strIPAddress) { try { LOG_INFO("[makeSIPID] strIPAddress : " + strIPAddress); String SIPID = "12345678_Resi_0101_0101_01"; String dong = "101"; String ho = "101"; String strType = DeviceString.strType_Resi; String strDeviceCnt = "01"; String[] IP_Parse = strIPAddress.split("\\."); if (IP_Parse != null) { dong = Integer.toString((((Integer.parseInt(getDongString()) / 100) * 100) + Integer.parseInt(IP_Parse[1]))); if (IP_Parse[2].equals("128")) { // 경비실폰 strType = DeviceString.strType_Guard; ho = IP_Parse[3]; } else if (IP_Parse[2].equals("0")) { // 로비폰 strType = DeviceString.strType_Lobby; ho = IP_Parse[3]; } else if (IP_Parse[2].equals("201")) { // 아이허브 strType = DeviceString.strType_Ihub; ho = IP_Parse[3]; } else { int nIP_DClass = Integer.parseInt(IP_Parse[3]); if (nIP_DClass < 200) { // 메인 세대 월패드 strType = DeviceString.strType_Resi; } else { // 분리 세대 월패드 strType = DeviceString.strType_RentResi; nIP_DClass = nIP_DClass - 200; } ho = IP_Parse[2] + ZeroPadding_Head(2, Integer.toString(nIP_DClass)); } SIPID = ZeroPadding_Head(8, getSitecodeString()) + "_" + strType + "_" + ZeroPadding_Head(4, dong) + "_" + ZeroPadding_Head(4, ho) + "_" + strDeviceCnt; LOG_INFO("[makeSIPID] SIPID : " + SIPID); return SIPID; } } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); } catch (Exception e) { Log.e(TAG, "[Exception] MakeSIPID(...) : " + e); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } return "ERROR"; } private String getSitecodeString() { try { String strResult = ""; WallpadDeviceSet Devset = new WallpadDeviceSet(this); String[] getData = Devset.GetSettingData("site_code"); Devset.closeDB(); if ((getData != null) && getData.length > 1) { strResult = getData[1]; } LOG("[getSitecodeString] strResult [" + strResult + "]"); return strResult; } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); return null; } catch (Exception e) { Log.e(TAG, "[Exception] getSitecodeString()"); return null; } } private String getDongString() { try { String strResult = ""; wallpaddbmgr DBMGR = new wallpaddbmgr(this); AddressSet Addr = DBMGR.getAddressMGR(); DBMGR.closeDB(); strResult = Addr.Dong; LOG("[getDongString] strResult [" + strResult + "]"); return strResult; } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); return null; } catch (Exception e) { Log.e(TAG, "[Exception] getDongString()"); return null; } } private String getHoString() { try { String strResult = ""; wallpaddbmgr DBMGR = new wallpaddbmgr(this); AddressSet Addr = DBMGR.getAddressMGR(); DBMGR.closeDB(); strResult = Addr.Ho; LOG("[getHoString] strResult [" + strResult + "]"); return strResult; } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); return null; } catch (Exception e) { Log.e(TAG, "[Exception] getHoString()"); return null; } } public static String ZeroPadding_Head(int nOutLength, String strOriginalString) { String strResult = strOriginalString; try { if (strOriginalString.length() < nOutLength) { for (int i = strOriginalString.length(); i < nOutLength; i++) { strResult = "0" + strResult; } return strResult; } else if (strOriginalString.length() == nOutLength) { return strResult; } else { Log.d(TAG, "[ZeroPadding_Head] strOriginalString(" + strOriginalString.length() + ") is longer than nOutLength(" + nOutLength + ")"); return strResult; } } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); return strResult; } catch (Exception e) { Log.e(TAG, "[ZeroPadding_Head] (Exception) ZeroPadding_Head(...) + e"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); return strResult; } } public void receiveNewCall(String strRemoteIP, String strRemoteSIPID, boolean bCallPopup) { try { LOG_INFO("[receiveNewCall] strRemoteIP [" + strRemoteIP + "], strRemoteSIPID [" + strRemoteSIPID + "]"); LOG_INFO("[receiveNewCall] CMCore.bDialerActive [" + CMCore.bDialerActive + "]"); if (!CMCore.bDialerActive) CMCore.bDialerActive = true; CALLEVENTTYPE mCALLEVENTTYPE = CALLEVENTTYPE.RECEIVE_CALL; CALLTYPE mCALLTYPE = CALLTYPE.NONE; if (strRemoteSIPID.contains(DeviceString.strType_Lobby)) { if (bLobbyCallUse) mCALLTYPE = CALLTYPE.LOBBY; else return; } else if (strRemoteSIPID.contains(DeviceString.strType_Guard)) { if (bGuardCallUse) mCALLTYPE = CALLTYPE.GUARD; else return; } else if (strRemoteSIPID.contains(DeviceString.strType_Resi)) { if (bResiCallUse) mCALLTYPE = CALLTYPE.RESIDENCE; else return; } else { Log.e(TAG, "[receiveNewCall] SIPID is not correct!!!"); return; } runCallMainActivity(mCALLEVENTTYPE, mCALLTYPE, bCallPopup); sendHandlerMsgDelayed(HANDLERMSG.RELEASE_BLOCK_INVITE_MSG, 0, 0, 0); } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); } catch (Exception e) { Log.e(TAG, "[Exception] receiveNewCall(String strRemoteIP, String strRemoteSIPID)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } } String strWallPadCallPackageName = "kr.co.icontrols.wallpadcall"; public void runCallMainActivity(CALLEVENTTYPE eEventType, CALLTYPE eCallType, boolean bCallPopup) { try { if (!bWallPadCallLive) { // 통화어플을 실행시킨다. LOG_WARN("[runCallMainActivity] ########## START ##########"); sendLCDBacklightStatus(true); WallpadStatusData mWallpadStatusData = new WallpadStatusData(getApplicationContext()); int nAlramStatus = mWallpadStatusData.GetAlarmStatus(); mWallpadStatusData.closeDB(); if (nAlramStatus != WallpadStatusData.GUARD_OUT) sendBR_AppFinish(getApplicationContext()); ComponentName mComponentName = new ComponentName("kr.co.icontrols.wallpadcall", "kr.co.icontrols.wallpadcall.MainActivity"); Intent mIntent = new Intent(Intent.ACTION_MAIN); mIntent.putExtra(CALLTRIGGER.CALLEVENTTYPE, eEventType.toString()); mIntent.putExtra(CALLTRIGGER.CALLTYPE, eCallType.toString()); if(bCallPopup) mIntent.putExtra("CALLPOPUP", "yes"); else mIntent.putExtra("CALLPOPUP", "no"); mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); mIntent.setComponent(mComponentName); startActivity(mIntent); Thread.sleep(500); // Call app이 실행되는 시간을 기다려준다. (빨리 띄우면 이벤트를 수신 못함) } else { LOG_WARN("[runCallMainActivity] WallPadCall is already running!!"); } } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); } catch (Exception e) { Log.e(TAG, "[Exception] runCallMainActivity()"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } } /** * Edited by jeff (2020.06.22) * LCD 잔상 현장 복구/보호를 위해 실행되고 있는 LCD Keeper를 종료하기 위해, 통화 App이 실행되면서 * backlight를 On하기 전에 이를 알리는 BR를 수신하여 LCD Keeper를 종료한다. * @param bOn */ private void sendLCDBacklightStatus(boolean bOn) { try { Log.d(TAG,"[sendLCDBacklightStatus] bOn [" + bOn + "]"); Intent mIntent = new Intent(); if (bOn) mIntent.setAction(define.NOTIFY_ACNAME_LCD_BACKLIGHT_ON); else mIntent.setAction(define.NOTIFY_ACNAME_LCD_BACKLIGHT_OFF); getApplicationContext().sendBroadcast(mIntent); } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); } catch (Exception e) { Log.e(TAG, "[Exception] sendLCDBacklightStatus(boolean bOn)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } } private boolean getCallAppRunningStatus() { boolean bRunning = false; try { WallpadStatusData DBMGR = new WallpadStatusData(getApplicationContext()); bRunning = DBMGR.GetCallAPKStatusRunning(); DBMGR.closeDB(); Log.d(TAG, "[getCallAppRunningStatus] bRunning : " + bRunning); return bRunning; } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); } catch (Exception e) { Log.d(TAG, "[Exception] getCallAppRunningStatus()"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } return bRunning; } private boolean CanIStartCallApp() { try { for (int i = 0; i < 10; i++) { LOG_WARN("[isCallAppRun] Check Count [" + i + "]"); if (!getTopActivity().equals(strWallPadCallPackageName)) { return true; } else { if (mClients.size() > 0) { LOG_WARN("[isCallAppRun] mClients.size() [" + mClients.size() + "]"); return false; } } Thread.sleep(100); } return false; } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); return false; } catch (Exception e) { Log.e(TAG, "[Exception] CanIStartCallApp()"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); return false; } } private String getTopActivity() { try { ActivityManager mActivityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); List mTaskInfo = mActivityManager.getRunningTasks(1); LOG_INFO("[getTopActivity] getClassName = " + mTaskInfo.get(0).topActivity.getClassName()); ComponentName mComponentName = mTaskInfo.get(0).topActivity; LOG_INFO("[getTopActivity] getPackageName = " + mComponentName.getPackageName()); return mComponentName.getPackageName(); } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); return null; } catch (Exception e) { Log.e(TAG, "[Exception] getTopActivity()"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); return null; } } private void sendBR_AppFinish(Context context) { try { LOG_WARN("[sendBR_AppFinish] Send App Finish!!"); Intent mIntent = new Intent(); mIntent.setAction(define.BR_APP_FINISH); context.sendBroadcast(mIntent); } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); } catch (Exception e) { Log.e(TAG, "[Exception] sendBR_AppFinish(Context context)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } } private void cancelCallForwardToStun() { try { LOG("[cancelCallForwardToStun]"); SIPController.sipCall.bForwardRequest = false; SIPController.forward.bForward = false; SIPController.forward.contact = ""; SIPController.forward.iForwardTarget = 0; SIPController.forward.dong = ""; SIPController.forward.ho = ""; SIPController.forward.number = ""; SIPController.forward.contact = ""; } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); } catch (Exception e) { Log.e(TAG, "[Exception] cancelCallForwardToStun() : " + e); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } } // Audio Tune public static short nEQ_60 = -1500; // dB public static short nEQ_230 = 0; // dB public static short nEQ_910 = 0; // dB public static short nEQ_4K = -1500; // dB public static short nEQ_14K = -1500; // dB static Equalizer mEqualizer; public void replyEQValue() { try { short[] EQValues = SIPSound.getEQValues(); for (int i = mClients.size() - 1; i >= 0; i--) { try { // Send data as a String Bundle b = new Bundle(); b.putString("cmd", "reply_get_eq_values"); b.putShort("60", EQValues[0]); b.putShort("230", EQValues[1]); b.putShort("910", EQValues[2]); b.putShort("4k", EQValues[3]); b.putShort("14k", EQValues[4]); Message msg = null; msg = Message.obtain(null, CMCore.BSSSIPStun_ICONTROLS_SET_INT_VALUE); msg.setData(b); mClients.get(i).send(msg); } catch (RemoteException e) { Log.e(TAG, "[RemoteException] replyEQValue -> mClients"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); mClients.remove(i); } } } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); } catch (Exception e) { Log.e(TAG, "[Exception] replyEQValue()"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } } public void setEQValue(String strEQ, short Value) { try { Log.i(TAG, "strEQ [" + strEQ + "], Value [" + Value + "]"); if (strEQ.equals("60")) SIPSound.ctrlEQ60(Value); else if (strEQ.equals("230")) SIPSound.ctrlEQ230(Value); else if (strEQ.equals("910")) SIPSound.ctrlEQ910(Value); else if (strEQ.equals("4k")) SIPSound.ctrlEQ4K(Value); else if (strEQ.equals("14k")) SIPSound.ctrlEQ14K(Value); else { Log.e(TAG, "strEQ is not available [" + strEQ + "]"); } replyEQValue(); } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); } catch (Exception e) { Log.e(TAG, "[Exception] setEQValue(String strEQ, short Value)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } } /** * JEFF, 2019.12.25 * WallPadMain이 실행되면 매 1초마다 WallPadCall의 실행상태를 파악한다. * WallPadMain에서 WallPadCall의 실행상태 확인을 요청하는 BR를 송신하고 * WallPadCall은 해당 BR이 수신되면 실행상태를 알리는 BR를 송신하여 이에 응답한다. * WallPadMain은 이 응답 BR의 수신여부를 판단하여 WallPadCall의 실행여부를 판단한다. */ int MAX_WALLPADCALL_LIVE_CNT = 3; int nWallPadCallACKCnt = MAX_WALLPADCALL_LIVE_CNT; // MAX_WALLPADCALL_LIVE_CNT회 이상 응답이 없으면 WallPadCall이 종료된것으로 판단한다. public static boolean bWallPadCallLive = false; // WallPadCall의 Live 상태를 나타낸다. boolean bCheckThreadRun = false; checkWallPadLive mcheckWallPadLive; class checkWallPadLive extends Thread { public checkWallPadLive() { Log.w(TAG,"[Thread.checkWallPadLive] bCheckThreadRun [" + bCheckThreadRun + "]"); } @Override public void run() { super.run(); try { while (bCheckThreadRun) { if (nWallPadCallACKCnt >= 0) { nWallPadCallACKCnt--; } else { bWallPadCallLive = false; } // Log.w(TAG,"[WallPadCallLiveBRCheck] bWallPadCallLive [" + bWallPadCallLive + "]"); Thread.sleep(1000); } } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); } catch (Exception e) { Log.e(TAG, "[Exception] checkWallPadLive.run()"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } } } BroadcastReceiver SIPStunBR = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { try { String strActionName = intent.getAction(); // Log.i(TAG,"[SIPStunBR] strActionName [" + strActionName + "]"); if (strActionName.equals(Declare.BR.BR_ACK_WALLPADCALL_LIVE)) { bWallPadCallLive = true; nWallPadCallACKCnt = MAX_WALLPADCALL_LIVE_CNT; // Log.w(TAG,"[WallPadCallLiveBRCheck] bWallPadCallLive [" + bWallPadCallLive + "]"); } else if (strActionName.equals(Declare.BR.BR_BLOCK_SIPCALL)) { bBLOCK_INVITE_MSG = true; StunHandler.removeMessages(HANDLERMSG.RELEASE_BLOCK_INVITE_MSG); sendHandlerMsgDelayed(HANDLERMSG.RELEASE_BLOCK_INVITE_MSG, 0, 0, 5000); } else { Log.w(TAG,"[SIPStunBR] Not supported strActionName [" + strActionName + "]"); } } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); } catch (Exception e) { Log.e(TAG, "[Exception] BroadcastReceiver -> SIPStunBR"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } } }; private void registerWallPadCallLiveBRReceiver() { try { LOG_INFO("[registerWallPadCallLiveBRReceiver] ========== START =========="); IntentFilter mIntentFilter = new IntentFilter(); mIntentFilter.addAction(Declare.BR.BR_ACK_WALLPADCALL_LIVE); mIntentFilter.addAction(Declare.BR.BR_BLOCK_SIPCALL); registerReceiver(SIPStunBR, mIntentFilter); bCheckThreadRun = true; mcheckWallPadLive = new checkWallPadLive(); mcheckWallPadLive.start(); } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); } catch (Exception e) { Log.e(TAG, "[Exception] registerWallPadCallLiveBRReceiver()"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } } private void unregisterWallPadCallLiveBRReceiver() { try { LOG_INFO("[unregisterBRReceiver] ========== START =========="); unregisterReceiver(SIPStunBR); bCheckThreadRun = false; mcheckWallPadLive = null; } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); } catch (Exception e) { Log.e(TAG, "[Exception] unregisterWallPadCallLiveBRReceiver()"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } } public void updateBlockStatus() { Log.v(TAG, "updateBlockStatus()"); for (int i = mClients.size() - 1; i >= 0; i--) { try { Bundle b = new Bundle(); b.putBoolean("ISBLOCK", bBLOCK_INVITE_MSG); Message msg = null; msg = Message.obtain(null, CMCore.BSSSIPStun_ICONTROLS_UPDATE_BLOCK_STATUS); msg.setData(b); mClients.get(i).send(msg); } catch (RemoteException e) { Log.e(TAG, "[RemoteException] updateBlockStatus()"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); mClients.remove(i); } catch (Exception e) { Log.e(TAG, "[Exception] updateBlockStatus()"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } } } }