Loading android/app/src/com/android/bluetooth/BluetoothMethodProxy.java +9 −0 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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 Loading Loading @@ -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 android/app/src/com/android/bluetooth/map/BluetoothMapContentObserver.java +38 −18 Original line number Diff line number Diff line Loading @@ -53,6 +53,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; Loading Loading @@ -135,7 +136,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; Loading Loading @@ -847,7 +849,7 @@ public class BluetoothMapContentObserver { } } /*package*/ class Msg { /*package*/ static class Msg { public long id; public int type; // Used as folder for SMS/MMS public int threadId; // Used for SMS/MMS at delete Loading Loading @@ -2254,13 +2256,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 */ Loading @@ -2280,7 +2285,8 @@ public class BluetoothMapContentObserver { getMsgListMms().remove(handle); } /* Delete message */ mResolver.delete(uri, null, null); BluetoothMethodProxy.getInstance().contentResolverDelete(mResolver, uri, null, null); } res = true; } Loading @@ -2293,10 +2299,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)); Loading @@ -2315,7 +2323,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 Loading Loading @@ -2344,10 +2354,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 */ Loading @@ -2367,7 +2379,8 @@ public class BluetoothMapContentObserver { getMsgListSms().remove(handle); } /* Delete message */ mResolver.delete(uri, null, null); BluetoothMethodProxy.getInstance().contentResolverDelete(mResolver, uri, null, null); } res = true; } Loading @@ -2379,10 +2392,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)); Loading @@ -2390,7 +2405,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) { Loading Loading @@ -2501,7 +2518,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!"); } Loading @@ -2519,7 +2537,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!"); } Loading @@ -2540,7 +2559,8 @@ public class BluetoothMapContentObserver { return (count > 0); } private class PushMsgInfo { @VisibleForTesting static class PushMsgInfo { public long id; public int transparent; public int retry; Loading android/app/tests/unit/src/com/android/bluetooth/map/BluetoothMapContentObserverTest.java +319 −3 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading @@ -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; Loading @@ -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; Loading @@ -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; Loading @@ -77,6 +95,7 @@ public class BluetoothMapContentObserverTest { static class ExceptionTestProvider extends MockContentProvider { HashSet<String> mContents = new HashSet<String>(); public ExceptionTestProvider(Context context) { super(context); } Loading Loading @@ -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(); } Loading @@ -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) { Loading Loading @@ -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); } } android/app/tests/unit/src/com/android/bluetooth/map/MsgTest.java 0 → 100644 +99 −0 File added.Preview size limit exceeded, changes collapsed. Show changes Loading
android/app/src/com/android/bluetooth/BluetoothMethodProxy.java +9 −0 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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 Loading Loading @@ -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
android/app/src/com/android/bluetooth/map/BluetoothMapContentObserver.java +38 −18 Original line number Diff line number Diff line Loading @@ -53,6 +53,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; Loading Loading @@ -135,7 +136,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; Loading Loading @@ -847,7 +849,7 @@ public class BluetoothMapContentObserver { } } /*package*/ class Msg { /*package*/ static class Msg { public long id; public int type; // Used as folder for SMS/MMS public int threadId; // Used for SMS/MMS at delete Loading Loading @@ -2254,13 +2256,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 */ Loading @@ -2280,7 +2285,8 @@ public class BluetoothMapContentObserver { getMsgListMms().remove(handle); } /* Delete message */ mResolver.delete(uri, null, null); BluetoothMethodProxy.getInstance().contentResolverDelete(mResolver, uri, null, null); } res = true; } Loading @@ -2293,10 +2299,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)); Loading @@ -2315,7 +2323,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 Loading Loading @@ -2344,10 +2354,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 */ Loading @@ -2367,7 +2379,8 @@ public class BluetoothMapContentObserver { getMsgListSms().remove(handle); } /* Delete message */ mResolver.delete(uri, null, null); BluetoothMethodProxy.getInstance().contentResolverDelete(mResolver, uri, null, null); } res = true; } Loading @@ -2379,10 +2392,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)); Loading @@ -2390,7 +2405,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) { Loading Loading @@ -2501,7 +2518,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!"); } Loading @@ -2519,7 +2537,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!"); } Loading @@ -2540,7 +2559,8 @@ public class BluetoothMapContentObserver { return (count > 0); } private class PushMsgInfo { @VisibleForTesting static class PushMsgInfo { public long id; public int transparent; public int retry; Loading
android/app/tests/unit/src/com/android/bluetooth/map/BluetoothMapContentObserverTest.java +319 −3 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading @@ -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; Loading @@ -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; Loading @@ -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; Loading @@ -77,6 +95,7 @@ public class BluetoothMapContentObserverTest { static class ExceptionTestProvider extends MockContentProvider { HashSet<String> mContents = new HashSet<String>(); public ExceptionTestProvider(Context context) { super(context); } Loading Loading @@ -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(); } Loading @@ -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) { Loading Loading @@ -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); } }
android/app/tests/unit/src/com/android/bluetooth/map/MsgTest.java 0 → 100644 +99 −0 File added.Preview size limit exceeded, changes collapsed. Show changes