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

Commit 26b3be3f authored by Joseph Pirozzo's avatar Joseph Pirozzo Committed by Automerger Merge Worker
Browse files

Merge "MAP: Send Group MMS" am: 62bd6a51 am: 3541a8d8

Original change: https://android-review.googlesource.com/c/platform/packages/apps/Bluetooth/+/1690060

Change-Id: Ic5dc61ae5d6eca027e3bf9765db7c4e40a74d330
parents 9a317788 3541a8d8
Loading
Loading
Loading
Loading
+7 −6
Original line number Original line Diff line number Diff line
@@ -3113,15 +3113,16 @@ public class BluetoothMapContentObserver {


        values.clear();
        values.clear();
        values.put(Mms.Addr.CONTACT_ID, "null");
        values.put(Mms.Addr.CONTACT_ID, "null");
        values.put(Mms.Addr.ADDRESS, String.join(",", toAddress));
        values.put(Mms.Addr.TYPE, BluetoothMapContent.MMS_TO);
        values.put(Mms.Addr.TYPE, BluetoothMapContent.MMS_TO);
        values.put(Mms.Addr.CHARSET, 106);
        values.put(Mms.Addr.CHARSET, 106);

        for (String address : toAddress) {
            values.put(Mms.Addr.ADDRESS, address);
            uri = Uri.parse(Mms.CONTENT_URI + "/" + handle + "/addr");
            uri = Uri.parse(Mms.CONTENT_URI + "/" + handle + "/addr");
            uri = mResolver.insert(uri, values);
            uri = mResolver.insert(uri, values);
            if (uri != null && V) {
            if (uri != null && V) {
                Log.v(TAG, " NEW URI " + uri.toString());
                Log.v(TAG, " NEW URI " + uri.toString());
            }
            }
        }
        return handle;
        return handle;
    }
    }


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


import static org.mockito.Mockito.*;
import static org.mockito.Mockito.*;


import android.content.ContentValues;
import android.content.Context;
import android.content.Context;
import android.database.Cursor;
import android.database.Cursor;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteException;
@@ -25,6 +26,8 @@ import android.net.Uri;
import android.os.Looper;
import android.os.Looper;
import android.os.RemoteException;
import android.os.RemoteException;
import android.os.UserManager;
import android.os.UserManager;
import android.provider.Telephony.Mms;
import android.provider.Telephony.Sms;
import android.telephony.TelephonyManager;
import android.telephony.TelephonyManager;
import android.test.mock.MockContentProvider;
import android.test.mock.MockContentProvider;
import android.test.mock.MockContentResolver;
import android.test.mock.MockContentResolver;
@@ -40,20 +43,42 @@ import org.junit.Assume;
import org.junit.Before;
import org.junit.Before;
import org.junit.Test;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runner.RunWith;
import org.mockito.Mockito;

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


@MediumTest
@MediumTest
@RunWith(AndroidJUnit4.class)
@RunWith(AndroidJUnit4.class)
public class BluetoothMapContentObserverTest {
public class BluetoothMapContentObserverTest {
    static final String TEST_NUMBER_ONE = "5551212";
    static final String TEST_NUMBER_TWO = "5551234";
    private Context mTargetContext;
    private Context mTargetContext;


    static class ExceptionTestProvider extends MockContentProvider {
    static class ExceptionTestProvider extends MockContentProvider {
        HashSet<String> mContents = new HashSet<String>();
        public ExceptionTestProvider(Context context) {
        public ExceptionTestProvider(Context context) {
            super(context);
            super(context);
        }
        }


