SIPController.java 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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 = new SIPSound(bMobile);
  50. } catch (RuntimeException re) {
  51. LogUtil.errorLogInfo("", TAG, re);
  52. SIPStack.exceptionCountAtCurrentCall++;
  53. return;
  54. } catch (Exception e) {
  55. //System.err.println("SIPSouond unavailable: " + e);
  56. LogUtil.errorLogInfo("", TAG, e);
  57. SIPStack.exceptionCountAtCurrentCall++;
  58. return;
  59. }
  60. for (int i = 0; i < SIPStack.SIP_MEDIA_PORTS; i++) {
  61. SIPStack.SIP_MEDIA_PORTFLAG[i] = false;
  62. }
  63. return;
  64. }
  65. public static void init() {
  66. Log.i(TAG, "======== SYSTEM INFO. =======");
  67. Log.i(TAG, "modelName is : " + Build.MODEL);
  68. Log.i(TAG, "device is : " + Build.DEVICE);
  69. Log.i(TAG, "ProductName is : " + Build.PRODUCT);
  70. Log.i(TAG, "ID is : " + Build.ID);
  71. Log.i(TAG, "USER is : " + Build.USER);
  72. Log.i(TAG, "TAGS is : " + Build.TAGS);
  73. Log.i(TAG, "VERSION is : " + Build.VERSION.SDK_INT);
  74. Log.i(TAG, "INCREMENTAL is : " + Build.VERSION.INCREMENTAL);
  75. Log.i(TAG, "RELEASE is : " + Build.VERSION.RELEASE);
  76. SIPStack.hwModelName = Build.MODEL;
  77. SIPStack.hwId = Build.ID;
  78. SIPStack.firmVersion = Build.VERSION.RELEASE;
  79. }
  80. public static String getSHVE140SLocalIpAddress() {
  81. String validIp = null;
  82. boolean bWifi = false;
  83. boolean bEthernet = false;
  84. try {
  85. Enumeration en = NetworkInterface.getNetworkInterfaces();
  86. while (en.hasMoreElements()) {
  87. NetworkInterface intf = (NetworkInterface) en.nextElement();
  88. bWifi = false;
  89. bEthernet = false;
  90. if (intf != null && intf.getName().length() > 0 && intf.getName().startsWith("wlan") == true) {
  91. bWifi = true;
  92. } else if (intf != null && intf.getName().length() > 0 && intf.getName().startsWith("eth") == true) {
  93. bEthernet = true;
  94. }
  95. Enumeration enumIpAddr = intf.getInetAddresses();
  96. while (enumIpAddr.hasMoreElements()) {
  97. InetAddress inetAddress = (InetAddress) enumIpAddr.nextElement();
  98. String strIp = null;
  99. if (inetAddress.toString() != null && inetAddress.toString().length() > 1) {
  100. strIp = inetAddress.toString().substring(1);
  101. StringTokenizer st = new StringTokenizer(strIp, ".", true);
  102. int tokenCount = 0;
  103. String token = null;
  104. int ipdigit_0 = 0;
  105. int ipdigit_1 = 0;
  106. int ipdigit_2 = 0;
  107. int ipdigit_3 = 0;
  108. while (st.hasMoreTokens()) {
  109. token = st.nextToken().trim();
  110. if (token != null && token.length() > 0 && token.length() <= 3 && token.compareTo(".") != 0 && !token.contains(":")) {
  111. if (tokenCount == 0) {
  112. ipdigit_0 = Integer.parseInt(token.trim());
  113. } else if (tokenCount == 1) {
  114. ipdigit_1 = Integer.parseInt(token.trim());
  115. } else if (tokenCount == 2) {
  116. ipdigit_2 = Integer.parseInt(token.trim());
  117. } else if (tokenCount == 3) {
  118. ipdigit_3 = Integer.parseInt(token.trim());
  119. }
  120. tokenCount++;
  121. }
  122. }
  123. if (tokenCount == 4) {
  124. 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 &&
  125. !(ipdigit_0 == 127 && ipdigit_1 == 0 && ipdigit_2 == 0 && ipdigit_3 == 1)) { // wifi is wlan0
  126. boolean bLast = true;
  127. // that is sk and etc all case
  128. if (!bLast || bEthernet || bWifi) {
  129. validIp = ipdigit_0 + "." + ipdigit_1 + "." + ipdigit_2 + "." + ipdigit_3;
  130. return validIp;
  131. } else if (bLast) {
  132. validIp = ipdigit_0 + "." + ipdigit_1 + "." + ipdigit_2 + "." + ipdigit_3;
  133. }
  134. }
  135. }
  136. }
  137. }
  138. }
  139. } catch (SocketException exception) {
  140. SIPStack.exceptionCountAtCurrentCall++;
  141. }
  142. return validIp;
  143. }
  144. public static boolean decideCodecChange(Context context) {
  145. //Log.i("SIPCTRL","decideCodecChange...");
  146. boolean val = false;
  147. SIPStack.WIFI_SIGNAL_VALUE = 0;
  148. try {
  149. final ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
  150. final android.net.NetworkInfo wifi = connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
  151. if (wifi.isAvailable() == true) {
  152. if (wifi.isConnected() == true) {
  153. WifiManager wifim;
  154. wifim = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
  155. if (wifim != null) {
  156. WifiInfo info = wifim.getConnectionInfo();
  157. SIPStack.WIFI_SIGNAL_VALUE = WifiManager.calculateSignalLevel(info.getRssi(), 5);
  158. if (SIPStack.WIFI_SIGNAL_VALUE > SIPStack.WIFI_CALL_SIGNAL_MIN) {
  159. val = false;
  160. } else {
  161. val = true;
  162. }
  163. }
  164. }
  165. }
  166. } catch (RuntimeException re) {
  167. LogUtil.errorLogInfo("", TAG, re);
  168. } catch (Exception e) {
  169. Log.e(TAG, "[Exception decideCodecChange(context)");
  170. }
  171. SIPStack.networkInfoCheckTime = new Date();
  172. return val;
  173. }
  174. }