SIPStun.java 277 KB

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