Loading android/app/src/com/android/bluetooth/map/BluetoothMapContent.java +24 −14 Original line number Diff line number Diff line Loading @@ -71,7 +71,8 @@ public class BluetoothMapContent { // Parameter Mask for selection of parameters to return in listings private static final int MASK_SUBJECT = 0x00000001; private static final int MASK_DATETIME = 0x00000002; @VisibleForTesting static final int MASK_DATETIME = 0x00000002; private static final int MASK_SENDER_NAME = 0x00000004; private static final int MASK_SENDER_ADDRESSING = 0x00000008; private static final int MASK_RECIPIENT_NAME = 0x00000010; Loading @@ -80,7 +81,8 @@ public class BluetoothMapContent { private static final int MASK_SIZE = 0x00000080; private static final int MASK_RECEPTION_STATUS = 0x00000100; private static final int MASK_TEXT = 0x00000200; private static final int MASK_ATTACHMENT_SIZE = 0x00000400; @VisibleForTesting static final int MASK_ATTACHMENT_SIZE = 0x00000400; private static final int MASK_PRIORITY = 0x00000800; private static final int MASK_READ = 0x00001000; private static final int MASK_SENT = 0x00002000; Loading @@ -88,7 +90,8 @@ public class BluetoothMapContent { private static final int MASK_REPLYTO_ADDRESSING = 0x00008000; // TODO: Duplicate in proposed spec // private static final int MASK_RECEPTION_STATE = 0x00010000; private static final int MASK_DELIVERY_STATUS = 0x00010000; @VisibleForTesting static final int MASK_DELIVERY_STATUS = 0x00010000; private static final int MASK_CONVERSATION_ID = 0x00020000; private static final int MASK_CONVERSATION_NAME = 0x00040000; private static final int MASK_FOLDER_TYPE = 0x00100000; Loading Loading @@ -154,7 +157,8 @@ public class BluetoothMapContent { private String mMessageVersion = BluetoothMapUtils.MAP_V10_STR; private int mRemoteFeatureMask = BluetoothMapUtils.MAP_FEATURE_DEFAULT_BITMASK; private int mMsgListingVersion = BluetoothMapUtils.MAP_MESSAGE_LISTING_FORMAT_V10; @VisibleForTesting int mMsgListingVersion = BluetoothMapUtils.MAP_MESSAGE_LISTING_FORMAT_V10; static final String[] SMS_PROJECTION = new String[]{ BaseColumns._ID, Loading Loading @@ -592,7 +596,8 @@ public class BluetoothMapContent { * the total message size. To provide a more accurate attachment size, one could * extract the length (in bytes) of the text parts. */ private void setAttachment(BluetoothMapMessageListingElement e, Cursor c, FilterInfo fi, @VisibleForTesting void setAttachment(BluetoothMapMessageListingElement e, Cursor c, FilterInfo fi, BluetoothMapAppParams ap) { if ((ap.getParameterMask() & MASK_ATTACHMENT_SIZE) != 0) { int size = 0; Loading Loading @@ -687,7 +692,8 @@ public class BluetoothMapContent { } } private void setDeliveryStatus(BluetoothMapMessageListingElement e, Cursor c, FilterInfo fi, @VisibleForTesting void setDeliveryStatus(BluetoothMapMessageListingElement e, Cursor c, FilterInfo fi, BluetoothMapAppParams ap) { if ((ap.getParameterMask() & MASK_DELIVERY_STATUS) != 0) { String deliveryStatus = "delivered"; Loading Loading @@ -1247,8 +1253,8 @@ public class BluetoothMapContent { } } private void setDateTime(BluetoothMapMessageListingElement e, Cursor c, FilterInfo fi, @VisibleForTesting void setDateTime(BluetoothMapMessageListingElement e, Cursor c, FilterInfo fi, BluetoothMapAppParams ap) { if ((ap.getParameterMask() & MASK_DATETIME) != 0) { long date = 0; Loading Loading @@ -2036,8 +2042,9 @@ public class BluetoothMapContent { /* Used only for SMS/MMS */ private void setConvoWhereFilterSmsMms(StringBuilder selection, ArrayList<String> selectionArgs, FilterInfo fi, BluetoothMapAppParams ap) { @VisibleForTesting void setConvoWhereFilterSmsMms(StringBuilder selection, FilterInfo fi, BluetoothMapAppParams ap) { if (smsSelected(fi, ap) || mmsSelected(ap)) { Loading Loading @@ -2088,7 +2095,8 @@ public class BluetoothMapContent { * @param ap * @return boolean true if sms is selected, false if not */ private boolean smsSelected(FilterInfo fi, BluetoothMapAppParams ap) { @VisibleForTesting boolean smsSelected(FilterInfo fi, BluetoothMapAppParams ap) { int msgType = ap.getFilterMessageType(); int phoneType = fi.mPhoneType; Loading Loading @@ -2125,7 +2133,8 @@ public class BluetoothMapContent { * @param ap * @return boolean true if mms is selected, false if not */ private boolean mmsSelected(BluetoothMapAppParams ap) { @VisibleForTesting boolean mmsSelected(BluetoothMapAppParams ap) { int msgType = ap.getFilterMessageType(); if (D) { Loading Loading @@ -2193,7 +2202,8 @@ public class BluetoothMapContent { return false; } private void setFilterInfo(FilterInfo fi) { @VisibleForTesting void setFilterInfo(FilterInfo fi) { TelephonyManager tm = mContext.getSystemService(TelephonyManager.class); if (tm != null) { fi.mPhoneType = tm.getPhoneType(); Loading Loading @@ -2762,7 +2772,7 @@ public class BluetoothMapContent { StringBuilder selection = new StringBuilder(120); // This covers most cases ArrayList<String> selectionArgs = new ArrayList<String>(12); // Covers all cases selection.append("1=1 "); // just to simplify building the where-clause setConvoWhereFilterSmsMms(selection, selectionArgs, fi, ap); setConvoWhereFilterSmsMms(selection, fi, ap); String[] args = null; if (selectionArgs.size() > 0) { args = new String[selectionArgs.size()]; Loading android/app/tests/unit/src/com/android/bluetooth/map/BluetoothMapContentTest.java +258 −6 Original line number Diff line number Diff line Loading @@ -26,13 +26,17 @@ import static org.mockito.Mockito.when; import android.content.ContentResolver; import android.content.Context; import android.database.Cursor; import android.database.MatrixCursor; import android.provider.ContactsContract; import android.provider.Telephony; import android.provider.Telephony.Threads; import android.telephony.TelephonyManager; import androidx.test.InstrumentationRegistry; import androidx.test.runner.AndroidJUnit4; import com.android.bluetooth.BluetoothMethodProxy; import com.android.bluetooth.SignedLongLong; import com.android.bluetooth.map.BluetoothMapContent.FilterInfo; import org.junit.After; import org.junit.Before; Loading @@ -46,22 +50,33 @@ import org.mockito.Spy; public class BluetoothMapContentTest { private static final String TEST_TEXT = "text"; private Context mTargetContext; @Mock private BluetoothMapAccountItem mAccountItem; @Mock private BluetoothMapMasInstance mMasInstance; @Mock private Context mContext; @Mock private TelephonyManager mTelephonyManager; @Mock private ContentResolver mContentResolver; @Mock private BluetoothMapAppParams mParams; @Spy private BluetoothMethodProxy mMapMethodProxy = BluetoothMethodProxy.getInstance(); private BluetoothMapContent mContent; private FilterInfo mInfo; private BluetoothMapMessageListingElement mElement; @Before public void setUp() { mTargetContext = InstrumentationRegistry.getTargetContext(); MockitoAnnotations.initMocks(this); BluetoothMethodProxy.setInstanceForTesting(mMapMethodProxy); mContent = new BluetoothMapContent(mContext, mAccountItem, mMasInstance); mInfo = new FilterInfo(); mElement = new BluetoothMapMessageListingElement(); } @After Loading @@ -71,7 +86,7 @@ public class BluetoothMapContentTest { @Test public void constructor_withNonNullAccountItem() { BluetoothMapContent content = new BluetoothMapContent(mTargetContext, mAccountItem, BluetoothMapContent content = new BluetoothMapContent(mContext, mAccountItem, mMasInstance); assertThat(content.mBaseUri).isNotNull(); Loading @@ -79,7 +94,7 @@ public class BluetoothMapContentTest { @Test public void constructor_withNullAccountItem() { BluetoothMapContent content = new BluetoothMapContent(mTargetContext, null, mMasInstance); BluetoothMapContent content = new BluetoothMapContent(mContext, null, mMasInstance); assertThat(content.mBaseUri).isNull(); } Loading Loading @@ -144,4 +159,241 @@ public class BluetoothMapContentTest { assertThat(BluetoothMapContent.getAddressMms(mContentResolver, id, type)).isEqualTo( TEST_TEXT); } @Test public void setAttachment_withTypeMms() { when(mParams.getParameterMask()).thenReturn( (long) BluetoothMapContent.MASK_ATTACHMENT_SIZE); mInfo.mMsgType = FilterInfo.TYPE_MMS; mInfo.mMmsColTextOnly = 0; mInfo.mMmsColAttachmentSize = 1; MatrixCursor cursor = new MatrixCursor( new String[]{"MmsColTextOnly", "MmsColAttachmentSize"}); cursor.addRow(new Object[]{0, -1}); cursor.moveToFirst(); mContent.setAttachment(mElement, cursor, mInfo, mParams); assertThat(mElement.getAttachmentSize()).isEqualTo(1); } @Test public void setAttachment_withTypeEmail() { when(mParams.getParameterMask()).thenReturn( (long) BluetoothMapContent.MASK_ATTACHMENT_SIZE); mInfo.mMsgType = FilterInfo.TYPE_EMAIL; mInfo.mMessageColAttachment = 0; mInfo.mMessageColAttachmentSize = 1; MatrixCursor cursor = new MatrixCursor(new String[]{"MessageColAttachment", "MessageColAttachmentSize"}); cursor.addRow(new Object[]{1, 0}); cursor.moveToFirst(); mContent.setAttachment(mElement, cursor, mInfo, mParams); assertThat(mElement.getAttachmentSize()).isEqualTo(1); } @Test public void setAttachment_withTypeIm() { int featureMask = 1 << 9; long parameterMask = 0x00100400; when(mParams.getParameterMask()).thenReturn(parameterMask); mInfo.mMsgType = FilterInfo.TYPE_IM; mInfo.mMessageColAttachment = 0; mInfo.mMessageColAttachmentSize = 1; mInfo.mMessageColAttachmentMime = 2; MatrixCursor cursor = new MatrixCursor(new String[]{"MessageColAttachment", "MessageColAttachmentSize", "MessageColAttachmentMime"}); cursor.addRow(new Object[]{1, 0, "test_mime_type"}); cursor.moveToFirst(); mContent.setRemoteFeatureMask(featureMask); mContent.setAttachment(mElement, cursor, mInfo, mParams); assertThat(mElement.getAttachmentSize()).isEqualTo(1); assertThat(mElement.getAttachmentMimeTypes()).isEqualTo("test_mime_type"); } @Test public void setRemoteFeatureMask() { int featureMask = 1 << 9; mContent.setRemoteFeatureMask(featureMask); assertThat(mContent.getRemoteFeatureMask()).isEqualTo(featureMask); assertThat(mContent.mMsgListingVersion).isEqualTo( BluetoothMapUtils.MAP_MESSAGE_LISTING_FORMAT_V11); } @Test public void setConvoWhereFilterSmsMms() throws Exception { when(mParams.getFilterMessageType()).thenReturn(0); when(mParams.getFilterReadStatus()).thenReturn(0x03); long lastActivity = 1L; when(mParams.getFilterLastActivityBegin()).thenReturn(lastActivity); when(mParams.getFilterLastActivityEnd()).thenReturn(lastActivity); String convoId = "1111"; when(mParams.getFilterConvoId()).thenReturn(SignedLongLong.fromString(convoId)); StringBuilder selection = new StringBuilder(); mContent.setConvoWhereFilterSmsMms(selection, mInfo, mParams); StringBuilder expected = new StringBuilder(); expected.append(" AND ").append(Threads.READ).append(" = 0"); expected.append(" AND ").append(Threads.READ).append(" = 1"); expected.append(" AND ") .append(Threads.DATE) .append(" >= ") .append(lastActivity); expected.append(" AND ") .append(Threads.DATE) .append(" <= ") .append(lastActivity); expected.append(" AND ") .append(Threads._ID) .append(" = ") .append(SignedLongLong.fromString(convoId).getLeastSignificantBits()); assertThat(selection.toString()).isEqualTo(expected.toString()); } @Test public void setDateTime_withTypeSms() { when(mParams.getParameterMask()).thenReturn((long) BluetoothMapContent.MASK_DATETIME); mInfo.mMsgType = FilterInfo.TYPE_SMS; mInfo.mSmsColDate = 0; MatrixCursor cursor = new MatrixCursor(new String[]{"SmsColDate"}); cursor.addRow(new Object[]{2L}); cursor.moveToFirst(); mContent.setDateTime(mElement, cursor, mInfo, mParams); assertThat(mElement.getDateTime()).isEqualTo(2L); } @Test public void setDateTime_withTypeMms() { when(mParams.getParameterMask()).thenReturn((long) BluetoothMapContent.MASK_DATETIME); mInfo.mMsgType = FilterInfo.TYPE_MMS; mInfo.mMmsColDate = 0; MatrixCursor cursor = new MatrixCursor(new String[]{"MmsColDate"}); cursor.addRow(new Object[]{2L}); cursor.moveToFirst(); mContent.setDateTime(mElement, cursor, mInfo, mParams); assertThat(mElement.getDateTime()).isEqualTo(2L * 1000L); } @Test public void setDateTime_withTypeIM() { when(mParams.getParameterMask()).thenReturn((long) BluetoothMapContent.MASK_DATETIME); mInfo.mMsgType = FilterInfo.TYPE_IM; mInfo.mMessageColDate = 0; MatrixCursor cursor = new MatrixCursor(new String[]{"MessageColDate"}); cursor.addRow(new Object[]{2L}); cursor.moveToFirst(); mContent.setDateTime(mElement, cursor, mInfo, mParams); assertThat(mElement.getDateTime()).isEqualTo(2L); } @Test public void setDeliveryStatus() { when(mParams.getParameterMask()).thenReturn( (long) BluetoothMapContent.MASK_DELIVERY_STATUS); mInfo.mMsgType = FilterInfo.TYPE_EMAIL; mInfo.mMessageColDelivery = 0; MatrixCursor cursor = new MatrixCursor(new String[]{"MessageColDelivery"}); cursor.addRow(new Object[]{"test_delivery_status"}); cursor.moveToFirst(); mContent.setDeliveryStatus(mElement, cursor, mInfo, mParams); assertThat(mElement.getDeliveryStatus()).isEqualTo("test_delivery_status"); } @Test public void setFilterInfo() { when(mContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager); when(mContext.getSystemServiceName(TelephonyManager.class)) .thenReturn(Context.TELEPHONY_SERVICE); when(mTelephonyManager.getPhoneType()).thenReturn(TelephonyManager.PHONE_TYPE_GSM); mContent.setFilterInfo(mInfo); assertThat(mInfo.mPhoneType).isEqualTo(TelephonyManager.PHONE_TYPE_GSM); } @Test public void smsSelected_withInvalidFilter() { when(mParams.getFilterMessageType()).thenReturn( BluetoothMapAppParams.INVALID_VALUE_PARAMETER); assertThat(mContent.smsSelected(mInfo, mParams)).isTrue(); } @Test public void smsSelected_withNoFilter() { int noFilter = 0; when(mParams.getFilterMessageType()).thenReturn(noFilter); assertThat(mContent.smsSelected(mInfo, mParams)).isTrue(); } @Test public void smsSelected_withSmsCdmaExcludeFilter_andPhoneTypeGsm() { when(mParams.getFilterMessageType()).thenReturn(BluetoothMapAppParams.FILTER_NO_SMS_CDMA); mInfo.mPhoneType = TelephonyManager.PHONE_TYPE_GSM; assertThat(mContent.smsSelected(mInfo, mParams)).isTrue(); mInfo.mPhoneType = TelephonyManager.PHONE_TYPE_CDMA; assertThat(mContent.smsSelected(mInfo, mParams)).isFalse(); } @Test public void smsSelected_witSmsGsmExcludeFilter_andPhoneTypeCdma() { when(mParams.getFilterMessageType()).thenReturn(BluetoothMapAppParams.FILTER_NO_SMS_GSM); mInfo.mPhoneType = TelephonyManager.PHONE_TYPE_CDMA; assertThat(mContent.smsSelected(mInfo, mParams)).isTrue(); mInfo.mPhoneType = TelephonyManager.PHONE_TYPE_GSM; assertThat(mContent.smsSelected(mInfo, mParams)).isFalse(); } @Test public void smsSelected_withGsmAndCdmaExcludeFilter() { int noSms = BluetoothMapAppParams.FILTER_NO_SMS_CDMA | BluetoothMapAppParams.FILTER_NO_SMS_GSM; when(mParams.getFilterMessageType()).thenReturn(noSms); assertThat(mContent.smsSelected(mInfo, mParams)).isFalse(); } @Test public void mmsSelected_withInvalidFilter() { when(mParams.getFilterMessageType()).thenReturn( BluetoothMapAppParams.INVALID_VALUE_PARAMETER); assertThat(mContent.mmsSelected(mParams)).isTrue(); } @Test public void mmsSelected_withNoFilter() { int noFilter = 0; when(mParams.getFilterMessageType()).thenReturn(noFilter); assertThat(mContent.mmsSelected(mParams)).isTrue(); } @Test public void mmsSelected_withMmsExcludeFilter() { when(mParams.getFilterMessageType()).thenReturn(BluetoothMapAppParams.FILTER_NO_MMS); assertThat(mContent.mmsSelected(mParams)).isFalse(); } } No newline at end of file Loading
android/app/src/com/android/bluetooth/map/BluetoothMapContent.java +24 −14 Original line number Diff line number Diff line Loading @@ -71,7 +71,8 @@ public class BluetoothMapContent { // Parameter Mask for selection of parameters to return in listings private static final int MASK_SUBJECT = 0x00000001; private static final int MASK_DATETIME = 0x00000002; @VisibleForTesting static final int MASK_DATETIME = 0x00000002; private static final int MASK_SENDER_NAME = 0x00000004; private static final int MASK_SENDER_ADDRESSING = 0x00000008; private static final int MASK_RECIPIENT_NAME = 0x00000010; Loading @@ -80,7 +81,8 @@ public class BluetoothMapContent { private static final int MASK_SIZE = 0x00000080; private static final int MASK_RECEPTION_STATUS = 0x00000100; private static final int MASK_TEXT = 0x00000200; private static final int MASK_ATTACHMENT_SIZE = 0x00000400; @VisibleForTesting static final int MASK_ATTACHMENT_SIZE = 0x00000400; private static final int MASK_PRIORITY = 0x00000800; private static final int MASK_READ = 0x00001000; private static final int MASK_SENT = 0x00002000; Loading @@ -88,7 +90,8 @@ public class BluetoothMapContent { private static final int MASK_REPLYTO_ADDRESSING = 0x00008000; // TODO: Duplicate in proposed spec // private static final int MASK_RECEPTION_STATE = 0x00010000; private static final int MASK_DELIVERY_STATUS = 0x00010000; @VisibleForTesting static final int MASK_DELIVERY_STATUS = 0x00010000; private static final int MASK_CONVERSATION_ID = 0x00020000; private static final int MASK_CONVERSATION_NAME = 0x00040000; private static final int MASK_FOLDER_TYPE = 0x00100000; Loading Loading @@ -154,7 +157,8 @@ public class BluetoothMapContent { private String mMessageVersion = BluetoothMapUtils.MAP_V10_STR; private int mRemoteFeatureMask = BluetoothMapUtils.MAP_FEATURE_DEFAULT_BITMASK; private int mMsgListingVersion = BluetoothMapUtils.MAP_MESSAGE_LISTING_FORMAT_V10; @VisibleForTesting int mMsgListingVersion = BluetoothMapUtils.MAP_MESSAGE_LISTING_FORMAT_V10; static final String[] SMS_PROJECTION = new String[]{ BaseColumns._ID, Loading Loading @@ -592,7 +596,8 @@ public class BluetoothMapContent { * the total message size. To provide a more accurate attachment size, one could * extract the length (in bytes) of the text parts. */ private void setAttachment(BluetoothMapMessageListingElement e, Cursor c, FilterInfo fi, @VisibleForTesting void setAttachment(BluetoothMapMessageListingElement e, Cursor c, FilterInfo fi, BluetoothMapAppParams ap) { if ((ap.getParameterMask() & MASK_ATTACHMENT_SIZE) != 0) { int size = 0; Loading Loading @@ -687,7 +692,8 @@ public class BluetoothMapContent { } } private void setDeliveryStatus(BluetoothMapMessageListingElement e, Cursor c, FilterInfo fi, @VisibleForTesting void setDeliveryStatus(BluetoothMapMessageListingElement e, Cursor c, FilterInfo fi, BluetoothMapAppParams ap) { if ((ap.getParameterMask() & MASK_DELIVERY_STATUS) != 0) { String deliveryStatus = "delivered"; Loading Loading @@ -1247,8 +1253,8 @@ public class BluetoothMapContent { } } private void setDateTime(BluetoothMapMessageListingElement e, Cursor c, FilterInfo fi, @VisibleForTesting void setDateTime(BluetoothMapMessageListingElement e, Cursor c, FilterInfo fi, BluetoothMapAppParams ap) { if ((ap.getParameterMask() & MASK_DATETIME) != 0) { long date = 0; Loading Loading @@ -2036,8 +2042,9 @@ public class BluetoothMapContent { /* Used only for SMS/MMS */ private void setConvoWhereFilterSmsMms(StringBuilder selection, ArrayList<String> selectionArgs, FilterInfo fi, BluetoothMapAppParams ap) { @VisibleForTesting void setConvoWhereFilterSmsMms(StringBuilder selection, FilterInfo fi, BluetoothMapAppParams ap) { if (smsSelected(fi, ap) || mmsSelected(ap)) { Loading Loading @@ -2088,7 +2095,8 @@ public class BluetoothMapContent { * @param ap * @return boolean true if sms is selected, false if not */ private boolean smsSelected(FilterInfo fi, BluetoothMapAppParams ap) { @VisibleForTesting boolean smsSelected(FilterInfo fi, BluetoothMapAppParams ap) { int msgType = ap.getFilterMessageType(); int phoneType = fi.mPhoneType; Loading Loading @@ -2125,7 +2133,8 @@ public class BluetoothMapContent { * @param ap * @return boolean true if mms is selected, false if not */ private boolean mmsSelected(BluetoothMapAppParams ap) { @VisibleForTesting boolean mmsSelected(BluetoothMapAppParams ap) { int msgType = ap.getFilterMessageType(); if (D) { Loading Loading @@ -2193,7 +2202,8 @@ public class BluetoothMapContent { return false; } private void setFilterInfo(FilterInfo fi) { @VisibleForTesting void setFilterInfo(FilterInfo fi) { TelephonyManager tm = mContext.getSystemService(TelephonyManager.class); if (tm != null) { fi.mPhoneType = tm.getPhoneType(); Loading Loading @@ -2762,7 +2772,7 @@ public class BluetoothMapContent { StringBuilder selection = new StringBuilder(120); // This covers most cases ArrayList<String> selectionArgs = new ArrayList<String>(12); // Covers all cases selection.append("1=1 "); // just to simplify building the where-clause setConvoWhereFilterSmsMms(selection, selectionArgs, fi, ap); setConvoWhereFilterSmsMms(selection, fi, ap); String[] args = null; if (selectionArgs.size() > 0) { args = new String[selectionArgs.size()]; Loading
android/app/tests/unit/src/com/android/bluetooth/map/BluetoothMapContentTest.java +258 −6 Original line number Diff line number Diff line Loading @@ -26,13 +26,17 @@ import static org.mockito.Mockito.when; import android.content.ContentResolver; import android.content.Context; import android.database.Cursor; import android.database.MatrixCursor; import android.provider.ContactsContract; import android.provider.Telephony; import android.provider.Telephony.Threads; import android.telephony.TelephonyManager; import androidx.test.InstrumentationRegistry; import androidx.test.runner.AndroidJUnit4; import com.android.bluetooth.BluetoothMethodProxy; import com.android.bluetooth.SignedLongLong; import com.android.bluetooth.map.BluetoothMapContent.FilterInfo; import org.junit.After; import org.junit.Before; Loading @@ -46,22 +50,33 @@ import org.mockito.Spy; public class BluetoothMapContentTest { private static final String TEST_TEXT = "text"; private Context mTargetContext; @Mock private BluetoothMapAccountItem mAccountItem; @Mock private BluetoothMapMasInstance mMasInstance; @Mock private Context mContext; @Mock private TelephonyManager mTelephonyManager; @Mock private ContentResolver mContentResolver; @Mock private BluetoothMapAppParams mParams; @Spy private BluetoothMethodProxy mMapMethodProxy = BluetoothMethodProxy.getInstance(); private BluetoothMapContent mContent; private FilterInfo mInfo; private BluetoothMapMessageListingElement mElement; @Before public void setUp() { mTargetContext = InstrumentationRegistry.getTargetContext(); MockitoAnnotations.initMocks(this); BluetoothMethodProxy.setInstanceForTesting(mMapMethodProxy); mContent = new BluetoothMapContent(mContext, mAccountItem, mMasInstance); mInfo = new FilterInfo(); mElement = new BluetoothMapMessageListingElement(); } @After Loading @@ -71,7 +86,7 @@ public class BluetoothMapContentTest { @Test public void constructor_withNonNullAccountItem() { BluetoothMapContent content = new BluetoothMapContent(mTargetContext, mAccountItem, BluetoothMapContent content = new BluetoothMapContent(mContext, mAccountItem, mMasInstance); assertThat(content.mBaseUri).isNotNull(); Loading @@ -79,7 +94,7 @@ public class BluetoothMapContentTest { @Test public void constructor_withNullAccountItem() { BluetoothMapContent content = new BluetoothMapContent(mTargetContext, null, mMasInstance); BluetoothMapContent content = new BluetoothMapContent(mContext, null, mMasInstance); assertThat(content.mBaseUri).isNull(); } Loading Loading @@ -144,4 +159,241 @@ public class BluetoothMapContentTest { assertThat(BluetoothMapContent.getAddressMms(mContentResolver, id, type)).isEqualTo( TEST_TEXT); } @Test public void setAttachment_withTypeMms() { when(mParams.getParameterMask()).thenReturn( (long) BluetoothMapContent.MASK_ATTACHMENT_SIZE); mInfo.mMsgType = FilterInfo.TYPE_MMS; mInfo.mMmsColTextOnly = 0; mInfo.mMmsColAttachmentSize = 1; MatrixCursor cursor = new MatrixCursor( new String[]{"MmsColTextOnly", "MmsColAttachmentSize"}); cursor.addRow(new Object[]{0, -1}); cursor.moveToFirst(); mContent.setAttachment(mElement, cursor, mInfo, mParams); assertThat(mElement.getAttachmentSize()).isEqualTo(1); } @Test public void setAttachment_withTypeEmail() { when(mParams.getParameterMask()).thenReturn( (long) BluetoothMapContent.MASK_ATTACHMENT_SIZE); mInfo.mMsgType = FilterInfo.TYPE_EMAIL; mInfo.mMessageColAttachment = 0; mInfo.mMessageColAttachmentSize = 1; MatrixCursor cursor = new MatrixCursor(new String[]{"MessageColAttachment", "MessageColAttachmentSize"}); cursor.addRow(new Object[]{1, 0}); cursor.moveToFirst(); mContent.setAttachment(mElement, cursor, mInfo, mParams); assertThat(mElement.getAttachmentSize()).isEqualTo(1); } @Test public void setAttachment_withTypeIm() { int featureMask = 1 << 9; long parameterMask = 0x00100400; when(mParams.getParameterMask()).thenReturn(parameterMask); mInfo.mMsgType = FilterInfo.TYPE_IM; mInfo.mMessageColAttachment = 0; mInfo.mMessageColAttachmentSize = 1; mInfo.mMessageColAttachmentMime = 2; MatrixCursor cursor = new MatrixCursor(new String[]{"MessageColAttachment", "MessageColAttachmentSize", "MessageColAttachmentMime"}); cursor.addRow(new Object[]{1, 0, "test_mime_type"}); cursor.moveToFirst(); mContent.setRemoteFeatureMask(featureMask); mContent.setAttachment(mElement, cursor, mInfo, mParams); assertThat(mElement.getAttachmentSize()).isEqualTo(1); assertThat(mElement.getAttachmentMimeTypes()).isEqualTo("test_mime_type"); } @Test public void setRemoteFeatureMask() { int featureMask = 1 << 9; mContent.setRemoteFeatureMask(featureMask); assertThat(mContent.getRemoteFeatureMask()).isEqualTo(featureMask); assertThat(mContent.mMsgListingVersion).isEqualTo( BluetoothMapUtils.MAP_MESSAGE_LISTING_FORMAT_V11); } @Test public void setConvoWhereFilterSmsMms() throws Exception { when(mParams.getFilterMessageType()).thenReturn(0); when(mParams.getFilterReadStatus()).thenReturn(0x03); long lastActivity = 1L; when(mParams.getFilterLastActivityBegin()).thenReturn(lastActivity); when(mParams.getFilterLastActivityEnd()).thenReturn(lastActivity); String convoId = "1111"; when(mParams.getFilterConvoId()).thenReturn(SignedLongLong.fromString(convoId)); StringBuilder selection = new StringBuilder(); mContent.setConvoWhereFilterSmsMms(selection, mInfo, mParams); StringBuilder expected = new StringBuilder(); expected.append(" AND ").append(Threads.READ).append(" = 0"); expected.append(" AND ").append(Threads.READ).append(" = 1"); expected.append(" AND ") .append(Threads.DATE) .append(" >= ") .append(lastActivity); expected.append(" AND ") .append(Threads.DATE) .append(" <= ") .append(lastActivity); expected.append(" AND ") .append(Threads._ID) .append(" = ") .append(SignedLongLong.fromString(convoId).getLeastSignificantBits()); assertThat(selection.toString()).isEqualTo(expected.toString()); } @Test public void setDateTime_withTypeSms() { when(mParams.getParameterMask()).thenReturn((long) BluetoothMapContent.MASK_DATETIME); mInfo.mMsgType = FilterInfo.TYPE_SMS; mInfo.mSmsColDate = 0; MatrixCursor cursor = new MatrixCursor(new String[]{"SmsColDate"}); cursor.addRow(new Object[]{2L}); cursor.moveToFirst(); mContent.setDateTime(mElement, cursor, mInfo, mParams); assertThat(mElement.getDateTime()).isEqualTo(2L); } @Test public void setDateTime_withTypeMms() { when(mParams.getParameterMask()).thenReturn((long) BluetoothMapContent.MASK_DATETIME); mInfo.mMsgType = FilterInfo.TYPE_MMS; mInfo.mMmsColDate = 0; MatrixCursor cursor = new MatrixCursor(new String[]{"MmsColDate"}); cursor.addRow(new Object[]{2L}); cursor.moveToFirst(); mContent.setDateTime(mElement, cursor, mInfo, mParams); assertThat(mElement.getDateTime()).isEqualTo(2L * 1000L); } @Test public void setDateTime_withTypeIM() { when(mParams.getParameterMask()).thenReturn((long) BluetoothMapContent.MASK_DATETIME); mInfo.mMsgType = FilterInfo.TYPE_IM; mInfo.mMessageColDate = 0; MatrixCursor cursor = new MatrixCursor(new String[]{"MessageColDate"}); cursor.addRow(new Object[]{2L}); cursor.moveToFirst(); mContent.setDateTime(mElement, cursor, mInfo, mParams); assertThat(mElement.getDateTime()).isEqualTo(2L); } @Test public void setDeliveryStatus() { when(mParams.getParameterMask()).thenReturn( (long) BluetoothMapContent.MASK_DELIVERY_STATUS); mInfo.mMsgType = FilterInfo.TYPE_EMAIL; mInfo.mMessageColDelivery = 0; MatrixCursor cursor = new MatrixCursor(new String[]{"MessageColDelivery"}); cursor.addRow(new Object[]{"test_delivery_status"}); cursor.moveToFirst(); mContent.setDeliveryStatus(mElement, cursor, mInfo, mParams); assertThat(mElement.getDeliveryStatus()).isEqualTo("test_delivery_status"); } @Test public void setFilterInfo() { when(mContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager); when(mContext.getSystemServiceName(TelephonyManager.class)) .thenReturn(Context.TELEPHONY_SERVICE); when(mTelephonyManager.getPhoneType()).thenReturn(TelephonyManager.PHONE_TYPE_GSM); mContent.setFilterInfo(mInfo); assertThat(mInfo.mPhoneType).isEqualTo(TelephonyManager.PHONE_TYPE_GSM); } @Test public void smsSelected_withInvalidFilter() { when(mParams.getFilterMessageType()).thenReturn( BluetoothMapAppParams.INVALID_VALUE_PARAMETER); assertThat(mContent.smsSelected(mInfo, mParams)).isTrue(); } @Test public void smsSelected_withNoFilter() { int noFilter = 0; when(mParams.getFilterMessageType()).thenReturn(noFilter); assertThat(mContent.smsSelected(mInfo, mParams)).isTrue(); } @Test public void smsSelected_withSmsCdmaExcludeFilter_andPhoneTypeGsm() { when(mParams.getFilterMessageType()).thenReturn(BluetoothMapAppParams.FILTER_NO_SMS_CDMA); mInfo.mPhoneType = TelephonyManager.PHONE_TYPE_GSM; assertThat(mContent.smsSelected(mInfo, mParams)).isTrue(); mInfo.mPhoneType = TelephonyManager.PHONE_TYPE_CDMA; assertThat(mContent.smsSelected(mInfo, mParams)).isFalse(); } @Test public void smsSelected_witSmsGsmExcludeFilter_andPhoneTypeCdma() { when(mParams.getFilterMessageType()).thenReturn(BluetoothMapAppParams.FILTER_NO_SMS_GSM); mInfo.mPhoneType = TelephonyManager.PHONE_TYPE_CDMA; assertThat(mContent.smsSelected(mInfo, mParams)).isTrue(); mInfo.mPhoneType = TelephonyManager.PHONE_TYPE_GSM; assertThat(mContent.smsSelected(mInfo, mParams)).isFalse(); } @Test public void smsSelected_withGsmAndCdmaExcludeFilter() { int noSms = BluetoothMapAppParams.FILTER_NO_SMS_CDMA | BluetoothMapAppParams.FILTER_NO_SMS_GSM; when(mParams.getFilterMessageType()).thenReturn(noSms); assertThat(mContent.smsSelected(mInfo, mParams)).isFalse(); } @Test public void mmsSelected_withInvalidFilter() { when(mParams.getFilterMessageType()).thenReturn( BluetoothMapAppParams.INVALID_VALUE_PARAMETER); assertThat(mContent.mmsSelected(mParams)).isTrue(); } @Test public void mmsSelected_withNoFilter() { int noFilter = 0; when(mParams.getFilterMessageType()).thenReturn(noFilter); assertThat(mContent.mmsSelected(mParams)).isTrue(); } @Test public void mmsSelected_withMmsExcludeFilter() { when(mParams.getFilterMessageType()).thenReturn(BluetoothMapAppParams.FILTER_NO_MMS); assertThat(mContent.mmsSelected(mParams)).isFalse(); } } No newline at end of file