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

- update test case

Bug: 132385707
Test: make -j42 RunSettingsRoboTests
Change-Id: Ibfd12e75f584b6884d1025018772ac9c19673156
This commit is contained in:
Tim Peng
2019-05-06 14:44:18 +08:00
committed by tim peng
parent 0abec2cc56
commit c007158819
3 changed files with 49 additions and 4 deletions

View File

@@ -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() {

View File

@@ -78,4 +78,9 @@ public class MediaOutputIndicatorWorker extends SliceBackgroundWorker implements
notifySliceChange();
}
}
@Override
public void onAudioModeChanged() {
notifySliceChange();
}
}

View File

@@ -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();
}
}