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

Commit f47c0ea4 authored by Kihong Seong's avatar Kihong Seong
Browse files

Add MsgTest and additional tests to BluetoothMapContentObserverTest

Bug: 237467631
Test: atest BluetoothInstrumentationTests
Change-Id: I3bca6240a43afed735cc84d99e9c5affd44f7880
parent 989855c3
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.net.Uri;
import android.os.Bundle;
import android.os.CancellationSignal;
import android.os.ParcelFileDescriptor;
import android.provider.Telephony;
import android.util.Log;

import com.android.internal.annotations.VisibleForTesting;
@@ -36,6 +37,7 @@ import com.android.obex.HeaderSet;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Set;

/**
 * Proxy class for method calls to help with unit testing
@@ -171,4 +173,11 @@ public class BluetoothMethodProxy {
    public <T> T getSystemService(Context context, Class<T> serviceClass) {
        return context.getSystemService(serviceClass);
    }

    /**
     * Proxies {@link Telephony.Threads#getOrCreateThreadId(Context, Set <String>)}.
     */
    public long telephonyGetOrCreateThreadId(Context context, Set<String> recipients) {
        return Telephony.Threads.getOrCreateThreadId(context, recipients);
    }
}
 No newline at end of file
+37 −17
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ import android.text.format.DateUtils;
import android.util.Log;
import android.util.Xml;

