socketio / socket.io-client-java

Full-featured Socket.IO Client Library for Java, which is compatible with Socket.IO v1.0 and later.
https://socketio.github.io/socket.io-client-java/installation.html
Other
5.34k stars 977 forks source link

Android 14 not compatible with version 2.1.0 #766

Open HimanshuImarticus opened 6 months ago

HimanshuImarticus commented 6 months ago

Socket connecting but showing ANRs in android 14 and working fine in lower android versions.

To Reproduce

Please fill the following code example:

Socket.IO server version: 4.0.0 Socket.IO java client version: 2.1.0

Client

public class SocketHelper {
    public static void main(String[] args) throws URISyntaxException {
            String protocol = ""https";
            String host = "apist.pegasust.imarticus.org";
            String port = mContext.getResources().getString(R.string.CHAT_HOST_PORT);
            String a_hid = SHA512Helper.sha512Generator(SharedPref.getAccountId(mContext));
            String token = TokenSecurityUtility.getAccessToken(mContext);
            token = (token == null) ? "" : token;
            options.multiplex = true;
            options.secure = false;
            options.transports = new String[]{WebSocket.NAME, Polling.NAME};
            SocketSSL.set(options);
            setUserTimeAtHandshake(System.currentTimeMillis());

            mSocket = IO.socket(String.format("%s://%s/?aid=%s&tokn=%s&ah=%s&utm=%s", protocol, host, account_id, token, a_hid, getUserTimeAtHandshake().toString()), options);
            mSocket.io().timeout(mContext.getResources().getInteger(R.integer.socket_timeout) * 1000);

            unbindSocket();
            bindSocket();
            mSocket.connect();
    }

private synchronized void unbindSocket() {
        if (mSocket == null) return;
        mSocket.off(SocketEvents.GROUP_MESSAGE, GroupMessageHandler.onGroupMessage);
}
private synchronized void bindSocket() {
        mSocket.on(SocketEvents.GROUP_MESSAGE, GroupMessageHandler.onGroupMessage);
}
}

Expected behavior App should work fine in all android versions ,but ANR showing in android 14 versions but working fine in other lower android versions.

Logs for ANR : Reason: Input dispatching timed out (f04a6f8 com.imarticus.debug/com.imarticus.activity.chat.GroupChatActivityNew (server) is not responding. Waited 10002ms for FocusEvent(hasFocus=true)) Parent: com.imarticus.debug/com.imarticus.activity.chat.GroupChatActivityNew ErrorId: e4c5a88a-891d-4178-b235-38894dced697 Frozen: s[false] g[false] Load: 15.15 / 13.46 / 13.28 ------ Current CPU Core Info ------

Platform: