Login and Connection

This topic introduces the functionalities and implementation methods related to login and connection of 'Linkus SDK for Android'.

Supported features

Feature Description
Initial login (manual login) Initial login after initializing Linkus SDK. The initial login requires login credentials and the address of PBX server to establish a connection with PBX and authenticate users.
Automatic login After the initial login, Linkus SDK will cache the login credentials and PBX server information on the local device, enabling users to directly use it on subsequent logins without having to enter it again.
Query user's login status Query if the user has logged in to Linkus SDK.
Query the connection status with PBX server Query if Linkus SDK is connected with the PBX server.
SDK notification callbacks Listen for and handle events such as user account logout, successful reconnection with PBX, CDR changes, etc.

Initial login (manual login)

This method is used when a user logs in to the Linkus SDK for the first time. This method requires the user to enter their extension numbers or email addresses and the login signature as the login credential, as well as the IP address of the PBX server to establish a connection with PBX.
/**
 * manual login
 *
 * @param context
 * @param userName:User's extension number or email address 
 * @param passWord:Login signature for Linkus SDK
 * @param localeIp:PBX's local IP address
 * @param localePort:Port of PBX's local IP address
 * @param remoteIp:PBX's public IP address
 * @param remotePort:Port of PBX's public IP address
 * Depending on users' actual usage environment, at least one set of values, either 'localeIp, localePort' or 'remoteIp, remotePort' must be filled in
 * @param requestCallback: Login result callback
 * @return: Return value of the login interface, indicating the reason for login failure or abnormality. For more information, refer to the table below
 */
public void loginBlock(Context context, String userName, String passWord, String localeIp, int localePort,
        String remoteIp, int remotePort, RequestCallback<Boolean> requestCallback)
//Sample code for manual login
        YlsLoginManager.getInstance().loginBlock(this, userName, password, localeIp,
        localePortI, remoteIp, remotePortI, new RequestCallback<>() {

@Override // Login succeess callback 
public void onSuccess(Boolean result) {
        closeProgressDialog();
        startActivity(new Intent(LoginActivity.this, DialPadActivity.class));
        }

@Override// Login failure callback
public void onFailed(int code) {
        closeProgressDialog();
        Toast.makeText(LoginActivity.this, R.string.login_tip_login_failed, Toast.LENGTH_LONG).show();
        }

@Override// Login exception callback 
public void onException(Throwable exception) {
        closeProgressDialog();
        Toast.makeText(LoginActivity.this, R.string.login_tip_login_failed, Toast.LENGTH_LONG).show();
        }
        });
Login interface return value description
Return Value Description
1 Failed to connect to the PBX server.
-5 No response to the login request.
403 Invalid user name or login signature.
405 Linkus UC client is disabled.
407 This account has been locked.
416 Access to the requested IP address is prohibited ( Allowed Country / Region IP Access Protection is enabled).

Automatic login

After the initial login, Linkus SDK will cache login information. This method will automatically read the cached information for login, eliminating the need for users to enter it again.
int networkType = NetWorkUtil.getNetWorkType(this);
        YlsLoginManager.getInstance().cacheLogin(networkType);

Query user's login status

/**
 * Query if a user has logged in to Linkus SDK
 * @return Return value, which indicates the user's login status. true: Logged in; false: Not logged in
 */
public boolean isLoginEd()
// Example
        boolean isLoginEd = YlsLoginManager.getInstance().isLoginEd();

Query the connection status with PBX server

/**
 * Query if Linkus SDK is connected with PBX server
 * @return Return value, which indicates the connection status. true: Connected; false: Not connected
 */
public synchronized boolean isConnected()
// Example
        YlsLoginManager.getInstance().isConnected();

SDK notification callbacks

The SDK notification callback can be used to listen for and handle events such as user account logout, reconnecting to the PBX, and changes of CDR.
YlsBaseManager.getInstance().setSdkCallback(new SdkCallback() {
// User account logout callback. Refer to the table below for account logout event types
@Override
public void onLogout(int type) {
        context.startActivity(new Intent(context, LoginActivity.class));
        }

// Linus SDK reconnecting with PBX success callback
@Override
public void onReconnectSuccess() {}

// CDR records change callback
@Override
public void onCdrChange(int syncResult) {
        EventBus.getDefault().post(new CallLogChangeEvent(syncResult));
        }
        });
Account logout event types
Event Code Description
SdkEventCode.EVENT_USER_RELOGIN 1005 The account has logged in elsewhere.
SdkEventCode.P_EVENT_DISABLE_LINKUS_APP 20014 Linkus Mobile Client is disabled.
SdkEventCode.EVENT_LOGIN_LOCKED 1009 This account has been locked.
SdkEventCode.EVENT_LOGIN_INFO_ILLEGAL 1010 Invalid cached login information.
SdkEventCode.EVENT_CACHE_LOGIIN_USER_NOTFOUND 1011 No available cached login information.
SdkEventCode.P_EVENT_LOGIN_MODE_CHANGE 20008 Login mode (manual login or automatic login) changes.
SdkEventCode.P_EVENT_COUNTRY_IP_LIMIT 20083 Access to the requested IP address is prohibited ( Allowed Country / Region IP Access Protection is enabled).
SdkEventCode.P_EVENT_LICENSE_EXPIRE 20093 PBX plan is NOT Ultimate Plan (UP).
SdkEventCode.P_EVENT_SDK_STATUS_CHANGE 20153 Linkus SDK is disabled on PBX.
SdkEventCode.P_EVENT_SDK_ACCESSKEY_CHANGE 20154 The AccessKey of Linkus SDK has been refreshed on PBX.