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

Commit d0792c91 authored by Thomas Girardier's avatar Thomas Girardier Committed by Android (Google) Code Review
Browse files

Merge "Add tests for BluetoothMapContent and BluetoothMapObexServer" into tm-qpr-dev

parents 82e73fd9 f8183405
Loading
Loading
Loading
Loading
+37 −27
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ import android.util.Log;
import com.android.bluetooth.BluetoothMethodProxy;
import com.android.bluetooth.DeviceWorkArounds;
import com.android.bluetooth.SignedLongLong;
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;
@@ -1339,9 +1340,15 @@ public class BluetoothMapContent {
        }

        // Fix Subject Display issue with HONDA Carkit - Ignore subject Mask.
        if (DeviceWorkArounds.addressStartsWith(BluetoothMapService.getRemoteDevice().getAddress(),
                    DeviceWorkArounds.HONDA_CARKIT)
                || (ap.getParameterMask() & MASK_SUBJECT) != 0) {
        boolean isHondaCarkit;
        if (Utils.isInstrumentationTestMode()) {
            isHondaCarkit = false;
        } else {
            isHondaCarkit = DeviceWorkArounds.addressStartsWith(
                    BluetoothMapService.getRemoteDevice().getAddress(),
                    DeviceWorkArounds.HONDA_CARKIT);
        }
        if (isHondaCarkit || (ap.getParameterMask() & MASK_SUBJECT) != 0) {
            if (fi.mMsgType == FilterInfo.TYPE_SMS) {
                subject = c.getString(fi.mSmsColSubject);
            } else if (fi.mMsgType == FilterInfo.TYPE_MMS) {
@@ -2284,7 +2291,8 @@ public class BluetoothMapContent {
                    if (D) {
                        Log.d(TAG, "msgType: " + fi.mMsgType + " where: " + where);
                    }
                    smsCursor = mResolver.query(Sms.CONTENT_URI, SMS_PROJECTION, where, null,
                    smsCursor = BluetoothMethodProxy.getInstance().contentResolverQuery(mResolver,
                            Sms.CONTENT_URI, SMS_PROJECTION, where, null,
                            Sms.DATE + " DESC" + limit);
                    if (smsCursor != null) {
                        BluetoothMapMessageListingElement e = null;
@@ -2326,7 +2334,8 @@ public class BluetoothMapContent {
                    if (D) {
                        Log.d(TAG, "msgType: " + fi.mMsgType + " where: " + where);
                    }
                    mmsCursor = mResolver.query(Mms.CONTENT_URI, MMS_PROJECTION, where, null,
                    mmsCursor = BluetoothMethodProxy.getInstance().contentResolverQuery(mResolver,
                            Mms.CONTENT_URI, MMS_PROJECTION, where, null,
                            Mms.DATE + " DESC" + limit);
                    if (mmsCursor != null) {
                        BluetoothMapMessageListingElement e = null;
@@ -2369,9 +2378,8 @@ public class BluetoothMapContent {
                        Log.d(TAG, "msgType: " + fi.mMsgType + " where: " + where);
                    }
                    Uri contentUri = Uri.parse(mBaseUri + BluetoothMapContract.TABLE_MESSAGE);
                    emailCursor =
                            mResolver.query(contentUri, BluetoothMapContract.BT_MESSAGE_PROJECTION,
                                    where, null,
                    emailCursor = BluetoothMethodProxy.getInstance().contentResolverQuery(mResolver,
                            contentUri, BluetoothMapContract.BT_MESSAGE_PROJECTION, where, null,
                            BluetoothMapContract.MessageColumns.DATE + " DESC" + limit);
                    if (emailCursor != null) {
                        BluetoothMapMessageListingElement e = null;
@@ -2413,8 +2421,8 @@ public class BluetoothMapContent {
                }

                Uri contentUri = Uri.parse(mBaseUri + BluetoothMapContract.TABLE_MESSAGE);
                imCursor = mResolver.query(contentUri,
                        BluetoothMapContract.BT_INSTANT_MESSAGE_PROJECTION, where, null,
                imCursor = BluetoothMethodProxy.getInstance().contentResolverQuery(mResolver,
                        contentUri, BluetoothMapContract.BT_INSTANT_MESSAGE_PROJECTION, where, null,
                        BluetoothMapContract.MessageColumns.DATE + " DESC" + limit);
                if (imCursor != null) {
                    BluetoothMapMessageListingElement e = null;
@@ -2522,8 +2530,8 @@ public class BluetoothMapContent {
        if (smsSelected(fi, ap) && folderElement.hasSmsMmsContent()) {
            fi.mMsgType = FilterInfo.TYPE_SMS;
            String where = setWhereFilter(folderElement, fi, ap);
            Cursor c = mResolver.query(Sms.CONTENT_URI, SMS_PROJECTION, where, null,
                    Sms.DATE + " DESC");
            Cursor c = BluetoothMethodProxy.getInstance().contentResolverQuery(mResolver,
                    Sms.CONTENT_URI, SMS_PROJECTION, where, null, Sms.DATE + " DESC");
            try {
                if (c != null) {
                    cnt = c.getCount();
@@ -2538,8 +2546,8 @@ public class BluetoothMapContent {
        if (mmsSelected(ap) && folderElement.hasSmsMmsContent()) {
            fi.mMsgType = FilterInfo.TYPE_MMS;
            String where = setWhereFilter(folderElement, fi, ap);
            Cursor c = mResolver.query(Mms.CONTENT_URI, MMS_PROJECTION, where, null,
                    Mms.DATE + " DESC");
            Cursor c = BluetoothMethodProxy.getInstance().contentResolverQuery(mResolver,
                    Mms.CONTENT_URI, MMS_PROJECTION, where, null, Mms.DATE + " DESC");
            try {
                if (c != null) {
                    cnt += c.getCount();
@@ -2556,8 +2564,9 @@ public class BluetoothMapContent {
            String where = setWhereFilter(folderElement, fi, ap);
            if (!where.isEmpty()) {
                Uri contentUri = Uri.parse(mBaseUri + BluetoothMapContract.TABLE_MESSAGE);
                Cursor c = mResolver.query(contentUri, BluetoothMapContract.BT_MESSAGE_PROJECTION,
                        where, null, BluetoothMapContract.MessageColumns.DATE + " DESC");
                Cursor c = BluetoothMethodProxy.getInstance().contentResolverQuery(mResolver,
                        contentUri, BluetoothMapContract.BT_MESSAGE_PROJECTION, where, null,
                        BluetoothMapContract.MessageColumns.DATE + " DESC");
                try {
                    if (c != null) {
                        cnt += c.getCount();
@@ -2575,8 +2584,8 @@ public class BluetoothMapContent {
            String where = setWhereFilter(folderElement, fi, ap);
            if (!where.isEmpty()) {
                Uri contentUri = Uri.parse(mBaseUri + BluetoothMapContract.TABLE_MESSAGE);
                Cursor c = mResolver.query(contentUri,
                        BluetoothMapContract.BT_INSTANT_MESSAGE_PROJECTION, where, null,
                Cursor c = BluetoothMethodProxy.getInstance().contentResolverQuery(mResolver,
                        contentUri, BluetoothMapContract.BT_INSTANT_MESSAGE_PROJECTION, where, null,
                        BluetoothMapContract.MessageColumns.DATE + " DESC");
                try {
                    if (c != null) {
@@ -2618,8 +2627,8 @@ public class BluetoothMapContent {
            String where = setWhereFilterFolderType(folderElement, fi);
            where += " AND " + Sms.READ + "=0 ";
            where += setWhereFilterPeriod(ap, fi);
            Cursor c = mResolver.query(Sms.CONTENT_URI, SMS_PROJECTION, where, null,
                    Sms.DATE + " DESC");
            Cursor c = BluetoothMethodProxy.getInstance().contentResolverQuery(mResolver,
                    Sms.CONTENT_URI, SMS_PROJECTION, where, null, Sms.DATE + " DESC");
            try {
                if (c != null) {
                    cnt = c.getCount();
@@ -2636,8 +2645,8 @@ public class BluetoothMapContent {
            String where = setWhereFilterFolderType(folderElement, fi);
            where += " AND " + Mms.READ + "=0 ";
            where += setWhereFilterPeriod(ap, fi);
            Cursor c = mResolver.query(Mms.CONTENT_URI, MMS_PROJECTION, where, null,
                    Sms.DATE + " DESC");
            Cursor c = BluetoothMethodProxy.getInstance().contentResolverQuery(mResolver,
                    Mms.CONTENT_URI, MMS_PROJECTION, where, null, Sms.DATE + " DESC");
            try {
                if (c != null) {
                    cnt += c.getCount();
@@ -2657,8 +2666,9 @@ public class BluetoothMapContent {
                where += " AND " + BluetoothMapContract.MessageColumns.FLAG_READ + "=0 ";
                where += setWhereFilterPeriod(ap, fi);
                Uri contentUri = Uri.parse(mBaseUri + BluetoothMapContract.TABLE_MESSAGE);
                Cursor c = mResolver.query(contentUri, BluetoothMapContract.BT_MESSAGE_PROJECTION,
                        where, null, BluetoothMapContract.MessageColumns.DATE + " DESC");
                Cursor c = BluetoothMethodProxy.getInstance().contentResolverQuery(mResolver,
                        contentUri, BluetoothMapContract.BT_MESSAGE_PROJECTION, where, null,
                        BluetoothMapContract.MessageColumns.DATE + " DESC");
                try {
                    if (c != null) {
                        cnt += c.getCount();
@@ -2678,8 +2688,8 @@ public class BluetoothMapContent {
                where += " AND " + BluetoothMapContract.MessageColumns.FLAG_READ + "=0 ";
                where += setWhereFilterPeriod(ap, fi);
                Uri contentUri = Uri.parse(mBaseUri + BluetoothMapContract.TABLE_MESSAGE);
                Cursor c = mResolver.query(contentUri,
                        BluetoothMapContract.BT_INSTANT_MESSAGE_PROJECTION, where, null,
                Cursor c = BluetoothMethodProxy.getInstance().contentResolverQuery(mResolver,
                        contentUri, BluetoothMapContract.BT_INSTANT_MESSAGE_PROJECTION, where, null,
                        BluetoothMapContract.MessageColumns.DATE + " DESC");
                try {
                    if (c != null) {
+2 −1
Original line number Diff line number Diff line
@@ -1308,7 +1308,8 @@ public class BluetoothMapObexServer extends ServerRequestHandler {
     * @param overwrite True: The msgType will be overwritten to match the message types supported
     * by this MAS instance. False: any unsupported message types will be masked out.
     */
    private void setMsgTypeFilterParams(BluetoothMapAppParams appParams, boolean overwrite) {
    @VisibleForTesting
    void setMsgTypeFilterParams(BluetoothMapAppParams appParams, boolean overwrite) {
        int masFilterMask = 0;
        if (!mEnableSmsMms) {
            masFilterMask |= BluetoothMapAppParams.FILTER_NO_SMS_CDMA;
+320 −6

File changed.

Preview size limit exceeded, changes collapsed.

+49 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.bluetooth.map;

import static com.google.common.truth.Truth.assertThat;

import static org.junit.Assert.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
@@ -39,6 +40,7 @@ import androidx.test.runner.AndroidJUnit4;
import com.android.bluetooth.BluetoothMethodProxy;
import com.android.bluetooth.mapapi.BluetoothMapContract;
import com.android.obex.ResponseCodes;
import com.android.obex.Operation;

import org.junit.Before;
import org.junit.Test;
@@ -185,6 +187,53 @@ public class BluetoothMapObexServerTest {
        assertThat(parentFolder.getFolderById(childId)).isNotNull();
    }

    @Test
    public void setMsgTypeFilterParams_withAccountNull_andOverwriteTrue() throws Exception {
        BluetoothMapObexServer obexServer = new BluetoothMapObexServer(null, mContext, mObserver,
                mMasInstance, null, false);

        obexServer.setMsgTypeFilterParams(mParams, true);

        int expectedMask = 0;
        expectedMask |= BluetoothMapAppParams.FILTER_NO_SMS_CDMA;
        expectedMask |= BluetoothMapAppParams.FILTER_NO_SMS_GSM;
        expectedMask |= BluetoothMapAppParams.FILTER_NO_MMS;
        expectedMask |= BluetoothMapAppParams.FILTER_NO_EMAIL;
        expectedMask |= BluetoothMapAppParams.FILTER_NO_IM;
        assertThat(mParams.getFilterMessageType()).isEqualTo(expectedMask);
    }

    @Test
    public void setMsgTypeFilterParams_withInvalidFilterMessageType() throws Exception {
        BluetoothMapAccountItem accountItemWithTypeEmail = BluetoothMapAccountItem.create(TEST_ID,
                TEST_NAME, TEST_PACKAGE_NAME, TEST_PROVIDER_AUTHORITY, TEST_DRAWABLE,
                BluetoothMapUtils.TYPE.EMAIL, TEST_UCI, TEST_UCI_PREFIX);
        BluetoothMapObexServer obexServer = new BluetoothMapObexServer(null, mContext, mObserver,
                mMasInstance, accountItemWithTypeEmail, TEST_ENABLE_SMS_MMS);

        // Passing mParams without any previous settings pass invalid filter message type
        assertThrows(IllegalArgumentException.class,
                () -> obexServer.setMsgTypeFilterParams(mParams, false));
    }

    @Test
    public void setMsgTypeFilterParams_withValidFilterMessageType() throws Exception {
        BluetoothMapAccountItem accountItemWithTypeIm = BluetoothMapAccountItem.create(TEST_ID,
                TEST_NAME, TEST_PACKAGE_NAME, TEST_PROVIDER_AUTHORITY, TEST_DRAWABLE,
                BluetoothMapUtils.TYPE.IM, TEST_UCI, TEST_UCI_PREFIX);
        BluetoothMapObexServer obexServer = new BluetoothMapObexServer(null, mContext, mObserver,
                mMasInstance, accountItemWithTypeIm, TEST_ENABLE_SMS_MMS);
        int expectedMask = 1;
        mParams.setFilterMessageType(expectedMask);

        obexServer.setMsgTypeFilterParams(mParams, false);

        int masFilterMask = 0;
        masFilterMask |= BluetoothMapAppParams.FILTER_NO_EMAIL;
        expectedMask |= masFilterMask;
        assertThat(mParams.getFilterMessageType()).isEqualTo(expectedMask);
    }

    private void setUpBluetoothMapAppParams(BluetoothMapAppParams params) {
        params.setPresenceAvailability(1);
        params.setPresenceStatus("test_presence_status");