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

Commit 50e3c5aa authored by Andrew Wyman's avatar Andrew Wyman Committed by Steve Kondik
Browse files

Bluetooth: Fix crash when sending SMS from handset instead of MAP

Some SMS apps use custom message types for internal handling. If MAP is
observing when this happens it will crash Bluetooth with array out of bounds.

Change-Id: I72fe6701f1fa9e43f16e79bc6b81b9e7c3256954
parent 7d8abf89
Loading
Loading
Loading
Loading
+19 −8
Original line number Diff line number Diff line
@@ -409,6 +409,13 @@ public class BluetoothMapContentObserver {
        mMsgListMms = msgListMms;
    }

    private String getFolderName(String[] names, int folderTypeId) {
        if (folderTypeId < names.length) {
            return names[folderTypeId];
        }
        return "unknown";
    }

    private void handleMsgListChangesSms() {
        if (V) Log.d(TAG, "handleMsgListChangesSms");

@@ -430,7 +437,7 @@ public class BluetoothMapContentObserver {
                        msg = new Msg(id, type);
                        msgListSms.put(id, msg);

                        if (folderSms[type].equals("inbox")) {
                        if (type == Sms.MESSAGE_TYPE_INBOX) {
                            Event evt = new Event("NewMessage", id, folderSms[type],
                                null, mSmsType);
                            sendEvent(evt);
@@ -438,9 +445,11 @@ public class BluetoothMapContentObserver {
                    } else {
                        /* Existing message */
                        if (type != msg.type) {
                            String newFolder = getFolderName(folderSms,type);
                            String oldFolder = getFolderName(folderSms,msg.type);
                            Log.d(TAG, "new type: " + type + " old type: " + msg.type);
                            Event evt = new Event("MessageShift", id, folderSms[type],
                                folderSms[msg.type], mSmsType);
                            Event evt = new Event("MessageShift", id, newFolder,
                                oldFolder, mSmsType);
                            sendEvent(evt);
                            msg.type = type;
                        }
@@ -479,7 +488,7 @@ public class BluetoothMapContentObserver {

                    if (msg == null) {
                        /* New message - only notify on retrieve conf */
                        if (folderMms[type].equals("inbox") &&
                        if (type == Mms.MESSAGE_BOX_INBOX &&
                            mtype != MESSAGE_TYPE_RETRIEVE_CONF) {
                                continue;
                        }
@@ -487,7 +496,7 @@ public class BluetoothMapContentObserver {
                        msg = new Msg(id, type);
                        msgListMms.put(id, msg);

                        if (folderMms[type].equals("inbox")) {
                        if (type == Mms.MESSAGE_BOX_INBOX) {
                            Event evt = new Event("NewMessage", id, folderMms[type],
                                null, TYPE.MMS);
                            sendEvent(evt);
@@ -495,13 +504,15 @@ public class BluetoothMapContentObserver {
                    } else {
                        /* Existing message */
                        if (type != msg.type) {
                            String newFolder = getFolderName(folderMms,type);
                            String oldFolder = getFolderName(folderMms,msg.type);
                            Log.d(TAG, "new type: " + type + " old type: " + msg.type);
                            Event evt = new Event("MessageShift", id, folderMms[type],
                                folderMms[msg.type], TYPE.MMS);
                            Event evt = new Event("MessageShift", id, newFolder,
                                oldFolder, TYPE.MMS);
                            sendEvent(evt);
                            msg.type = type;

                            if (folderMms[type].equals("sent")) {
                            if (type == Mms.MESSAGE_BOX_SENT) {
                                evt = new Event("SendingSuccess", id,
                                    folderSms[type], null, TYPE.MMS);
                                sendEvent(evt);