BelledonneCommunications / linphone-android

Linphone.org mirror for linphone-android (https://gitlab.linphone.org/BC/public/linphone-android)
https://linphone.org
GNU General Public License v3.0
1.12k stars 683 forks source link

How to know the reason of connection failed ? #689

Closed Atepheh closed 5 years ago

Atepheh commented 5 years ago

for example when connection failed in status bar write "Connection failed (401 unauthorized)" or "Connection failed (408 Time out)"

DroidPulkit commented 5 years ago

I think it is writen with it 401 unauthorized : Probably the username and password for the domain is wrong 408 Time out : Server didn't respond in x seconds, increase the timeout setting, or check the server why it is not responding back

Atepheh commented 5 years ago

I may not have expressed myself clearly. I know why 401 or 408 errors happen. I wanna put a Log inside the code that when "Connection Failed" this Log tell me the reason of connection failed. for example if connection failed because of 401 error it tell me "401 error". I don't know where should I put this Log. I found this code inside "StatusBarFragment.java" :

CoreListenerStub mListener =
                new CoreListenerStub() {
                    @Override
                    public void onRegistrationStateChanged(
                            final Core core,
                            final ProxyConfig proxy,
                            final RegistrationState state,
                            String smessage) {
                        if (core.getProxyConfigList() == null) {
                            mStatusLed.setImageResource(R.drawable.led_disconnected);
                            mStatusText.setText(getString(R.string.no_account));
                        } else {
                            mStatusLed.setVisibility(View.VISIBLE);
                        }

                        if (core.getDefaultProxyConfig() != null
                                && core.getDefaultProxyConfig().equals(proxy)) {
                            mStatusLed.setImageResource(getStatusIconResource(state));
                            mStatusText.setText(getStatusIconText(state));
                        } else if (core.getDefaultProxyConfig() == null) {
                            mStatusLed.setImageResource(getStatusIconResource(state));
                            mStatusText.setText(getStatusIconText(state));
                        }

                        try {
                            mStatusText.setOnClickListener(
                                    new OnClickListener() {
                                        @Override
                                        public void onClick(View v) {
                                            Core core = LinphoneManager.getCore();
                                            if (core != null) {
                                                core.refreshRegisters();
                                            }
                                        }
                                    });
                        } catch (IllegalStateException ise) {
                            Log.e(ise);
                        }
                    }

                    @Override
                    public void onNotifyReceived(
                            Core core, Event ev, String eventName, Content content) {

                        if (!content.getType().equals("application")) return;
                        if (!content.getSubtype().equals("simple-message-summary")) return;

                        if (content.getSize() == 0) return;

                        int unreadCount = 0;
                        String data = content.getStringBuffer().toLowerCase();
                        String[] voiceMail = data.split("voice-message: ");
                        if (voiceMail.length >= 2) {
                            final String[] intToParse = voiceMail[1].split("/", 0);
                            try {
                                unreadCount = Integer.parseInt(intToParse[0]);
                            } catch (NumberFormatException nfe) {
                                Log.e("[Status Fragment] " + nfe);
                            }
                            if (unreadCount > 0) {
                                mVoicemailCount.setText(String.valueOf(unreadCount));
                                mVoicemail.setVisibility(View.VISIBLE);
                                mVoicemailCount.setVisibility(View.VISIBLE);
                            } else {
                                mVoicemail.setVisibility(View.GONE);
                                mVoicemailCount.setVisibility(View.GONE);
                            }
                        }
                    }
                };

RegistrationState.class is :

public enum RegistrationState {
    None(0),
    Progress(1),
    Ok(2),
    Cleared(3),
    Failed(4);

    protected final int mValue;

    private RegistrationState(int value) {
        this.mValue = value;
    }

    public static RegistrationState fromInt(int value) throws RuntimeException {
        switch(value) {
        case 0:
            return None;
        case 1:
            return Progress;
        case 2:
            return Ok;
        case 3:
            return Cleared;
        case 4:
            return Failed;
        default:
            throw new RuntimeException("Unhandled enum value " + value + " for RegistrationState");
        }
    }

    public int toInt() {
        return this.mValue;
    }
}
DroidPulkit commented 5 years ago

Check this out if this helps, I have implemented something similar in the version I am working on

public void onRegistrationStateChanged(
                            final Core core,
                            final ProxyConfig proxy,
                            final RegistrationState state,
                            String smessage) {
//Checking if Registeration failed and logging it then
// The smessage above contains the Error code
if (state == RegistrationState.Failed){
         Log.d(TAG, smessage)
}
Atepheh commented 5 years ago

Thank you . It works.