Add ability to show/hide individual settings in Sounds page.

This adds the following 7 new boolean flags:
config_show_alarm_volume
config_show_charging_sounds
config_show_media_volume
config_show_notification_ringtone
config_show_notification_volume
config_show_screen_locking_sounds
config_show_touch_sounds

Which when set to false, will hide the respective preferences in Sounds
page.

Bug: 69813881
Test: make RunSettingsRoboTests
ROBOTEST_FILTER=com.android.settings.notification all pass.

Change-Id: I84a2ce66b07c00d658422ce1a0eacaf9a01fae8a
This commit is contained in:
Ben Lin
2018-01-05 12:30:09 -08:00
parent 533dfdfbfd
commit 921e3d14b8
17 changed files with 180 additions and 30 deletions

View File

@@ -60,6 +60,27 @@
<!-- Whether high_power_apps should be shown or not. -->
<bool name="config_show_high_power_apps">true</bool>
<!-- Whether media_volume should be shown or not. -->
<bool name="config_show_media_volume">true</bool>
<!-- Whether alarm_volume should be shown or not. -->
<bool name="config_show_alarm_volume">true</bool>
<!-- Whether notification_volume should be shown or not. -->
<bool name="config_show_notification_volume">true</bool>
<!-- Whether notification_ringtone should be shown or not. -->
<bool name="config_show_notification_ringtone">true</bool>
<!-- Whether screen_locking_sounds should be shown or not. -->
<bool name="config_show_screen_locking_sounds">true</bool>
<!-- Whether charging_sounds should be shown or not. -->
<bool name="config_show_charging_sounds">true</bool>
<!-- Whether touch_sounds should be shown or not. -->
<bool name="config_show_touch_sounds">true</bool>
<!-- Whether device_administrators should be shown or not. -->
<bool name="config_show_device_administrators">true</bool>

View File

@@ -21,6 +21,7 @@ import android.media.AudioManager;
import com.android.internal.annotations.VisibleForTesting;
import com.android.settings.notification.VolumeSeekBarPreference.Callback;
import com.android.settings.R;
import com.android.settingslib.core.lifecycle.Lifecycle;
public class AlarmVolumePreferenceController extends
@@ -43,7 +44,8 @@ public class AlarmVolumePreferenceController extends
@Override
public boolean isAvailable() {
return !mHelper.isSingleVolume();
return mContext.getResources().getBoolean(R.bool.config_show_alarm_volume)
&& !mHelper.isSingleVolume();
}
@Override

View File

@@ -21,6 +21,7 @@ import static com.android.settings.notification.SettingPref.TYPE_GLOBAL;
import android.content.Context;
import android.provider.Settings.Global;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settingslib.core.lifecycle.Lifecycle;
@@ -33,7 +34,10 @@ public class ChargingSoundPreferenceController extends SettingPrefController {
super(context, parent, lifecycle);
mPreference = new SettingPref(
TYPE_GLOBAL, KEY_CHARGING_SOUNDS, Global.CHARGING_SOUNDS_ENABLED, DEFAULT_ON);
}
@Override
public boolean isAvailable() {
return mContext.getResources().getBoolean(R.bool.config_show_charging_sounds);
}
}

View File

@@ -19,6 +19,7 @@ package com.android.settings.notification;
import android.content.Context;
import android.media.AudioManager;
import com.android.settings.notification.VolumeSeekBarPreference.Callback;
import com.android.settings.R;
import com.android.settingslib.core.lifecycle.Lifecycle;
public class MediaVolumePreferenceController extends
@@ -32,7 +33,7 @@ public class MediaVolumePreferenceController extends
@Override
public boolean isAvailable() {
return true;
return mContext.getResources().getBoolean(R.bool.config_show_media_volume);
}
@Override

View File

