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

Commit b6095917 authored by William Escande's avatar William Escande Committed by Gerrit Code Review
Browse files

Merge changes from topic "bluetooth_local_getidentity_instead_of_re-entrant_call" into main

* changes:
  Prefer local getIdentityAddress call vs Framework
  Setup Looper for OppServiceTest
parents 87d62783 c5e51afc
Loading
Loading
Loading
Loading
+4 −5
Original line number Diff line number Diff line
@@ -236,11 +236,10 @@ public final class Utils {
     * @return either identity address or device address in String format
     */
    public static String getBrEdrAddress(BluetoothDevice device) {
        String address = device.getIdentityAddress();
        if (address == null) {
            address = device.getAddress();
        }
        return address;
        final AdapterService service = AdapterService.getAdapterService();
        final String address = device.getAddress();
        String identity = service != null ? service.getIdentityAddress(address) : null;
        return identity != null ? identity : address;
    }

    /**
+4 −4
Original line number Diff line number Diff line
@@ -4816,17 +4816,17 @@ public class AdapterService extends Service {
    }

    int getConnectionState(BluetoothDevice device) {
        final String address = device.getAddress();
        if (Flags.apiGetConnectionStateUsingIdentityAddress()) {
            int connectionState =
                    mNativeInterface.getConnectionState(getBytesFromAddress(device.getAddress()));
            final String identityAddress = device.getIdentityAddress();
            int connectionState = mNativeInterface.getConnectionState(getBytesFromAddress(address));
            final String identityAddress = getIdentityAddress(address);
            if (identityAddress != null) {
                connectionState |=
                        mNativeInterface.getConnectionState(getBytesFromAddress(identityAddress));
            }
            return connectionState;
        }
        return mNativeInterface.getConnectionState(getBytesFromAddress(device.getAddress()));
        return mNativeInterface.getConnectionState(getBytesFromAddress(address));
    }

    int getConnectionHandle(BluetoothDevice device, int transport) {
+39 −16
Original line number Diff line number Diff line
@@ -29,10 +29,10 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.timeout;
import static org.mockito.Mockito.verify;

import android.bluetooth.BluetoothAdapter;
import android.content.ContentResolver;
import android.content.Context;
import android.database.MatrixCursor;
import android.os.Looper;

import androidx.test.filters.MediumTest;
import androidx.test.platform.app.InstrumentationRegistry;
@@ -57,7 +57,6 @@ import org.mockito.junit.MockitoRule;
@RunWith(AndroidJUnit4.class)
public class BluetoothOppServiceTest {
    private BluetoothOppService mService = null;
    private BluetoothAdapter mAdapter = null;
    private boolean mIsAdapterServiceSet;
    private boolean mIsBluetoothOppServiceStarted;

@@ -69,6 +68,9 @@ public class BluetoothOppServiceTest {

    @Before
    public void setUp() throws Exception {
        if (Looper.myLooper() == null) {
            Looper.prepare();
        }
        Context targetContext = InstrumentationRegistry.getInstrumentation().getTargetContext();

        BluetoothMethodProxy.setInstanceForTesting(mBluetoothMethodProxy);
@@ -86,10 +88,6 @@ public class BluetoothOppServiceTest {
        mService.setAvailable(true);
        mIsBluetoothOppServiceStarted = true;

        // Try getting the Bluetooth adapter
        mAdapter = BluetoothAdapter.getDefaultAdapter();
        Assert.assertNotNull(mAdapter);

        // Wait until the initial trimDatabase operation is done.
        verify(mBluetoothMethodProxy, timeout(3_000))
                .contentResolverQuery(
@@ -132,12 +130,38 @@ public class BluetoothOppServiceTest {
        int infoTimestamp = 123456789;
        int infoTimestamp2 = 123489;

        BluetoothOppShareInfo shareInfo = mock(BluetoothOppShareInfo.class);
        shareInfo.mTimestamp = infoTimestamp;
        shareInfo.mDestination = "AA:BB:CC:DD:EE:FF";
        BluetoothOppShareInfo shareInfo2 = mock(BluetoothOppShareInfo.class);
        shareInfo2.mTimestamp = infoTimestamp2;
        shareInfo2.mDestination = "00:11:22:33:44:55";
        BluetoothOppShareInfo shareInfo =
                new BluetoothOppShareInfo(
                        1, // id
                        null, // Uri,
                        "hint",
                        "filename",
                        "mimetype",
                        0, // direction
                        "AA:BB:CC:DD:EE:FF", // destination
                        0, // visibility,
                        0, // confirm
                        0, // status
                        0, // totalBytes
                        0, // currentBytes
                        infoTimestamp,
                        false); // mediaScanned
        BluetoothOppShareInfo shareInfo2 =
                new BluetoothOppShareInfo(
                        1, // id
                        null, // Uri,
                        "hint",
                        "filename",
                        "mimetype",
                        0, // direction
                        "00:11:22:33:44:55", // destination
                        0, // visibility,
                        0, // confirm
                        0, // status
                        0, // totalBytes
                        0, // currentBytes
                        infoTimestamp2,
                        false); // mediaScanned

        mService.mShares.clear();
        mService.mShares.add(shareInfo);
@@ -152,10 +176,9 @@ public class BluetoothOppServiceTest {
        mService.mBatches.add(batch2);

        mService.deleteShare(0);
        assertThat(mService.mShares.size()).isEqualTo(1);
        assertThat(mService.mBatches.size()).isEqualTo(1);
        assertThat(mService.mShares.get(0)).isEqualTo(shareInfo2);
        assertThat(mService.mBatches.get(0)).isEqualTo(batch2);

        assertThat(mService.mShares).containsExactly(shareInfo2);
        assertThat(mService.mBatches).containsExactly(batch2);
    }

    @Test