SIPStun.java 276 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328
  1. package kr.co.icontrols.callengine.sip;
  2. import android.app.ActivityManager;
  3. import android.app.Service;
  4. import android.content.BroadcastReceiver;
  5. import android.content.ComponentName;
  6. import android.content.Context;
  7. import android.content.Intent;
  8. import android.content.IntentFilter;
  9. import android.content.SharedPreferences;
  10. import android.media.AudioManager;
  11. import android.media.MediaPlayer;
  12. import android.media.audiofx.Equalizer;
  13. import android.net.ConnectivityManager;
  14. import android.net.NetworkInfo;
  15. import android.os.Build;
  16. import android.os.Bundle;
  17. import android.os.Handler;
  18. import android.os.IBinder;
  19. import android.os.Looper;
  20. import android.os.Message;
  21. import android.os.Messenger;
  22. import android.os.RemoteException;
  23. import android.util.Log;
  24. import com.artncore.WallPadDataMgr.WallpadDeviceSet;
  25. import com.artncore.WallPadDataMgr.WallpadStatusData;
  26. import com.artncore.WallPadDataMgr.wallpaddbmgr;
  27. import com.artncore.WallPadDataMgr.wallpaddbmgr.AddressSet;
  28. import com.artncore.commons.define;
  29. import com.util.LogUtil;
  30. import java.io.IOException;
  31. import java.net.DatagramPacket;
  32. import java.net.DatagramSocket;
  33. import java.net.InetAddress;
  34. import java.net.NetworkInterface;
  35. import java.net.SocketException;
  36. import java.net.SocketTimeoutException;
  37. import java.net.UnknownHostException;
  38. import java.util.ArrayList;
  39. import java.util.Collections;
  40. import java.util.Date;
  41. import java.util.List;
  42. import java.util.StringTokenizer;
  43. import java.util.TimerTask;
  44. import java.util.regex.Pattern;
  45. import bssoft.stack.sip.BSSVideo;
  46. import bssoft.stack.sip.CMCore;
  47. import bssoft.stack.sip.SIPCONTACTHeader;
  48. import bssoft.stack.sip.SIPCall;
  49. import bssoft.stack.sip.SIPHeader;
  50. import bssoft.stack.sip.SIPRequestLine;
  51. import bssoft.stack.sip.SIPStack;
  52. import kr.co.icontrols.callengine.engine.CallManager;
  53. import kr.co.icontrols.callengine.remotecall.AVPacket;
  54. import kr.co.icontrols.callengine.engine.CallManager.CALLEVENTTYPE;
  55. import kr.co.icontrols.callengine.engine.CallManager.CALLTYPE;
  56. import kr.co.icontrols.wallpadcall.MainActivity;
  57. import kr.co.icontrols.wallpadcall.declare.Common;
  58. import kr.co.icontrols.wallpadcall.declare.Declare;
  59. import kr.co.icontrols.wallpadcall.declare.Declare.CALLTRIGGER;
  60. public class SIPStun extends Service {
  61. static final String TAG = "SIPStun";
  62. boolean bLOG = true;
  63. private void LOG(String log) {
  64. if (bLOG) Log.v(TAG, log);
  65. }
  66. boolean bLOG_DEBUG = true;
  67. private void LOG_DEBUG(String log) {
  68. if (bLOG_DEBUG) Log.d(TAG, log);
  69. }
  70. boolean bLOG_INFO = true;
  71. private void LOG_INFO(String log) {
  72. if (bLOG_INFO) Log.i(TAG, log);
  73. }
  74. boolean bLOG_WARN = true;
  75. private void LOG_WARN(String log) {
  76. if (bLOG_WARN) Log.w(TAG, log);
  77. }
  78. boolean bLOG_ERROR = true;
  79. private void LOG_ERROR(String log) {
  80. if (bLOG_ERROR) Log.e(TAG, log);
  81. }
  82. public SIPSignalReceiver mSIPSignalReceiver = null;
  83. android.media.Ringtone oRingTone = null;
  84. MediaPlayer oRingbackTone = null;
  85. CMCore cmcore = null;
  86. ConnectivityManager connectivityManager = null;
  87. protected static String padNumber = "";
  88. protected static int officeNumber = 0; // 1:정문 2:후문 3:관할 4:관리사무소
  89. protected int latestMenu = 0;
  90. private static boolean isRunning = false;
  91. ArrayList<Messenger> mClients = new ArrayList<Messenger>();
  92. final Messenger mMessenger = new Messenger(new CmPiper());
  93. public static boolean bBlackCall = false;
  94. public static boolean bBlackCallSupport = true;
  95. public static boolean bBlackcallBackgroundMode = true;
  96. boolean bBLOCK_INVITE_MSG = false;
  97. static AVPacket avPacket = null; // 방문객 원격통화 모바일 오디오 데이터
  98. private boolean bLobbyCallUse = false, bGuardCallUse = false, bResiCallUse = false;
  99. @Override
  100. public IBinder onBind(Intent intent) {
  101. return mMessenger.getBinder();
  102. }
  103. class CmPiper extends Handler { // Handler of incoming messages from UI.
  104. @Override
  105. public void handleMessage(Message msg) {
  106. String value = "null";
  107. switch (msg.what) {
  108. case CMCore.BSSSIPStun_ICONTROLS_REGISTER:
  109. mClients.add(msg.replyTo);
  110. Log.i(TAG, "SIPStun CmPiper DIALER_REGISTER : " + msg.toString());
  111. updateBlockStatus();
  112. if (SIPStack.bDirectCall == true) {
  113. if (padNumber == null || padNumber.length() == 0) {
  114. boolean bValidroom = getMyroomname();
  115. if (bValidroom == false) {
  116. Log.i(TAG, "Invalid room");
  117. dialerPadNumber("");
  118. } else dialerPadNumber(padNumber);
  119. } else dialerPadNumber(padNumber);
  120. if (SIPStun.bBlackcallBackgroundMode == true) {
  121. if (SIPStun.bBlackCall == true && SIPController.sipCall.flag == true && SIPController.sipCall.bResponsebackgroundcall == true && SIPController.sipCall.bResponsebackgroundcallReady == false) {
  122. SIPController.sipCall.bResponsebackgroundcallReady = true;
  123. SIPController.sipCall.responsebackgroundcallTimer = new Date();
  124. } else {
  125. dialerPadType(BSSVideo.HNS_SERVICE_ORIGINATOR_SELECTED, officeNumber);
  126. }
  127. } else {
  128. dialerPadType(BSSVideo.HNS_SERVICE_ORIGINATOR_SELECTED, officeNumber);
  129. }
  130. }
  131. break;
  132. case CMCore.BSSSIPStun_ICONTROLS_UNREGISTER:
  133. mClients.remove(msg.replyTo);
  134. Log.i(TAG, "SIPStun CmPiper CMCore.BSSSIPStun_ICONTROLS_UNREGISTER : " + msg.toString());
  135. callTerminate();
  136. break;
  137. case CMCore.BSSSIPStun_ICONTROLS_DIALER_COMMAND:
  138. Log.i(TAG, "SIPStun CmPiper CMCore.BSSSIPStun_ICONTROLS_DIALER_COMMAND : " + msg.toString());
  139. break;
  140. case CMCore.BSSSIPStun_ICONTROLS_CONTACT_CALLNEIGHBOR:
  141. value = msg.getData().getString("CALLNEIGHBOR");
  142. Log.i(TAG, ">>>SIPStun CmPiper BSSSIPStun_ICONTROLS_CONTACT_CALLNEIGHBOR : " + value);
  143. break;
  144. case CMCore.BSSSIPStun_ICONTROLS_CONTACT_CALLGUARD:
  145. value = msg.getData().getString("CALLGUARD");
  146. Log.i(TAG, ">>>SIPStun CmPiper BSSSIPStun_ICONTROLS_CONTACT_CALLGUARD : " + value);
  147. break;
  148. case CMCore.BSSSIPStun_ICONTROLS_DIALER_ACCEPTMULTICALL:
  149. value = msg.getData().getString("ACCEPTMULTICALL");
  150. if (SIPController.pendingCall != null && SIPController.pendingCall.flag == true) {
  151. SIPController.pendingCall.bAsMaster = true;
  152. }
  153. Log.i(TAG, ">>>SIPStun CmPiper BSSSIPStun_ICONTROLS_DIALER_ACCEPTMULTICALL");
  154. break;
  155. case CMCore.BSSSIPStun_ICONTROLS_DIALER_REJECTMULTICALL:
  156. value = msg.getData().getString("REJECTMULTICALL");
  157. if (SIPController.pendingCall != null && SIPController.pendingCall.flag == true) {
  158. SIPController.pendingCall.bRejectRequest = true;
  159. }
  160. Log.i(TAG, ">>>SIPStun CmPiper BSSSIPStun_ICONTROLS_DIALER_REJECTMULTICALL");
  161. break;
  162. case CMCore.BSSSIPStun_ICONTROLS_DIALER_FORWARD:
  163. value = msg.getData().getString("FORWARD");
  164. if (SIPController.sipCall != null && SIPController.sipCall.flag == true) {
  165. Log.i(TAG, ">>>SIPStun CmPiper BSSSIPStun_ICONTROLS_DIALER_FORWARD : " + value);
  166. SIPController.forward.contact = new String(value);
  167. SIPController.sipCall.bForwardRequest = true;
  168. }
  169. Log.i(TAG, ">>>SIPStun CmPiper BSSSIPStun_ICONTROLS_DIALER_FORWARD");
  170. Log.d(TAG, "FORWARD : " + value);
  171. break;
  172. case CMCore.BSSSIPStun_ICONTROLS_SET_INT_VALUE:
  173. String strEQCtrl = msg.getData().getString("cmd");
  174. Log.w(TAG, "strEQCtrl [" + strEQCtrl + "]");
  175. if (strEQCtrl.equals("get_eq_values")) {
  176. replyEQValue();
  177. } else if (strEQCtrl.equals("set_eq_value")) {
  178. String strEQ = msg.getData().getString("eq");
  179. short sValue = msg.getData().getShort("value");
  180. setEQValue(strEQ, sValue);
  181. }
  182. break;
  183. case CMCore.BSSSIPStun_ICONTROLS_BLOCK_INVITE_MSG:
  184. Log.e(TAG, "[CmPiper] BSSSIPStun_ICONTROLS_BLOCK_INVITE_MSG");
  185. // BR을 수신하여 처리하는 것으로 변경하였으나, 혹시몰라 여기도 남겨둠
  186. bBLOCK_INVITE_MSG = true;
  187. StunHandler.removeMessages(HANDLERMSG.RELEASE_BLOCK_INVITE_MSG);
  188. sendHandlerMsgDelayed(HANDLERMSG.RELEASE_BLOCK_INVITE_MSG, 0, 0, 3000);
  189. break;
  190. case Declare.VISITORREMOTECALL.BSSSIPStun_ICONTROLS_RECEIVE_MOBILE_AUDIO_LOBBY:
  191. avPacket = (AVPacket) msg.getData().getSerializable(Declare.VISITORREMOTECALL.MOBILE_AUDIO_TO_LOBBY);
  192. SIPSound.bufferringMobileAudio(avPacket.data, avPacket.length);
  193. break;
  194. case Declare.VISITORREMOTECALL.BSSSIPStun_ICONTROLS_RECEIVE_MOBILE_AUDIO_GUARD:
  195. avPacket = (AVPacket) msg.getData().getSerializable(Declare.VISITORREMOTECALL.MOBILE_AUDIO_TO_GUARD);
  196. SIPSound.bufferringMobileAudio(avPacket.data, avPacket.length);
  197. break;
  198. default:
  199. Log.i(TAG, "SIPStun CmPiper default:" + msg.toString());
  200. super.handleMessage(msg);
  201. }
  202. }
  203. }
  204. public final class HANDLERMSG {
  205. public final static int RELEASE_BLOCK_INVITE_MSG = 100;
  206. public final static int NEWCALL_TRY_01 = 200;
  207. public final static int NEWCALL_TRY_02 = 300;
  208. public final static int NEWCALL_TRY_03 = 400;
  209. public final static int NEWCALL_TRY_04 = 500;
  210. public final static int NEWCALL_TRY_05 = 600;
  211. }
  212. boolean bRECEIVE_REMOTE_AUDIO = false;
  213. public Handler StunHandler = new Handler(Looper.getMainLooper()) {
  214. public void handleMessage(Message msg) {
  215. LOG("[StunHandler] StunHandler : what [" + msg.what + "], arg1 [" + msg.arg1 + "], arg2 [" + msg.arg2 + "]");
  216. switch (msg.what) {
  217. case HANDLERMSG.RELEASE_BLOCK_INVITE_MSG:
  218. bBLOCK_INVITE_MSG = false;
  219. updateBlockStatus();
  220. break;
  221. case HANDLERMSG.NEWCALL_TRY_01:
  222. break;
  223. case HANDLERMSG.NEWCALL_TRY_02:
  224. break;
  225. case HANDLERMSG.NEWCALL_TRY_03:
  226. break;
  227. case HANDLERMSG.NEWCALL_TRY_04:
  228. break;
  229. case HANDLERMSG.NEWCALL_TRY_05:
  230. break;
  231. default:
  232. LOG("StunHandler : " + msg.what);
  233. break;
  234. }
  235. }
  236. };
  237. public void sendHandlerMsg(int what, int arg1, int arg2) {
  238. try {
  239. LOG("[sendHandlerMsg] what [" + what + "], arg1 [" + arg1 + "], arg2 [" + arg2 + "]");
  240. Message HandleMsg = StunHandler.obtainMessage();
  241. HandleMsg.what = what;
  242. HandleMsg.arg1 = arg1;
  243. HandleMsg.arg2 = arg2;
  244. StunHandler.sendMessage(HandleMsg);
  245. } catch (RuntimeException re) {
  246. LogUtil.errorLogInfo("", TAG, re);
  247. } catch (Exception e) {
  248. Log.e(TAG, "[Exception] sendHandlerMsg(msg)");
  249. //e.printStackTrace();
  250. LogUtil.errorLogInfo("", TAG, e);
  251. }
  252. }
  253. public void sendHandlerMsg(int what, int arg1, int arg2, Object obj) {
  254. try {
  255. LOG("[sendHandlerMsg] what [" + what + "], arg1 [" + arg1 + "], arg2 [" + arg2 + "]");
  256. Message HandleMsg = StunHandler.obtainMessage();
  257. HandleMsg.what = what;
  258. HandleMsg.arg1 = arg1;
  259. HandleMsg.arg2 = arg2;
  260. HandleMsg.obj= obj;
  261. StunHandler.sendMessage(HandleMsg);
  262. } catch (RuntimeException re) {
  263. LogUtil.errorLogInfo("", TAG, re);
  264. } catch (Exception e) {
  265. Log.e(TAG, "[Exception] sendHandlerMsg(msg)");
  266. //e.printStackTrace();
  267. LogUtil.errorLogInfo("", TAG, e);
  268. }
  269. }
  270. public void sendHandlerMsgDelayed(int what, int arg1, int arg2, long delay) {
  271. try {
  272. LOG("[sendHandlerMsgDelayed] what [" + what + "], arg1 [" + arg1 + "], arg2 [" + arg2 + "], delay [" + delay + "]");
  273. Message HandleMsg = StunHandler.obtainMessage();
  274. HandleMsg.what = what;
  275. HandleMsg.arg1 = arg1;
  276. HandleMsg.arg2 = arg2;
  277. StunHandler.sendMessageDelayed(HandleMsg, delay);
  278. } catch (RuntimeException re) {
  279. LogUtil.errorLogInfo("", TAG, re);
  280. } catch (Exception e) {
  281. Log.e(TAG, "[Exception] sendHandlerMsgDelayed(msg)");
  282. //e.printStackTrace();
  283. LogUtil.errorLogInfo("", TAG, e);
  284. }
  285. }
  286. @Override
  287. public void onCreate() {
  288. SIPStack.SIP_MESSAGE_DEBUG = true;
  289. Log.i(TAG, " SIPStun onCreate called newly");
  290. super.onCreate();
  291. SIPStack.setLicense("주식회사아이콘트롤스 200701243005451");
  292. SIPStack.bootTime = new Date();
  293. BSSVideo.bService = false;
  294. BSSVideo.bViewme = false;
  295. SIPStack.ventureCall = true;
  296. // 서비스폰 타입설정 ////////////////////////////////////////////////////////////
  297. BSSVideo.HNS_SERVICE_ORIGINATOR_SELECTED = BSSVideo.HNS_SERVICE_NEIGHBOR;
  298. //세대기:HNS_SERVICE_NEIGHBOR,
  299. //로비폰:HNS_SERVICE_LOBBY,
  300. //경비실폰:HNS_SERVICE_GUARD
  301. BSSVideo.HNS_SERVICE_RECEIVER_SELECTED = BSSVideo.HNS_SERVICE_NONE;
  302. latestMenu = BSSVideo.HNS_SERVICE_ORIGINATOR_SELECTED;
  303. if (BSSVideo.HNS_SERVICE_ORIGINATOR_SELECTED == BSSVideo.HNS_SERVICE_GUARD) {
  304. officeNumber = 1; //1:정문 2:후문 3:관할 4:관리사무소
  305. } else officeNumber = 0; //not assign
  306. if (SIPStack.bActive == false) {
  307. if (SIPController.BACKGROUNDTimer != null) SIPController.BACKGROUNDTimer.cancel();
  308. Log.i(TAG, "===================== SIPStack.init!! =====================");
  309. SIPController.init();
  310. SIPStack.bNetworkActive = false;
  311. }
  312. SIPStack.bBackgroundRunning = false;
  313. SIPStack.bGeneralPhoneDetected = false;
  314. getStackKey();
  315. WallpadDeviceSet deviceSet = new WallpadDeviceSet(this);
  316. bLobbyCallUse = deviceSet.Get_LobbyCallUse();
  317. bGuardCallUse = deviceSet.Get_GuardCallUse();
  318. bResiCallUse = deviceSet.Get_ResidenceCallUse();
  319. deviceSet.closeDB();
  320. LOG("[onCreate] bLobbyCallUse [" + bLobbyCallUse + "], bGuardCallUse [" + bGuardCallUse + "], bResiCallUse [" + bResiCallUse + "]");
  321. try {
  322. String host = SIPController.getSHVE140SLocalIpAddress();
  323. Log.i(TAG, "Host : " + host);
  324. InetAddress thisComputer = null;
  325. if (host != null && host.length() > 0) thisComputer = InetAddress.getByName(host);
  326. else thisComputer = InetAddress.getByName("127.0.0.1");
  327. byte[] address = thisComputer.getAddress();
  328. if (address.length == 4) {
  329. int unsignedByte1 = address[0] < 0 ? address[0] + 256 : address[0];
  330. int unsignedByte2 = address[1] < 0 ? address[1] + 256 : address[1];
  331. int unsignedByte3 = address[2] < 0 ? address[2] + 256 : address[2];
  332. int unsignedByte4 = address[3] < 0 ? address[3] + 256 : address[3];
  333. SIPStack.strLocalip = unsignedByte1 + "." + unsignedByte2 + "." + unsignedByte3 + "." + unsignedByte4;
  334. } else if (SIPStack.SIP_MESSAGE_DEBUG == true) {
  335. Log.i(TAG, "no ipv4.");
  336. }
  337. if (SIPStack.SIP_MESSAGE_DEBUG == true) {
  338. Log.i(TAG, SIPStack.strLocalip + " founded.");
  339. }
  340. if (SIPStack.stackkey.strServerDomain == null) {
  341. SIPStack.stackkey.strServerDomain = "";
  342. }
  343. if (SIPStack.bDirectCall == true) {
  344. boolean bValidroom = getMyroomname();
  345. if (bValidroom == false) {
  346. Log.i("SIPStun", "Invalid room");
  347. dialerPadNumber("");
  348. } else {
  349. dialerPadNumber(padNumber);
  350. }
  351. }
  352. if (SIPStack.bActive == false) SIPController.initSound(SIPController.bMobileCall);
  353. if (SIPStack.bActive == false) {
  354. mSIPSignalReceiver = new SIPSignalReceiver(thisComputer, SIPStack.localPort);
  355. if (mSIPSignalReceiver != null) {
  356. mSIPSignalReceiver.start();
  357. SIPStack.localPort = SIPStack.SIP_SIGNAL_PORT;
  358. SIPStack.ipdns.bSipAddressResolved = false;
  359. cmcore = new CMCore();
  360. connectivityManager = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);
  361. initializeCm(address, SIPStack.strLocalip.getBytes(), SIPStack.localPort, SIPStack.stackkey.strServerHost, SIPStack.stackkey.serverPort, SIPStack.stackkey.strServerDomain, SIPStack.stackkey.strId.getBytes(),
  362. SIPStack.stackkey.strCid.getBytes(), SIPStack.stackkey.strAuthid.getBytes(), SIPStack.stackkey.strAuthpassword.getBytes());
  363. SIPController.audioRTPManager = new RTPManager(this, SIPStack.SIP_MEDIATYPE_AUDIO);
  364. SIPSound.amAudioManager = (AudioManager) this.getSystemService(AUDIO_SERVICE);
  365. SIPSound.initRoute();
  366. if (SIPController.sipCall == null) {
  367. Log.i(TAG, "sipCall is null");
  368. }
  369. SIPStack.bActive = true;
  370. }
  371. }
  372. registerWallPadCallLiveBRReceiver();
  373. } catch (UnknownHostException uhe) {
  374. Log.e(TAG, "[UnknownHostException] onCreate()");
  375. //uhe.printStackTrace();
  376. LogUtil.errorLogInfo("", TAG, uhe);
  377. } catch (Exception e) {
  378. Log.e(TAG, "[Exception] onCreate()");
  379. //e.printStackTrace();
  380. LogUtil.errorLogInfo("", TAG, e);
  381. }
  382. Log.i(TAG, "===================== Service Started!! =====================");
  383. CMCore.bPausing = false;
  384. isRunning = true;
  385. }
  386. public boolean getMyroomname() {
  387. try {
  388. padNumber = "";
  389. boolean bJeffreyWay = true;
  390. // Log.i(TAG, "[getMyroomname] bJeffreyWay : " + bJeffreyWay);
  391. if (bJeffreyWay) {
  392. SIPStack.strLocalip = getDeviceIPAddress();
  393. Log.i(TAG, "[getMyroomname] SIPStack.strLocalip [" + SIPStack.strLocalip + "]");
  394. int nMaxTryCnt = 10;
  395. int nCnt = 0;
  396. while ((!validateIPAddress(SIPStack.strLocalip)) && (nCnt < nMaxTryCnt)) {
  397. Thread.sleep(1000);
  398. SIPStack.strLocalip = getDeviceIPAddress();
  399. nCnt++;
  400. }
  401. Log.i(TAG, "[getMyroomname] After while loof!! SIPStack.strLocalip [" + SIPStack.strLocalip + "], nCnt [" + nCnt + "]");
  402. // System.out.print(unsignedByte + ".");
  403. String[] aDeviceName = makeDeviceName(SIPStack.strLocalip);
  404. if (aDeviceName[0] == DeviceString.strType_Lobby) {
  405. // 로비폰
  406. padNumber = aDeviceName[1] + "동 " + aDeviceName[2] + "번 로비";
  407. } else if (aDeviceName[0] == DeviceString.strType_Guard) {
  408. // 경비실기
  409. padNumber = aDeviceName[1] + "동 " + aDeviceName[2] + "번 경비실";
  410. } else if (aDeviceName[0] == DeviceString.strType_RentResi) {
  411. // 분리 세대 단말기
  412. padNumber = aDeviceName[1] + "동 " + aDeviceName[2] + "-1호";
  413. } else {
  414. // 세대단말기
  415. padNumber = aDeviceName[1] + "동 " + aDeviceName[2] + "호";
  416. }
  417. SIPStack.stackkey.strId = makeSIPID(SIPStack.strLocalip);
  418. SIPStack.stackkey.strAuthid = makeSIPID(SIPStack.strLocalip);
  419. return true;
  420. } else {
  421. String host = SIPController.getSHVE140SLocalIpAddress();
  422. InetAddress thisComputer = null;
  423. if (host != null && host.length() > 0) thisComputer = InetAddress.getByName(host);
  424. else thisComputer = InetAddress.getByName("127.0.0.1");
  425. byte[] address = thisComputer.getAddress();
  426. if (address.length == 4) {
  427. int unsignedByte1 = address[0] < 0 ? address[0] + 256 : address[0];
  428. int unsignedByte2 = address[1] < 0 ? address[1] + 256 : address[1];
  429. int unsignedByte3 = address[2] < 0 ? address[2] + 256 : address[2];
  430. int unsignedByte4 = address[3] < 0 ? address[3] + 256 : address[3];
  431. SIPStack.strLocalip = unsignedByte1 + "." + unsignedByte2 + "." + unsignedByte3 + "." + unsignedByte4;
  432. Log.i(TAG, "[getMyroomname] SIPStack.strLocalip : " + SIPStack.strLocalip);
  433. // System.out.print(unsignedByte + ".");
  434. String[] aDeviceName = makeDeviceName(SIPStack.strLocalip);
  435. if (aDeviceName[0] == DeviceString.strType_Lobby) {
  436. // 로비폰
  437. padNumber = aDeviceName[1] + "동 " + aDeviceName[2] + "번 로비";
  438. } else if (aDeviceName[0] == DeviceString.strType_Guard) {
  439. // 경비실기
  440. padNumber = aDeviceName[1] + "동 " + aDeviceName[2] + "번 경비실";
  441. } else {
  442. // 세대단말기
  443. padNumber = aDeviceName[1] + "동 " + aDeviceName[2] + "호";
  444. }
  445. SIPStack.stackkey.strId = makeSIPID(SIPStack.strLocalip);
  446. SIPStack.stackkey.strAuthid = makeSIPID(SIPStack.strLocalip);
  447. return true;
  448. } else return false;
  449. }
  450. } catch (RuntimeException re) {
  451. LogUtil.errorLogInfo("", TAG, re);
  452. } catch (Exception e) {
  453. Log.e(TAG, "[Exception] getMyroomname()");
  454. //e.printStackTrace();
  455. LogUtil.errorLogInfo("", TAG, e);
  456. }
  457. return false;
  458. }
  459. 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])$");
  460. private boolean validateIPAddress(String IPAddress) {
  461. Log.i(TAG, "[validateIPAddress] IPAddress [" + IPAddress + "]");
  462. if (IPAddress == null) return false;
  463. return mPattern.matcher(IPAddress).matches();
  464. }
  465. public String getDeviceIPAddress() {
  466. try {
  467. LOG("[getDeviceIPAddress] START!");
  468. if (Integer.parseInt(Build.VERSION.RELEASE.substring(0, 1)) >= 7) {
  469. // // 메이드인랩 김수진 선임 (A0S 7.0)
  470. List<NetworkInterface> interfaces = Collections.list(NetworkInterface.getNetworkInterfaces());
  471. for (NetworkInterface intf : interfaces) {
  472. List<InetAddress> addrs = Collections.list(intf.getInetAddresses());
  473. for (InetAddress addr : addrs) {
  474. if (!addr.isLoopbackAddress()) {
  475. String sAddr = addr.getHostAddress();
  476. boolean isIPv4 = sAddr.indexOf(':') < 0;
  477. if (isIPv4)
  478. return sAddr;
  479. }
  480. }
  481. }
  482. } else {
  483. // 기존코드 (AOS 6.0)
  484. String strResult = "";
  485. String strNetInfo ="";
  486. if(NetworkInterface.getByName("eth0")!=null)
  487. strNetInfo = NetworkInterface.getByName("eth0").toString();
  488. LOG_DEBUG("strNetInfo " + strNetInfo);
  489. LOG("[getDeviceIPAddress] strNetInfo : " + strNetInfo + "]");
  490. strNetInfo.trim();
  491. String[] Parse_01 = strNetInfo.split("\\]");
  492. String[] Parse_02 = Parse_01[Parse_01.length - 1].split("\\/");
  493. strResult = Parse_02[1];
  494. LOG("[getDeviceIPAddress] DONE! [IP Address : " + strResult + "]");
  495. return strResult;
  496. }
  497. } catch (RuntimeException re) {
  498. LogUtil.errorLogInfo("", TAG, re);
  499. } catch (Exception e) {
  500. Log.e(TAG, "[Exception] getDeviceIPAddress()");
  501. //e.printStackTrace();
  502. LogUtil.errorLogInfo("", TAG, e);
  503. }
  504. return "";
  505. }
  506. private void getStackKey() {
  507. SharedPreferences prefs = getSharedPreferences("PrefName", MODE_PRIVATE);
  508. String textId = prefs.getString(SIPStack.stackkey.KEY_BSS_ID, "");
  509. String textAuthid = prefs.getString(SIPStack.stackkey.KEY_BSS_AUTHID, "");
  510. String textPassword = prefs.getString(SIPStack.stackkey.KEY_BSS_PASSWORD, "");
  511. String textCid = prefs.getString(SIPStack.stackkey.KEY_BSS_CID, "");
  512. String textServerip = prefs.getString(SIPStack.stackkey.KEY_BSS_SERVERIP, "");
  513. String textDomain = prefs.getString(SIPStack.stackkey.KEY_BSS_SERVERDOMAIN, "");
  514. String textPort = prefs.getString(SIPStack.stackkey.KEY_BSS_SERVERPORT, "");
  515. String textImsi = prefs.getString(SIPStack.stackkey.KEY_BSS_IMSI, "");
  516. String textGeneralPhone = prefs.getString(SIPStack.stackkey.KEY_BSS_GENERALPHONE, "");
  517. String textWebid = prefs.getString(SIPStack.stackkey.KEY_BSS_WEBID, "");
  518. String textWebpwd = prefs.getString(SIPStack.stackkey.KEY_BSS_WEBPWD, "");
  519. String textLatestdial = prefs.getString(SIPStack.stackkey.KEY_BSS_LATESTDIAL, "");
  520. String textForward = prefs.getString(SIPStack.stackkey.KEY_BSS_FORWARD, "");
  521. SIPStack.stackkey.strImsi = textImsi.trim();
  522. SIPStack.stackkey.strGeneralPhone = textGeneralPhone.trim();
  523. SIPStack.stackkey.strWebId = textWebid.trim();
  524. SIPStack.stackkey.strWebPwd = textWebpwd.trim();
  525. SIPStack.userDial.latestDial = textLatestdial.trim();
  526. Log.i(TAG, "[getStackKey] >>>>>WEB ID : " + SIPStack.stackkey.strWebId + " WEB PWD : " + SIPStack.stackkey.strWebPwd);
  527. SIPStack.stackkey.strId = textId.trim();
  528. SIPStack.stackkey.strCid = textCid.trim();
  529. SIPStack.stackkey.strAuthid = textAuthid.trim();
  530. SIPStack.stackkey.strAuthpassword = textPassword.trim();
  531. SIPStack.stackkey.strServerHost = textServerip.trim();
  532. SIPStack.stackkey.strServerDomain = textDomain.trim();
  533. if (textPort.trim().length() > 0)
  534. SIPStack.stackkey.serverPort = Integer.parseInt(textPort.trim());
  535. else SIPStack.stackkey.serverPort = 5060;
  536. // 192.168.10.21
  537. SIPStack.stackkey.strId = "07077392005";
  538. SIPStack.stackkey.strAuthid = "07077392005";
  539. SIPStack.stackkey.strAuthpassword = "002005";
  540. SIPStack.stackkey.strServerHost = "192.168.10.2";
  541. SIPStack.stackkey.serverPort = 5060;
  542. SIPController.forward.setValue(textForward.trim());
  543. if (SIPStack.SIP_MESSAGE_DEBUG == true) {
  544. Log.i(TAG, "ID : " + SIPStack.stackkey.strId);
  545. Log.i(TAG, "CID : " + SIPStack.stackkey.strCid);
  546. Log.i(TAG, "AUTHID : " + SIPStack.stackkey.strAuthid);
  547. Log.i(TAG, "AUTHPASSWORD : " + SIPStack.stackkey.strAuthpassword);
  548. Log.i(TAG, "SERVERHOST : " + SIPStack.stackkey.strServerHost);
  549. Log.i(TAG, "SERVERDOMAIN : " + SIPStack.stackkey.strServerDomain);
  550. Log.i(TAG, "SERVERPORT : " + SIPStack.stackkey.serverPort);
  551. Log.i(TAG, "FORWARD set : " + SIPController.forward.bForward + " type : " + SIPController.forward.iForwardTarget + " number : " + SIPController.forward.number);
  552. }
  553. return;
  554. }
  555. @Override
  556. public int onStartCommand(Intent intent, int flags, int startId) {
  557. LOG_WARN("[onStartCommand] flags [" + flags + "], startId [" + startId + "]");
  558. return START_STICKY; // run until explicitly stopped.
  559. }
  560. public static boolean isRunning() {
  561. return isRunning;
  562. }
  563. @Override
  564. public void onDestroy() {
  565. super.onDestroy();
  566. unregisterWallPadCallLiveBRReceiver();
  567. if (SIPStack.bUseCtrlTimer == true) {
  568. if (cmcore.SIGNALCTRLTimer != null) {
  569. cmcore.SIGNALCTRLTimer.cancel();
  570. }
  571. cmcore.SIGNALCTRLTimer = null;
  572. } else {
  573. if (cmcore.SIGNALCTRLThread != null && cmcore.SIGNALCTRLThread.isAlive() == true) {
  574. cmcore.SIGNALCTRLThread.interrupt();
  575. cmcore.SIGNALCTRLRunning = false;
  576. }
  577. }
  578. mSIPSignalReceiver.interrupt();
  579. SIPStack.bActive = false;
  580. Log.i(TAG, "===================== Service Stopped!! =====================");
  581. isRunning = false;
  582. }
  583. // SignalReceiver
  584. class SIPSignalReceiver extends Thread {
  585. InetAddress thisComputer;
  586. protected DatagramSocket theSocket;
  587. protected DatagramPacket dp;
  588. protected boolean bFlag = false;
  589. boolean bReady = false;
  590. byte[] buffer;
  591. public SIPSignalReceiver(InetAddress thisComputer, int port) {
  592. bReady = false;
  593. try {
  594. if (port > 0 && port <= 65556) {
  595. SIPStack.SIP_SIGNAL_PORT = port;
  596. for (int i = 0; i < SIPStack.MAX_SIGNAL_PORTS; i++) {
  597. SIPStack.SIP_SIGNAL_PORT = port + i;
  598. Log.i(TAG, "try SIP Signal socket create on " + SIPStack.SIP_SIGNAL_PORT);
  599. try {
  600. theSocket = new DatagramSocket(SIPStack.SIP_SIGNAL_PORT);
  601. } catch (RuntimeException re) {
  602. LogUtil.errorLogInfo("", TAG, re);
  603. } catch (Exception e) {
  604. Log.e(TAG, "[Exception] SipSignalReceiver -> SipSignalReceiver (InetAddress thisComputer, int port)");
  605. }
  606. if (theSocket != null) {
  607. bFlag = true;
  608. break;
  609. }
  610. }
  611. if (theSocket == null) {
  612. Log.i(TAG, "[SipSignalReceiver] theSocket is null!!!");
  613. bFlag = false;
  614. return;
  615. }
  616. theSocket.setReuseAddress(true);
  617. this.thisComputer = thisComputer;
  618. }
  619. buffer = new byte[SIPStack.SIP_MAXMESSAGE_SIZE];
  620. } catch (SocketException se) {
  621. Log.e(TAG, "[SocketException] ERROR SipSignalReceiver Construct");
  622. //System.err.println(se);
  623. LogUtil.errorLogInfo("", TAG, se);
  624. SIPStack.exceptionCountAtCurrentCall++;
  625. } catch (Exception e) {
  626. Log.e(TAG, "[Exception] SipSignalReceiver construct exception occurred.");
  627. }
  628. }
  629. public void run() {
  630. Log.i(TAG, "[SipSignalReceiver] run() >>>> Signal Thread receive ready.");
  631. try {
  632. dp = new DatagramPacket(buffer, buffer.length);
  633. } catch (NullPointerException ne) {
  634. //System.err.println(ne);
  635. LogUtil.errorLogInfo("", TAG, ne);
  636. SIPStack.exceptionCountAtCurrentCall++;
  637. return;
  638. }
  639. bReady = true;
  640. this.setPriority(1);
  641. while (bReady && theSocket != null && dp != null) {
  642. try {
  643. Log.i(TAG, "[SipSignalReceiver] >>>> SOCKET SoTimeout : " + theSocket.getSoTimeout());
  644. dp.setLength(SIPStack.SIP_MAXMESSAGE_SIZE);
  645. dp.setData(buffer);
  646. theSocket.receive(dp);
  647. if (CMCore.bPausing == true) {
  648. Date currentTime = new Date();
  649. int milli = (int) (currentTime.getTime() - CMCore.pauseTime.getTime());
  650. if (milli < CMCore.BSSSIPStun_ICONTROLS_PAUSING_DURATION) {
  651. Log.e(TAG, "CMCore.bPausing [" + CMCore.bPausing + "], pause duration [" + milli + "]. signal is ignored!!!");
  652. continue;
  653. }
  654. }
  655. if (0 != BSSSipParser(dp)) {
  656. if (SIPStack.SIP_MESSAGE_DEBUG == true)
  657. Log.i(TAG, "SIP MESSAGE PARSER ERROR");
  658. Thread.yield();
  659. }
  660. SIPStack.bIntraffic = true;
  661. } catch (SocketTimeoutException se) {
  662. Log.e(TAG, "[SocketTimeoutException] Socket time out...");
  663. //se.printStackTrace();
  664. LogUtil.errorLogInfo("", TAG, se);
  665. } catch (IOException e) {
  666. Log.e(TAG, "[IOException] IOException");
  667. //e.printStackTrace();
  668. LogUtil.errorLogInfo("", TAG, e);
  669. //System.err.println(e);
  670. SIPStack.exceptionCountAtCurrentCall++;
  671. } catch (Exception e1) {
  672. Log.e(TAG, "[Exception] +++ SipSignalReceiver receive thread exception occurred.");
  673. //e1.printStackTrace();
  674. //System.err.println(e1);
  675. LogUtil.errorLogInfo("", TAG, e1);
  676. }
  677. }
  678. Log.e(TAG, "Signal Thread terminated");
  679. }
  680. public int BSSSipParser(DatagramPacket dp) {
  681. if (dp == null) return -1;
  682. String remoteIp = null;
  683. byte[] address = dp.getAddress().getAddress();
  684. if (address == null || address.length <= 0) return -1;
  685. if (address.length == 4) {
  686. int unsignedByte1 = address[0] < 0 ? address[0] + 256 : address[0];
  687. int unsignedByte2 = address[1] < 0 ? address[1] + 256 : address[1];
  688. int unsignedByte3 = address[2] < 0 ? address[2] + 256 : address[2];
  689. int unsignedByte4 = address[3] < 0 ? address[3] + 256 : address[3];
  690. remoteIp = unsignedByte1 + "." + unsignedByte2 + "." + unsignedByte3 + "." + unsignedByte4;
  691. } else return -1;
  692. int remotePort = dp.getPort();
  693. if (remotePort <= 0) return -1;
  694. int iMessageType = 0;
  695. int iMethodType = 0;
  696. String s = new String(dp.getData(), 0, 0, dp.getLength());
  697. if (s == null || s.length() <= 0) return -1;
  698. // SIP PARSE
  699. StringTokenizer st = new StringTokenizer(s, "\n", true);
  700. // int headerCount = 0;
  701. if (st.hasMoreTokens()) {
  702. String str = st.nextToken();
  703. if (str.length() > 0) {
  704. iMethodType = SIPStack.getRequestlineMethod(str);
  705. // Log.d(TAG, "[BSSSipParser] iMethodType [" + iMethodType + "]");
  706. if (iMethodType == SIPStack.SIP_METHODTYPE_NONE) {
  707. return 0;
  708. } else if (iMethodType == SIPStack.SIP_METHODTYPE_RESPONSE) {
  709. iMethodType = SIPStack.getCSeqMethod(s);
  710. // Log.i(TAG, ">>>>>>>>>> RESPONSE iMethodType : " + iMethodType);
  711. if (iMethodType == SIPStack.SIP_METHODTYPE_NONE) return 0;
  712. iMessageType = SIPStack.SIP_MSGTYPE_RESPONSE;
  713. if (iMethodType == SIPStack.SIP_METHODTYPE_REGISTER)
  714. SIPParser(s, iMessageType, iMethodType);
  715. else if (iMethodType != SIPStack.SIP_METHODTYPE_NONE)
  716. SIPParser(s, iMessageType, iMethodType, remoteIp, remotePort);
  717. return 0;
  718. } else {
  719. iMessageType = SIPStack.SIP_MSGTYPE_REQUEST;
  720. SIPParser(s, iMessageType, iMethodType, remoteIp, remotePort);
  721. }
  722. }
  723. }
  724. return 0; // normal
  725. } // BSSSipParser()
  726. public int BSSSipSendUdpPacket(String sIp, int iPort, byte[] data, int dataSize) {
  727. int sent = 0;
  728. if (sIp == null || sIp.length() == 0) return 0;
  729. if (iPort <= 0) return 0;
  730. if (dataSize <= 0) return 0;
  731. try {
  732. InetAddress ia = InetAddress.getByName(sIp);
  733. if (ia != null) {
  734. DatagramPacket dp = new DatagramPacket(data, dataSize, ia, iPort);
  735. if (dp != null && theSocket!=null ) theSocket.send(dp);
  736. sent = dataSize;
  737. SIPStack.bOuttraffic = true;
  738. if (bPrintSIPMsgIO) printSIPMessage(MESSAGE.SEND, new String(data));
  739. }
  740. } catch (UnknownHostException uhe) {
  741. Log.e(TAG, "[UnknownHostException] BSSSipSendUdpPacket(String sIp, int iPort, byte[] data, int dataSize)");
  742. //System.err.println(uhe);
  743. LogUtil.errorLogInfo("", TAG, uhe);
  744. SIPStack.exceptionCountAtCurrentCall++;
  745. } catch (java.net.SocketException she) {
  746. Log.e(TAG, "[SocketException] Cause: " + she.getCause());
  747. Log.e(TAG, "[SocketException] Reason: " + she.getMessage());
  748. if (she.getMessage().indexOf("ENETUNREACH") >= 0 || she.getMessage().indexOf("Network is unreachable") >= 0) {
  749. SIPStack.networkStatus = SIPStack.SIP_NETIF_UNREACHABLE;
  750. Log.e(TAG, "[BSSSipSendUdpPacket] networkStatus was set to SIP_NETIF_UNREACHABLE");
  751. }
  752. //System.err.println(she);
  753. LogUtil.errorLogInfo("", TAG, she);
  754. try {
  755. Log.e(TAG, "!!! Socket is invalid, renew.");
  756. theSocket = new DatagramSocket(SIPStack.SIP_SIGNAL_PORT);
  757. } catch (RuntimeException re) {
  758. LogUtil.errorLogInfo("", TAG, re);
  759. } catch (Exception e) {
  760. Log.e(TAG, "[Exception] !!! Socket is invalid, renew.");
  761. }
  762. SIPStack.exceptionCountAtCurrentCall++;
  763. } catch (IOException ie) {
  764. Log.e(TAG, "[IOException] BSSSipSendUdpPacket(String sIp, int iPort, byte[] data, int dataSize)");
  765. //System.err.println(ie);
  766. LogUtil.errorLogInfo("", TAG, ie);
  767. SIPStack.exceptionCountAtCurrentCall++;
  768. } catch (Exception e) {
  769. // when call OnNetworkException error processing
  770. Log.e(TAG, "[Exception] BSSSipSendUdpPacket(String sIp, int iPort, byte[] data, int dataSize)");
  771. Log.e(TAG, "!!!BSSSipSendUdpPacket Exception occurred. <BSS> : " + sent);
  772. //System.err.println(e);
  773. LogUtil.errorLogInfo("", TAG, e);
  774. return -1;
  775. }
  776. return sent;
  777. }
  778. }
  779. class SIGNALCTRLThread extends Thread {
  780. @Override
  781. public void run() {
  782. Log.d(TAG, "[SIGNALCTRLThread.run]");
  783. while (cmcore.SIGNALCTRLRunning == true) {
  784. try {
  785. Thread.sleep(SIPStack.SIPCTRL_INTERVAL);
  786. if (cmcore.SIGNALCTRLThread == null) {
  787. break;
  788. }
  789. if (cmcore.SIGNALCTRLThread.isInterrupted()) {
  790. break;
  791. }
  792. if (SIPStack.networkStatus != SIPStack.SIP_NETIF_AVAILABLE) {
  793. if (SIPStack.networkStatus == SIPStack.SIP_NETIF_UNREACHABLE) {
  794. // SERVICE MESSAGE NEEDED
  795. updateDialerStatus("NETWORK UNREACHABLE.", true);
  796. } else if (SIPStack.networkStatus == SIPStack.SIP_NETIF_UNAVAILABLE) {
  797. // SERVICE MESSAGE NEEDED
  798. updateDialerStatus("NETWORK not ready.", true);
  799. }
  800. if (SIPStack.networkStatus == SIPStack.SIP_NETIF_UNAVAILABLE || SIPStack.networkStatus == SIPStack.SIP_NETIF_UNREACHABLE) {
  801. if (connectivityManager != null && connectivityManager.getActiveNetworkInfo() != null) {
  802. NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo();
  803. switch (activeNetwork.getType()) {
  804. case ConnectivityManager.TYPE_WIMAX: // 4g 망 체크
  805. if (SIPStack.isInternetWiMax == false && SIPStack.bBackgroundRunning)
  806. SIPStack.bShutdownApplication = true;
  807. SIPStack.isInternetWiMax = true;
  808. SIPStack.isInternetWiFi = false;
  809. SIPStack.isInternetMobile = false;
  810. SIPStack.PRIMARY_CODEC_AUDIO = SIPStack.SIP_CODEC_G711U;
  811. break;
  812. case ConnectivityManager.TYPE_WIFI: // wifi망 체크
  813. if (SIPStack.isInternetWiFi == false && SIPStack.bBackgroundRunning)
  814. SIPStack.bShutdownApplication = true;
  815. SIPStack.isInternetWiMax = false;
  816. SIPStack.isInternetWiFi = true;
  817. SIPStack.isInternetMobile = false;
  818. SIPStack.PRIMARY_CODEC_AUDIO = SIPStack.SIP_CODEC_G711U;
  819. break;
  820. case ConnectivityManager.TYPE_MOBILE: // 3g 망 체크
  821. if (SIPStack.isInternetMobile == false && SIPStack.bBackgroundRunning)
  822. SIPStack.bShutdownApplication = true;
  823. SIPStack.isInternetWiMax = false; //false;
  824. SIPStack.isInternetWiFi = false;
  825. SIPStack.isInternetMobile = true;
  826. SIPStack.PRIMARY_CODEC_AUDIO = SIPStack.SIP_CODEC_G711U;
  827. break;
  828. }
  829. }
  830. cmcore.netcheckIntervalTimer = new Date();
  831. try {
  832. String host = SIPController.getSHVE140SLocalIpAddress();
  833. cmcore.action_net_1(host);
  834. } catch (RuntimeException re) {
  835. LogUtil.errorLogInfo("", TAG, re);
  836. } catch (Exception e) {
  837. Log.e(TAG, "[Exception] String host = SIPController.getSHVE140SLocalIpAddress();");
  838. //e.printStackTrace();
  839. LogUtil.errorLogInfo("", TAG, e);
  840. }
  841. }
  842. continue;
  843. }
  844. if (SIPStack.bDirectCall == false && cmcore.regState != SIPStack.SIP_REGSTATE_REGISTERED) {
  845. if (true == cmcore.action_net_0()) sendRegister();
  846. }
  847. // REGIST CONTROL
  848. if (cmcore.ctrlIndex == 0) {
  849. if (SIPStack.bShutdownApplication) {
  850. if (SIPStack.bDirectCall == false) {
  851. sendUNRegister();
  852. }
  853. SIPStack.bShutdownApplication = false;
  854. // SERVICE MESSAGE NEEDED
  855. dialerShutdownApplication();
  856. }
  857. if (SIPStack.bDirectCall == false) {
  858. SIPCTRLRegister();
  859. }
  860. } else if (cmcore.ctrlIndex == 1) {
  861. // CALL CONTROL
  862. if (SIPStack.bVibrating == true) {
  863. if (!(SIPController.sipCall != null && SIPController.sipCall.flag == true && SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_OFFERRED)) {
  864. // SERVICE MESSAGE NEEDED
  865. dialerVibrator(false);
  866. }
  867. }
  868. if (SIPController.sipCall != null && SIPController.sipCall.flag == true && SIPController.sipCall.bResponsebackgroundcall == true &&
  869. SIPController.sipCall.bResponsebackgroundcallReady == true && SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_OFFERRED) {
  870. if (SIPStun.bBlackcallBackgroundMode == true) {
  871. if (SIPController.sipCall.bResponsebackgroundcallReady == true) {
  872. Date currentTime = new Date();
  873. long durationMilliSeconds = Math.abs(currentTime.getTime() - SIPController.sipCall.responsebackgroundcallTimer.getTime());
  874. if (durationMilliSeconds > 1000) {
  875. Log.i(TAG, "MILL TIME : " + durationMilliSeconds);
  876. SIPController.sipCall.responsebackgroundcallTimer = new Date();
  877. SIPController.sipCall.bResponsebackgroundcall = false;
  878. SIPController.sipCall.bResponsebackgroundcallReady = false;
  879. // SERVICE MESSAGE NEEDED
  880. dialerNotifyIncomingCall(SIPController.sipCall.dnis, SIPController.sipCall.dnis + "@" + SIPController.sipCall.remoteIp + ":" + SIPController.sipCall.remotePort);
  881. if (SIPStack.bDirectCall == true) {
  882. dialerVideoSet(true);
  883. }
  884. }
  885. }
  886. } else {
  887. Date currentTime = new Date();
  888. long durationSeconds = Math.abs((currentTime.getTime() - SIPController.sipCall.responsebackgroundcallTimer.getTime()) / 1000);
  889. if (durationSeconds > 0) {
  890. SIPController.sipCall.bResponsebackgroundcall = false;
  891. // SERVICE MESSAGE NEEDED
  892. dialerNotifyIncomingCall(SIPController.sipCall.dnis, SIPController.sipCall.dnis + "@" + SIPController.sipCall.remoteIp + ":" + SIPController.sipCall.remotePort);
  893. }
  894. }
  895. }
  896. if (SIPController.sipCall != null && SIPController.sipCall.flag == true && SIPController.sipCall.bCancelRequest) {
  897. callTerminate();
  898. SIPController.sipCall.bCancelRequest = false;
  899. } else if (SIPController.sipCall != null && SIPController.sipCall.flag == true && SIPController.sipCall.bRejectRequest) {
  900. if (SIPController.sipCall.remoteSdp != null && SIPController.sipCall.remoteSdp.flag == true && SIPController.audioRTPManager != null) {
  901. if (SIPController.sipCall.remoteSdp.audioM != null && SIPController.sipCall.remoteSdp.audioM.flag == true) {
  902. if (SIPController.sipCall.sdp != null && SIPController.sipCall.sdp.audioM != null && SIPController.audioRTPManager != null) {
  903. SIPController.audioRTPManager.RTPEnd(1);
  904. // SERVICE MESSAGE NEEDED
  905. if (SIPStack.bDirectCall == true) {
  906. dialerVideoSet(false);
  907. }
  908. }
  909. }
  910. }
  911. SIPController.sipCall.bRejectRequest = false;
  912. SIPController.sipCall.bCancelRequest = true;
  913. } else if (SIPController.sipCall != null && SIPController.sipCall.bNewcallRequest) {
  914. if (SIPController.sipCall.bDirectcall == true) {
  915. SIPController.sipCall.bNewcallRequest = false;
  916. // Log.d(TAG, "[SIGNALCTRLThread] SIPController.bMobileCall [" + SIPController.bMobileCall + "]");
  917. directcallActivate(SIPController.sipCall.number, SIPController.bMobileCall);
  918. } else if (cmcore.regState == SIPStack.SIP_REGSTATE_REGISTERED) {
  919. SIPController.sipCall.bNewcallRequest = false;
  920. callActivate(SIPController.sipCall.number);
  921. }
  922. } else if (SIPController.sipCall != null && SIPController.sipCall.bUpdateRequest) {
  923. if (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_CONNECTED) {
  924. sendHold();
  925. }
  926. SIPController.sipCall.bUpdateRequest = false;
  927. } else if (SIPController.sipCall != null && SIPController.sipCall.flag == true && SIPController.forward.bForward == true && SIPController.sipCall.bForwardRequest == true) {
  928. SIPController.sipCall.bForwardRequest = false;
  929. if (SIPController.sipCall.remoteSdp != null && SIPController.sipCall.remoteSdp.flag == true && SIPController.audioRTPManager != null) {
  930. if (SIPController.sipCall.remoteSdp.audioM != null && SIPController.sipCall.remoteSdp.audioM.flag == true) {
  931. if (SIPController.sipCall.sdp != null && SIPController.sipCall.sdp.audioM != null && SIPController.audioRTPManager != null) {
  932. SIPController.audioRTPManager.RTPEnd(2);
  933. // SERVICE MESSAGE NEEDED
  934. if (SIPStack.bDirectCall == true) {
  935. dialerVideoSet(false);
  936. }
  937. }
  938. }
  939. }
  940. redirectTerminate(SIPController.forward.contact);
  941. cancelCallForwardToStun();
  942. } else {
  943. SIPCTRLCall();
  944. }
  945. }
  946. if (cmcore.ctrlIndex == 0) cmcore.ctrlIndex = 1;
  947. else cmcore.ctrlIndex = 0;
  948. } catch (RuntimeException re) {
  949. LogUtil.errorLogInfo("", TAG, re);
  950. } catch (Exception e) {
  951. Log.e(TAG, "[Exception] SIGNALCTRLThread.while(cmcore.SIGNALCTRLRunning)");
  952. //e.printStackTrace();
  953. LogUtil.errorLogInfo("", TAG, e);
  954. }
  955. }
  956. cmcore.SIGNALCTRLRunning = false;
  957. cmcore.SIGNALCTRLThread = null;
  958. } // run()
  959. }
  960. class CTRLTimerTask extends TimerTask {
  961. public void run() {
  962. if (cmcore.SIGNALCTRLTimer == null) {
  963. Log.e(TAG, "cmcore.SIGNALCTRLTimer is null!! ");
  964. return;
  965. }
  966. Log.w(TAG, "[CTRLTimerTask]");
  967. if (SIPStack.networkStatus != SIPStack.SIP_NETIF_AVAILABLE) {
  968. if (SIPStack.networkStatus == SIPStack.SIP_NETIF_UNREACHABLE) {
  969. // SERVICE MESSAGE NEEDED
  970. updateDialerStatus("NETWORK UNREACHABLE.", true);
  971. } else if (SIPStack.networkStatus == SIPStack.SIP_NETIF_UNAVAILABLE) {
  972. //SERVICE MESSAGE NEEDED
  973. updateDialerStatus("NETWORK not ready.", true);
  974. }
  975. if (SIPStack.networkStatus == SIPStack.SIP_NETIF_UNAVAILABLE || SIPStack.networkStatus == SIPStack.SIP_NETIF_UNREACHABLE) {
  976. if (connectivityManager != null && connectivityManager.getActiveNetworkInfo() != null) {
  977. NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo();
  978. switch (activeNetwork.getType()) {
  979. case ConnectivityManager.TYPE_WIMAX: // 4g 망 체크
  980. if (SIPStack.isInternetWiMax == false && SIPStack.bBackgroundRunning)
  981. SIPStack.bShutdownApplication = true;
  982. SIPStack.isInternetWiMax = true;
  983. SIPStack.isInternetWiFi = false;
  984. SIPStack.isInternetMobile = false;
  985. SIPStack.PRIMARY_CODEC_AUDIO = SIPStack.SIP_CODEC_G711U;
  986. break;
  987. case ConnectivityManager.TYPE_WIFI: // wifi망 체크
  988. if (SIPStack.isInternetWiFi == false && SIPStack.bBackgroundRunning)
  989. SIPStack.bShutdownApplication = true;
  990. SIPStack.isInternetWiMax = false;
  991. SIPStack.isInternetWiFi = true;
  992. SIPStack.isInternetMobile = false;
  993. SIPStack.PRIMARY_CODEC_AUDIO = SIPStack.SIP_CODEC_G711U;
  994. break;
  995. case ConnectivityManager.TYPE_MOBILE: // 3g 망 체크
  996. if (SIPStack.isInternetMobile == false && SIPStack.bBackgroundRunning)
  997. SIPStack.bShutdownApplication = true;
  998. SIPStack.isInternetWiMax = false; // false;
  999. SIPStack.isInternetWiFi = false;
  1000. SIPStack.isInternetMobile = true;
  1001. SIPStack.PRIMARY_CODEC_AUDIO = SIPStack.SIP_CODEC_G711U;
  1002. break;
  1003. }
  1004. }
  1005. cmcore.netcheckIntervalTimer = new Date();
  1006. try {
  1007. String host = SIPController.getSHVE140SLocalIpAddress();
  1008. cmcore.action_net_1(host);
  1009. } catch (RuntimeException re) {
  1010. LogUtil.errorLogInfo("", TAG, re);
  1011. } catch (Exception e) {
  1012. Log.e(TAG, "[Exception] String host = SIPController.getSHVE140SLocalIpAddress()");
  1013. }
  1014. }
  1015. return;
  1016. }
  1017. if (SIPStack.bDirectCall == false && cmcore.regState != SIPStack.SIP_REGSTATE_REGISTERED) {
  1018. if (true == cmcore.action_net_0()) sendRegister();
  1019. }
  1020. // REGIST CONTROL
  1021. if (cmcore.ctrlIndex == 0) {
  1022. if (SIPStack.bShutdownApplication) {
  1023. if (SIPStack.bDirectCall == false) sendUNRegister();
  1024. SIPStack.bShutdownApplication = false;
  1025. // SERVICE MESSAGE NEEDED
  1026. dialerShutdownApplication();
  1027. }
  1028. if (SIPStack.bDirectCall == false) SIPCTRLRegister();
  1029. } else if (cmcore.ctrlIndex == 1) {
  1030. // CALL CONTROL
  1031. if (SIPStack.bVibrating == true) {
  1032. if (!(SIPController.sipCall != null && SIPController.sipCall.flag == true && SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_OFFERRED)) {
  1033. // SERVICE MESSAGE NEEDED
  1034. dialerVibrator(false);
  1035. }
  1036. }
  1037. if (SIPController.sipCall != null && SIPController.sipCall.flag == true && SIPController.sipCall.bResponsebackgroundcall == true &&
  1038. SIPController.sipCall.bResponsebackgroundcallReady == true && SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_OFFERRED) {
  1039. if (SIPStun.bBlackcallBackgroundMode == true) {
  1040. if (SIPController.sipCall.bResponsebackgroundcallReady == true) {
  1041. Date currentTime = new Date();
  1042. int durationMilliSeconds = (int) (currentTime.getTime() - SIPController.sipCall.responsebackgroundcallTimer.getTime());
  1043. if (durationMilliSeconds > 1000) {
  1044. Log.i(TAG, "MILL TIME : " + durationMilliSeconds);
  1045. SIPController.sipCall.responsebackgroundcallTimer = new Date();
  1046. SIPController.sipCall.bResponsebackgroundcall = false;
  1047. SIPController.sipCall.bResponsebackgroundcallReady = false;
  1048. // SERVICE MESSAGE NEEDED
  1049. dialerNotifyIncomingCall(SIPController.sipCall.dnis, SIPController.sipCall.dnis + "@" + SIPController.sipCall.remoteIp + ":" + SIPController.sipCall.remotePort);
  1050. if (SIPStack.bDirectCall == true) {
  1051. dialerVideoSet(true);
  1052. }
  1053. }
  1054. }
  1055. } else {
  1056. Date currentTime = new Date();
  1057. int durationSeconds = (int) (currentTime.getTime() - SIPController.sipCall.responsebackgroundcallTimer.getTime()) / 1000;
  1058. if (durationSeconds > 0) {
  1059. SIPController.sipCall.bResponsebackgroundcall = false;
  1060. // SERVICE MESSAGE NEEDED
  1061. dialerNotifyIncomingCall(SIPController.sipCall.dnis, SIPController.sipCall.dnis + "@" + SIPController.sipCall.remoteIp + ":" + SIPController.sipCall.remotePort);
  1062. }
  1063. }
  1064. }
  1065. if (SIPController.sipCall != null && SIPController.sipCall.flag == true && SIPController.sipCall.bCancelRequest) {
  1066. callTerminate();
  1067. SIPController.sipCall.bCancelRequest = false;
  1068. } else if (SIPController.sipCall != null && SIPController.sipCall.flag == true && SIPController.sipCall.bRejectRequest) {
  1069. if (SIPController.sipCall.remoteSdp != null && SIPController.sipCall.remoteSdp.flag == true && SIPController.audioRTPManager != null) {
  1070. if (SIPController.sipCall.remoteSdp.audioM != null && SIPController.sipCall.remoteSdp.audioM.flag == true) {
  1071. if (SIPController.sipCall.sdp != null && SIPController.sipCall.sdp.audioM != null && SIPController.audioRTPManager != null) {
  1072. SIPController.audioRTPManager.RTPEnd(3);
  1073. // SERVICE MESSAGE NEEDED
  1074. if (SIPStack.bDirectCall == true) dialerVideoSet(false);
  1075. }
  1076. }
  1077. }
  1078. SIPController.sipCall.bRejectRequest = false;
  1079. SIPController.sipCall.bCancelRequest = true;
  1080. } else if (SIPController.sipCall != null && SIPController.sipCall.bNewcallRequest) {
  1081. if (SIPController.sipCall.bDirectcall == true) {
  1082. SIPController.sipCall.bNewcallRequest = false;
  1083. // Log.d(TAG, "[CTRLTimerTask] SIPController.bMobileCall [" + SIPController.bMobileCall + "]");
  1084. directcallActivate(SIPController.sipCall.number, SIPController.bMobileCall);
  1085. } else if (cmcore.regState == SIPStack.SIP_REGSTATE_REGISTERED) {
  1086. SIPController.sipCall.bNewcallRequest = false;
  1087. callActivate(SIPController.sipCall.number);
  1088. }
  1089. } else if (SIPController.sipCall != null && SIPController.sipCall.bUpdateRequest) {
  1090. if (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_CONNECTED) {
  1091. sendHold();
  1092. }
  1093. SIPController.sipCall.bUpdateRequest = false;
  1094. } else if (SIPController.sipCall != null && SIPController.sipCall.flag == true && SIPController.forward.bForward == true && SIPController.sipCall.bForwardRequest == true) {
  1095. SIPController.sipCall.bForwardRequest = false;
  1096. if (SIPController.sipCall.remoteSdp != null && SIPController.sipCall.remoteSdp.flag == true && SIPController.audioRTPManager != null) {
  1097. if (SIPController.sipCall.remoteSdp.audioM != null && SIPController.sipCall.remoteSdp.audioM.flag == true) {
  1098. if (SIPController.sipCall.sdp != null && SIPController.sipCall.sdp.audioM != null && SIPController.audioRTPManager != null) {
  1099. SIPController.audioRTPManager.RTPEnd(4);
  1100. // SERVICE MESSAGE NEEDED
  1101. if (SIPStack.bDirectCall == true) dialerVideoSet(false);
  1102. }
  1103. }
  1104. }
  1105. redirectTerminate(SIPController.forward.contact);
  1106. SIPController.forward.contact = "";
  1107. } else {
  1108. SIPCTRLCall();
  1109. }
  1110. }
  1111. if (cmcore.ctrlIndex == 0) cmcore.ctrlIndex = 1;
  1112. else cmcore.ctrlIndex = 0;
  1113. }
  1114. }
  1115. public void initializeCm(byte[] byteAddress, byte[] byteLocalip, int localport, byte[] byteServerip, int serverport, byte[] byteServerdomain, byte[] byteId, byte[] byteCid, byte[] byteAuthid, byte[] byteAuthpassword) {
  1116. SIPController.sipCall = new SIPCall();
  1117. // Multicall part
  1118. SIPController.pendingCall = new SIPCall(true);
  1119. if (connectivityManager != null && connectivityManager.getActiveNetworkInfo() != null) {
  1120. NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo();
  1121. switch (activeNetwork.getType()) {
  1122. case ConnectivityManager.TYPE_WIMAX: // 4g 망 체크
  1123. SIPStack.isInternetWiMax = true;
  1124. SIPStack.isInternetWiFi = false;
  1125. SIPStack.isInternetMobile = false;
  1126. SIPStack.PRIMARY_CODEC_AUDIO = SIPStack.SIP_CODEC_G711U;
  1127. break;
  1128. case ConnectivityManager.TYPE_WIFI: // wifi망 체크
  1129. SIPStack.isInternetWiMax = false;
  1130. SIPStack.isInternetWiFi = true;
  1131. SIPStack.isInternetMobile = false;
  1132. SIPStack.PRIMARY_CODEC_AUDIO = SIPStack.SIP_CODEC_G711U;
  1133. break;
  1134. case ConnectivityManager.TYPE_MOBILE: // 3g 망 체크
  1135. SIPStack.isInternetWiMax = false;//false;
  1136. SIPStack.isInternetWiFi = false;
  1137. SIPStack.isInternetMobile = true;
  1138. SIPStack.PRIMARY_CODEC_AUDIO = SIPStack.SIP_CODEC_G711U;
  1139. break;
  1140. }
  1141. }
  1142. cmcore.action_0(byteLocalip, localport, byteServerip, serverport, byteServerdomain, byteId, byteCid, byteAuthid, byteAuthpassword);
  1143. if (SIPStack.bUseCtrlTimer == true) {
  1144. cmcore.SIGNALCTRLTimer.scheduleAtFixedRate(new CTRLTimerTask(), 0, SIPStack.SIPCTRL_INTERVAL);
  1145. } else {
  1146. cmcore.SIGNALCTRLThread = new SIGNALCTRLThread();
  1147. if (cmcore.SIGNALCTRLThread != null) {
  1148. cmcore.SIGNALCTRLRunning = true;
  1149. cmcore.SIGNALCTRLThread.start();
  1150. }
  1151. }
  1152. if (connectivityManager != null && connectivityManager.getActiveNetworkInfo() != null) {
  1153. NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo();
  1154. switch (activeNetwork.getType()) {
  1155. case ConnectivityManager.TYPE_WIMAX: // 4g 망 체크
  1156. SIPStack.isInternetWiMax = true;
  1157. SIPStack.isInternetWiFi = false;
  1158. SIPStack.isInternetMobile = false;
  1159. SIPStack.PRIMARY_CODEC_AUDIO = SIPStack.SIP_CODEC_G711U;
  1160. break;
  1161. case ConnectivityManager.TYPE_WIFI: // wifi망 체크
  1162. SIPStack.isInternetWiMax = false;
  1163. SIPStack.isInternetWiFi = true;
  1164. SIPStack.isInternetMobile = false;
  1165. SIPStack.PRIMARY_CODEC_AUDIO = SIPStack.SIP_CODEC_G711U;
  1166. break;
  1167. case ConnectivityManager.TYPE_MOBILE: // 3g 망 체크
  1168. SIPStack.isInternetWiMax = false;//false;
  1169. SIPStack.isInternetWiFi = false;
  1170. SIPStack.isInternetMobile = true;
  1171. SIPStack.PRIMARY_CODEC_AUDIO = SIPStack.SIP_CODEC_G711U;
  1172. break;
  1173. }
  1174. }
  1175. cmcore.netcheckIntervalTimer = new Date();
  1176. try {
  1177. String host = SIPController.getSHVE140SLocalIpAddress();
  1178. if (true == cmcore.action_net_2(host)) {
  1179. sendRegister();
  1180. }
  1181. } catch (RuntimeException re) {
  1182. LogUtil.errorLogInfo("", TAG, re);
  1183. } catch (Exception e) {
  1184. Log.e(TAG, "[Exception] String host = SIPController.getSHVE140SLocalIpAddress()");
  1185. }
  1186. } // SipSignalReceiver()
  1187. public void initializeCm(byte[] byteAddress, byte[] byteLocalip, int localport, String strServerHost, int serverport, String strServerDomain, byte[] byteId, byte[] byteCid, byte[] byteAuthid, byte[] byteAuthpassword) {
  1188. SIPController.sipCall = new SIPCall();
  1189. // Multicall part
  1190. SIPController.pendingCall = new SIPCall(true);
  1191. cmcore.action_1(byteAddress, byteLocalip, localport, strServerHost, serverport, strServerDomain, byteId, byteCid, byteAuthid, byteAuthpassword);
  1192. if (SIPStack.bUseCtrlTimer == true) {
  1193. cmcore.SIGNALCTRLTimer.scheduleAtFixedRate(new CTRLTimerTask(), 0, SIPStack.SIPCTRL_INTERVAL);
  1194. } else {
  1195. cmcore.SIGNALCTRLThread = new SIGNALCTRLThread();
  1196. if (cmcore.SIGNALCTRLThread != null) {
  1197. cmcore.SIGNALCTRLRunning = true;
  1198. cmcore.SIGNALCTRLThread.start();
  1199. }
  1200. }
  1201. }
  1202. public void resumeCm(byte[] byteAddress, byte[] byteLocalip, int localport, String strServerHost, int serverport, String strServerDomain, byte[] byteId, byte[] byteCid, byte[] byteAuthid, byte[] byteAuthpassword) {
  1203. SIPStack.ipdns.bSipAddressResolved = true;
  1204. SIPStack.ipdns.sipTry = 0;
  1205. // SERVICE MESSAGE NEEDED
  1206. if (SIPStack.bDirectCall == false) dialerRegistStatus(SIPStack.bNetworkActive);
  1207. }//SipSignalReceiver()
  1208. public void resetConfiguration(String strId, String strCid, String strAuthid, String strAuthpassword, String strServerHost, String strServerDomain, int serverport) {
  1209. // Set server information
  1210. cmcore.action_2(strId, strCid, strAuthid, strAuthpassword, strServerHost, strServerDomain, serverport);
  1211. sendRegister();
  1212. }
  1213. public void SIPCTRLRegister() {
  1214. if (SIPStack.ipdns.bSipAddressResolved == false) {
  1215. return;
  1216. }
  1217. Date currentTime = new Date();
  1218. int duration = (int) (currentTime.getTime() - cmcore.regTime.getTime()) / 1000;
  1219. int startduration = (int) (currentTime.getTime() - SIPStack.bootTime.getTime()) / 1000;
  1220. if (cmcore.regState == SIPStack.SIP_REGSTATE_IDLE && startduration > 0 && startduration < 10 && mSIPSignalReceiver != null && mSIPSignalReceiver.bReady == true) {
  1221. byte[] buffer = cmcore.message.getBytes();
  1222. if (cmcore.message.length() > 0) {
  1223. if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, cmcore.message);
  1224. cmcore.regState = SIPStack.SIP_REGSTATE_REGISTERING;
  1225. int repeatSendCount = 0;
  1226. while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) {
  1227. if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(cmcore.serverIp, cmcore.serverPort, buffer, buffer.length)) {
  1228. break;
  1229. }
  1230. repeatSendCount++;
  1231. }
  1232. cmcore.regTime = new Date();
  1233. }
  1234. } else if (decideRegister() == true && cmcore.regState != SIPStack.SIP_REGSTATE_REGISTERING && cmcore.regState != SIPStack.SIP_REGSTATE_AUTHORIZING && cmcore.regState != SIPStack.SIP_REGSTATE_UNAVAILABLE) {
  1235. cmcore.regState = SIPStack.SIP_REGSTATE_REGISTERING;
  1236. sendRegister();
  1237. } else if (duration >= SIPStack.CS_TIMEOUT_RESPONSE && cmcore.regState == SIPStack.SIP_REGSTATE_REGISTERING) { // 30
  1238. cmcore.regState = SIPStack.SIP_REGSTATE_REGISTERING;
  1239. sendRegister();
  1240. }
  1241. return;
  1242. }
  1243. public void SIPCTRLCall() {
  1244. Date currentTime = new Date();
  1245. long durationMilli = Math.abs(currentTime.getTime() - cmcore.ctrlIntervalTimer.getTime());
  1246. long durationRegistStatus = Math.abs((currentTime.getTime() - cmcore.registStatusTimer.getTime()) / 1000);
  1247. if (durationMilli < 500) {
  1248. return;
  1249. } else {
  1250. cmcore.ctrlIntervalTimer = new Date();
  1251. durationMilli = Math.abs((currentTime.getTime() - cmcore.netcheckIntervalTimer.getTime()) / 1000);
  1252. if (durationMilli > SIPStack.NETWORKIF_CHECK_TIME) {
  1253. if (connectivityManager != null && connectivityManager.getActiveNetworkInfo() != null) {
  1254. NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo();
  1255. switch (activeNetwork.getType()) {
  1256. case ConnectivityManager.TYPE_WIMAX: // 4g 망 체크
  1257. if (SIPStack.isInternetWiMax == false && SIPStack.bBackgroundRunning)
  1258. SIPStack.bShutdownApplication = true;
  1259. SIPStack.isInternetWiMax = true;
  1260. SIPStack.isInternetWiFi = false;
  1261. SIPStack.isInternetMobile = false;
  1262. SIPStack.PRIMARY_CODEC_AUDIO = SIPStack.SIP_CODEC_G711U;
  1263. break;
  1264. case ConnectivityManager.TYPE_WIFI: // wifi망 체크
  1265. if (SIPStack.isInternetWiFi == false && SIPStack.bBackgroundRunning)
  1266. SIPStack.bShutdownApplication = true;
  1267. SIPStack.isInternetWiMax = false;
  1268. SIPStack.isInternetWiFi = true;
  1269. SIPStack.isInternetMobile = false;
  1270. SIPStack.PRIMARY_CODEC_AUDIO = SIPStack.SIP_CODEC_G711U;
  1271. break;
  1272. case ConnectivityManager.TYPE_MOBILE: // 3g 망 체크
  1273. if (SIPStack.isInternetMobile == false && SIPStack.bBackgroundRunning)
  1274. SIPStack.bShutdownApplication = true;
  1275. SIPStack.isInternetWiMax = false; // false;
  1276. SIPStack.isInternetWiFi = false;
  1277. SIPStack.isInternetMobile = true;
  1278. SIPStack.PRIMARY_CODEC_AUDIO = SIPStack.SIP_CODEC_G711U;
  1279. break;
  1280. }
  1281. }
  1282. cmcore.netcheckIntervalTimer = new Date();
  1283. try {
  1284. String host = SIPController.getSHVE140SLocalIpAddress();
  1285. if (true == cmcore.action_net_3(host)) {
  1286. sendUNRegister(cmcore.previfIp, cmcore.previfPort);
  1287. cmcore.regState = SIPStack.SIP_REGSTATE_UNREGISTERING;
  1288. }
  1289. } catch (RuntimeException re) {
  1290. LogUtil.errorLogInfo("", TAG, re);
  1291. } catch (Exception e) {
  1292. Log.e(TAG, "[Exception] String host = SIPController.getSHVE140SLocalIpAddress()");
  1293. }
  1294. }
  1295. }
  1296. if (durationRegistStatus > 0) {
  1297. if ((SIPStack.bIntraffic || SIPStack.bOuttraffic) && SIPController.sipCall != null && SIPController.sipCall.flag == false) {
  1298. if (cmcore.regState == SIPStack.SIP_REGSTATE_REGISTERED) {
  1299. // SERVICE MESSAGE NEEDED
  1300. if (SIPStack.bDirectCall == false) dialerRegistStatus(true);
  1301. } else {
  1302. // SERVICE MESSAGE NEEDED
  1303. if (SIPStack.bDirectCall == false) dialerRegistStatus(false);
  1304. }
  1305. cmcore.registStatusTimer = new Date();
  1306. } else if (durationRegistStatus > 3) {
  1307. if (cmcore.regState == SIPStack.SIP_REGSTATE_REGISTERED) {
  1308. // SERVICE MESSAGE NEEDED
  1309. if (SIPStack.bDirectCall == false) dialerRegistStatus(true);
  1310. } else {
  1311. // SERVICE MESSAGE NEEDED
  1312. if (SIPStack.bDirectCall == false) dialerRegistStatus(false);
  1313. }
  1314. cmcore.registStatusTimer = new Date();
  1315. }
  1316. }
  1317. // Multicall call state processing
  1318. if (SIPController.pendingCall != null && SIPController.pendingCall.flag == true) {
  1319. // Log.d(TAG, "[SIPCTRLCall]");
  1320. if (SIPController.pendingCall.callTime_TI != null)
  1321. SIPController.pendingCall.expiresTI = (int) (currentTime.getTime() - SIPController.pendingCall.callTime_TI.getTime()) / 1000;
  1322. if (SIPController.pendingCall.callTime_T0 != null)
  1323. SIPController.pendingCall.expiresT0 = (int) (currentTime.getTime() - SIPController.pendingCall.callTime_T0.getTime()) / 1000;
  1324. if (SIPController.pendingCall.callTime_T00 != null)
  1325. SIPController.pendingCall.expiresT00 = (int) (currentTime.getTime() - SIPController.pendingCall.callTime_T00.getTime()) / 1000;
  1326. if (SIPController.pendingCall.callTime_T1 != null)
  1327. SIPController.pendingCall.expiresT1 = (int) (currentTime.getTime() - SIPController.pendingCall.callTime_T1.getTime()) / 1000;
  1328. if (SIPController.pendingCall.callTime_T2 != null)
  1329. SIPController.pendingCall.expiresT2 = (int) (currentTime.getTime() - SIPController.pendingCall.callTime_T2.getTime()) / 1000;
  1330. if (SIPController.pendingCall.callTime_T3 != null)
  1331. SIPController.pendingCall.expiresT3 = (int) (currentTime.getTime() - SIPController.pendingCall.callTime_T3.getTime()) / 1000;
  1332. if (SIPController.pendingCall.callTime_T4 != null)
  1333. SIPController.pendingCall.expiresT4 = (int) (currentTime.getTime() - SIPController.pendingCall.callTime_T4.getTime()) / 1000;
  1334. if (SIPController.pendingCall.callTime_T5 != null)
  1335. SIPController.pendingCall.expiresT5 = (int) (currentTime.getTime() - SIPController.pendingCall.callTime_T5.getTime()) / 1000;
  1336. if (SIPController.pendingCall.callTime_T6 != null)
  1337. SIPController.pendingCall.expiresT6 = (int) (currentTime.getTime() - SIPController.pendingCall.callTime_T6.getTime()) / 1000;
  1338. if (SIPController.pendingCall.callTime_T7 != null)
  1339. SIPController.pendingCall.expiresT7 = (int) (currentTime.getTime() - SIPController.pendingCall.callTime_T7.getTime()) / 1000;
  1340. if (SIPController.pendingCall.callTime_T8 != null)
  1341. SIPController.pendingCall.expiresT8 = (int) (currentTime.getTime() - SIPController.pendingCall.callTime_T8.getTime()) / 1000;
  1342. if (SIPController.pendingCall.callTime_T9 != null)
  1343. SIPController.pendingCall.expiresT9 = (int) (currentTime.getTime() - SIPController.pendingCall.callTime_T9.getTime());//milli seconds
  1344. // Log.d(TAG, "[SIPCTRLCall] SIPController.sipCall.callState [" + SIPController.sipCall.callState + "]");
  1345. if (SIPController.pendingCall.bAsMaster == true) {
  1346. // CONNECTED TIMEOUT PROCESSING
  1347. SIPController.sipCall.exceptionT4();
  1348. // CONFERENCE CALL CHECK NEEDED
  1349. if (SIPController.audioRTPManager != null)
  1350. SIPController.audioRTPManager.RTPEnd(5);
  1351. if (SIPStack.bDirectCall == true) {
  1352. // SERVICE MESSAGE NEEDED
  1353. dialerVideoSet(false);
  1354. }
  1355. sendBye();
  1356. SIPController.sipCall.resetCall();
  1357. SIPController.sipCall = SIPController.pendingCall;
  1358. SIPController.pendingCall = new SIPCall();
  1359. // for temporary
  1360. if (SIPController.sipCall.callDirection == SIPStack.SIP_CALLDIRECTION_IN && SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_OFFERRED) {
  1361. Log.i(TAG, "call exchange : " + SIPController.sipCall.remoteIp);
  1362. BSSVideo.bProgressvideooffer = true;
  1363. sendProgressingwithbody(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort);
  1364. if (SIPController.sipCall.callDirection == SIPStack.SIP_CALLDIRECTION_IN && SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_OFFERRED) {
  1365. // Phone status set
  1366. // SERVICE MESSAGE NEEDED
  1367. updateDialerStatus("Incoming call accept.", false);
  1368. directsendAccept(false); // 방문객 원격통화로 인하여 CallOwner (boolean) 파라미터 추가
  1369. return;
  1370. }
  1371. }
  1372. return;
  1373. } else {
  1374. if (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_TERMINATING || SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_DISCONNECTING || SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_IDLE) {
  1375. // CONNECTED TIMEOUT PROCESSING
  1376. SIPController.sipCall.exceptionT4();
  1377. // CONFERENCE CALL CHECK NEEDED
  1378. if (SIPController.audioRTPManager != null)
  1379. SIPController.audioRTPManager.RTPEnd(6);
  1380. if (SIPStack.bDirectCall == true) {
  1381. // SERVICE MESSAGE NEEDED
  1382. dialerVideoSet(false);
  1383. }
  1384. sendBye();
  1385. SIPController.sipCall.resetCall();
  1386. SIPController.sipCall = SIPController.pendingCall;
  1387. SIPController.pendingCall = new SIPCall();
  1388. // for temporary
  1389. if (SIPController.sipCall.callDirection == SIPStack.SIP_CALLDIRECTION_IN && SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_OFFERRED) {
  1390. Log.i(TAG, "call exchange : " + SIPController.sipCall.remoteIp);
  1391. BSSVideo.bProgressvideooffer = true;
  1392. sendProgressingwithbody(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort);
  1393. }
  1394. return;
  1395. }
  1396. }
  1397. if (SIPController.pendingCall.bRejectRequest == true) {
  1398. if (SIPController.bMulticallBusyResponse == true) rejectPendingCall(486);
  1399. else rejectPendingCall(480);
  1400. } else if (SIPController.pendingCall.callState == SIPStack.SIP_CALLSTATE_IDLE) {
  1401. if (SIPController.pendingCall.expiresTI > SIPStack.CS_TIMEOUT_TI) {
  1402. SIPController.pendingCall.resetCall();
  1403. }
  1404. } else if (SIPController.pendingCall.callState == SIPStack.SIP_CALLSTATE_DISCONNECTING) {
  1405. if (SIPController.pendingCall.expiresT5 > SIPStack.CS_TIMEOUT_T5) {
  1406. // DISCONNECTING TIMEOUT PROCESSING
  1407. SIPController.pendingCall.resetCall();
  1408. }
  1409. } else if (SIPController.pendingCall.callState == SIPStack.SIP_CALLSTATE_TERMINATING) {
  1410. if (SIPController.pendingCall.expiresT6 > SIPStack.CS_TIMEOUT_T6) {
  1411. SIPController.pendingCall.resetCall();
  1412. }
  1413. } else if (SIPController.pendingCall.callState == SIPStack.SIP_CALLSTATE_OFFERRED) {
  1414. if (SIPController.pendingCall.expiresT7 > SIPStack.CS_TIMEOUT_T7) {
  1415. SIPController.pendingCall.exceptionT7();
  1416. rejectPendingCall(408);
  1417. }
  1418. } else if (SIPController.pendingCall.callState == SIPStack.SIP_CALLSTATE_CANCELLING) {
  1419. if (SIPController.pendingCall.expiresT8 > SIPStack.CS_TIMEOUT_T8) {
  1420. SIPController.pendingCall.resetCall();
  1421. }
  1422. } else if (SIPController.pendingCall.callState == SIPStack.SIP_CALLSTATE_RECANCELLING) {
  1423. if (SIPController.pendingCall.expiresT8 > SIPStack.CS_TIMEOUT_T8) {
  1424. SIPController.pendingCall.resetCall();
  1425. }
  1426. } else if (SIPController.pendingCall.callState == SIPStack.SIP_CALLSTATE_CANCELREMOTEACCEPTED) {
  1427. if (SIPController.pendingCall.expiresT8 > SIPStack.CS_TIMEOUT_T8) {
  1428. SIPController.pendingCall.resetCall();
  1429. }
  1430. } else if (SIPController.pendingCall.callState == SIPStack.SIP_CALLSTATE_CANCELLED) {
  1431. if (SIPController.pendingCall.expiresT8 > SIPStack.CS_TIMEOUT_T8) {
  1432. SIPController.pendingCall.resetCall();
  1433. }
  1434. }
  1435. }
  1436. if (SIPController.sipCall == null || SIPController.sipCall.flag == false) {
  1437. if (cmcore.regState == SIPStack.SIP_REGSTATE_REGISTERED) {
  1438. // SERVICE MESSAGE NEEDED
  1439. updateDialerStatus("Ready.", cmcore.bRequestReadySet);
  1440. } else {
  1441. // SERVICE MESSAGE NEEDED
  1442. if (SIPStack.bDirectCall == false)
  1443. updateDialerStatus("Not registered.", cmcore.bRequestReadySet);
  1444. }
  1445. if (cmcore.bRequestReadySet == true) {
  1446. cmcore.bRequestReadySet = false;
  1447. }
  1448. return;
  1449. }
  1450. if (SIPController.sipCall != null && SIPController.sipCall.flag == true) {
  1451. if (SIPController.sipCall.callTime_TI != null)
  1452. SIPController.sipCall.expiresTI = (int) (currentTime.getTime() - SIPController.sipCall.callTime_TI.getTime()) / 1000;
  1453. if (SIPController.sipCall.callTime_T0 != null)
  1454. SIPController.sipCall.expiresT0 = (int) (currentTime.getTime() - SIPController.sipCall.callTime_T0.getTime()) / 1000;
  1455. if (SIPController.sipCall.callTime_T00 != null)
  1456. SIPController.sipCall.expiresT00 = (int) (currentTime.getTime() - SIPController.sipCall.callTime_T00.getTime()) / 1000;
  1457. if (SIPController.sipCall.callTime_T1 != null)
  1458. SIPController.sipCall.expiresT1 = (int) (currentTime.getTime() - SIPController.sipCall.callTime_T1.getTime()) / 1000;
  1459. if (SIPController.sipCall.callTime_T2 != null)
  1460. SIPController.sipCall.expiresT2 = (int) (currentTime.getTime() - SIPController.sipCall.callTime_T2.getTime()) / 1000;
  1461. if (SIPController.sipCall.callTime_T3 != null)
  1462. SIPController.sipCall.expiresT3 = (int) (currentTime.getTime() - SIPController.sipCall.callTime_T3.getTime()) / 1000;
  1463. if (SIPController.sipCall.callTime_T4 != null)
  1464. SIPController.sipCall.expiresT4 = (int) (currentTime.getTime() - SIPController.sipCall.callTime_T4.getTime()) / 1000;
  1465. if (SIPController.sipCall.callTime_T5 != null)
  1466. SIPController.sipCall.expiresT5 = (int) (currentTime.getTime() - SIPController.sipCall.callTime_T5.getTime()) / 1000;
  1467. if (SIPController.sipCall.callTime_T6 != null)
  1468. SIPController.sipCall.expiresT6 = (int) (currentTime.getTime() - SIPController.sipCall.callTime_T6.getTime()) / 1000;
  1469. if (SIPController.sipCall.callTime_T7 != null)
  1470. SIPController.sipCall.expiresT7 = (int) (currentTime.getTime() - SIPController.sipCall.callTime_T7.getTime()) / 1000;
  1471. if (SIPController.sipCall.callTime_T8 != null)
  1472. SIPController.sipCall.expiresT8 = (int) (currentTime.getTime() - SIPController.sipCall.callTime_T8.getTime()) / 1000;
  1473. if (SIPController.sipCall.callTime_T9 != null)
  1474. SIPController.sipCall.expiresT9 = (int) (currentTime.getTime() - SIPController.sipCall.callTime_T9.getTime());
  1475. if (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_IDLE) {
  1476. if (SIPController.sipCall.expiresTI > SIPStack.CS_TIMEOUT_TI) {
  1477. // IDLE TIMEOUT PROCESSING
  1478. SIPController.sipCall.exceptionTI();
  1479. //SERVICE MESSAGE NEEDED
  1480. updateDialerStatus("Ready.", true);
  1481. }
  1482. } else if (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_INVITING) {
  1483. if ((SIPStack.ventureCall == true || SIPStack.bDirectCall == true) && SIPController.sipCall.expiresT00 > 3) {
  1484. sendReInvite();
  1485. SIPStack.ventureCall = false;
  1486. } else if (SIPController.sipCall.expiresT00 > SIPStack.CS_TIMEOUT_T00) {
  1487. //INVITING REPEAT TIMEOUT PROCESSING
  1488. sendReInvite();
  1489. SIPStack.ventureCall = false;
  1490. }
  1491. if (SIPController.sipCall.expiresT0 > SIPStack.CS_TIMEOUT_T000) {
  1492. Log.i(TAG, " " + SIPController.sipCall.expiresT0);
  1493. sendCancel();
  1494. }
  1495. } else if (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_PROCEEDING) {
  1496. if (SIPController.sipCall.expiresT1 > SIPStack.CS_TIMEOUT_T1) {
  1497. //PROCEEDING TIMEOUT PROCESSING
  1498. SIPController.sipCall.exceptionT1();
  1499. // CONFERENCE CALL CHECK NEEDED
  1500. if (SIPController.audioRTPManager != null)
  1501. SIPController.audioRTPManager.RTPEnd(7);
  1502. if (SIPStack.bDirectCall == true) {
  1503. //SERVICE MESSAGE NEEDED
  1504. dialerVideoSet(false);
  1505. }
  1506. sendCancel();
  1507. }
  1508. } else if (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_PROGRESSING) {
  1509. if (SIPController.sipCall.expiresT2 > SIPStack.CS_TIMEOUT_T2) {
  1510. //PROGRESSING TIMEOUT PROCESSING
  1511. SIPController.sipCall.exceptionT2();
  1512. // CONFERENCE CALL CHECK NEEDED
  1513. if (SIPController.audioRTPManager != null)
  1514. SIPController.audioRTPManager.RTPEnd(8);
  1515. if (SIPStack.bDirectCall == true) {
  1516. //SERVICE MESSAGE NEEDED
  1517. dialerVideoSet(false);
  1518. }
  1519. sendCancel();
  1520. }
  1521. } else if (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_ACCEPTED || SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_REMOTEACCEPTED) {
  1522. if (SIPController.sipCall.expiresT3 > SIPStack.CS_TIMEOUT_T3) {
  1523. //ACCEPTED TIMEOUT PROCESSING
  1524. SIPController.sipCall.exceptionT3();
  1525. // CONFERENCE CALL CHECK NEEDED
  1526. if (SIPController.audioRTPManager != null)
  1527. SIPController.audioRTPManager.RTPEnd(9);
  1528. if (SIPStack.bDirectCall == true) {
  1529. //SERVICE MESSAGE NEEDED
  1530. dialerVideoSet(false);
  1531. }
  1532. sendBye();
  1533. }
  1534. } else if (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_CONNECTED) {
  1535. if (SIPController.sipCall.expiresT4 > SIPStack.CS_TIMEOUT_T4) {
  1536. //CONNECTED TIMEOUT PROCESSING
  1537. SIPController.sipCall.exceptionT4();
  1538. // CONFERENCE CALL CHECK NEEDED
  1539. if (SIPController.audioRTPManager != null)
  1540. SIPController.audioRTPManager.RTPEnd(10);
  1541. if (SIPStack.bDirectCall == true) {
  1542. //SERVICE MESSAGE NEEDED
  1543. dialerVideoSet(false);
  1544. }
  1545. sendBye();
  1546. } else {
  1547. int expiresT40 = 0;
  1548. if (SIPController.sipCall.callTime_T40 != null) {
  1549. expiresT40 = (int) (currentTime.getTime() - SIPController.sipCall.callTime_T40.getTime()) / 1000;
  1550. if (expiresT40 > 0) {
  1551. SIPController.sipCall.callTime_T40 = new Date();
  1552. }
  1553. }
  1554. // try {
  1555. // if (SIPController.audioRTPManager != null && SIPController.sipCall.expiresT4 > 1 && SIPController.audioRTPManager.bDisableVoice == false) {
  1556. // int muteDuration = (int) (currentTime.getTime() - SIPController.audioRTPManager.rtpCore.rtpArrivalTime.getTime());
  1557. // Log.e(TAG, "[SIPStun] ========== RTP END ========== muteDuration [" + muteDuration + "]");
  1558. // if (muteDuration > 5000) {
  1559. // // milliseconds
  1560. // // CONFERENCE CALL CHECK NEEDED
  1561. // if (SIPController.audioRTPManager != null)
  1562. // SIPController.audioRTPManager.RTPEnd(11);
  1563. // if (SIPStack.bDirectCall == true) {
  1564. // //SERVICE MESSAGE NEEDED
  1565. // dialerVideoSet(false);
  1566. // }
  1567. // sendBye();
  1568. // //SERVICE MESSAGE NEEDED
  1569. // updateDialerStatus("No Audio Packet Received for 3Sec!", false);
  1570. // //SERVICE MESSAGE NEEDED
  1571. // dialerNotifyCallEnd("No Audio Packet Received for 3Sec!", SIPController.sipCall.dnis, SIPController.sipCall.dnis + "@" + SIPController.sipCall.remoteIp + ":" + SIPController.sipCall.remotePort, false);
  1572. // }
  1573. // }
  1574. // } catch (RuntimeException re) {
  1575. // LogUtil.errorLogInfo("", TAG, re);
  1576. // } catch (Exception e) {
  1577. // Log.e(TAG, "[Exception] dialerVideoSet(false)");
  1578. // }
  1579. }
  1580. } else if (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_DISCONNECTING) {
  1581. if (SIPController.sipCall.bByedisconnected == true && SIPController.sipCall.expiresT9 > 500) {
  1582. //resend bye
  1583. resendBye();
  1584. }
  1585. if (SIPController.sipCall.expiresT5 > SIPStack.CS_TIMEOUT_T5) {
  1586. //DISCONNECTING TIMEOUT PROCESSING
  1587. SIPController.sipCall.exceptionT5();
  1588. SIPController.sipCall.resetCall();
  1589. }
  1590. } else if (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_TERMINATING) {
  1591. if (SIPController.sipCall.expiresT6 > SIPStack.CS_TIMEOUT_T6) {
  1592. dialerNotifyCallEnd("Call Terminating.", SIPController.sipCall.dnis, SIPController.sipCall.dnis + "@" + SIPController.sipCall.remoteIp + ":" + SIPController.sipCall.remotePort, false);
  1593. SIPController.sipCall.exceptionT6();
  1594. cmcore.ctrlIntervalTimer = new Date();
  1595. cmcore.bRequestReadySet = true;
  1596. }
  1597. } else if (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_OFFERRED) {
  1598. if (SIPController.sipCall.expiresT7 > SIPStack.CS_TIMEOUT_T7) {
  1599. //OFFERRED TIMEOUT PROCESSING
  1600. SIPController.sipCall.exceptionT7();
  1601. //CONFERENCE CALL CHECK NEEDED
  1602. if (SIPController.audioRTPManager != null)
  1603. SIPController.audioRTPManager.RTPEnd(12);
  1604. if (SIPStack.bDirectCall == true) {
  1605. //SERVICE MESSAGE NEEDED
  1606. dialerVideoSet(false);
  1607. }
  1608. rejectCall(408);
  1609. }
  1610. } else if (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_CANCELLING) {
  1611. //more code needed !!!!
  1612. if (SIPController.sipCall.expiresT8 > SIPStack.CS_TIMEOUT_T80) {
  1613. //CANCELLING TIMEOUT PROCESSING
  1614. sendRecancel();
  1615. }
  1616. } else if (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_RECANCELLING) {
  1617. //more code needed !!!!
  1618. if (SIPController.sipCall.expiresT8 > SIPStack.CS_TIMEOUT_T8) {
  1619. //CANCELLING TIMEOUT PROCESSING
  1620. SIPController.sipCall.exceptionT8();
  1621. //SERVICE MESSAGE NEEDED
  1622. dialerNotifyCallEnd("전화를 받지 않습니다.", SIPController.sipCall.dnis, SIPController.sipCall.dnis + "@" + SIPController.sipCall.remoteIp + ":" + SIPController.sipCall.remotePort, false);
  1623. SIPController.sipCall.resetCall();
  1624. }
  1625. } else if (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_CANCELREMOTEACCEPTED) {
  1626. if (SIPController.sipCall.expiresT8 > SIPStack.CS_TIMEOUT_T8) {
  1627. dialerNotifyCallFail(487, SIPController.sipCall.remoteIp, makeSIPID(SIPController.sipCall.remoteIp));
  1628. // CANCELLING TIMEOUT PROCESSING
  1629. SIPController.sipCall.exceptionT8();
  1630. SIPController.sipCall.resetCall();
  1631. }
  1632. }
  1633. } else if (SIPController.sipCall.callMode == SIPStack.SIP_CALLMODE_HOLD) {
  1634. // more job
  1635. }
  1636. return;
  1637. }
  1638. public int SIPParser(String strMessage, int nMSGType, int nMethodType) {
  1639. if (strMessage == null || strMessage.length() <= 0) return 0;
  1640. boolean bSendRegister = false;
  1641. if (bPrintSIPMsgIO) {
  1642. Log.i(TAG, "[SIPParser] nMSGType [" + nMSGType + "], nMethodType [" + nMethodType + "]");
  1643. printSIPMessage(MESSAGE.RECEIVE, strMessage);
  1644. }
  1645. if (nMSGType != SIPStack.SIP_MSGTYPE_RESPONSE || nMethodType != SIPStack.SIP_METHODTYPE_REGISTER)
  1646. return -1;
  1647. SIPRequestLine requestLine = new SIPRequestLine(strMessage);
  1648. if (requestLine == null || requestLine.flag == false) return 0;
  1649. switch (requestLine.code) {
  1650. case 200:
  1651. cmcore.repeatRegisterCount = 0;
  1652. if (cmcore.regState == SIPStack.SIP_REGSTATE_REGISTERING || cmcore.regState == SIPStack.SIP_REGSTATE_AUTHORIZING || cmcore.regState == SIPStack.SIP_REGSTATE_UNREGISTERING) {
  1653. SIPCONTACTHeader contactHeader = cmcore.action_reg_0(strMessage);
  1654. if (contactHeader != null && contactHeader.flag == false) {
  1655. contactHeader = new SIPCONTACTHeader(strMessage);
  1656. }
  1657. if (contactHeader == null || contactHeader.flag == false || contactHeader.expires == 0 || cmcore.regState == SIPStack.SIP_REGSTATE_UNREGISTERING) {
  1658. if (cmcore.bInterfaceChanged == true) {
  1659. cmcore.bInterfaceChanged = false;
  1660. cmcore.regState = SIPStack.SIP_REGSTATE_REGISTERING;
  1661. sendRegister();
  1662. } else {
  1663. cmcore.regState = SIPStack.SIP_REGSTATE_IDLE;
  1664. }
  1665. break;
  1666. }
  1667. if (contactHeader.expires > 0) {
  1668. cmcore.expiresSeconds = contactHeader.getExpires();
  1669. } else if (contactHeader.expires < 0) {
  1670. SIPHeader expiresHeader = new SIPHeader(strMessage, SIPStack.SIP_HEADERTYPE_EXPIRES);
  1671. if (expiresHeader != null && expiresHeader.flag == true && expiresHeader.headerValue != null && expiresHeader.headerValue.length() > 0) {
  1672. cmcore.expiresSeconds = Integer.parseInt(expiresHeader.headerValue.trim());
  1673. }
  1674. }
  1675. // SET REGISTERSTATE AS REGISTERED
  1676. if (cmcore.expiresSeconds > 0) {
  1677. cmcore.regTime = new Date();
  1678. cmcore.regState = SIPStack.SIP_REGSTATE_REGISTERED;
  1679. // Phone status set
  1680. if (SIPController.sipCall == null || SIPController.sipCall.flag == false) {
  1681. // SERVICE MESSAGE NEEDED
  1682. updateDialerStatus("Ready.", false);
  1683. }
  1684. if (true == cmcore.action_reg_1(strMessage)) {
  1685. cmcore.regState = SIPStack.SIP_REGSTATE_UNREGISTERING;
  1686. sendUNRegister(cmcore.previfIp, cmcore.previfPort);
  1687. }
  1688. } else if (cmcore.expiresSeconds == 0) {
  1689. cmcore.regTime = new Date();
  1690. cmcore.regState = SIPStack.SIP_REGSTATE_IDLE;
  1691. // SERVICE MESSAGE NEEDED
  1692. updateDialerStatus("Service Off mode", false);
  1693. }
  1694. }
  1695. break;
  1696. case 401:
  1697. if (cmcore.repeatRegisterCount > 3) {
  1698. cmcore.regState = SIPStack.SIP_REGSTATE_UNAVAILABLE;
  1699. cmcore.repeatRegisterCount = 0;
  1700. // Phone status set
  1701. // SERVICE MESSAGE NEEDED
  1702. updateDialerStatus("Server 인증 실패하였습니다.", false);
  1703. break;
  1704. }
  1705. cmcore.regState = SIPStack.SIP_REGSTATE_UNAUTHORIZED;
  1706. // Phone status set
  1707. if (SIPController.sipCall.flag == false) {
  1708. // SERVICE MESSAGE NEEDED
  1709. updateDialerStatus("Regist Unauthorized.", false);
  1710. }
  1711. if (true == cmcore.action_reg_2(strMessage)) {
  1712. bSendRegister = true;
  1713. cmcore.repeatRegisterCount++;
  1714. }
  1715. break;
  1716. case 407:
  1717. if (cmcore.repeatRegisterCount > 3) {
  1718. cmcore.regState = SIPStack.SIP_REGSTATE_UNAVAILABLE;
  1719. cmcore.repeatRegisterCount = 0;
  1720. // Phone status set
  1721. // SERVICE MESSAGE NEEDED
  1722. updateDialerStatus("Server 인증 실패하였습니다.", false);
  1723. break;
  1724. }
  1725. // Phone status set
  1726. // SERVICE MESSAGE NEEDED
  1727. updateDialerStatus("Regist Unauthorized.", false);
  1728. if (true == cmcore.action_reg_3(strMessage)) {
  1729. bSendRegister = true;
  1730. }
  1731. break;
  1732. case 423:
  1733. cmcore.action_reg_4(strMessage);
  1734. sendRegister();
  1735. break;
  1736. default:
  1737. if (requestLine.code >= 400) cmcore.regState = SIPStack.SIP_REGSTATE_UNAVAILABLE;
  1738. break;
  1739. }
  1740. if (bSendRegister) {
  1741. cmcore.regState = SIPStack.SIP_REGSTATE_AUTHORIZING;
  1742. if (cmcore.authorizationH != null && cmcore.authorizationH.length() > 0)
  1743. sendRegister();
  1744. }
  1745. return 0; // normal
  1746. } // SIPParser()
  1747. public void UPDATEParser(String message, int msgType, String remoteIp, int remotePort) {
  1748. Log.d(TAG, "[UPDATEParser]");
  1749. if (SIPController.sipCall == null || SIPController.sipCall.flag == false || (SIPController.sipCall.callMode != SIPStack.SIP_CALLMODE_BASIC && SIPController.sipCall.callMode != SIPStack.SIP_CALLMODE_HOLD)) {
  1750. if (msgType == SIPStack.SIP_MSGTYPE_RESPONSE) {
  1751. SIPRequestLine requestLine = new SIPRequestLine(message);
  1752. if (requestLine != null && requestLine.flag == true && requestLine.code >= 300) {
  1753. sendFinalAck(message, remoteIp, remotePort);
  1754. }
  1755. }
  1756. return;
  1757. }
  1758. if (msgType == SIPStack.SIP_MSGTYPE_REQUEST) {
  1759. if (SIPController.sipCall != null) {
  1760. if (SIPController.sipCall.flag == true) {
  1761. // busy
  1762. // validate call
  1763. SIPHeader sipHeader = new SIPHeader(message, SIPStack.SIP_HEADERTYPE_CALLID);
  1764. boolean bValidCall = false;
  1765. if (sipHeader != null && sipHeader.flag == true) {
  1766. if (sipHeader.headerValue != null && sipHeader.headerValue.length() > 0 && SIPController.sipCall.callId != null && sipHeader.headerValue.compareTo(SIPController.sipCall.callId) == 0) {
  1767. bValidCall = true;
  1768. }
  1769. }
  1770. if (bValidCall == true) {
  1771. // EXIST CALL
  1772. // IF HOLDMODE
  1773. if (SIPController.sipCall.callMode == SIPStack.SIP_CALLMODE_HOLD) {
  1774. if (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_UPDATEOFFERRED) {
  1775. // ACCEPT
  1776. }
  1777. return;
  1778. } else if (SIPController.sipCall.callMode == SIPStack.SIP_CALLMODE_BASIC && SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_CONNECTED) {
  1779. // IF CONNECTED
  1780. // SET CALLMODE AS UPDATE
  1781. SIPController.sipCall.callMode = SIPStack.SIP_CALLMODE_HOLD;
  1782. SIPController.sipCall.callState = SIPStack.SIP_CALLSTATE_UPDATEOFFERRED;
  1783. SIPController.sipCall.callDirection = SIPStack.SIP_CALLDIRECTION_IN;
  1784. //parse message + construct local and remote sdp +negotiate codec
  1785. if (true == SIPController.sipCall.constructUPDATEHeaders(message, remoteIp, remotePort)) {
  1786. // response trying
  1787. sendProceeding(remoteIp, remotePort);
  1788. if (false == sendUpdateAccept()) {
  1789. rejectCall(message, 480, remoteIp, remotePort);
  1790. return;
  1791. }
  1792. } else {
  1793. rejectCall(message, 480, remoteIp, remotePort);
  1794. return;
  1795. }
  1796. // ACCEPT
  1797. return;
  1798. } else {
  1799. // DISCARD
  1800. return;
  1801. }
  1802. } else {
  1803. // invalid update call
  1804. rejectCall(message, 400, remoteIp, remotePort);
  1805. return;
  1806. }
  1807. } else {
  1808. // invalid update call
  1809. rejectCall(message, 400, remoteIp, remotePort);
  1810. return;
  1811. }
  1812. } else {
  1813. // response 400
  1814. // no sip call handle
  1815. // response only
  1816. rejectCall(message, 400, remoteIp, remotePort);
  1817. return;
  1818. }
  1819. } else if (msgType == SIPStack.SIP_MSGTYPE_RESPONSE && SIPController.sipCall.flag == true && SIPController.sipCall.callDirection == SIPStack.SIP_CALLDIRECTION_OUT) {
  1820. if (SIPController.sipCall.callMode != SIPStack.SIP_CALLMODE_HOLD) return;
  1821. SIPRequestLine requestLine = new SIPRequestLine(message);
  1822. if (requestLine != null) {
  1823. // validate call
  1824. SIPHeader sipHeader = new SIPHeader(message, SIPStack.SIP_HEADERTYPE_CALLID);
  1825. boolean bValidCall = false;
  1826. if (sipHeader != null && sipHeader.flag == true) {
  1827. if (sipHeader.headerValue != null && sipHeader.headerValue.length() > 0 && SIPController.sipCall.callId != null && sipHeader.headerValue.compareTo(SIPController.sipCall.callId) == 0) {
  1828. SIPHeader seqHeader = new SIPHeader(message, SIPStack.SIP_HEADERTYPE_CSEQ);
  1829. if (seqHeader != null && seqHeader.callSequenceNumber() == SIPController.sipCall.CSEQ_NUMBER) {
  1830. bValidCall = true;
  1831. } else if (requestLine.code < 200) {
  1832. return;
  1833. }
  1834. }
  1835. }
  1836. if (bValidCall == true) {
  1837. sipHeader = null;
  1838. sipHeader = new SIPHeader(message, SIPStack.SIP_HEADERTYPE_TO);
  1839. if (sipHeader != null) {
  1840. SIPController.sipCall.toH = sipHeader.header;
  1841. SIPController.sipCall.toTag = sipHeader.getTag();
  1842. }
  1843. }
  1844. sipHeader = new SIPHeader(message, SIPStack.SIP_HEADERTYPE_CSEQ);
  1845. if (bValidCall == true) {
  1846. SIPController.sipCall.remoteIp = remoteIp;
  1847. SIPController.sipCall.remotePort = remotePort;
  1848. if (requestLine.code >= 200 && sipHeader != null && sipHeader.flag == true) {
  1849. SIPController.sipCall.CSEQ_NUMBER = sipHeader.callSequenceNumber();
  1850. }
  1851. if (requestLine.code == 100) {
  1852. // trying
  1853. SIPController.sipCall.callState = SIPStack.SIP_CALLSTATE_UPDATEPROCEEDING;
  1854. SIPController.sipCall.callTime_T1 = new Date();
  1855. } else if (requestLine.code >= 180 && requestLine.code <= 183) {
  1856. // progressing
  1857. SIPController.sipCall.callState = SIPStack.SIP_CALLSTATE_UPDATEPROGRESSING;
  1858. SIPController.sipCall.callTime_T2 = new Date();
  1859. if (true == SIPController.sipCall.parseRemoteSdp(message)) {
  1860. if (SIPController.sipCall.sdp != null && SIPController.sipCall.sdp.flag == true) {
  1861. SIPController.sipCall.negotiateAudioCodec();
  1862. }
  1863. if (SIPController.sipCall.remoteSdp != null && SIPController.sipCall.remoteSdp.flag == true && SIPController.audioRTPManager != null) {
  1864. if (SIPController.sipCall.remoteSdp.audioM.flag == true) {
  1865. if (SIPController.audioRTPManager != null) {
  1866. SIPController.audioRTPManager.setRemoteMediaInfo(SIPController.sipCall.remoteSdp.audioM.commonCodec, SIPController.sipCall.remoteSdp.audioM.mediaIp, SIPController.sipCall.remoteSdp.audioM.mediaPort);
  1867. if (SIPController.sipCall.sdp != null && SIPController.sipCall.sdp.audioM != null && SIPController.audioRTPManager.rtpCore.bActive == false) {
  1868. SIPController.audioRTPManager.RTPInit(SIPController.sipCall.sdp.audioM.mediaPort, 1);
  1869. }
  1870. }
  1871. }
  1872. }
  1873. }
  1874. } else if (requestLine.code == 200 && SIPController.sipCall.CSEQ_NUMBER == sipHeader.callSequenceNumber() &&
  1875. (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_UPDATING || SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_UPDATEPROCEEDING ||
  1876. SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_UPDATEPROGRESSING)) {
  1877. // connected
  1878. SIPController.sipCall.callState = SIPStack.SIP_CALLSTATE_UPDATEREMOTEACCEPTED;
  1879. SIPController.sipCall.callTime_T3 = new Date();
  1880. boolean ret = sendAck(message);
  1881. if (ret == true) {
  1882. SIPController.sipCall.callState = SIPStack.SIP_CALLSTATE_CONNECTED;
  1883. SIPController.sipCall.callMode = SIPStack.SIP_CALLMODE_BASIC;
  1884. SIPSound.resetBufferInfo();
  1885. // SERVICE MESSAGE NEEDED
  1886. dialerNotifyCallConnected(SIPController.sipCall.dnis, SIPController.sipCall.dnis + "@" + SIPController.sipCall.remoteIp + ":" + SIPController.sipCall.remotePort);
  1887. }
  1888. // remote body analysis
  1889. // MUST BE CHANGE
  1890. if (true == SIPController.sipCall.parseRemoteSdp(message)) {
  1891. if (SIPController.sipCall.sdp != null && SIPController.sipCall.sdp.flag == true) {
  1892. SIPController.sipCall.negotiateAudioCodec();
  1893. }
  1894. if (SIPController.sipCall.remoteSdp != null && SIPController.sipCall.remoteSdp.flag == true && SIPController.audioRTPManager != null) {
  1895. if (SIPController.sipCall.remoteSdp.audioM != null && SIPController.sipCall.remoteSdp.audioM.flag == true) {
  1896. if (SIPController.audioRTPManager != null) {
  1897. SIPController.audioRTPManager.setRemoteMediaInfo(SIPController.sipCall.remoteSdp.audioM.commonCodec, SIPController.sipCall.remoteSdp.audioM.mediaIp, SIPController.sipCall.remoteSdp.audioM.mediaPort);
  1898. if (SIPController.sipCall.sdp != null && SIPController.sipCall.sdp.audioM != null && SIPController.audioRTPManager.rtpCore.bActive == false) {
  1899. SIPController.audioRTPManager.RTPInit(SIPController.sipCall.sdp.audioM.mediaPort, 2);
  1900. }
  1901. }
  1902. }
  1903. }
  1904. }
  1905. } else if (requestLine.code == 401 && (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_UPDATING || SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_UPDATEPROCEEDING ||
  1906. SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_UPDATEPROGRESSING)) {
  1907. SIPController.sipCall.callState = SIPStack.SIP_CALLSTATE_UPDATEUNAUTHORIZED;
  1908. sendFinalAck(message);
  1909. if (reactionForWWWAUTHENTICATE(message) == false) {
  1910. if (SIPController.audioRTPManager != null)
  1911. SIPController.audioRTPManager.RTPEnd(13);
  1912. SIPController.sipCall.resetCall();
  1913. }
  1914. } else if (requestLine.code == 407 && (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_UPDATING || SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_UPDATEPROCEEDING ||
  1915. SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_UPDATEPROGRESSING)) {
  1916. // Proxy-Athenticate
  1917. SIPController.sipCall.callState = SIPStack.SIP_CALLSTATE_UPDATEUNAUTHORIZED;
  1918. sendFinalAck(message);
  1919. if (reactionForPROXYAUTHENTICATE(message) == false) {
  1920. if (SIPController.audioRTPManager != null)
  1921. SIPController.audioRTPManager.RTPEnd(14);
  1922. SIPController.sipCall.resetCall();
  1923. }
  1924. } else if (requestLine.code == 302 && (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_UPDATING || SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_UPDATEPROCEEDING ||
  1925. SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_UPDATEPROGRESSING)) {
  1926. // terminating
  1927. // FORWARD - MUST BE PROCESSED MORE
  1928. SIPController.sipCall.callState = SIPStack.SIP_CALLSTATE_TERMINATING;
  1929. sendFinalAck(message);
  1930. if (SIPController.audioRTPManager != null)
  1931. SIPController.audioRTPManager.RTPEnd(15);
  1932. SIPController.sipCall.resetCall();
  1933. } else if (requestLine.code >= 300 && (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_UPDATING || SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_UPDATEPROCEEDING ||
  1934. SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_UPDATEPROGRESSING || SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_UPDATEUNAUTHORIZED)) {
  1935. // terminating
  1936. SIPController.sipCall.callState = SIPStack.SIP_CALLSTATE_TERMINATING;
  1937. sendFinalAck(message);
  1938. if (SIPController.audioRTPManager != null)
  1939. SIPController.audioRTPManager.RTPEnd(16);
  1940. SIPController.sipCall.resetCall();
  1941. }
  1942. } else {
  1943. sendFinalAck(message, remoteIp, remotePort);
  1944. }
  1945. }
  1946. }
  1947. return;
  1948. }
  1949. String m_strMessage = "", m_strRemoteIP = "";
  1950. int m_strRemotePort = 0;
  1951. public void INVITEParser(String strMessage, int nMSGType, String strRemoteIP, int strRemotePort) {
  1952. try {
  1953. Log.w(TAG, "[INVITEParser] bBLOCK_INVITE_MSG [" + bBLOCK_INVITE_MSG + "]");
  1954. Log.w(TAG, "[INVITEParser] strMessage [" + strMessage + "]");
  1955. //m_strMessage = strMessage;
  1956. //m_strRemoteIP = strRemoteIP;
  1957. //m_strRemotePort = strRemotePort;
  1958. if (bBLOCK_INVITE_MSG) {
  1959. rejectCall(strMessage, 486, strRemoteIP, strRemotePort);
  1960. return;
  1961. }
  1962. if (nMSGType == SIPStack.SIP_MSGTYPE_REQUEST) {
  1963. if (SIPController.sipCall != null) {
  1964. Log.d(TAG, "[INVITEParser] [SIPController.sipCall.flag = " + SIPController.sipCall.flag + "]");
  1965. if (SIPController.sipCall.flag == true) {
  1966. // busy
  1967. boolean bValidCall = SIPController.sipCall.isCurrentCall(strMessage);
  1968. Log.d(TAG, "[INVITEParser] bValidCall = " + bValidCall);
  1969. if (bValidCall == true) {
  1970. //EXIST CALL
  1971. //IF HOLDEMODE
  1972. if (SIPController.sipCall.callMode == SIPStack.SIP_CALLMODE_HOLD) {
  1973. UPDATEParser(strMessage, nMSGType, strRemoteIP, strRemotePort);
  1974. return;
  1975. }
  1976. else if (SIPController.sipCall.callMode == SIPStack.SIP_CALLMODE_BASIC && SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_CONNECTED) {
  1977. // IF CONNECTED
  1978. // UPDATE PROCESSING
  1979. UPDATEParser(strMessage, nMSGType, strRemoteIP, strRemotePort);
  1980. return;
  1981. }
  1982. else {
  1983. // DISCARD
  1984. return;
  1985. }
  1986. }
  1987. else {
  1988. Log.i(TAG, "BUSY CHECK : callState : " + SIPController.sipCall.callState);
  1989. if (SIPController.sipCall.callState != SIPStack.SIP_CALLSTATE_CONNECTED) {
  1990. rejectCall(strMessage, 486, strRemoteIP, strRemotePort);
  1991. return;
  1992. }
  1993. if (SIPController.bMulticallSupport == true) {
  1994. if (SIPController.pendingCall != null) {
  1995. if (SIPController.pendingCall.flag == true) {
  1996. if (SIPController.pendingCall.isCurrentCall(strMessage) == true) {
  1997. // pendingCall self
  1998. // no action
  1999. } else {
  2000. /* KSJ 2022.06.16
  2001. invite 두번 들어오는 경우가 발생 하여 먼저 들어온 remoteIP 를 저장 하여,
  2002. 통화 중인 같은 IP 에서 call 발생할 경우 multi call 처리를 하지 않고 내용 버리기 위한 코드.
  2003. */
  2004. if(m_strRemoteIP != strRemoteIP) {
  2005. // pendingCall exist and another pending call incoming
  2006. rejectCall(strMessage, 486, strRemoteIP, strRemotePort);
  2007. }
  2008. }
  2009. return;
  2010. } else {
  2011. // New incoming pending call
  2012. CMCore.bDialerActive = true;
  2013. if (CMCore.bDialerActive == false) {
  2014. rejectCall(strMessage, 486, strRemoteIP, strRemotePort);
  2015. return;
  2016. }
  2017. // pending call construct
  2018. String fromId = null;
  2019. String toId = null;
  2020. SIPHeader sipHeader = new SIPHeader(strMessage, SIPStack.SIP_HEADERTYPE_TO);
  2021. if (sipHeader != null && sipHeader.flag == true) {
  2022. toId = sipHeader.getId().trim();
  2023. if (toId != null && toId.length() > 0) {
  2024. sipHeader = new SIPHeader(strMessage, SIPStack.SIP_HEADERTYPE_FROM);
  2025. if (sipHeader != null && sipHeader.flag == true) {
  2026. fromId = sipHeader.getId().trim();
  2027. }
  2028. }
  2029. toId = makeSIPID(toId);
  2030. fromId = makeSIPID(fromId);
  2031. Log.d(TAG, "[INVITEParser111] cmcore.id [" + cmcore.id + "], toId [" + toId + "]");
  2032. if (cmcore.id != null && toId.compareTo(cmcore.id) == 0) {
  2033. // activate call handler
  2034. boolean ret = false;
  2035. if (SIPStack.bDirectCall == false) {
  2036. if (strRemoteIP.compareTo(cmcore.serverIp) == 0) {
  2037. ret = SIPController.pendingCall.activeCallHandle(cmcore.id, cmcore.cid, cmcore.authid, cmcore.authpassword, fromId, strRemoteIP, strRemotePort, cmcore.serverDomain, cmcore.localIp, cmcore.localPort);
  2038. } else {
  2039. ret = SIPController.pendingCall.activeCallHandle(cmcore.id, cmcore.cid, cmcore.authid, cmcore.authpassword, fromId, strRemoteIP, strRemotePort, strRemoteIP, cmcore.localIp, cmcore.localPort);
  2040. }
  2041. } else {
  2042. ret = SIPController.pendingCall.activeCallHandle(cmcore.id, cmcore.cid, cmcore.authid, cmcore.authpassword, fromId, strRemoteIP, strRemotePort, strRemoteIP, cmcore.localIp, cmcore.localPort);
  2043. }
  2044. if (ret == true) {
  2045. SIPController.pendingCall.callState = SIPStack.SIP_CALLSTATE_OFFERRED;
  2046. SIPController.pendingCall.callDirection = SIPStack.SIP_CALLDIRECTION_IN;
  2047. SIPController.pendingCall.callTime_T7 = new Date();//offerred timer
  2048. if (true == SIPController.pendingCall.constructHeaders(strMessage, strRemoteIP, strRemotePort)) {
  2049. if (SIPController.sipCall.remoteContactUri.contains("Lobby") && SIPController.pendingCall.remoteContactUri.contains("Lobby")) {
  2050. rejectPendingCall(486);
  2051. return;
  2052. }
  2053. else if (SIPController.sipCall.remoteContactUri.contains("Guard") && SIPController.pendingCall.remoteContactUri.contains("Guard")) {
  2054. rejectPendingCall(486);
  2055. return;
  2056. }
  2057. else if (SIPController.sipCall.remoteContactUri.contains("Resi") && SIPController.pendingCall.remoteContactUri.contains("Resi")) {
  2058. rejectPendingCall(486);
  2059. return;
  2060. }
  2061. sendPendingProceeding(strRemoteIP, strRemotePort);
  2062. dialerNotifyIncomingMultiCall(SIPController.pendingCall.dnis, SIPController.pendingCall.dnis + "@" + SIPController.pendingCall.remoteIp + ":" + SIPController.pendingCall.remotePort);
  2063. } else {
  2064. rejectCall(strMessage, 480, strRemoteIP, strRemotePort);
  2065. return;
  2066. }
  2067. } else {
  2068. rejectCall(strMessage, 480, strRemoteIP, strRemotePort);
  2069. return;
  2070. }
  2071. sendPendingProgressing(strRemoteIP, strRemotePort);
  2072. return;
  2073. } else {
  2074. rejectCall(strMessage, 404, strRemoteIP, strRemotePort);
  2075. return;
  2076. }
  2077. } else {
  2078. rejectCall(strMessage, 486, strRemoteIP, strRemotePort);
  2079. }
  2080. }
  2081. } else {
  2082. rejectCall(strMessage, 486, strRemoteIP, strRemotePort);
  2083. }
  2084. }
  2085. else {
  2086. // BUSY
  2087. rejectCall(strMessage, 486, strRemoteIP, strRemotePort);
  2088. }
  2089. }
  2090. }
  2091. else {
  2092. // BUSY UPDATE END
  2093. // processing inviting call
  2094. SIPStun.bBlackCall = false;
  2095. boolean bCallPopup = false;
  2096. String fromId = null;
  2097. String toId = null;
  2098. SIPHeader sipHeader = new SIPHeader(strMessage, SIPStack.SIP_HEADERTYPE_TO);
  2099. if (sipHeader != null && sipHeader.flag == true) {
  2100. toId = sipHeader.getId().trim();
  2101. if (toId != null && toId.length() > 0) {
  2102. sipHeader = new SIPHeader(strMessage, SIPStack.SIP_HEADERTYPE_FROM);
  2103. if (sipHeader != null && sipHeader.flag == true) {
  2104. fromId = sipHeader.getId().trim();
  2105. }
  2106. }
  2107. sipHeader = new SIPHeader(strMessage, SIPStack.SIP_HEADERTYPE_CONTACT);
  2108. Log.d(TAG, "[INVITEParser22222] SIP_HEADERTYPE_CONTACT [" + sipHeader.header + "]");
  2109. if(!sipHeader.header.contains("Lobby") && !sipHeader.header.contains("Resi"))
  2110. {
  2111. sipHeader = new SIPHeader(strMessage, SIPStack.SIP_HEADERTYPE_CALLID);
  2112. if(sipHeader.header.contains("HNSLOBBY"))
  2113. {
  2114. bCallPopup = true;
  2115. }
  2116. else if(sipHeader.header.contains("CNSTEC"))
  2117. {
  2118. bCallPopup = true;
  2119. }
  2120. }
  2121. toId = makeSIPID(toId);
  2122. fromId = makeSIPID(fromId);
  2123. Log.d(TAG, "[INVITEParser22222] cmcore.id [" + cmcore.id + "], toId [" + toId + "]");
  2124. // KSJ 호출이 온 IP를 저장 하고 이후 사용 하기 위한 코드 2022.06.16
  2125. m_strMessage = strMessage;
  2126. m_strRemoteIP = strRemoteIP;
  2127. m_strRemotePort = strRemotePort;
  2128. if (cmcore.id != null && toId.compareTo(cmcore.id) == 0) {
  2129. // activate call handler
  2130. boolean ret = false;
  2131. if (SIPStack.bDirectCall == false) {
  2132. if (strRemoteIP.compareTo(cmcore.serverIp) == 0) {
  2133. ret = SIPController.sipCall.activeCallHandle(cmcore.id, cmcore.cid, cmcore.authid, cmcore.authpassword, fromId, strRemoteIP, strRemotePort, cmcore.serverDomain, cmcore.localIp, cmcore.localPort);
  2134. } else {
  2135. ret = SIPController.sipCall.activeCallHandle(cmcore.id, cmcore.cid, cmcore.authid, cmcore.authpassword, fromId, strRemoteIP, strRemotePort, strRemoteIP, cmcore.localIp, cmcore.localPort);
  2136. }
  2137. }
  2138. else {
  2139. Log.i(TAG, "[INVITEParser] New call. Dialer awaken.");
  2140. Log.i(TAG, "[INVITEParser] strRemoteIP [" + strRemoteIP + "], fromId [" + fromId + "]");
  2141. receiveNewCall(strRemoteIP, fromId, bCallPopup);
  2142. Log.d(TAG, "[INVITEParser] CMCore.bDialerActive [" + CMCore.bDialerActive + "]");
  2143. // CMCore.bDialerActive는 GUI의 foreground 여부를 의미한다. (true: foreground)
  2144. // 통화어플 적용시에는 상관없으므로 주석처리한다.
  2145. // GUI는 receiveNewCall(String strRemoteIP, String strRemoteSIPID) 함수에서 실행한다.
  2146. if (CMCore.bDialerActive == false) {
  2147. Log.e(TAG, "[INVITEParser] ============ SEULKI 2 ============");
  2148. SIPStun.bBlackCall = true;
  2149. Log.d(TAG, "[INVITEParser] SIPStun.bBlackcallBackgroundMode [" + SIPStun.bBlackcallBackgroundMode + "]");
  2150. if (SIPStun.bBlackcallBackgroundMode == true) {
  2151. Log.e(TAG, "[INVITEParser] ============ SEULKI 3 ============");
  2152. ret = SIPController.sipCall.activeCallHandle(cmcore.id, cmcore.cid, cmcore.authid, cmcore.authpassword, fromId, strRemoteIP, strRemotePort, strRemoteIP, cmcore.localIp, cmcore.localPort);
  2153. if (ret == true) {
  2154. Log.e(TAG, "[INVITEParser] ============ SEULKI 4 ============");
  2155. SIPController.sipCall.callState = SIPStack.SIP_CALLSTATE_OFFERRED;
  2156. SIPController.sipCall.callDirection = SIPStack.SIP_CALLDIRECTION_IN;
  2157. SIPController.sipCall.callTime_T7 = new Date(); // offerred timer
  2158. // parse message + construct local and remote sdp +negotiate codec
  2159. if (true == SIPController.sipCall.constructHeaders(strMessage, strRemoteIP, strRemotePort)) {
  2160. Log.e(TAG, "[INVITEParser] ============ SEULKI 5 ============");
  2161. // response trying
  2162. sendProceeding(strRemoteIP, strRemotePort);
  2163. SIPController.sipCall.bResponsebackgroundcall = true;
  2164. SIPController.sipCall.bResponsebackgroundcallReady = false;
  2165. if (SIPController.sipCall.hnsOriginatorServiceType == BSSVideo.HNS_SERVICE_LOBBY) {
  2166. SIPController.latestMenu = 1;
  2167. } else if (SIPController.sipCall.hnsOriginatorServiceType == BSSVideo.HNS_SERVICE_GUARD) {
  2168. SIPController.latestMenu = 2;
  2169. } else if (SIPController.sipCall.hnsOriginatorServiceType == BSSVideo.HNS_SERVICE_NEIGHBOR) {
  2170. SIPController.latestMenu = 3;
  2171. }
  2172. if ((BSSVideo.bProgressvideooffer == true) || (SIPController.forward.bForward == true)) {
  2173. Log.e(TAG, "[INVITEParser] ============ SEULKI 6 ============");
  2174. sendProgressingBlackcallwithbody(strRemoteIP, strRemotePort);
  2175. } else {
  2176. Log.e(TAG, "[INVITEParser] ============ SEULKI 7 ============");
  2177. sendProgressing(strRemoteIP, strRemotePort);
  2178. }
  2179. }
  2180. }
  2181. }
  2182. return;
  2183. }
  2184. ret = SIPController.sipCall.activeCallHandle(cmcore.id, cmcore.cid, cmcore.authid, cmcore.authpassword, fromId, strRemoteIP, strRemotePort, strRemoteIP, cmcore.localIp, cmcore.localPort);
  2185. }
  2186. if (ret == true) {
  2187. Log.e(TAG, "[INVITEParser] ============ SEULKI 8 ============");
  2188. SIPController.sipCall.callState = SIPStack.SIP_CALLSTATE_OFFERRED;
  2189. SIPController.sipCall.callDirection = SIPStack.SIP_CALLDIRECTION_IN;
  2190. SIPController.sipCall.callTime_T7 = new Date();//offerred timer
  2191. //parse message + construct local and remote sdp +negotiate codec
  2192. if (true == SIPController.sipCall.constructHeaders(strMessage, strRemoteIP, strRemotePort)) {
  2193. Log.e(TAG, "[INVITEParser] ============ SEULKI 9 ============");
  2194. // response trying
  2195. sendProceeding(strRemoteIP, strRemotePort);
  2196. updateDialerStatus("전화가 왔습니다.", false);
  2197. dialerNotifyIncomingCall(SIPController.sipCall.dnis, SIPController.sipCall.dnis + "@" + SIPController.sipCall.remoteIp + ":" + SIPController.sipCall.remotePort);
  2198. } else {
  2199. Log.e(TAG, "[INVITEParser] ============ SEULKI 10 ============");
  2200. rejectCall(strMessage, 480, strRemoteIP, strRemotePort);
  2201. updateDialerStatus("전화를 종료했습니다.", false);
  2202. return;
  2203. }
  2204. } else {
  2205. Log.e(TAG, "[INVITEParser] ============ SEULKI 11 ============");
  2206. rejectCall(strMessage, 480, strRemoteIP, strRemotePort);
  2207. return;
  2208. }
  2209. if (BSSVideo.bProgressvideooffer == true || SIPController.forward.bForward == true) {
  2210. Log.e(TAG, "[INVITEParser] ============ SEULKI 12 ============");
  2211. //KSJ 2443 1세대 버전 호환을 위해 주석
  2212. //sendProgressingwithbody(strRemoteIP, strRemotePort);
  2213. } else {
  2214. Log.e(TAG, "[INVITEParser] ============ SEULKI 13 ============");
  2215. sendProgressing(strRemoteIP, strRemotePort);
  2216. }
  2217. } else {
  2218. Log.e(TAG, "[INVITEParser] ============ SEULKI 14 ============");
  2219. rejectCall(strMessage, 404, strRemoteIP, strRemotePort);
  2220. return;
  2221. }
  2222. }
  2223. }
  2224. } else {
  2225. // response 480
  2226. // no sip call handle
  2227. // response only
  2228. Log.e(TAG, "[INVITEParser] ============ SEULKI 15 ============");
  2229. rejectCall(strMessage, 480, strRemoteIP, strRemotePort);
  2230. }
  2231. } else if (nMSGType == SIPStack.SIP_MSGTYPE_RESPONSE) {
  2232. if (true == cmcore.INVITEParser_action_0(SIPController.sipCall, strMessage)) {
  2233. SIPHeader sipHeader = null;
  2234. sipHeader = new SIPHeader(strMessage, SIPStack.SIP_HEADERTYPE_TO);
  2235. if (sipHeader != null) {
  2236. SIPController.sipCall.toH = sipHeader.header;
  2237. SIPController.sipCall.toTag = sipHeader.getTag();
  2238. }
  2239. sipHeader = new SIPHeader(strMessage, SIPStack.SIP_HEADERTYPE_CSEQ);
  2240. if (SIPController.sipCall.callMode == SIPStack.SIP_CALLMODE_HOLD) {
  2241. UPDATEParser(strMessage, nMSGType, strRemoteIP, strRemotePort);
  2242. return;
  2243. }
  2244. SIPController.sipCall.remoteIp = strRemoteIP;
  2245. SIPController.sipCall.remotePort = strRemotePort;
  2246. if ((SIPController.sipCall.responseCode >= 200) && (sipHeader != null) && (sipHeader.flag == true)) {
  2247. SIPController.sipCall.CSEQ_NUMBER = sipHeader.callSequenceNumber();
  2248. }
  2249. if (SIPController.sipCall.responseCode == 100) {
  2250. // trying
  2251. SIPController.sipCall.callState = SIPStack.SIP_CALLSTATE_PROCEEDING;
  2252. SIPController.sipCall.callTime_T1 = new Date();
  2253. // Phone status set
  2254. // SERVICE MESSAGE NEEDED
  2255. updateDialerStatus("Call proceeding.", false);
  2256. } else if ((SIPController.sipCall.responseCode >= 180) && (SIPController.sipCall.responseCode <= 183)) {
  2257. // progressing
  2258. // SERVICE MESSAGE NEEDED
  2259. dialerNotifyRingbackTone(true);
  2260. // Phone status set
  2261. // SERVICE MESSAGE NEEDED
  2262. updateDialerStatus("Call progressing.", false);
  2263. SIPController.sipCall.callState = SIPStack.SIP_CALLSTATE_PROGRESSING;
  2264. SIPController.sipCall.callTime_T2 = new Date();
  2265. if (true == SIPController.sipCall.parseRemoteSdp(strMessage)) {
  2266. if ((SIPController.sipCall.sdp != null) && (SIPController.sipCall.sdp.flag == true)) {
  2267. SIPController.sipCall.negotiateAudioCodec();
  2268. }
  2269. if ((SIPController.sipCall.remoteSdp != null) && (SIPController.sipCall.remoteSdp.flag == true) && (SIPController.audioRTPManager != null)) {
  2270. if ((SIPController.sipCall.remoteSdp.audioM != null) && (SIPController.sipCall.remoteSdp.audioM.flag == true)) {
  2271. if (SIPController.audioRTPManager != null) {
  2272. SIPController.audioRTPManager.setRemoteMediaInfo(SIPController.sipCall.remoteSdp.audioM.commonCodec, SIPController.sipCall.remoteSdp.audioM.mediaIp, SIPController.sipCall.remoteSdp.audioM.mediaPort);
  2273. if ((SIPController.sipCall.sdp != null) && (SIPController.sipCall.sdp.audioM != null) && (SIPController.audioRTPManager.rtpCore.bActive == false)) {
  2274. if ((SIPStack.bDirectCall == true) && (BSSVideo.bProgressvideooffer == true)) {
  2275. // SERVICE MESSAGE NEEDED
  2276. dialerVideoSet(true);
  2277. } else {
  2278. SIPController.audioRTPManager.RTPInit(SIPController.sipCall.sdp.audioM.mediaPort, 3);
  2279. }
  2280. }
  2281. }
  2282. }
  2283. }
  2284. } else {
  2285. // local ringbacktone play
  2286. // SERVICE MESSAGE NEEDED
  2287. dialerNotifyRingbackTone(true);
  2288. }
  2289. } else if ((SIPController.sipCall.responseCode == 200) && (SIPController.sipCall.CSEQ_NUMBER == sipHeader.callSequenceNumber()) &&
  2290. ((SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_INVITING) || (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_PROCEEDING) || (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_PROGRESSING))) {
  2291. // connected
  2292. // Phone status set
  2293. // SERVICE MESSAGE NEEDED
  2294. updateDialerStatus("Connected.", false);
  2295. SIPController.sipCall.callState = SIPStack.SIP_CALLSTATE_REMOTEACCEPTED;
  2296. SIPController.sipCall.callTime_T3 = new Date();
  2297. boolean ret = sendAck(strMessage);
  2298. if (ret == true) {
  2299. SIPController.sipCall.callState = SIPStack.SIP_CALLSTATE_CONNECTED;
  2300. SIPController.sipCall.callTime_T4 = new Date();
  2301. SIPController.sipCall.callTime_T40 = new Date();
  2302. SIPSound.resetBufferInfo();
  2303. // SERVICE MESSAGE NEEDED
  2304. dialerNotifyCallConnected(SIPController.sipCall.dnis, SIPController.sipCall.dnis + "@" + SIPController.sipCall.remoteIp + ":" + SIPController.sipCall.remotePort);
  2305. }
  2306. if (true == SIPController.sipCall.parseRemoteSdp(strMessage)) {
  2307. if ((SIPController.sipCall.sdp != null) && (SIPController.sipCall.sdp.flag == true)) {
  2308. SIPController.sipCall.negotiateAudioCodec();
  2309. }
  2310. if ((SIPController.sipCall.remoteSdp != null) && (SIPController.sipCall.remoteSdp.flag == true) && (SIPController.audioRTPManager != null)) {
  2311. if ((SIPController.sipCall.remoteSdp.audioM != null) && (SIPController.sipCall.remoteSdp.audioM.flag == true)) {
  2312. if (SIPController.audioRTPManager != null) {
  2313. SIPController.audioRTPManager.setRemoteMediaInfo(SIPController.sipCall.remoteSdp.audioM.commonCodec, SIPController.sipCall.remoteSdp.audioM.mediaIp, SIPController.sipCall.remoteSdp.audioM.mediaPort);
  2314. if ((SIPController.sipCall.sdp != null) && (SIPController.sipCall.sdp.audioM != null) && (SIPController.audioRTPManager.rtpCore.bActive == false)) {
  2315. if (SIPStack.bDirectCall == true) {
  2316. if (SIPController.bMobileCall) SIPController.audioRTPManager.RTPRemoteCallInit(SIPController.sipCall.sdp.audioM.mediaPort);
  2317. else SIPController.audioRTPManager.RTPInit(SIPController.sipCall.sdp.audioM.mediaPort, 4);
  2318. // SIPController.audioRTPManager.RTPInit(SIPController.sipCall.sdp.audioM.mediaPort, 4);
  2319. // SERVICE MESSAGE NEEDED
  2320. dialerVideoSet(true);
  2321. } else {
  2322. SIPController.audioRTPManager.RTPInit(SIPController.sipCall.sdp.audioM.mediaPort, 5);
  2323. }
  2324. }
  2325. }
  2326. }
  2327. }
  2328. }
  2329. } else if ((SIPController.sipCall.responseCode == 401) && ((SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_INVITING) ||
  2330. (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_PROCEEDING) || (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_PROGRESSING))) {
  2331. // Athenticate
  2332. // Phone status set
  2333. // SERVICE MESSAGE NEEDED
  2334. updateDialerStatus("Call Unauthorized(401).", false);
  2335. SIPController.sipCall.callState = SIPStack.SIP_CALLSTATE_UNAUTHORIZED;
  2336. SIPController.sipCall.authorizationACKH = "";
  2337. sendFinalAck(strMessage);
  2338. if (reactionForWWWAUTHENTICATE(strMessage) == false) {
  2339. if (SIPController.audioRTPManager != null)
  2340. SIPController.audioRTPManager.RTPEnd(17);
  2341. if (SIPStack.bDirectCall == true) {
  2342. // SERVICE MESSAGE NEEDED
  2343. dialerVideoSet(false);
  2344. }
  2345. dialerNotifyCallFail(SIPController.sipCall.responseCode, SIPController.sipCall.remoteIp, makeSIPID(SIPController.sipCall.remoteIp));
  2346. //SERVICE MESSAGE NEEDED
  2347. dialerNotifyCallEnd("Call Unauthorized(401).", SIPController.sipCall.dnis, SIPController.sipCall.dnis + "@" + SIPController.sipCall.remoteIp + ":" + SIPController.sipCall.remotePort, false);
  2348. SIPController.sipCall.resetCall();
  2349. }
  2350. } else if ((SIPController.sipCall.responseCode == 407) && ((SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_INVITING) ||
  2351. (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_PROCEEDING) || (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_PROGRESSING))) {
  2352. // Proxy-Athenticate
  2353. // Phone status set
  2354. // SERVICE MESSAGE NEEDED
  2355. updateDialerStatus("Call Unauthorized(407).", false);
  2356. SIPController.sipCall.callState = SIPStack.SIP_CALLSTATE_UNAUTHORIZED;
  2357. SIPController.sipCall.authorizationACKH = "";
  2358. sendFinalAck(strMessage);
  2359. if (reactionForPROXYAUTHENTICATE(strMessage) == false) {
  2360. if (SIPController.audioRTPManager != null)
  2361. SIPController.audioRTPManager.RTPEnd(18);
  2362. if (SIPStack.bDirectCall == true) {
  2363. //SERVICE MESSAGE NEEDED
  2364. dialerVideoSet(false);
  2365. }
  2366. dialerNotifyCallFail(SIPController.sipCall.responseCode, SIPController.sipCall.remoteIp, makeSIPID(SIPController.sipCall.remoteIp));
  2367. // SERVICE MESSAGE NEEDED
  2368. dialerNotifyCallEnd("Call Unauthorized(407).", SIPController.sipCall.dnis, SIPController.sipCall.dnis + "@" + SIPController.sipCall.remoteIp + ":" + SIPController.sipCall.remotePort, false);
  2369. SIPController.sipCall.resetCall();
  2370. }
  2371. } else if ((SIPController.sipCall.responseCode == 302) && ((SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_INVITING) ||
  2372. (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_PROCEEDING) ||
  2373. (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_PROGRESSING))) {
  2374. // terminating
  2375. // SERVICE MESSAGE NEEDED
  2376. LOG_INFO("[INVITEParser] BSSVideo.HNS_SERVICE_RECEIVER_SELECTED [" + BSSVideo.HNS_SERVICE_RECEIVER_SELECTED + "]");
  2377. LOG_INFO("[INVITEParser] SIPController.sipCall.remoteIp : " + SIPController.sipCall.remoteIp);
  2378. LOG_INFO("[INVITEParser] SIPController.sipCall.number : " + SIPController.sipCall.number);
  2379. LOG_INFO("[INVITEParser] SIPController.sipCall.cid : " + SIPController.sipCall.cid);
  2380. LOG_INFO("[INVITEParser] SIPController.sipCall.dnis : " + SIPController.sipCall.dnis);
  2381. LOG_INFO("[INVITEParser] SIPController.sipCall.dong_number : " + SIPController.sipCall.dong_number);
  2382. LOG_INFO("[INVITEParser] SIPController.sipCall.ho_number : " + SIPController.sipCall.ho_number);
  2383. LOG_INFO("[INVITEParser] SIPController.sipCall.id : " + SIPController.sipCall.id);
  2384. SIPCONTACTHeader contactHeader = new SIPCONTACTHeader(strMessage);
  2385. updateDialerStatus("Call forwarded./" + contactHeader.getSipuri(), true);
  2386. SIPController.sipCall.callState = SIPStack.SIP_CALLSTATE_REDIRECTED;
  2387. sendRedirectFinalAck(strMessage);
  2388. if (SIPController.audioRTPManager != null)
  2389. SIPController.audioRTPManager.RTPEnd(19);
  2390. if (SIPStack.bDirectCall == true) {
  2391. dialerVideoSet(false);
  2392. }
  2393. SIPController.sipCall.resetCall();
  2394. } else if ((SIPController.sipCall.responseCode >= 300) && ((SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_INVITING) ||
  2395. (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_PROCEEDING) ||
  2396. (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_PROGRESSING) ||
  2397. (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_UNAUTHORIZED) ||
  2398. (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_CANCELLING) ||
  2399. (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_RECANCELLING) ||
  2400. (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_CANCELREMOTEACCEPTED))) {
  2401. // terminating
  2402. // Phone status set
  2403. // SERVICE MESSAGE NEEDED
  2404. updateDialerStatus("Call rejected by remoter.", true);
  2405. SIPController.sipCall.callState = SIPStack.SIP_CALLSTATE_TERMINATING;
  2406. sendFinalAck(strMessage);
  2407. if (SIPController.audioRTPManager != null)
  2408. SIPController.audioRTPManager.RTPEnd(20);
  2409. if (SIPStack.bDirectCall == true) {
  2410. // SERVICE MESSAGE NEEDED
  2411. dialerVideoSet(false);
  2412. }
  2413. dialerNotifyCallFail(SIPController.sipCall.responseCode, SIPController.sipCall.remoteIp, makeSIPID(SIPController.sipCall.remoteIp));
  2414. // SERVICE MESSAGE NEEDED
  2415. dialerNotifyCallEnd("Call rejected by remoter.", SIPController.sipCall.dnis, SIPController.sipCall.dnis + "@" + SIPController.sipCall.remoteIp + ":" + SIPController.sipCall.remotePort, false);
  2416. SIPController.sipCall.resetCall();
  2417. } else {
  2418. }
  2419. } else {
  2420. }
  2421. } else {
  2422. }
  2423. } catch (RuntimeException re) {
  2424. LogUtil.errorLogInfo("", TAG, re);
  2425. } catch (Exception e) {
  2426. Log.e(TAG, "[Exception] INVITEParser(String message, int msgType, String remoteIp, int remotePort)");
  2427. //e.printStackTrace();
  2428. LogUtil.errorLogInfo("", TAG, e);
  2429. }
  2430. }
  2431. public void ACKParser(String message, int msgType, String remoteIp, int remotePort) {
  2432. boolean bValid = false;
  2433. if (SIPController.sipCall != null && SIPController.sipCall.flag == true) {
  2434. bValid = SIPController.sipCall.isCurrentCall(message);
  2435. }
  2436. if (bValid == true) {
  2437. if (msgType == SIPStack.SIP_MSGTYPE_REQUEST && SIPController.sipCall.flag == true && SIPController.sipCall.callMode == SIPStack.SIP_CALLMODE_HOLD) {
  2438. if (true == cmcore.ACKParser_action_0(SIPController.sipCall, message)) {
  2439. SIPSound.resetBufferInfo();
  2440. // SERVICE MESSAGE NEEDED
  2441. dialerNotifyCallConnected(SIPController.sipCall.dnis, SIPController.sipCall.dnis + "@" + SIPController.sipCall.remoteIp + ":" + SIPController.sipCall.remotePort);
  2442. }
  2443. } else if (msgType == SIPStack.SIP_MSGTYPE_REQUEST && SIPController.sipCall.flag == true && SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_ACCEPTED) {
  2444. if (true == cmcore.ACKParser_action_1(SIPController.sipCall, message)) {
  2445. // SERVICE MESSAGE NEEDED
  2446. updateDialerStatus("Connected.", false);
  2447. SIPSound.resetBufferInfo();
  2448. // SERVICE MESSAGE NEEDED
  2449. dialerNotifyCallConnected(SIPController.sipCall.dnis, SIPController.sipCall.dnis + "@" + SIPController.sipCall.remoteIp + ":" + SIPController.sipCall.remotePort);
  2450. }
  2451. } else if (msgType == SIPStack.SIP_MSGTYPE_REQUEST && SIPController.sipCall.flag == true && (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_CANCELLED ||
  2452. SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_TERMINATING)) {
  2453. //Log.i(TAG, "ACK arrived.");
  2454. if (true == cmcore.ACKParser_action_2(SIPController.sipCall, message)) {
  2455. if (SIPController.audioRTPManager != null)
  2456. SIPController.audioRTPManager.RTPEnd(21);
  2457. if (SIPStack.bDirectCall == true) {
  2458. // SERVICE MESSAGE NEEDED
  2459. dialerVideoSet(false);
  2460. }
  2461. // SERVICE MESSAGE NEEDED
  2462. dialerNotifyCallEnd("", SIPController.sipCall.dnis, SIPController.sipCall.dnis + "@" + SIPController.sipCall.remoteIp + ":" + SIPController.sipCall.remotePort, false);
  2463. SIPController.sipCall.resetCall();
  2464. }
  2465. }
  2466. return;
  2467. }
  2468. if (SIPController.pendingCall != null && SIPController.pendingCall.flag == true) {
  2469. bValid = SIPController.pendingCall.isCurrentCall(message);
  2470. }
  2471. if (bValid == true) {
  2472. if (msgType == SIPStack.SIP_MSGTYPE_REQUEST && SIPController.pendingCall.flag == true && (SIPController.pendingCall.callState == SIPStack.SIP_CALLSTATE_CANCELLED ||
  2473. SIPController.pendingCall.callState == SIPStack.SIP_CALLSTATE_TERMINATING)) {
  2474. SIPController.pendingCall.resetCall();
  2475. }
  2476. }
  2477. return;
  2478. }
  2479. public void CANCELParser(String message, int msgType, String remoteIp, int remotePort) {
  2480. boolean bValid = false;
  2481. if (SIPController.sipCall != null && SIPController.sipCall.flag == true) {
  2482. bValid = SIPController.sipCall.isCurrentCall(message);
  2483. }
  2484. if (bValid == true) {
  2485. if (msgType == SIPStack.SIP_MSGTYPE_REQUEST && SIPController.sipCall.flag == true && SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_OFFERRED) {
  2486. if (true == cmcore.CANCELParser_action_0(SIPController.sipCall, message)) {
  2487. acceptCancelRequest(message, remoteIp, remotePort);
  2488. if (SIPController.sipCall.remoteSdp != null && SIPController.sipCall.remoteSdp.flag == true && SIPController.audioRTPManager != null) {
  2489. if (SIPController.sipCall.remoteSdp.audioM != null && SIPController.sipCall.remoteSdp.audioM.flag == true) {
  2490. if (SIPController.sipCall.sdp != null && SIPController.sipCall.sdp.audioM != null && SIPController.audioRTPManager != null) {
  2491. SIPController.audioRTPManager.RTPEnd(22);
  2492. if (SIPStack.bDirectCall == true) {
  2493. // SERVICE MESSAGE NEEDED
  2494. dialerVideoSet(false);
  2495. }
  2496. }
  2497. }
  2498. }
  2499. rejectCall(487);
  2500. }
  2501. } else if (msgType == SIPStack.SIP_MSGTYPE_RESPONSE && SIPController.sipCall.flag == true && (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_CANCELLING ||
  2502. SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_RECANCELLING)) {
  2503. if (true == cmcore.CANCELParser_action_1(SIPController.sipCall, message)) {
  2504. SIPController.sipCall.callState = SIPStack.SIP_CALLSTATE_CANCELREMOTEACCEPTED;
  2505. // none action
  2506. }
  2507. }
  2508. return;
  2509. }
  2510. // Multicall
  2511. if (SIPController.pendingCall != null && SIPController.pendingCall.flag == true) {
  2512. bValid = SIPController.pendingCall.isCurrentCall(message);
  2513. }
  2514. if (bValid == true) {
  2515. if (msgType == SIPStack.SIP_MSGTYPE_REQUEST && SIPController.pendingCall.flag == true && SIPController.pendingCall.callState == SIPStack.SIP_CALLSTATE_OFFERRED) {
  2516. if (true == cmcore.CANCELParser_action_0(SIPController.pendingCall, message)) {
  2517. acceptPendingCancelRequest(message, remoteIp, remotePort);
  2518. rejectPendingCall(487);
  2519. dialerNotifyMulticallCancel(getSIPIDfromMessage(message), remoteIp);
  2520. }
  2521. }
  2522. return;
  2523. }
  2524. }
  2525. private String getSIPIDfromMessage(String strMessage) {
  2526. try {
  2527. String[] strParsed_01 = strMessage.split("Contact: <sip:");
  2528. String[] strParsed_02 = strParsed_01[1].split("@");
  2529. return strParsed_02[0];
  2530. } catch (RuntimeException re) {
  2531. LogUtil.errorLogInfo("", TAG, re);
  2532. return null;
  2533. } catch (Exception e) {
  2534. Log.e(TAG, "[Exception] getSIPIDfromMessage(String strMessage)");
  2535. //e.printStackTrace();
  2536. LogUtil.errorLogInfo("", TAG, e);
  2537. return null;
  2538. }
  2539. }
  2540. public void BYEParser(String message, int msgType, String remoteIp, int remotePort) {
  2541. try {
  2542. Log.i(TAG, "[BYEParser] msgType [" + msgType + "], remoteIp [" + remoteIp + "], remotePort [" + remotePort + "]");
  2543. if (msgType == SIPStack.SIP_MSGTYPE_REQUEST && SIPController.sipCall.flag == true && (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_ACCEPTED ||
  2544. SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_REMOTEACCEPTED ||
  2545. SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_CONNECTED)) {
  2546. if (true == cmcore.action_bye_0(SIPController.sipCall, message)) {
  2547. if (SIPController.audioRTPManager != null)
  2548. SIPController.audioRTPManager.RTPEnd(23);
  2549. if (SIPStack.bDirectCall == true) {
  2550. // SERVICE MESSAGE NEEDED
  2551. dialerVideoSet(false);
  2552. }
  2553. int duration = 0;
  2554. Date currentTime = new Date();
  2555. if (SIPController.sipCall.callTime_T4 != null) {
  2556. duration = (int) (currentTime.getTime() - SIPController.sipCall.callTime_T4.getTime()) / 1000;
  2557. if (SIPController.sipCall.callDirection == SIPStack.SIP_CALLDIRECTION_IN)
  2558. duration -= 1;
  2559. if (duration < 0) duration = 0;
  2560. }
  2561. sendByeResponse(message, remoteIp, remotePort);
  2562. Log.d(TAG, "[BYEParser] SIPController.sipCall.dnis [" + SIPController.sipCall.dnis + "], SIPController.sipCall.remoteIp [" + SIPController.sipCall.remoteIp + "], SIPController.sipCall.remotePort [" + SIPController.sipCall.remotePort + "]");
  2563. dialerNotifyCallFail(700, remoteIp, makeSIPID(remoteIp));
  2564. //SERVICE MESSAGE NEEDED
  2565. updateDialerStatus("상대가 전화를 끊었습니다.", false);
  2566. //SERVICE MESSAGE NEEDED
  2567. dialerNotifyCallEnd("상대가 전화를 끊었습니다.", makeSIPID(remoteIp), makeSIPID(remoteIp) + "@" + remoteIp + ":" + remotePort, false);
  2568. }
  2569. } else if (msgType == SIPStack.SIP_MSGTYPE_RESPONSE && SIPController.sipCall.flag == true && SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_DISCONNECTING) {
  2570. if (true == cmcore.action_bye_1(SIPController.sipCall, message)) {
  2571. if (SIPController.audioRTPManager != null)
  2572. SIPController.audioRTPManager.RTPEnd(24);
  2573. if (SIPStack.bDirectCall == true) {
  2574. // SERVICE MESSAGE NEEDED
  2575. dialerVideoSet(false);
  2576. }
  2577. // SERVICE MESSAGE NEEDED
  2578. updateDialerStatus("Ready.", true);
  2579. // SERVICE MESSAGE NEEDED
  2580. dialerNotifyCallEnd("Ready.", SIPController.sipCall.dnis, SIPController.sipCall.dnis + "@" + SIPController.sipCall.remoteIp + ":" + SIPController.sipCall.remotePort, false);
  2581. }
  2582. }
  2583. } catch (RuntimeException re) {
  2584. LogUtil.errorLogInfo("", TAG, re);
  2585. } catch (Exception e) {
  2586. Log.e(TAG, "[Exception] BYEParser(String message, int msgType, String remoteIp, int remotePort)");
  2587. //e.printStackTrace();
  2588. LogUtil.errorLogInfo("", TAG, e);
  2589. }
  2590. }
  2591. public int SIPParser(String strMessage, int nMSGType, int nMethodType, String strRemoteIP, int strRemotePort) {
  2592. try {
  2593. if (bPrintSIPMsgIO) {
  2594. Log.i(TAG, "[SIPParser] nMSGType [" + nMSGType + "], nMethodType [" + nMethodType + "], strRemoteIP [" + strRemoteIP + "], strRemotePort [" + strRemotePort + "]");
  2595. printSIPMessage(MESSAGE.RECEIVE, strMessage);
  2596. }
  2597. if (nMethodType == SIPStack.SIP_METHODTYPE_INVITE) {
  2598. // INVITE MESSAGE PROCESSING
  2599. INVITEParser(strMessage, nMSGType, strRemoteIP, strRemotePort);
  2600. } else if (nMethodType == SIPStack.SIP_METHODTYPE_ACK) {
  2601. // ACK MESSAGE PROCESSING
  2602. ACKParser(strMessage, nMSGType, strRemoteIP, strRemotePort);
  2603. } else if (nMethodType == SIPStack.SIP_METHODTYPE_OPTIONS) {
  2604. // OPTIONS MESSAGE PROCESSING
  2605. if (nMSGType == SIPStack.SIP_MSGTYPE_REQUEST) {
  2606. sendOptionsResponse(strMessage, strRemoteIP, strRemotePort, 200);
  2607. }
  2608. } else if (nMethodType == SIPStack.SIP_METHODTYPE_INFO) {
  2609. // INFO MESSAGE PROCESSING
  2610. if (true == cmcore.action_info_0(SIPController.sipCall, strMessage, nMSGType)) {
  2611. sendInfoResponse(strMessage, strRemoteIP, strRemotePort, 200);
  2612. }
  2613. } else if (nMethodType == SIPStack.SIP_METHODTYPE_CANCEL) {
  2614. // CANCEL MESSAGE PROCESSING
  2615. CANCELParser(strMessage, nMSGType, strRemoteIP, strRemotePort);
  2616. } else if (nMethodType == SIPStack.SIP_METHODTYPE_BYE) {
  2617. // BYE MESSAGE PROCESSING
  2618. BYEParser(strMessage, nMSGType, strRemoteIP, strRemotePort);
  2619. } else if (nMethodType == SIPStack.SIP_METHODTYPE_REFER) {
  2620. // REFER
  2621. // IF NEED,CODING NEEDED
  2622. } else if (nMethodType == SIPStack.SIP_METHODTYPE_NOTIFY) {
  2623. // NOTIFY
  2624. // IF NEED,CODING NEEDED
  2625. } else if (nMethodType == SIPStack.SIP_METHODTYPE_MESSAGE) {
  2626. // MESSAGE
  2627. if (nMSGType == SIPStack.SIP_MSGTYPE_REQUEST) {
  2628. sendMessageResponse(strMessage, strRemoteIP, strRemotePort, 200);
  2629. }
  2630. } else if (nMethodType == SIPStack.SIP_METHODTYPE_SUBSCRIBE) {
  2631. // SUBSCRIBE
  2632. // IF NEED,CODING NEEDED
  2633. } else if (nMethodType == SIPStack.SIP_METHODTYPE_PRACK) {
  2634. // PRACK
  2635. // IF NEED,CODING NEEDED
  2636. }
  2637. return 0;
  2638. } catch (RuntimeException re) {
  2639. LogUtil.errorLogInfo("", TAG, re);
  2640. return -1;
  2641. } catch (Exception e) {
  2642. Log.e(TAG, "SIPParser(String strMessage, int nMSGType, int nMethodType, String strRemoteIP, int strRemotePort)");
  2643. //e.printStackTrace();
  2644. LogUtil.errorLogInfo("", TAG, e);
  2645. return -1;
  2646. }
  2647. }
  2648. public void registRTPManager(RTPManager rtpmanager, int mediaType) {
  2649. if (mediaType == SIPStack.SIP_MEDIATYPE_AUDIO) {
  2650. SIPController.audioRTPManager = rtpmanager;
  2651. if (SIPStack.SIP_MESSAGE_DEBUG == true)
  2652. Log.i(TAG, "AUDIO RTPMANAGER SET Notified to RegisterManager.");
  2653. }
  2654. }
  2655. public boolean sendRegister() {
  2656. if (cmcore.makeRegister() == true) {
  2657. if (cmcore.message.length() > 0 && mSIPSignalReceiver != null) {
  2658. byte[] buffer = cmcore.message.getBytes();
  2659. if (cmcore.message.length() > 0) {
  2660. if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, cmcore.message);
  2661. int repeatSendCount = 0;
  2662. while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) {
  2663. if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(cmcore.serverIp, cmcore.serverPort, buffer, buffer.length)) {
  2664. break;
  2665. }
  2666. repeatSendCount++;
  2667. }
  2668. cmcore.regTime = new Date();
  2669. }
  2670. }
  2671. return true;
  2672. }
  2673. return false;
  2674. }
  2675. public boolean sendUNRegister() {
  2676. if (cmcore.makeUNRegister() == true) {
  2677. if (cmcore.message.length() > 0 && mSIPSignalReceiver != null) {
  2678. byte[] buffer = cmcore.message.getBytes();
  2679. if (cmcore.message.length() > 0) {
  2680. if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, cmcore.message);
  2681. int repeatSendCount = 0;
  2682. while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) {
  2683. if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(cmcore.serverIp, cmcore.serverPort, buffer, buffer.length)) {
  2684. break;
  2685. }
  2686. repeatSendCount++;
  2687. }
  2688. cmcore.regTime = new Date();
  2689. }
  2690. }
  2691. return true;
  2692. }
  2693. return false;
  2694. }
  2695. public boolean sendUNRegister(String contactip, int contactport) {
  2696. if (cmcore.makeUNRegister(contactip, contactport) == true) {
  2697. if (cmcore.message.length() > 0 && mSIPSignalReceiver != null) {
  2698. byte[] buffer = cmcore.message.getBytes();
  2699. if (cmcore.message.length() > 0) {
  2700. if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, cmcore.message);
  2701. int repeatSendCount = 0;
  2702. while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) {
  2703. if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(cmcore.serverIp, cmcore.serverPort, buffer, buffer.length)) {
  2704. break;
  2705. }
  2706. repeatSendCount++;
  2707. }
  2708. cmcore.regTime = new Date();
  2709. }
  2710. }
  2711. return true;
  2712. }
  2713. return false;
  2714. }
  2715. public boolean decideRegister() {
  2716. Date currentDate = new Date();
  2717. int seconds = (int) (currentDate.getTime() - cmcore.regTime.getTime()) / 1000;
  2718. if (seconds > cmcore.expiresSeconds - 10) return true;
  2719. else return false;
  2720. }
  2721. public boolean callActivate(String number) {
  2722. if (SIPController.sipCall == null) return false;
  2723. String dial = "";
  2724. if (SIPController.sipCall.flag == false) {
  2725. // Phone status set
  2726. // SERVICE MESSAGE NEEDED
  2727. updateDialerStatus("Calling to " + number, false);
  2728. if (number.length() > 32) {
  2729. dial = number.substring(0, 32);
  2730. } else {
  2731. dial = new String(number);
  2732. }
  2733. return callMake(dial);
  2734. } else if (SIPController.sipCall.callDirection == SIPStack.SIP_CALLDIRECTION_IN && SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_OFFERRED) {
  2735. // Phone status set
  2736. // SERVICE MESSAGE NEEDED
  2737. updateDialerStatus("Incoming call accept.", false);
  2738. return sendAccept();
  2739. }
  2740. return false;
  2741. }
  2742. public boolean directcallActivate(String strNumber, boolean bMobile) {
  2743. try {
  2744. LOG_DEBUG("[directcallActivate] strNumber [" + strNumber + "], bMobile [" + bMobile + "]");
  2745. if (SIPController.sipCall == null) {
  2746. LOG("[directcallActivate] SIPController.sipCall is null!!");
  2747. return false;
  2748. }
  2749. String dial = "";
  2750. LOG_DEBUG("[directcallActivate] SIPController.sipCall.flag = " + SIPController.sipCall.flag);
  2751. if (SIPController.sipCall.flag == false) {
  2752. // Phone status set
  2753. // SERVICE MESSAGE NEEDED
  2754. updateDialerStatus("Calling to " + strNumber, false);
  2755. if (strNumber.length() > 32) {
  2756. dial = strNumber.substring(0, 32);
  2757. } else {
  2758. dial = new String(strNumber);
  2759. }
  2760. return directcallMake(dial);
  2761. } else if (SIPController.sipCall.callDirection == SIPStack.SIP_CALLDIRECTION_IN && SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_OFFERRED) {
  2762. // Phone status set
  2763. // SERVICE MESSAGE NEEDED
  2764. updateDialerStatus("Incoming call accept.", false);
  2765. return directsendAccept(bMobile);
  2766. }
  2767. return false;
  2768. } catch (RuntimeException re) {
  2769. LogUtil.errorLogInfo("", TAG, re);
  2770. return false;
  2771. } catch (Exception e) {
  2772. Log.e(TAG, "[Exception] directcallActivate(String strNumber)");
  2773. //e.printStackTrace();
  2774. LogUtil.errorLogInfo("", TAG, e);
  2775. return false;
  2776. }
  2777. }
  2778. public boolean callMake(String number) {
  2779. if (cmcore.regState != SIPStack.SIP_REGSTATE_REGISTERED) {
  2780. // SERVICE MESSAGE NEEDED
  2781. dialerNotifyCallEnd("Not registered.", "", "", true);
  2782. return false;
  2783. }
  2784. if (true == cmcore.makeCallMake(SIPController.sipCall, number)) {
  2785. if (SIPController.sipCall.message.length() > 0 && mSIPSignalReceiver != null) {
  2786. byte[] buffer = SIPController.sipCall.message.getBytes();
  2787. if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, SIPController.sipCall.message);
  2788. int repeatSendCount = 0;
  2789. while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) {
  2790. if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort, buffer, buffer.length)) {
  2791. break;
  2792. }
  2793. repeatSendCount++;
  2794. }
  2795. SIPController.sipCall.callTime_T0 = new Date();
  2796. SIPController.sipCall.callTime_T00 = new Date();
  2797. SIPController.sipCall.invitingTimes++;
  2798. return true;
  2799. }
  2800. }
  2801. return false;
  2802. }
  2803. public boolean directcallMake(String number) {
  2804. if (SIPController.sipCall == null || SIPController.sipCall.flag == true) return false;
  2805. if (true == cmcore.makeDirectcallMake(SIPController.sipCall, number)) {
  2806. if (SIPController.sipCall.message.length() > 0 && mSIPSignalReceiver != null) {
  2807. byte[] buffer = SIPController.sipCall.message.getBytes();
  2808. if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, SIPController.sipCall.message);
  2809. int repeatSendCount = 0;
  2810. while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) {
  2811. if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort, buffer, buffer.length)) {
  2812. // INVITING
  2813. break;
  2814. }
  2815. repeatSendCount++;
  2816. }
  2817. SIPController.sipCall.callTime_T0 = new Date();
  2818. SIPController.sipCall.callTime_T00 = new Date();
  2819. SIPController.sipCall.invitingTimes++;
  2820. }
  2821. return true;
  2822. }
  2823. return false;
  2824. }
  2825. public boolean sendReInvite() {
  2826. if (true == cmcore.makeSendReInvite(SIPController.sipCall)) {
  2827. if (SIPController.sipCall.message.length() > 0 && mSIPSignalReceiver != null) {
  2828. byte[] buffer = SIPController.sipCall.message.getBytes();
  2829. if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, SIPController.sipCall.message);
  2830. int repeatSendCount = 0;
  2831. while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) {
  2832. if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort, buffer, buffer.length)) {
  2833. break;
  2834. }
  2835. repeatSendCount++;
  2836. }
  2837. SIPController.sipCall.callTime_T00 = new Date();
  2838. SIPController.sipCall.invitingTimes++;
  2839. return true;
  2840. }
  2841. }
  2842. return false;
  2843. }
  2844. public boolean sendRepeatInvite() {
  2845. if (SIPController.sipCall == null || SIPController.sipCall.flag == false) return false;
  2846. if (SIPController.sipCall.message == null || SIPController.sipCall.message.length() == 0)
  2847. return false;
  2848. if (SIPController.sipCall.message.length() > 0 && mSIPSignalReceiver != null) {
  2849. byte[] buffer = SIPController.sipCall.message.getBytes();
  2850. if (SIPController.sipCall.message.length() > 0) {
  2851. if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, SIPController.sipCall.message);
  2852. int repeatSendCount = 0;
  2853. while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) {
  2854. if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort, buffer, buffer.length)) {
  2855. break;
  2856. }
  2857. repeatSendCount++;
  2858. }
  2859. SIPController.sipCall.callTime_T00 = new Date();
  2860. SIPController.sipCall.invitingTimes++;
  2861. }
  2862. }
  2863. return true;
  2864. }
  2865. public boolean sendRedirectCall(String message) {
  2866. if (true == cmcore.makeSendRedirectCall(SIPController.sipCall, message)) {
  2867. if (SIPController.sipCall.message.length() > 0 && mSIPSignalReceiver != null) {
  2868. byte[] buffer = new byte[SIPController.sipCall.message.length()];
  2869. SIPController.sipCall.message.getBytes(0, SIPController.sipCall.message.length(), buffer, 0);
  2870. if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, SIPController.sipCall.message);
  2871. int repeatSendCount = 0;
  2872. while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) {
  2873. if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort, buffer, buffer.length)) {
  2874. break;
  2875. }
  2876. repeatSendCount++;
  2877. }
  2878. SIPController.sipCall.callState = SIPStack.SIP_CALLSTATE_INVITING;
  2879. SIPController.sipCall.callDirection = SIPStack.SIP_CALLDIRECTION_OUT;
  2880. SIPController.sipCall.callTime_T0 = new Date();
  2881. SIPController.sipCall.invitingTimes++;
  2882. return true;
  2883. }
  2884. } else {
  2885. SIPController.sipCall.resetCall();
  2886. }
  2887. return false;
  2888. }
  2889. public boolean reactionForWWWAUTHENTICATE(String message) {
  2890. if (true == cmcore.makeReactionForWWWAUTHENTICATE(SIPController.sipCall, message)) {
  2891. if (SIPController.sipCall.message.length() > 0 && mSIPSignalReceiver != null) {
  2892. byte[] buffer = SIPController.sipCall.message.getBytes();
  2893. if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, SIPController.sipCall.message);
  2894. int repeatSendCount = 0;
  2895. while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) {
  2896. if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort, buffer, buffer.length)) {
  2897. mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort, buffer, buffer.length);
  2898. break;
  2899. }
  2900. repeatSendCount++;
  2901. }
  2902. SIPController.sipCall.callTime_T0 = new Date();
  2903. SIPController.sipCall.callTime_T00 = new Date();
  2904. return true;
  2905. }
  2906. }
  2907. return false;
  2908. }
  2909. public boolean reactionForPROXYAUTHENTICATE(String message) {
  2910. if (true == cmcore.makeReactionForPROXYAUTHENTICATE(SIPController.sipCall, message)) {
  2911. if (SIPController.sipCall.message.length() > 0 && mSIPSignalReceiver != null) {
  2912. byte[] buffer = SIPController.sipCall.message.getBytes();
  2913. if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, SIPController.sipCall.message);
  2914. int repeatSendCount = 0;
  2915. while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) {
  2916. if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort, buffer, buffer.length)) {
  2917. mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort, buffer, buffer.length);
  2918. break;
  2919. }
  2920. repeatSendCount++;
  2921. }
  2922. SIPController.sipCall.callTime_T0 = new Date();
  2923. SIPController.sipCall.callTime_T00 = new Date();
  2924. return true;
  2925. }
  2926. }
  2927. return false;
  2928. }
  2929. public boolean sendProceeding(String remoteIp, int remotePort) {
  2930. String sendmessage = cmcore.makeSendProceeding(SIPController.sipCall);
  2931. if (sendmessage.length() > 0 && mSIPSignalReceiver != null) {
  2932. byte[] buffer = sendmessage.getBytes();
  2933. if (sendmessage.length() > 0) {
  2934. if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, sendmessage);
  2935. SIPController.sipCall.callTime_T6 = new Date();
  2936. int repeatSendCount = 0;
  2937. while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) {
  2938. if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(remoteIp, remotePort, buffer, buffer.length)) {
  2939. break;
  2940. }
  2941. repeatSendCount++;
  2942. }
  2943. }
  2944. }
  2945. return true;
  2946. }
  2947. //MultiCall Proceeding
  2948. public boolean sendPendingProceeding(String remoteIp, int remotePort) {
  2949. String sendmessage = cmcore.makeSendProceeding(SIPController.pendingCall);
  2950. if (sendmessage.length() > 0 && mSIPSignalReceiver != null) {
  2951. byte[] buffer = sendmessage.getBytes();
  2952. if (sendmessage.length() > 0) {
  2953. if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, sendmessage);
  2954. SIPController.pendingCall.callTime_T6 = new Date();
  2955. int repeatSendCount = 0;
  2956. while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) {
  2957. if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(remoteIp, remotePort, buffer, buffer.length)) {
  2958. break;
  2959. }
  2960. repeatSendCount++;
  2961. }
  2962. }
  2963. }
  2964. return true;
  2965. }
  2966. public boolean sendProgressing(String remoteIp, int remotePort) {
  2967. if (SIPController.sipCall == null || SIPController.sipCall.flag == false) return false;
  2968. String sendmessage = cmcore.makeSendProgressing(SIPController.sipCall);
  2969. if (sendmessage.length() > 0 && mSIPSignalReceiver != null) {
  2970. byte[] buffer = sendmessage.getBytes();
  2971. if (sendmessage.length() > 0) {
  2972. if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, sendmessage);
  2973. SIPController.sipCall.callTime_T6 = new Date();
  2974. int repeatSendCount = 0;
  2975. while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) {
  2976. if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(remoteIp, remotePort, buffer, buffer.length)) {
  2977. break;
  2978. }
  2979. repeatSendCount++;
  2980. }
  2981. }
  2982. }
  2983. return true;
  2984. }
  2985. //Multicall Progressing
  2986. public boolean sendPendingProgressing(String remoteIp, int remotePort) {
  2987. if (SIPController.pendingCall == null || SIPController.pendingCall.flag == false)
  2988. return false;
  2989. String sendmessage = cmcore.makeSendProgressing(SIPController.pendingCall);
  2990. if (sendmessage.length() > 0 && mSIPSignalReceiver != null) {
  2991. byte[] buffer = sendmessage.getBytes();
  2992. if (sendmessage.length() > 0) {
  2993. if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, sendmessage);
  2994. SIPController.pendingCall.callTime_T6 = new Date();
  2995. int repeatSendCount = 0;
  2996. while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) {
  2997. if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(remoteIp, remotePort, buffer, buffer.length)) {
  2998. break;
  2999. }
  3000. repeatSendCount++;
  3001. }
  3002. }
  3003. }
  3004. return true;
  3005. }
  3006. public boolean sendProgressingwithbody(String remoteIp, int remotePort) {
  3007. Log.d(TAG, "[sendProgressingwithbody] remoteIp [" + remoteIp + "], remotePort [" + remotePort + "]");
  3008. if (SIPController.sipCall == null || SIPController.sipCall.flag == false) return false;
  3009. if (SIPController.sipCall.callDirection == SIPStack.SIP_CALLDIRECTION_IN && SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_OFFERRED) {
  3010. String sendmessage = cmcore.makeSendProgressingwithbody(SIPController.sipCall);
  3011. if (sendmessage.length() > 0 && mSIPSignalReceiver != null) {
  3012. byte[] buffer = sendmessage.getBytes();
  3013. if (sendmessage.length() > 0) {
  3014. if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, sendmessage);
  3015. SIPController.sipCall.callTime_T6 = new Date();
  3016. int repeatSendCount = 0;
  3017. while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) {
  3018. if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort, buffer, buffer.length)) {
  3019. break;
  3020. }
  3021. repeatSendCount++;
  3022. }
  3023. if (SIPController.sipCall.remoteSdp != null && SIPController.sipCall.remoteSdp.flag == true && SIPController.audioRTPManager != null) {
  3024. if (SIPController.sipCall.remoteSdp.audioM != null && SIPController.sipCall.remoteSdp.audioM.flag == true) {
  3025. if (SIPController.sipCall.sdp != null && SIPController.sipCall.sdp.audioM != null && SIPController.audioRTPManager != null) {
  3026. SIPController.audioRTPManager.setRemoteMediaInfo(SIPController.sipCall.remoteSdp.audioM.commonCodec, SIPController.sipCall.remoteSdp.audioM.mediaIp, SIPController.sipCall.remoteSdp.audioM.mediaPort);
  3027. if (SIPStack.bDirectCall == true) {
  3028. // SERVICE MESSAGE NEEDED
  3029. dialerVideoSet(true);
  3030. }
  3031. }
  3032. }
  3033. }
  3034. }
  3035. }
  3036. }
  3037. return true;
  3038. }
  3039. public boolean sendProgressingBlackcallwithbody(String remoteIp, int remotePort) {
  3040. if (SIPController.sipCall == null || SIPController.sipCall.flag == false) return false;
  3041. if (SIPController.sipCall.callDirection == SIPStack.SIP_CALLDIRECTION_IN && SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_OFFERRED) {
  3042. String sendmessage = cmcore.makeSendProgressingwithbody(SIPController.sipCall);
  3043. if (sendmessage.length() > 0 && mSIPSignalReceiver != null) {
  3044. byte[] buffer = sendmessage.getBytes();
  3045. if (sendmessage.length() > 0) {
  3046. if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, sendmessage);
  3047. SIPController.sipCall.callTime_T6 = new Date();
  3048. int repeatSendCount = 0;
  3049. while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) {
  3050. if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort, buffer, buffer.length)) {
  3051. break;
  3052. }
  3053. repeatSendCount++;
  3054. }
  3055. if (SIPController.sipCall.remoteSdp != null && SIPController.sipCall.remoteSdp.flag == true && SIPController.audioRTPManager != null) {
  3056. if (SIPController.sipCall.remoteSdp.audioM != null && SIPController.sipCall.remoteSdp.audioM.flag == true) {
  3057. if (SIPController.sipCall.sdp != null && SIPController.sipCall.sdp.audioM != null && SIPController.audioRTPManager != null) {
  3058. SIPController.audioRTPManager.setRemoteMediaInfo(SIPController.sipCall.remoteSdp.audioM.commonCodec, SIPController.sipCall.remoteSdp.audioM.mediaIp, SIPController.sipCall.remoteSdp.audioM.mediaPort);
  3059. //if(SIPStack.bDirectCall==true) {
  3060. //SERVICE MESSAGE NEEDED
  3061. // dialerVideoSet(true);
  3062. //}
  3063. }
  3064. }
  3065. }
  3066. }
  3067. }
  3068. }
  3069. return true;
  3070. }
  3071. public boolean acceptCancelRequest(String strMessage, String strRemoteIP, int strRemotePort) {
  3072. try {
  3073. LOG("[acceptCancelRequest] strMessage [" + strMessage + "], strRemoteIP [" + strRemoteIP + "], strRemotePort [" + strRemotePort + "]");
  3074. String strSendMessage = cmcore.makeAcceptCancelRequest(SIPController.sipCall, strMessage);
  3075. if (strSendMessage.length() > 0 && mSIPSignalReceiver != null) {
  3076. byte[] buffer = strSendMessage.getBytes();
  3077. if (strSendMessage.length() > 0) {
  3078. if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, strMessage);
  3079. SIPController.sipCall.callTime_T8 = new Date();
  3080. int repeatSendCount = 0;
  3081. while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) {
  3082. if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(strRemoteIP, strRemotePort, buffer, buffer.length)) {
  3083. break;
  3084. }
  3085. repeatSendCount++;
  3086. }
  3087. }
  3088. return true;
  3089. }
  3090. return false;
  3091. } catch (RuntimeException re) {
  3092. LogUtil.errorLogInfo("", TAG, re);
  3093. return false;
  3094. } catch (Exception e) {
  3095. Log.e(TAG, "acceptCancelRequest(String strMessage, String strRemoteIP, int strRemotePort)");
  3096. return false;
  3097. }
  3098. }
  3099. public boolean acceptPendingCancelRequest(String message, String remoteIp, int remotePort) {
  3100. String sendmessage = cmcore.makeAcceptCancelRequest(SIPController.pendingCall, message);
  3101. if (sendmessage.length() > 0 && mSIPSignalReceiver != null) {
  3102. byte[] buffer = sendmessage.getBytes();
  3103. if (sendmessage.length() > 0) {
  3104. if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, sendmessage);
  3105. // if (SIPStack.SIP_MESSAGE_DEBUG == true) Log.i(TAG, "SENT\n" + sendmessage);
  3106. SIPController.pendingCall.callTime_T8 = new Date();
  3107. int repeatSendCount = 0;
  3108. while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) {
  3109. if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(remoteIp, remotePort, buffer, buffer.length)) {
  3110. break;
  3111. }
  3112. repeatSendCount++;
  3113. }
  3114. }
  3115. return true;
  3116. }
  3117. return false;
  3118. }
  3119. public boolean sendAccept() {
  3120. Log.d(TAG, "[sendAccept]");
  3121. String sendmessage = cmcore.makeSendAccept(SIPController.sipCall);
  3122. if (sendmessage.length() > 0 && mSIPSignalReceiver != null) {
  3123. byte[] buffer = sendmessage.getBytes();
  3124. if (sendmessage.length() > 0) {
  3125. if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, sendmessage);
  3126. SIPController.sipCall.callTime_T3 = new Date();
  3127. int repeatSendCount = 0;
  3128. while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) {
  3129. if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort, buffer, buffer.length)) {
  3130. break;
  3131. }
  3132. repeatSendCount++;
  3133. }
  3134. SIPController.sipCall.callState = SIPStack.SIP_CALLSTATE_ACCEPTED;
  3135. if (SIPController.sipCall.remoteSdp != null && SIPController.sipCall.remoteSdp.flag == true && SIPController.audioRTPManager != null) {
  3136. if (SIPController.sipCall.remoteSdp.audioM != null && SIPController.sipCall.remoteSdp.audioM.flag == true) {
  3137. if (SIPController.sipCall.sdp != null && SIPController.sipCall.sdp.audioM != null && SIPController.audioRTPManager != null) {
  3138. SIPController.audioRTPManager.setRemoteMediaInfo(SIPController.sipCall.remoteSdp.audioM.commonCodec, SIPController.sipCall.remoteSdp.audioM.mediaIp, SIPController.sipCall.remoteSdp.audioM.mediaPort);
  3139. SIPController.audioRTPManager.RTPInit(SIPController.sipCall.sdp.audioM.mediaPort, 6);
  3140. if (SIPStack.bDirectCall == true) {
  3141. // SERVICE MESSAGE NEEDED
  3142. dialerVideoSet(true);
  3143. }
  3144. }
  3145. }
  3146. }
  3147. }
  3148. return true;
  3149. } else return false;
  3150. }
  3151. public boolean directsendAccept(boolean bMobile) {
  3152. try {
  3153. LOG_INFO("[directsendAccept] bMobile [" + bMobile + "]");
  3154. String sendmessage = cmcore.makeDirectsendAccept(SIPController.sipCall);
  3155. if (sendmessage.length() > 0 && mSIPSignalReceiver != null) {
  3156. byte[] buffer = sendmessage.getBytes();
  3157. if (sendmessage.length() > 0) {
  3158. if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, sendmessage);
  3159. SIPController.sipCall.callTime_T3 = new Date();
  3160. int repeatSendCount = 0;
  3161. while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) {
  3162. if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort, buffer, buffer.length)) {
  3163. break;
  3164. }
  3165. repeatSendCount++;
  3166. }
  3167. SIPController.sipCall.callState = SIPStack.SIP_CALLSTATE_ACCEPTED;
  3168. if (SIPController.sipCall.remoteSdp != null && SIPController.sipCall.remoteSdp.flag == true && SIPController.audioRTPManager != null) {
  3169. if (SIPController.sipCall.remoteSdp.audioM != null && SIPController.sipCall.remoteSdp.audioM.flag == true) {
  3170. if (SIPController.sipCall.sdp != null && SIPController.sipCall.sdp.audioM != null && SIPController.audioRTPManager != null) {
  3171. SIPController.audioRTPManager.setRemoteMediaInfo(SIPController.sipCall.remoteSdp.audioM.commonCodec, SIPController.sipCall.remoteSdp.audioM.mediaIp, SIPController.sipCall.remoteSdp.audioM.mediaPort);
  3172. LOG_INFO("[directsendAccept] SIPController.audioRTPManager.rtpCore.bActive [" + SIPController.audioRTPManager.rtpCore.bActive + "]");
  3173. if (SIPController.audioRTPManager.rtpCore.bActive == false) {
  3174. if (bMobile) SIPController.audioRTPManager.RTPRemoteCallInit(SIPController.sipCall.sdp.audioM.mediaPort);
  3175. else SIPController.audioRTPManager.RTPInit(SIPController.sipCall.sdp.audioM.mediaPort, 7);
  3176. }
  3177. if (SIPStack.bDirectCall == true) {
  3178. // SERVICE MESSAGE NEEDED
  3179. dialerVideoSet(true);
  3180. }
  3181. }
  3182. }
  3183. }
  3184. }
  3185. return true;
  3186. }
  3187. return false;
  3188. } catch (RuntimeException re) {
  3189. LogUtil.errorLogInfo("", TAG, re);
  3190. return false;
  3191. } catch (Exception e) {
  3192. Log.e(TAG, "[Exception] directsendAccept()");
  3193. //e.printStackTrace();
  3194. LogUtil.errorLogInfo("", TAG, e);
  3195. return false;
  3196. }
  3197. }
  3198. public boolean sendUpdateAccept() {
  3199. Log.d(TAG, "[sendUpdateAccept]");
  3200. String sendmessage = cmcore.makeSendUpdateAccept(SIPController.sipCall);
  3201. if (sendmessage.length() > 0 && mSIPSignalReceiver != null) {
  3202. byte[] buffer = sendmessage.getBytes();
  3203. if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, sendmessage);
  3204. SIPController.sipCall.callTime_T6 = new Date();
  3205. int repeatSendCount = 0;
  3206. while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) {
  3207. if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort, buffer, buffer.length)) {
  3208. break;
  3209. }
  3210. repeatSendCount++;
  3211. }
  3212. SIPController.sipCall.callState = SIPStack.SIP_CALLSTATE_UPDATEACCEPTED;
  3213. if (SIPController.sipCall.remoteSdp != null && SIPController.sipCall.remoteSdp.flag == true && SIPController.audioRTPManager != null) {
  3214. if (SIPController.sipCall.remoteSdp.audioM != null && SIPController.sipCall.remoteSdp.audioM.flag == true) {
  3215. if (SIPController.audioRTPManager != null) {
  3216. SIPController.audioRTPManager.setRemoteMediaInfo(SIPController.sipCall.remoteSdp.audioM.commonCodec, SIPController.sipCall.remoteSdp.audioM.mediaIp, SIPController.sipCall.remoteSdp.audioM.mediaPort);
  3217. if (SIPController.sipCall.sdp != null && SIPController.sipCall.sdp.audioM != null && SIPController.audioRTPManager.rtpCore.bActive == false) {
  3218. SIPController.audioRTPManager.RTPInit(SIPController.sipCall.sdp.audioM.mediaPort, 8);
  3219. }
  3220. }
  3221. }
  3222. }
  3223. return true;
  3224. }
  3225. return false;
  3226. }
  3227. public boolean rejectCall(int code) {
  3228. String sendmessage = cmcore.makeRejectCall(SIPController.sipCall, code);
  3229. if (sendmessage.length() > 0 && mSIPSignalReceiver != null) {
  3230. byte[] buffer = sendmessage.getBytes();
  3231. if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, sendmessage);
  3232. SIPController.sipCall.callTime_T6 = new Date();
  3233. int repeatSendCount = 0;
  3234. while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) {
  3235. if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort, buffer, buffer.length)) {
  3236. break;
  3237. }
  3238. repeatSendCount++;
  3239. }
  3240. SIPController.sipCall.callState = SIPStack.SIP_CALLSTATE_TERMINATING;
  3241. Log.i(TAG, "rejectCall code : " + code);
  3242. // Phone status set
  3243. // SERVICE MESSAGE NEEDED
  3244. updateDialerStatus("Call reject.", true);
  3245. return true;
  3246. }
  3247. return false;
  3248. }
  3249. public boolean redirectResponse(String contact) {
  3250. String sendmessage = cmcore.makeRejectCall(SIPController.sipCall, 302, contact);
  3251. if (sendmessage.length() > 0 && mSIPSignalReceiver != null) {
  3252. byte[] buffer = sendmessage.getBytes();
  3253. if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, sendmessage);
  3254. SIPController.sipCall.callTime_T6 = new Date();
  3255. int repeatSendCount = 0;
  3256. while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) {
  3257. if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort, buffer, buffer.length)) {
  3258. break;
  3259. }
  3260. repeatSendCount++;
  3261. }
  3262. SIPController.sipCall.callState = SIPStack.SIP_CALLSTATE_TERMINATING;
  3263. // Phone status set
  3264. // SERVICE MESSAGE NEEDED
  3265. updateDialerStatus("Call reject.", true);
  3266. return true;
  3267. }
  3268. return false;
  3269. }
  3270. public boolean rejectPendingCall(int code) {
  3271. Log.i("SIPStun", ">>>rejectPendingCall debug 1 " + SIPController.pendingCall.remoteIp + " port:" + SIPController.pendingCall.remotePort);
  3272. String sendmessage = cmcore.makeRejectCall(SIPController.pendingCall, code);
  3273. if (sendmessage.length() > 0 && mSIPSignalReceiver != null) {
  3274. byte[] buffer = sendmessage.getBytes();
  3275. if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, sendmessage);
  3276. SIPController.pendingCall.callTime_T6 = new Date();
  3277. int repeatSendCount = 0;
  3278. while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) {
  3279. if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.pendingCall.remoteIp, SIPController.pendingCall.remotePort, buffer, buffer.length)) {
  3280. break;
  3281. }
  3282. repeatSendCount++;
  3283. }
  3284. SIPController.pendingCall.callState = SIPStack.SIP_CALLSTATE_TERMINATING;
  3285. }
  3286. return true;
  3287. }
  3288. public boolean rejectCall(String message, int code, String remoteIp, int remotePort) {
  3289. String sendmessage = cmcore.makeRejectCall(message, code, cmcore.localIp, cmcore.localPort, remoteIp, remotePort);
  3290. if (sendmessage.length() > 0 && mSIPSignalReceiver != null) {
  3291. byte[] buffer = sendmessage.getBytes();
  3292. if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, sendmessage);
  3293. int repeatSendCount = 0;
  3294. while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) {
  3295. if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(remoteIp, remotePort, buffer, buffer.length)) {
  3296. break;
  3297. }
  3298. repeatSendCount++;
  3299. }
  3300. }
  3301. return true;
  3302. }
  3303. public boolean redirectIncomingCall(String redirectId) {
  3304. String sendmessage = cmcore.makeRedirectIncomingCall(SIPController.sipCall, redirectId);
  3305. if (sendmessage.length() > 0 && mSIPSignalReceiver != null) {
  3306. // Phone status set
  3307. // SERVICE MESSAGE NEEDED
  3308. updateDialerStatus("Call forwarding to " + redirectId, true);
  3309. byte[] buffer = sendmessage.getBytes();
  3310. if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, sendmessage);
  3311. SIPController.sipCall.callTime_T6 = new Date();
  3312. int repeatSendCount = 0;
  3313. while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) {
  3314. if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort, buffer, buffer.length)) {
  3315. break;
  3316. }
  3317. repeatSendCount++;
  3318. }
  3319. SIPController.sipCall.callState = SIPStack.SIP_CALLSTATE_TERMINATING;
  3320. return true;
  3321. }
  3322. return false;
  3323. }
  3324. public boolean sendProgressing(String body, String remoteIp, int remotePort) {
  3325. String sendmessage = cmcore.makeSendProgressing(SIPController.sipCall, body);
  3326. if (sendmessage.length() > 0 && mSIPSignalReceiver != null) {
  3327. byte[] buffer = sendmessage.getBytes();
  3328. if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, sendmessage);
  3329. SIPController.sipCall.callTime_T6 = new Date();
  3330. int repeatSendCount = 0;
  3331. while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) {
  3332. if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(remoteIp, remotePort, buffer, buffer.length)) {
  3333. break;
  3334. }
  3335. repeatSendCount++;
  3336. }
  3337. }
  3338. return true;
  3339. }
  3340. public boolean sendAck(String message) {
  3341. if (true == cmcore.makeSendAck(SIPController.sipCall, message)) {
  3342. if (SIPController.sipCall.message.length() > 0 && mSIPSignalReceiver != null) {
  3343. byte[] buffer = SIPController.sipCall.message.getBytes();
  3344. if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, SIPController.sipCall.message);
  3345. SIPController.sipCall.callTime_T4 = new Date();
  3346. SIPController.sipCall.callTime_T40 = new Date();
  3347. if (SIPController.sipCall.routeIp != null && SIPController.sipCall.routeIp.length() > 0 && SIPController.sipCall.routePort > 0) {
  3348. int repeatSendCount = 0;
  3349. while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) {
  3350. if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.routeIp, SIPController.sipCall.routePort, buffer, buffer.length)) {
  3351. break;
  3352. }
  3353. repeatSendCount++;
  3354. }
  3355. } else {
  3356. int repeatSendCount = 0;
  3357. while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) {
  3358. if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort, buffer, buffer.length)) {
  3359. break;
  3360. }
  3361. repeatSendCount++;
  3362. }
  3363. }
  3364. return true;
  3365. }
  3366. }
  3367. return false;
  3368. }
  3369. public boolean sendFinalAck(String message) {
  3370. if (true == cmcore.makeSendFinalAck(SIPController.sipCall, message)) {
  3371. if (SIPController.sipCall.message.length() > 0 && mSIPSignalReceiver != null) {
  3372. byte[] buffer = SIPController.sipCall.message.getBytes();
  3373. if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, SIPController.sipCall.message);
  3374. // if (SIPStack.SIP_MESSAGE_DEBUG == true) Log.i(TAG, "SEND\n" + SIPController.sipCall.message);
  3375. if (SIPController.sipCall.routeIp != null && SIPController.sipCall.routeIp.length() > 0 && SIPController.sipCall.routePort > 0) {
  3376. int repeatSendCount = 0;
  3377. while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) {
  3378. if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.routeIp, SIPController.sipCall.routePort, buffer, buffer.length)) {
  3379. mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.routeIp, SIPController.sipCall.routePort, buffer, buffer.length);
  3380. mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.routeIp, SIPController.sipCall.routePort, buffer, buffer.length);
  3381. break;
  3382. }
  3383. repeatSendCount++;
  3384. }
  3385. } else {
  3386. int repeatSendCount = 0;
  3387. while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) {
  3388. if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort, buffer, buffer.length)) {
  3389. mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort, buffer, buffer.length);
  3390. mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort, buffer, buffer.length);
  3391. break;
  3392. }
  3393. repeatSendCount++;
  3394. }
  3395. }
  3396. return true;
  3397. }
  3398. }
  3399. return false;
  3400. }
  3401. public boolean sendFinalAck(String message, String remoteIp, int remotePort) {
  3402. String sendmessage = cmcore.makeSendFinalAck(SIPController.sipCall, message, remoteIp, remotePort);
  3403. if (sendmessage.length() > 0 && mSIPSignalReceiver != null) {
  3404. byte[] buffer = sendmessage.getBytes();
  3405. if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, sendmessage);
  3406. if (remoteIp != null && remoteIp.length() > 0 && remotePort > 0) {
  3407. int repeatSendCount = 0;
  3408. while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) {
  3409. if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(remoteIp, remotePort, buffer, buffer.length)) {
  3410. mSIPSignalReceiver.BSSSipSendUdpPacket(remoteIp, remotePort, buffer, buffer.length);
  3411. mSIPSignalReceiver.BSSSipSendUdpPacket(remoteIp, remotePort, buffer, buffer.length);
  3412. break;
  3413. }
  3414. }
  3415. return true;
  3416. }
  3417. }
  3418. return false;
  3419. }
  3420. public boolean sendRedirectFinalAck(String message) {
  3421. if (true == cmcore.makeSendRedirectFinalAck(SIPController.sipCall, message)) {
  3422. if (SIPController.sipCall.message.length() > 0 && mSIPSignalReceiver != null) {
  3423. byte[] buffer = SIPController.sipCall.message.getBytes();
  3424. if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, SIPController.sipCall.message);
  3425. if (SIPController.sipCall.routeIp != null && SIPController.sipCall.routeIp.length() > 0 && SIPController.sipCall.routePort > 0) {
  3426. int repeatSendCount = 0;
  3427. while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) {
  3428. if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.routeIp, SIPController.sipCall.routePort, buffer, buffer.length)) {
  3429. break;
  3430. }
  3431. repeatSendCount++;
  3432. }
  3433. } else {
  3434. int repeatSendCount = 0;
  3435. while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) {
  3436. if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort, buffer, buffer.length)) {
  3437. break;
  3438. }
  3439. repeatSendCount++;
  3440. }
  3441. }
  3442. return true;
  3443. }
  3444. }
  3445. return false;
  3446. }
  3447. // REJECT OR BYE OR CANCEL
  3448. public boolean callTerminate() {
  3449. if (SIPController.sipCall == null || SIPController.sipCall.flag == false) {
  3450. return false;
  3451. }
  3452. SIPController.sipCall.bCancelRequest = false;
  3453. if (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_CONNECTED || SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_ACCEPTED || SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_REMOTEACCEPTED) {
  3454. // Phone status set
  3455. // SERVICE MESSAGE NEEDED
  3456. updateDialerStatus("Call disconnecting./" + SIPController.sipCall.dnis, false);
  3457. int duration = 0;
  3458. Date currentTime = new Date();
  3459. if (SIPController.sipCall.callTime_T4 != null) {
  3460. duration = (int) (currentTime.getTime() - SIPController.sipCall.callTime_T4.getTime()) / 1000;
  3461. if (SIPController.sipCall.callDirection == SIPStack.SIP_CALLDIRECTION_IN)
  3462. duration -= 1;
  3463. if (duration < 0) duration = 0;
  3464. }
  3465. if (SIPController.audioRTPManager != null) SIPController.audioRTPManager.RTPEnd(25);
  3466. if (SIPStack.bDirectCall == true) {
  3467. // SERVICE MESSAGE NEEDED
  3468. dialerVideoSet(false);
  3469. }
  3470. return sendBye();
  3471. } else if (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_INVITING || SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_PROCEEDING || SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_PROGRESSING) {
  3472. // Phone status set
  3473. // SERVICE MESSAGE NEEDED
  3474. updateDialerStatus("Call cancelling./" + SIPController.sipCall.dnis, false);
  3475. rejectPendingCall(480);
  3476. //rejectCall(486);
  3477. if (SIPController.audioRTPManager != null) SIPController.audioRTPManager.RTPEnd(26);
  3478. if (SIPStack.bDirectCall == true) {
  3479. // SERVICE MESSAGE NEEDED
  3480. dialerVideoSet(false);
  3481. }
  3482. return sendCancel();
  3483. } else if (SIPController.sipCall.callDirection == SIPStack.SIP_CALLDIRECTION_IN && (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_OFFERRED || SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_CANCELLED)) {
  3484. // Phone status set
  3485. // SERVICE MESSAGE NEEDED
  3486. if (SIPController.bSinglecallBusyResponse == true) {
  3487. SIPController.bSinglecallBusyResponse = false;
  3488. updateDialerStatus("Busy Call reject./" + SIPController.sipCall.dnis, false);
  3489. return rejectCall(486);
  3490. } else {
  3491. updateDialerStatus("Call reject./" + SIPController.sipCall.dnis, false);
  3492. return rejectCall(480);
  3493. }
  3494. } else if (SIPController.sipCall.flag == true && SIPController.sipCall.callState != SIPStack.SIP_CALLSTATE_TERMINATING) {
  3495. if (SIPController.audioRTPManager != null) SIPController.audioRTPManager.RTPEnd(27);
  3496. if (SIPStack.bDirectCall == true) {
  3497. // SERVICE MESSAGE NEEDED
  3498. dialerVideoSet(false);
  3499. }
  3500. // SERVICE MESSAGE NEEDED
  3501. dialerNotifyCallEnd("", SIPController.sipCall.dnis, SIPController.sipCall.dnis + "@" + SIPController.sipCall.remoteIp + ":" + SIPController.sipCall.remotePort, false);
  3502. SIPController.sipCall.resetCall();
  3503. } else {
  3504. Log.e(TAG, "[callTerminate] NO IF");
  3505. }
  3506. return true;
  3507. }
  3508. // Redirect response
  3509. public boolean redirectTerminate(String contact) {
  3510. if (SIPController.sipCall == null || SIPController.sipCall.flag == false) {
  3511. return false;
  3512. }
  3513. LOG_INFO("[redirectTerminate] contact [" + contact + "]");
  3514. SIPController.sipCall.bForwardRequest = false;
  3515. if (SIPController.sipCall.callDirection == SIPStack.SIP_CALLDIRECTION_IN && (SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_OFFERRED)) {
  3516. // Phone status set
  3517. // SERVICE MESSAGE NEEDED
  3518. LOG_INFO("[redirectTerminate] BSSVideo.HNS_SERVICE_RECEIVER_SELECTED [" + BSSVideo.HNS_SERVICE_RECEIVER_SELECTED + "]");
  3519. LOG_INFO("[redirectTerminate] SIPController.sipCall.remoteIp : " + SIPController.sipCall.remoteIp);
  3520. LOG_INFO("[redirectTerminate] SIPController.sipCall.number : " + SIPController.sipCall.number);
  3521. LOG_INFO("[redirectTerminate] SIPController.sipCall.cid : " + SIPController.sipCall.cid);
  3522. LOG_INFO("[redirectTerminate] SIPController.sipCall.dnis : " + SIPController.sipCall.dnis);
  3523. LOG_INFO("[redirectTerminate] SIPController.sipCall.dong_number : " + SIPController.sipCall.dong_number);
  3524. LOG_INFO("[redirectTerminate] SIPController.sipCall.ho_number : " + SIPController.sipCall.ho_number);
  3525. LOG_INFO("[redirectTerminate] SIPController.sipCall.id : " + SIPController.sipCall.id);
  3526. updateDialerStatus("Call forwarded.", false);
  3527. return redirectResponse(contact);
  3528. } else if (SIPController.sipCall.flag == true && SIPController.sipCall.callState != SIPStack.SIP_CALLSTATE_TERMINATING) {
  3529. if (SIPController.audioRTPManager != null) SIPController.audioRTPManager.RTPEnd(28);
  3530. if (SIPStack.bDirectCall == true) {
  3531. // SERVICE MESSAGE NEEDED
  3532. dialerVideoSet(false);
  3533. }
  3534. // SERVICE MESSAGE NEEDED
  3535. dialerNotifyCallEnd("", SIPController.sipCall.dnis, SIPController.sipCall.dnis + "@" + SIPController.sipCall.remoteIp + ":" + SIPController.sipCall.remotePort, false);
  3536. SIPController.sipCall.resetCall();
  3537. }
  3538. return true;
  3539. }
  3540. // BYE
  3541. public boolean sendBye() {
  3542. if (SIPController.sipCall == null || SIPController.sipCall.flag == false) return false;
  3543. if (true == cmcore.makeBye(SIPController.sipCall)) {
  3544. if (SIPController.sipCall.message.length() > 0 && mSIPSignalReceiver != null) {
  3545. byte[] buffer = SIPController.sipCall.message.getBytes();
  3546. if (SIPController.sipCall.message.length() > 0) {
  3547. if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, SIPController.sipCall.message);
  3548. SIPController.sipCall.callTime_T5 = new Date();
  3549. SIPController.sipCall.callTime_T6 = new Date();
  3550. SIPController.sipCall.callTime_T9 = new Date();
  3551. SIPController.sipCall.bByedisconnected = true;
  3552. SIPController.sipCall.callState = SIPStack.SIP_CALLSTATE_DISCONNECTING;
  3553. int repeatSendCount = 0;
  3554. while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) {
  3555. if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort, buffer, buffer.length)) {
  3556. mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort, buffer, buffer.length);
  3557. mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort, buffer, buffer.length);
  3558. break;
  3559. }
  3560. repeatSendCount++;
  3561. }
  3562. }
  3563. }
  3564. return true;
  3565. }
  3566. return false;
  3567. }
  3568. public boolean resendBye() {
  3569. if (SIPController.sipCall == null || SIPController.sipCall.flag == false) return false;
  3570. if (SIPController.sipCall.callState != SIPStack.SIP_CALLSTATE_DISCONNECTING) return false;
  3571. if (true == cmcore.makeReBye(SIPController.sipCall)) {
  3572. if (SIPController.sipCall.message.length() > 0 && mSIPSignalReceiver != null) {
  3573. byte[] buffer = SIPController.sipCall.message.getBytes();
  3574. if (SIPController.sipCall.message.length() > 0) {
  3575. if (bPrintSIPMsg)
  3576. printSIPMessage(MESSAGE.RESEND, SIPController.sipCall.message);
  3577. SIPController.sipCall.callTime_T9 = new Date();
  3578. SIPController.sipCall.bByedisconnected = true;
  3579. int repeatSendCount = 0;
  3580. while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) {
  3581. if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort, buffer, buffer.length)) {
  3582. mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort, buffer, buffer.length);
  3583. mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort, buffer, buffer.length);
  3584. break;
  3585. }
  3586. repeatSendCount++;
  3587. }
  3588. }
  3589. }
  3590. return true;
  3591. }
  3592. return false;
  3593. }
  3594. public boolean sendByeResponse(String message, String remoteIp, int remotePort) {
  3595. String sendmessage = cmcore.makeSendByeResponse(SIPController.sipCall, message);
  3596. if (sendmessage.length() > 0 && mSIPSignalReceiver != null) {
  3597. byte[] buffer = sendmessage.getBytes();
  3598. if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, sendmessage);
  3599. // if (SIPStack.SIP_MESSAGE_DEBUG == true) Log.i(TAG, "SENT\n" + sendmessage);
  3600. SIPController.sipCall.callTime_T6 = new Date();
  3601. int repeatSendCount = 0;
  3602. while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) {
  3603. if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(remoteIp, remotePort, buffer, buffer.length)) {
  3604. mSIPSignalReceiver.BSSSipSendUdpPacket(remoteIp, remotePort, buffer, buffer.length);
  3605. mSIPSignalReceiver.BSSSipSendUdpPacket(remoteIp, remotePort, buffer, buffer.length);
  3606. break;
  3607. }
  3608. repeatSendCount++;
  3609. }
  3610. }
  3611. return true;
  3612. }
  3613. // CANCEL
  3614. public boolean sendCancel() {
  3615. if (SIPController.sipCall == null || SIPController.sipCall.flag == false) return false;
  3616. if (true == cmcore.makeCancel(SIPController.sipCall)) {
  3617. if (SIPController.sipCall.message.length() > 0 && mSIPSignalReceiver != null) {
  3618. byte[] buffer = SIPController.sipCall.message.getBytes();
  3619. if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, SIPController.sipCall.message);
  3620. // if (SIPStack.SIP_MESSAGE_DEBUG == true) Log.i(TAG, "SEND\n" + SIPController.sipCall.message);
  3621. SIPController.sipCall.callTime_T8 = new Date();
  3622. SIPController.sipCall.callState = SIPStack.SIP_CALLSTATE_CANCELLING;
  3623. int repeatSendCount = 0;
  3624. while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) {
  3625. if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort, buffer, buffer.length)) {
  3626. break;
  3627. }
  3628. repeatSendCount++;
  3629. }
  3630. return true;
  3631. }
  3632. }
  3633. return false;
  3634. }
  3635. public boolean sendRecancel() {
  3636. //Log.i(TAG, "RECANCELLING");
  3637. if (SIPController.sipCall == null || SIPController.sipCall.flag == false) return false;
  3638. if (true == cmcore.makeRecancel(SIPController.sipCall)) {
  3639. if (SIPController.sipCall.message.length() > 0 && mSIPSignalReceiver != null) {
  3640. byte[] buffer = SIPController.sipCall.message.getBytes();
  3641. if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, SIPController.sipCall.message);
  3642. // if (SIPStack.SIP_MESSAGE_DEBUG == true) Log.i(TAG, "SEND\n" + SIPController.sipCall.message);
  3643. SIPController.sipCall.callTime_T8 = new Date();
  3644. SIPController.sipCall.callState = SIPStack.SIP_CALLSTATE_RECANCELLING;
  3645. int repeatSendCount = 0;
  3646. while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) {
  3647. if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort, buffer, buffer.length)) {
  3648. break;
  3649. }
  3650. repeatSendCount++;
  3651. }
  3652. return true;
  3653. }
  3654. }
  3655. return false;
  3656. }
  3657. // OPTIONS
  3658. public boolean sendOptionsResponse(String message, String remoteIp, int remotePort, int code) {
  3659. String sendmessage = cmcore.makeSendOptionsResponse(SIPController.sipCall, message, code);
  3660. if (sendmessage.length() > 0 && mSIPSignalReceiver != null) {
  3661. byte[] buffer = sendmessage.getBytes();
  3662. if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, sendmessage);
  3663. int repeatSendCount = 0;
  3664. while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) {
  3665. if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(remoteIp, remotePort, buffer, buffer.length)) {
  3666. break;
  3667. }
  3668. repeatSendCount++;
  3669. }
  3670. return true;
  3671. }
  3672. return false;
  3673. }
  3674. //INFO
  3675. public boolean sendInfoResponse(String message, String remoteIp, int remotePort, int code) {
  3676. String sendmessage = cmcore.makeSendInfoResponse(SIPController.sipCall, message, code);
  3677. if (sendmessage.length() > 0 && mSIPSignalReceiver != null) {
  3678. byte[] buffer = sendmessage.getBytes();
  3679. if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, sendmessage);
  3680. int repeatSendCount = 0;
  3681. while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) {
  3682. if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(remoteIp, remotePort, buffer, buffer.length)) {
  3683. break;
  3684. }
  3685. repeatSendCount++;
  3686. }
  3687. } else return false;
  3688. // DTMF PARSE
  3689. SIPHeader sipHeader = new SIPHeader(message, SIPStack.SIP_HEADERTYPE_CONTENTTYPE);
  3690. if (sipHeader != null && sipHeader.flag == true && sipHeader.headerValue != null && sipHeader.headerValue.length() > 0) {
  3691. if (sipHeader.headerValue.compareTo("application/dtmf-relay") == 0) {
  3692. // DTMF-RELAY TYPE
  3693. if (SIPController.sipCall != null && SIPController.sipCall.flag == true && SIPController.sipCall.parseDtmfSdp(message, SIPStack.SIP_DTMFINFO_DTMFRELAY) == true) {
  3694. // SERVICE MESSAGE NEEDED
  3695. dialerNotifyDtmf(SIPController.sipCall.detectedDtmf);
  3696. }
  3697. } else if (sipHeader.headerValue.compareTo("application/dtmf") == 0) {
  3698. // DTMF TYPE
  3699. if (SIPController.sipCall != null && SIPController.sipCall.flag == true && SIPController.sipCall.parseDtmfSdp(message, SIPStack.SIP_DTMFINFO_DTMF) == true) {
  3700. // SERVICE MESSAGE NEEDED
  3701. dialerNotifyDtmf(SIPController.sipCall.detectedDtmf);
  3702. }
  3703. }
  3704. }
  3705. return true;
  3706. }
  3707. // OPTIONS
  3708. public boolean sendMessageResponse(String message, String remoteIp, int remotePort, int code) {
  3709. String sendmessage = cmcore.makeSendInfoResponse(SIPController.sipCall, message, code);
  3710. if (sendmessage.length() > 0 && mSIPSignalReceiver != null) {
  3711. byte[] buffer = sendmessage.getBytes();
  3712. if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, sendmessage);
  3713. int repeatSendCount = 0;
  3714. while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) {
  3715. if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(remoteIp, remotePort, buffer, buffer.length)) {
  3716. break;
  3717. }
  3718. repeatSendCount++;
  3719. }
  3720. return true;
  3721. }
  3722. return false;
  3723. }
  3724. public boolean sendUpdate() {
  3725. if (true == cmcore.makeSendUpdate(SIPController.sipCall)) {
  3726. if (SIPController.sipCall.message.length() > 0 && mSIPSignalReceiver != null) {
  3727. byte[] buffer = SIPController.sipCall.message.getBytes();
  3728. if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, SIPController.sipCall.message);
  3729. int repeatSendCount = 0;
  3730. while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) {
  3731. if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort, buffer, buffer.length)) {
  3732. break;
  3733. }
  3734. repeatSendCount++;
  3735. }
  3736. SIPController.sipCall.callTime_T0 = new Date();
  3737. return true;
  3738. }
  3739. }
  3740. return false;
  3741. }
  3742. public boolean sendUpdate(String flow) {
  3743. if (true == cmcore.makeSendUpdate(SIPController.sipCall, flow)) {
  3744. if (SIPController.sipCall.message.length() > 0 && mSIPSignalReceiver != null) {
  3745. byte[] buffer = SIPController.sipCall.message.getBytes();
  3746. if (bPrintSIPMsg) printSIPMessage(MESSAGE.SEND, SIPController.sipCall.message);
  3747. int repeatSendCount = 0;
  3748. while (repeatSendCount < SIPStack.REPEAT_SENDCOUNT) {
  3749. if (buffer.length == mSIPSignalReceiver.BSSSipSendUdpPacket(SIPController.sipCall.remoteIp, SIPController.sipCall.remotePort, buffer, buffer.length)) {
  3750. break;
  3751. }
  3752. repeatSendCount++;
  3753. }
  3754. SIPController.sipCall.callTime_T0 = new Date();
  3755. return true;
  3756. }
  3757. }
  3758. return false;
  3759. }
  3760. public void sendHold() {
  3761. if (SIPController.sipCall != null && SIPController.sipCall.flag == true && SIPController.sipCall.callMode == SIPStack.SIP_CALLMODE_BASIC && SIPController.sipCall.callState == SIPStack.SIP_CALLSTATE_CONNECTED) {
  3762. if (SIPController.sipCall.bHolding == true) {
  3763. SIPController.sipCall.bHolding = false;
  3764. sendUpdate("sendrecv");
  3765. if (SIPController.sipSound != null)
  3766. SIPController.sipSound.flowIndicator = SIPStack.SIP_MEDIAFLOW_SENDRECV;
  3767. } else {
  3768. SIPController.sipCall.bHolding = true;
  3769. sendUpdate();
  3770. if (SIPController.sipSound != null)
  3771. SIPController.sipSound.flowIndicator = SIPStack.SIP_MEDIAFLOW_SENDONLY;
  3772. }
  3773. }
  3774. }
  3775. public void updateDialerStatus(String arg1, boolean bSet) {
  3776. Log.d(TAG, "[updateDialerStatus] arg1 [" + arg1 + "], bSet [" + bSet + "]");
  3777. for (int i = mClients.size() - 1; i >= 0; i--) {
  3778. try {
  3779. // Send data as a String
  3780. Bundle b = new Bundle();
  3781. b.putString("UPDATESTATUS", arg1);
  3782. Message msg = null;
  3783. if (bSet == true)
  3784. msg = Message.obtain(null, CMCore.BSSSIPStun_ICONTROLS_CM_UPDATESTATUS_TRUE);
  3785. else msg = Message.obtain(null, CMCore.BSSSIPStun_ICONTROLS_CM_UPDATESTATUS_FALSE);
  3786. msg.setData(b);
  3787. mClients.get(i).send(msg);
  3788. // Log.d(TAG, "[updateDialerStatus]" + MainActivity.mCallController.mCallInfo.getRESI().toString());
  3789. // if(MainActivity.mCallController.mCallInfo.getRESI() == CallManager.CALLSTATUS.IDLE) {
  3790. // Log.d(TAG, "[updateDialerStatus]" + MainActivity.mCallController.mCallInfo.getRESI().toString());
  3791. //rejectPendingCall(480);
  3792. //rejectCall(m_strMessage, 487, m_strRemoteIP, m_strRemotePort);
  3793. //Thread.sleep(1000);
  3794. // }
  3795. } catch (RemoteException e) {
  3796. Log.e(TAG, "[RemoteException] updateDialerStatus(String arg1, boolean bSet)");
  3797. //e.printStackTrace();
  3798. LogUtil.errorLogInfo("", TAG, e);
  3799. mClients.remove(i);
  3800. } catch (Exception e) {
  3801. Log.e(TAG, "[Exception] updateDialerStatus(String arg1, boolean bSet)");
  3802. //e.printStackTrace();
  3803. LogUtil.errorLogInfo("", TAG, e);
  3804. }
  3805. }
  3806. }
  3807. public void dialerVideoSet(boolean bSet) {
  3808. for (int i = mClients.size() - 1; i >= 0; i--) {
  3809. try {
  3810. // Send data as a String
  3811. Bundle b = new Bundle();
  3812. b.putString("VIDEOSET", SIPController.sipCall.dnis);
  3813. Message msg = null;
  3814. if (bSet == true)
  3815. msg = Message.obtain(null, CMCore.BSSSIPStun_ICONTROLS_CM_VIDEOSET_TRUE);
  3816. else msg = Message.obtain(null, CMCore.BSSSIPStun_ICONTROLS_CM_VIDEOSET_FALSE);
  3817. msg.setData(b);
  3818. mClients.get(i).send(msg);
  3819. } catch (RemoteException e) {
  3820. Log.e(TAG, "[RemoteException] dialerVideoSet(boolean bSet)");
  3821. //e.printStackTrace();
  3822. LogUtil.errorLogInfo("", TAG, e);
  3823. mClients.remove(i);
  3824. } catch (Exception e) {
  3825. Log.e(TAG, "[Exception] dialerVideoSet(boolean bSet)");
  3826. //e.printStackTrace();
  3827. LogUtil.errorLogInfo("", TAG, e);
  3828. }
  3829. }
  3830. }
  3831. public void dialerNotifyIncomingCall(String dn, String uri) {
  3832. Log.i(TAG, "[dialerNotifyIncomingCall] dn [" + dn + "], uri [" + uri + "], mClients.size() [" + mClients.size() + "]");
  3833. int nCnt = 0;
  3834. while (mClients.size() == 0) {
  3835. if (nCnt == 5) continue;
  3836. nCnt++;
  3837. try {
  3838. Thread.sleep(100);
  3839. } catch (InterruptedException e) {
  3840. Log.e(TAG, "[InterruptedException] dialerNotifyIncomingCall(String dn, String uri)");
  3841. //e.printStackTrace();
  3842. LogUtil.errorLogInfo("", TAG, e);
  3843. }
  3844. }
  3845. for (int i = mClients.size() - 1; i >= 0; i--) {
  3846. try {
  3847. // Send data as a String
  3848. Bundle b = new Bundle();
  3849. b.putString("INCOMINGCALL", dn + ";" + uri);
  3850. Message msg = null;
  3851. msg = Message.obtain(null, CMCore.BSSSIPStun_ICONTROLS_CM_INCOMINGCALL);
  3852. msg.setData(b);
  3853. mClients.get(i).send(msg);
  3854. } catch (RemoteException e) {
  3855. Log.e(TAG, "[RemoteException] dialerNotifyIncomingCall(String dn, String uri)");
  3856. //e.printStackTrace();
  3857. LogUtil.errorLogInfo("", TAG, e);
  3858. mClients.remove(i);
  3859. } catch (Exception e) {
  3860. Log.e(TAG, "[Exception] dialerNotifyIncomingCall(String dn, String uri)");
  3861. //e.printStackTrace();
  3862. LogUtil.errorLogInfo("", TAG, e);
  3863. }
  3864. }
  3865. }
  3866. public void dialerNotifyIncomingMultiCall(String dn, String uri) {
  3867. // 멀티콜 사용을 위해 콜 정보를 임시로 저장한다.
  3868. getMultiCallInfo();
  3869. for (int i = mClients.size() - 1; i >= 0; i--) {
  3870. try {
  3871. // Send data as a String
  3872. Bundle b = new Bundle();
  3873. b.putString("INCOMINGMULTICALL", dn + ";" + uri);
  3874. Message msg = null;
  3875. msg = Message.obtain(null, CMCore.BSSSIPStun_ICONTROLS_CM_INCOMINGMULTICALL);
  3876. msg.setData(b);
  3877. mClients.get(i).send(msg);
  3878. } catch (RemoteException e) {
  3879. Log.e(TAG, "[RemoteException] dialerNotifyIncomingMultiCall(String dn,String uri)");
  3880. //e.printStackTrace();
  3881. LogUtil.errorLogInfo("", TAG, e);
  3882. mClients.remove(i);
  3883. } catch (Exception e) {
  3884. Log.e(TAG, "[Exception] dialerNotifyIncomingMultiCall(String dn,String uri)");
  3885. //e.printStackTrace();
  3886. LogUtil.errorLogInfo("", TAG, e);
  3887. }
  3888. }
  3889. }
  3890. private void getMultiCallInfo() {
  3891. try {
  3892. Log.d(TAG, "[getMultiCallInfo] SIPController.sipCall.bPending = " + SIPController.sipCall.bPending);
  3893. Log.d(TAG, "[getMultiCallInfo] SIPController.sipCall.remoteIp = " + SIPController.sipCall.remoteIp);
  3894. Log.d(TAG, "[getMultiCallInfo] SIPController.sipCall.remoteContactUri = " + SIPController.sipCall.remoteContactUri);
  3895. Log.d(TAG, "[getMultiCallInfo] SIPController.sipCall.remoteContactIp = " + SIPController.sipCall.remoteContactIp);
  3896. Log.d(TAG, "[getMultiCallInfo] SIPController.sipCall.cid = " + SIPController.sipCall.cid);
  3897. Log.d(TAG, "[getMultiCallInfo] SIPController.sipCall.dnis = " + SIPController.sipCall.dnis);
  3898. Log.d(TAG, "[getMultiCallInfo] SIPController.pendingCall.bPending = " + SIPController.pendingCall.bPending);
  3899. Log.d(TAG, "[getMultiCallInfo] SIPController.pendingCall.remoteIp = " + SIPController.pendingCall.remoteIp);
  3900. Log.d(TAG, "[getMultiCallInfo] SIPController.pendingCall.remoteContactUri = " + SIPController.pendingCall.remoteContactUri);
  3901. Log.d(TAG, "[getMultiCallInfo] SIPController.pendingCall.remoteContactIp = " + SIPController.pendingCall.remoteContactIp);
  3902. Log.d(TAG, "[getMultiCallInfo] SIPController.pendingCall.cid = " + SIPController.pendingCall.cid);
  3903. Log.d(TAG, "[getMultiCallInfo] SIPController.pendingCall.dnis = " + SIPController.pendingCall.dnis);
  3904. SIPController.MultiCall = new SIPCall();
  3905. SIPController.MultiCall = SIPController.pendingCall;
  3906. Log.d(TAG, "[getMultiCallInfo] SIPController.MultiCall.bPending = " + SIPController.MultiCall.bPending);
  3907. Log.d(TAG, "[getMultiCallInfo] SIPController.MultiCall.remoteIp = " + SIPController.MultiCall.remoteIp);
  3908. Log.d(TAG, "[getMultiCallInfo] SIPController.MultiCall.remoteContactUri = " + SIPController.MultiCall.remoteContactUri);
  3909. Log.d(TAG, "[getMultiCallInfo] SIPController.MultiCall.remoteContactIp = " + SIPController.MultiCall.remoteContactIp);
  3910. Log.d(TAG, "[getMultiCallInfo] SIPController.MultiCall.cid = " + SIPController.MultiCall.cid);
  3911. Log.d(TAG, "[getMultiCallInfo] SIPController.MultiCall.dnis = " + SIPController.MultiCall.dnis);
  3912. } catch (RuntimeException re) {
  3913. LogUtil.errorLogInfo("", TAG, re);
  3914. } catch (Exception e) {
  3915. Log.e(TAG, "[Exception] getMultiCallInfo()");
  3916. //e.printStackTrace();
  3917. LogUtil.errorLogInfo("", TAG, e);
  3918. }
  3919. }
  3920. public void dialerNotifyCallConnected(String dn, String uri) {
  3921. for (int i = mClients.size() - 1; i >= 0; i--) {
  3922. try {
  3923. // Send data as a String
  3924. Bundle b = new Bundle();
  3925. b.putString("CALLCONNECTED", dn + ";" + uri);
  3926. Message msg = null;
  3927. msg = Message.obtain(null, CMCore.BSSSIPStun_ICONTROLS_CM_CALLCONNECTED);
  3928. msg.setData(b);
  3929. mClients.get(i).send(msg);
  3930. } catch (RemoteException e) {
  3931. Log.e(TAG, "[RemoteException] dialerNotifyCallConnected(String dn, String uri)");
  3932. //e.printStackTrace();
  3933. LogUtil.errorLogInfo("", TAG, e);
  3934. mClients.remove(i);
  3935. } catch (Exception e) {
  3936. Log.e(TAG, "[Exception] dialerNotifyCallConnected(String dn, String uri)");
  3937. //e.printStackTrace();
  3938. LogUtil.errorLogInfo("", TAG, e);
  3939. }
  3940. }
  3941. }
  3942. public void dialerNotifyBackgroundIncomingCall(String dn, String uri) {
  3943. for (int i = mClients.size() - 1; i >= 0; i--) {
  3944. try {
  3945. // Send data as a String
  3946. Bundle b = new Bundle();
  3947. b.putString("BACKGROUNDINCOMINGCALL", dn + ";" + uri);
  3948. Message msg = null;
  3949. msg = Message.obtain(null, CMCore.BSSSIPStun_ICONTROLS_CM_BACKGROUNDINCOMINGCALL);
  3950. msg.setData(b);
  3951. mClients.get(i).send(msg);
  3952. } catch (RemoteException e) {
  3953. Log.e(TAG, "[RemoteException] dialerNotifyBackgroundIncomingCall(String dn, String uri)");
  3954. //e.printStackTrace();
  3955. LogUtil.errorLogInfo("", TAG, e);
  3956. mClients.remove(i);
  3957. } catch (Exception e) {
  3958. Log.e(TAG, "[Exception] dialerNotifyBackgroundIncomingCall(String dn, String uri)");
  3959. //e.printStackTrace();
  3960. LogUtil.errorLogInfo("", TAG, e);
  3961. }
  3962. }
  3963. }
  3964. // shutdownApplication()
  3965. public void dialerShutdownApplication() {
  3966. for (int i = mClients.size() - 1; i >= 0; i--) {
  3967. try {
  3968. // Send data as a String
  3969. Bundle b = new Bundle();
  3970. b.putString("SHUTDOWNAPPLICATION", "");
  3971. Message msg = null;
  3972. msg = Message.obtain(null, CMCore.BSSSIPStun_ICONTROLS_CM_SHUTDOWNAPPLICATION);
  3973. msg.setData(b);
  3974. mClients.get(i).send(msg);
  3975. } catch (RemoteException e) {
  3976. Log.e(TAG, "[RemoteException] dialerShutdownApplication()");
  3977. //e.printStackTrace();
  3978. LogUtil.errorLogInfo("", TAG, e);
  3979. mClients.remove(i);
  3980. } catch (Exception e) {
  3981. Log.e(TAG, "[Exception] dialerShutdownApplication()");
  3982. //e.printStackTrace();
  3983. LogUtil.errorLogInfo("", TAG, e);
  3984. }
  3985. }
  3986. }
  3987. // vibrator(boolean bSet)
  3988. public void dialerVibrator(boolean bSet) {
  3989. for (int i = mClients.size() - 1; i >= 0; i--) {
  3990. try {
  3991. // Send data as a String
  3992. Bundle b = new Bundle();
  3993. b.putString("VIBRATOR", "null");
  3994. Message msg = null;
  3995. if (bSet == true)
  3996. msg = Message.obtain(null, CMCore.BSSSIPStun_ICONTROLS_CM_VIBRATOR_TRUE);
  3997. else msg = Message.obtain(null, CMCore.BSSSIPStun_ICONTROLS_CM_VIBRATOR_FALSE);
  3998. msg.setData(b);
  3999. mClients.get(i).send(msg);
  4000. } catch (RemoteException e) {
  4001. Log.e(TAG, "[RemoteException] dialerVibrator(boolean bSet)");
  4002. //e.printStackTrace();
  4003. LogUtil.errorLogInfo("", TAG, e);
  4004. mClients.remove(i);
  4005. } catch (Exception e) {
  4006. Log.e(TAG, "[Exception] dialerVibrator(boolean bSet)");
  4007. //e.printStackTrace();
  4008. LogUtil.errorLogInfo("", TAG, e);
  4009. }
  4010. }
  4011. }
  4012. // registStatus(SIPStack.bNetworkActive);
  4013. public void dialerRegistStatus(boolean bSet) {
  4014. for (int i = mClients.size() - 1; i >= 0; i--) {
  4015. try {
  4016. // Send data as a String
  4017. Bundle b = new Bundle();
  4018. b.putString("REGISTSTATUS", "null");
  4019. Message msg = null;
  4020. if (bSet == true)
  4021. msg = Message.obtain(null, CMCore.BSSSIPStun_ICONTROLS_CM_REGISTSTATUS_TRUE);
  4022. else msg = Message.obtain(null, CMCore.BSSSIPStun_ICONTROLS_CM_REGISTSTATUS_FALSE);
  4023. msg.setData(b);
  4024. mClients.get(i).send(msg);
  4025. } catch (RemoteException e) {
  4026. Log.e(TAG, "[RemoteException] dialerRegistStatus(boolean bSet)");
  4027. //e.printStackTrace();
  4028. LogUtil.errorLogInfo("", TAG, e);
  4029. mClients.remove(i);
  4030. } catch (Exception e) {
  4031. Log.e(TAG, "[Exception] dialerRegistStatus(boolean bSet)");
  4032. //e.printStackTrace();
  4033. LogUtil.errorLogInfo("", TAG, e);
  4034. }
  4035. }
  4036. }
  4037. // notifyRingbackTone(false)
  4038. public void dialerNotifyRingbackTone(boolean bSet) {
  4039. for (int i = mClients.size() - 1; i >= 0; i--) {
  4040. try {
  4041. // Send data as a String
  4042. Bundle b = new Bundle();
  4043. b.putString("RINGBACKTONE", SIPController.sipCall.dnis);
  4044. Message msg = null;
  4045. if (bSet == true)
  4046. msg = Message.obtain(null, CMCore.BSSSIPStun_ICONTROLS_CM_RINGBACKTONE_TRUE);
  4047. else msg = Message.obtain(null, CMCore.BSSSIPStun_ICONTROLS_CM_RINGBACKTONE_FALSE);
  4048. msg.setData(b);
  4049. mClients.get(i).send(msg);
  4050. } catch (RemoteException e) {
  4051. Log.e(TAG, "[RemoteException] dialerNotifyRingbackTone(boolean bSet)");
  4052. //e.printStackTrace();
  4053. LogUtil.errorLogInfo("", TAG, e);
  4054. mClients.remove(i);
  4055. } catch (Exception e) {
  4056. Log.e(TAG, "[Exception] dialerNotifyRingbackTone(boolean bSet)");
  4057. //e.printStackTrace();
  4058. LogUtil.errorLogInfo("", TAG, e);
  4059. }
  4060. }
  4061. }
  4062. // notifyCallEnd(value, false);
  4063. public void dialerNotifyCallEnd(String status, String dn, String uri, boolean bSet) {
  4064. Log.d(TAG, "[dialerNotifyCallEnd] status: " + status);
  4065. for (int i = mClients.size() - 1; i >= 0; i--) {
  4066. try {
  4067. // Send data as a String
  4068. Bundle b = new Bundle();
  4069. b.putString("CALLEND", status + ";" + dn + ";" + uri);
  4070. Message msg = null;
  4071. if (bSet == true)
  4072. msg = Message.obtain(null, CMCore.BSSSIPStun_ICONTROLS_CM_CALLEND_TRUE);
  4073. else msg = Message.obtain(null, CMCore.BSSSIPStun_ICONTROLS_CM_CALLEND_FALSE);
  4074. msg.setData(b);
  4075. mClients.get(i).send(msg);
  4076. } catch (RemoteException e) {
  4077. Log.e(TAG, "[RemoteException] dialerNotifyCallEnd(String status, String dn, String uri, boolean bSet)");
  4078. //e.printStackTrace();
  4079. LogUtil.errorLogInfo("", TAG, e);
  4080. mClients.remove(i);
  4081. } catch (Exception e) {
  4082. Log.e(TAG, "[Exception] dialerNotifyCallEnd(String status, String dn, String uri, boolean bSet)");
  4083. //e.printStackTrace();
  4084. LogUtil.errorLogInfo("", TAG, e);
  4085. }
  4086. }
  4087. if (SIPStun.bBlackCall == true) {
  4088. SIPStun.bBlackCall = false;
  4089. if (SIPStun.bBlackCallSupport == true) SIPStack.bShutdownApplication = true;
  4090. }
  4091. }
  4092. // dialerNotifyCallFail(SIPController.sipCall.responseCode,SIPController.sipCall.remoteIp);
  4093. public void dialerNotifyCallFail(int finalCode, String remoteip, String uri) {
  4094. for (int i = mClients.size() - 1; i >= 0; i--) {
  4095. try {
  4096. // Send data as a String
  4097. Bundle b = new Bundle();
  4098. b.putString("CALLFAIL", finalCode + "|" + remoteip + "|" + uri);
  4099. Message msg = null;
  4100. msg = Message.obtain(null, CMCore.BSSSIPStun_ICONTROLS_CM_OUTCALLFAIL);
  4101. msg.setData(b);
  4102. mClients.get(i).send(msg);
  4103. } catch (RemoteException e) {
  4104. Log.e(TAG, "[RemoteException] dialerNotifyCallFail(int finalCode, String remoteip)");
  4105. //e.printStackTrace();
  4106. LogUtil.errorLogInfo("", TAG, e);
  4107. mClients.remove(i);
  4108. } catch (Exception e) {
  4109. Log.e(TAG, "[Exception] dialerNotifyCallFail(int finalCode, String remoteip)");
  4110. //e.printStackTrace();
  4111. LogUtil.errorLogInfo("", TAG, e);
  4112. }
  4113. }
  4114. }
  4115. //notifyDtmf(SIPController.sipCall.detectedDtmf);
  4116. public void dialerNotifyDtmf(int dtmf) {
  4117. for (int i = mClients.size() - 1; i >= 0; i--) {
  4118. try {
  4119. // Send data as a String
  4120. Bundle b = new Bundle();
  4121. b.putString("OUTBANDDTMF", dtmf + "");
  4122. Message msg = null;
  4123. msg = Message.obtain(null, CMCore.BSSSIPStun_ICONTROLS_CM_OUTBANDDTMF);
  4124. msg.setData(b);
  4125. mClients.get(i).send(msg);
  4126. } catch (RemoteException e) {
  4127. Log.e(TAG, "[RemoteException] dialerNotifyDtmf(int dtmf)");
  4128. //e.printStackTrace();
  4129. LogUtil.errorLogInfo("", TAG, e);
  4130. mClients.remove(i);
  4131. } catch (Exception e) {
  4132. Log.e(TAG, "[Exception] dialerNotifyDtmf(int dtmf)");
  4133. //e.printStackTrace();
  4134. LogUtil.errorLogInfo("", TAG, e);
  4135. }
  4136. }
  4137. }
  4138. public void dialerPadNumber(String number) {
  4139. for (int i = mClients.size() - 1; i >= 0; i--) {
  4140. try {
  4141. // Send data as a String
  4142. Bundle b = new Bundle();
  4143. b.putString("PADNUMBER", number);
  4144. Message msg = null;
  4145. msg = Message.obtain(null, CMCore.BSSSIPStun_ICONTROLS_CM_PADNUMBER);
  4146. msg.setData(b);
  4147. mClients.get(i).send(msg);
  4148. } catch (RemoteException e) {
  4149. Log.e(TAG, "[RemoteException] dialerPadNumber(String number)");
  4150. //e.printStackTrace();
  4151. LogUtil.errorLogInfo("", TAG, e);
  4152. mClients.remove(i);
  4153. } catch (Exception e) {
  4154. Log.e(TAG, "[Exception] dialerPadNumber(String number)");
  4155. //e.printStackTrace();
  4156. LogUtil.errorLogInfo("", TAG, e);
  4157. }
  4158. }
  4159. }
  4160. public void dialerPadType(int padType, int officeNumber) {
  4161. for (int i = mClients.size() - 1; i >= 0; i--) {
  4162. try {
  4163. // Send data as a String
  4164. Bundle b = new Bundle();
  4165. String value = padType + "." + officeNumber;
  4166. b.putString("PADTYPE", value);
  4167. Message msg = null;
  4168. msg = Message.obtain(null, CMCore.BSSSIPStun_ICONTROLS_CM_PADTYPE);
  4169. msg.setData(b);
  4170. mClients.get(i).send(msg);
  4171. } catch (RemoteException e) {
  4172. Log.e(TAG, "[RemoteException] dialerPadType(int padType, int officeNumber)");
  4173. //e.printStackTrace();
  4174. LogUtil.errorLogInfo("", TAG, e);
  4175. mClients.remove(i);
  4176. } catch (Exception e) {
  4177. Log.e(TAG, "[Exception] dialerPadType(int padType, int officeNumber)");
  4178. //e.printStackTrace();
  4179. LogUtil.errorLogInfo("", TAG, e);
  4180. }
  4181. }
  4182. }
  4183. // BSSSIPStun_ICONTROLS_CM_CANCELMULTICALL
  4184. public void dialerNotifyMulticallCancel(String dn, String uri) {
  4185. for (int i = mClients.size() - 1; i >= 0; i--) {
  4186. try {
  4187. // Send data as a String
  4188. Bundle b = new Bundle();
  4189. b.putString("CANCELMULTICALL", dn + ";" + uri);
  4190. Message msg = null;
  4191. msg = Message.obtain(null, CMCore.BSSSIPStun_ICONTROLS_CM_CANCELMULTICALL);
  4192. msg.setData(b);
  4193. mClients.get(i).send(msg);
  4194. } catch (RemoteException e) {
  4195. Log.e(TAG, "[RemoteException] dialerNotifyMulticallCancel()");
  4196. //e.printStackTrace();
  4197. LogUtil.errorLogInfo("", TAG, e);
  4198. mClients.remove(i);
  4199. } catch (Exception e) {
  4200. Log.e(TAG, "[Exception] dialerNotifyMulticallCancel()");
  4201. //e.printStackTrace();
  4202. LogUtil.errorLogInfo("", TAG, e);
  4203. }
  4204. }
  4205. }
  4206. enum MESSAGE {
  4207. SEND, // 전송
  4208. RESEND, // 재전송
  4209. RECEIVE, // 수신
  4210. }
  4211. boolean bPrintSIPMsg = true;
  4212. boolean bPrintSIPMsgIO = false;
  4213. private void printSIPMessage(MESSAGE eType, String strMessage) {
  4214. try {
  4215. Log.w(TAG, "[printSIPMessage] eType [" + eType + "]");
  4216. Log.d(TAG, strMessage);
  4217. Log.w(TAG, "[printSIPMessage] End of SIP message");
  4218. } catch (RuntimeException re) {
  4219. LogUtil.errorLogInfo("", TAG, re);
  4220. } catch (Exception e) {
  4221. Log.e(TAG, "[Exception] printSIPMessage(MESSAGE eType, String strMessage)");
  4222. //e.printStackTrace();
  4223. LogUtil.errorLogInfo("", TAG, e);
  4224. }
  4225. }
  4226. public static class DeviceString {
  4227. public static String strType_Resi = "Resi";
  4228. public static String strType_RentResi = "RentResi";
  4229. public static String strType_Lobby = "Lobby";
  4230. public static String strType_Guard = "Guard";
  4231. public static String strType_Ihub = "Ihub";
  4232. }
  4233. public String[] makeDeviceName(String ipaddress) {
  4234. String[] aDeviceName = new String[3];
  4235. try {
  4236. String dong = "101";
  4237. String ho = "101";
  4238. String type = DeviceString.strType_Resi;
  4239. String[] IP_Parse = ipaddress.split("\\.");
  4240. dong = Integer.toString((((Integer.parseInt(getDongString()) / 100) * 100) + Integer.parseInt(IP_Parse[1])));
  4241. if (IP_Parse[2] == "128") {
  4242. // 경비실폰
  4243. type = DeviceString.strType_Guard;
  4244. ho = IP_Parse[3];
  4245. } else if (IP_Parse[2] == "0") {
  4246. // 로비폰
  4247. type = DeviceString.strType_Lobby;
  4248. ho = IP_Parse[3];
  4249. } else {
  4250. int nIP_DClass = Integer.parseInt(IP_Parse[3]);
  4251. if (nIP_DClass < 200) {
  4252. // 메인 세대 월패드
  4253. type = DeviceString.strType_Resi;
  4254. } else {
  4255. // 분리 세대 월패드
  4256. type = DeviceString.strType_RentResi;
  4257. nIP_DClass = nIP_DClass - 200;
  4258. }
  4259. ho = IP_Parse[2] + ZeroPadding_Head(2, Integer.toString(nIP_DClass));
  4260. }
  4261. aDeviceName[0] = type;
  4262. aDeviceName[1] = dong;
  4263. aDeviceName[2] = ho;
  4264. return aDeviceName;
  4265. } catch (RuntimeException re) {
  4266. LogUtil.errorLogInfo("", TAG, re);
  4267. return aDeviceName;
  4268. } catch (Exception e) {
  4269. Log.e(TAG, "[Exception] makeDeviceName(String ipaddress)");
  4270. //e.printStackTrace();
  4271. LogUtil.errorLogInfo("", TAG, e);
  4272. return aDeviceName;
  4273. }
  4274. }
  4275. public String makeSIPID(String strIPAddress) {
  4276. try {
  4277. LOG_INFO("[makeSIPID] strIPAddress : " + strIPAddress);
  4278. String SIPID = "12345678_Resi_0101_0101_01";
  4279. String dong = "101";
  4280. String ho = "101";
  4281. String strType = DeviceString.strType_Resi;
  4282. String strDeviceCnt = "01";
  4283. String[] IP_Parse = strIPAddress.split("\\.");
  4284. if (IP_Parse != null) {
  4285. dong = Integer.toString((((Integer.parseInt(getDongString()) / 100) * 100) + Integer.parseInt(IP_Parse[1])));
  4286. if (IP_Parse[2].equals("128")) {
  4287. // 경비실폰
  4288. strType = DeviceString.strType_Guard;
  4289. ho = IP_Parse[3];
  4290. } else if (IP_Parse[2].equals("0")) {
  4291. // 로비폰
  4292. strType = DeviceString.strType_Lobby;
  4293. ho = IP_Parse[3];
  4294. } else if (IP_Parse[2].equals("201")) {
  4295. // 아이허브
  4296. strType = DeviceString.strType_Ihub;
  4297. ho = IP_Parse[3];
  4298. } else {
  4299. int nIP_DClass = Integer.parseInt(IP_Parse[3]);
  4300. if (nIP_DClass < 200) {
  4301. // 메인 세대 월패드
  4302. strType = DeviceString.strType_Resi;
  4303. } else {
  4304. // 분리 세대 월패드
  4305. strType = DeviceString.strType_RentResi;
  4306. nIP_DClass = nIP_DClass - 200;
  4307. }
  4308. ho = IP_Parse[2] + ZeroPadding_Head(2, Integer.toString(nIP_DClass));
  4309. }
  4310. SIPID = ZeroPadding_Head(8, getSitecodeString()) + "_" + strType + "_" + ZeroPadding_Head(4, dong) + "_" + ZeroPadding_Head(4, ho) + "_" + strDeviceCnt;
  4311. LOG_INFO("[makeSIPID] SIPID : " + SIPID);
  4312. return SIPID;
  4313. }
  4314. } catch (RuntimeException re) {
  4315. LogUtil.errorLogInfo("", TAG, re);
  4316. } catch (Exception e) {
  4317. Log.e(TAG, "[Exception] MakeSIPID(...) : " + e);
  4318. //e.printStackTrace();
  4319. LogUtil.errorLogInfo("", TAG, e);
  4320. }
  4321. return "ERROR";
  4322. }
  4323. private String getSitecodeString() {
  4324. try {
  4325. String strResult = "";
  4326. WallpadDeviceSet Devset = new WallpadDeviceSet(this);
  4327. String[] getData = Devset.GetSettingData("site_code");
  4328. Devset.closeDB();
  4329. if ((getData != null) && getData.length > 1) {
  4330. strResult = getData[1];
  4331. }
  4332. LOG("[getSitecodeString] strResult [" + strResult + "]");
  4333. return strResult;
  4334. } catch (RuntimeException re) {
  4335. LogUtil.errorLogInfo("", TAG, re);
  4336. return null;
  4337. } catch (Exception e) {
  4338. Log.e(TAG, "[Exception] getSitecodeString()");
  4339. return null;
  4340. }
  4341. }
  4342. private String getDongString() {
  4343. try {
  4344. String strResult = "";
  4345. wallpaddbmgr DBMGR = new wallpaddbmgr(this);
  4346. AddressSet Addr = DBMGR.getAddressMGR();
  4347. DBMGR.closeDB();
  4348. strResult = Addr.Dong;
  4349. LOG("[getDongString] strResult [" + strResult + "]");
  4350. return strResult;
  4351. } catch (RuntimeException re) {
  4352. LogUtil.errorLogInfo("", TAG, re);
  4353. return null;
  4354. } catch (Exception e) {
  4355. Log.e(TAG, "[Exception] getDongString()");
  4356. return null;
  4357. }
  4358. }
  4359. private String getHoString() {
  4360. try {
  4361. String strResult = "";
  4362. wallpaddbmgr DBMGR = new wallpaddbmgr(this);
  4363. AddressSet Addr = DBMGR.getAddressMGR();
  4364. DBMGR.closeDB();
  4365. strResult = Addr.Ho;
  4366. LOG("[getHoString] strResult [" + strResult + "]");
  4367. return strResult;
  4368. } catch (RuntimeException re) {
  4369. LogUtil.errorLogInfo("", TAG, re);
  4370. return null;
  4371. } catch (Exception e) {
  4372. Log.e(TAG, "[Exception] getHoString()");
  4373. return null;
  4374. }
  4375. }
  4376. public static String ZeroPadding_Head(int nOutLength, String strOriginalString) {
  4377. String strResult = strOriginalString;
  4378. try {
  4379. if (strOriginalString.length() < nOutLength) {
  4380. for (int i = strOriginalString.length(); i < nOutLength; i++) {
  4381. strResult = "0" + strResult;
  4382. }
  4383. return strResult;
  4384. } else if (strOriginalString.length() == nOutLength) {
  4385. return strResult;
  4386. } else {
  4387. Log.d(TAG, "[ZeroPadding_Head] strOriginalString(" + strOriginalString.length() + ") is longer than nOutLength(" + nOutLength + ")");
  4388. return strResult;
  4389. }
  4390. } catch (RuntimeException re) {
  4391. LogUtil.errorLogInfo("", TAG, re);
  4392. return strResult;
  4393. } catch (Exception e) {
  4394. Log.e(TAG, "[ZeroPadding_Head] (Exception) ZeroPadding_Head(...) + e");
  4395. //e.printStackTrace();
  4396. LogUtil.errorLogInfo("", TAG, e);
  4397. return strResult;
  4398. }
  4399. }
  4400. public void receiveNewCall(String strRemoteIP, String strRemoteSIPID, boolean bCallPopup) {
  4401. try {
  4402. LOG_INFO("[receiveNewCall] strRemoteIP [" + strRemoteIP + "], strRemoteSIPID [" + strRemoteSIPID + "]");
  4403. LOG_INFO("[receiveNewCall] CMCore.bDialerActive [" + CMCore.bDialerActive + "]");
  4404. if (!CMCore.bDialerActive) CMCore.bDialerActive = true;
  4405. CALLEVENTTYPE mCALLEVENTTYPE = CALLEVENTTYPE.RECEIVE_CALL;
  4406. CALLTYPE mCALLTYPE = CALLTYPE.NONE;
  4407. if (strRemoteSIPID.contains(DeviceString.strType_Lobby)) {
  4408. if (bLobbyCallUse) mCALLTYPE = CALLTYPE.LOBBY;
  4409. else return;
  4410. }
  4411. else if (strRemoteSIPID.contains(DeviceString.strType_Guard)) {
  4412. if (bGuardCallUse) mCALLTYPE = CALLTYPE.GUARD;
  4413. else return;
  4414. }
  4415. else if (strRemoteSIPID.contains(DeviceString.strType_Resi)) {
  4416. if (bResiCallUse) mCALLTYPE = CALLTYPE.RESIDENCE;
  4417. else return;
  4418. }
  4419. else {
  4420. Log.e(TAG, "[receiveNewCall] SIPID is not correct!!!");
  4421. return;
  4422. }
  4423. runCallMainActivity(mCALLEVENTTYPE, mCALLTYPE, bCallPopup);
  4424. sendHandlerMsgDelayed(HANDLERMSG.RELEASE_BLOCK_INVITE_MSG, 0, 0, 0);
  4425. } catch (RuntimeException re) {
  4426. LogUtil.errorLogInfo("", TAG, re);
  4427. } catch (Exception e) {
  4428. Log.e(TAG, "[Exception] receiveNewCall(String strRemoteIP, String strRemoteSIPID)");
  4429. //e.printStackTrace();
  4430. LogUtil.errorLogInfo("", TAG, e);
  4431. }
  4432. }
  4433. String strWallPadCallPackageName = "kr.co.icontrols.wallpadcall";
  4434. public void runCallMainActivity(CALLEVENTTYPE eEventType, CALLTYPE eCallType, boolean bCallPopup) {
  4435. try {
  4436. if (!bWallPadCallLive) {
  4437. // 통화어플을 실행시킨다.
  4438. LOG_WARN("[runCallMainActivity] ########## START ##########");
  4439. sendLCDBacklightStatus(true);
  4440. WallpadStatusData mWallpadStatusData = new WallpadStatusData(getApplicationContext());
  4441. int nAlramStatus = mWallpadStatusData.GetAlarmStatus();
  4442. mWallpadStatusData.closeDB();
  4443. if (nAlramStatus != WallpadStatusData.GUARD_OUT) sendBR_AppFinish(getApplicationContext());
  4444. ComponentName mComponentName = new ComponentName("kr.co.icontrols.wallpadcall", "kr.co.icontrols.wallpadcall.MainActivity");
  4445. Intent mIntent = new Intent(Intent.ACTION_MAIN);
  4446. mIntent.putExtra(CALLTRIGGER.CALLEVENTTYPE, eEventType.toString());
  4447. mIntent.putExtra(CALLTRIGGER.CALLTYPE, eCallType.toString());
  4448. if(bCallPopup)
  4449. mIntent.putExtra("CALLPOPUP", "yes");
  4450. else
  4451. mIntent.putExtra("CALLPOPUP", "no");
  4452. mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  4453. mIntent.setComponent(mComponentName);
  4454. startActivity(mIntent);
  4455. Thread.sleep(500); // Call app이 실행되는 시간을 기다려준다. (빨리 띄우면 이벤트를 수신 못함)
  4456. } else {
  4457. LOG_WARN("[runCallMainActivity] WallPadCall is already running!! bRecordingStatus[" + MainActivity.bRecordingStatus + "]");
  4458. // yjyoon.
  4459. // 거동수상자 녹화 중 세대/로비/경비에서 콜이 왔을 때,
  4460. // 새로운 콜을 생성하기 전 녹화를 중지시킨다.
  4461. if (MainActivity.bRecordingStatus) {
  4462. Intent iIntent = new Intent();
  4463. iIntent.setAction(Declare.BR.BR_REQUEST_RECORD_STOP);
  4464. iIntent.putExtra(define.NOTIBR_KIND, 2);
  4465. iIntent.putExtra(CALLTRIGGER.CALLEVENTTYPE, eEventType.toString());
  4466. iIntent.putExtra(CALLTRIGGER.CALLTYPE, eCallType.toString());
  4467. if (bCallPopup) {
  4468. iIntent.putExtra("CALLPOPUP", "yes");
  4469. } else {
  4470. iIntent.putExtra("CALLPOPUP", "no");
  4471. }
  4472. getApplicationContext().sendBroadcast(iIntent);
  4473. }
  4474. }
  4475. } catch (RuntimeException re) {
  4476. LogUtil.errorLogInfo("", TAG, re);
  4477. } catch (Exception e) {
  4478. Log.e(TAG, "[Exception] runCallMainActivity()");
  4479. //e.printStackTrace();
  4480. LogUtil.errorLogInfo("", TAG, e);
  4481. }
  4482. }
  4483. /**
  4484. * Edited by jeff (2020.06.22)
  4485. * LCD 잔상 현장 복구/보호를 위해 실행되고 있는 LCD Keeper를 종료하기 위해, 통화 App이 실행되면서
  4486. * backlight를 On하기 전에 이를 알리는 BR를 수신하여 LCD Keeper를 종료한다.
  4487. * @param bOn
  4488. */
  4489. private void sendLCDBacklightStatus(boolean bOn) {
  4490. try {
  4491. Log.d(TAG,"[sendLCDBacklightStatus] bOn [" + bOn + "]");
  4492. Intent mIntent = new Intent();
  4493. if (bOn) mIntent.setAction(define.NOTIFY_ACNAME_LCD_BACKLIGHT_ON);
  4494. else mIntent.setAction(define.NOTIFY_ACNAME_LCD_BACKLIGHT_OFF);
  4495. getApplicationContext().sendBroadcast(mIntent);
  4496. } catch (RuntimeException re) {
  4497. LogUtil.errorLogInfo("", TAG, re);
  4498. } catch (Exception e) {
  4499. Log.e(TAG, "[Exception] sendLCDBacklightStatus(boolean bOn)");
  4500. //e.printStackTrace();
  4501. LogUtil.errorLogInfo("", TAG, e);
  4502. }
  4503. }
  4504. private boolean getCallAppRunningStatus() {
  4505. boolean bRunning = false;
  4506. try {
  4507. WallpadStatusData DBMGR = new WallpadStatusData(getApplicationContext());
  4508. bRunning = DBMGR.GetCallAPKStatusRunning();
  4509. DBMGR.closeDB();
  4510. Log.d(TAG, "[getCallAppRunningStatus] bRunning : " + bRunning);
  4511. return bRunning;
  4512. } catch (RuntimeException re) {
  4513. LogUtil.errorLogInfo("", TAG, re);
  4514. } catch (Exception e) {
  4515. Log.d(TAG, "[Exception] getCallAppRunningStatus()");
  4516. //e.printStackTrace();
  4517. LogUtil.errorLogInfo("", TAG, e);
  4518. }
  4519. return bRunning;
  4520. }
  4521. private boolean CanIStartCallApp() {
  4522. try {
  4523. for (int i = 0; i < 10; i++) {
  4524. LOG_WARN("[isCallAppRun] Check Count [" + i + "]");
  4525. if (!getTopActivity().equals(strWallPadCallPackageName)) {
  4526. return true;
  4527. } else {
  4528. if (mClients.size() > 0) {
  4529. LOG_WARN("[isCallAppRun] mClients.size() [" + mClients.size() + "]");
  4530. return false;
  4531. }
  4532. }
  4533. Thread.sleep(100);
  4534. }
  4535. return false;
  4536. } catch (RuntimeException re) {
  4537. LogUtil.errorLogInfo("", TAG, re);
  4538. return false;
  4539. } catch (Exception e) {
  4540. Log.e(TAG, "[Exception] CanIStartCallApp()");
  4541. //e.printStackTrace();
  4542. LogUtil.errorLogInfo("", TAG, e);
  4543. return false;
  4544. }
  4545. }
  4546. private String getTopActivity() {
  4547. try {
  4548. ActivityManager mActivityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
  4549. List<ActivityManager.RunningTaskInfo> mTaskInfo = mActivityManager.getRunningTasks(1);
  4550. LOG_INFO("[getTopActivity] getClassName = " + mTaskInfo.get(0).topActivity.getClassName());
  4551. ComponentName mComponentName = mTaskInfo.get(0).topActivity;
  4552. LOG_INFO("[getTopActivity] getPackageName = " + mComponentName.getPackageName());
  4553. return mComponentName.getPackageName();
  4554. } catch (RuntimeException re) {
  4555. LogUtil.errorLogInfo("", TAG, re);
  4556. return null;
  4557. } catch (Exception e) {
  4558. Log.e(TAG, "[Exception] getTopActivity()");
  4559. //e.printStackTrace();
  4560. LogUtil.errorLogInfo("", TAG, e);
  4561. return null;
  4562. }
  4563. }
  4564. private void sendBR_AppFinish(Context context) {
  4565. try {
  4566. LOG_WARN("[sendBR_AppFinish] Send App Finish!!");
  4567. Intent mIntent = new Intent();
  4568. mIntent.setAction(define.BR_APP_FINISH);
  4569. context.sendBroadcast(mIntent);
  4570. } catch (RuntimeException re) {
  4571. LogUtil.errorLogInfo("", TAG, re);
  4572. } catch (Exception e) {
  4573. Log.e(TAG, "[Exception] sendBR_AppFinish(Context context)");
  4574. //e.printStackTrace();
  4575. LogUtil.errorLogInfo("", TAG, e);
  4576. }
  4577. }
  4578. private void cancelCallForwardToStun() {
  4579. try {
  4580. LOG("[cancelCallForwardToStun]");
  4581. SIPController.sipCall.bForwardRequest = false;
  4582. SIPController.forward.bForward = false;
  4583. SIPController.forward.contact = "";
  4584. SIPController.forward.iForwardTarget = 0;
  4585. SIPController.forward.dong = "";
  4586. SIPController.forward.ho = "";
  4587. SIPController.forward.number = "";
  4588. SIPController.forward.contact = "";
  4589. } catch (RuntimeException re) {
  4590. LogUtil.errorLogInfo("", TAG, re);
  4591. } catch (Exception e) {
  4592. Log.e(TAG, "[Exception] cancelCallForwardToStun() : " + e);
  4593. //e.printStackTrace();
  4594. LogUtil.errorLogInfo("", TAG, e);
  4595. }
  4596. }
  4597. // Audio Tune
  4598. public static short nEQ_60 = -1500; // dB
  4599. public static short nEQ_230 = 0; // dB
  4600. public static short nEQ_910 = 0; // dB
  4601. public static short nEQ_4K = -1500; // dB
  4602. public static short nEQ_14K = -1500; // dB
  4603. static Equalizer mEqualizer;
  4604. public void replyEQValue() {
  4605. try {
  4606. short[] EQValues = SIPSound.getEQValues();
  4607. for (int i = mClients.size() - 1; i >= 0; i--) {
  4608. try {
  4609. // Send data as a String
  4610. Bundle b = new Bundle();
  4611. b.putString("cmd", "reply_get_eq_values");
  4612. b.putShort("60", EQValues[0]);
  4613. b.putShort("230", EQValues[1]);
  4614. b.putShort("910", EQValues[2]);
  4615. b.putShort("4k", EQValues[3]);
  4616. b.putShort("14k", EQValues[4]);
  4617. Message msg = null;
  4618. msg = Message.obtain(null, CMCore.BSSSIPStun_ICONTROLS_SET_INT_VALUE);
  4619. msg.setData(b);
  4620. mClients.get(i).send(msg);
  4621. } catch (RemoteException e) {
  4622. Log.e(TAG, "[RemoteException] replyEQValue -> mClients");
  4623. //e.printStackTrace();
  4624. LogUtil.errorLogInfo("", TAG, e);
  4625. mClients.remove(i);
  4626. }
  4627. }
  4628. } catch (RuntimeException re) {
  4629. LogUtil.errorLogInfo("", TAG, re);
  4630. } catch (Exception e) {
  4631. Log.e(TAG, "[Exception] replyEQValue()");
  4632. //e.printStackTrace();
  4633. LogUtil.errorLogInfo("", TAG, e);
  4634. }
  4635. }
  4636. public void setEQValue(String strEQ, short Value) {
  4637. try {
  4638. Log.i(TAG, "strEQ [" + strEQ + "], Value [" + Value + "]");
  4639. if (strEQ.equals("60")) SIPSound.ctrlEQ60(Value);
  4640. else if (strEQ.equals("230")) SIPSound.ctrlEQ230(Value);
  4641. else if (strEQ.equals("910")) SIPSound.ctrlEQ910(Value);
  4642. else if (strEQ.equals("4k")) SIPSound.ctrlEQ4K(Value);
  4643. else if (strEQ.equals("14k")) SIPSound.ctrlEQ14K(Value);
  4644. else {
  4645. Log.e(TAG, "strEQ is not available [" + strEQ + "]");
  4646. }
  4647. replyEQValue();
  4648. } catch (RuntimeException re) {
  4649. LogUtil.errorLogInfo("", TAG, re);
  4650. } catch (Exception e) {
  4651. Log.e(TAG, "[Exception] setEQValue(String strEQ, short Value)");
  4652. //e.printStackTrace();
  4653. LogUtil.errorLogInfo("", TAG, e);
  4654. }
  4655. }
  4656. /**
  4657. * JEFF, 2019.12.25
  4658. * WallPadMain이 실행되면 매 1초마다 WallPadCall의 실행상태를 파악한다.
  4659. * WallPadMain에서 WallPadCall의 실행상태 확인을 요청하는 BR를 송신하고
  4660. * WallPadCall은 해당 BR이 수신되면 실행상태를 알리는 BR를 송신하여 이에 응답한다.
  4661. * WallPadMain은 이 응답 BR의 수신여부를 판단하여 WallPadCall의 실행여부를 판단한다.
  4662. */
  4663. int MAX_WALLPADCALL_LIVE_CNT = 3;
  4664. int nWallPadCallACKCnt = MAX_WALLPADCALL_LIVE_CNT; // MAX_WALLPADCALL_LIVE_CNT회 이상 응답이 없으면 WallPadCall이 종료된것으로 판단한다.
  4665. public static boolean bWallPadCallLive = false; // WallPadCall의 Live 상태를 나타낸다.
  4666. boolean bCheckThreadRun = false;
  4667. checkWallPadLive mcheckWallPadLive;
  4668. class checkWallPadLive extends Thread {
  4669. public checkWallPadLive() {
  4670. Log.w(TAG,"[Thread.checkWallPadLive] bCheckThreadRun [" + bCheckThreadRun + "]");
  4671. }
  4672. @Override
  4673. public void run() {
  4674. super.run();
  4675. try {
  4676. while (bCheckThreadRun) {
  4677. if (nWallPadCallACKCnt >= 0) {
  4678. nWallPadCallACKCnt--;
  4679. }
  4680. else {
  4681. bWallPadCallLive = false;
  4682. }
  4683. // Log.w(TAG,"[WallPadCallLiveBRCheck] bWallPadCallLive [" + bWallPadCallLive + "]");
  4684. Thread.sleep(1000);
  4685. }
  4686. } catch (RuntimeException re) {
  4687. LogUtil.errorLogInfo("", TAG, re);
  4688. } catch (Exception e) {
  4689. Log.e(TAG, "[Exception] checkWallPadLive.run()");
  4690. //e.printStackTrace();
  4691. LogUtil.errorLogInfo("", TAG, e);
  4692. }
  4693. }
  4694. }
  4695. BroadcastReceiver SIPStunBR = new BroadcastReceiver() {
  4696. @Override
  4697. public void onReceive(Context context, Intent intent) {
  4698. try {
  4699. String strActionName = intent.getAction();
  4700. // Log.i(TAG,"[SIPStunBR] strActionName [" + strActionName + "]");
  4701. if (strActionName.equals(Declare.BR.BR_ACK_WALLPADCALL_LIVE)) {
  4702. bWallPadCallLive = true;
  4703. nWallPadCallACKCnt = MAX_WALLPADCALL_LIVE_CNT;
  4704. // Log.w(TAG,"[WallPadCallLiveBRCheck] bWallPadCallLive [" + bWallPadCallLive + "]");
  4705. }
  4706. else if (strActionName.equals(Declare.BR.BR_BLOCK_SIPCALL)) {
  4707. bBLOCK_INVITE_MSG = true;
  4708. StunHandler.removeMessages(HANDLERMSG.RELEASE_BLOCK_INVITE_MSG);
  4709. sendHandlerMsgDelayed(HANDLERMSG.RELEASE_BLOCK_INVITE_MSG, 0, 0, 5000);
  4710. }
  4711. else {
  4712. Log.w(TAG,"[SIPStunBR] Not supported strActionName [" + strActionName + "]");
  4713. }
  4714. } catch (RuntimeException re) {
  4715. LogUtil.errorLogInfo("", TAG, re);
  4716. } catch (Exception e) {
  4717. Log.e(TAG, "[Exception] BroadcastReceiver -> SIPStunBR");
  4718. //e.printStackTrace();
  4719. LogUtil.errorLogInfo("", TAG, e);
  4720. }
  4721. }
  4722. };
  4723. private void registerWallPadCallLiveBRReceiver() {
  4724. try {
  4725. LOG_INFO("[registerWallPadCallLiveBRReceiver] ========== START ==========");
  4726. IntentFilter mIntentFilter = new IntentFilter();
  4727. mIntentFilter.addAction(Declare.BR.BR_ACK_WALLPADCALL_LIVE);
  4728. mIntentFilter.addAction(Declare.BR.BR_BLOCK_SIPCALL);
  4729. registerReceiver(SIPStunBR, mIntentFilter);
  4730. bCheckThreadRun = true;
  4731. mcheckWallPadLive = new checkWallPadLive();
  4732. mcheckWallPadLive.start();
  4733. } catch (RuntimeException re) {
  4734. LogUtil.errorLogInfo("", TAG, re);
  4735. } catch (Exception e) {
  4736. Log.e(TAG, "[Exception] registerWallPadCallLiveBRReceiver()");
  4737. //e.printStackTrace();
  4738. LogUtil.errorLogInfo("", TAG, e);
  4739. }
  4740. }
  4741. private void unregisterWallPadCallLiveBRReceiver() {
  4742. try {
  4743. LOG_INFO("[unregisterBRReceiver] ========== START ==========");
  4744. unregisterReceiver(SIPStunBR);
  4745. bCheckThreadRun = false;
  4746. mcheckWallPadLive = null;
  4747. } catch (RuntimeException re) {
  4748. LogUtil.errorLogInfo("", TAG, re);
  4749. } catch (Exception e) {
  4750. Log.e(TAG, "[Exception] unregisterWallPadCallLiveBRReceiver()");
  4751. //e.printStackTrace();
  4752. LogUtil.errorLogInfo("", TAG, e);
  4753. }
  4754. }
  4755. public void updateBlockStatus() {
  4756. Log.v(TAG, "updateBlockStatus()");
  4757. for (int i = mClients.size() - 1; i >= 0; i--) {
  4758. try {
  4759. Bundle b = new Bundle();
  4760. b.putBoolean("ISBLOCK", bBLOCK_INVITE_MSG);
  4761. Message msg = null;
  4762. msg = Message.obtain(null, CMCore.BSSSIPStun_ICONTROLS_UPDATE_BLOCK_STATUS);
  4763. msg.setData(b);
  4764. mClients.get(i).send(msg);
  4765. } catch (RemoteException e) {
  4766. Log.e(TAG, "[RemoteException] updateBlockStatus()");
  4767. //e.printStackTrace();
  4768. LogUtil.errorLogInfo("", TAG, e);
  4769. mClients.remove(i);
  4770. } catch (Exception e) {
  4771. Log.e(TAG, "[Exception] updateBlockStatus()");
  4772. //e.printStackTrace();
  4773. LogUtil.errorLogInfo("", TAG, e);
  4774. }
  4775. }
  4776. }
  4777. }