Loading android/app/src/com/android/bluetooth/hap/HapClientNativeInterface.java +1 −27 Original line number Diff line number Diff line Loading @@ -23,7 +23,6 @@ import android.bluetooth.BluetoothHapPresetInfo; import android.util.Log; import com.android.bluetooth.Utils; import com.android.internal.annotations.GuardedBy; import com.android.internal.annotations.VisibleForTesting; import java.util.ArrayList; Loading @@ -35,38 +34,13 @@ public class HapClientNativeInterface { private final BluetoothAdapter mAdapter; @GuardedBy("INSTANCE_LOCK") private static HapClientNativeInterface sInstance; private static final Object INSTANCE_LOCK = new Object(); private HapClientNativeInterface() { public HapClientNativeInterface() { mAdapter = BluetoothAdapter.getDefaultAdapter(); if (mAdapter == null) { Log.wtf(TAG, "No Bluetooth Adapter Available"); } } /** * Get singleton instance. */ public static HapClientNativeInterface getInstance() { synchronized (INSTANCE_LOCK) { if (sInstance == null) { sInstance = new HapClientNativeInterface(); } return sInstance; } } /** Set singleton instance. */ @VisibleForTesting public static void setInstance(HapClientNativeInterface instance) { synchronized (INSTANCE_LOCK) { sInstance = instance; } } /** * Initiates HapClientService connection to a remote device. * Loading android/app/src/com/android/bluetooth/hap/HapClientService.java +7 −6 Original line number Diff line number Diff line Loading @@ -119,8 +119,14 @@ public class HapClientService extends ProfileService { } public HapClientService(AdapterService adapterService) { this(adapterService, new HapClientNativeInterface()); } @VisibleForTesting HapClientService(AdapterService adapterService, HapClientNativeInterface nativeInterface) { super(adapterService); mAdapterService = Objects.requireNonNull(adapterService); mHapClientNativeInterface = Objects.requireNonNull(nativeInterface); } @Override Loading @@ -141,15 +147,11 @@ public class HapClientService extends ProfileService { throw new IllegalStateException("start() called twice"); } // Get HapClientNativeInterface, DatabaseManager, AudioManager. // None of them can be null. // Get DatabaseManager mDatabaseManager = Objects.requireNonNull( mAdapterService.getDatabase(), "DatabaseManager cannot be null when HapClientService starts"); mHapClientNativeInterface = Objects.requireNonNull( HapClientNativeInterface.getInstance(), "HapClientNativeInterface cannot be null when HapClientService starts"); // Start handler thread for state machines mHandler = new Handler(Looper.getMainLooper()); Loading Loading @@ -204,7 +206,6 @@ public class HapClientService extends ProfileService { // Cleanup GATT interface mHapClientNativeInterface.cleanup(); mHapClientNativeInterface = null; // Cleanup the internals mDeviceCurrentPresetMap.clear(); Loading android/app/tests/unit/src/com/android/bluetooth/btservice/ProfileServiceTest.java +8 −18 Original line number Diff line number Diff line Loading @@ -35,7 +35,6 @@ import com.android.bluetooth.a2dp.A2dpNativeInterface; import com.android.bluetooth.avrcp.AvrcpNativeInterface; import com.android.bluetooth.btservice.storage.DatabaseManager; import com.android.bluetooth.csip.CsipSetCoordinatorNativeInterface; import com.android.bluetooth.hap.HapClientNativeInterface; import com.android.bluetooth.hearingaid.HearingAidNativeInterface; import com.android.bluetooth.hfp.HeadsetNativeInterface; import com.android.bluetooth.hid.HidDeviceNativeInterface; Loading @@ -57,6 +56,7 @@ import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; import java.lang.reflect.InvocationTargetException; import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.concurrent.FutureTask; Loading Loading @@ -85,7 +85,6 @@ public class ProfileServiceTest { @Mock private HidHostNativeInterface mHidHostNativeInterface; @Mock private PanNativeInterface mPanNativeInterface; @Mock private CsipSetCoordinatorNativeInterface mCsipSetCoordinatorInterface; @Mock private HapClientNativeInterface mHapClientInterface; @Mock private LeAudioNativeInterface mLeAudioInterface; @Mock private VolumeControlNativeInterface mVolumeControlInterface; Loading @@ -103,11 +102,6 @@ public class ProfileServiceTest { private void setAllProfilesState(int state, int invocationNumber) { int profileCount = mProfiles.length; for (int profile : mProfiles) { if (profile == BluetoothProfile.GATT) { // GattService is no longer a service to be start independently profileCount--; continue; } setProfileState(profile, state); } if (invocationNumber == 0) { Loading Loading @@ -145,7 +139,13 @@ public class ProfileServiceTest { doReturn(false).when(mAdapterService).isA2dpOffloadEnabled(); doReturn(false).when(mAdapterService).pbapPseDynamicVersionUpgradeIsEnabled(); mProfiles = Config.getSupportedProfiles(); mProfiles = Arrays.stream(Config.getSupportedProfiles()) .filter( profile -> profile != BluetoothProfile.HAP_CLIENT && profile != BluetoothProfile.GATT) .toArray(); TestUtils.setAdapterService(mAdapterService); Assert.assertNotNull(AdapterService.getAdapterService()); Loading @@ -158,7 +158,6 @@ public class ProfileServiceTest { HidHostNativeInterface.setInstance(mHidHostNativeInterface); PanNativeInterface.setInstance(mPanNativeInterface); CsipSetCoordinatorNativeInterface.setInstance(mCsipSetCoordinatorInterface); HapClientNativeInterface.setInstance(mHapClientInterface); LeAudioNativeInterface.setInstance(mLeAudioInterface); VolumeControlNativeInterface.setInstance(mVolumeControlInterface); } Loading @@ -177,7 +176,6 @@ public class ProfileServiceTest { HidHostNativeInterface.setInstance(null); PanNativeInterface.setInstance(null); CsipSetCoordinatorNativeInterface.setInstance(null); HapClientNativeInterface.setInstance(null); LeAudioNativeInterface.setInstance(null); VolumeControlNativeInterface.setInstance(null); } Loading Loading @@ -242,10 +240,6 @@ public class ProfileServiceTest { public void testRepeatedEnableDisableSingly() { int profileNumber = 0; for (int profile : mProfiles) { if (profile == BluetoothProfile.GATT) { // GattService is no longer a service to be start independently continue; } for (int i = 0; i < NUM_REPEATS; i++) { setProfileState(profile, BluetoothAdapter.STATE_ON); ArgumentCaptor<ProfileService> start = Loading @@ -272,10 +266,6 @@ public class ProfileServiceTest { public void testProfileServiceRegisterUnregister() { int profileNumber = 0; for (int profile : mProfiles) { if (profile == BluetoothProfile.GATT) { // GattService is no longer a service to be start independently continue; } for (int i = 0; i < NUM_REPEATS; i++) { setProfileState(profile, BluetoothAdapter.STATE_ON); ArgumentCaptor<ProfileService> start = Loading android/app/tests/unit/src/com/android/bluetooth/hap/HapClientNativeInterfaceTest.java +1 −1 Original line number Diff line number Diff line Loading @@ -47,7 +47,7 @@ public class HapClientNativeInterfaceTest { public void setUp() throws Exception { when(mService.isAvailable()).thenReturn(true); HapClientService.setHapClient(mService); mNativeInterface = HapClientNativeInterface.getInstance(); mNativeInterface = new HapClientNativeInterface(); } @After Loading android/app/tests/unit/src/com/android/bluetooth/hap/HapClientTest.java +1 −3 Original line number Diff line number Diff line Loading @@ -126,7 +126,6 @@ public class HapClientTest { mAdapter = BluetoothAdapter.getDefaultAdapter(); mAttributionSource = mAdapter.getAttributionSource(); HapClientNativeInterface.setInstance(mNativeInterface); startService(); mService.mFactory = mServiceFactory; doReturn(mCsipService).when(mServiceFactory).getCsipSetCoordinatorService(); Loading Loading @@ -200,13 +199,12 @@ public class HapClientTest { mService.mCallbacks.unregister(mCallback); stopService(); HapClientNativeInterface.setInstance(null); mAdapter = null; } private void startService() throws TimeoutException { mService = new HapClientService(mAdapterService); mService = new HapClientService(mAdapterService, mNativeInterface); mService.start(); mService.setAvailable(true); } Loading Loading
android/app/src/com/android/bluetooth/hap/HapClientNativeInterface.java +1 −27 Original line number Diff line number Diff line Loading @@ -23,7 +23,6 @@ import android.bluetooth.BluetoothHapPresetInfo; import android.util.Log; import com.android.bluetooth.Utils; import com.android.internal.annotations.GuardedBy; import com.android.internal.annotations.VisibleForTesting; import java.util.ArrayList; Loading @@ -35,38 +34,13 @@ public class HapClientNativeInterface { private final BluetoothAdapter mAdapter; @GuardedBy("INSTANCE_LOCK") private static HapClientNativeInterface sInstance; private static final Object INSTANCE_LOCK = new Object(); private HapClientNativeInterface() { public HapClientNativeInterface() { mAdapter = BluetoothAdapter.getDefaultAdapter(); if (mAdapter == null) { Log.wtf(TAG, "No Bluetooth Adapter Available"); } } /** * Get singleton instance. */ public static HapClientNativeInterface getInstance() { synchronized (INSTANCE_LOCK) { if (sInstance == null) { sInstance = new HapClientNativeInterface(); } return sInstance; } } /** Set singleton instance. */ @VisibleForTesting public static void setInstance(HapClientNativeInterface instance) { synchronized (INSTANCE_LOCK) { sInstance = instance; } } /** * Initiates HapClientService connection to a remote device. * Loading
android/app/src/com/android/bluetooth/hap/HapClientService.java +7 −6 Original line number Diff line number Diff line Loading @@ -119,8 +119,14 @@ public class HapClientService extends ProfileService { } public HapClientService(AdapterService adapterService) { this(adapterService, new HapClientNativeInterface()); } @VisibleForTesting HapClientService(AdapterService adapterService, HapClientNativeInterface nativeInterface) { super(adapterService); mAdapterService = Objects.requireNonNull(adapterService); mHapClientNativeInterface = Objects.requireNonNull(nativeInterface); } @Override Loading @@ -141,15 +147,11 @@ public class HapClientService extends ProfileService { throw new IllegalStateException("start() called twice"); } // Get HapClientNativeInterface, DatabaseManager, AudioManager. // None of them can be null. // Get DatabaseManager mDatabaseManager = Objects.requireNonNull( mAdapterService.getDatabase(), "DatabaseManager cannot be null when HapClientService starts"); mHapClientNativeInterface = Objects.requireNonNull( HapClientNativeInterface.getInstance(), "HapClientNativeInterface cannot be null when HapClientService starts"); // Start handler thread for state machines mHandler = new Handler(Looper.getMainLooper()); Loading Loading @@ -204,7 +206,6 @@ public class HapClientService extends ProfileService { // Cleanup GATT interface mHapClientNativeInterface.cleanup(); mHapClientNativeInterface = null; // Cleanup the internals mDeviceCurrentPresetMap.clear(); Loading
android/app/tests/unit/src/com/android/bluetooth/btservice/ProfileServiceTest.java +8 −18 Original line number Diff line number Diff line Loading @@ -35,7 +35,6 @@ import com.android.bluetooth.a2dp.A2dpNativeInterface; import com.android.bluetooth.avrcp.AvrcpNativeInterface; import com.android.bluetooth.btservice.storage.DatabaseManager; import com.android.bluetooth.csip.CsipSetCoordinatorNativeInterface; import com.android.bluetooth.hap.HapClientNativeInterface; import com.android.bluetooth.hearingaid.HearingAidNativeInterface; import com.android.bluetooth.hfp.HeadsetNativeInterface; import com.android.bluetooth.hid.HidDeviceNativeInterface; Loading @@ -57,6 +56,7 @@ import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; import java.lang.reflect.InvocationTargetException; import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.concurrent.FutureTask; Loading Loading @@ -85,7 +85,6 @@ public class ProfileServiceTest { @Mock private HidHostNativeInterface mHidHostNativeInterface; @Mock private PanNativeInterface mPanNativeInterface; @Mock private CsipSetCoordinatorNativeInterface mCsipSetCoordinatorInterface; @Mock private HapClientNativeInterface mHapClientInterface; @Mock private LeAudioNativeInterface mLeAudioInterface; @Mock private VolumeControlNativeInterface mVolumeControlInterface; Loading @@ -103,11 +102,6 @@ public class ProfileServiceTest { private void setAllProfilesState(int state, int invocationNumber) { int profileCount = mProfiles.length; for (int profile : mProfiles) { if (profile == BluetoothProfile.GATT) { // GattService is no longer a service to be start independently profileCount--; continue; } setProfileState(profile, state); } if (invocationNumber == 0) { Loading Loading @@ -145,7 +139,13 @@ public class ProfileServiceTest { doReturn(false).when(mAdapterService).isA2dpOffloadEnabled(); doReturn(false).when(mAdapterService).pbapPseDynamicVersionUpgradeIsEnabled(); mProfiles = Config.getSupportedProfiles(); mProfiles = Arrays.stream(Config.getSupportedProfiles()) .filter( profile -> profile != BluetoothProfile.HAP_CLIENT && profile != BluetoothProfile.GATT) .toArray(); TestUtils.setAdapterService(mAdapterService); Assert.assertNotNull(AdapterService.getAdapterService()); Loading @@ -158,7 +158,6 @@ public class ProfileServiceTest { HidHostNativeInterface.setInstance(mHidHostNativeInterface); PanNativeInterface.setInstance(mPanNativeInterface); CsipSetCoordinatorNativeInterface.setInstance(mCsipSetCoordinatorInterface); HapClientNativeInterface.setInstance(mHapClientInterface); LeAudioNativeInterface.setInstance(mLeAudioInterface); VolumeControlNativeInterface.setInstance(mVolumeControlInterface); } Loading @@ -177,7 +176,6 @@ public class ProfileServiceTest { HidHostNativeInterface.setInstance(null); PanNativeInterface.setInstance(null); CsipSetCoordinatorNativeInterface.setInstance(null); HapClientNativeInterface.setInstance(null); LeAudioNativeInterface.setInstance(null); VolumeControlNativeInterface.setInstance(null); } Loading Loading @@ -242,10 +240,6 @@ public class ProfileServiceTest { public void testRepeatedEnableDisableSingly() { int profileNumber = 0; for (int profile : mProfiles) { if (profile == BluetoothProfile.GATT) { // GattService is no longer a service to be start independently continue; } for (int i = 0; i < NUM_REPEATS; i++) { setProfileState(profile, BluetoothAdapter.STATE_ON); ArgumentCaptor<ProfileService> start = Loading @@ -272,10 +266,6 @@ public class ProfileServiceTest { public void testProfileServiceRegisterUnregister() { int profileNumber = 0; for (int profile : mProfiles) { if (profile == BluetoothProfile.GATT) { // GattService is no longer a service to be start independently continue; } for (int i = 0; i < NUM_REPEATS; i++) { setProfileState(profile, BluetoothAdapter.STATE_ON); ArgumentCaptor<ProfileService> start = Loading
android/app/tests/unit/src/com/android/bluetooth/hap/HapClientNativeInterfaceTest.java +1 −1 Original line number Diff line number Diff line Loading @@ -47,7 +47,7 @@ public class HapClientNativeInterfaceTest { public void setUp() throws Exception { when(mService.isAvailable()).thenReturn(true); HapClientService.setHapClient(mService); mNativeInterface = HapClientNativeInterface.getInstance(); mNativeInterface = new HapClientNativeInterface(); } @After Loading
android/app/tests/unit/src/com/android/bluetooth/hap/HapClientTest.java +1 −3 Original line number Diff line number Diff line Loading @@ -126,7 +126,6 @@ public class HapClientTest { mAdapter = BluetoothAdapter.getDefaultAdapter(); mAttributionSource = mAdapter.getAttributionSource(); HapClientNativeInterface.setInstance(mNativeInterface); startService(); mService.mFactory = mServiceFactory; doReturn(mCsipService).when(mServiceFactory).getCsipSetCoordinatorService(); Loading Loading @@ -200,13 +199,12 @@ public class HapClientTest { mService.mCallbacks.unregister(mCallback); stopService(); HapClientNativeInterface.setInstance(null); mAdapter = null; } private void startService() throws TimeoutException { mService = new HapClientService(mAdapterService); mService = new HapClientService(mAdapterService, mNativeInterface); mService.start(); mService.setAvailable(true); } Loading