Fix errorprone issues - part 2

Errorprone build that is triggered for BluetoothInstrumentationTests is
throwing some new errors that must be fixed before new tests are added.

Bug: 150670922
Test: BluetoothInstrumentationTests
Tag: #stability
Change-Id: Ie492b115773e97e346170821d76b412569e9064a
diff --git a/tests/unit/src/com/android/bluetooth/StateMachineTest.java b/tests/unit/src/com/android/bluetooth/StateMachineTest.java
index 31f97bb..7bd6dbd 100644
--- a/tests/unit/src/com/android/bluetooth/StateMachineTest.java
+++ b/tests/unit/src/com/android/bluetooth/StateMachineTest.java
@@ -918,7 +918,7 @@
             }
         }
 
-        class ChildState extends State {
+        static class ChildState extends State {
             @Override
             public boolean processMessage(Message message) {
                 return NOT_HANDLED;
@@ -1013,7 +1013,7 @@
             }
         }
 
-        class ChildState2 extends State {
+        static class ChildState2 extends State {
             @Override
             public boolean processMessage(Message message) {
                 return NOT_HANDLED;
@@ -1586,7 +1586,7 @@
          * without a delay the arrival time difference should always >= to SM7_DELAY_TIME.
          */
         long arrivalTimeDiff = sm7.mArrivalTimeMsg3 - sm7.mArrivalTimeMsg2;
-        long expectedDelay = sm7.SM7_DELAY_TIME - SM7_DELAY_FUDGE;
+        long expectedDelay = (long) sm7.SM7_DELAY_TIME - SM7_DELAY_FUDGE;
         if (sm7.isDbg()) tlog("testStateMachine7: expect " + arrivalTimeDiff
                 + " >= " + expectedDelay);
         Assert.assertTrue(arrivalTimeDiff >= expectedDelay);
diff --git a/tests/unit/src/com/android/bluetooth/audio_util/MediaPlayerListTest.java b/tests/unit/src/com/android/bluetooth/audio_util/MediaPlayerListTest.java
index 78e131f..44054f3 100644
--- a/tests/unit/src/com/android/bluetooth/audio_util/MediaPlayerListTest.java
+++ b/tests/unit/src/com/android/bluetooth/audio_util/MediaPlayerListTest.java
@@ -89,7 +89,6 @@
         when(mMockContext.registerReceiver(any(), any())).thenReturn(null);
         when(mMockContext.getApplicationContext()).thenReturn(mMockContext);
         when(mMockContext.getPackageManager()).thenReturn(mockPackageManager);
-        List<ResolveInfo> playerList = new ArrayList<ResolveInfo>();
         when(mockPackageManager.queryIntentServices(any(), anyInt())).thenReturn(null);
 
         Method method = BrowsablePlayerConnector.class.getDeclaredMethod("setInstanceForTesting",
diff --git a/tests/unit/src/com/android/bluetooth/avrcpcontroller/AvrcpItemTest.java b/tests/unit/src/com/android/bluetooth/avrcpcontroller/AvrcpItemTest.java
index b6aacf6..83ae419 100644
--- a/tests/unit/src/com/android/bluetooth/avrcpcontroller/AvrcpItemTest.java
+++ b/tests/unit/src/com/android/bluetooth/avrcpcontroller/AvrcpItemTest.java
@@ -371,7 +371,7 @@
         Assert.assertEquals(UUID, desc.getMediaId());
         Assert.assertEquals(null, desc.getMediaUri());
         Assert.assertEquals(title, desc.getTitle().toString());
-        Assert.assertEquals(null, desc.getSubtitle());
+        Assert.assertEquals(desc.getSubtitle(), null);
         Assert.assertEquals(uri, desc.getIconUri());
         Assert.assertEquals(null, desc.getIconBitmap());
     }
@@ -400,7 +400,7 @@
         Assert.assertEquals(UUID, desc.getMediaId());
         Assert.assertEquals(null, desc.getMediaUri());
         Assert.assertEquals(displayName, desc.getTitle().toString());
-        Assert.assertEquals(null, desc.getSubtitle());
+        Assert.assertEquals(desc.getSubtitle(), null);
         Assert.assertEquals(uri, desc.getIconUri());
         Assert.assertEquals(null, desc.getIconBitmap());
     }
@@ -427,7 +427,7 @@
         Assert.assertEquals(UUID, desc.getMediaId());
         Assert.assertEquals(null, desc.getMediaUri());
         Assert.assertEquals(title, desc.getTitle().toString());
-        Assert.assertEquals(null, desc.getSubtitle());
+        Assert.assertEquals(desc.getSubtitle(), null);
         Assert.assertEquals(uri, desc.getIconUri());
         Assert.assertEquals(null, desc.getIconBitmap());
     }
diff --git a/tests/unit/src/com/android/bluetooth/btservice/bluetoothKeystore/BluetoothKeystoreServiceTest.java b/tests/unit/src/com/android/bluetooth/btservice/bluetoothKeystore/BluetoothKeystoreServiceTest.java
index 1719b69..73c0240 100644
--- a/tests/unit/src/com/android/bluetooth/btservice/bluetoothKeystore/BluetoothKeystoreServiceTest.java
+++ b/tests/unit/src/com/android/bluetooth/btservice/bluetoothKeystore/BluetoothKeystoreServiceTest.java
@@ -25,7 +25,7 @@
 import java.nio.file.Paths;
 import java.security.NoSuchAlgorithmException;
 import java.util.HashMap;
-import java.util.LinkedList;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
@@ -113,7 +113,7 @@
             "LE_KEY_LID ="
             );
 
-    private List<String> mConfigData = new LinkedList<>();
+    private List<String> mConfigData = new ArrayList<>();
 
     private Map<String, String> mNameDecryptKeyResult = new HashMap<>();
 
diff --git a/tests/unit/src/com/android/bluetooth/hid/HidDeviceTest.java b/tests/unit/src/com/android/bluetooth/hid/HidDeviceTest.java
index 1078a2e..a448315 100644
--- a/tests/unit/src/com/android/bluetooth/hid/HidDeviceTest.java
+++ b/tests/unit/src/com/android/bluetooth/hid/HidDeviceTest.java
@@ -166,7 +166,7 @@
             try {
                 mConnectionStateChangedQueue.put(intent);
             } catch (InterruptedException e) {
-                Assert.fail("Cannot add Intent to the queue");
+                throw new AssertionError("Cannot add Intent to the queue", e);
             }
         }
     }
