0

I am trying to register with my SIP account. I doudt it's a programming issue because I rewrote the SIP programme twice from scratch and took inspiration from different sources. AND!! I look over the permission actually in the APP in the setting option of my android phone and the permission "RECEIVE DATA FROM INTERNET" is NOT THERE!! even if I use the permission android.permission.INTERNET in my manifest file. I don't get it!! Further more, I am using a firebase DATABASE over the internet with this APP and I can read and write into it. How is this possible??

MORE SPECIFIC DESCRIPTION OF THE PROBLEM : The APP call the onRegistering then calls the onRegistrationFailed with error : SIP ERROR MSG : localProfileUri=sip:rafael.hogue@sip2sip.info errorCode=time out!! errorMessage=registration timed out

using this source code:

private Builder builder = null;
private void log_and_register()
{
    try
    {
        c.DEBUG().ftrace("VOIP Supported: " + SipManager.isVoipSupported(c.ma()));
        c.DEBUG().ftrace("SIP API Supported: " + SipManager.isApiSupported(c.ma()));

        mSipManager = SipManager.newInstance(c.ma());
        builder = new Builder(c.config().getSIP_UserName(), c.config().getSIP_Domain());
        builder.setPassword(c.config().getSIP_Password());
        //builder.setProtocol("UDP"); //"TCP");
        //builder.setPort(5060);   //5080  5070
        builder.setAutoRegistration(true);
        mSipProfile = builder.build();
    }
    catch (ParseException pe)
    {
        c.DEBUG().ftrace("incapable of parsing domain name, username or password!");
        c.DEBUG().ASSERT(0 == 1);
    }
    try
    {
        Intent intent = new Intent();
        intent.setAction("android.SipDemo.INCOMING_CALL");
        PendingIntent pendingIntent = PendingIntent.getBroadcast(c.ma(), 0, intent, Intent.FILL_IN_DATA);
        mSipManager.open(mSipProfile, pendingIntent, null);
    }
    catch (SipException se)
    {
        c.DEBUG().ftrace("WALKIE TALKIE NOT WORKING - Sip Exception!!");
        c.DEBUG().ASSERT(0 == 1);
    }
    if (ContextCompat.checkSelfPermission(c.ma(), Manifest.permission.USE_SIP) == PackageManager.PERMISSION_GRANTED)
        c.DEBUG().ftrace("GRANTED!!!");
    else
        ActivityCompat.requestPermissions(c.ma(), new String[]{Manifest.permission.USE_SIP}, 1);
    try
    {
        if (mSipManager.isRegistered(mSipProfile.getUriString()))
        {
            c.DEBUG().ftrace("already registered !!" + mSipManager.isRegistered(mSipProfile.getUriString()));
            return;
        }
    }
    catch (Exception e)
    {
        c.DEBUG().ftrace("NO!!");
    }
    try
    {
        //mSipManager.register(mSipProfile, 30, new SipRegistrationListener(){
        //mSipManager.register(mSipProfile, 30000, new SipRegistrationListener(){
        c.DEBUG().ftrace("THIS IS THE TRACE BEFORE REGISTATION : " + mSipProfile.getUriString());
        mSipManager.setRegistrationListener(mSipProfile.getUriString(), new SipRegistrationListener()
        {
            public void onRegistering(String localProfileUri)
            {
                c.DEBUG().ftrace("Registering with SIP Server...");
            }
            // next version has it!!
            public void onRegistrationTimeout()
            {
            }
            public void onRegistrationDone(String localProfileUri, long expiryTime)
            {
                c.DEBUG().ftrace("SIP Ready");
            }
            public void onRegistrationFailed(String localProfileUri, int errorCode, String errorMessage)
            {
                // -9 signifie qu'il y a un appel en cours
                c.DEBUG().ftrace("CANNOT REGISTER domain=" + c.config().getSIP_Domain() + " / username=" + c.config().getSIP_UserName());
                c.DEBUG().ftrace("SIP ERROR MSG : localProfileUri=" + localProfileUri + "   errorCode=" + errCode(errorCode) + "  errorMessage=" + errorMessage);
            }
        });
    }
    catch (Exception e)
    {
        c.DEBUG().ftrace("Cannot initialise wakie talkie!");
        c.DEBUG().ASSERT(0 == 1);
    }
    // https:github.com/aosp-mirror/platform_development/commit/a025796211f15c2796f8ea3208c066801aa250b6
}

I include those permission:

<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAPTURE_AUDIO_OUTPUT" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />

<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.USE_SIP" />
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.MODIFY_PHONE_STATE" tools:ignore="ProtectedPermissions" />

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.REBOOT" tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.STATUS_BAR" tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.WAKE_LOCK" />

<uses-feature android:name="android.hardware.sip.voip" android:required="true" />
<uses-feature android:name="android.hardware.wifi" android:required="true" />
<uses-feature android:name="android.hardware.microphone" android:required="true" />

