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"
diff --git a/src/com/android/settings/notification/VibrateWhenRingPreferenceController.java b/src/com/android/settings/notification/VibrateWhenRingPreferenceController.java
index ae111b2..f1ce0af 100644
--- a/src/com/android/settings/notification/VibrateWhenRingPreferenceController.java
+++ b/src/com/android/settings/notification/VibrateWhenRingPreferenceController.java
@@ -23,6 +23,7 @@
 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 @@
     @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 @@
             }
         }
     }
+
+    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;
+        }
+    }
+
 }
diff --git a/tests/robotests/src/com/android/settings/notification/SoundSettingsTest.java b/tests/robotests/src/com/android/settings/notification/SoundSettingsTest.java
index 4f3dce6..56d0828 100644
--- a/tests/robotests/src/com/android/settings/notification/SoundSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/notification/SoundSettingsTest.java
@@ -32,6 +32,7 @@
 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 @@
 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);
diff --git a/tests/robotests/src/com/android/settings/notification/VibrateWhenRingPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/VibrateWhenRingPreferenceControllerTest.java
index 7334b45..3f53ce9 100644
--- a/tests/robotests/src/com/android/settings/notification/VibrateWhenRingPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/VibrateWhenRingPreferenceControllerTest.java
@@ -29,6 +29,7 @@
 
 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.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 @@
     }
 
     @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 @@
     @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 @@
                 new VibrateWhenRingPreferenceController(mContext, "bad_key");
         assertThat(controller.isSliceable()).isFalse();
     }
+
 }
diff --git a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowDeviceConfig.java b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowDeviceConfig.java
new file mode 100644
index 0000000..d46e755
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowDeviceConfig.java
@@ -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; }
+}
+
+