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

Commit e9ff01b0 authored by Łukasz Rymanowski's avatar Łukasz Rymanowski
Browse files

gtbs: Fix for crash when uri is not set

java.lang.NullPointerException: Attempt to invoke virtual method 'byte[] java.lang.String.getBytes()' on a null object reference
	at com.android.bluetooth.tbs.TbsGatt.setBearerListCurrentCalls(TbsGatt.java:496)
	at com.android.bluetooth.tbs.TbsGeneric.notifyCclc(TbsGeneric.java:885)
	at com.android.bluetooth.tbs.TbsGeneric.currentCallsList(TbsGeneric.java:549)

Bug: 215625928
Test: compile
Change-Id: I42ff9274bf29b1f5ca2b118375e37fa1d174e4b2
parent a84bfeaf
Loading
Loading
Loading
Loading
+14 −2
Original line number Diff line number Diff line
@@ -501,13 +501,25 @@ public class TbsGatt {
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        for (Map.Entry<Integer, TbsCall> entry : callsList.entrySet()) {
            TbsCall call = entry.getValue();
            int listItemLength = Math.min(listItemLengthMax, 3 + call.getUri().getBytes().length);
            if (call == null) {
                Log.w(TAG, "setBearerListCurrentCalls: call is null");
                continue;
            }

            int uri_len = 0;
            if (call.getUri() != null) {
                uri_len =  call.getUri().getBytes().length;
            }

            int listItemLength = Math.min(listItemLengthMax, 3 + uri_len);
            stream.write((byte) (listItemLength & 0xff));
            stream.write((byte) (entry.getKey() & 0xff));
            stream.write((byte) (call.getState() & 0xff));
            stream.write((byte) (call.getFlags() & 0xff));
            if (uri_len > 0) {
                stream.write(call.getUri().getBytes(), 0, listItemLength - 3);
            }
        }

        return mBearerListCurrentCallsCharacteristic.setValue(stream.toByteArray());
    }