@@ -19,6 +19,8 @@ package com.android.settings.notification;
import android.content.Context;
import android.media.RingtoneManager;
import com.android.settings.R;
public class NotificationRingtonePreferenceController extends RingtonePreferenceControllerBase {
private static final String KEY_NOTIFICATION_RINGTONE = "notification_ringtone";
@@ -27,6 +29,11 @@ public class NotificationRingtonePreferenceController extends RingtonePreference
super(context);
}
@Override
public boolean isAvailable() {
return mContext.getResources().getBoolean(R.bool.config_show_notification_ringtone);
}
@Override
public String getPreferenceKey() {
return KEY_NOTIFICATION_RINGTONE;

View File

@@ -20,6 +20,7 @@ import android.content.Context;
import android.media.AudioManager;
import com.android.internal.annotations.VisibleForTesting;
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.notification.VolumeSeekBarPreference.Callback;
import com.android.settingslib.core.lifecycle.Lifecycle;
@@ -45,7 +46,8 @@ public class NotificationVolumePreferenceController extends
@Override
public boolean isAvailable() {
return !Utils.isVoiceCapable(mContext) && !mHelper.isSingleVolume();
return mContext.getResources().getBoolean(R.bool.config_show_notification_volume)
&& !Utils.isVoiceCapable(mContext) && !mHelper.isSingleVolume();
}
@Override

View File

@@ -21,6 +21,7 @@ import static com.android.settings.notification.SettingPref.TYPE_SYSTEM;
import android.content.Context;
import android.provider.Settings.System;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settingslib.core.lifecycle.Lifecycle;
@@ -35,4 +36,8 @@ public class ScreenLockSoundPreferenceController extends SettingPrefController {
TYPE_SYSTEM, KEY_SCREEN_LOCKING_SOUNDS, System.LOCKSCREEN_SOUNDS_ENABLED, DEFAULT_ON);
}
@Override
public boolean isAvailable() {
return mContext.getResources().getBoolean(R.bool.config_show_screen_locking_sounds);
}
}

View File

@@ -33,6 +33,7 @@ import com.android.settings.R;
import com.android.settings.RingtonePreference;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.widget.PreferenceCategoryController;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.lifecycle.Lifecycle;
@@ -201,15 +202,45 @@ public class SoundSettings extends DashboardFragment {
controllers.add(new WorkSoundPreferenceController(context, fragment, lifecycle));
// === Other Sound Settings ===
controllers.add(new DialPadTonePreferenceController(context, fragment, lifecycle));
controllers.add(new ScreenLockSoundPreferenceController(context, fragment, lifecycle));
controllers.add(new ChargingSoundPreferenceController(context, fragment, lifecycle));
controllers.add(new DockingSoundPreferenceController(context, fragment, lifecycle));
controllers.add(new TouchSoundPreferenceController(context, fragment, lifecycle));
controllers.add(new VibrateOnTouchPreferenceController(context, fragment, lifecycle));
controllers.add(new DockAudioMediaPreferenceController(context, fragment, lifecycle));
controllers.add(new BootSoundPreferenceController(context));
controllers.add(new EmergencyTonePreferenceController(context, fragment, lifecycle));
final DialPadTonePreferenceController dialPadTonePreferenceController =
new DialPadTonePreferenceController(context, fragment, lifecycle);
final ScreenLockSoundPreferenceController screenLockSoundPreferenceController =
new ScreenLockSoundPreferenceController(context, fragment, lifecycle);
final ChargingSoundPreferenceController chargingSoundPreferenceController =
new ChargingSoundPreferenceController(context, fragment, lifecycle);
final DockingSoundPreferenceController dockingSoundPreferenceController =
new DockingSoundPreferenceController(context, fragment, lifecycle);
final TouchSoundPreferenceController touchSoundPreferenceController =
new TouchSoundPreferenceController(context, fragment, lifecycle);
final VibrateOnTouchPreferenceController vibrateOnTouchPreferenceController =
new VibrateOnTouchPreferenceController(context, fragment, lifecycle);
final DockAudioMediaPreferenceController dockAudioMediaPreferenceController =
new DockAudioMediaPreferenceController(context, fragment, lifecycle);
final BootSoundPreferenceController bootSoundPreferenceController =
new BootSoundPreferenceController(context);
final EmergencyTonePreferenceController emergencyTonePreferenceController =
new EmergencyTonePreferenceController(context, fragment, lifecycle);
controllers.add(dialPadTonePreferenceController);
controllers.add(screenLockSoundPreferenceController);
controllers.add(chargingSoundPreferenceController);
controllers.add(dockingSoundPreferenceController);
controllers.add(touchSoundPreferenceController);
controllers.add(vibrateOnTouchPreferenceController);
controllers.add(dockAudioMediaPreferenceController);
controllers.add(bootSoundPreferenceController);
controllers.add(emergencyTonePreferenceController);
controllers.add(new PreferenceCategoryController(context,
"other_sounds_and_vibrations_category",
Arrays.asList(dialPadTonePreferenceController,
screenLockSoundPreferenceController,
chargingSoundPreferenceController,
dockingSoundPreferenceController,
touchSoundPreferenceController,
vibrateOnTouchPreferenceController,
dockAudioMediaPreferenceController,
bootSoundPreferenceController,
emergencyTonePreferenceController)));
return controllers;
}

