Prevent ringing updates

- Add video
- Update text
- Link from Sound settings
- Inherit from BasePreferenceController

Test: make -j RunSettingsRoboTests
Change-Id: If8cd9efd4e6034e6f6864a142a86cbc23bf59dc3
Fixes: 76832936
Fixes: 74410634
diff --git a/res/drawable-nodpi/gesture_prevent_ringing b/res/drawable-nodpi/gesture_prevent_ringing
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/res/drawable-nodpi/gesture_prevent_ringing
diff --git a/res/raw/gesture_prevent_ringing.mp4 b/res/raw/gesture_prevent_ringing.mp4
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/res/raw/gesture_prevent_ringing.mp4
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 34cac8a..8ea041a 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -9879,6 +9879,8 @@
     <string name="gesture_prevent_ringing_screen_title">Prevent ringing</string>
     <!-- Title for prevent ringing setting -->
     <string name="gesture_prevent_ringing_title">Press Power &amp; Volume Up together</string>
+    <!-- Title for prevent ringing setting -->
+    <string name="gesture_prevent_ringing_sound_title">Shortcut to prevent ringing</string>
     <!-- Option for prevent ringing setting -->
     <string name="prevent_ringing_option_vibrate">Vibrate</string>
     <!-- Option for prevent ringing setting -->
@@ -9886,11 +9888,11 @@
     <!-- Option for prevent ringing setting -->
     <string name="prevent_ringing_option_none">Do nothing</string>
     <!-- Summary for prevent ringing setting -->
-    <string name="prevent_ringing_option_vibrate_summary">Vibrate all calls and notifications</string>
+    <string name="prevent_ringing_option_vibrate_summary">On (vibrate)</string>
     <!-- Summary for prevent ringing setting -->
-    <string name="prevent_ringing_option_mute_summary">Mute all calls and notifications</string>
+    <string name="prevent_ringing_option_mute_summary">On (mute)</string>
     <!-- Summary for prevent ringing setting -->
-    <string name="prevent_ringing_option_none_summary">Do nothing</string>
+    <string name="prevent_ringing_option_none_summary">Off</string>
 
     <!-- Title for detail page of wifi network [CHAR LIMIT=30] -->
     <string name="pref_title_network_details">Network details</string>
diff --git a/res/xml/gestures.xml b/res/xml/gestures.xml
index 0eaa2a6..aec933a 100644
--- a/res/xml/gestures.xml
+++ b/res/xml/gestures.xml
@@ -60,6 +60,7 @@
     <Preference
         android:key="gesture_prevent_ringing_summary"
         android:title="@string/gesture_prevent_ringing_screen_title"
-        android:fragment="com.android.settings.gestures.PreventRingingGestureSettings" />
+        android:fragment="com.android.settings.gestures.PreventRingingGestureSettings"
+        settings:controller="com.android.settings.gestures.PreventRingingPreferenceController" />
 
 </PreferenceScreen>
diff --git a/res/xml/prevent_ringing_gesture_settings.xml b/res/xml/prevent_ringing_gesture_settings.xml
index 10732fc..08146e4 100644
--- a/res/xml/prevent_ringing_gesture_settings.xml
+++ b/res/xml/prevent_ringing_gesture_settings.xml
@@ -21,15 +21,17 @@
     android:key="gesture_prevent_ringing_screen"
     android:title="@string/gesture_prevent_ringing_screen_title">
 
-    <!-- TODO: Add video preference when it exists -->
     <com.android.settings.widget.VideoPreference
-        android:key="gesture_prevent_ringing_video" />
+        android:key="gesture_prevent_ringing_video"
+        app:animation="@raw/gesture_prevent_ringing"
+        app:preview="@drawable/gesture_prevent_ringing" />
 
     <ListPreference
         android:key="gesture_prevent_ringing"
         android:title="@string/gesture_prevent_ringing_title"
         android:entries="@array/gesture_prevent_ringing_entries"
         android:entryValues="@array/gesture_prevent_ringing_values"
+        app:controller="com.android.settings.gestures.PreventRingingPreferenceController"
         app:keywords="@string/keywords_gesture" />
 
 </PreferenceScreen>
\ No newline at end of file
diff --git a/res/xml/sound_settings.xml b/res/xml/sound_settings.xml
index 7fd3709..9772fa2 100644
--- a/res/xml/sound_settings.xml
+++ b/res/xml/sound_settings.xml
@@ -20,7 +20,7 @@
     android:title="@string/sound_settings"
     android:key="sound_settings"
     settings:keywords="@string/keywords_sounds"
-    settings:initialExpandedChildrenCount="7">
+    settings:initialExpandedChildrenCount="8">
 
     <!-- Media volume -->
     <com.android.settings.notification.VolumeSeekBarPreference
