Hide Dock speaker plays from sound pages
In order to ensure the setting only works on the analog docks, adding the docking state checks. Bug: 270492232 Test: manual test 1) Connect to digital dock 2) Check the sound page and the dock speaker plays shouldn't be displayed Change-Id: I1dc1e0aac8b9067ec8f5f1defc721294caf2949e
This commit is contained in:
@@ -19,14 +19,19 @@ package com.android.settings.notification;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Answers.RETURNS_DEEP_STUBS;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.provider.Settings.Global;
|
||||
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
@@ -72,6 +77,7 @@ public class DockAudioMediaPreferenceControllerTest {
|
||||
mController = new DockAudioMediaPreferenceController(mContext, mSetting, null);
|
||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
|
||||
doReturn(mScreen).when(mSetting).getPreferenceScreen();
|
||||
fakeDockState(Intent.EXTRA_DOCK_STATE_LE_DESK);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -90,6 +96,34 @@ public class DockAudioMediaPreferenceControllerTest {
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_undocked_shouldReturnFalse() {
|
||||
when(mContext.registerReceiver(nullable(BroadcastReceiver.class),
|
||||
any(IntentFilter.class))).thenReturn(null);
|
||||
when(mContext.getResources().getBoolean(com.android.settings.R.bool.has_dock_settings))
|
||||
.thenReturn(true);
|
||||
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_highEndDock_shouldReturnFalse() {
|
||||
fakeDockState(Intent.EXTRA_DOCK_STATE_HE_DESK);
|
||||
when(mContext.getResources().getBoolean(com.android.settings.R.bool.has_dock_settings))
|
||||
.thenReturn(true);
|
||||
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_lowEndDock_shouldReturnTrue() {
|
||||
fakeDockState(Intent.EXTRA_DOCK_STATE_LE_DESK);
|
||||
when(mContext.getResources().getBoolean(com.android.settings.R.bool.has_dock_settings))
|
||||
.thenReturn(true);
|
||||
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_dockAudioDisabled_shouldSelectFirstItem() {
|
||||
Global.putInt(mContentResolver, Global.DOCK_AUDIO_MEDIA_ENABLED, 0);
|
||||
@@ -127,4 +161,11 @@ public class DockAudioMediaPreferenceControllerTest {
|
||||
assertThat(Global.getInt(mContentResolver, Global.DOCK_AUDIO_MEDIA_ENABLED, 0))
|
||||
.isEqualTo(1);
|
||||
}
|
||||
|
||||
private void fakeDockState(int dockState) {
|
||||
Intent intent = new Intent(Intent.ACTION_DOCK_EVENT);
|
||||
intent.putExtra(Intent.EXTRA_DOCK_STATE, dockState);
|
||||
when(mContext.registerReceiver(nullable(BroadcastReceiver.class),
|
||||
any(IntentFilter.class))).thenReturn(intent);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user