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

Commit 4eda6542 authored by Sandeep Samdaria's avatar Sandeep Samdaria Committed by Automerger Merge Worker
Browse files

Merge "Fix flaky tests related to bluetooth browser media service." am:...

Merge "Fix flaky tests related to bluetooth browser media service." am: fd63f06b am: c604df94 am: cc555735 am: 710916b7

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Bluetooth/+/2516851



Change-Id: Ib29c8bbfe94457c3f9804a00c9f2292a2d8ce1eb
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 90520e23 710916b7
Loading
Loading
Loading
Loading
+15 −1
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
 */
package com.android.bluetooth;

import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;

import static org.mockito.ArgumentMatchers.eq;
@@ -29,11 +30,12 @@ import android.content.res.Resources;
import android.os.Handler;
import android.os.Looper;
import android.os.MessageQueue;
import android.os.Process;
import android.service.media.MediaBrowserService;

import androidx.test.InstrumentationRegistry;
import androidx.test.rule.ServiceTestRule;

import com.android.bluetooth.avrcpcontroller.BluetoothMediaBrowserService;
import com.android.bluetooth.btservice.AdapterService;
import com.android.bluetooth.btservice.ProfileService;

@@ -366,6 +368,18 @@ public class TestUtils {
        return adapterConfig;
    }

    /**
     * Prepare the intent to start bluetooth browser media service.
     *
     * @return intent with the appropriate component & action set.
     */
    public static Intent prepareIntentToStartBluetoothBrowserMediaService() {
        final Intent intent = new Intent(InstrumentationRegistry.getTargetContext(),
                BluetoothMediaBrowserService.class);
        intent.setAction(MediaBrowserService.SERVICE_INTERFACE);
        return intent;
    }

    /**
     * Helper class used to run synchronously a runnable action on a looper.
     */
+8 −3
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.*;

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.media.AudioManager;
@@ -39,7 +40,6 @@ import com.android.bluetooth.avrcpcontroller.BluetoothMediaBrowserService;
import com.android.bluetooth.btservice.AdapterService;

import org.junit.After;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -68,6 +68,9 @@ public class A2dpSinkStreamHandlerTest {
    @Rule
    public final ServiceTestRule mServiceRule = new ServiceTestRule();

    @Rule
    public final ServiceTestRule mBluetoothBrowserMediaServiceTestRule = new ServiceTestRule();

    @Mock
    private AdapterService mAdapterService;

@@ -82,6 +85,9 @@ public class A2dpSinkStreamHandlerTest {
        TestUtils.setAdapterService(mAdapterService);
        doReturn(true, false).when(mAdapterService).isStartedProfile(anyString());
        TestUtils.startService(mServiceRule, AvrcpControllerService.class);
        final Intent bluetoothBrowserMediaServiceStartIntent =
                TestUtils.prepareIntentToStartBluetoothBrowserMediaService();
        mBluetoothBrowserMediaServiceTestRule.startService(bluetoothBrowserMediaServiceStartIntent);

        mHandlerThread = new HandlerThread("A2dpSinkStreamHandlerTest");
        mHandlerThread.start();
@@ -101,7 +107,6 @@ public class A2dpSinkStreamHandlerTest {
        when(mMockPackageManager.hasSystemFeature(any())).thenReturn(false);

        mStreamHandler = spy(new A2dpSinkStreamHandler(mMockA2dpSink, mMockNativeInterface));
        BluetoothMediaBrowserService.setActive(false);
    }

    @After
+7 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import static org.mockito.Mockito.doReturn;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProfile;
import android.content.Intent;

import androidx.test.filters.SmallTest;
import androidx.test.rule.ServiceTestRule;
@@ -49,6 +50,9 @@ public class AvrcpBipClientTest {
    @Rule
    public final ServiceTestRule mServiceRule = new ServiceTestRule();

    @Rule
    public final ServiceTestRule mBluetoothBrowserMediaServiceTestRule = new ServiceTestRule();

    @Mock
    private AdapterService mAdapterService;

@@ -65,6 +69,9 @@ public class AvrcpBipClientTest {
        doReturn(true, false).when(mAdapterService).isStartedProfile(anyString());
        TestUtils.startService(mServiceRule, AvrcpControllerService.class);
        mService = AvrcpControllerService.getAvrcpControllerService();
        final Intent bluetoothBrowserMediaServiceStartIntent =
                TestUtils.prepareIntentToStartBluetoothBrowserMediaService();
        mBluetoothBrowserMediaServiceTestRule.startService(bluetoothBrowserMediaServiceStartIntent);

        mAdapter = BluetoothAdapter.getDefaultAdapter();
        mTestDevice = mAdapter.getRemoteDevice("00:01:02:03:04:05");
+7 −2
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import static org.mockito.Mockito.when;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProfile;
import android.content.Intent;
import android.media.AudioManager;
import android.support.v4.media.session.PlaybackStateCompat;

@@ -60,6 +61,8 @@ public class AvrcpControllerServiceTest {
    private BluetoothAdapter mAdapter = null;

    @Rule public final ServiceTestRule mServiceRule = new ServiceTestRule();
    @Rule
    public final ServiceTestRule mBluetoothBrowserMediaServiceTestRule = new ServiceTestRule();

    @Mock private AdapterService mAdapterService;
    @Mock private AvrcpControllerStateMachine mStateMachine;
@@ -79,7 +82,9 @@ public class AvrcpControllerServiceTest {
        assertThat(mAdapter).isNotNull();
        mRemoteDevice = mAdapter.getRemoteDevice(REMOTE_DEVICE_ADDRESS);
        mService.mDeviceStateMap.put(mRemoteDevice, mStateMachine);
        BluetoothMediaBrowserService.setActive(false);
        final Intent bluetoothBrowserMediaServiceStartIntent =
                TestUtils.prepareIntentToStartBluetoothBrowserMediaService();
        mBluetoothBrowserMediaServiceTestRule.startService(bluetoothBrowserMediaServiceStartIntent);
    }

    @After