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

Commit 4901bce1 authored by William Escande's avatar William Escande Committed by Gerrit Code Review
Browse files

Merge "ErrorProne: BluetoothMapContentObserver"

parents c01e1876 adf04a67
Loading
Loading
Loading
Loading
+14 −82
Original line number Diff line number Diff line
@@ -42,7 +42,6 @@ import android.provider.Telephony;
import android.provider.Telephony.Mms;
import android.provider.Telephony.MmsSms;
import android.provider.Telephony.Sms;
import android.provider.Telephony.Sms.Inbox;
import android.telephony.PhoneStateListener;
import android.telephony.ServiceState;
import android.telephony.SmsManager;
@@ -107,8 +106,8 @@ public class BluetoothMapContentObserver {
    private static final long EVENT_FILTER_SENDING_FAILED = 1L << 4;
    private static final long EVENT_FILTER_DELIVERY_SUCCESS = 1L << 5;
    private static final long EVENT_FILTER_DELIVERY_FAILED = 1L << 6;
    private static final long EVENT_FILTER_MEMORY_FULL = 1L << 7; // Unused
    private static final long EVENT_FILTER_MEMORY_AVAILABLE = 1L << 8; // Unused
    // private static final long EVENT_FILTER_MEMORY_FULL = 1L << 7; // Unused
    // private static final long EVENT_FILTER_MEMORY_AVAILABLE = 1L << 8; // Unused
    private static final long EVENT_FILTER_READ_STATUS_CHANGED = 1L << 9;
    private static final long EVENT_FILTER_CONVERSATION_CHANGED = 1L << 10;
    private static final long EVENT_FILTER_PARTICIPANT_PRESENCE_CHANGED = 1L << 11;
@@ -383,7 +382,7 @@ public class BluetoothMapContentObserver {

    /**
     * Currently we only have data for IM / email contacts
     * @param contactList
     *
     * @param changesDetected that is not chat state changed nor presence state changed.
     */
    private void setContactList(Map<String, BluetoothMapConvoContactElement> contactList,
@@ -530,13 +529,13 @@ public class BluetoothMapContentObserver {

    /**
     * Set the folder structure to be used for this instance.
     * @param folderStructure
     *
     */
    public void setFolderStructure(BluetoothMapFolderElement folderStructure) {
    void setFolderStructure(BluetoothMapFolderElement folderStructure) {
        this.mFolders = folderStructure;
    }

    private class ConvoContactInfo {
    private static class ConvoContactInfo {
        public int mConvoColConvoId = -1;
        public int mConvoColLastActivity = -1;
        public int mConvoColName = -1;
@@ -827,7 +826,7 @@ public class BluetoothMapContentObserver {
        }
    }

    /*package*/ class Msg {
    static class Msg {
        public long id;
        public int type;               // Used as folder for SMS/MMS
        public int threadId;           // Used for SMS/MMS at delete
@@ -871,7 +870,7 @@ public class BluetoothMapContentObserver {
            if (obj == null) {
                return false;
            }
            if (getClass() != obj.getClass()) {
            if (!(obj instanceof Msg)) {
                return false;
            }
            Msg other = (Msg) obj;
@@ -2405,15 +2404,9 @@ public class BluetoothMapContentObserver {
    }

    /**
     *
     * @param handle
     * @param type
     * @param mCurrentFolder
     * @param uriStr
     * @param statusValue
     * @return true is success
     */
    public boolean setMessageStatusDeleted(long handle, TYPE type,
    boolean setMessageStatusDeleted(long handle, TYPE type,
            BluetoothMapFolderElement mCurrentFolder, String uriStr, int statusValue) {
        boolean res = false;
        if (D) {
@@ -2447,14 +2440,9 @@ public class BluetoothMapContentObserver {
    }

    /**
     *
     * @param handle
     * @param type
     * @param uriStr
     * @param statusValue
     * @return true at success
     */
    public boolean setMessageStatusRead(long handle, TYPE type, String uriStr, int statusValue)
    boolean setMessageStatusRead(long handle, TYPE type, String uriStr, int statusValue)
            throws RemoteException {
        int count = 0;

@@ -2519,7 +2507,7 @@ public class BluetoothMapContentObserver {
        return (count > 0);
    }

    private class PushMsgInfo {
    private static class PushMsgInfo {
        public long id;
        public int transparent;
        public int retry;
@@ -2594,7 +2582,6 @@ public class BluetoothMapContentObserver {
        int transparent = (ap.getTransparent() == BluetoothMapAppParams.INVALID_VALUE_PARAMETER) ? 0
                : ap.getTransparent();
        int retry = ap.getRetry();
        int charset = ap.getCharset();
        long handle = -1;
        long folderId = -1;

@@ -2701,7 +2688,6 @@ public class BluetoothMapContentObserver {
                if (recipient.getEnvLevel() == 0) {
                    /* Only send to first address */
                    String phone = recipient.getFirstPhoneNumber();
                    String email = recipient.getFirstEmail();
                    String folder = folderElement.getName();
                    String msgBody = null;

@@ -2870,10 +2856,6 @@ public class BluetoothMapContentObserver {
        }
    }

    private void moveDraftToOutbox(long handle) {
        moveMmsToFolder(handle, mResolver, Mms.MESSAGE_BOX_OUTBOX);
    }

    /**
     * Move a MMS to another folder.
     * @param handle the CP handle of the message to move
@@ -3177,7 +3159,7 @@ public class BluetoothMapContentObserver {
        ArrayList<String> parts = smsMng.divideMessage(msgBody);
        msgInfo.parts = parts.size();
        // We add a time stamp to differentiate delivery reports from each other for resent messages
        msgInfo.timestamp = Calendar.getInstance().getTime().getTime();
        msgInfo.timestamp = Calendar.getInstance().getTimeInMillis();
        msgInfo.partsDelivered = 0;
        msgInfo.partsSent = 0;

@@ -3240,9 +3222,6 @@ public class BluetoothMapContentObserver {
        }
    }

    private static final String[] ID_PROJECTION = new String[]{Sms._ID};
    private static final Uri UPDATE_STATUS_URI = Uri.withAppendedPath(Sms.CONTENT_URI, "/status");

    private class SmsBroadcastReceiver extends BroadcastReceiver {
        public void register() {
            Handler handler = new Handler(Looper.getMainLooper());
@@ -3295,11 +3274,10 @@ public class BluetoothMapContentObserver {
                }

                if (msgInfo.partsSent == msgInfo.parts) {
                    actionMessageSent(context, intent, msgInfo, handle);
                    actionMessageSent(context, msgInfo, handle);
                }
            } else if (action.equals(ACTION_MESSAGE_DELIVERY)) {
                long timestamp = intent.getLongExtra(EXTRA_MESSAGE_SENT_TIMESTAMP, 0);
                int status = -1;
                if (msgInfo.timestamp == timestamp) {
                    msgInfo.partsDelivered++;
                }
@@ -3308,8 +3286,7 @@ public class BluetoothMapContentObserver {
            }
        }

        private void actionMessageSent(
                Context context, Intent intent, PushMsgInfo msgInfo, long handle) {
        private void actionMessageSent(Context context, PushMsgInfo msgInfo, long handle) {
            /* As the MESSAGE_SENT intent is forwarded from the MAP service, we use the intent
             * to carry the result, as getResult() will not return the correct value.
             */
@@ -3373,50 +3350,6 @@ public class BluetoothMapContentObserver {
                if (V && nRows > 0) Log.v(TAG, "Deleted message with Uri = " + msgUri);
            }
        }

        private void actionMessageDelivery(Context context, Intent intent, PushMsgInfo msgInfo) {
            Uri messageUri = intent.getData();
            msgInfo.sendInProgress = false;

            Cursor cursor = mResolver.query(msgInfo.uri, ID_PROJECTION, null, null, null);

            try {
                if (cursor.moveToFirst()) {
                    int messageId = cursor.getInt(0);

                    Uri updateUri = ContentUris.withAppendedId(UPDATE_STATUS_URI, messageId);

                    if (D) {
                        Log.d(TAG, "actionMessageDelivery: uri=" + messageUri + ", status="
                                + msgInfo.statusDelivered);
                    }

                    ContentValues contentValues = new ContentValues(2);

                    contentValues.put(Sms.STATUS, msgInfo.statusDelivered);
                    contentValues.put(Inbox.DATE_SENT, System.currentTimeMillis());
                    mResolver.update(updateUri, contentValues, null, null);
                } else {
                    Log.d(TAG, "Can't find message for status update: " + messageUri);
                }
            } finally {
                if (cursor != null) {
                    cursor.close();
                }
            }

            if (msgInfo.statusDelivered == 0) {
                Event evt = new Event(EVENT_TYPE_DELEVERY_SUCCESS, msgInfo.id,
                        getSmsFolderName(Sms.MESSAGE_TYPE_SENT), null, mSmsType);
                sendEvent(evt);
            } else {
                Event evt = new Event(EVENT_TYPE_DELIVERY_FAILURE, msgInfo.id,
                        getSmsFolderName(Sms.MESSAGE_TYPE_SENT), null, mSmsType);
                sendEvent(evt);
            }

            mPushMsgList.remove(msgInfo.id);
        }
    }

    private class CeBroadcastReceiver extends BroadcastReceiver {
@@ -3642,7 +3575,6 @@ public class BluetoothMapContentObserver {
            if (c != null && c.moveToFirst()) {
                do {
                    long id = c.getLong(c.getColumnIndex(Sms._ID));
                    String msgBody = c.getString(c.getColumnIndex(Sms.BODY));
                    PushMsgInfo msgInfo = mPushMsgList.get(id);
                    if (msgInfo == null || !msgInfo.resend) {
                        continue;