@@ -177,9 +177,8 @@
             Assert.assertNotNull(intent);
             return intent;
         } catch (InterruptedException e) {
-            Assert.fail("Cannot obtain an Intent from the queue");
+            throw new AssertionError("Cannot obtain an Intent from the queue", e);
         }
-        return null;
     }
 
     private void verifyConnectionStateIntent(int timeoutMs, BluetoothDevice device, int newState,
@@ -200,7 +199,7 @@
             int lastCallbackType = lastCallback;
             Assert.assertEquals(callbackType, lastCallbackType);
         } catch (InterruptedException e) {
-            Assert.fail("Cannot obtain a callback from the queue");
+            throw new AssertionError("Cannot obtain a callback from the queue", e);
         }
     }
 
@@ -213,7 +212,7 @@
                     mCallbackQueue.put(CALLBACK_APP_UNREGISTERED);
                 }
             } catch (InterruptedException e) {
-                Assert.fail("Cannot add Intent to the queue");
+                throw new AssertionError("Cannot add Intent to the queue", e);
             }
         }
 
@@ -225,7 +224,7 @@
             try {
                 mCallbackQueue.put(CALLBACK_ON_GET_REPORT);
             } catch (InterruptedException e) {
-                Assert.fail("Cannot add Intent to the queue");
+                throw new AssertionError("Cannot add Intent to the queue", e);
             }
         }
 
@@ -233,7 +232,7 @@
             try {
                 mCallbackQueue.put(CALLBACK_ON_SET_REPORT);
             } catch (InterruptedException e) {
-                Assert.fail("Cannot add Intent to the queue");
+                throw new AssertionError("Cannot add Intent to the queue", e);
             }
         }
 
@@ -241,7 +240,7 @@
             try {
                 mCallbackQueue.put(CALLBACK_ON_SET_PROTOCOL);
             } catch (InterruptedException e) {
-                Assert.fail("Cannot add Intent to the queue");
+                throw new AssertionError("Cannot add Intent to the queue", e);
             }
         }
 
@@ -249,7 +248,8 @@
             try {
                 mCallbackQueue.put(CALLBACK_ON_INTR_DATA);
             } catch (InterruptedException e) {
-                Assert.fail("Cannot add Intent to the queue");
+                throw new AssertionError("Cannot add Intent to the queue", e);
+
             }
         }
 
@@ -257,7 +257,7 @@
             try {
                 mCallbackQueue.put(CALLBACK_ON_VIRTUAL_UNPLUG);
             } catch (InterruptedException e) {
-                Assert.fail("Cannot add Intent to the queue");
+                throw new AssertionError("Cannot add Intent to the queue", e);
             }
         }
     }
diff --git a/tests/unit/src/com/android/bluetooth/telephony/BluetoothInCallServiceTest.java b/tests/unit/src/com/android/bluetooth/telephony/BluetoothInCallServiceTest.java
index 878ad8b..dd5dbe9 100644
--- a/tests/unit/src/com/android/bluetooth/telephony/BluetoothInCallServiceTest.java
+++ b/tests/unit/src/com/android/bluetooth/telephony/BluetoothInCallServiceTest.java
@@ -54,7 +54,7 @@
 import com.android.bluetooth.hfp.BluetoothHeadsetProxy;
 
 import java.util.ArrayList;
