Merge "Settings for skip and silence gestures"
diff --git a/res/drawable-nodpi/gesture_silence b/res/drawable-nodpi/gesture_silence
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/res/drawable-nodpi/gesture_silence
diff --git a/res/drawable-nodpi/gesture_skip b/res/drawable-nodpi/gesture_skip
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/res/drawable-nodpi/gesture_skip
diff --git a/res/raw/gesture_silence.mp4 b/res/raw/gesture_silence.mp4
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/res/raw/gesture_silence.mp4
diff --git a/res/raw/gesture_skip.mp4 b/res/raw/gesture_skip.mp4
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/res/raw/gesture_skip.mp4
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 1ae7340..5511559 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -10495,4 +10495,9 @@
     <!-- String for talkback on the account avatar of the search bar.  [CHAR LIMIT=NONE] -->
     <string name="search_bar_account_avatar_content_description"></string>
 
+    <!-- Preference title text for skip media gesture [CHAR LIMIT=60]-->
+    <string name="gesture_skip_title">Skip gesture</string>
+
+    <!-- Preference title text for silence gesture [CHAR LIMIT=60]-->
+    <string name="gesture_silence_title">Silence alerts gesture</string>
 </resources>
diff --git a/res/xml/gestures.xml b/res/xml/gestures.xml
index df86251..fe0f94c 100644
--- a/res/xml/gestures.xml
+++ b/res/xml/gestures.xml
@@ -28,6 +28,18 @@
         settings:controller="com.android.settings.gestures.AssistGestureSettingsPreferenceController" />
 
     <Preference
+        android:key="gesture_skip_summary"
+        android:title="@string/gesture_skip_title"
+        android:fragment="com.android.settings.gestures.SkipGestureSettings"
+        settings:controller="com.android.settings.gestures.SkipGesturePreferenceController" />
+
+    <Preference
+        android:key="gesture_silence_summary"
+        android:title="@string/gesture_silence_title"
+        android:fragment="com.android.settings.gestures.SilenceGestureSettings"
+        settings:controller="com.android.settings.gestures.SilenceGesturePreferenceController" />
+
+    <Preference
         android:key="gesture_wake_screen_input_summary"
         android:title="@string/ambient_display_wake_screen_title"
         android:fragment="com.android.settings.gestures.WakeScreenGestureSettings"
