Loading android/app/src/com/android/bluetooth/vc/VolumeControlService.java +15 −3 Original line number Diff line number Diff line Loading @@ -79,7 +79,10 @@ public class VolumeControlService extends ProfileService { @VisibleForTesting RemoteCallbackList<IBluetoothVolumeControlCallback> mCallbacks; private class VolumeControlOffsetDescriptor { @VisibleForTesting static class VolumeControlOffsetDescriptor { Map<Integer, Descriptor> mVolumeOffsets; private class Descriptor { Descriptor() { mValue = 0; Loading @@ -94,15 +97,18 @@ public class VolumeControlService extends ProfileService { VolumeControlOffsetDescriptor() { mVolumeOffsets = new HashMap<>(); } int size() { return mVolumeOffsets.size(); } void add(int id) { Descriptor d = mVolumeOffsets.get(id); if (d == null) { mVolumeOffsets.put(id, new Descriptor()); } } boolean setValue(int id, int value) { Descriptor d = mVolumeOffsets.get(id); if (d == null) { Loading @@ -111,6 +117,7 @@ public class VolumeControlService extends ProfileService { d.mValue = value; return true; } int getValue(int id) { Descriptor d = mVolumeOffsets.get(id); if (d == null) { Loading @@ -118,6 +125,7 @@ public class VolumeControlService extends ProfileService { } return d.mValue; } boolean setDescription(int id, String desc) { Descriptor d = mVolumeOffsets.get(id); if (d == null) { Loading @@ -126,6 +134,7 @@ public class VolumeControlService extends ProfileService { d.mDescription = desc; return true; } String getDescription(int id) { Descriptor d = mVolumeOffsets.get(id); if (d == null) { Loading @@ -133,6 +142,7 @@ public class VolumeControlService extends ProfileService { } return d.mDescription; } boolean setLocation(int id, int location) { Descriptor d = mVolumeOffsets.get(id); if (d == null) { Loading @@ -141,6 +151,7 @@ public class VolumeControlService extends ProfileService { d.mLocation = location; return true; } int getLocation(int id) { Descriptor d = mVolumeOffsets.get(id); if (d == null) { Loading @@ -148,12 +159,15 @@ public class VolumeControlService extends ProfileService { } return d.mLocation; } void remove(int id) { mVolumeOffsets.remove(id); } void clear() { mVolumeOffsets.clear(); } void dump(StringBuilder sb) { for (Map.Entry<Integer, Descriptor> entry : mVolumeOffsets.entrySet()) { Descriptor descriptor = entry.getValue(); Loading @@ -164,8 +178,6 @@ public class VolumeControlService extends ProfileService { ProfileService.println(sb, " description: " + descriptor.mDescription); } } Map<Integer, Descriptor> mVolumeOffsets; } @VisibleForTesting Loading android/app/tests/unit/src/com/android/bluetooth/vc/VolumeControlServiceTest.java +41 −0 Original line number Diff line number Diff line Loading @@ -718,6 +718,47 @@ public class VolumeControlServiceTest { verify(mNativeInterface).unmuteGroup(groupId); } @Test public void testVolumeControlOffsetDescriptor() { VolumeControlService.VolumeControlOffsetDescriptor descriptor = new VolumeControlService.VolumeControlOffsetDescriptor(); int invalidId = -1; int validId = 10; int testValue = 100; String testDesc = "testDescription"; int testLocation = 10000; Assert.assertEquals(0, descriptor.size()); descriptor.add(validId); Assert.assertEquals(1, descriptor.size()); Assert.assertFalse(descriptor.setValue(invalidId, testValue)); Assert.assertTrue(descriptor.setValue(validId, testValue)); Assert.assertEquals(0, descriptor.getValue(invalidId)); Assert.assertEquals(testValue, descriptor.getValue(validId)); Assert.assertFalse(descriptor.setDescription(invalidId, testDesc)); Assert.assertTrue(descriptor.setDescription(validId, testDesc)); Assert.assertEquals(null, descriptor.getDescription(invalidId)); Assert.assertEquals(testDesc, descriptor.getDescription(validId)); Assert.assertFalse(descriptor.setLocation(invalidId, testLocation)); Assert.assertTrue(descriptor.setLocation(validId, testLocation)); Assert.assertEquals(0, descriptor.getLocation(invalidId)); Assert.assertEquals(testLocation, descriptor.getLocation(validId)); StringBuilder sb = new StringBuilder(); descriptor.dump(sb); Assert.assertTrue(sb.toString().contains(testDesc)); descriptor.add(validId + 1); Assert.assertEquals(2, descriptor.size()); descriptor.remove(validId); Assert.assertEquals(1, descriptor.size()); descriptor.clear(); Assert.assertEquals(0, descriptor.size()); } private void connectDevice(BluetoothDevice device) throws Exception { VolumeControlStackEvent connCompletedEvent; Loading Loading
android/app/src/com/android/bluetooth/vc/VolumeControlService.java +15 −3 Original line number Diff line number Diff line Loading @@ -79,7 +79,10 @@ public class VolumeControlService extends ProfileService { @VisibleForTesting RemoteCallbackList<IBluetoothVolumeControlCallback> mCallbacks; private class VolumeControlOffsetDescriptor { @VisibleForTesting static class VolumeControlOffsetDescriptor { Map<Integer, Descriptor> mVolumeOffsets; private class Descriptor { Descriptor() { mValue = 0; Loading @@ -94,15 +97,18 @@ public class VolumeControlService extends ProfileService { VolumeControlOffsetDescriptor() { mVolumeOffsets = new HashMap<>(); } int size() { return mVolumeOffsets.size(); } void add(int id) { Descriptor d = mVolumeOffsets.get(id); if (d == null) { mVolumeOffsets.put(id, new Descriptor()); } } boolean setValue(int id, int value) { Descriptor d = mVolumeOffsets.get(id); if (d == null) { Loading @@ -111,6 +117,7 @@ public class VolumeControlService extends ProfileService { d.mValue = value; return true; } int getValue(int id) { Descriptor d = mVolumeOffsets.get(id); if (d == null) { Loading @@ -118,6 +125,7 @@ public class VolumeControlService extends ProfileService { } return d.mValue; } boolean setDescription(int id, String desc) { Descriptor d = mVolumeOffsets.get(id); if (d == null) { Loading @@ -126,6 +134,7 @@ public class VolumeControlService extends ProfileService { d.mDescription = desc; return true; } String getDescription(int id) { Descriptor d = mVolumeOffsets.get(id); if (d == null) { Loading @@ -133,6 +142,7 @@ public class VolumeControlService extends ProfileService { } return d.mDescription; } boolean setLocation(int id, int location) { Descriptor d = mVolumeOffsets.get(id); if (d == null) { Loading @@ -141,6 +151,7 @@ public class VolumeControlService extends ProfileService { d.mLocation = location; return true; } int getLocation(int id) { Descriptor d = mVolumeOffsets.get(id); if (d == null) { Loading @@ -148,12 +159,15 @@ public class VolumeControlService extends ProfileService { } return d.mLocation; } void remove(int id) { mVolumeOffsets.remove(id); } void clear() { mVolumeOffsets.clear(); } void dump(StringBuilder sb) { for (Map.Entry<Integer, Descriptor> entry : mVolumeOffsets.entrySet()) { Descriptor descriptor = entry.getValue(); Loading @@ -164,8 +178,6 @@ public class VolumeControlService extends ProfileService { ProfileService.println(sb, " description: " + descriptor.mDescription); } } Map<Integer, Descriptor> mVolumeOffsets; } @VisibleForTesting Loading
android/app/tests/unit/src/com/android/bluetooth/vc/VolumeControlServiceTest.java +41 −0 Original line number Diff line number Diff line Loading @@ -718,6 +718,47 @@ public class VolumeControlServiceTest { verify(mNativeInterface).unmuteGroup(groupId); } @Test public void testVolumeControlOffsetDescriptor() { VolumeControlService.VolumeControlOffsetDescriptor descriptor = new VolumeControlService.VolumeControlOffsetDescriptor(); int invalidId = -1; int validId = 10; int testValue = 100; String testDesc = "testDescription"; int testLocation = 10000; Assert.assertEquals(0, descriptor.size()); descriptor.add(validId); Assert.assertEquals(1, descriptor.size()); Assert.assertFalse(descriptor.setValue(invalidId, testValue)); Assert.assertTrue(descriptor.setValue(validId, testValue)); Assert.assertEquals(0, descriptor.getValue(invalidId)); Assert.assertEquals(testValue, descriptor.getValue(validId)); Assert.assertFalse(descriptor.setDescription(invalidId, testDesc)); Assert.assertTrue(descriptor.setDescription(validId, testDesc)); Assert.assertEquals(null, descriptor.getDescription(invalidId)); Assert.assertEquals(testDesc, descriptor.getDescription(validId)); Assert.assertFalse(descriptor.setLocation(invalidId, testLocation)); Assert.assertTrue(descriptor.setLocation(validId, testLocation)); Assert.assertEquals(0, descriptor.getLocation(invalidId)); Assert.assertEquals(testLocation, descriptor.getLocation(validId)); StringBuilder sb = new StringBuilder(); descriptor.dump(sb); Assert.assertTrue(sb.toString().contains(testDesc)); descriptor.add(validId + 1); Assert.assertEquals(2, descriptor.size()); descriptor.remove(validId); Assert.assertEquals(1, descriptor.size()); descriptor.clear(); Assert.assertEquals(0, descriptor.size()); } private void connectDevice(BluetoothDevice device) throws Exception { VolumeControlStackEvent connCompletedEvent; Loading