View File

@@ -23,6 +23,7 @@ import android.content.Context;
import android.media.AudioManager;
import android.os.AsyncTask;
import android.provider.Settings.System;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settingslib.core.lifecycle.Lifecycle;
@@ -53,4 +54,9 @@ public class TouchSoundPreferenceController extends SettingPrefController {
}
};
}
@Override
public boolean isAvailable() {
return mContext.getResources().getBoolean(R.bool.config_show_touch_sounds);
}
}

View File

@@ -22,6 +22,13 @@
<bool name="config_display_recent_apps">false</bool>
<bool name="config_show_wifi_settings">false</bool>
<bool name="config_show_high_power_apps">false</bool>
<bool name="config_show_alarm_volume">false</bool>
<bool name="config_show_charging_sounds">false</bool>
<bool name="config_show_media_volume">false</bool>
<bool name="config_show_notification_ringtone">false</bool>
<bool name="config_show_notification_volume">false</bool>
<bool name="config_show_screen_locking_sounds">false</bool>
<bool name="config_show_touch_sounds">false</bool>
<bool name="config_show_device_administrators">false</bool>
<bool name="config_show_premium_sms">false</bool>
<bool name="config_show_data_saver">false</bool>

View File

@@ -27,28 +27,37 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class AlarmVolumePreferenceControllerTest {
@Mock
private Context mContext;
@Mock
private AudioHelper mHelper;
private Context mContext;
private AlarmVolumePreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
mController = new AlarmVolumePreferenceController(mContext, null, null, mHelper);
}
@Test
@Config(qualifiers = "mcc999")
public void isAvailable_whenNotVisible_isFalse() {
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void isAvailable_singleVolume_shouldReturnFalse() {
when(mHelper.isSingleVolume()).thenReturn(true);

View File

@@ -31,11 +31,13 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
@@ -50,15 +52,15 @@ public class ChargingSoundPreferenceControllerTest {
private ContentResolver mContentResolver;
@Mock
private SoundSettings mSetting;
@Mock
private Context mContext;
private Context mContext;
private ChargingSoundPreferenceController mController;
private SwitchPreference mPreference;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
when(mSetting.getActivity()).thenReturn(mActivity);
when(mActivity.getContentResolver()).thenReturn(mContentResolver);
mPreference = new SwitchPreference(ShadowApplication.getInstance().getApplicationContext());
@@ -68,10 +70,16 @@ public class ChargingSoundPreferenceControllerTest {
}
@Test
public void isAvailable_isAlwaysTrue() {
public void isAvailable_byDefault_isTrue() {
assertThat(mController.isAvailable()).isTrue();
}
@Test
@Config(qualifiers = "mcc999")
public void isAvailable_whenNotVisible_isFalse() {
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void displayPreference_chargingSoundEnabled_shouldCheckedPreference() {
Global.putInt(mContentResolver, Global.CHARGING_SOUNDS_ENABLED, 1);

View File

@@ -27,30 +27,38 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.spy;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class MediaVolumePreferenceControllerTest {
@Mock
private Context mContext;
private MediaVolumePreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
mController = new MediaVolumePreferenceController(mContext, null, null);
}
@Test
public void isAlwaysAvailable() {
public void isAvailable_byDefault_isTrue() {
assertThat(mController.isAvailable()).isTrue();
}
@Test
@Config(qualifiers = "mcc999")
public void isAvailable_whenNotVisible_isFalse() {
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void getAudioStream_shouldReturnMusic() {
assertThat(mController.getAudioStream()).isEqualTo(AudioManager.STREAM_MUSIC);

View File

@@ -27,24 +27,38 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.spy;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class NotificationRingtonePreferenceControllerTest {
@Mock
private Context mContext;
private NotificationRingtonePreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
mController = new NotificationRingtonePreferenceController(mContext);
}
@Test
public void isAvailable_byDefault_isTrue() {
assertThat(mController.isAvailable()).isTrue();
}
@Test
@Config(qualifiers = "mcc999")
public void isAvailable_whenNotVisible_isFalse() {
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void getRingtoneType_shouldReturnNotification() {
assertThat(mController.getRingtoneType()).isEqualTo(RingtoneManager.TYPE_NOTIFICATION);

View File

@@ -29,17 +29,18 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class NotificationVolumePreferenceControllerTest {
@Mock
private Context mContext;
@Mock
private AudioHelper mHelper;
@Mock
@@ -49,17 +50,25 @@ public class NotificationVolumePreferenceControllerTest {
@Mock
private Vibrator mVibrator;
private Context mContext;
private NotificationVolumePreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
when(mContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager);
when(mContext.getSystemService(Context.AUDIO_SERVICE)).thenReturn(mAudioManager);
when(mContext.getSystemService(Context.VIBRATOR_SERVICE)).thenReturn(mVibrator);
mController = new NotificationVolumePreferenceController(mContext, null, null, mHelper);
}
@Test
@Config(qualifiers = "mcc999")
public void isAvailable_whenNotVisible_shouldReturnFalse() {
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void isAvailable_singleVolume_shouldReturnFalse() {
when(mHelper.isSingleVolume()).thenReturn(true);

View File

@@ -31,11 +31,13 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
@@ -50,15 +52,15 @@ public class ScreenLockSoundPreferenceControllerTest {
private ContentResolver mContentResolver;
@Mock
private SoundSettings mSetting;
@Mock
private Context mContext;
private Context mContext;
private ScreenLockSoundPreferenceController mController;
private SwitchPreference mPreference;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
when(mSetting.getActivity()).thenReturn(mActivity);
when(mActivity.getContentResolver()).thenReturn(mContentResolver);
mPreference = new SwitchPreference(ShadowApplication.getInstance().getApplicationContext());
@@ -68,10 +70,16 @@ public class ScreenLockSoundPreferenceControllerTest {
}
@Test
public void isAvailable_isAlwaysTrue() {
public void isAvailable_byDefault_isTrue() {
assertThat(mController.isAvailable()).isTrue();
}
@Test
@Config(qualifiers = "mcc999")
public void isAvailable_whenNotVisible_isFalse() {
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void displayPreference_lockScreenSoundEnabled_shouldCheckedPreference() {
System.putInt(mContentResolver, System.LOCKSCREEN_SOUNDS_ENABLED, 1);

View File

@@ -32,11 +32,13 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -54,15 +56,15 @@ public class TouchSoundPreferenceControllerTest {
private ContentResolver mContentResolver;
@Mock
private SoundSettings mSetting;
@Mock
private Context mContext;
private Context mContext;
private TouchSoundPreferenceController mController;
private SwitchPreference mPreference;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
when(mActivity.getSystemService(Context.AUDIO_SERVICE)).thenReturn(mAudioManager);
when(mSetting.getActivity()).thenReturn(mActivity);
when(mActivity.getContentResolver()).thenReturn(mContentResolver);
@@ -73,10 +75,16 @@ public class TouchSoundPreferenceControllerTest {
}
@Test
public void isAvailable_isAlwaysTrue() {
public void isAvailable_byDefault_isTrue() {
assertThat(mController.isAvailable()).isTrue();
}
@Test
@Config(qualifiers = "mcc999")
public void isAvailable_whenNotVisible_isFalse() {
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void displayPreference_soundEffectEnabled_shouldCheckedPreference() {
System.putInt(mContentResolver, System.SOUND_EFFECTS_ENABLED, 1);