        @Override
        @Override
        public Cursor query(Uri uri, String[] b, String s, String[] c, String d) {
        public Cursor query(Uri uri, String[] b, String s, String[] c, String d) {
            throw new SQLiteException();
            // Throw exception for SMS queries for easy initialization
            if (Sms.CONTENT_URI.equals(uri)) throw new SQLiteException();

            // Return a cursor otherwise for Thread IDs
            Cursor cursor = Mockito.mock(Cursor.class);
            when(cursor.moveToFirst()).thenReturn(true);
            when(cursor.getLong(anyInt())).thenReturn(0L);
            return cursor;
        }

        @Override
        public Uri insert(Uri uri, ContentValues values) {
            // Store addresses for later verification
            Object address = values.get(Mms.Addr.ADDRESS);
            if (address != null) mContents.add((String) address);
            return Uri.withAppendedPath(Mms.Outbox.CONTENT_URI, "0");
        }
        }
    }
    }


@@ -94,4 +119,66 @@ public class BluetoothMapContentObserverTest {
            Assert.fail("Threw SQLiteException instead of Assert.failing cleanly");
            Assert.fail("Threw SQLiteException instead of Assert.failing cleanly");
        }
        }
    }
    }

    @Test
    public void testPushGroupMMS() {
        if (Looper.myLooper() == null) {
            Looper.prepare();
        }
        Context mockContext = mock(Context.class);
        MockContentResolver mockResolver = new MockContentResolver();
        ExceptionTestProvider mockProvider = new ExceptionTestProvider(mockContext);

        mockResolver.addProvider("sms", mockProvider);
        mockResolver.addProvider("mms", mockProvider);
        mockResolver.addProvider("mms-sms", mockProvider);
        TelephonyManager mockTelephony = mock(TelephonyManager.class);
        UserManager mockUserService = mock(UserManager.class);
        BluetoothMapMasInstance mockMas = mock(BluetoothMapMasInstance.class);

        // Functions that get called when BluetoothMapContentObserver is created
        when(mockUserService.isUserUnlocked()).thenReturn(true);
        when(mockContext.getContentResolver()).thenReturn(mockResolver);
        when(mockContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mockTelephony);
        when(mockContext.getSystemService(Context.USER_SERVICE)).thenReturn(mockUserService);

        BluetoothMapbMessageMime message = new BluetoothMapbMessageMime();
        message.setType(BluetoothMapUtils.TYPE.MMS);
        message.setFolder("telecom/msg/outbox");
        message.addSender("Zero", "0");
        message.addRecipient("One", new String[] {TEST_NUMBER_ONE}, null);
        message.addRecipient("Two", new String[] {TEST_NUMBER_TWO}, null);
        BluetoothMapbMessageMime.MimePart body =  message.addMimePart();
        try {
            body.mContentType = "text/plain";
            body.mData = "HelloWorld".getBytes("utf-8");
        } catch (Exception e) {
            Assert.fail("Failed to setup test message");
        }

        BluetoothMapAppParams appParams = new BluetoothMapAppParams();
        BluetoothMapFolderElement folderElement = new BluetoothMapFolderElement("outbox", null);

        try {
            // The constructor of BluetoothMapContentObserver calls initMsgList
            BluetoothMapContentObserver observer =
                    new BluetoothMapContentObserver(mockContext, null, mockMas, null, true);
            observer.pushMessage(message, folderElement, appParams, null);
        } catch (RemoteException e) {
            Assert.fail("Failed to created BluetoothMapContentObserver object");
        } catch (SQLiteException e) {
            Assert.fail("Threw SQLiteException instead of Assert.failing cleanly");
        } catch (IOException e) {
            Assert.fail("Threw IOException");
        } catch (NullPointerException e) {
            //expected that the test case will end in a NPE as part of the sendMultimediaMessage
            //pendingSendIntent
        }

        // Validate that 3 addresses were inserted into the database with 2 being the recipients
        Assert.assertEquals(3, mockProvider.mContents.size());
        Assert.assertTrue(mockProvider.mContents.contains(TEST_NUMBER_ONE));
        Assert.assertTrue(mockProvider.mContents.contains(TEST_NUMBER_TWO));
    }

}
}