@@ -70,6 +70,14 @@
         settings:allowDividerAbove="true"
         android:order="-120"/>
 
+    <Preference
+        android:key="gesture_prevent_ringing_sound"
+        android:title="@string/gesture_prevent_ringing_sound_title"
+        settings:allowDividerAbove="true"
+        android:order="-110"
+        android:fragment="com.android.settings.gestures.PreventRingingGestureSettings"
+        settings:controller="com.android.settings.gestures.PreventRingingPreferenceController" />
+
     <!-- Phone ringtone -->
     <com.android.settings.DefaultRingtonePreference
         android:key="ringtone"
diff --git a/src/com/android/settings/gestures/GestureSettings.java b/src/com/android/settings/gestures/GestureSettings.java
index f6fe82c..439819c 100644
--- a/src/com/android/settings/gestures/GestureSettings.java
+++ b/src/com/android/settings/gestures/GestureSettings.java
@@ -64,19 +64,6 @@
     }
 
     @Override
-    protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
-        return buildPreferenceControllers(context, getLifecycle());
-    }
-
-    static List<AbstractPreferenceController> buildPreferenceControllers(
-            @NonNull Context context, @Nullable Lifecycle lifecycle) {
-        final List<AbstractPreferenceController> controllers = new ArrayList<>();
-        controllers.add(new PreventRingingPreferenceController(
-                context, lifecycle, UserHandle.myUserId(), KEY_PREVENT_RINGING));
-        return controllers;
-    }
-
-    @Override
     public void onAttach(Context context) {
         super.onAttach(context);
         use(AssistGestureSettingsPreferenceController.class).setAssistOnly(false);
@@ -102,12 +89,6 @@
                 }
 
                 @Override
-                public List<AbstractPreferenceController> createPreferenceControllers(
-                        Context context) {
-                    return buildPreferenceControllers(context, null);
-                }
-
-                @Override
                 public List<String> getNonIndexableKeys(Context context) {
                     List<String> keys = super.getNonIndexableKeys(context);
                     // Duplicates in summary and details pages.
@@ -117,6 +98,7 @@
                     keys.add(KEY_DOUBLE_TWIST);
                     keys.add(KEY_DOUBLE_TAP_SCREEN);
                     keys.add(KEY_PICK_UP);
+                    keys.add(KEY_PREVENT_RINGING);
 
                     return keys;
                 }
diff --git a/src/com/android/settings/gestures/GesturesSettingPreferenceController.java b/src/com/android/settings/gestures/GesturesSettingPreferenceController.java
index e4e24d8..1eb188a 100644
--- a/src/com/android/settings/gestures/GesturesSettingPreferenceController.java
+++ b/src/com/android/settings/gestures/GesturesSettingPreferenceController.java
@@ -27,6 +27,7 @@
 import com.android.settings.overlay.FeatureFactory;
 import com.android.settingslib.core.AbstractPreferenceController;
 
+import java.util.ArrayList;
 import java.util.List;
 
 public class GesturesSettingPreferenceController extends BasePreferenceController {
@@ -63,8 +64,7 @@
             @NonNull Context context) {
         final AmbientDisplayConfiguration ambientDisplayConfiguration =
                 new AmbientDisplayConfiguration(context);
-        final List<AbstractPreferenceController> controllers =
-                GestureSettings.buildPreferenceControllers(context, null);
+        final List<AbstractPreferenceController> controllers = new ArrayList<>();
 
         controllers.add(new AssistGestureSettingsPreferenceController(context, FAKE_PREF_KEY)
                 .setAssistOnly(false));
@@ -75,6 +75,7 @@
                 .setConfig(ambientDisplayConfiguration));
         controllers.add(new DoubleTapScreenPreferenceController(context, FAKE_PREF_KEY)
                 .setConfig(ambientDisplayConfiguration));
+        controllers.add(new PreventRingingPreferenceController(context, FAKE_PREF_KEY));
         return controllers;
     }
 
diff --git a/src/com/android/settings/gestures/PreventRingingGestureSettings.java b/src/com/android/settings/gestures/PreventRingingGestureSettings.java
index 9897b48..09570df 100644
--- a/src/com/android/settings/gestures/PreventRingingGestureSettings.java
+++ b/src/com/android/settings/gestures/PreventRingingGestureSettings.java
@@ -61,19 +61,6 @@
         return 0;
     }
 
