Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c23971b3 authored by Irfan Sheriff's avatar Irfan Sheriff
Browse files

Handle client loss for a full connection

Bug: 3513246
Change-Id: I928544a05702bb004457e2b0d2eeb3c34f98edf9
parent c3549dd4
Loading
Loading
Loading
Loading
+24 −11
Original line number Diff line number Diff line
@@ -135,6 +135,8 @@ public class AsyncChannel {
     * channel is forcibly disconnected by the system or as a reply to CMD_CHANNEL_DISCONNECT.
     *
     * msg.arg1 == 0 : STATUS_SUCCESSFUL
     *             1 : STATUS_BINDING_UNSUCCESSFUL
     *             2 : STATUS_SEND_UNSUCCESSFUL
     *               : All other values signify failure and the channel state is indeterminate
     * msg.obj  == the AsyncChannel
     * msg.replyTo = messenger disconnecting or null if it was never connected.
@@ -147,6 +149,9 @@ public class AsyncChannel {
    /** Error attempting to bind on a connect */
    public static final int STATUS_BINDING_UNSUCCESSFUL = 1;

    /** Error attempting to send a message */
    public static final int STATUS_SEND_UNSUCCESSFUL = 2;

    /** Service connection */
    private AsyncChannelConnection mConnection;

@@ -345,11 +350,7 @@ public class AsyncChannel {
            mSrcContext.unbindService(mConnection);
        }
        if (mSrcHandler != null) {
            Message msg = mSrcHandler.obtainMessage(CMD_CHANNEL_DISCONNECTED);
            msg.arg1 = STATUS_SUCCESSFUL;
            msg.obj = this;
            msg.replyTo = mDstMessenger;
            mSrcHandler.sendMessage(msg);
            replyDisconnected(STATUS_SUCCESSFUL);
        }
    }

@@ -363,7 +364,7 @@ public class AsyncChannel {
        try {
            mDstMessenger.send(msg);
        } catch (RemoteException e) {
            log("TODO: handle sendMessage RemoteException" + e);
            replyDisconnected(STATUS_SEND_UNSUCCESSFUL);
        }
    }

@@ -712,6 +713,7 @@ public class AsyncChannel {

    /**
     * Reply to the src handler that we're half connected.
     * see: CMD_CHANNEL_HALF_CONNECTED for message contents
     *
     * @param status to be stored in msg.arg1
     */
@@ -723,6 +725,21 @@ public class AsyncChannel {
        mSrcHandler.sendMessage(msg);
    }

    /**
     * Reply to the src handler that we are disconnected
     * see: CMD_CHANNEL_DISCONNECTED for message contents
     *
     * @param status to be stored in msg.arg1
     */
    private void replyDisconnected(int status) {
        Message msg = mSrcHandler.obtainMessage(CMD_CHANNEL_DISCONNECTED);
        msg.arg1 = status;
        msg.obj = this;
        msg.replyTo = mDstMessenger;
        mSrcHandler.sendMessage(msg);
    }


    /**
     * ServiceConnection to receive call backs.
     */
@@ -736,11 +753,7 @@ public class AsyncChannel {
        }

        public void onServiceDisconnected(ComponentName className) {
            Message msg = mSrcHandler.obtainMessage(CMD_CHANNEL_DISCONNECTED);
            msg.arg1 = STATUS_SUCCESSFUL;
            msg.obj = AsyncChannel.this;
            msg.replyTo = mDstMessenger;
            mSrcHandler.sendMessage(msg);
            replyDisconnected(STATUS_SUCCESSFUL);
        }
    }

+9 −0
Original line number Diff line number Diff line
@@ -229,6 +229,15 @@ public class WifiService extends IWifiManager.Stub {
                    }
                    break;
                }
                case AsyncChannel.CMD_CHANNEL_DISCONNECTED: {
                    if (msg.arg1 == AsyncChannel.STATUS_SEND_UNSUCCESSFUL) {
                        Slog.d(TAG, "Send failed, client connection lost");
                    } else {
                        Slog.d(TAG, "Client connection lost with reason: " + msg.arg1);
                    }
                    mClients.remove((AsyncChannel) msg.obj);
                    break;
                }
                case AsyncChannel.CMD_CHANNEL_FULL_CONNECTION: {
                    AsyncChannel ac = new AsyncChannel();
                    ac.connect(mContext, this, msg.replyTo);