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

Commit 9dc561f7 authored by Zhihai Xu's avatar Zhihai Xu Committed by Android (Google) Code Review
Browse files

Merge "NPE in bluetooth MAP cause bluetooth process crash" into klp-dev

parents 80be110d 9679a425
Loading
Loading
Loading
Loading
+23 −7
Original line number Diff line number Diff line
@@ -261,6 +261,13 @@ public class BluetoothMnsObexClient {
        int responseCode = -1;
        HeaderSet request;
        int maxChunkSize, bytesToWrite, bytesWritten = 0;
        ClientSession clientSession = mClientSession;

        if ((!mConnected) || (clientSession == null)) {
            Log.w(TAG, "sendEvent after disconnect:" + mConnected);
            return responseCode;
        }

        request = new HeaderSet();
        BluetoothMapAppParams appParams = new BluetoothMapAppParams();
        appParams.setMasInstanceId(masInstanceId);
@@ -272,8 +279,12 @@ public class BluetoothMnsObexClient {
            request.setHeader(HeaderSet.TYPE, TYPE_EVENT);
            request.setHeader(HeaderSet.APPLICATION_PARAMETER, appParams.EncodeParams());

            if (hsConnect.mConnectionID != null) {
                request.mConnectionID = new byte[4];
                System.arraycopy(hsConnect.mConnectionID, 0, request.mConnectionID, 0, 4);
            } else {
                Log.w(TAG, "sendEvent: no connection ID");
            }

            synchronized (this) {
                mWaitingForRemote = true;
@@ -281,7 +292,7 @@ public class BluetoothMnsObexClient {
            // Send the header first and then the body
            try {
                if (V) Log.v(TAG, "Send headerset Event ");
                putOperation = (ClientOperation)mClientSession.put(request);
                putOperation = (ClientOperation)clientSession.put(request);
                // TODO - Should this be kept or Removed

            } catch (IOException e) {
@@ -313,10 +324,8 @@ public class BluetoothMnsObexClient {

                if (bytesWritten == eventBytes.length) {
                    Log.i(TAG, "SendEvent finished send length" + eventBytes.length);
                    outputStream.close();
                } else {
                    error = true;
                    outputStream.close();
                    putOperation.abort();
                    Log.i(TAG, "SendEvent interrupted");
                }
@@ -329,7 +338,14 @@ public class BluetoothMnsObexClient {
            error = true;
        } finally {
            try {
                if (!error) {
                if (outputStream != null) {
                    outputStream.close();
                }
            } catch (IOException e) {
                Log.e(TAG, "Error when closing stream after send " + e.getMessage());
            }
            try {
                if ((!error) && (putOperation != null)) {
                    responseCode = putOperation.getResponseCode();
                    if (responseCode != -1) {
                        if (V) Log.v(TAG, "Put response code " + responseCode);