Merge "If the ramping ringer adaptive volume is enabled then do not show this setting. It will be injected from settings intelligence with additional user options"

This commit is contained in:
TreeHugger Robot
2019-01-31 06:18:30 +00:00
committed by Android (Google) Code Review
4 changed files with 97 additions and 9 deletions

View File

@@ -23,6 +23,7 @@ import android.content.Context;
import android.database.ContentObserver;
import android.net.Uri;
import android.os.Handler;
import android.provider.DeviceConfig;
import android.provider.Settings;
import android.text.TextUtils;
@@ -62,7 +63,11 @@ public class VibrateWhenRingPreferenceController extends TogglePreferenceControl
@Override
@AvailabilityStatus
public int getAvailabilityStatus() {
return Utils.isVoiceCapable(mContext) ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
// If ramping ringer is enabled then this setting will be injected
// with additional options.
return Utils.isVoiceCapable(mContext) && !isRampingRingerEnabled()
? AVAILABLE
: UNSUPPORTED_ON_DEVICE;
}
@Override
@@ -123,4 +128,19 @@ public class VibrateWhenRingPreferenceController extends TogglePreferenceControl
}
}
}
private boolean isRampingRingerEnabled() {
String enableRampingRinger = DeviceConfig.getProperty(
DeviceConfig.Telephony.NAMESPACE,
DeviceConfig.Telephony.RAMPING_RINGER_ENABLED);
if (enableRampingRinger == null) {
return false;
}
try {
return Boolean.valueOf(enableRampingRinger);
} catch (Exception e) {
return false;
}
}
}

View File

@@ -32,6 +32,7 @@ import android.preference.SeekBarVolumizer;
import com.android.settings.R;
import com.android.settings.testutils.XmlTestUtils;
import com.android.settings.testutils.shadow.ShadowAudioHelper;
import com.android.settings.testutils.shadow.ShadowDeviceConfig;
import com.android.settings.testutils.shadow.ShadowUserManager;
import org.junit.Test;
@@ -47,7 +48,7 @@ import java.util.List;
public class SoundSettingsTest {
@Test
@Config(shadows = {ShadowUserManager.class, ShadowAudioHelper.class})
@Config(shadows = {ShadowUserManager.class, ShadowAudioHelper.class, ShadowDeviceConfig.class})
public void getNonIndexableKeys_existInXmlLayout() {
final Context context = spy(RuntimeEnvironment.application);
AudioManager audioManager = mock(AudioManager.class);

View File

@@ -29,6 +29,7 @@ import static org.mockito.Mockito.when;
import android.content.ContentResolver;
import android.content.Context;
import android.provider.DeviceConfig;
import android.provider.Settings;
import android.telephony.TelephonyManager;
@@ -36,17 +37,21 @@ import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import androidx.preference.TwoStatePreference;
import com.android.settings.testutils.shadow.ShadowDeviceConfig;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.annotation.Config;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadow.api.Shadow;
import org.robolectric.shadows.ShadowContentResolver;
@RunWith(RobolectricTestRunner.class)
@Config(shadows={ShadowDeviceConfig.class})
public class VibrateWhenRingPreferenceControllerTest {
private static final String KEY_VIBRATE_WHEN_RINGING = "vibrate_when_ringing";
@@ -74,20 +79,42 @@ public class VibrateWhenRingPreferenceControllerTest {
}
@Test
public void display_voiceCapable_shouldDisplay() {
public void display_shouldDisplay() {
when(mTelephonyManager.isVoiceCapable()).thenReturn(true);
DeviceConfig.setProperty("namespace", "key", "false", false);
mController.displayPreference(mScreen);
assertThat(mPreference.isVisible()).isTrue();
}
@Test
public void display_notVoiceCapable_shouldNotDisplay() {
public void display_shouldNotDisplay_notVoiceCapable() {
when(mTelephonyManager.isVoiceCapable()).thenReturn(false);
DeviceConfig.setProperty("namespace", "key", "false", false);
mController.displayPreference(mScreen);
assertThat(mPreference.isVisible()).isFalse();
}
@Test
public void display_shouldNotDisplay_RampingRingerEnabled() {
when(mTelephonyManager.isVoiceCapable()).thenReturn(true);
DeviceConfig.setProperty("namespace", "key", "true", false);
mController.displayPreference(mScreen);
assertThat(mPreference.isVisible()).isFalse();
}
@Test
public void display_shouldNotDisplay_VoiceEnabled_RampingRingerEnabled() {
when(mTelephonyManager.isVoiceCapable()).thenReturn(true);
DeviceConfig.setProperty("namespace", "key", "true", false);
mController.displayPreference(mScreen);
assertThat(mPreference.isVisible()).isFalse();
}
@Test
public void display_shouldNotDisplay_VoiceDisabled_RampingRingerEnabled() {
when(mTelephonyManager.isVoiceCapable()).thenReturn(false);
DeviceConfig.setProperty("namespace", "key", "true", false);
mController.displayPreference(mScreen);
assertThat(mPreference.isVisible()).isFalse();
}
@@ -112,14 +139,14 @@ public class VibrateWhenRingPreferenceControllerTest {
@Test
public void voiceCapable_availabled() {
when(mTelephonyManager.isVoiceCapable()).thenReturn(true);
DeviceConfig.setProperty("namespace", "key", "false", false);
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
}
@Test
public void voiceCapable_notAvailabled() {
when(mTelephonyManager.isVoiceCapable()).thenReturn(false);
DeviceConfig.setProperty("namespace", "key", "false", false);
assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
}
@@ -197,4 +224,5 @@ public class VibrateWhenRingPreferenceControllerTest {
new VibrateWhenRingPreferenceController(mContext, "bad_key");
assertThat(controller.isSliceable()).isFalse();
}
}

View File

@@ -0,0 +1,39 @@
/*
* Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.testutils.shadow;
import org.robolectric.annotation.Config;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
@Implements(android.provider.DeviceConfig.class)
public class ShadowDeviceConfig {
private static String configValue;
@Implementation
protected static boolean setProperty(
String namespace, String name, String value, boolean makeDefault) {
configValue = value;
return true;
}
@Implementation
protected static String getProperty(String ns, String key) { return configValue; }
}