Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f52b5811 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge changes I77fed50b,Icb963b0c,Id1d683d8,I91d9ccc5 into main

* changes:
  Avoid binder calls in HidHostService
  HidHost: various cleanup
  HidHost: Use AdapterService provided
  Utils: add Adapter to getByteBrEdrAddress params
parents 0fe8974d d73ca454
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -250,14 +250,21 @@ public final class Utils {
        return identity != null ? identity : address;
    }

    /**
     * @see #getByteBrEdrAddress(AdapterService, BluetoothDevice)
     */
    public static byte[] getByteBrEdrAddress(BluetoothDevice device) {
        return getByteBrEdrAddress(AdapterService.getAdapterService(), device);
    }

    /**
     * Returns the correct device address to be used for connections over BR/EDR transport.
     *
     * @param service the provided AdapterService
     * @param device the device for which to obtain the connection address
     * @return either identity address or device address as a byte array
     */
    public static byte[] getByteBrEdrAddress(BluetoothDevice device) {
        final AdapterService service = AdapterService.getAdapterService();
    public static byte[] getByteBrEdrAddress(AdapterService service, BluetoothDevice device) {
        // If dual mode device bonded over BLE first, BR/EDR address will be identity address
        // Otherwise, BR/EDR address will be same address as in BluetoothDevice#getAddress
        byte[] address = service.getByteIdentityAddress(device);
+0 −1
Original line number Diff line number Diff line
@@ -5432,7 +5432,6 @@ public class AdapterService extends Service {
     * @param device the remote device that we want to get UUIDs from
     * @return the uuids of the remote device
     */
    @VisibleForTesting
    public ParcelUuid[] getRemoteUuids(BluetoothDevice device) {
        DeviceProperties deviceProp = mRemoteDevices.getDeviceProperties(device);
        if (deviceProp == null) {
+110 −159

File changed.

Preview size limit exceeded, changes collapsed.

+13 −15
Original line number Diff line number Diff line
@@ -20,9 +20,8 @@ import static org.mockito.Mockito.*;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProfile;
import android.content.Context;
import android.os.Looper;

import androidx.test.InstrumentationRegistry;
import androidx.test.filters.MediumTest;
import androidx.test.runner.AndroidJUnit4;

@@ -43,29 +42,29 @@ import org.mockito.junit.MockitoRule;
@MediumTest
@RunWith(AndroidJUnit4.class)
public class HidHostServiceTest {
    private HidHostService mService = null;
    private BluetoothAdapter mAdapter = null;
    private BluetoothDevice mTestDevice;
    private Context mTargetContext;

    @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();

    private final BluetoothAdapter mAdapter = BluetoothAdapter.getDefaultAdapter();

    private HidHostService mService;
    private BluetoothDevice mTestDevice;

    @Mock private AdapterService mAdapterService;
    @Mock private DatabaseManager mDatabaseManager;
    @Mock private HidHostNativeInterface mNativeInterface;

    @Before
    public void setUp() throws Exception {
        mTargetContext = InstrumentationRegistry.getTargetContext();
        TestUtils.setAdapterService(mAdapterService);
        when(mAdapterService.getDatabase()).thenReturn(mDatabaseManager);
        doReturn(mDatabaseManager).when(mAdapterService).getDatabase();
        HidHostNativeInterface.setInstance(mNativeInterface);
        mService = new HidHostService(mTargetContext);

        if (Looper.myLooper() == null) {
            Looper.prepare();
        }

        mService = new HidHostService(mAdapterService);
        mService.start();
        mService.setAvailable(true);
        // Try getting the Bluetooth adapter
        mAdapter = BluetoothAdapter.getDefaultAdapter();
        Assert.assertNotNull(mAdapter);

        // Get a device for testing
        mTestDevice = TestUtils.getTestDevice(mAdapter, 0);
@@ -78,7 +77,6 @@ public class HidHostServiceTest {
        HidHostNativeInterface.setInstance(null);
        mService = HidHostService.getHidHostService();
        Assert.assertNull(mService);
        TestUtils.clearAdapterService(mAdapterService);
    }

    @Test