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

Commit c0071588 authored by Tim Peng's avatar Tim Peng Committed by tim peng
Browse files

Hide audio switcher entry-point in the volume slice when in call

- update test case

Bug: 132385707
Test: make -j42 RunSettingsRoboTests
Change-Id: Ibfd12e75f584b6884d1025018772ac9c19673156
parent 0abec2cc
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.telephony.TelephonyManager;
import android.util.Log;

import androidx.core.graphics.drawable.IconCompat;
@@ -113,9 +114,14 @@ public class MediaOutputIndicatorSlice implements CustomSliceable {

    private boolean isVisible() {
        // To decide Slice's visibility.
        // return true if device is connected or previously connected, false for other cases.
        return !CollectionUtils.isEmpty(getConnectedA2dpDevices())
                || !CollectionUtils.isEmpty(getConnectedHearingAidDevices());
        // Return true if
        // 1. phone is not in ongoing call mode
        // 2. Bluetooth device is connected
        final TelephonyManager telephonyManager =
                (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
        return telephonyManager.getCallState() == TelephonyManager.CALL_STATE_IDLE
                && (!CollectionUtils.isEmpty(getConnectedA2dpDevices())
                || !CollectionUtils.isEmpty(getConnectedHearingAidDevices()));
    }

    private List<BluetoothDevice> getConnectedA2dpDevices() {
+5 −0
Original line number Diff line number Diff line
@@ -78,4 +78,9 @@ public class MediaOutputIndicatorWorker extends SliceBackgroundWorker implements
            notifySliceChange();
        }
    }

    @Override
    public void onAudioModeChanged() {
        notifySliceChange();
    }
}
+35 −1
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothManager;
import android.content.Context;
import android.telephony.TelephonyManager;

import androidx.slice.Slice;
import androidx.slice.SliceMetadata;
@@ -47,12 +48,15 @@ import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.shadow.api.Shadow;
import org.robolectric.shadows.ShadowTelephonyManager;

import java.util.ArrayList;
import java.util.List;

@RunWith(RobolectricTestRunner.class)
@Config(shadows = {ShadowBluetoothUtils.class})
@Config(shadows = {ShadowBluetoothUtils.class,
        ShadowTelephonyManager.class})
public class MediaOutputIndicatorSliceTest {

    private static final String TEST_A2DP_DEVICE_NAME = "Test_A2DP_BT_Device_NAME";
@@ -76,11 +80,14 @@ public class MediaOutputIndicatorSliceTest {
    private Context mContext;
    private List<BluetoothDevice> mDevicesList;
    private MediaOutputIndicatorSlice mMediaOutputIndicatorSlice;
    private ShadowTelephonyManager mShadowTelephonyManager;

    @Before
    public void setUp() throws Exception {
        MockitoAnnotations.initMocks(this);
        mContext = spy(RuntimeEnvironment.application);
        mShadowTelephonyManager = Shadow.extract(mContext.getSystemService(
                Context.TELEPHONY_SERVICE));
        // Set-up specs for SliceMetadata.
        SliceProvider.setSpecs(SliceLiveData.SUPPORTED_SPECS);

@@ -151,4 +158,31 @@ public class MediaOutputIndicatorSliceTest {
        assertThat(metadata.getTitle()).isEqualTo(mContext.getText(R.string.media_output_title));
        assertThat(metadata.getSubtitle()).isEqualTo(TEST_HAP_DEVICE_NAME);
    }

    @Test
    public void getSlice_callStateIdle_available() {
        mDevicesList.add(mA2dpDevice);
        when(mA2dpProfile.getConnectedDevices()).thenReturn(mDevicesList);
        mShadowTelephonyManager.setCallState(TelephonyManager.CALL_STATE_IDLE);

        assertThat(mMediaOutputIndicatorSlice.getSlice()).isNotNull();
    }

    @Test
    public void getSlice_callStateRinging_returnNull() {
        mDevicesList.add(mA2dpDevice);
        when(mA2dpProfile.getConnectedDevices()).thenReturn(mDevicesList);
        mShadowTelephonyManager.setCallState(TelephonyManager.CALL_STATE_RINGING);

        assertThat(mMediaOutputIndicatorSlice.getSlice()).isNull();
    }

    @Test
    public void getSlice_callStateOffHook_returnNull() {
        mDevicesList.add(mA2dpDevice);
        when(mA2dpProfile.getConnectedDevices()).thenReturn(mDevicesList);
        mShadowTelephonyManager.setCallState(TelephonyManager.CALL_STATE_OFFHOOK);

        assertThat(mMediaOutputIndicatorSlice.getSlice()).isNull();
    }
}