Android 上的 Portsip SDK 10. 注册或刷新没有得到回复

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

这是我的登录功能:

 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 函数是:

  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
}

我用这个参数调用的:

  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)
                }
            })

这是我发送给登录的数据:

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

通常我会收到回复:

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

但是当我在 Pixel 3 上尝试时,未连接到 PC(未调试)并且屏幕关闭超过 4-5 分钟,它会调用注册函数,我在日志中看到:

    FL.d("handleIncoming portSIPRegisterRegisterServer Called")

但是我没有从 Register 得到响应,无论是 Success 还是 Failure。

知道如何解决这个问题吗?我的清单中有这个:

<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" />

感觉是在熄屏的情况下忽略注册调用?如果我打开屏幕,我会收到 onLoginSuccess

我注意到它只会等待,只有在我收到未接来电通知时才真正拨打网络电话。 因此,我从我的 FCM 创建了一个基本通知,让用户知道 VOIP 服务正在注册。用户进行视觉输入后,注册 voip 服务完美无缺,它会在大约 200-300 毫秒内收到回复。