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

Commit 56e0598b authored by Zongheng Wang's avatar Zongheng Wang
Browse files

MAP: move moveMessageToFolder to BT Utils

Bug: 140562205
Test: Manual
Change-Id: Id05f08dbc915febd59cc47cc511a7ea8e52a42ce
parent b8092b63
Loading
Loading
Loading
Loading
+29 −0
Original line number Diff line number Diff line
@@ -19,11 +19,13 @@ package com.android.bluetooth;
import android.app.AppOpsManager;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.ContentValues;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.pm.PackageManager;
import android.content.pm.UserInfo;
import android.location.LocationManager;
import android.net.Uri;
import android.os.Binder;
import android.os.Build;
import android.os.ParcelUuid;
@@ -31,6 +33,7 @@ import android.os.Process;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.Telephony;
import android.util.Log;

import org.xmlpull.v1.XmlPullParser;
@@ -586,4 +589,30 @@ public final class Utils {
        }
        return ret.toString();
    }

    /**
     * Move a message to the given folder.
     *
     * @param context the context to use
     * @param uri the message to move
     * @param messageSent if the message is SENT or FAILED
     * @return true if the operation succeeded
     */
    public static boolean moveMessageToFolder(Context context, Uri uri, boolean messageSent) {
        if (uri == null) {
            return false;
        }

        ContentValues values = new ContentValues(3);
        if (messageSent) {
            values.put(Telephony.Sms.READ, 1);
            values.put(Telephony.Sms.TYPE, Telephony.Sms.MESSAGE_TYPE_SENT);
        } else {
            values.put(Telephony.Sms.READ, 0);
            values.put(Telephony.Sms.TYPE, Telephony.Sms.MESSAGE_TYPE_FAILED);
        }
        values.put(Telephony.Sms.ERROR_CODE, 0);

        return 1 == context.getContentResolver().update(uri, values, null, null);
    }
}
+6 −6
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ import android.text.format.DateUtils;
import android.util.Log;
import android.util.Xml;

import com.android.bluetooth.Utils;
import com.android.bluetooth.map.BluetoothMapUtils.TYPE;
import com.android.bluetooth.map.BluetoothMapbMessageMime.MimePart;
import com.android.bluetooth.mapapi.BluetoothMapContract;
@@ -3272,7 +3273,7 @@ public class BluetoothMapContentObserver {
                    Log.d(TAG, "actionMessageSent: result OK");
                }
                if (msgInfo.transparent == 0) {
                    if (!Sms.moveMessageToFolder(context, msgInfo.uri, Sms.MESSAGE_TYPE_SENT, 0)) {
                    if (!Utils.moveMessageToFolder(context, msgInfo.uri, true)) {
                        Log.w(TAG, "Failed to move " + msgInfo.uri + " to SENT");
                    }
                } else {
@@ -3294,8 +3295,7 @@ public class BluetoothMapContentObserver {
                    sendEvent(evt);
                } else {
                    if (msgInfo.transparent == 0) {
                        if (!Sms.moveMessageToFolder(context, msgInfo.uri, Sms.MESSAGE_TYPE_FAILED,
                                0)) {
                        if (!Utils.moveMessageToFolder(context, msgInfo.uri, false)) {
                            Log.w(TAG, "Failed to move " + msgInfo.uri + " to FAILED");
                        }
                    } else {
@@ -3509,7 +3509,7 @@ public class BluetoothMapContentObserver {
        if (result == Activity.RESULT_OK) {
            Log.d(TAG, "actionMessageSentDisconnected: result OK");
            if (transparent == 0) {
                if (!Sms.moveMessageToFolder(context, uri, Sms.MESSAGE_TYPE_SENT, 0)) {
                if (!Utils.moveMessageToFolder(context, uri, true)) {
                    Log.d(TAG, "Failed to move " + uri + " to SENT");
                }
            } else {
@@ -3522,7 +3522,7 @@ public class BluetoothMapContentObserver {
            } else */
            {
                if (transparent == 0) {
                    if (!Sms.moveMessageToFolder(context, uri, Sms.MESSAGE_TYPE_FAILED, 0)) {
                    if (!Utils.moveMessageToFolder(context, uri, false)) {
                        Log.d(TAG, "Failed to move " + uri + " to FAILED");
                    }
                } else {
@@ -3597,7 +3597,7 @@ public class BluetoothMapContentObserver {
                    if (msgInfo == null || !msgInfo.resend) {
                        continue;
                    }
                    Sms.moveMessageToFolder(mContext, msgInfo.uri, Sms.MESSAGE_TYPE_FAILED, 0);
                    Utils.moveMessageToFolder(mContext, msgInfo.uri, false);
                } while (c.moveToNext());
            }
        } finally {