Merge "Hide Dock speaker plays from sound pages" into udc-dev am: df5bbc630d
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/21955162 Change-Id: Ib02077e90eb31f378ce1fe54d99ec408dea8e18b Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -19,6 +19,8 @@ package com.android.settings.notification;
|
||||
import static com.android.settings.notification.SettingPref.TYPE_GLOBAL;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.res.Resources;
|
||||
import android.provider.Settings.Global;
|
||||
|
||||
@@ -41,7 +43,7 @@ public class DockAudioMediaPreferenceController extends SettingPrefController {
|
||||
DEFAULT_DOCK_AUDIO_MEDIA, DOCK_AUDIO_MEDIA_DISABLED, DOCK_AUDIO_MEDIA_ENABLED) {
|
||||
@Override
|
||||
public boolean isApplicable(Context context) {
|
||||
return context.getResources().getBoolean(
|
||||
return isLeDesk() && context.getResources().getBoolean(
|
||||
com.android.settings.R.bool.has_dock_settings);
|
||||
}
|
||||
|
||||
@@ -60,4 +62,18 @@ public class DockAudioMediaPreferenceController extends SettingPrefController {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the state of docking type
|
||||
* @return true if it is low-end dock types
|
||||
*/
|
||||
private boolean isLeDesk() {
|
||||
IntentFilter intentFilter = new IntentFilter(Intent.ACTION_DOCK_EVENT);
|
||||
Intent dockStatus = mContext.registerReceiver(null, intentFilter);
|
||||
if (dockStatus == null) {
|
||||
return false;
|
||||
}
|
||||
int dockState = dockStatus.getIntExtra(Intent.EXTRA_DOCK_STATE, -1);
|
||||
return dockState == Intent.EXTRA_DOCK_STATE_LE_DESK;
|
||||
}
|
||||
}
|
||||
|
@@ -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