123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- package kr.co.icontrols.callengine.sip;
- import java.net.DatagramPacket;
- import java.net.InetAddress;
- import java.net.NetworkInterface;
- import java.net.SocketException;
- import java.util.Date;
- import java.util.Enumeration;
- import java.util.StringTokenizer;
- import java.util.Timer;
- import android.app.Activity;
- import android.app.Notification;
- import android.content.Context;
- import android.net.ConnectivityManager;
- import android.net.wifi.WifiInfo;
- import android.net.wifi.WifiManager;
- import android.os.Build;
- import android.os.Vibrator;
- import android.util.Log;
- import com.util.LogUtil;
- import bssoft.stack.sip.*;
- public class SIPController {
- static String TAG = "SIPController";
- public static SIPSound sipSound = null;
- public static RTPManager audioRTPManager = null;
- public static SIPCall sipCall = null;
- public static SIPCall pendingCall = null;
- public static SIPCall MultiCall = null; // 멀티콜 정보를 임시로 담아두고, 멀티콜을 통화시작전에 메인콜(sipCall)을 종료하고 메인콜에 대입한다.
- public static Notification notification = null;
- public static Timer BACKGROUNDTimer = null;
- public static Activity ownerContent = null;
- public static Activity mainContent = null;
- public static Vibrator vibe = null;
- /**
- * JEFF, 2020.01.02
- * MoIP 멀티콜 지원을 하지 않기위해 아래 플래그를 false로 변경한다.
- */
- public static boolean bMulticallSupport = false;
- public static Forward forward = new Forward();
- public static DatagramPacket dp = null;
- public static int latestMenu = 0;
- public static boolean bMulticallBusyResponse = true;
- public static boolean bSinglecallBusyResponse = false;
- public static boolean bMobileCall = false;
- public static int nFilterMode = 0;
- public static int[] nFilterPreset = null;
- public static void initSound(boolean bMobile) { // SOUND DEVICE PREPARE
- try {
- Log.d(TAG, "[initSound] bMobile [" + bMobile + "]");
- sipSound = new SIPSound(bMobile);
- } catch (RuntimeException re) {
- LogUtil.errorLogInfo("", TAG, re);
- SIPStack.exceptionCountAtCurrentCall++;
- return;
- } catch (Exception e) {
- //System.err.println("SIPSouond unavailable: " + e);
- LogUtil.errorLogInfo("", TAG, e);
- SIPStack.exceptionCountAtCurrentCall++;
- return;
- }
- for (int i = 0; i < SIPStack.SIP_MEDIA_PORTS; i++) {
- SIPStack.SIP_MEDIA_PORTFLAG[i] = false;
- }
- return;
- }
- public static void init() {
- Log.i(TAG, "======== SYSTEM INFO. =======");
- Log.i(TAG, "modelName is : " + Build.MODEL);
- Log.i(TAG, "device is : " + Build.DEVICE);
- Log.i(TAG, "ProductName is : " + Build.PRODUCT);
- Log.i(TAG, "ID is : " + Build.ID);
- Log.i(TAG, "USER is : " + Build.USER);
- Log.i(TAG, "TAGS is : " + Build.TAGS);
- Log.i(TAG, "VERSION is : " + Build.VERSION.SDK_INT);
- Log.i(TAG, "INCREMENTAL is : " + Build.VERSION.INCREMENTAL);
- Log.i(TAG, "RELEASE is : " + Build.VERSION.RELEASE);
- SIPStack.hwModelName = Build.MODEL;
- SIPStack.hwId = Build.ID;
- SIPStack.firmVersion = Build.VERSION.RELEASE;
- }
- public static String getSHVE140SLocalIpAddress() {
- String validIp = null;
- boolean bWifi = false;
- boolean bEthernet = false;
- try {
- Enumeration en = NetworkInterface.getNetworkInterfaces();
- while (en.hasMoreElements()) {
- NetworkInterface intf = (NetworkInterface) en.nextElement();
- bWifi = false;
- bEthernet = false;
- if (intf != null && intf.getName().length() > 0 && intf.getName().startsWith("wlan") == true) {
- bWifi = true;
- } else if (intf != null && intf.getName().length() > 0 && intf.getName().startsWith("eth") == true) {
- bEthernet = true;
- }
- Enumeration enumIpAddr = intf.getInetAddresses();
- while (enumIpAddr.hasMoreElements()) {
- InetAddress inetAddress = (InetAddress) enumIpAddr.nextElement();
- String strIp = null;
- if (inetAddress.toString() != null && inetAddress.toString().length() > 1) {
- strIp = inetAddress.toString().substring(1);
- StringTokenizer st = new StringTokenizer(strIp, ".", true);
- int tokenCount = 0;
- String token = null;
- int ipdigit_0 = 0;
- int ipdigit_1 = 0;
- int ipdigit_2 = 0;
- int ipdigit_3 = 0;
- while (st.hasMoreTokens()) {
- token = st.nextToken().trim();
- if (token != null && token.length() > 0 && token.length() <= 3 && token.compareTo(".") != 0 && !token.contains(":")) {
- if (tokenCount == 0) {
- ipdigit_0 = Integer.parseInt(token.trim());
- } else if (tokenCount == 1) {
- ipdigit_1 = Integer.parseInt(token.trim());
- } else if (tokenCount == 2) {
- ipdigit_2 = Integer.parseInt(token.trim());
- } else if (tokenCount == 3) {
- ipdigit_3 = Integer.parseInt(token.trim());
- }
- tokenCount++;
- }
- }
- if (tokenCount == 4) {
- 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 &&
- !(ipdigit_0 == 127 && ipdigit_1 == 0 && ipdigit_2 == 0 && ipdigit_3 == 1)) { // wifi is wlan0
- boolean bLast = true;
- // that is sk and etc all case
- if (!bLast || bEthernet || bWifi) {
- validIp = ipdigit_0 + "." + ipdigit_1 + "." + ipdigit_2 + "." + ipdigit_3;
- return validIp;
- } else if (bLast) {
- validIp = ipdigit_0 + "." + ipdigit_1 + "." + ipdigit_2 + "." + ipdigit_3;
- }
- }
- }
- }
- }
- }
- } catch (SocketException exception) {
- SIPStack.exceptionCountAtCurrentCall++;
- }
- return validIp;
- }
- public static boolean decideCodecChange(Context context) {
- //Log.i("SIPCTRL","decideCodecChange...");
- boolean val = false;
- SIPStack.WIFI_SIGNAL_VALUE = 0;
- try {
- final ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
- final android.net.NetworkInfo wifi = connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
- if (wifi.isAvailable() == true) {
- if (wifi.isConnected() == true) {
- WifiManager wifim;
- wifim = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
- if (wifim != null) {
- WifiInfo info = wifim.getConnectionInfo();
- SIPStack.WIFI_SIGNAL_VALUE = WifiManager.calculateSignalLevel(info.getRssi(), 5);
- if (SIPStack.WIFI_SIGNAL_VALUE > SIPStack.WIFI_CALL_SIGNAL_MIN) {
- val = false;
- } else {
- val = true;
- }
- }
- }
- }
- } catch (RuntimeException re) {
- LogUtil.errorLogInfo("", TAG, re);
- } catch (Exception e) {
- Log.e(TAG, "[Exception decideCodecChange(context)");
- }
- SIPStack.networkInfoCheckTime = new Date();
- return val;
- }
- }
|