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

Commit d3ea0610 authored by Kihong Seong's avatar Kihong Seong Committed by Automerger Merge Worker
Browse files

Merge "Add tests for BluetoothMapContent and BluetoothMapObexServer" am: 5c8c07b6

parents 042d4c13 5c8c07b6
Loading
Loading
Loading
Loading
+37 −27
Original line number Diff line number Diff line
@@ -39,6 +39,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;
@@ -1267,9 +1268,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) {
@@ -2177,7 +2184,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;
@@ -2219,7 +2227,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;
@@ -2262,9 +2271,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;
@@ -2305,8 +2313,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;
@@ -2414,8 +2422,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();
@@ -2430,8 +2438,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();
@@ -2448,8 +2456,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();
@@ -2467,8 +2476,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) {
@@ -2510,8 +2519,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();
@@ -2528,8 +2537,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();
@@ -2549,8 +2558,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();
@@ -2570,8 +2580,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
@@ -1311,7 +1311,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");