Loading android/app/src/com/android/bluetooth/gatt/GattObjectsFactory.java +16 −3 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.bluetooth.gatt; import android.os.Looper; import android.util.Log; import com.android.bluetooth.Utils; Loading Loading @@ -68,9 +69,21 @@ public class GattObjectsFactory { return ScanNativeInterface.getInstance(); } public ScanManager createScanManager(GattService service, AdapterService adapterService, BluetoothAdapterProxy bluetoothAdapterProxy) { return new ScanManager(service, adapterService, bluetoothAdapterProxy); /** * Create an instance of ScanManager * * @param service a GattService instance * @param adapterService an AdapterService instance * @param bluetoothAdapterProxy a bluetoothAdapterProxy instance * @param looper the looper to be used for processing messages * @return the created ScanManager instance */ public ScanManager createScanManager( GattService service, AdapterService adapterService, BluetoothAdapterProxy bluetoothAdapterProxy, Looper looper) { return new ScanManager(service, adapterService, bluetoothAdapterProxy, looper); } public PeriodicScanManager createPeriodicScanManager(AdapterService adapterService) { Loading android/app/src/com/android/bluetooth/gatt/GattService.java +7 −2 Original line number Diff line number Diff line Loading @@ -69,6 +69,7 @@ import android.net.MacAddress; import android.os.Binder; import android.os.Build; import android.os.Handler; import android.os.HandlerThread; import android.os.IBinder; import android.os.Message; import android.os.ParcelUuid; Loading Loading @@ -359,8 +360,12 @@ public class GattService extends ProfileService { mAdapterService, mAdvertiserMap); mScanManager = GattObjectsFactory.getInstance() .createScanManager(this, mAdapterService, mBluetoothAdapterProxy); HandlerThread thread = new HandlerThread("BluetoothScanManager"); thread.start(); mScanManager = GattObjectsFactory.getInstance() .createScanManager( this, mAdapterService, mBluetoothAdapterProxy, thread.getLooper()); mPeriodicScanManager = GattObjectsFactory.getInstance() .createPeriodicScanManager(mAdapterService); Loading android/app/src/com/android/bluetooth/gatt/ScanManager.java +3 −5 Original line number Diff line number Diff line Loading @@ -32,7 +32,6 @@ import android.content.IntentFilter; import android.hardware.display.DisplayManager; import android.location.LocationManager; import android.os.Handler; import android.os.HandlerThread; import android.os.Looper; import android.os.Message; import android.os.RemoteException; Loading Loading @@ -160,7 +159,8 @@ public class ScanManager { ScanManager( GattService service, AdapterService adapterService, BluetoothAdapterProxy bluetoothAdapterProxy) { BluetoothAdapterProxy bluetoothAdapterProxy, Looper looper) { mRegularScanClients = Collections.newSetFromMap(new ConcurrentHashMap<ScanClient, Boolean>()); mBatchClients = Collections.newSetFromMap(new ConcurrentHashMap<ScanClient, Boolean>()); Loading @@ -184,9 +184,7 @@ public class ScanManager { mPriorityMap.put(ScanSettings.SCAN_MODE_AMBIENT_DISCOVERY, 4); mPriorityMap.put(ScanSettings.SCAN_MODE_LOW_LATENCY, 5); HandlerThread thread = new HandlerThread("BluetoothScanManager"); thread.start(); mHandler = new ClientHandler(thread.getLooper()); mHandler = new ClientHandler(looper); if (mDm != null) { mDm.registerDisplayListener(mDisplayListener, null); } Loading android/app/tests/unit/src/com/android/bluetooth/gatt/GattServiceTest.java +1 −1 Original line number Diff line number Diff line Loading @@ -119,7 +119,7 @@ public class GattServiceTest { GattObjectsFactory.setInstanceForTesting(mFactory); doReturn(mNativeInterface).when(mFactory).getNativeInterface(); doReturn(mScanManager).when(mFactory).createScanManager(any(), any(), any()); doReturn(mScanManager).when(mFactory).createScanManager(any(), any(), any(), any()); doReturn(mPeriodicScanManager).when(mFactory).createPeriodicScanManager(any()); doReturn(mDistanceMeasurementManager).when(mFactory) .createDistanceMeasurementManager(any()); Loading android/app/tests/unit/src/com/android/bluetooth/gatt/ScanManagerTest.java +14 −4 Original line number Diff line number Diff line Loading @@ -52,6 +52,7 @@ import android.os.Binder; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.os.test.TestLooper; import android.provider.Settings; import android.test.mock.MockContentProvider; import android.test.mock.MockContentResolver; Loading Loading @@ -106,6 +107,7 @@ public class ScanManagerTest { private Context mTargetContext; private ScanManager mScanManager; private Handler mHandler; private TestLooper mTestLooper; private CountDownLatch mLatch; private long mScanReportDelay; Loading Loading @@ -181,7 +183,14 @@ public class ScanManagerTest { doReturn(mTargetContext.getUser()).when(mMockGattService).getUser(); doReturn(mTargetContext.getPackageName()).when(mMockGattService).getPackageName(); mScanManager = new ScanManager(mMockGattService, mAdapterService, mBluetoothAdapterProxy); mTestLooper = new TestLooper(); mTestLooper.startAutoDispatch(); mScanManager = new ScanManager( mMockGattService, mAdapterService, mBluetoothAdapterProxy, mTestLooper.getLooper()); mHandler = mScanManager.getClientHandler(); assertThat(mHandler).isNotNull(); Loading @@ -194,6 +203,7 @@ public class ScanManagerTest { @After public void tearDown() throws Exception { mTestLooper.stopAutoDispatchAndIgnoreExceptions(); TestUtils.clearAdapterService(mAdapterService); BluetoothAdapterProxy.setInstanceForTesting(null); GattObjectsFactory.setInstanceForTesting(null); Loading @@ -216,7 +226,7 @@ public class ScanManagerTest { } mHandler.sendMessage(msg); // Wait for async work from handler thread TestUtils.waitForLooperToBeIdle(mHandler.getLooper()); TestUtils.waitForLooperToFinishScheduledTask(mHandler.getLooper()); } private ScanClient createScanClient( Loading Loading @@ -1394,7 +1404,7 @@ public class ScanManagerTest { BluetoothProfile.STATE_CONNECTING); // Wait for handleConnectingState to happen TestUtils.waitForLooperToBeIdle(mHandler.getLooper()); TestUtils.waitForLooperToFinishScheduledTask(mHandler.getLooper()); assertThat(mScanManager.mIsConnecting).isTrue(); } Loading Loading @@ -1430,7 +1440,7 @@ public class ScanManagerTest { t1.join(); t2.join(); TestUtils.waitForLooperToBeIdle(mHandler.getLooper()); TestUtils.waitForLooperToFinishScheduledTask(mHandler.getLooper()); assertThat(mScanManager.mProfilesConnecting).isEqualTo(3); } } Loading
android/app/src/com/android/bluetooth/gatt/GattObjectsFactory.java +16 −3 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.bluetooth.gatt; import android.os.Looper; import android.util.Log; import com.android.bluetooth.Utils; Loading Loading @@ -68,9 +69,21 @@ public class GattObjectsFactory { return ScanNativeInterface.getInstance(); } public ScanManager createScanManager(GattService service, AdapterService adapterService, BluetoothAdapterProxy bluetoothAdapterProxy) { return new ScanManager(service, adapterService, bluetoothAdapterProxy); /** * Create an instance of ScanManager * * @param service a GattService instance * @param adapterService an AdapterService instance * @param bluetoothAdapterProxy a bluetoothAdapterProxy instance * @param looper the looper to be used for processing messages * @return the created ScanManager instance */ public ScanManager createScanManager( GattService service, AdapterService adapterService, BluetoothAdapterProxy bluetoothAdapterProxy, Looper looper) { return new ScanManager(service, adapterService, bluetoothAdapterProxy, looper); } public PeriodicScanManager createPeriodicScanManager(AdapterService adapterService) { Loading
android/app/src/com/android/bluetooth/gatt/GattService.java +7 −2 Original line number Diff line number Diff line Loading @@ -69,6 +69,7 @@ import android.net.MacAddress; import android.os.Binder; import android.os.Build; import android.os.Handler; import android.os.HandlerThread; import android.os.IBinder; import android.os.Message; import android.os.ParcelUuid; Loading Loading @@ -359,8 +360,12 @@ public class GattService extends ProfileService { mAdapterService, mAdvertiserMap); mScanManager = GattObjectsFactory.getInstance() .createScanManager(this, mAdapterService, mBluetoothAdapterProxy); HandlerThread thread = new HandlerThread("BluetoothScanManager"); thread.start(); mScanManager = GattObjectsFactory.getInstance() .createScanManager( this, mAdapterService, mBluetoothAdapterProxy, thread.getLooper()); mPeriodicScanManager = GattObjectsFactory.getInstance() .createPeriodicScanManager(mAdapterService); Loading
android/app/src/com/android/bluetooth/gatt/ScanManager.java +3 −5 Original line number Diff line number Diff line Loading @@ -32,7 +32,6 @@ import android.content.IntentFilter; import android.hardware.display.DisplayManager; import android.location.LocationManager; import android.os.Handler; import android.os.HandlerThread; import android.os.Looper; import android.os.Message; import android.os.RemoteException; Loading Loading @@ -160,7 +159,8 @@ public class ScanManager { ScanManager( GattService service, AdapterService adapterService, BluetoothAdapterProxy bluetoothAdapterProxy) { BluetoothAdapterProxy bluetoothAdapterProxy, Looper looper) { mRegularScanClients = Collections.newSetFromMap(new ConcurrentHashMap<ScanClient, Boolean>()); mBatchClients = Collections.newSetFromMap(new ConcurrentHashMap<ScanClient, Boolean>()); Loading @@ -184,9 +184,7 @@ public class ScanManager { mPriorityMap.put(ScanSettings.SCAN_MODE_AMBIENT_DISCOVERY, 4); mPriorityMap.put(ScanSettings.SCAN_MODE_LOW_LATENCY, 5); HandlerThread thread = new HandlerThread("BluetoothScanManager"); thread.start(); mHandler = new ClientHandler(thread.getLooper()); mHandler = new ClientHandler(looper); if (mDm != null) { mDm.registerDisplayListener(mDisplayListener, null); } Loading
android/app/tests/unit/src/com/android/bluetooth/gatt/GattServiceTest.java +1 −1 Original line number Diff line number Diff line Loading @@ -119,7 +119,7 @@ public class GattServiceTest { GattObjectsFactory.setInstanceForTesting(mFactory); doReturn(mNativeInterface).when(mFactory).getNativeInterface(); doReturn(mScanManager).when(mFactory).createScanManager(any(), any(), any()); doReturn(mScanManager).when(mFactory).createScanManager(any(), any(), any(), any()); doReturn(mPeriodicScanManager).when(mFactory).createPeriodicScanManager(any()); doReturn(mDistanceMeasurementManager).when(mFactory) .createDistanceMeasurementManager(any()); Loading
android/app/tests/unit/src/com/android/bluetooth/gatt/ScanManagerTest.java +14 −4 Original line number Diff line number Diff line Loading @@ -52,6 +52,7 @@ import android.os.Binder; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.os.test.TestLooper; import android.provider.Settings; import android.test.mock.MockContentProvider; import android.test.mock.MockContentResolver; Loading Loading @@ -106,6 +107,7 @@ public class ScanManagerTest { private Context mTargetContext; private ScanManager mScanManager; private Handler mHandler; private TestLooper mTestLooper; private CountDownLatch mLatch; private long mScanReportDelay; Loading Loading @@ -181,7 +183,14 @@ public class ScanManagerTest { doReturn(mTargetContext.getUser()).when(mMockGattService).getUser(); doReturn(mTargetContext.getPackageName()).when(mMockGattService).getPackageName(); mScanManager = new ScanManager(mMockGattService, mAdapterService, mBluetoothAdapterProxy); mTestLooper = new TestLooper(); mTestLooper.startAutoDispatch(); mScanManager = new ScanManager( mMockGattService, mAdapterService, mBluetoothAdapterProxy, mTestLooper.getLooper()); mHandler = mScanManager.getClientHandler(); assertThat(mHandler).isNotNull(); Loading @@ -194,6 +203,7 @@ public class ScanManagerTest { @After public void tearDown() throws Exception { mTestLooper.stopAutoDispatchAndIgnoreExceptions(); TestUtils.clearAdapterService(mAdapterService); BluetoothAdapterProxy.setInstanceForTesting(null); GattObjectsFactory.setInstanceForTesting(null); Loading @@ -216,7 +226,7 @@ public class ScanManagerTest { } mHandler.sendMessage(msg); // Wait for async work from handler thread TestUtils.waitForLooperToBeIdle(mHandler.getLooper()); TestUtils.waitForLooperToFinishScheduledTask(mHandler.getLooper()); } private ScanClient createScanClient( Loading Loading @@ -1394,7 +1404,7 @@ public class ScanManagerTest { BluetoothProfile.STATE_CONNECTING); // Wait for handleConnectingState to happen TestUtils.waitForLooperToBeIdle(mHandler.getLooper()); TestUtils.waitForLooperToFinishScheduledTask(mHandler.getLooper()); assertThat(mScanManager.mIsConnecting).isTrue(); } Loading Loading @@ -1430,7 +1440,7 @@ public class ScanManagerTest { t1.join(); t2.join(); TestUtils.waitForLooperToBeIdle(mHandler.getLooper()); TestUtils.waitForLooperToFinishScheduledTask(mHandler.getLooper()); assertThat(mScanManager.mProfilesConnecting).isEqualTo(3); } }