diff --git a/res/xml/silence_gesture_settings.xml b/res/xml/silence_gesture_settings.xml
new file mode 100644
index 0000000..208a41d
--- /dev/null
+++ b/res/xml/silence_gesture_settings.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2019 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.
+-->
+<PreferenceScreen
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    android:key="silence_gesture"
+    android:title="@string/gesture_silence_title">
+
+    <com.android.settings.widget.VideoPreference
+        android:key="gesture_silence_video"
+        app:animation="@raw/gesture_silence"
+        app:preview="@drawable/gesture_silence"/>
+</PreferenceScreen>
diff --git a/res/xml/skip_gesture_settings.xml b/res/xml/skip_gesture_settings.xml
new file mode 100644
index 0000000..3d88ac8
--- /dev/null
+++ b/res/xml/skip_gesture_settings.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2019 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.
+-->
+<PreferenceScreen
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    android:key="skip_gesture"
+    android:title="@string/gesture_skip_title">
+
+    <com.android.settings.widget.VideoPreference
+        android:key="gesture_skip_video"
+        app:animation="@raw/gesture_skip"
+        app:preview="@drawable/gesture_skip"/>
+</PreferenceScreen>
diff --git a/src/com/android/settings/gestures/SilenceGesturePreferenceController.java b/src/com/android/settings/gestures/SilenceGesturePreferenceController.java
new file mode 100644
index 0000000..8059304
--- /dev/null
+++ b/src/com/android/settings/gestures/SilenceGesturePreferenceController.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2019 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.gestures;
+
+import static android.provider.Settings.Secure.SILENCE_GESTURE;
+
+import android.content.Context;
+import android.provider.Settings;
+import android.text.TextUtils;
+
+public class SilenceGesturePreferenceController extends GesturePreferenceController {
+
+    private static final int ON = 1;
+    private static final int OFF = 0;
+
+    private static final String PREF_KEY_VIDEO = "gesture_silence_video";
+
+    public SilenceGesturePreferenceController(Context context, String key) {
+        super(context, key);
+    }
+
+    @Override
+    public int getAvailabilityStatus() {
+        return mContext.getResources()
+                .getBoolean(com.android.internal.R.bool.config_silenceSensorAvailable)
+                ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
+    }
+
+    @Override
+    public boolean isSliceable() {
+        return true;
+    }
+
+    @Override
+    protected String getVideoPrefKey() {
+        return PREF_KEY_VIDEO;
+    }
+
+    @Override
+    public boolean isChecked() {
+        return Settings.Secure.getInt(mContext.getContentResolver(), SILENCE_GESTURE, ON) == ON;
+    }
+
+    @Override
+    public boolean setChecked(boolean isChecked) {
+        return Settings.Secure.putInt(mContext.getContentResolver(), SILENCE_GESTURE,
+                isChecked ? ON : OFF);
+    }
+}
diff --git a/src/com/android/settings/gestures/SilenceGestureSettings.java b/src/com/android/settings/gestures/SilenceGestureSettings.java
new file mode 100644
index 0000000..e4acab7
--- /dev/null
+++ b/src/com/android/settings/gestures/SilenceGestureSettings.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2019 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.gestures;
+
+import android.app.settings.SettingsEnums;
+import android.content.Context;
+import android.provider.SearchIndexableResource;
+
+import com.android.settings.R;
+import com.android.settings.dashboard.DashboardFragment;
+import com.android.settings.search.BaseSearchIndexProvider;
+import com.android.settingslib.search.SearchIndexable;
+
+import java.util.Arrays;
+import java.util.List;
+
+@SearchIndexable
+public class SilenceGestureSettings extends DashboardFragment {
+
+    private static final String TAG = "SilenceGestureSettings";
+
+    @Override
+    public int getMetricsCategory() {
+        return SettingsEnums.SETTINGS_GESTURE_SILENCE;
+    }
+
+    @Override
+    protected String getLogTag() {
+        return TAG;
+    }
+
+    @Override
+    protected int getPreferenceScreenResId() {
+        return R.xml.silence_gesture_settings;
+    }
+
+    public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
+            new BaseSearchIndexProvider() {
+                @Override
+                public List<SearchIndexableResource> getXmlResourcesToIndex(
+                        Context context, boolean enabled) {
+                    final SearchIndexableResource sir = new SearchIndexableResource(context);
+                    sir.xmlResId = R.xml.silence_gesture_settings;
+                    return Arrays.asList(sir);
+                }
+            };
+
+}
diff --git a/src/com/android/settings/gestures/SkipGesturePreferenceController.java b/src/com/android/settings/gestures/SkipGesturePreferenceController.java
new file mode 100644
index 0000000..d1c0a03
--- /dev/null
+++ b/src/com/android/settings/gestures/SkipGesturePreferenceController.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2019 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.gestures;
+
+import static android.provider.Settings.Secure.SKIP_GESTURE;
+
+import android.content.Context;
+import android.provider.Settings;
+import android.text.TextUtils;
+
+public class SkipGesturePreferenceController extends GesturePreferenceController {
+
+    private static final int ON = 1;
+    private static final int OFF = 0;
+
+    private static final String PREF_KEY_VIDEO = "gesture_silence_video";
+
+    public SkipGesturePreferenceController(Context context, String key) {
+        super(context, key);
+    }
+
+    @Override
+    public int getAvailabilityStatus() {
+        return mContext.getResources()
+                .getBoolean(com.android.internal.R.bool.config_skipSensorAvailable) ? AVAILABLE
+                : UNSUPPORTED_ON_DEVICE;
+    }
+
+    @Override
+    public boolean isSliceable() {
+        return true;
+    }
+
+    @Override
+    protected String getVideoPrefKey() {
+        return PREF_KEY_VIDEO;
+    }
+
+    @Override
+    public boolean isChecked() {
+        return Settings.Secure.getInt(mContext.getContentResolver(), SKIP_GESTURE, ON) == ON;
+    }
+
+    @Override
+    public boolean setChecked(boolean isChecked) {
+        return Settings.Secure.putInt(mContext.getContentResolver(), SKIP_GESTURE,
+                isChecked ? ON : OFF);
+    }
+}
diff --git a/src/com/android/settings/gestures/SkipGestureSettings.java b/src/com/android/settings/gestures/SkipGestureSettings.java
new file mode 100644
index 0000000..7d1090b
--- /dev/null
+++ b/src/com/android/settings/gestures/SkipGestureSettings.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2019 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.gestures;
+
+import android.app.settings.SettingsEnums;
+import android.content.Context;
+import android.provider.SearchIndexableResource;
+
+import com.android.settings.R;
+import com.android.settings.dashboard.DashboardFragment;
+import com.android.settings.search.BaseSearchIndexProvider;
+import com.android.settingslib.search.SearchIndexable;
+
+import java.util.Arrays;
+import java.util.List;
+
+@SearchIndexable
+public class SkipGestureSettings extends DashboardFragment {
+
+    private static final String TAG = "SkipGestureSettings";
+
+    @Override
+    public int getMetricsCategory() {
+        return SettingsEnums.SETTINGS_GESTURE_SKIP;
+    }
+
+    @Override
+    protected String getLogTag() {
+        return TAG;
+    }
+
+    @Override
+    protected int getPreferenceScreenResId() {
+        return R.xml.skip_gesture_settings;
+    }
+
+    public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
+            new BaseSearchIndexProvider() {
+                @Override
+                public List<SearchIndexableResource> getXmlResourcesToIndex(
+                        Context context, boolean enabled) {
+                    final SearchIndexableResource sir = new SearchIndexableResource(context);
+                    sir.xmlResId = R.xml.skip_gesture_settings;
+                    return Arrays.asList(sir);
+                }
+            };
+
+}
+
diff --git a/tests/robotests/src/com/android/settings/gestures/SilenceGesturePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/SilenceGesturePreferenceControllerTest.java
new file mode 100644
index 0000000..2dc880b
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/gestures/SilenceGesturePreferenceControllerTest.java
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2019 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.gestures;
+
+import static android.provider.Settings.Secure.SILENCE_GESTURE;
+
+import static com.android.settings.core.BasePreferenceController.AVAILABLE;
+import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.provider.Settings;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Answers;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RobolectricTestRunner;
+
+@RunWith(RobolectricTestRunner.class)
+public class SilenceGesturePreferenceControllerTest {
+
+    private static final String KEY_SILENCE = "gesture_silence";
+
+    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+    private Context mContext;
+    @Mock
+    private Resources mResources;
+
+    private SilenceGesturePreferenceController mController;
+
+    @Before
+    public void setUp() {
+        MockitoAnnotations.initMocks(this);
+        when(mContext.getResources()).thenReturn(mResources);
+        mController = new SilenceGesturePreferenceController(mContext, KEY_SILENCE);
+    }
+
+    @Test
+    public void getAvailabilityStatus_gestureNotSupported_UNSUPPORTED_ON_DEVICE() {
+        when(mResources.getBoolean(
+                com.android.internal.R.bool.config_silenceSensorAvailable))
+                .thenReturn(false);
+        final int availabilityStatus = mController.getAvailabilityStatus();
+
+        assertThat(availabilityStatus).isEqualTo(UNSUPPORTED_ON_DEVICE);
+    }
+
+    @Test
+    public void getAvailabilityStatus_gestureSupported_AVAILABLE() {
+        when(mResources.getBoolean(
+                com.android.internal.R.bool.config_silenceSensorAvailable)).thenReturn(true);
+        final int availabilityStatus = mController.getAvailabilityStatus();
+
+        assertThat(availabilityStatus).isEqualTo(AVAILABLE);
+    }
+
+    @Test
+    public void isSliceableCorrectKey_returnsTrue() {
+        assertThat(mController.isSliceable()).isTrue();
+    }
+
+    @Test
+    public void isChecked_testTrue() {
+        Settings.Secure.putInt(mContext.getContentResolver(), SILENCE_GESTURE, 1);
+        assertThat(mController.isChecked()).isTrue();
+    }
+
+    @Test
+    public void isChecked_testFalse() {
+        Settings.Secure.putInt(mContext.getContentResolver(), SILENCE_GESTURE, 0);
+        assertThat(mController.isChecked()).isFalse();
+    }
+}
diff --git a/tests/robotests/src/com/android/settings/gestures/SkipGesturePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/SkipGesturePreferenceControllerTest.java
new file mode 100644
index 0000000..c544786
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/gestures/SkipGesturePreferenceControllerTest.java
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2019 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.gestures;
+
+import static android.provider.Settings.Secure.SKIP_GESTURE;
+
+import static com.android.settings.core.BasePreferenceController.AVAILABLE;
+import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.provider.Settings;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Answers;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RobolectricTestRunner;
+
+@RunWith(RobolectricTestRunner.class)
+public class SkipGesturePreferenceControllerTest {
+
+    private static final String KEY_SKIP = "gesture_skip";
+
+    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+    private Context mContext;
+    @Mock
+    private Resources mResources;
+
+    private SkipGesturePreferenceController mController;
+
+    @Before
+    public void setUp() {
+        MockitoAnnotations.initMocks(this);
+        when(mContext.getResources()).thenReturn(mResources);
+        mController = new SkipGesturePreferenceController(mContext, KEY_SKIP);
+    }
+
+    @Test
+    public void getAvailabilityStatus_gestureNotSupported_UNSUPPORTED_ON_DEVICE() {
+        when(mResources.getBoolean(
+                com.android.internal.R.bool.config_skipSensorAvailable))
+                .thenReturn(false);
+        final int availabilityStatus = mController.getAvailabilityStatus();
+
+        assertThat(availabilityStatus).isEqualTo(UNSUPPORTED_ON_DEVICE);
+    }
+
+    @Test
+    public void getAvailabilityStatus_gestureSupported_AVAILABLE() {
+        when(mResources.getBoolean(
+                com.android.internal.R.bool.config_skipSensorAvailable)).thenReturn(true);
+        final int availabilityStatus = mController.getAvailabilityStatus();
+
+        assertThat(availabilityStatus).isEqualTo(AVAILABLE);
+    }
+
+    @Test
+    public void isSliceableCorrectKey_returnsTrue() {
+        assertThat(mController.isSliceable()).isTrue();
+    }
+
+    @Test
+    public void isChecked_testTrue() {
+        Settings.Secure.putInt(mContext.getContentResolver(), SKIP_GESTURE, 1);
+        assertThat(mController.isChecked()).isTrue();
+    }
+
+    @Test
+    public void isChecked_testFalse() {
+        Settings.Secure.putInt(mContext.getContentResolver(), SKIP_GESTURE, 0);
+        assertThat(mController.isChecked()).isFalse();
+    }
+}