-import java.util.LinkedList;
+import java.util.Arrays;
 import java.util.List;
 import java.util.UUID;
 import java.util.concurrent.TimeUnit;
@@ -312,10 +312,8 @@
         when(parentCall.getGenericConferenceActiveChildCallId())
                 .thenReturn(confCall1Id);
         when(parentCall.isConference()).thenReturn(true);
-        List<String> childrenIds = new LinkedList<String>(){{
-            add(confCall1.getTelecomCallId());
-            add(confCall2.getTelecomCallId());
-        }};
+        List<String> childrenIds = Arrays.asList(confCall1.getTelecomCallId(),
+                confCall2.getTelecomCallId());
         when(parentCall.getChildrenIds()).thenReturn(childrenIds);
         //Add links from child calls to parent
         String parentId = parentCall.getTelecomCallId();
@@ -375,10 +373,8 @@
         String foregroundCallId = foregroundCall.getTelecomCallId();
         when(parentCall.getGenericConferenceActiveChildCallId()).thenReturn(foregroundCallId);
         when(parentCall.isConference()).thenReturn(true);
-        List<String> childrenIds = new LinkedList<String>(){{
-            add(foregroundCall.getTelecomCallId());
-            add(heldCall.getTelecomCallId());
-        }};
+        List<String> childrenIds = Arrays.asList(foregroundCall.getTelecomCallId(),
+                heldCall.getTelecomCallId());
         when(parentCall.getChildrenIds()).thenReturn(childrenIds);
         //Add links from child calls to parent
         String parentId = parentCall.getTelecomCallId();
@@ -423,10 +419,8 @@
         when(parentCall.wasConferencePreviouslyMerged()).thenReturn(true);
         //when(parentCall.getConferenceLevelActiveCall()).thenReturn(confCall1);
         when(parentCall.isConference()).thenReturn(true);
-        List<String> childrenIds = new LinkedList<String>(){{
-            add(confCall1.getTelecomCallId());
-            add(confCall2.getTelecomCallId());
-        }};
+        List<String> childrenIds = Arrays.asList(confCall1.getTelecomCallId(),
+            confCall2.getTelecomCallId());
         when(parentCall.getChildrenIds()).thenReturn(childrenIds);
         //Add links from child calls to parent
         String parentId = parentCall.getTelecomCallId();
@@ -687,10 +681,8 @@
         removeCallCapability(parentConfCall, Connection.CAPABILITY_CONFERENCE_HAS_NO_CHILDREN);
         when(parentConfCall.wasConferencePreviouslyMerged()).thenReturn(true);
         when(parentConfCall.isConference()).thenReturn(true);
-        List<String> childrenIds = new LinkedList<String>(){{
-            add(confCall1.getTelecomCallId());
-            add(confCall2.getTelecomCallId());
-        }};
+        List<String> childrenIds = Arrays.asList(confCall1.getTelecomCallId(),
+                confCall2.getTelecomCallId());
         when(parentConfCall.getChildrenIds()).thenReturn(childrenIds);
 
         clearInvocations(mMockBluetoothHeadset);
@@ -819,10 +811,8 @@
         removeCallCapability(parentCall, Connection.CAPABILITY_CONFERENCE_HAS_NO_CHILDREN);
         when(parentCall.isConference()).thenReturn(true);
         when(parentCall.wasConferencePreviouslyMerged()).thenReturn(false);
-        List<String> childrenIds = new LinkedList<String>(){{
-            add(foregroundCall.getTelecomCallId());
-            add(heldCall.getTelecomCallId());
-        }};
+        List<String> childrenIds = Arrays.asList(foregroundCall.getTelecomCallId(),
+                heldCall.getTelecomCallId());
         when(parentCall.getChildrenIds()).thenReturn(childrenIds);
 
         clearInvocations(mMockBluetoothHeadset);
@@ -868,10 +858,8 @@
         addCallCapability(parentCall, Connection.CAPABILITY_MERGE_CONFERENCE);
         removeCallCapability(parentCall, Connection.CAPABILITY_CONFERENCE_HAS_NO_CHILDREN);
         when(parentCall.isConference()).thenReturn(true);
-        List<String> childrenIds = new LinkedList<String>(){{
-            add(foregroundCall.getTelecomCallId());
-            add(heldCall.getTelecomCallId());
-        }};
+        List<String> childrenIds = Arrays.asList(foregroundCall.getTelecomCallId(),
+                heldCall.getTelecomCallId());
         when(parentCall.getChildrenIds()).thenReturn(childrenIds);
 
         mBluetoothInCallService.onCallAdded(parentCall);