SIPController.java 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. package kr.co.icontrols.callengine.sip;
  2. import java.net.DatagramPacket;
  3. import java.net.InetAddress;
  4. import java.net.NetworkInterface;
  5. import java.net.SocketException;
  6. import java.util.Date;
  7. import java.util.Enumeration;
  8. import java.util.StringTokenizer;
  9. import java.util.Timer;
  10. import android.app.Activity;
  11. import android.app.Notification;
  12. import android.content.Context;
  13. import android.net.ConnectivityManager;
  14. import android.net.wifi.WifiInfo;
  15. import android.net.wifi.WifiManager;
  16. import android.os.Build;
  17. import android.os.Vibrator;
  18. import android.util.Log;
  19. import com.util.LogUtil;
  20. import bssoft.stack.sip.*;
  21. public class SIPController {
  22. static String TAG = "SIPController";
  23. public static SIPSound sipSound = null;
  24. public static RTPManager audioRTPManager = null;
  25. public static SIPCall sipCall = null;
  26. public static SIPCall pendingCall = null;
  27. public static SIPCall MultiCall = null; // 멀티콜 정보를 임시로 담아두고, 멀티콜을 통화시작전에 메인콜(sipCall)을 종료하고 메인콜에 대입한다.
  28. public static Notification notification = null;
  29. public static Timer BACKGROUNDTimer = null;
  30. public static Activity ownerContent = null;
  31. public static Activity mainContent = null;
  32. public static Vibrator vibe = null;
  33. /**
  34. * JEFF, 2020.01.02
  35. * MoIP 멀티콜 지원을 하지 않기위해 아래 플래그를 false로 변경한다.
  36. */
  37. public static boolean bMulticallSupport = false;
  38. public static Forward forward = new Forward();
  39. public static DatagramPacket dp = null;
  40. public static int latestMenu = 0;
  41. public static boolean bMulticallBusyResponse = true;
  42. public static boolean bSinglecallBusyResponse = false;
  43. public static boolean bMobileCall = false;
  44. public static int nFilterMode = 0;
  45. public static int[] nFilterPreset = null;
  46. public static void initSound(boolean bMobile) { // SOUND DEVICE PREPARE
  47. try {
  48. Log.d(TAG, "[initSound] bMobile [" + bMobile + "]");
  49. sipSound = null;
  50. sipSound = new SIPSound(bMobile);
  51. } catch (RuntimeException re) {
  52. LogUtil.errorLogInfo("", TAG, re);
  53. SIPStack.exceptionCountAtCurrentCall++;
  54. return;
  55. } catch (Exception e) {
  56. //System.err.println("SIPSouond unavailable: " + e);
  57. LogUtil.errorLogInfo("", TAG, e);
  58. SIPStack.exceptionCountAtCurrentCall++;
  59. return;
  60. }
  61. for (int i = 0; i < SIPStack.SIP_MEDIA_PORTS; i++) {
  62. SIPStack.SIP_MEDIA_PORTFLAG[i] = false;
  63. }
  64. return;
  65. }
  66. public static void init() {
  67. Log.i(TAG, "======== SYSTEM INFO. =======");
  68. Log.i(TAG, "modelName is : " + Build.MODEL);
  69. Log.i(TAG, "device is : " + Build.DEVICE);
  70. Log.i(TAG, "ProductName is : " + Build.PRODUCT);
  71. Log.i(TAG, "ID is : " + Build.ID);
  72. Log.i(TAG, "USER is : " + Build.USER);
  73. Log.i(TAG, "TAGS is : " + Build.TAGS);
  74. Log.i(TAG, "VERSION is : " + Build.VERSION.SDK_INT);
  75. Log.i(TAG, "INCREMENTAL is : " + Build.VERSION.INCREMENTAL);
  76. Log.i(TAG, "RELEASE is : " + Build.VERSION.RELEASE);
  77. SIPStack.hwModelName = Build.MODEL;
  78. SIPStack.hwId = Build.ID;
  79. SIPStack.firmVersion = Build.VERSION.RELEASE;
  80. }
  81. public static String getSHVE140SLocalIpAddress() {
  82. String validIp = null;
  83. boolean bWifi = false;
  84. boolean bEthernet = false;
  85. try {
  86. Enumeration en = NetworkInterface.getNetworkInterfaces();
  87. while (en.hasMoreElements()) {
  88. NetworkInterface intf = (NetworkInterface) en.nextElement();
  89. bWifi = false;
  90. bEthernet = false;
  91. if (intf != null && intf.getName().length() > 0 && intf.getName().startsWith("wlan") == true) {
  92. bWifi = true;
  93. } else if (intf != null && intf.getName().length() > 0 && intf.getName().startsWith("eth") == true) {
  94. bEthernet = true;
  95. }
  96. Enumeration enumIpAddr = intf.getInetAddresses();
  97. while (enumIpAddr.hasMoreElements()) {
  98. InetAddress inetAddress = (InetAddress) enumIpAddr.nextElement();
  99. String strIp = null;
  100. if (inetAddress.toString() != null && inetAddress.toString().length() > 1) {
  101. strIp = inetAddress.toString().substring(1);
  102. StringTokenizer st = new StringTokenizer(strIp, ".", true);
  103. int tokenCount = 0;
  104. String token = null;
  105. int ipdigit_0 = 0;
  106. int ipdigit_1 = 0;
  107. int ipdigit_2 = 0;
  108. int ipdigit_3 = 0;
  109. while (st.hasMoreTokens()) {
  110. token = st.nextToken().trim();
  111. if (token != null && token.length() > 0 && token.length() <= 3 && token.compareTo(".") != 0 && !token.contains(":")) {
  112. if (tokenCount == 0) {
  113. ipdigit_0 = Integer.parseInt(token.trim());
  114. } else if (tokenCount == 1) {
  115. ipdigit_1 = Integer.parseInt(token.trim());
  116. } else if (tokenCount == 2) {
  117. ipdigit_2 = Integer.parseInt(token.trim());
  118. } else if (tokenCount == 3) {
  119. ipdigit_3 = Integer.parseInt(token.trim());
  120. }
  121. tokenCount++;
  122. }
  123. }
  124. if (tokenCount == 4) {
  125. if (ipdigit_0 > 0 && ipdigit_0 <= 255 && ipdigit_1 >= 0 && ipdigit_1 <= 255 && ipdigit_2 >= 0 && ipdigit_2 <= 255 && ipdigit_3 >= 0 && ipdigit_3 <= 255 &&
  126. !(ipdigit_0 == 127 && ipdigit_1 == 0 && ipdigit_2 == 0 && ipdigit_3 == 1)) { // wifi is wlan0
  127. boolean bLast = true;
  128. // that is sk and etc all case
  129. if (!bLast || bEthernet || bWifi) {
  130. validIp = ipdigit_0 + "." + ipdigit_1 + "." + ipdigit_2 + "." + ipdigit_3;
  131. return validIp;
  132. } else if (bLast) {
  133. validIp = ipdigit_0 + "." + ipdigit_1 + "." + ipdigit_2 + "." + ipdigit_3;
  134. }
  135. }
  136. }
  137. }
  138. }
  139. }
  140. } catch (SocketException exception) {
  141. SIPStack.exceptionCountAtCurrentCall++;
  142. }
  143. return validIp;
  144. }
  145. public static boolean decideCodecChange(Context context) {
  146. //Log.i("SIPCTRL","decideCodecChange...");
  147. boolean val = false;
  148. SIPStack.WIFI_SIGNAL_VALUE = 0;
  149. try {
  150. final ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
  151. final android.net.NetworkInfo wifi = connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
  152. if (wifi.isAvailable() == true) {
  153. if (wifi.isConnected() == true) {
  154. WifiManager wifim;
  155. wifim = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
  156. if (wifim != null) {
  157. WifiInfo info = wifim.getConnectionInfo();
  158. SIPStack.WIFI_SIGNAL_VALUE = WifiManager.calculateSignalLevel(info.getRssi(), 5);
  159. if (SIPStack.WIFI_SIGNAL_VALUE > SIPStack.WIFI_CALL_SIGNAL_MIN) {
  160. val = false;
  161. } else {
  162. val = true;
  163. }
  164. }
  165. }
  166. }
  167. } catch (RuntimeException re) {
  168. LogUtil.errorLogInfo("", TAG, re);
  169. } catch (Exception e) {
  170. Log.e(TAG, "[Exception decideCodecChange(context)");
  171. }
  172. SIPStack.networkInfoCheckTime = new Date();
  173. return val;
  174. }
  175. }