summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author William Escande <wescande@google.com> 2025-02-20 18:55:31 -0800
committer William Escande <wescande@google.com> 2025-02-24 14:19:48 -0800
commitd4ada3225507c628e0ea195d8fc61462b95149c8 (patch)
tree278810cce3b21e37fc5f154497202e98d243e6a6
parent0f45ca0eec3bfef25bcee3fc2b1555a06fa67849 (diff)
Errorprone fix & enforce FieldCanBeStatic
Bug: 344658662 Test: m BluetoothInstrumentationTests Test: m . Flag: Exempt refactor Change-Id: I8c487c01d3b67a6a833960a337e5a507bdd89afa
-rw-r--r--Android.bp1
-rw-r--r--android/app/src/com/android/bluetooth/pbap/BluetoothPbapCallLogComposer.java10
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/avrcpcontroller/AvrcpCoverArtStorageTest.java213
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/mapclient/MapClientStateMachineTest.java75
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppTransferTest.java140
5 files changed, 189 insertions, 250 deletions
diff --git a/Android.bp b/Android.bp
index e1e9a5041d..eb330fa827 100644
--- a/Android.bp
+++ b/Android.bp
@@ -136,6 +136,7 @@ java_defaults {
"-Xep:EqualsHashCode:ERROR",
"-Xep:EqualsIncompatibleType:ERROR",
"-Xep:FallThrough:ERROR",
+ "-Xep:FieldCanBeStatic:ERROR",
"-Xep:Finalize:ERROR",
"-Xep:ForEachIterable:ERROR",
"-Xep:FutureReturnValueIgnored:ERROR",
diff --git a/android/app/src/com/android/bluetooth/pbap/BluetoothPbapCallLogComposer.java b/android/app/src/com/android/bluetooth/pbap/BluetoothPbapCallLogComposer.java
index 99b0b13bea..54750ea3aa 100644
--- a/android/app/src/com/android/bluetooth/pbap/BluetoothPbapCallLogComposer.java
+++ b/android/app/src/com/android/bluetooth/pbap/BluetoothPbapCallLogComposer.java
@@ -89,13 +89,12 @@ public class BluetoothPbapCallLogComposer implements AutoCloseable {
private static final String VCARD_PROPERTY_CALLTYPE_OUTGOING = "DIALED";
private static final String VCARD_PROPERTY_CALLTYPE_MISSED = "MISSED";
+
private final Context mContext;
private Cursor mCursor;
private String mErrorReason = NO_ERROR;
- private final String RFC_2455_FORMAT = "yyyyMMdd'T'HHmmss";
-
public BluetoothPbapCallLogComposer(final Context context) {
mContext = context;
}
@@ -220,10 +219,11 @@ public class BluetoothPbapCallLogComposer implements AutoCloseable {
}
/** Format according to RFC 2445 DATETIME type. The format is: ("%Y%m%dT%H%M%S"). */
- private String toRfc2455Format(final long millSecs) {
+ private static String toRfc2455Format(final long millSecs) {
+ String rfc2455Format = "yyyyMMdd'T'HHmmss";
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(millSecs);
- SimpleDateFormat df = new SimpleDateFormat(RFC_2455_FORMAT);
+ SimpleDateFormat df = new SimpleDateFormat(rfc2455Format);
return df.format(cal.getTime());
}
@@ -233,7 +233,7 @@ public class BluetoothPbapCallLogComposer implements AutoCloseable {
*/
private void tryAppendCallHistoryTimeStampField(final VCardBuilder builder) {
// Extension for call history as defined in
- // in the Specification for Ic Mobile Communcation - ver 1.1,
+ // in the Specification for Ic Mobile Communication - ver 1.1,
// Oct 2000. This is used to send the details of the call
// history - missed, incoming, outgoing along with date and time
// to the requesting device (For example, transferring phone book
diff --git a/android/app/tests/unit/src/com/android/bluetooth/avrcpcontroller/AvrcpCoverArtStorageTest.java b/android/app/tests/unit/src/com/android/bluetooth/avrcpcontroller/AvrcpCoverArtStorageTest.java
index 58020003c3..98d00ebe5d 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/avrcpcontroller/AvrcpCoverArtStorageTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/avrcpcontroller/AvrcpCoverArtStorageTest.java
@@ -42,20 +42,17 @@ import java.io.InputStream;
/** A test suite for the AvrcpCoverArtStorage class. */
@RunWith(AndroidJUnit4.class)
public final class AvrcpCoverArtStorageTest {
- private Context mTargetContext;
- private Resources mTestResources;
+ private final Context mTargetContext =
+ InstrumentationRegistry.getInstrumentation().getTargetContext();
+ private final Resources mTestResources = TestUtils.getTestApplicationResources(mTargetContext);
private final BluetoothDevice mDevice1 = getTestDevice(56);
private final BluetoothDevice mDevice2 = getTestDevice(57);
private Bitmap mImage1;
private Bitmap mImage2;
- private final String mHandle1 = "1";
- private final String mHandle2 = "2";
private AvrcpCoverArtStorage mAvrcpCoverArtStorage;
@Before
public void setUp() {
- mTargetContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
- mTestResources = TestUtils.getTestApplicationResources(mTargetContext);
InputStream is =
mTestResources.openRawResource(com.android.bluetooth.tests.R.raw.image_200_200);
mImage1 = BitmapFactory.decodeStream(is);
@@ -75,8 +72,6 @@ public final class AvrcpCoverArtStorageTest {
}
mImage1 = null;
mImage2 = null;
- mTestResources = null;
- mTargetContext = null;
}
private void assertImageSame(Bitmap expected, BluetoothDevice device, String handle) {
@@ -86,259 +81,251 @@ public final class AvrcpCoverArtStorageTest {
@Test
public void addNewImage_imageExists() {
- Uri expectedUri = AvrcpCoverArtProvider.getImageUri(mDevice1, mHandle1);
- assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, mHandle1)).isFalse();
+ Uri expectedUri = AvrcpCoverArtProvider.getImageUri(mDevice1, "1");
+ assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, "1")).isFalse();
- Uri uri = mAvrcpCoverArtStorage.addImage(mDevice1, mHandle1, mImage1);
+ Uri uri = mAvrcpCoverArtStorage.addImage(mDevice1, "1", mImage1);
assertThat(uri).isEqualTo(expectedUri);
- assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, mHandle1)).isTrue();
+ assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, "1")).isTrue();
}
@Test
public void addExistingImage_imageUpdated() {
- Uri expectedUri = AvrcpCoverArtProvider.getImageUri(mDevice1, mHandle1);
- assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, mHandle1)).isFalse();
+ Uri expectedUri = AvrcpCoverArtProvider.getImageUri(mDevice1, "1");
+ assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, "1")).isFalse();
- Uri uri = mAvrcpCoverArtStorage.addImage(mDevice1, mHandle1, mImage1);
- assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, mHandle1)).isTrue();
+ Uri uri = mAvrcpCoverArtStorage.addImage(mDevice1, "1", mImage1);
+ assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, "1")).isTrue();
assertThat(uri).isEqualTo(expectedUri);
- assertImageSame(mImage1, mDevice1, mHandle1);
+ assertImageSame(mImage1, mDevice1, "1");
- uri = mAvrcpCoverArtStorage.addImage(mDevice1, mHandle1, mImage2);
- assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, mHandle1)).isTrue();
+ uri = mAvrcpCoverArtStorage.addImage(mDevice1, "1", mImage2);
+ assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, "1")).isTrue();
assertThat(uri).isEqualTo(expectedUri);
- assertImageSame(mImage2, mDevice1, mHandle1);
+ assertImageSame(mImage2, mDevice1, "1");
}
@Test
public void addTwoImageSameDevice_bothExist() {
- Uri expectedUri1 = AvrcpCoverArtProvider.getImageUri(mDevice1, mHandle1);
- Uri expectedUri2 = AvrcpCoverArtProvider.getImageUri(mDevice1, mHandle2);
- assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, mHandle1)).isFalse();
- assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, mHandle2)).isFalse();
+ Uri expectedUri1 = AvrcpCoverArtProvider.getImageUri(mDevice1, "1");
+ Uri expectedUri2 = AvrcpCoverArtProvider.getImageUri(mDevice1, "2");
+ assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, "1")).isFalse();
+ assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, "2")).isFalse();
- Uri uri1 = mAvrcpCoverArtStorage.addImage(mDevice1, mHandle1, mImage1);
- Uri uri2 = mAvrcpCoverArtStorage.addImage(mDevice1, mHandle2, mImage2);
+ Uri uri1 = mAvrcpCoverArtStorage.addImage(mDevice1, "1", mImage1);
+ Uri uri2 = mAvrcpCoverArtStorage.addImage(mDevice1, "2", mImage2);
- assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, mHandle1)).isTrue();
+ assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, "1")).isTrue();
assertThat(uri1).isEqualTo(expectedUri1);
- assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, mHandle2)).isTrue();
+ assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, "2")).isTrue();
assertThat(uri2).isEqualTo(expectedUri2);
}
@Test
public void addTwoImageDifferentDevices_bothExist() {
- Uri expectedUri1 = AvrcpCoverArtProvider.getImageUri(mDevice1, mHandle1);
- Uri expectedUri2 = AvrcpCoverArtProvider.getImageUri(mDevice2, mHandle1);
- assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, mHandle1)).isFalse();
- assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice2, mHandle1)).isFalse();
+ Uri expectedUri1 = AvrcpCoverArtProvider.getImageUri(mDevice1, "1");
+ Uri expectedUri2 = AvrcpCoverArtProvider.getImageUri(mDevice2, "1");
+ assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, "1")).isFalse();
+ assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice2, "1")).isFalse();
- Uri uri1 = mAvrcpCoverArtStorage.addImage(mDevice1, mHandle1, mImage1);
- Uri uri2 = mAvrcpCoverArtStorage.addImage(mDevice2, mHandle1, mImage1);
+ Uri uri1 = mAvrcpCoverArtStorage.addImage(mDevice1, "1", mImage1);
+ Uri uri2 = mAvrcpCoverArtStorage.addImage(mDevice2, "1", mImage1);
- assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, mHandle1)).isTrue();
+ assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, "1")).isTrue();
assertThat(uri1).isEqualTo(expectedUri1);
- assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, mHandle1)).isTrue();
+ assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, "1")).isTrue();
assertThat(uri2).isEqualTo(expectedUri2);
}
@Test
public void addNullImage_imageNotAdded() {
- Uri uri = mAvrcpCoverArtStorage.addImage(mDevice1, mHandle1, null);
- assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, mHandle1)).isFalse();
+ Uri uri = mAvrcpCoverArtStorage.addImage(mDevice1, "1", null);
+ assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, "1")).isFalse();
assertThat(uri).isNull();
}
@Test
public void addImageNullDevice_imageNotAdded() {
- Uri uri = mAvrcpCoverArtStorage.addImage(null, mHandle1, mImage1);
- assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, mHandle1)).isFalse();
+ Uri uri = mAvrcpCoverArtStorage.addImage(null, "1", mImage1);
+ assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, "1")).isFalse();
assertThat(uri).isNull();
}
@Test
public void addImageNullHandle_imageNotAdded() {
Uri uri = mAvrcpCoverArtStorage.addImage(mDevice1, null, mImage1);
- assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, mHandle1)).isFalse();
+ assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, "1")).isFalse();
assertThat(uri).isNull();
}
@Test
public void addImageEmptyHandle_imageNotAdded() {
Uri uri = mAvrcpCoverArtStorage.addImage(mDevice1, "", mImage1);
- assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, mHandle1)).isFalse();
+ assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, "1")).isFalse();
assertThat(uri).isNull();
}
@Test
public void getImage_canGetImageFromStorage() {
- mAvrcpCoverArtStorage.addImage(mDevice1, mHandle1, mImage1);
- assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, mHandle1)).isTrue();
- assertImageSame(mImage1, mDevice1, mHandle1);
+ mAvrcpCoverArtStorage.addImage(mDevice1, "1", mImage1);
+ assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, "1")).isTrue();
+ assertImageSame(mImage1, mDevice1, "1");
}
@Test
public void getImageSameHandleDifferentDevices_canGetImagesFromStorage() {
- mAvrcpCoverArtStorage.addImage(mDevice1, mHandle1, mImage1);
- mAvrcpCoverArtStorage.addImage(mDevice2, mHandle1, mImage2);
- assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, mHandle1)).isTrue();
- assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice2, mHandle1)).isTrue();
- assertImageSame(mImage1, mDevice1, mHandle1);
- assertImageSame(mImage2, mDevice2, mHandle1);
+ mAvrcpCoverArtStorage.addImage(mDevice1, "1", mImage1);
+ mAvrcpCoverArtStorage.addImage(mDevice2, "1", mImage2);
+ assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, "1")).isTrue();
+ assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice2, "1")).isTrue();
+ assertImageSame(mImage1, mDevice1, "1");
+ assertImageSame(mImage2, mDevice2, "1");
}
@Test
public void getImageThatDoesntExist_returnsNull() {
- assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, mHandle1)).isFalse();
- Bitmap image = mAvrcpCoverArtStorage.getImage(mDevice1, mHandle1);
+ assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, "1")).isFalse();
+ Bitmap image = mAvrcpCoverArtStorage.getImage(mDevice1, "1");
assertThat(image).isNull();
}
@Test
public void getImageNullDevice_returnsNull() {
- assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, mHandle1)).isFalse();
- Bitmap image = mAvrcpCoverArtStorage.getImage(null, mHandle1);
+ assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, "1")).isFalse();
+ Bitmap image = mAvrcpCoverArtStorage.getImage(null, "1");
assertThat(image).isNull();
}
@Test
public void getImageNullHandle_returnsNull() {
- assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, mHandle1)).isFalse();
+ assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, "1")).isFalse();
Bitmap image = mAvrcpCoverArtStorage.getImage(mDevice1, null);
assertThat(image).isNull();
}
@Test
public void getImageEmptyHandle_returnsNull() {
- assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, mHandle1)).isFalse();
+ assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, "1")).isFalse();
Bitmap image = mAvrcpCoverArtStorage.getImage(mDevice1, "");
assertThat(image).isNull();
}
@Test
public void removeExistingImage_imageDoesntExist() {
- mAvrcpCoverArtStorage.addImage(mDevice1, mHandle1, mImage1);
- mAvrcpCoverArtStorage.addImage(mDevice1, mHandle2, mImage1);
- mAvrcpCoverArtStorage.addImage(mDevice2, mHandle1, mImage1);
- mAvrcpCoverArtStorage.removeImage(mDevice1, mHandle1);
- assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, mHandle1)).isFalse();
- assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, mHandle2)).isTrue();
- assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice2, mHandle1)).isTrue();
+ mAvrcpCoverArtStorage.addImage(mDevice1, "1", mImage1);
+ mAvrcpCoverArtStorage.addImage(mDevice1, "2", mImage1);
+ mAvrcpCoverArtStorage.addImage(mDevice2, "1", mImage1);
+ mAvrcpCoverArtStorage.removeImage(mDevice1, "1");
+ assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, "1")).isFalse();
+ assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, "2")).isTrue();
+ assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice2, "1")).isTrue();
}
@Test
public void removeNonExistentImage_nothingHappens() {
- mAvrcpCoverArtStorage.addImage(mDevice1, mHandle1, mImage1);
- mAvrcpCoverArtStorage.removeImage(mDevice1, mHandle2);
- assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, mHandle1)).isTrue();
+ mAvrcpCoverArtStorage.addImage(mDevice1, "1", mImage1);
+ mAvrcpCoverArtStorage.removeImage(mDevice1, "2");
+ assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, "1")).isTrue();
}
@Test
public void removeImageNullDevice_nothingHappens() {
- mAvrcpCoverArtStorage.addImage(mDevice1, mHandle1, mImage1);
- mAvrcpCoverArtStorage.removeImage(null, mHandle1);
- assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, mHandle1)).isTrue();
+ mAvrcpCoverArtStorage.addImage(mDevice1, "1", mImage1);
+ mAvrcpCoverArtStorage.removeImage(null, "1");
+ assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, "1")).isTrue();
}
@Test
public void removeImageNullHandle_nothingHappens() {
- mAvrcpCoverArtStorage.addImage(mDevice1, mHandle1, mImage1);
+ mAvrcpCoverArtStorage.addImage(mDevice1, "1", mImage1);
mAvrcpCoverArtStorage.removeImage(mDevice1, null);
- assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, mHandle1)).isTrue();
+ assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, "1")).isTrue();
}
@Test
public void removeImageEmptyHandle_nothingHappens() {
- mAvrcpCoverArtStorage.addImage(mDevice1, mHandle1, mImage1);
+ mAvrcpCoverArtStorage.addImage(mDevice1, "1", mImage1);
mAvrcpCoverArtStorage.removeImage(mDevice1, "");
- assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, mHandle1)).isTrue();
+ assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, "1")).isTrue();
}
@Test
public void removeImageNullInputs_nothingHappens() {
- mAvrcpCoverArtStorage.addImage(mDevice1, mHandle1, mImage1);
+ mAvrcpCoverArtStorage.addImage(mDevice1, "1", mImage1);
mAvrcpCoverArtStorage.removeImage(null, null);
- assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, mHandle1)).isTrue();
+ assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, "1")).isTrue();
}
@Test
public void removeAllImagesForDevice_onlyOneDeviceImagesGone() {
- mAvrcpCoverArtStorage.addImage(mDevice1, mHandle1, mImage1);
- mAvrcpCoverArtStorage.addImage(mDevice1, mHandle2, mImage1);
- mAvrcpCoverArtStorage.addImage(mDevice2, mHandle1, mImage1);
+ mAvrcpCoverArtStorage.addImage(mDevice1, "1", mImage1);
+ mAvrcpCoverArtStorage.addImage(mDevice1, "2", mImage1);
+ mAvrcpCoverArtStorage.addImage(mDevice2, "1", mImage1);
mAvrcpCoverArtStorage.removeImagesForDevice(mDevice1);
- assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, mHandle1)).isFalse();
- assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, mHandle2)).isFalse();
- assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice2, mHandle1)).isTrue();
+ assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, "1")).isFalse();
+ assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, "2")).isFalse();
+ assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice2, "1")).isTrue();
}
@Test
public void removeAllImagesForDeviceDne_nothingHappens() {
- mAvrcpCoverArtStorage.addImage(mDevice1, mHandle1, mImage1);
- mAvrcpCoverArtStorage.addImage(mDevice1, mHandle2, mImage1);
+ mAvrcpCoverArtStorage.addImage(mDevice1, "1", mImage1);
+ mAvrcpCoverArtStorage.addImage(mDevice1, "2", mImage1);
mAvrcpCoverArtStorage.removeImagesForDevice(mDevice2);
- assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, mHandle1)).isTrue();
- assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, mHandle2)).isTrue();
+ assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, "1")).isTrue();
+ assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, "2")).isTrue();
}
@Test
public void removeAllImagesForNullDevice_nothingHappens() {
- mAvrcpCoverArtStorage.addImage(mDevice1, mHandle1, mImage1);
- mAvrcpCoverArtStorage.addImage(mDevice1, mHandle2, mImage1);
+ mAvrcpCoverArtStorage.addImage(mDevice1, "1", mImage1);
+ mAvrcpCoverArtStorage.addImage(mDevice1, "2", mImage1);
mAvrcpCoverArtStorage.removeImagesForDevice(null);
- assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, mHandle1)).isTrue();
- assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, mHandle2)).isTrue();
+ assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, "1")).isTrue();
+ assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, "2")).isTrue();
}
@Test
public void clearStorageOneDevice_allImagesRemoved() {
- mAvrcpCoverArtStorage.addImage(mDevice1, mHandle1, mImage1);
- mAvrcpCoverArtStorage.addImage(mDevice1, mHandle2, mImage1);
+ mAvrcpCoverArtStorage.addImage(mDevice1, "1", mImage1);
+ mAvrcpCoverArtStorage.addImage(mDevice1, "2", mImage1);
mAvrcpCoverArtStorage.clear();
- assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, mHandle1)).isFalse();
- assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, mHandle2)).isFalse();
+ assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, "1")).isFalse();
+ assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, "2")).isFalse();
}
@Test
public void clearStorageManyDevices_allImagesRemoved() {
- mAvrcpCoverArtStorage.addImage(mDevice1, mHandle1, mImage1);
- mAvrcpCoverArtStorage.addImage(mDevice1, mHandle2, mImage1);
- mAvrcpCoverArtStorage.addImage(mDevice2, mHandle1, mImage1);
- mAvrcpCoverArtStorage.addImage(mDevice2, mHandle2, mImage1);
+ mAvrcpCoverArtStorage.addImage(mDevice1, "1", mImage1);
+ mAvrcpCoverArtStorage.addImage(mDevice1, "2", mImage1);
+ mAvrcpCoverArtStorage.addImage(mDevice2, "1", mImage1);
+ mAvrcpCoverArtStorage.addImage(mDevice2, "2", mImage1);
mAvrcpCoverArtStorage.clear();
- assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, mHandle1)).isFalse();
- assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, mHandle2)).isFalse();
- assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice2, mHandle1)).isFalse();
- assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice2, mHandle2)).isFalse();
+ assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, "1")).isFalse();
+ assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice1, "2")).isFalse();
+ assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice2, "1")).isFalse();
+ assertThat(mAvrcpCoverArtStorage.doesImageExist(mDevice2, "2")).isFalse();
}
@Test
public void toString_returnsDeviceInfo() {
String expectedString =
- "CoverArtStorage:\n"
- + " "
- + mDevice1
- + " ("
- + 1
- + "):"
- + "\n "
- + mHandle1
- + "\n";
-
- mAvrcpCoverArtStorage.addImage(mDevice1, mHandle1, mImage1);
+ "CoverArtStorage:\n" + " " + mDevice1 + " (" + 1 + "):" + "\n " + "1" + "\n";
+
+ mAvrcpCoverArtStorage.addImage(mDevice1, "1", mImage1);
assertThat(mAvrcpCoverArtStorage.toString()).isEqualTo(expectedString);
}
diff --git a/android/app/tests/unit/src/com/android/bluetooth/mapclient/MapClientStateMachineTest.java b/android/app/tests/unit/src/com/android/bluetooth/mapclient/MapClientStateMachineTest.java
index 1f8cfb4a5d..fbd9bf4201 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/mapclient/MapClientStateMachineTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/mapclient/MapClientStateMachineTest.java
@@ -125,6 +125,9 @@ public class MapClientStateMachineTest {
private static final boolean MESSAGE_SEEN = true;
private static final boolean MESSAGE_NOT_SEEN = false;
+ private static final String SMS_HANDLE = "0001";
+ private static final String MMS_HANDLE = "0002";
+
private static final String TEST_MESSAGE_HANDLE = "0123456789000032";
private static final String TEST_MESSAGE = "Hello World!";
private static final String SENT_PATH = "telecom/msg/sent";
@@ -143,9 +146,6 @@ public class MapClientStateMachineTest {
private final BluetoothDevice mDevice = getTestDevice(74);
private final Context mTargetContext =
InstrumentationRegistry.getInstrumentation().getTargetContext();
- private final String mTestMessageSmsHandle = "0001";
- private final String mTestMessageMmsHandle = "0002";
- private final String mTestMessageUnknownHandle = "0003";
private Bmessage mTestIncomingSmsBmessage;
private Bmessage mTestIncomingMmsBmessage;
@@ -231,7 +231,7 @@ public class MapClientStateMachineTest {
createTestMessages();
when(mRequestGetMessage.getMessage()).thenReturn(mTestIncomingSmsBmessage);
- when(mRequestGetMessage.getHandle()).thenReturn(mTestMessageSmsHandle);
+ when(mRequestGetMessage.getHandle()).thenReturn(SMS_HANDLE);
when(mService.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager);
when(mTelephonyManager.isSmsCapable()).thenReturn(false);
@@ -369,16 +369,13 @@ public class MapClientStateMachineTest {
public void testSMSMessageSent() {
masConnected_whenConnecting_isConnected(); // transition to the connected state
- when(mRequestPushMessage.getMsgHandle()).thenReturn(mTestMessageSmsHandle);
+ when(mRequestPushMessage.getMsgHandle()).thenReturn(SMS_HANDLE);
when(mRequestPushMessage.getBMsg()).thenReturn(mTestIncomingSmsBmessage);
sendAndDispatchMessage(MceStateMachine.MSG_MAS_REQUEST_COMPLETED, mRequestPushMessage);
verify(mDatabase)
.storeMessage(
- eq(mTestIncomingSmsBmessage),
- eq(mTestMessageSmsHandle),
- any(),
- eq(MESSAGE_SEEN));
+ eq(mTestIncomingSmsBmessage), eq(SMS_HANDLE), any(), eq(MESSAGE_SEEN));
}
/**
@@ -518,12 +515,7 @@ public class MapClientStateMachineTest {
String dateTime = new ObexTime(Instant.now()).toString();
EventReport event =
createNewEventReport(
- "NewMessage",
- dateTime,
- mTestMessageSmsHandle,
- "telecom/msg/inbox",
- null,
- "SMS_GSM");
+ "NewMessage", dateTime, SMS_HANDLE, "telecom/msg/inbox", null, "SMS_GSM");
sendAndDispatchEvent(event);
@@ -533,10 +525,7 @@ public class MapClientStateMachineTest {
verify(mDatabase)
.storeMessage(
- eq(mTestIncomingSmsBmessage),
- eq(mTestMessageSmsHandle),
- any(),
- eq(MESSAGE_NOT_SEEN));
+ eq(mTestIncomingSmsBmessage), eq(SMS_HANDLE), any(), eq(MESSAGE_NOT_SEEN));
}
/** Test seen status set for new MMS */
@@ -547,15 +536,10 @@ public class MapClientStateMachineTest {
String dateTime = new ObexTime(Instant.now()).toString();
EventReport event =
createNewEventReport(
- "NewMessage",
- dateTime,
- mTestMessageMmsHandle,
- "telecom/msg/inbox",
- null,
- "MMS");
+ "NewMessage", dateTime, MMS_HANDLE, "telecom/msg/inbox", null, "MMS");
when(mRequestGetMessage.getMessage()).thenReturn(mTestIncomingMmsBmessage);
- when(mRequestGetMessage.getHandle()).thenReturn(mTestMessageMmsHandle);
+ when(mRequestGetMessage.getHandle()).thenReturn(MMS_HANDLE);
sendAndDispatchEvent(event);
@@ -565,10 +549,7 @@ public class MapClientStateMachineTest {
verify(mDatabase)
.storeMessage(
- eq(mTestIncomingMmsBmessage),
- eq(mTestMessageMmsHandle),
- any(),
- eq(MESSAGE_NOT_SEEN));
+ eq(mTestIncomingMmsBmessage), eq(MMS_HANDLE), any(), eq(MESSAGE_NOT_SEEN));
}
@Test
@@ -579,15 +560,10 @@ public class MapClientStateMachineTest {
String dateTime = new ObexTime(Instant.now()).toString();
EventReport event =
createNewEventReport(
- "NewMessage",
- dateTime,
- mTestMessageMmsHandle,
- "telecom/msg/inbox",
- null,
- "MMS");
+ "NewMessage", dateTime, MMS_HANDLE, "telecom/msg/inbox", null, "MMS");
// Prepare to send back message content, but use handle B
- when(mRequestGetMessage.getHandle()).thenReturn(mTestMessageUnknownHandle);
+ when(mRequestGetMessage.getHandle()).thenReturn("0003"); // unknown handle
when(mRequestGetMessage.getMessage()).thenReturn(mTestIncomingMmsBmessage);
sendAndDispatchEvent(event);
@@ -607,7 +583,7 @@ public class MapClientStateMachineTest {
masConnected_whenConnecting_isConnected(); // transition to the connected state
com.android.bluetooth.mapclient.Message testMessageListingSms =
- createNewMessage("SMS_GSM", mTestMessageSmsHandle);
+ createNewMessage("SMS_GSM", SMS_HANDLE);
ArrayList<com.android.bluetooth.mapclient.Message> messageListSms = new ArrayList<>();
messageListSms.add(testMessageListingSms);
when(mRequestGetMessagesListing.getList()).thenReturn(messageListSms);
@@ -633,12 +609,12 @@ public class MapClientStateMachineTest {
masConnected_whenConnecting_isConnected(); // transition to the connected state
com.android.bluetooth.mapclient.Message testMessageListingMms =
- createNewMessage("MMS", mTestMessageMmsHandle);
+ createNewMessage("MMS", MMS_HANDLE);
ArrayList<com.android.bluetooth.mapclient.Message> messageListMms = new ArrayList<>();
messageListMms.add(testMessageListingMms);
when(mRequestGetMessage.getMessage()).thenReturn(mTestIncomingMmsBmessage);
- when(mRequestGetMessage.getHandle()).thenReturn(mTestMessageMmsHandle);
+ when(mRequestGetMessage.getHandle()).thenReturn(MMS_HANDLE);
when(mRequestGetMessagesListing.getList()).thenReturn(messageListMms);
sendAndDispatchMessage(
@@ -665,20 +641,14 @@ public class MapClientStateMachineTest {
String dateTime = new ObexTime(Instant.now()).toString();
EventReport event =
createNewEventReport(
- "NewMessage",
- dateTime,
- mTestMessageSmsHandle,
- "telecom/msg/inbox",
- null,
- "SMS_GSM");
+ "NewMessage", dateTime, SMS_HANDLE, "telecom/msg/inbox", null, "SMS_GSM");
sendAndDispatchEvent(event);
verify(mMasClient).makeRequest(any(RequestGetMessage.class));
- MceStateMachine.MessageMetadata messageMetadata =
- mStateMachine.mMessages.get(mTestMessageSmsHandle);
- assertThat(messageMetadata.getHandle()).isEqualTo(mTestMessageSmsHandle);
+ MceStateMachine.MessageMetadata messageMetadata = mStateMachine.mMessages.get(SMS_HANDLE);
+ assertThat(messageMetadata.getHandle()).isEqualTo(SMS_HANDLE);
assertThat(new ObexTime(Instant.ofEpochMilli(messageMetadata.getTimestamp())).toString())
.isEqualTo(dateTime);
}
@@ -725,12 +695,7 @@ public class MapClientStateMachineTest {
String dateTime = new ObexTime(Instant.now()).toString();
EventReport event =
createNewEventReport(
- "NewMessage",
- dateTime,
- mTestMessageSmsHandle,
- "telecom/msg/inbox",
- null,
- "SMS_GSM");
+ "NewMessage", dateTime, SMS_HANDLE, "telecom/msg/inbox", null, "SMS_GSM");
sendAndDispatchEvent(event);
diff --git a/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppTransferTest.java b/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppTransferTest.java
index 80ef0232ec..c122b44579 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppTransferTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppTransferTest.java
@@ -73,20 +73,6 @@ public class BluetoothOppTransferTest {
@Mock BluetoothMethodProxy mCallProxy;
@Mock Context mContext;
- private final Uri mUri = Uri.parse("file://Idontknow/Justmadeitup");
- private final String mHintString = "this is a object that take 4 bytes";
- private final String mFilename = "random.jpg";
- private final String mMimetype = "image/jpeg";
- private final int mDirection = BluetoothShare.DIRECTION_INBOUND;
- private final String mDestination = "01:23:45:67:89:AB";
- private final int mVisibility = BluetoothShare.VISIBILITY_VISIBLE;
- private final int mConfirm = BluetoothShare.USER_CONFIRMATION_AUTO_CONFIRMED;
- private final int mStatus = BluetoothShare.STATUS_PENDING;
- private final int mTotalBytes = 1023;
- private final int mCurrentBytes = 42;
- private final int mTimestamp = 123456789;
- private final boolean mMediaScanned = false;
-
BluetoothOppBatch mBluetoothOppBatch;
BluetoothOppTransfer mTransfer;
BluetoothOppTransfer.EventHandler mEventHandler;
@@ -116,19 +102,19 @@ public class BluetoothOppTransferTest {
mInitShareInfo =
new BluetoothOppShareInfo(
8765,
- mUri,
- mHintString,
- mFilename,
- mMimetype,
- mDirection,
- mDestination,
- mVisibility,
- mConfirm,
- mStatus,
- mTotalBytes,
- mCurrentBytes,
- mTimestamp,
- mMediaScanned);
+ Uri.parse("file://Idontknow/Justmadeitup"),
+ "this is a object that take 4 bytes",
+ "random.jpg",
+ "image/jpeg",
+ BluetoothShare.DIRECTION_INBOUND,
+ "01:23:45:67:89:AB",
+ BluetoothShare.VISIBILITY_VISIBLE,
+ BluetoothShare.USER_CONFIRMATION_AUTO_CONFIRMED,
+ BluetoothShare.STATUS_PENDING,
+ 1023,
+ 42,
+ 123456789,
+ false);
mBluetoothOppBatch = new BluetoothOppBatch(mContext, mInitShareInfo);
mTransfer = new BluetoothOppTransfer(mContext, mBluetoothOppBatch, mSession);
mEventHandler = mTransfer.new EventHandler(Looper.getMainLooper());
@@ -144,19 +130,19 @@ public class BluetoothOppTransferTest {
BluetoothOppShareInfo newShareInfo =
new BluetoothOppShareInfo(
1,
- mUri,
- mHintString,
- mFilename,
- mMimetype,
+ Uri.parse("file://Idontknow/Justmadeitup"),
+ "this is a object that take 4 bytes",
+ "random.jpg",
+ "image/jpeg",
BluetoothShare.DIRECTION_INBOUND,
- mDestination,
- mVisibility,
+ "01:23:45:67:89:AB",
+ BluetoothShare.VISIBILITY_VISIBLE,
BluetoothShare.USER_CONFIRMATION_AUTO_CONFIRMED,
- mStatus,
- mTotalBytes,
- mCurrentBytes,
- mTimestamp,
- mMediaScanned);
+ BluetoothShare.STATUS_PENDING,
+ 1023,
+ 42,
+ 123456789,
+ false);
doAnswer(
invocation -> {
@@ -238,19 +224,19 @@ public class BluetoothOppTransferTest {
mInitShareInfo =
new BluetoothOppShareInfo(
123,
- mUri,
- mHintString,
- mFilename,
- mMimetype,
+ Uri.parse("file://Idontknow/Justmadeitup"),
+ "this is a object that take 4 bytes",
+ "random.jpg",
+ "image/jpeg",
BluetoothShare.DIRECTION_OUTBOUND,
- mDestination,
- mVisibility,
- mConfirm,
- mStatus,
- mTotalBytes,
- mCurrentBytes,
- mTimestamp,
- mMediaScanned);
+ "01:23:45:67:89:AB",
+ BluetoothShare.VISIBILITY_VISIBLE,
+ BluetoothShare.USER_CONFIRMATION_AUTO_CONFIRMED,
+ BluetoothShare.STATUS_PENDING,
+ 1023,
+ 42,
+ 123456789,
+ false);
mBluetoothOppBatch = new BluetoothOppBatch(mContext, mInitShareInfo);
mTransfer = new BluetoothOppTransfer(mContext, mBluetoothOppBatch, mSession);
mEventHandler = mTransfer.new EventHandler(Looper.getMainLooper());
@@ -286,19 +272,19 @@ public class BluetoothOppTransferTest {
mInitShareInfo =
new BluetoothOppShareInfo(
123,
- mUri,
- mHintString,
- mFilename,
- mMimetype,
+ Uri.parse("file://Idontknow/Justmadeitup"),
+ "this is a object that take 4 bytes",
+ "random.jpg",
+ "image/jpeg",
BluetoothShare.DIRECTION_OUTBOUND,
- mDestination,
- mVisibility,
- mConfirm,
- mStatus,
- mTotalBytes,
- mCurrentBytes,
- mTimestamp,
- mMediaScanned);
+ "01:23:45:67:89:AB",
+ BluetoothShare.VISIBILITY_VISIBLE,
+ BluetoothShare.USER_CONFIRMATION_AUTO_CONFIRMED,
+ BluetoothShare.STATUS_PENDING,
+ 1023,
+ 42,
+ 123456789,
+ false);
mBluetoothOppBatch = new BluetoothOppBatch(mContext, mInitShareInfo);
mTransfer = new BluetoothOppTransfer(mContext, mBluetoothOppBatch, mSession);
mEventHandler = mTransfer.new EventHandler(Looper.getMainLooper());
@@ -318,19 +304,19 @@ public class BluetoothOppTransferTest {
BluetoothOppShareInfo newInfo =
new BluetoothOppShareInfo(
321,
- mUri,
- mHintString,
- mFilename,
- mMimetype,
- mDirection,
- mDestination,
- mVisibility,
- mConfirm,
- mStatus,
- mTotalBytes,
- mCurrentBytes,
- mTimestamp,
- mMediaScanned);
+ Uri.parse("file://Idontknow/Justmadeitup"),
+ "this is a object that take 4 bytes",
+ "random.jpg",
+ "image/jpeg",
+ BluetoothShare.DIRECTION_INBOUND,
+ "01:23:45:67:89:AB",
+ BluetoothShare.VISIBILITY_VISIBLE,
+ BluetoothShare.USER_CONFIRMATION_AUTO_CONFIRMED,
+ BluetoothShare.STATUS_PENDING,
+ 1023,
+ 42,
+ 123456789,
+ false);
// Adding new info will assign value to mCurrentShare
mBluetoothOppBatch.addShare(newInfo);
mEventHandler.handleMessage(message);
@@ -387,7 +373,7 @@ public class BluetoothOppTransferTest {
.getTargetContext()
.getSystemService(BluetoothManager.class)
.getAdapter()
- .getRemoteDevice(mDestination);
+ .getRemoteDevice("01:23:45:67:89:AB");
BluetoothOppTransfer transfer = new BluetoothOppTransfer(mContext, mBluetoothOppBatch);
transfer.mCurrentShare = mInitShareInfo;
transfer.mCurrentShare.mConfirm = BluetoothShare.USER_CONFIRMATION_PENDING;
@@ -410,7 +396,7 @@ public class BluetoothOppTransferTest {
.getTargetContext()
.getSystemService(BluetoothManager.class)
.getAdapter()
- .getRemoteDevice(mDestination);
+ .getRemoteDevice("01:23:45:67:89:AB");
BluetoothOppTransfer transfer = new BluetoothOppTransfer(mContext, mBluetoothOppBatch);
transfer.mCurrentShare = mInitShareInfo;