Below there is a reference to my first problem that I try solving with the Audio Streaming solution that has work well on a local WIFI network BUT it doesn't see my mobile IP. I don't want to have only local WIFI walki talki (and phone)so the previous solution doen't work for me!!

reference: sip registration failure - tried 3 diff. account

Rafael
  • 1
  • 2

1 Answers1

0

First thing when we get error code "in progress" it means that there is a call in progress that was initiated by a previous execution of the program. Then we have to go in setting of the smatphone and delete the call. The switch is in different location on different smartphone (so you have to search into the setting) On the "zenfone 3" smatphone (for exemple) the switch is in: "Setting->Connections->Call->Calling accounts->SIP accounts" then you have to click on the sip account and delete it. It is written "This account is currently in use by the [appname] app" under the sip account information.

Also after you delete the previous call then you will probably continue having a time out but this time the onRegistering() method will be called before the time out. So in order to fix that you will have to log into the sip2sip.info account (or your sip account) and search into it. In the sip2sip.info you will find that you need to use the proxy use bellow for example but it differ with every account. These are the setting for that sip account for exemple:

        SipProfile.Builder builder = new SipProfile.Builder(c.config().getSIP_UserName(), c.config().getSIP_Domain());
        builder.setPassword(c.config().getSIP_Password());

        // this line is needed for the "sip2sip.info" sip account
        builder.setOutboundProxy("proxy.sipthor.net");

        mSipProfile = builder.build();

These verification can be of use also:

    c.ft().forcePermission(Manifest.permission.USE_SIP);
    c.ft().forcePermission( Manifest.permission.INTERNET);
    c.DEBUG().ftrace("VOIP Supported: " + SipManager.isVoipSupported(c.ma()));
    c.DEBUG().ftrace("SIP API Supported: " + SipManager.isApiSupported(c.ma()));


void forcePermission(String permission)
{
    if (ContextCompat.checkSelfPermission(c.ma(), permission) == PackageManager.PERMISSION_GRANTED)
    {
        c.DEBUG().ftrace(permission + " GRANTED !!!");
    }
    else
    {
        c.DEBUG().ftrace("FORCING GRANTING "+permission+" !!!");
        ActivityCompat.requestPermissions(c.ma(), new String[]{permission}, 1);
    }
}

Note : c.ma() is a pointer to my MainActivity class.

This can also be usefull in order to understand the return code when the registration fails:

// FOR MORE DETAILS SEE
// https://stackoverflow.com/questions/20563566/sip-error-while-registration
// https://stackoverflow.com/questions/19502482/how-to-send-instant-message-via-sip/20443357#20443357
// https://developer.android.com/reference/android/net/sip/SipErrorCode
// https://en.wikipedia.org/wiki/List_of_SIP_response_codes#4xx.E2.80.94Client_Failure_Responses
private String errCode(int iErrorCode)
{
    String sErr = "";
    switch (iErrorCode)
    {
        case CLIENT_ERROR:
            sErr = "client error!!";
            break;
        case CROSS_DOMAIN_AUTHENTICATION:
            sErr = "cross domain authentification!!";
            break;
        case DATA_CONNECTION_LOST:
            sErr = "data connection lost!!";
            break;
        case INVALID_CREDENTIALS:
            sErr = "invalid credentials!!";
            break;
        case INVALID_REMOTE_URI:
            sErr = "invalid remote uri!!";
            break;
        case IN_PROGRESS:
            sErr = "In progress!!";
            break;
        case NO_ERROR:
            sErr = "No error!!";
            break;
        case PEER_NOT_REACHABLE:
            sErr = "peer not reachable!!";
            break;
        case SERVER_ERROR:
            sErr = "server error!!";
            break;
        case SERVER_UNREACHABLE:
            sErr = "server unreachable!!";
            break;
        case SOCKET_ERROR:
            sErr = "socket error!!";
            break;
        case TIME_OUT:
            sErr = "time out!!";
            break;
        case TRANSACTION_TERMINTED:
            sErr = "No transaction terminated!!";
            break;
        default:
            sErr = "No error detected!!";
            break;
    }
    return (sErr);
}



            @Override
            public void onRegistrationFailed(String localProfileUri, int errorCode, String errorMessage)
            {
                // -9 signifie qu'il y a un appel en cours
                c.DEBUG().ftrace("CANNOT REGISTER domain=" + c.config().getSIP_Domain() + " / username=" + c.config().getSIP_UserName());
                c.DEBUG().ftrace("SIP ERROR MSG : localProfileUri=" + localProfileUri + " err=" + errorCode + "   errorCode=" + errCode(errorCode) + "  errorMessage=" + errorMessage);
                updateStatus(STATE_CONNECTED_FAILURE);
                if (errorCode == -9)
                    closeLocalProfile();
            }

Also your sip account has to be set to true with certain services when you log into your sip account and sometime we also have to respond to an email automatically generated to activate the account.

Then the registration for the sip calling system works !

Good luck!!

Rafael
  • 1
  • 2