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