androidsipvoipsip-serverportsip

Portsip SDK on Android 10. Registration or Refresh does not get back response


This is my login function:

 fun login(
        userName: String, password: String, serverHost: String?, serverPort: Int, transportType: Int, displayName: String, authName: String, userDomain: String,
        srtpPolicy: Int, localP: Int?, loginHandler: SIPLoginHandler?) {
    App.retryRegistrationOnFailure = true
    isLoginInProgress = true
    this.userName = null

    broadcastAuthUpdate()

    this.loginHandler = loginHandler

    val rm = Random()
    var localPort = 5060 + rm.nextInt(60000)
    if (localP != null && localP != -1) {
        localPort = localP
    }
    val prefs = androidx.preference.PreferenceManager.getDefaultSharedPreferences(this@SIPManager)
    val editor = prefs.edit()
    editor.putInt(getString(R.string.keySIPLocalPort), localPort)
    editor.apply()
    var result = 0
    try {
        portSipSdk!!.DeleteCallManager()
    } catch (e: Exception) {
        FL.e(TAG, "handleIncomingCall Error trying to delete the call manager. Was not registered? Error: " + e.message)
    }

    portSipSdk!!.CreateCallManager(this)
    portSipSdk!!.setOnPortSIPEvent(this)

    val dataPath = getExternalFilesDir(null)!!.absolutePath
    result = portSipSdk!!
            .initialize(transportType, "0.0.0.0", localPort, PortSipEnumDefine.ENUM_LOG_LEVEL_NONE, dataPath, MAX_SESSIONS, agentName, 0, 0, dataPath, "",
                    false, null)
    if (result != PortSipErrorcode.ECoreErrorNone) {
        FL.d(TAG, "handleIncomingCall Error initializing, code = $result")
        val message = "Error initializing, code = $result"
        portSipSdk!!.DeleteCallManager()
        sessions.clear()
        isLoginInProgress = false
        loginHandler?.onLoginFailure(message)
        broadcastAuthUpdate()
        return
    }

    val stunServerPort = 0
    val stunServer = ""

    result = portSipSdk!!.setLicenseKey(licenceKey)
    if (result != PortSipErrorcode.ECoreErrorNone) {
        FL.d(TAG, "handleIncomingCall Failed to set licence, code = $result")
    }
    if (result == PortSipErrorcode.ECoreWrongLicenseKey) {
        val message = "Failed to set licence, code = $result"
        portSipSdk!!.DeleteCallManager()
        sessions.clear()
        isLoginInProgress = false
        loginHandler?.onLoginFailure(message)
        broadcastAuthUpdate()
        return
    }

    result = portSipSdk!!.setUser(userName, displayName, authName, password, userDomain, serverHost, serverPort, stunServer, stunServerPort, "", 0)
    if (result != PortSipErrorcode.ECoreErrorNone) {
        FL.d(TAG, "handleIncomingCall setUser failure ErrorCode = $result")
        val message = "setUser failure ErrorCode = $result"
        portSipSdk!!.DeleteCallManager()
        sessions.clear()
        isLoginInProgress = false
        loginHandler?.onLoginFailure(message)
        broadcastAuthUpdate()
        return
    }
    portSipSdk!!.setVideoDeviceId(1)
    portSipSdk!!.setSrtpPolicy(srtpPolicy)
    val preferences = PreferenceManager.getDefaultSharedPreferences(this)
    ConfigPreferences(this, preferences, portSipSdk!!)

    portSipSdk!!.enable3GppTags(false)
    initialiseKeepAlive()

    portSipSdk!!.setInstanceId(instanceId)
    FL.d(TAG, "*******************************DATA is: \nUN $userName, \nPASS $password, \nSERVERHOST $serverHost, \nSERVERPORT $serverPort ,\nTransortTYPE $transportType, \nDisplay $displayName, \nAUTH $authName, \nuserDpm $userDomain, \nsrtp $srtpPolicy, \nhandler $loginHandler, \nlocalPort $localPort, \nstunserver $stunServer, \nstunport $stunServerPort")
    if (!portSIPRegisterRegisterServer(loginHandler))
    //if it fails, I return, not setting the username
    {
        FL.d(TAG, "*******************************FAILED TO REREGISTER SERVERL ")
        return
    }

    this.userName = userName
}

portSIPREgisterRegisterServer function is:

  private fun portSIPRegisterRegisterServer(loginHandler: SIPLoginHandler?): Boolean {
    val result: Int
    result = portSipSdk!!.registerServer(3600, 3)
    FL.d("handleIncoming portSIPRegisterRegisterServer Called")
    if (result != PortSipErrorcode.ECoreErrorNone) {
        val message = "handleIncomingCall registerServer failure ErrorCode =$result"
        portSipSdk!!.unRegisterServer()
        portSipSdk!!.DeleteCallManager()
        sessions.clear()
        isLoginInProgress = false
        loginHandler?.onLoginFailure(message)
        broadcastAuthUpdate()
        FL.d(TAG, "*******************************FAILED portSIPRegisterRegisterServer" + result)
        return false
    }
    registrationTimePassed = System.currentTimeMillis()
    registrationType = SIPREGISTRATION.LOGIN
    return true
}

That I call with this parameters:

  SIPManager.instance!!
            .login(userName!!, password!!, hostName, portNumber, transportType, "", "", "", srtpPolicy, localPortNumber, object : SIPLoginHandler {
                override fun onLoginSuccess(message: String) {
                    FL.d(TAG, "handleIncomingCall Login TRIED and SUCCESS: $message")
                    sipLoginHandler.onLoginSuccess(message)
                }

                override fun onLoginFailure(errorMessage: String) {
                    FL.d(TAG, "handleIncomingCall Login TRIED and FAILED: $errorMessage")
                    SIPManager.instance!!.loginToXelionServer(sipLoginHandler)
                }
            })

This is the DATA I send to login:

 DATA is: 
UN <myuser>, 
PASS <mypass>, 
SERVERHOST <myserver>, 
SERVERPORT 5060 ,
TransortTYPE 0, 
Display , 
AUTH , 
userDpm , 
srtp 0, 
handler com.xelion.android.pushmessages.IncomingPhoneCallPushHandler$tryToReRegisterBecauseRefreshFailed$1@cb36a8d, 
localPort 29292, 
stunserver , 
stunport 0

Usually I get this back as a response:

handleIncomingCall Login TRIED and SUCCESS: Status: none code: 200

But when I try on a Pixel 3, not connected to PC (not debugging) And screen was closed for more than 4-5 minutes, It will call the register function and I see this in the log:

    FL.d("handleIncoming portSIPRegisterRegisterServer Called")

But I do not get back a response from the Register , either Success or Failure.

Any ideea how to fix this? I have this in my manifest:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />

I feel that it ignores the register call, while the screen is off? IF I open the screen I get the onLoginSuccess


Solution

  • What I noticed that it would just wait, and only actually make the network call when I received the Missed Calls notification. So I created a basic notification from my FCM to let the user know that the VOIP Service is registering. After the user has visual input, registering the voip service works flawlessly, it receives back a response in around 200-300 ms.