package kr.co.icontrols.callengine.remotecall; 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.os.Bundle; import android.os.Handler; import android.os.IBinder; import android.os.Looper; import android.os.Message; import android.os.Messenger; import android.util.Log; import com.artncore.WallPadDataMgr.WallPadRemoteCallUserData; import com.artncore.WallPadDataMgr.WallPadRemoteCallUserData.RemoteCallUserClass; import com.artncore.WallPadDataMgr.WallpadDeviceSet; import com.artncore.WallPadDataMgr.WallpadStatusData; import com.artncore.WallPadDataMgr.wallpaddbmgr; import com.artncore.commons.define; import com.artncore.wallpadimap.RetProci; import com.hdc.visitorcall.VisitorCallLib; import com.util.LogUtil; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.xml.sax.InputSource; import java.io.StringReader; import java.util.ArrayList; import java.util.List; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import kr.co.icontrols.callengine.engine.CallManager.CALLEVENTTYPE; import kr.co.icontrols.callengine.engine.CallManager.CALLOWNER; import kr.co.icontrols.callengine.engine.CallManager.CALLSTATUS; import kr.co.icontrols.callengine.engine.CallManager.CALLTYPE; import kr.co.icontrols.callengine.remotecall.RemoteCallMSG.REMOTECALLHANDELKEY; import kr.co.icontrols.callengine.remotecall.RemoteCallMSG.REMOTECALLMSG; import kr.co.icontrols.callengine.remotecall.RemoteCallMSG.REMOTECALL_CALLER; import kr.co.icontrols.callengine.remotecall.RemoteCallMSG.REMOTECALL_CALLOWNER; import kr.co.icontrols.callengine.remotecall.RemoteCallMSG.REMOTECALL_CALLTYPE; import kr.co.icontrols.callengine.sip.SIPStun; import kr.co.icontrols.wallpadcall.declare.DataClasses.GuardListTable; import kr.co.icontrols.wallpadcall.declare.DataClasses.RemoteIDInfo; import kr.co.icontrols.wallpadcall.declare.Declare; import kr.co.icontrols.wallpadcall.declare.Declare.CALLTRIGGER; import kr.co.icontrols.wallpadcall.declare.Declare.VISITORREMOTECALL; import kr.co.icontrols.wallpadcall.declare.Global; import kr.co.icontrols.wallpadcall.declare.Global.ConfigValues; import kr.co.icontrols.wallpadcall.imap.Request_check_sip_activation; public class RemoteCallManager extends Service implements VisitorCallLib.Callback { static String TAG = "RemoteCallManager"; ArrayList mRemoteMsns = new ArrayList(); final Messenger mMessenger = new Messenger(new RemoteCallManagerHandler()); VisitorCallLib mVisitorCallLib; WallPadRemoteCallUserData wallPadRemoteCallUserData = null; GuardListTable mGuardListTable = null; // 경비실기 목록 @Override public IBinder onBind(Intent intent) { return mMessenger.getBinder(); } int dong, ho; String ip; @Override public void onCreate() { try { Log.i(TAG, "========== RemoteCallManager onCreate called newly!!! =========="); super.onCreate(); registerBRReceiver(); Log.i(TAG, "[onCreate] --------------- VisitorCallLib ---------------"); if (InitInfo()) { wallPadRemoteCallUserData = new WallPadRemoteCallUserData(this); mVisitorCallLib = VisitorCallLib.getInstance(); mVisitorCallLib.setCallback(this); mVisitorCallLib.ShowLog(1); Log.d(TAG, "[onCreate] ====== mVisitorCallLib.SetInternalServerInfo ======"); mVisitorCallLib.SetInternalServerInfo(VISITORREMOTECALL.INTERNAL_SERVER_IP, VISITORREMOTECALL.INTERNAL_SERVER_PORT); WallpadStatusData SetData = new WallpadStatusData(getApplicationContext()); wallpaddbmgr.AddressSet addc = SetData.getAddressMGR(); dong = Integer.parseInt(addc.Dong); ho = Integer.parseInt(addc.Ho); ip = addc.IPAddress; boolean bRegister = SetData.GetRemoteCallRegistration(); Log.d(TAG, "[onCreate] bRegister [" + bRegister + "]"); SetData.closeDB(); // if (!bRegister) sendHandlerMsgDelayed(HANDLERMSG.REGISTER_REMOTECALL_LIB, 0, 0, 2000); // 방문객 원격통화 라이브러리 등록 여부 판단 후 등록 (서비스 시작 후 2초 딜레이) // else Log.w(TAG, "[onCreate] Already VisitorCallLib Registration did!!!"); } else { Log.w(TAG, "[onCreate] InitInfo Fail!!"); } } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); } catch (Exception e) { Log.e(TAG, "[Exception] onCreate()"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } } @Override public int onStartCommand(Intent intent, int flags, int startId) { Log.d(TAG, "[onStartCommand] flags [" + flags + "], startId [" + startId + "]"); return START_STICKY; // run until explicitly stopped. } @Override public void onDestroy() { try { super.onDestroy(); unregisterBRReceiver(); Log.i(TAG, "[onDestroy] ===================== RemoteCallManager Stopped!! ====================="); } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); } catch (Exception e) { Log.e(TAG, "[Exception] onDestroy()"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } } private void sendMsgToRemoteMsns(int nMsg, CALLTYPE eCallType) { try { int nRemoteCnt = mRemoteMsns.size(); // Log.d(TAG, "[sendMsgToRemoteMsns] nRemoteCnt [" + nRemoteCnt + "], eCallType [" + eCallType + "]"); Bundle bundle = new Bundle(); bundle.putString(REMOTECALLHANDELKEY.CALLTYPE, eCallType.toString()); Message msg = Message.obtain(null, nMsg, 0, 0, null); msg.setData(bundle); for (int i = 0; i < nRemoteCnt; i++) { mRemoteMsns.get(i).send(msg); } } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); } catch (Exception e) { Log.e(TAG, "[Exception] sendMsgToRemoteMsns(int nMsg, CALLTYPE eCallType)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } } private void sendMsgToRemoteMsns(int nMsg, CALLTYPE eCallType, AVPacket avPacket) { try { int nRemoteCnt = mRemoteMsns.size(); // Log.d(TAG, "[sendMsgToRemoteMsns] nRemoteCnt [" + nRemoteCnt + "], eCallType [" + eCallType + "], avPacket.length [" + avPacket.length + "]"); Bundle bundle = new Bundle(); bundle.putString(REMOTECALLHANDELKEY.CALLTYPE, eCallType.toString()); bundle.putSerializable(REMOTECALLHANDELKEY.AVPACKET, avPacket); Message msg = Message.obtain(null, nMsg, 0, 0, null); msg.setData(bundle); for (int i = 0; i < nRemoteCnt; i++) { mRemoteMsns.get(i).send(msg); } } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); } catch (Exception e) { Log.e(TAG, "[Exception] sendMsgToRemoteMsns(int nMsg, CALLTYPE eCallType, AVPacket avPacket)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } } private boolean InitInfo() { try { WallpadDeviceSet devSet = new WallpadDeviceSet(this); String[] strValue = devSet.GetSettingData("방문객원격통화"); devSet.closeDB(); if (strValue != null) { String IP = getExtractData(strValue[1], "IP"); if (IP != null) { String Port = IP.substring(IP.indexOf(":") + 1); IP = IP.substring(0, IP.indexOf(":")); int nPort = 0; if (Port != null) nPort = Integer.parseInt(Port); VISITORREMOTECALL.INTERNAL_SERVER_IP = IP; VISITORREMOTECALL.INTERNAL_SERVER_PORT = nPort; Log.d(TAG, "[InitInfo] INTERNAL_SERVER_IP [" + VISITORREMOTECALL.INTERNAL_SERVER_IP + "], INTERNAL_SERVER_PORT [" + VISITORREMOTECALL.INTERNAL_SERVER_PORT + "]"); return true; } } } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); } catch (Exception e) { Log.e(TAG, "[Exception] InitInfo()"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } return false; } private String getExtractData(String FullText, String Name) { try { if (FullText.indexOf(Name) > 0) { String CutString = FullText.substring(FullText.indexOf(Name)); // Log.d(TAG, "[getExtractData] CutString [" + CutString + "]"); String subString = CutString.substring(Name.length() + 1, CutString.indexOf(")")); Log.d(TAG, "[getExtractData] subString [" + subString + "]"); return subString; } } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); } catch (Exception e) { //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } return null; } private void registerRemoteCallLib() { try { if (mVisitorCallLib != null) { WallpadStatusData SetData = new WallpadStatusData(getApplicationContext()); SetData.SetRemoteCallUserCnt(0); // 방문객원격통화 월패드 등록시 사용자 DB도 0으로 설정 (초기화) SetData.SetRemoteCallRegistration(false); WallpadDeviceSet devSet = new WallpadDeviceSet(getApplicationContext()); int nHomeViewerUse = devSet.Get_RemoteCall_HomeViewerUse() ? 1 : 0; devSet.closeDB(); Log.d(TAG, "[registerRemoteCallLib] nHomeViewerUse [" + nHomeViewerUse + "]"); String strResult = mVisitorCallLib.Registration(dong, ho, ip, nHomeViewerUse, 1); if (strResult != null) { Log.d(TAG, "[registerRemoteCallLib] ====== mVisitorCallLib.Registration ======"); Log.d(TAG, "[registerRemoteCallLib] strResult [" + strResult + "]"); SetData.SetRemoteCallRegistration(true); String strGuardList = getGuardList(); if (strGuardList != null) { if (!strGuardList.equals("")) { Log.d(TAG, "[registerRemoteCallLib] == mVisitorCallLib.SetSecurityOffice =="); int nResult = mVisitorCallLib.SetSecurityOffice(dong, ho, strGuardList); // 초기화 후 경비실기 목록 전달 Log.d(TAG, "[registerRemoteCallLib] nResult [" + nResult + "]"); } } else { Log.w(TAG, "[registerRemoteCallLib] strGuardList is null!!"); } } SetData.closeDB(); } } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); } catch (Exception e) { Log.e(TAG, "[Exception] registerRemoteCallLib()"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } } /************************************************************ * * 방문객원격통화 관련 (콜백, 이벤트) * ************************************************************/ public static boolean bMobileTalk = false; // 스마트폰에서 통화 시작 @Override public int EVENT_StartCalling(int handle, String caller) { try { Log.d(TAG, "[EVENT_StartCalling] handle [" + handle + "], caller [" + caller + "]"); Object obj = caller; Message message = VisitorCallEventHandler.obtainMessage(VisitorCallEvent.EVENT_START_CALLING, obj); VisitorCallEventHandler.sendMessage(message); return 0; } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); return -1; } catch (Exception e) { Log.e(TAG, "[Exception] EVENT_StartCalling(int handle, String caller)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } return -1; } // 스마트폰에서 문열림 @Override public int EVENT_UnlockDoor(int handle, String device, String caller) { try { // 현관, 로비 권한에 따라 문열림 처리 Log.d(TAG, "[EVENT_UnlockDoor] handle [" + handle + "], device [" + device + "], caller [" + caller + "]"); if (device.equals(REMOTECALL_CALLTYPE.CALLTYPE_LOBBY)) { int nUserCnt = wallPadRemoteCallUserData.GetRemoteCallUserCnt(); Log.d(TAG, "[EVENT_UnlockDoor] nUserCnt [" + nUserCnt + "]"); List dataList = wallPadRemoteCallUserData.GetRemoteCallUserData(); for (int i = 0; i < nUserCnt; i++) { if (caller.equals(dataList.get(i).Name)) { if (dataList.get(i).LobbyOpenAuth.equals("1")) { Object obj = device; Message message = VisitorCallEventHandler.obtainMessage(VisitorCallEvent.EVENT_UNLOCK_DOOR, obj); VisitorCallEventHandler.sendMessage(message); return 0; } else { return -2; // 로비문열림 권한이 없는 경우 } } } } else if (device.equals(REMOTECALL_CALLTYPE.CALLTYPE_DOOR)) { int nUserCnt = wallPadRemoteCallUserData.GetRemoteCallUserCnt(); Log.d(TAG, "[EVENT_UnlockDoor] nUserCnt [" + nUserCnt + "]"); List dataList = wallPadRemoteCallUserData.GetRemoteCallUserData(); for (int i = 0; i < nUserCnt; i++) { if (caller.equals(dataList.get(i).Name)) { if (dataList.get(i).DoorOpenAuth.equals("1")) { Object obj = device; Message message = VisitorCallEventHandler.obtainMessage(VisitorCallEvent.EVENT_UNLOCK_DOOR, obj); VisitorCallEventHandler.sendMessage(message); return 0; } else { return -2; // 현관문열림 권한이 없는 경우 } } } } } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); } catch (Exception e) { Log.e(TAG, "[Exception] EVENT_UnlockDoor(int handle, String device, String caller)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } return -1; } // 스마트폰에서 현관모니터링 또는 경비발신 요청 @Override public int EVENT_RequestMonitor(int handle, String device, String caller) { try { Log.d(TAG, "[EVENT_RequestMonitor] handle [" + handle + "], device [" + device + "], caller [" + caller + "]"); Log.d(TAG, "[EVENT_RequestMonitor] bWallPadCallLive [" + SIPStun.bWallPadCallLive + "]"); if (!SIPStun.bWallPadCallLive && mHandle == -1) { // 모바일 요청 성공 mVisitorCallLib.ndkHandle = mHandle = handle; Log.d(TAG, "[EVENT_RequestMonitor] EVENT_REQUEST_MONITOR_SUCCESS mHandle [" + mHandle + "]"); } else { // 모바일 요청 실패 Log.w(TAG, "[EVENT_RequestMonitor] EVENT_REQUEST_MONITOR_ERR mHandle [" + mHandle + "]"); Object obj = handle; Message message = VisitorCallEventHandler.obtainMessage(VisitorCallEvent.EVENT_REQUEST_MONITOR_ERR, obj); VisitorCallEventHandler.sendMessage(message); return -3; } if (device.equals(REMOTECALL_CALLTYPE.CALLTYPE_DOOR)) { // 현관모니터링 요청 int nUserCnt = wallPadRemoteCallUserData.GetRemoteCallUserCnt(); Log.d(TAG, "[EVENT_RequestMonitor] CALLTYPE_DOOR nUserCnt [" + nUserCnt + "]"); List dataList = wallPadRemoteCallUserData.GetRemoteCallUserData(); for (int i = 0; i < nUserCnt; i++) { if (caller.equals(dataList.get(i).Name)) { if (dataList.get(i).MonitorAuth.equals("1")) { Object obj = device; Message message = VisitorCallEventHandler.obtainMessage(VisitorCallEvent.EVENT_REQUEST_MONITOR, obj); VisitorCallEventHandler.sendMessage(message); return 0; } else { return -2; // 현관보기 권한이 없는 경우 } } } } else if (device.equals(REMOTECALL_CALLTYPE.CALLTYPE_WALLPAD)) { // 모바일에서 세대모니터링 요청 int nUserCnt = wallPadRemoteCallUserData.GetRemoteCallUserCnt(); Log.d(TAG, "[EVENT_RequestMonitor] CALLTYPE_WALLPAD nUserCnt [" + nUserCnt + "]"); List dataList = wallPadRemoteCallUserData.GetRemoteCallUserData(); for (int i = 0; i < nUserCnt; i++) { Log.d(TAG, "[EVENT_RequestMonitor] dataList.Name [" + dataList.get(i).Name + "], dataList.HomeViewerAuth [" + dataList.get(i).HomeViewerAuth + "]"); if (caller.equals(dataList.get(i).Name)) { if (dataList.get(i).HomeViewerAuth.equals("1")) { Object obj = device; Message message = VisitorCallEventHandler.obtainMessage(VisitorCallEvent.EVENT_REQUEST_MONITOR, obj); VisitorCallEventHandler.sendMessage(message); return 0; } else { return -2; // 홈뷰어 권한이 없는 경우 } } } } else { // 모바일에서 경비 발신 요청 if (REMOTECALL_CALLTYPE.CALLTYPE_GUARD_NAME == null) { if (mGuardListTable == null) getGuardList(); } // Log.d(TAG, "[EVENT_RequestMonitor] CALLTYPE_GUARD_NAME.size() [" + REMOTECALL_CALLTYPE.CALLTYPE_GUARD_NAME.size() + "]"); if(REMOTECALL_CALLTYPE.CALLTYPE_GUARD_NAME!=null) { for (int i = 0; i < REMOTECALL_CALLTYPE.CALLTYPE_GUARD_NAME.size(); i++) { if (REMOTECALL_CALLTYPE.CALLTYPE_GUARD_NAME!=null && REMOTECALL_CALLTYPE.CALLTYPE_GUARD_NAME.get(i).equals(device)) { Log.d(TAG, "[EVENT_RequestMonitor] CALLTYPE_GUARD_NAME[" + i + "] = " + REMOTECALL_CALLTYPE.CALLTYPE_GUARD_NAME.get(i)); // 모바일에서 경비실 통화 발신 RemoteCallMSG.REMOTE_CALLTYPE = CALLTYPE.GUARD; return tryGuardCall(getGuardID(device)); } } } } } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); } catch (Exception e) { Log.e(TAG, "[Exception] EVENT_RequestMonitor(int handle, String device, String caller)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } Log.w(TAG, "[EVENT_RequestMonitor] EVENT_RequestMonitor_FAIL!!!"); return -1; } // 스마트폰에서 전달한 오디오 데이터 수신 (이 데이터를 현관카메라/로비폰/경비실기로 전달) @Override public void EVENT_AudioData(int handle, byte[] bytes, int size) { try { // Log.d(TAG, "[EVENT_AudioData] handle [" + handle + "], bytes.length [" + bytes.length + "], size [" + size + "]"); if (!bMobileTalk) { // Log.w(TAG, "[EVENT_AudioData] CALLOWNER isn't Mobile!!"); // 통화주체(CallOwner)가 모바일인 경우에만 오디오 데이터 수신 return; } AVPacket avPacket = new AVPacket(); avPacket.avType = 1; // 1: AUDIO avPacket.data = bytes; avPacket.length = size; avPacket.frameType = 0; // 0: G711, 1: PCM 데이터 전송 Object obj = avPacket; Message message = VisitorCallEventHandler.obtainMessage(VisitorCallEvent.EVENT_AUDIO_DATA, obj); VisitorCallEventHandler.sendMessage(message); } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); } catch (Exception e) { Log.e(TAG, "[Exception] EVENT_AudioData(int handle, byte[] bytes, int size)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } } // 스마트폰에서 사용자 등록을 위한 인증키 전달 @Override public int EVENT_RequestShowAuthorityKey(int handle, String strKey) { try { Log.d(TAG, "[EVENT_RequestShowAuthorityKey] handle [" + handle + "], strKey [" + strKey + "]"); } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); } catch (Exception e) { Log.e(TAG, "[Exception] EVENT_RequestShowAuthorityKey(int handler, String strKey)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } return -1; } // 월패드에서 사용자 리스트 요청 후 비동기로 받음 (GetRegisteredUserList에 대한 콜백) @Override public void EVENT_RegisteredUserList(int handle, String userXML) { try { Log.d(TAG, "[EVENT_RegisteredUserList] handle [" + handle + "], userXML [" + userXML + "]"); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse(new InputSource(new StringReader(userXML))); NodeList userList = document.getElementsByTagName("user"); int remoteCallUserCnt = userList.getLength(); Log.d(TAG, "[EVENT_RegisteredUserList] remoteCallUserCnt [" + remoteCallUserCnt + "]"); Log.d(TAG, "[EVENT_RegisteredUserList] === Send BR === REMOTECALL_USER_REGISTER_RESULT"); Intent mIntent = new Intent(); // 설정 앱에서 실제 등록 확인을 위한 사용자 수 BR 전송 mIntent.setAction("REMOTECALL_USER_REGISTER_RESULT"); mIntent.putExtra("REMOTECALL_USER_CNT", remoteCallUserCnt); sendBroadcast(mIntent); WallpadStatusData SetData = new WallpadStatusData(getApplicationContext()); SetData.SetRemoteCallUserCnt(remoteCallUserCnt); // 사용자 추가 완료 후 DB 저장 (DB 업데이트) SetData.closeDB(); addRemoteCallUserInfo(userList, document); } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); } catch (Exception e) { Log.e(TAG, "[Exception] EVENT_RegisteredUserList(int handle, String userXML)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } } // 월패드에서 사용자 제거 후 결과값 알려줌 (DelRegisteredUserList에 대한 콜백) @Override public void EVENT_DelRegisteredUserList(int handle, int result, String message) { try { Log.d(TAG, "[EVENT_DelRegisteredUserList] handle [" + handle + "], result [" + result + "], message [" + message + "]"); } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); } catch (Exception e) { Log.e(TAG, "[Exception] EVENT_DelRegisteredUserList(int handle, int result, String message)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } } // 월패드에서 사용자 권한 변경 후 결과값 알려줌 (SetUserAuthority에 대한 콜백) @Override public void EVENT_SetUserAuthority(int handle, int result, String message) { try { Log.d(TAG, "[EVENT_SetUserAuthority] handle [" + handle + "], result [" + result + "], message [" + message + "]"); if (result == 0) { // debugging List dataList = wallPadRemoteCallUserData.GetRemoteCallUserData(); for (int i = 0; i < wallPadRemoteCallUserData.GetRemoteCallUserCnt(); i++) { Log.d(TAG, "[EVENT_SetUserAuthority] dataList.Name [" + dataList.get(i).Name + "], dataList.MonitorAuth [" + dataList.get(i).MonitorAuth + "], dataList.HomeViewerAuth [" + dataList.get(i).HomeViewerAuth + "]"); } } } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); } catch (Exception e) { Log.e(TAG, "[Exception] EVENT_SetUserAuthority(int handle, int result, String message)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } } /** * 스마트폰에서 사용자 등록을 완료한 경우 호출되는 콜백함수 * @param handle * @param eventType 0 (사용자 추가) * @param eventContent 추가된 사용자의 PhoneKey(UDID) * @param eventLength */ @Override public void EVENT_OtherEvent(int handle, int eventType, String eventContent, int eventLength) { try { Log.d(TAG, "[EVENT_OtherEvent] handle [" + handle + "], eventType [" + eventType + "], eventContent [" + eventContent + "], eventLength [" + eventLength + "]"); int arg1 = eventType; Object obj = eventContent; Message message = VisitorCallEventHandler.obtainMessage(VisitorCallEvent.EVENT_OTHEREVENT, arg1, 0, obj); VisitorCallEventHandler.sendMessage(message); } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); } catch (Exception e) { Log.e(TAG, "[Exception] EVENT_OtherEvent(int handle, int eventType, String eventContent, int eventLength)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } } @Override public void EVENT_TestMedia(int i, byte[] bytes, int i1, int i2) { } // 세션 연결이 끝난 경우 호출되는 콜백함수 @Override public void EVENT_ClosedSession(int handle, int count) { try { Log.d(TAG, "[EVENT_CloseSession] handle [" + handle + "], count [" + count + "]"); if (count == 0) { bMobileTalk = false; Object obj = handle; Message message = VisitorCallEventHandler.obtainMessage(VisitorCallEvent.EVENT_CLOSED_SESSION, obj); VisitorCallEventHandler.sendMessage(message); } } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); } catch (Exception e) { Log.e(TAG, "[Exception] EVENT_ClosedSession(int handle, int count)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } } // 방문객원격통화 이벤트 핸들러 interface VisitorCallEvent { public final int EVENT_REGISTRATION = 0; public final int EVENT_REQUEST_MONITOR = 1; public final int EVENT_START_CALLING = 2; public final int EVENT_AUDIO_DATA = 3; public final int EVENT_UNLOCK_DOOR = 4; public final int EVENT_GETUSERLIST = 6; public final int EVENT_DELUSERLIST = 7; public final int EVENT_OTHEREVENT = 8; public final int EVENT_REQUEST_MONITOR_ERR = 9; public final int EVENT_CLOSED_SESSION = 10; } int mHandle = -1; private Handler VisitorCallEventHandler = new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); try { // Log.d(TAG, "[VisitorCallEventHandler] msg.what [" + msg.what + "]"); if (msg.what == VisitorCallEvent.EVENT_REQUEST_MONITOR) { String device = (String) msg.obj; if (device.equals(REMOTECALL_CALLTYPE.CALLTYPE_DOOR)) { RemoteCallMSG.REMOTE_CALLTYPE = CALLTYPE.FRONT; runCallMainActivity(CALLOWNER.MOBILE, CALLEVENTTYPE.REQUEST_FRONT_MONITORING, RemoteCallMSG.REMOTE_CALLTYPE, null); // 통화 앱 실행 sendMsgToRemoteMsns(REMOTECALLMSG.RECEIVE_EVENT_REQUEST_MONITOR, RemoteCallMSG.REMOTE_CALLTYPE); // 데이터 전달 } else if (device.equals(REMOTECALL_CALLTYPE.CALLTYPE_WALLPAD)) { RemoteCallMSG.REMOTE_CALLTYPE = CALLTYPE.RESIDENCE; runCallMainActivity(CALLOWNER.MOBILE, CALLEVENTTYPE.REQUEST_FRONT_MONITORING, RemoteCallMSG.REMOTE_CALLTYPE, null); // 통화 앱 실행 sendMsgToRemoteMsns(REMOTECALLMSG.RECEIVE_EVENT_REQUEST_MONITOR, RemoteCallMSG.REMOTE_CALLTYPE); // 데이터 전달 } } else if (msg.what == VisitorCallEvent.EVENT_START_CALLING) { Log.d(TAG, "[VisitorCallEventHandler] REMOTE_CALLTYPE [" + RemoteCallMSG.REMOTE_CALLTYPE + "]"); if (RemoteCallMSG.REMOTE_CALLTYPE != CALLTYPE.NONE) sendMsgToRemoteMsns(REMOTECALLMSG.RECEIVE_EVENT_START_CALL, RemoteCallMSG.REMOTE_CALLTYPE); } else if (msg.what == VisitorCallEvent.EVENT_AUDIO_DATA) { AVPacket avp = (AVPacket) msg.obj; if (RemoteCallMSG.REMOTE_CALLTYPE != CALLTYPE.NONE) sendMsgToRemoteMsns(REMOTECALLMSG.RECEIVE_EVENT_AUDIO_DATA, RemoteCallMSG.REMOTE_CALLTYPE, avp); } else if (msg.what == VisitorCallEvent.EVENT_UNLOCK_DOOR) { String device = (String) msg.obj; if (device.equals(REMOTECALL_CALLTYPE.CALLTYPE_DOOR)) RemoteCallMSG.REMOTE_CALLTYPE = CALLTYPE.FRONT; else if (device.equals(REMOTECALL_CALLTYPE.CALLTYPE_LOBBY)) RemoteCallMSG.REMOTE_CALLTYPE = CALLTYPE.LOBBY; else RemoteCallMSG.REMOTE_CALLTYPE = CALLTYPE.NONE; Log.d(TAG, "[VisitorCallEventHandler] REMOTE_CALLTYPE [" + RemoteCallMSG.REMOTE_CALLTYPE + "]"); if (RemoteCallMSG.REMOTE_CALLTYPE != CALLTYPE.NONE) sendMsgToRemoteMsns(REMOTECALLMSG.RECEIVE_EVENT_UNLOCK_DOOR, RemoteCallMSG.REMOTE_CALLTYPE); } else if (msg.what == VisitorCallEvent.EVENT_OTHEREVENT) { int eventType = msg.arg1; String phoneKey = (String) msg.obj; Log.d(TAG, "[VisitorCallEventHandler] eventType [" + eventType + "], phoneKey [" + phoneKey + "]"); if (eventType == 0) { sendHandlerMsg(HANDLERMSG.GET_USERLIST, 0, 0, phoneKey); } } else if (msg.what == VisitorCallEvent.EVENT_CLOSED_SESSION || msg.what == VisitorCallEvent.EVENT_REQUEST_MONITOR_ERR) { int handle = (int) msg.obj; if (mVisitorCallLib != null) { Log.d(TAG, "[VisitorCallEventHandler] EVENT_CLOSED_SESSION handle [" + handle + "]"); mVisitorCallLib.Close(handle); mVisitorCallLib.ndkHandle = mHandle = -1; } bMobileTalk = false; Log.d(TAG, "[VisitorCallEventHandler] REMOTE_CALLTYPE handle [" + RemoteCallMSG.REMOTE_CALLTYPE + "]"); if (RemoteCallMSG.REMOTE_CALLTYPE != CALLTYPE.NONE) { sendMsgToRemoteMsns(REMOTECALLMSG.RECEIVE_EVENT_CLOSE_SESSION, RemoteCallMSG.REMOTE_CALLTYPE); if (RemoteCallMSG.REMOTE_CALLOWNER == CALLOWNER.MOBILE) { Log.d(TAG, "[VisitorCallEventHandler] REMOTE_CALLOWNER [" + RemoteCallMSG.REMOTE_CALLOWNER + "]"); WallpadStatusData mWallpadStatusData = new WallpadStatusData(getApplicationContext()); int nAlarmStatus = mWallpadStatusData.GetAlarmStatus(); mWallpadStatusData.closeDB(); Log.d(TAG, "[VisitorCallEventHandler] nAlarmStatus [" + nAlarmStatus + "]"); if (RemoteCallMSG.REMOTE_CALLTYPE == CALLTYPE.FRONT) { if (nAlarmStatus != WallpadStatusData.GUARD_OUT) sendBR_AppFinish(getApplicationContext()); } } } } } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); } catch (Exception e) { Log.e(TAG, "[Exception] VisitorCallEventHandler.handleMessage()"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } } }; class RemoteCallManagerHandler extends Handler { @Override public void handleMessage(Message msg) { Log.d(TAG, "[RemoteCallManagerHandler] what [" + msg.what + "], arg1 [" + msg.arg1 + "], arg2 [" + msg.arg2 + "], obj [" + msg.obj + "]"); switch (msg.what) { case REMOTECALLMSG.REGISTER: Log.w(TAG, "[RemoteCallManagerHandler] REGISTER [" + msg.obj + "]"); mRemoteMsns.add(msg.replyTo); break; case REMOTECALLMSG.UNREGISTER: Log.w(TAG, "[RemoteCallManagerHandler] UNREGISTER [" + msg.obj + "]"); mRemoteMsns.remove(msg.replyTo); break; case REMOTECALLMSG.SEND_OPEN_REMOTECALLLIB: openRemoteCallLib(msg.getData()); break; case REMOTECALLMSG.SEND_CLOSE_REMOTECALLLIB: closeRemoteCallLib(); break; case REMOTECALLMSG.SEND_MSG_TO_REMOTECALL: sendCommandToRemoteCall(msg.getData()); break; default: break; } } } private void openRemoteCallLib(Bundle mBundle) { try { CALLTYPE eCallType = CALLTYPE.getCALLTYPE(mBundle.getString(REMOTECALLHANDELKEY.CALLTYPE)); Log.d(TAG, "[openRemoteCallLib] eCallType [" + eCallType + "]"); if (mVisitorCallLib != null) { if (eCallType == CALLTYPE.FRONT) { CALLSTATUS eCallStatus = CALLSTATUS.getCALLSTATUS(mBundle.getString(REMOTECALLHANDELKEY.CALLSTATUS)); Log.d(TAG, "[openRemoteCallLib] eCallStatus [" + eCallStatus + "]"); mVisitorCallLib.ndkHandle = mHandle = mVisitorCallLib.OpenEx(dong, ho, REMOTECALL_CALLTYPE.CALLTYPE_DOOR, REMOTECALL_CALLOWNER.CALLEVENT_VISITOR); Log.d(TAG, "[openRemoteCallLib] mHandle [" + mHandle + "]"); } else if (eCallType == CALLTYPE.LOBBY) { mVisitorCallLib.ndkHandle = mHandle = mVisitorCallLib.OpenEx(dong, ho, REMOTECALL_CALLTYPE.CALLTYPE_LOBBY, REMOTECALL_CALLOWNER.CALLEVENT_VISITOR); Log.d(TAG, "[openRemoteCallLib] mHandle [" + mHandle + "]"); } else if (eCallType == CALLTYPE.GUARD) { String sRemoteSIPID = mBundle.getString(REMOTECALLHANDELKEY.REMOTEID); String sRemoteIP = mBundle.getString(REMOTECALLHANDELKEY.REMOTEIP); Log.d(TAG, "[openRemoteCallLib] sRemoteSIPID [" + sRemoteSIPID + "], sRemoteIP [" + sRemoteIP + "]"); mVisitorCallLib.ndkHandle = mHandle = mVisitorCallLib.OpenEx(dong, ho, getCallerName(eCallType, sRemoteSIPID, sRemoteIP), REMOTECALL_CALLOWNER.CALLEVENT_CALL); Log.d(TAG, "[openRemoteCallLib] mHandle [" + mHandle + "]"); } else { Log.w(TAG, "[openRemoteCallLib] Not Supported eCallType!! [" + eCallType + "]"); } } } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); } catch (Exception e) { Log.e(TAG, "[Exception] openRemoteCallLib(Bundle mBundle)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } } private void closeRemoteCallLib() { try { Log.d(TAG, "[closeRemoteCallLib] mHandle [" + mHandle + "]"); if (mVisitorCallLib != null) { if (mHandle >= 0) mVisitorCallLib.Close(mHandle); mVisitorCallLib.ndkHandle = mHandle = -1; } } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); } catch (Exception e) { Log.e(TAG, "[Exception] closeRemoteCallLib()"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } } // 추가된 사용자 정보 저장 private void addRemoteCallUserInfo(NodeList userList, Document document) { try { int nUserCnt = userList.getLength(); Log.d(TAG, "[addRemoteCallUserInfo] nUserCnt [" + nUserCnt + "]"); String Name = "", PhoneKey = "", MonitorAuth = "", LobbyOpenAuth = ""; for (int i = 0; i < nUserCnt; i++) { Node node = userList.item(i); Element element = (Element) node; NodeList phone_number = element.getElementsByTagName("phone_number"); PhoneKey = phone_number.item(0).getChildNodes().item(0).getNodeValue(); NodeList name = element.getElementsByTagName("name"); Name = name.item(0).getChildNodes().item(0).getNodeValue(); NodeList authList = document.getElementsByTagName("auth"); for (int j = 0; j < authList.getLength(); j++) { Node authNode = userList.item(j); Element authElement = (Element) authNode; NodeList monitor_auth = authElement.getElementsByTagName("monitor"); MonitorAuth = monitor_auth.item(0).getChildNodes().item(0).getNodeValue(); NodeList lobby_auth = authElement.getElementsByTagName("open_lobby"); LobbyOpenAuth = lobby_auth.item(0).getChildNodes().item(0).getNodeValue(); } } Log.d(TAG, "[addRemoteCallUserInfo] Name [" + Name + "], PhoneKey [" + PhoneKey + "], MonitorAuth [" + MonitorAuth + "], LobbyOpenAuth [" + LobbyOpenAuth + "]"); if (mVisitorCallLib != null) mVisitorCallLib.SetUserAuthority(dong, ho, PhoneKey, 1, Integer.parseInt(MonitorAuth), 0, Integer.parseInt(LobbyOpenAuth)); // 통화기능/영상감시/현관문열림/로비문열림 wallPadRemoteCallUserData.AddRemoteCallUserInfo(PhoneKey, Name); // DB에 추가 } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); } catch (Exception e) { Log.e(TAG, "[Exception] addRemoteCallUserInfo(NodeList userList, Document document)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } } // Open을 통해 연결된 세션으로 타명령어 전송 private void sendCommandToRemoteCall(Bundle mBundle) { try { int cmd = mBundle.getInt(REMOTECALLHANDELKEY.COMMAND); String strRemoteID = mBundle.getString(REMOTECALLHANDELKEY.REMOTEID); String strRemoteIP = mBundle.getString(REMOTECALLHANDELKEY.REMOTEIP); CALLTYPE eCallType = CALLTYPE.getCALLTYPE(mBundle.getString(REMOTECALLHANDELKEY.CALLTYPE)); Log.d(TAG, "[sendCommandToRemoteCall] cmd [" + cmd + "], strRemoteID [" + strRemoteID + "], strRemoteIP [" + strRemoteIP + "], eCallType [" + eCallType + "]"); if (eCallType != null) { String strCaller = getCallerName(eCallType, strRemoteID, strRemoteIP); Log.d(TAG, "[sendCommandToRemoteCall] strCaller [" + strCaller + "]"); if (mVisitorCallLib != null) { mVisitorCallLib.SendCommand(mVisitorCallLib.ndkHandle, cmd, strCaller); } } } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); } catch (Exception e) { Log.e(TAG, "[Exception] sendCommandToRemoteCall()"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } } // 원격지 ID와 IP로 Caller 이름 가져오기 private String getCallerName(CALLTYPE eCallType, String sRemoteID, String sRemoteIP) { try { Log.d(TAG, "[getCallerName] eCallType [" + eCallType + "]"); if (eCallType == CALLTYPE.GUARD || eCallType == CALLTYPE.RESIDENCE) { if ((sRemoteID != null) && (sRemoteIP != null)) { return getRemoteName(sRemoteID, sRemoteIP); } } else if (eCallType == CALLTYPE.FRONT) { return REMOTECALL_CALLER.CALLER_FRONT; } else if (eCallType == CALLTYPE.LOBBY) { return REMOTECALL_CALLER.CALLER_LOBBY; } return "NONE"; } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); return "ERROR"; } catch (Exception e) { Log.e(TAG, "[Exception] getCallerName(String strGuardIP)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); return "ERROR"; } } public String getRemoteName(String strSIPID, String strIP) { try { Log.d(TAG, "[getRemoteName] strSIPID [" + strSIPID + "], strIP [" + strIP + "]"); String[] strParse = strSIPID.split("_"); String strDeviceType = strParse[1]; String strHeadID = Integer.toString(Integer.parseInt(strParse[2])); String strTailID = Integer.toString(Integer.parseInt(strParse[3])); String strResult = "NONE"; if (strDeviceType.equalsIgnoreCase(Declare.DEVICENAME.strType_Resi)) { strResult = strHeadID + "동 " + strTailID + "호"; } else if (strDeviceType.equalsIgnoreCase(Declare.DEVICENAME.strType_RentResi)) { strResult = strHeadID + "동 " + strTailID + "-1호"; } else if (strDeviceType.equalsIgnoreCase(Declare.DEVICENAME.strType_Guard)) { strResult = getGuardName(strIP); if (strResult.equals("NONE") || strResult.equals("ERROR")) { strResult = strHeadID + "동 " + strTailID + "번 경비"; } if (strResult.equals("경비실")) strResult = REMOTECALL_CALLTYPE.CALLTYPE_CTRL_GUARD; else if (strResult.equals("관리실")) strResult = REMOTECALL_CALLTYPE.CALLTYPE_OFFICE_GUARD; else if (strResult.contains("정문")) strResult = REMOTECALL_CALLTYPE.CALLTYPE_MAINGATE_GUARD; else if (strResult.contains("후문")) strResult = REMOTECALL_CALLTYPE.CALLTYPE_SUBGATE_GUARD; } else if (strDeviceType.equalsIgnoreCase(Declare.DEVICENAME.strType_Lobby)) { strResult = strHeadID + "동 " + strTailID + "번 로비폰"; } Log.d(TAG, "[getRemoteName] strResult [" + strResult + "]"); return strResult; } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); return "ERROR"; } catch (Exception e) { Log.e(TAG, "[Exception] getRemoteName(String strSIPID, String strIP)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); return "ERROR"; } } public String getGuardName(String strGuardIP) { try { Log.d(TAG, "[getGuardName] strGuardIP [" + strGuardIP + "]"); if (mGuardListTable == null) { Log.w(TAG, "[getGuardName] mGuardListTable is null!"); getGuardList(); } if (mGuardListTable != null) { int nGuardCnt = mGuardListTable.getCnt(); for (int i = 0; i < nGuardCnt; i++) { if (mGuardListTable.getGuardInfo(i).IP().equals(strGuardIP)) { String strGuardName = mGuardListTable.getGuardInfo(i).NAME(); Log.d(TAG, "[getGuardName] strGuardName [" + strGuardName + "]"); return strGuardName; } } } return "NONE"; } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); return "ERROR"; } catch (Exception e) { Log.e(TAG, "[Exception] getGuardName(String strGuardIP)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); return "ERROR"; } } public String getGuardID(String strGuardName) { try { if (strGuardName.equals(REMOTECALL_CALLTYPE.CALLTYPE_CTRL_GUARD)) return REMOTECALLHANDELKEY.GUARD_01; else if (strGuardName.equals(REMOTECALL_CALLTYPE.CALLTYPE_MAINGATE_GUARD)) return REMOTECALLHANDELKEY.GUARD_02; else if (strGuardName.equals(REMOTECALL_CALLTYPE.CALLTYPE_SUBGATE_GUARD)) return REMOTECALLHANDELKEY.GUARD_03; else if (strGuardName.equals(REMOTECALL_CALLTYPE.CALLTYPE_OFFICE_GUARD)) return REMOTECALLHANDELKEY.GUARD_04; else return REMOTECALLHANDELKEY.GUARD_01; } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); return null; } catch (Exception e) { Log.e(TAG, "[Exception] getGuardID(String strGuardName)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); return null; } } private String getGuardList() { try { List GuardList = null; WallpadDeviceSet deviceSet = new WallpadDeviceSet(getApplicationContext()); GuardList = deviceSet.GetGuardList(); mGuardListTable = new GuardListTable(); mGuardListTable.clearTable(); Log.d(TAG, "[getGuardList] GuardList.size [" + GuardList.size() + "]"); for (int i = 0; i < GuardList.size(); i++) { Log.d(TAG, "[getGuardList] GuardList [" + i + "] = " + GuardList.get(i)[0]); mGuardListTable.addGuardTable(GuardList.get(i)[0], Global.makeGuardIP(GuardList.get(i)[1]), null); } deviceSet.closeDB(); int nGuardCnt = mGuardListTable.getCnt(); if (nGuardCnt > 0) { REMOTECALL_CALLTYPE.CALLTYPE_GUARD_NAME = new ArrayList<>(); REMOTECALL_CALLTYPE.CALLTYPE_GUARD_NAME.clear(); for (int i = 0; i < nGuardCnt; i++) { if (mGuardListTable.getGuardInfo(i).NAME().equals("경비실")) { REMOTECALL_CALLTYPE.CALLTYPE_GUARD_NAME.add(REMOTECALL_CALLTYPE.CALLTYPE_CTRL_GUARD); REMOTECALL_CALLTYPE.strCONTROLGUARD_IP = mGuardListTable.getGuardInfo(i).IP(); } else if (mGuardListTable.getGuardInfo(i).NAME().contains("정문")) { REMOTECALL_CALLTYPE.CALLTYPE_GUARD_NAME.add(REMOTECALL_CALLTYPE.CALLTYPE_MAINGATE_GUARD); REMOTECALL_CALLTYPE.strMAINGATEGUARD_IP = mGuardListTable.getGuardInfo(i).IP(); } else if (mGuardListTable.getGuardInfo(i).NAME().contains("후문")) { REMOTECALL_CALLTYPE.CALLTYPE_GUARD_NAME.add(REMOTECALL_CALLTYPE.CALLTYPE_SUBGATE_GUARD); REMOTECALL_CALLTYPE.strSUBGATEGUARD_IP = mGuardListTable.getGuardInfo(i).IP(); } else if (mGuardListTable.getGuardInfo(i).NAME().equals("관리실")) { REMOTECALL_CALLTYPE.CALLTYPE_GUARD_NAME.add(REMOTECALL_CALLTYPE.CALLTYPE_OFFICE_GUARD); REMOTECALL_CALLTYPE.strOFFICEGUARD_IP = mGuardListTable.getGuardInfo(i).IP(); } } String strGuardList = ""; for (int i = 0; i < REMOTECALL_CALLTYPE.CALLTYPE_GUARD_NAME.size(); i++) { strGuardList += REMOTECALL_CALLTYPE.CALLTYPE_GUARD_NAME.get(i) + ","; } strGuardList = strGuardList.substring(0, strGuardList.length() - 1); Log.d(TAG, "[getGuardList] strGuardList [" + strGuardList + "]"); return strGuardList; } return null; } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); return null; } catch (Exception e) { Log.e(TAG, "[Exception] getGuardList()"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); return null; } } private int tryGuardCall(String strGuardInfo) { try { Log.d(TAG, "[tryGuardCall] strGuardInfo [" + strGuardInfo + "]"); String strGuardIP = ""; if (strGuardInfo != null) { if (strGuardInfo.equals(REMOTECALLHANDELKEY.GUARD_01)) strGuardIP = REMOTECALL_CALLTYPE.strCONTROLGUARD_IP; else if (strGuardInfo.equals(REMOTECALLHANDELKEY.GUARD_02)) strGuardIP = REMOTECALL_CALLTYPE.strMAINGATEGUARD_IP; else if (strGuardInfo.equals(REMOTECALLHANDELKEY.GUARD_03)) strGuardIP = REMOTECALL_CALLTYPE.strSUBGATEGUARD_IP; else if (strGuardInfo.equals(REMOTECALLHANDELKEY.GUARD_04)) strGuardIP = REMOTECALL_CALLTYPE.strOFFICEGUARD_IP; Log.d(TAG, "[tryGuardCall] strGuardIP [" + strGuardIP + "]"); if (!strGuardIP.equals("")) { String[] IP_Parse = strGuardIP.split("\\."); int nDong = 101; if (ConfigValues.bIPExpansion) { if (IP_Parse[1].equals("0")) nDong = 100; else nDong = (Integer.parseInt(IP_Parse[0]) * 100) + Integer.parseInt(IP_Parse[1]); } else { nDong = ((Integer.parseInt(Global.getDongString()) / 100) * 100) + Integer.parseInt(IP_Parse[1]); } int nHo = Integer.parseInt(IP_Parse[3]); RemoteIDInfo.strDong = Integer.toString(nDong); RemoteIDInfo.strHo = Integer.toString(nHo); Log.d(TAG, "[tryGuardCall] strDong [" + RemoteIDInfo.strDong + "], strHo [" + RemoteIDInfo.strHo + "]"); bGuardConnCheck = false; // 변수 초기화 if (send_check_sip_activation_request(strGuardIP)) { if (!bGuardConnCheck) Thread.sleep(2000); // TODO SIP 연결 체크를 위한 딜레이 Log.d(TAG, "[tryGuardCall] bGuardConnCheck [" + bGuardConnCheck + "]"); if (bGuardConnCheck) return 0; } } } } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); } catch (Exception e) { Log.e(TAG, "[Exception] tryGuardCall()"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } return -1; } private boolean bGuardConnCheck = false; // 경비실기 SIP 연결 여부 private boolean send_check_sip_activation_request(final String strTargetIP) { try { Request_check_sip_activation check_sip_activation = new Request_check_sip_activation(getApplicationContext()); if (check_sip_activation.send_check_sip_activation(strTargetIP, null)) { check_sip_activation.setResultCtrl(new RetProci() { @Override public void ProcSuccess() { Log.d(TAG, "[send_check_sip_activation_request] ProcSuccess()"); bGuardConnCheck = true; runCallMainActivity(CALLOWNER.MOBILE, CALLEVENTTYPE.TRYING_CALL, CALLTYPE.GUARD, strTargetIP); // 통화 앱 실행 } @Override public void ProcError() { Log.e(TAG, "[send_check_sip_activation_request] ProcError()"); bGuardConnCheck = false; closeRemoteCallLib(); // 경비실기 통신 실패시 방문객원격통화 세션 닫기 } @Override public void ProcDoing() { } }); Log.d(TAG, "[send_check_sip_activation_request] bGuardConnCheck [" + bGuardConnCheck + "]"); return true; } } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); } catch (Exception e) { Log.e(TAG, "[Exception] send_check_sip_activation_request(String strTargetIP)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } return false; } private static String strPHONE_KEY = ""; private void callRegisteredUserList(String phoneKey) { try { strPHONE_KEY = phoneKey; Log.d(TAG, "[callRegisteredUserList] strPHONE_KEY [" + strPHONE_KEY + "]"); if (mVisitorCallLib != null) { Log.d(TAG, "[callRegisteredUserList] dong [" + dong + "], ho [" + ho + "]"); mVisitorCallLib.GetRegisteredUserList(dong, ho); // 사용자 리스트 요청 } } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); } catch (Exception e) { Log.e(TAG, "[Exception] callRegisteredUserList(String phoneKey)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } } String strWallPadCallPackageName = "kr.co.icontrols.wallpadcall"; String strWallPadCallMainActivityName = "kr.co.icontrols.wallpadcall.MainActivity"; public void runCallMainActivity(CALLOWNER eCallOwner, CALLEVENTTYPE eEventType, CALLTYPE eCallType, String strRemoteInfo) { try { if (mHandle < 0) { Log.w(TAG, "[runCallMainActivity] mHandle [" + mHandle + "]"); closeRemoteCallLib(); return; // 모바일에서 세션이 끊어진 경우 통화 앱 실행 안함 } if (!SIPStun.bWallPadCallLive) { // 통화어플을 실행시킨다. Log.d(TAG, "[runCallMainActivity] ########## START ##########"); sendLCDBacklightStatus(true); WallpadStatusData mWallpadStatusData = new WallpadStatusData(getApplicationContext()); int nAlarmStatus = mWallpadStatusData.GetAlarmStatus(); mWallpadStatusData.closeDB(); Log.d(TAG, "[runCallMainActivity] nAlarmStatus [" + nAlarmStatus + "]"); if (nAlarmStatus != WallpadStatusData.GUARD_OUT) sendBR_AppFinish(getApplicationContext()); ComponentName mComponentName = new ComponentName(strWallPadCallPackageName, strWallPadCallMainActivityName); Intent mIntent = new Intent(Intent.ACTION_MAIN); mIntent.putExtra(CALLTRIGGER.CALLOWNER, eCallOwner.toString()); mIntent.putExtra(CALLTRIGGER.CALLEVENTTYPE, eEventType.toString()); mIntent.putExtra(CALLTRIGGER.CALLTYPE, eCallType.toString()); mIntent.putExtra(CALLTRIGGER.REMOTEINFO, strRemoteInfo); mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); mIntent.setComponent(mComponentName); startActivity(mIntent); Thread.sleep(500); } else { Log.w(TAG, "[runCallMainActivity] WallPadCall is already running!!"); } } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); } catch (Exception e) { Log.e(TAG, "[Exception] runCallMainActivity(CALLOWNER eCallOwner, CALLEVENTTYPE eEventType, CALLTYPE eCallType, String strRemoteInfo)"); //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); } } public final class HANDLERMSG { public final static int REGISTER_REMOTECALL_LIB = 100; public final static int GET_USERLIST = 200; } public Handler mHandler = new Handler(Looper.getMainLooper()) { public void handleMessage(Message msg) { Log.d(TAG, "[mHandler] what [" + msg.what + "], arg1 [" + msg.arg1 + "], arg2 [" + msg.arg2 + "]"); switch (msg.what) { case HANDLERMSG.REGISTER_REMOTECALL_LIB: registerRemoteCallLib(); break; case HANDLERMSG.GET_USERLIST: callRegisteredUserList((String) msg.obj); break; default: break; } } }; public void sendHandlerMsg(int what, int arg1, int arg2, Object obj) { try { Log.d(TAG, "[sendHandlerMsg] what [" + what + "], arg1 [" + arg1 + "], arg2 [" + arg2 + "], obj [" + obj.toString() + "]"); Message HandleMsg = mHandler.obtainMessage(); HandleMsg.what = what; HandleMsg.arg1 = arg1; HandleMsg.arg2 = arg2; HandleMsg.obj = obj; mHandler.sendMessage(HandleMsg); } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); } catch (Exception e) { Log.e(TAG, "[Exception] sendHandlerMsg(int what, int arg1, int arg2, Object obj)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } } public void sendHandlerMsgDelayed(int what, int arg1, int arg2, long delay) { try { Log.d(TAG, "[sendHandlerMsgDelayed] what [" + what + "], arg1 [" + arg1 + "], arg2 [" + arg2 + "], delay [" + delay + "]"); Message HandleMsg = mHandler.obtainMessage(); HandleMsg.what = what; HandleMsg.arg1 = arg1; HandleMsg.arg2 = arg2; mHandler.sendMessageDelayed(HandleMsg, delay); } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); } catch (Exception e) { Log.e(TAG, "[Exception] sendHandlerMsgDelayed(int what, int arg1, int arg2, long delay"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } } private final static String STRING_SPLITER = "/"; // 방문객원격통화 User Info Spliter // BR BroadcastReceiver mRemoteCallBR = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { try { String strAction = intent.getAction(); Log.d(TAG, "[mRemoteCallBR.onReceive] strAction [" + strAction + "]"); if (strAction.equals(Declare.BR.VISITOR_REMOTE_CALL)) { int kind = intent.getIntExtra(define.NOTIBR_KIND, -1); // Log.d(TAG, "[mRemoteCallBR] kind [" + kind + "]"); if (kind == define.NOTIFY_EVENT_REMOTECALL_USER_INITIALIZE) { registerRemoteCallLib(); } else if (kind == define.NOTIFY_EVENT_REMOTECALL_USER_DELETE) { String strPhoneKey = intent.getStringExtra(define.NOTIBR_REMOTECALL_USER_DELETE_PHONEKEY); if (strPhoneKey != null) { Log.d(TAG, "[mRemoteCallBR] strPhoneKey [" + strPhoneKey + "]"); if (!strPhoneKey.equals("")) { if (mVisitorCallLib != null) mVisitorCallLib.DelRegisteredUserList(dong, ho, strPhoneKey); // 라이브러리 삭제 } } } else if (kind == define.NOTIFY_EVENT_REMOTECALL_USER_CHANGE_AUTHORITY) { String[] strInfo = intent.getStringExtra(define.NOTIBR_REMOTECALL_USER_CHANGE_AUTHORITY_INFO).split(STRING_SPLITER); // PhoneKey/MonitorAuth/LobbyOpenAuth/DoorOpenAuth/HomeViewerAuth; if (strInfo != null) { String strPhoneKey = strInfo[0]; String strMonitorAuth = strInfo[1]; String strLobbyOpenAuth = strInfo[2]; String strDoorOpenAuth = strInfo[3]; String strHomeViewerAuth = strInfo[4]; Log.d(TAG, "[mRemoteCallBR] strPhoneKey [" + strPhoneKey + "], strMonitorAuth [" + strMonitorAuth + "], strLobbyOpenAuth [" + strLobbyOpenAuth + "], " + "strDoorOpenAuth [" + strDoorOpenAuth + "], strHomeViewerAuth [" + strHomeViewerAuth + "]"); if (mVisitorCallLib != null) { // 라이브러리 변경 (통화 권한은 모니터링 권한과 동일하게 설정, 현관문열림 권한은 항상 0) if (mVisitorCallLib.SetUserAuthority(dong, ho, strPhoneKey, Integer.parseInt(strMonitorAuth), Integer.parseInt(strMonitorAuth), 0, Integer.parseInt(strLobbyOpenAuth)) >= 0) { // DB 테이블 변경 wallPadRemoteCallUserData.UpdateRemoteCallUserInfo(strPhoneKey, Declare.DBInfo.VALUE_NAME_HISTORY_USER[2], strMonitorAuth); wallPadRemoteCallUserData.UpdateRemoteCallUserInfo(strPhoneKey, Declare.DBInfo.VALUE_NAME_HISTORY_USER[3], strLobbyOpenAuth); wallPadRemoteCallUserData.UpdateRemoteCallUserInfo(strPhoneKey, Declare.DBInfo.VALUE_NAME_HISTORY_USER[4], strDoorOpenAuth); wallPadRemoteCallUserData.UpdateRemoteCallUserInfo(strPhoneKey, Declare.DBInfo.VALUE_NAME_HISTORY_USER[5], strHomeViewerAuth); } } } } else if (kind == define.NOTIFY_EVENT_REMOTECALL_USER_AUTHORITY_KEY) { String strKey = intent.getStringExtra("USER_AUTH_KEY"); Log.d(TAG, "[mRemoteCallBR] strKey [" + strKey + "]"); if (strKey != null) { mVisitorCallLib.SendRegistrationKey(dong, ho, strKey); } } else if (kind == define.NOTIFY_EVENT_CHANGE_GUARDLIST) { // 경비실기 설정정보가 변경된 경우 방문객원격통화 스트림 서버로 경비실기 목록 다시 전달 String strGuardList = getGuardList(); if (strGuardList != null) { Log.d(TAG, "[mRemoteCallBR] strGuardList [" + strGuardList + "]"); if (!strGuardList.equals("")) { Log.d(TAG, "[mRemoteCallBR] == mVisitorCallLib.SetSecurityOffice =="); int nResult = mVisitorCallLib.SetSecurityOffice(dong, ho, strGuardList); // 경비실기 목록 재전달 Log.d(TAG, "[mRemoteCallBR] nResult [" + nResult + "]"); } } } } } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); } catch (Exception e) { Log.e(TAG, "[Exception] onReceive(Context context, Intent intent)"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } } }; private void registerBRReceiver() { try { IntentFilter filter = new IntentFilter(); filter.addAction(Declare.BR.VISITOR_REMOTE_CALL); registerReceiver(mRemoteCallBR, filter, null, null); } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); } catch (Exception e) { Log.e(TAG, "[Exception] registerBRReceiver()"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } } private void unregisterBRReceiver() { try { if (mRemoteCallBR != null) { unregisterReceiver(mRemoteCallBR); } } catch (RuntimeException re) { LogUtil.errorLogInfo("", TAG, re); } catch (Exception e) { Log.e(TAG, "[Exception] unregisterBRReceiver()"); //e.printStackTrace(); LogUtil.errorLogInfo("", TAG, e); } } private void sendBR_AppFinish(Context context) { try { Log.d(TAG, "[sendBR_AppFinish] Send App Finish!!"); Intent mIntent = new Intent(); mIntent.setAction(define.BR_APP_FINISH); mIntent.putExtra(CALLTRIGGER.CALLOWNER, "MOBILE"); 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); } } }