import com.android.bluetooth.BluetoothMethodProxy;
import com.android.bluetooth.Utils;
import com.android.bluetooth.map.BluetoothMapUtils.TYPE;
import com.android.bluetooth.map.BluetoothMapbMessageMime.MimePart;
@@ -134,7 +135,8 @@ public class BluetoothMapContentObserver {

    private Context mContext;
    private ContentResolver mResolver;
    private ContentProviderClient mProviderClient = null;
    @VisibleForTesting
    ContentProviderClient mProviderClient = null;
    private BluetoothMnsObexClient mMnsClient;
    private BluetoothMapMasInstance mMasInstance = null;
    private int mMasId;
@@ -2253,13 +2255,16 @@ public class BluetoothMapContentObserver {
    private void updateThreadId(Uri uri, String valueString, long threadId) {
        ContentValues contentValues = new ContentValues();
        contentValues.put(valueString, threadId);
        mResolver.update(uri, contentValues, null, null);
        BluetoothMethodProxy.getInstance().contentResolverUpdate(mResolver, uri, contentValues,
                null, null);
    }

    private boolean deleteMessageMms(long handle) {
    @VisibleForTesting
    boolean deleteMessageMms(long handle) {
        boolean res = false;
        Uri uri = ContentUris.withAppendedId(Mms.CONTENT_URI, handle);
        Cursor c = mResolver.query(uri, null, null, null, null);
        Cursor c = BluetoothMethodProxy.getInstance().contentResolverQuery(mResolver, uri, null,
                null, null, null);
        try {
            if (c != null && c.moveToFirst()) {
                /* Move to deleted folder, or delete if already in deleted folder */
@@ -2279,7 +2284,8 @@ public class BluetoothMapContentObserver {
                        getMsgListMms().remove(handle);
                    }
                    /* Delete message */
                    mResolver.delete(uri, null, null);
                    BluetoothMethodProxy.getInstance().contentResolverDelete(mResolver, uri, null,
                            null);
                }
                res = true;
            }
@@ -2292,10 +2298,12 @@ public class BluetoothMapContentObserver {
        return res;
    }

    private boolean unDeleteMessageMms(long handle) {
    @VisibleForTesting
    boolean unDeleteMessageMms(long handle) {
        boolean res = false;
        Uri uri = ContentUris.withAppendedId(Mms.CONTENT_URI, handle);
        Cursor c = mResolver.query(uri, null, null, null, null);
        Cursor c = BluetoothMethodProxy.getInstance().contentResolverQuery(mResolver, uri, null,
                null, null, null);
        try {
            if (c != null && c.moveToFirst()) {
                int threadId = c.getInt(c.getColumnIndex(Mms.THREAD_ID));
@@ -2314,7 +2322,9 @@ public class BluetoothMapContentObserver {
                    }
                    Set<String> recipients = new HashSet<String>();
                    recipients.addAll(Arrays.asList(address));
                    Long oldThreadId = Telephony.Threads.getOrCreateThreadId(mContext, recipients);
                    Long oldThreadId =
                            BluetoothMethodProxy.getInstance().telephonyGetOrCreateThreadId(
                                    mContext, recipients);
                    synchronized (getMsgListMms()) {
                        Msg msg = getMsgListMms().get(handle);
                        if (msg != null) { // This will always be the case
@@ -2343,10 +2353,12 @@ public class BluetoothMapContentObserver {
        return res;
    }

    private boolean deleteMessageSms(long handle) {
    @VisibleForTesting
    boolean deleteMessageSms(long handle) {
        boolean res = false;
        Uri uri = ContentUris.withAppendedId(Sms.CONTENT_URI, handle);
        Cursor c = mResolver.query(uri, null, null, null, null);
        Cursor c = BluetoothMethodProxy.getInstance().contentResolverQuery(mResolver, uri, null,
                null, null, null);
        try {
            if (c != null && c.moveToFirst()) {
                /* Move to deleted folder, or delete if already in deleted folder */
@@ -2366,7 +2378,8 @@ public class BluetoothMapContentObserver {
                        getMsgListSms().remove(handle);
                    }
                    /* Delete message */
                    mResolver.delete(uri, null, null);
                    BluetoothMethodProxy.getInstance().contentResolverDelete(mResolver, uri, null,
                            null);
                }
                res = true;
            }
@@ -2378,10 +2391,12 @@ public class BluetoothMapContentObserver {
        return res;
    }

    private boolean unDeleteMessageSms(long handle) {
    @VisibleForTesting
    boolean unDeleteMessageSms(long handle) {
        boolean res = false;
        Uri uri = ContentUris.withAppendedId(Sms.CONTENT_URI, handle);
        Cursor c = mResolver.query(uri, null, null, null, null);
        Cursor c = BluetoothMethodProxy.getInstance().contentResolverQuery(mResolver, uri, null,
                null, null, null);
        try {
            if (c != null && c.moveToFirst()) {
                int threadId = c.getInt(c.getColumnIndex(Sms.THREAD_ID));
@@ -2389,7 +2404,9 @@ public class BluetoothMapContentObserver {
                    String address = c.getString(c.getColumnIndex(Sms.ADDRESS));
                    Set<String> recipients = new HashSet<String>();
                    recipients.addAll(Arrays.asList(address));
                    Long oldThreadId = Telephony.Threads.getOrCreateThreadId(mContext, recipients);
                    Long oldThreadId =
                            BluetoothMethodProxy.getInstance().telephonyGetOrCreateThreadId(
                                    mContext, recipients);
                    synchronized (getMsgListSms()) {
                        Msg msg = getMsgListSms().get(handle);
                        if (msg != null) {
@@ -2489,7 +2506,8 @@ public class BluetoothMapContentObserver {
                    msg.flagRead = statusValue;
                }
            }
            count = mResolver.update(uri, contentValues, null, null);
            count = BluetoothMethodProxy.getInstance().contentResolverUpdate(mResolver, uri,
                    contentValues, null, null);
            if (D) {
                Log.d(TAG, " -> " + count + " rows updated!");
            }
@@ -2507,7 +2525,8 @@ public class BluetoothMapContentObserver {
                    msg.flagRead = statusValue;
                }
            }
            count = mResolver.update(uri, contentValues, null, null);
            count = BluetoothMethodProxy.getInstance().contentResolverUpdate(mResolver, uri,
                    contentValues, null, null);
            if (D) {
                Log.d(TAG, " -> " + count + " rows updated!");
            }
@@ -2528,7 +2547,8 @@ public class BluetoothMapContentObserver {
        return (count > 0);
    }

    private static class PushMsgInfo {
    @VisibleForTesting
    static class PushMsgInfo {
        public long id;
        public int transparent;
        public int retry;
+319 −3
Original line number Diff line number Diff line
@@ -18,15 +18,18 @@ package com.android.bluetooth.map;

import static org.mockito.Mockito.*;

import android.content.ContentProviderClient;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.MatrixCursor;
import android.database.sqlite.SQLiteException;
import android.net.Uri;
import android.os.Handler;
import android.os.Looper;
import android.os.RemoteException;
import android.os.UserManager;
import android.provider.Telephony;
import android.provider.Telephony.Mms;
import android.provider.Telephony.Sms;
import android.telephony.TelephonyManager;
@@ -36,9 +39,12 @@ import android.test.mock.MockContentResolver;
import androidx.test.filters.MediumTest;
import androidx.test.runner.AndroidJUnit4;

import com.android.bluetooth.BluetoothMethodProxy;
import com.android.bluetooth.R;
import com.android.bluetooth.map.BluetoothMapUtils.TYPE;
import com.android.obex.ResponseCodes;

import org.junit.After;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.Before;
@@ -47,8 +53,10 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.mockito.Spy;

import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;

@@ -59,6 +67,12 @@ public class BluetoothMapContentObserverTest {
    static final String TEST_NUMBER_TWO = "5551234";
    static final int TEST_MAS_ID = 1;
    static final long TEST_HANDLE = 1;
    static final String TEST_URI_STR = "test_uri_str";
    static final int TEST_STATUS_VALUE = 1;
    static final int TEST_THREAD_ID = 1;
    static final long TEST_OLD_THREAD_ID = 2;
    static final int TEST_PLACEHOLDER_INT = 1;
    static final String TEST_ADDRESS = "test_address";

    @Mock
    private BluetoothMnsObexClient mClient;
@@ -70,6 +84,10 @@ public class BluetoothMapContentObserverTest {
    private UserManager mUserService;
    @Mock
    private Context mContext;
    @Mock
    private ContentProviderClient mProviderClient;
    @Spy
    private BluetoothMethodProxy mMapMethodProxy = BluetoothMethodProxy.getInstance();

    private ExceptionTestProvider mProvider;
    private MockContentResolver mMockContentResolver;
@@ -77,6 +95,7 @@ public class BluetoothMapContentObserverTest {

    static class ExceptionTestProvider extends MockContentProvider {
        HashSet<String> mContents = new HashSet<String>();

        public ExceptionTestProvider(Context context) {
            super(context);
        }
@@ -107,6 +126,7 @@ public class BluetoothMapContentObserverTest {
        Assume.assumeTrue("Ignore test when BluetoothMapService is not enabled",
                BluetoothMapService.isEnabled());
        MockitoAnnotations.initMocks(this);
        BluetoothMethodProxy.setInstanceForTesting(mMapMethodProxy);
        if (Looper.myLooper() == null) {
            Looper.prepare();
        }
@@ -127,6 +147,11 @@ public class BluetoothMapContentObserverTest {
        mObserver = new BluetoothMapContentObserver(mContext, mClient, mInstance, null, true);
    }

    @After
    public void tearDown() throws Exception {
        BluetoothMethodProxy.setInstanceForTesting(null);
    }

    @Test
    public void testPushGroupMMS() {
        if (Looper.myLooper() == null) {
@@ -311,4 +336,295 @@ public class BluetoothMapContentObserverTest {
                mObserver.setNotificationRegistration(BluetoothMapAppParams.NOTIFICATION_STATUS_NO),
                ResponseCodes.OBEX_HTTP_OK);
    }

    @Test
    public void testSetMessageStatusRead_withTypeSmsGsm() throws Exception {
        TYPE type = TYPE.SMS_GSM;
        Map<Long, BluetoothMapContentObserver.Msg> map = new HashMap<>();
        BluetoothMapContentObserver.Msg msg = createSimpleMsg();
        map.put(TEST_HANDLE, msg);
        mObserver.setMsgListSms(map, true);
        int count = 1;
        doReturn(count).when(mMapMethodProxy).contentResolverUpdate(any(), any(), any(), any(),
                any());

        Assert.assertTrue(mObserver.setMessageStatusRead(TEST_HANDLE, type, TEST_URI_STR,
                TEST_STATUS_VALUE));

        Assert.assertEquals(msg.flagRead, TEST_STATUS_VALUE);
    }

    @Test
    public void testSetMessageStatusRead_withTypeMms() throws Exception {
        TYPE type = TYPE.MMS;
        Map<Long, BluetoothMapContentObserver.Msg> map = new HashMap<>();
        BluetoothMapContentObserver.Msg msg = createSimpleMsg();
        map.put(TEST_HANDLE, msg);
        mObserver.setMsgListMms(map, true);
        int count = 1;
        doReturn(count).when(mMapMethodProxy).contentResolverUpdate(any(), any(), any(), any(),
                any());

        Assert.assertTrue(mObserver.setMessageStatusRead(TEST_HANDLE, type, TEST_URI_STR,
                TEST_STATUS_VALUE));

        Assert.assertEquals(msg.flagRead, TEST_STATUS_VALUE);
    }

    @Test
    public void testSetMessageStatusRead_withTypeEmail() throws Exception {
        TYPE type = TYPE.EMAIL;
        Map<Long, BluetoothMapContentObserver.Msg> map = new HashMap<>();
        BluetoothMapContentObserver.Msg msg = createSimpleMsg();
        map.put(TEST_HANDLE, msg);
        mObserver.setMsgListMsg(map, true);
        int count = 1;
        mObserver.mProviderClient = mProviderClient;
        when(mProviderClient.update(any(), any(), any(), any())).thenReturn(count);

        Assert.assertTrue(mObserver.setMessageStatusRead(TEST_HANDLE, type, TEST_URI_STR,
                TEST_STATUS_VALUE));

        Assert.assertEquals(msg.flagRead, TEST_STATUS_VALUE);
    }

    @Test
    public void testDeleteMessageMms_withNonDeletedThreadId() {
        Map<Long, BluetoothMapContentObserver.Msg> map = new HashMap<>();
        BluetoothMapContentObserver.Msg msg = createMsgWithTypeAndThreadId(Mms.MESSAGE_BOX_ALL,
                TEST_THREAD_ID);
        map.put(TEST_HANDLE, msg);
        mObserver.setMsgListMms(map, true);
        Assert.assertEquals(msg.threadId, TEST_THREAD_ID);

        MatrixCursor cursor = new MatrixCursor(new String[] {Mms.THREAD_ID});
        cursor.addRow(new Object[] {TEST_THREAD_ID});
        doReturn(cursor).when(mMapMethodProxy).contentResolverQuery(any(), any(), any(), any(),
                any(), any());
        doReturn(TEST_PLACEHOLDER_INT).when(mMapMethodProxy).contentResolverUpdate(any(), any(),
                any(), any(), any());

        Assert.assertTrue(mObserver.deleteMessageMms(TEST_HANDLE));

        Assert.assertEquals(msg.threadId, BluetoothMapContentObserver.DELETED_THREAD_ID);
    }

    @Test
    public void testDeleteMessageMms_withDeletedThreadId() {
        Map<Long, BluetoothMapContentObserver.Msg> map = new HashMap<>();
        BluetoothMapContentObserver.Msg msg = createMsgWithTypeAndThreadId(Mms.MESSAGE_BOX_ALL,
                TEST_THREAD_ID);
        map.put(TEST_HANDLE, msg);
        mObserver.setMsgListMms(map, true);
        Assert.assertNotNull(mObserver.getMsgListMms().get(TEST_HANDLE));

        MatrixCursor cursor = new MatrixCursor(new String[] {Mms.THREAD_ID});
        cursor.addRow(new Object[] {BluetoothMapContentObserver.DELETED_THREAD_ID});
        doReturn(cursor).when(mMapMethodProxy).contentResolverQuery(any(), any(), any(), any(),
                any(), any());
        doReturn(TEST_PLACEHOLDER_INT).when(mMapMethodProxy).contentResolverDelete(any(), any(),
                any(), any());

        Assert.assertTrue(mObserver.deleteMessageMms(TEST_HANDLE));

        Assert.assertNull(mObserver.getMsgListMms().get(TEST_HANDLE));
    }

    @Test
    public void testDeleteMessageSms_withNonDeletedThreadId() {
        Map<Long, BluetoothMapContentObserver.Msg> map = new HashMap<>();
        BluetoothMapContentObserver.Msg msg = createMsgWithTypeAndThreadId(Sms.MESSAGE_TYPE_ALL,
                TEST_THREAD_ID);
        map.put(TEST_HANDLE, msg);
        mObserver.setMsgListSms(map, true);
        Assert.assertEquals(msg.threadId, TEST_THREAD_ID);

        MatrixCursor cursor = new MatrixCursor(new String[] {Mms.THREAD_ID});
        cursor.addRow(new Object[] {TEST_THREAD_ID});
        doReturn(cursor).when(mMapMethodProxy).contentResolverQuery(any(), any(), any(), any(),
                any(), any());
        doReturn(TEST_PLACEHOLDER_INT).when(mMapMethodProxy).contentResolverUpdate(any(), any(),
                any(), any(), any());

        Assert.assertTrue(mObserver.deleteMessageSms(TEST_HANDLE));

        Assert.assertEquals(msg.threadId, BluetoothMapContentObserver.DELETED_THREAD_ID);
    }

    @Test
    public void testDeleteMessageSms_withDeletedThreadId() {
        Map<Long, BluetoothMapContentObserver.Msg> map = new HashMap<>();
        BluetoothMapContentObserver.Msg msg = createMsgWithTypeAndThreadId(Sms.MESSAGE_TYPE_ALL,
                TEST_THREAD_ID);
        map.put(TEST_HANDLE, msg);
        mObserver.setMsgListSms(map, true);
        Assert.assertNotNull(mObserver.getMsgListSms().get(TEST_HANDLE));

        MatrixCursor cursor = new MatrixCursor(new String[] {Mms.THREAD_ID});
        cursor.addRow(new Object[] {BluetoothMapContentObserver.DELETED_THREAD_ID});
        doReturn(cursor).when(mMapMethodProxy).contentResolverQuery(any(), any(), any(), any(),
                any(), any());
        doReturn(TEST_PLACEHOLDER_INT).when(mMapMethodProxy).contentResolverDelete(any(), any(),
                any(), any());

        Assert.assertTrue(mObserver.deleteMessageSms(TEST_HANDLE));

        Assert.assertNull(mObserver.getMsgListSms().get(TEST_HANDLE));
    }

    @Test
    public void testUnDeleteMessageMms_withDeletedThreadId_andMessageBoxInbox() {
        Map<Long, BluetoothMapContentObserver.Msg> map = new HashMap<>();
        BluetoothMapContentObserver.Msg msg = createMsgWithTypeAndThreadId(Mms.MESSAGE_BOX_ALL,
                TEST_THREAD_ID);
        map.put(TEST_HANDLE, msg);
        mObserver.setMsgListMms(map, true);
        Assert.assertEquals(msg.threadId, TEST_THREAD_ID);
        Assert.assertEquals(msg.type, Mms.MESSAGE_BOX_ALL);

        MatrixCursor cursor = new MatrixCursor(
                new String[] {Mms.THREAD_ID, Mms._ID, Mms.MESSAGE_BOX, Mms.Addr.ADDRESS});
        cursor.addRow(new Object[] {BluetoothMapContentObserver.DELETED_THREAD_ID, 1L,
                Mms.MESSAGE_BOX_INBOX, TEST_ADDRESS});
        doReturn(cursor).when(mMapMethodProxy).contentResolverQuery(any(), any(), any(), any(),
                any(), any());
        doReturn(TEST_PLACEHOLDER_INT).when(mMapMethodProxy).contentResolverUpdate(any(), any(),
                any(), any(), any());
        doReturn(TEST_OLD_THREAD_ID).when(mMapMethodProxy).telephonyGetOrCreateThreadId(any(),
                any());

        Assert.assertTrue(mObserver.unDeleteMessageMms(TEST_HANDLE));

        Assert.assertEquals(msg.threadId, TEST_OLD_THREAD_ID);
        Assert.assertEquals(msg.type, Mms.MESSAGE_BOX_INBOX);
    }

    @Test
    public void testUnDeleteMessageMms_withDeletedThreadId_andMessageBoxSent() {
        Map<Long, BluetoothMapContentObserver.Msg> map = new HashMap<>();
        BluetoothMapContentObserver.Msg msg = createMsgWithTypeAndThreadId(Mms.MESSAGE_BOX_ALL,
                TEST_THREAD_ID);
        map.put(TEST_HANDLE, msg);
        mObserver.setMsgListMms(map, true);
        Assert.assertEquals(msg.threadId, TEST_THREAD_ID);
        Assert.assertEquals(msg.type, Mms.MESSAGE_BOX_ALL);

        MatrixCursor cursor = new MatrixCursor(
                new String[] {Mms.THREAD_ID, Mms._ID, Mms.MESSAGE_BOX, Mms.Addr.ADDRESS});
        cursor.addRow(new Object[] {BluetoothMapContentObserver.DELETED_THREAD_ID, 1L,
                Mms.MESSAGE_BOX_SENT, TEST_ADDRESS});
        doReturn(cursor).when(mMapMethodProxy).contentResolverQuery(any(), any(), any(), any(),
                any(), any());
        doReturn(TEST_PLACEHOLDER_INT).when(mMapMethodProxy).contentResolverUpdate(any(), any(),
                any(), any(), any());
        doReturn(TEST_OLD_THREAD_ID).when(mMapMethodProxy).telephonyGetOrCreateThreadId(any(),
                any());

        Assert.assertTrue(mObserver.unDeleteMessageMms(TEST_HANDLE));

        Assert.assertEquals(msg.threadId, TEST_OLD_THREAD_ID);
        Assert.assertEquals(msg.type, Mms.MESSAGE_BOX_INBOX);
    }

    @Test
    public void testUnDeleteMessageMms_withoutDeletedThreadId() {
        Map<Long, BluetoothMapContentObserver.Msg> map = new HashMap<>();
        BluetoothMapContentObserver.Msg msg = createMsgWithTypeAndThreadId(Mms.MESSAGE_BOX_ALL,
                TEST_THREAD_ID);
        map.put(TEST_HANDLE, msg);
        mObserver.setMsgListMms(map, true);
        Assert.assertEquals(msg.threadId, TEST_THREAD_ID);
        Assert.assertEquals(msg.type, Mms.MESSAGE_BOX_ALL);

        MatrixCursor cursor = new MatrixCursor(
                new String[] {Mms.THREAD_ID, Mms._ID, Mms.MESSAGE_BOX, Mms.Addr.ADDRESS,});
        cursor.addRow(new Object[] {TEST_THREAD_ID, 1L, Mms.MESSAGE_BOX_SENT, TEST_ADDRESS});
        doReturn(cursor).when(mMapMethodProxy).contentResolverQuery(any(), any(), any(), any(),
                any(), any());
        doReturn(TEST_OLD_THREAD_ID).when(mMapMethodProxy).telephonyGetOrCreateThreadId(any(),
                any());

        Assert.assertTrue(mObserver.unDeleteMessageMms(TEST_HANDLE));

        // Nothing changes when thread id is not BluetoothMapContentObserver.DELETED_THREAD_ID
        Assert.assertEquals(msg.threadId, TEST_THREAD_ID);
        Assert.assertEquals(msg.type, Sms.MESSAGE_TYPE_ALL);
    }

    @Test
    public void testUnDeleteMessageSms_withDeletedThreadId() {
        Map<Long, BluetoothMapContentObserver.Msg> map = new HashMap<>();
        BluetoothMapContentObserver.Msg msg = createMsgWithTypeAndThreadId(Sms.MESSAGE_TYPE_ALL,
                TEST_THREAD_ID);
        map.put(TEST_HANDLE, msg);
        mObserver.setMsgListSms(map, true);
        Assert.assertEquals(msg.threadId, TEST_THREAD_ID);
        Assert.assertEquals(msg.type, Sms.MESSAGE_TYPE_ALL);

        MatrixCursor cursor = new MatrixCursor(
                new String[] {Sms.THREAD_ID, Sms.ADDRESS});
        cursor.addRow(new Object[] {BluetoothMapContentObserver.DELETED_THREAD_ID, TEST_ADDRESS});
        doReturn(cursor).when(mMapMethodProxy).contentResolverQuery(any(), any(), any(), any(),
                any(), any());
        doReturn(TEST_PLACEHOLDER_INT).when(mMapMethodProxy).contentResolverUpdate(any(), any(),
                any(), any(), any());
        doReturn(TEST_OLD_THREAD_ID).when(mMapMethodProxy).telephonyGetOrCreateThreadId(any(),
                any());

        Assert.assertTrue(mObserver.unDeleteMessageSms(TEST_HANDLE));

        Assert.assertEquals(msg.threadId, TEST_OLD_THREAD_ID);
        Assert.assertEquals(msg.type, Sms.MESSAGE_TYPE_INBOX);
    }

    @Test
    public void testUnDeleteMessageSms_withoutDeletedThreadId() {
        Map<Long, BluetoothMapContentObserver.Msg> map = new HashMap<>();
        BluetoothMapContentObserver.Msg msg = createMsgWithTypeAndThreadId(Sms.MESSAGE_TYPE_ALL,
                TEST_THREAD_ID);
        map.put(TEST_HANDLE, msg);
        mObserver.setMsgListSms(map, true);
        Assert.assertEquals(msg.threadId, TEST_THREAD_ID);
        Assert.assertEquals(msg.type, Sms.MESSAGE_TYPE_ALL);

        MatrixCursor cursor = new MatrixCursor(
                new String[] {Sms.THREAD_ID, Sms.ADDRESS});
        cursor.addRow(new Object[] {TEST_THREAD_ID, TEST_ADDRESS});
        doReturn(cursor).when(mMapMethodProxy).contentResolverQuery(any(), any(), any(), any(),
                any(), any());
        doReturn(TEST_OLD_THREAD_ID).when(mMapMethodProxy).telephonyGetOrCreateThreadId(any(),
                any());

        Assert.assertTrue(mObserver.unDeleteMessageSms(TEST_HANDLE));

        // Nothing changes when thread id is not BluetoothMapContentObserver.DELETED_THREAD_ID
        Assert.assertEquals(msg.threadId, TEST_THREAD_ID);
        Assert.assertEquals(msg.type, Sms.MESSAGE_TYPE_ALL);
    }

    @Test
    public void testPushMsgInfo() {
        long id = 1;
        int transparent = 1;
        int retry = 1;
        String phone = "test_phone";
        Uri uri = mock(Uri.class);

        BluetoothMapContentObserver.PushMsgInfo msgInfo =
                new BluetoothMapContentObserver.PushMsgInfo(id, transparent, retry, phone, uri);

        Assert.assertEquals(msgInfo.id, id);
        Assert.assertEquals(msgInfo.transparent, transparent);
        Assert.assertEquals(msgInfo.retry, retry);
        Assert.assertEquals(msgInfo.phone, phone);
        Assert.assertEquals(msgInfo.uri, uri);
    }

    private BluetoothMapContentObserver.Msg createSimpleMsg() {
        return new BluetoothMapContentObserver.Msg(1, 1L, 1);
    }

    private BluetoothMapContentObserver.Msg createMsgWithTypeAndThreadId(int type, int threadId) {
        return new BluetoothMapContentObserver.Msg(1, type, threadId, 1);
    }
}
+99 −0

File added.

Preview size limit exceeded, changes collapsed.