-    @Override
-    protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
-        return buildPreferenceControllers(context, getLifecycle());
-    }
-
-    private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
-            Lifecycle lifecycle) {
-        final List<AbstractPreferenceController> controllers = new ArrayList<>();
-        controllers.add(new PreventRingingPreferenceController(context, lifecycle,
-                UserHandle.myUserId(),  KEY_PREVENT_RINGING));
-        return controllers;
-    }
-
     public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
             new BaseSearchIndexProvider() {
                 @Override
@@ -83,12 +70,6 @@
                     sir.xmlResId = R.xml.prevent_ringing_gesture_settings;
                     return Arrays.asList(sir);
                 }
-
-                @Override
-                public List<AbstractPreferenceController> createPreferenceControllers(
-                        Context context) {
-                    return buildPreferenceControllers(context, null /* lifecycle */);
-                }
             };
 
 }
diff --git a/src/com/android/settings/gestures/PreventRingingPreferenceController.java b/src/com/android/settings/gestures/PreventRingingPreferenceController.java
index 3255c92..493755f 100644
--- a/src/com/android/settings/gestures/PreventRingingPreferenceController.java
+++ b/src/com/android/settings/gestures/PreventRingingPreferenceController.java
@@ -21,7 +21,6 @@
 import static android.provider.Settings.Secure.VOLUME_HUSH_OFF;
 import static android.provider.Settings.Secure.VOLUME_HUSH_VIBRATE;
 
-import android.annotation.UserIdInt;
 import android.content.Context;
 import android.os.Bundle;
 import android.provider.Settings;
@@ -31,22 +30,20 @@
 import android.support.v7.preference.PreferenceScreen;
 
 import com.android.settings.R;
+import com.android.settings.core.BasePreferenceController;
 import com.android.settings.core.PreferenceControllerMixin;
 import com.android.settings.widget.VideoPreference;
-import com.android.settingslib.core.AbstractPreferenceController;
-import com.android.settingslib.core.lifecycle.Lifecycle;
 import com.android.settingslib.core.lifecycle.LifecycleObserver;
 import com.android.settingslib.core.lifecycle.events.OnCreate;
 import com.android.settingslib.core.lifecycle.events.OnPause;
 import com.android.settingslib.core.lifecycle.events.OnResume;
 import com.android.settingslib.core.lifecycle.events.OnSaveInstanceState;
 
-public class PreventRingingPreferenceController extends AbstractPreferenceController
+public class PreventRingingPreferenceController extends BasePreferenceController
         implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener,
         LifecycleObserver, OnResume, OnPause, OnCreate, OnSaveInstanceState {
 
     private static final String PREF_KEY_VIDEO = "gesture_prevent_ringing_video";
-    private final String mPrefKey;
     @VisibleForTesting
     static final String KEY_VIDEO_PAUSED = "key_video_paused";
 
@@ -56,17 +53,15 @@
 
     private final String SECURE_KEY = VOLUME_HUSH_GESTURE;
 
-    @UserIdInt
-    private final int mUserId;
+    public PreventRingingPreferenceController(Context context, String key) {
+        super(context, key);
+    }
 
-    public PreventRingingPreferenceController(Context context, Lifecycle lifecycle,
-            @UserIdInt int userId, String key) {
-        super(context);
-        if (lifecycle != null) {
-            lifecycle.addObserver(this);
-        }
-        mUserId = userId;
-        mPrefKey = key;
+    @Override
+    public int getAvailabilityStatus() {
+        return mContext.getResources().getBoolean(
+                com.android.internal.R.bool.config_volumeHushGestureEnabled)
+                ? AVAILABLE : DISABLED_UNSUPPORTED;
     }
 
     @Override
@@ -144,22 +139,11 @@
         }
     }
 
-    @Override
-    public boolean isAvailable() {
-        return mContext.getResources()
-                .getBoolean(com.android.internal.R.bool.config_volumeHushGestureEnabled);
-    }
-
     protected String getVideoPrefKey() {
         return PREF_KEY_VIDEO;
     }
 
     @Override
-    public String getPreferenceKey() {
-        return mPrefKey;
-    }
-
-    @Override
     public boolean onPreferenceChange(Preference preference, Object newValue) {
         int value = Integer.parseInt((String) newValue);
         Settings.Secure.putInt(mContext.getContentResolver(), SECURE_KEY, value);
diff --git a/tests/robotests/src/com/android/settings/gestures/PreventRingingPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/PreventRingingPreferenceControllerTest.java
index d92e0e0..b687b46 100644
--- a/tests/robotests/src/com/android/settings/gestures/PreventRingingPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/gestures/PreventRingingPreferenceControllerTest.java
@@ -68,8 +68,7 @@
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        mController = new PreventRingingPreferenceController(
-                mContext, null, 0, KEY_PICK_UP);
+        mController = new PreventRingingPreferenceController(mContext, KEY_PICK_UP);
     }
 
     @Test