From d5428a5cd4459067ca71b6dc4935d3f18e520450 Mon Sep 17 00:00:00 2001 From: Beverly Date: Mon, 14 Jan 2019 18:12:47 -0500 Subject: [PATCH] Settings for skip and silence gestures Test: make RunSettingsRoboTests Bug: 118388808 Change-Id: Ic906b42476283d245b423ef8842b6818cf7893a5 --- res/drawable-nodpi/gesture_silence | 0 res/drawable-nodpi/gesture_skip | 0 res/raw/gesture_silence.mp4 | 0 res/raw/gesture_skip.mp4 | 0 res/values/strings.xml | 5 + res/xml/gestures.xml | 12 +++ res/xml/silence_gesture_settings.xml | 26 +++++ res/xml/skip_gesture_settings.xml | 26 +++++ .../SilenceGesturePreferenceController.java | 63 +++++++++++++ .../gestures/SilenceGestureSettings.java | 62 ++++++++++++ .../SkipGesturePreferenceController.java | 63 +++++++++++++ .../gestures/SkipGestureSettings.java | 63 +++++++++++++ ...ilenceGesturePreferenceControllerTest.java | 94 +++++++++++++++++++ .../SkipGesturePreferenceControllerTest.java | 94 +++++++++++++++++++ 14 files changed, 508 insertions(+) create mode 100644 res/drawable-nodpi/gesture_silence create mode 100644 res/drawable-nodpi/gesture_skip create mode 100644 res/raw/gesture_silence.mp4 create mode 100644 res/raw/gesture_skip.mp4 create mode 100644 res/xml/silence_gesture_settings.xml create mode 100644 res/xml/skip_gesture_settings.xml create mode 100644 src/com/android/settings/gestures/SilenceGesturePreferenceController.java create mode 100644 src/com/android/settings/gestures/SilenceGestureSettings.java create mode 100644 src/com/android/settings/gestures/SkipGesturePreferenceController.java create mode 100644 src/com/android/settings/gestures/SkipGestureSettings.java create mode 100644 tests/robotests/src/com/android/settings/gestures/SilenceGesturePreferenceControllerTest.java create mode 100644 tests/robotests/src/com/android/settings/gestures/SkipGesturePreferenceControllerTest.java diff --git a/res/drawable-nodpi/gesture_silence b/res/drawable-nodpi/gesture_silence new file mode 100644 index 00000000000..e69de29bb2d diff --git a/res/drawable-nodpi/gesture_skip b/res/drawable-nodpi/gesture_skip new file mode 100644 index 00000000000..e69de29bb2d diff --git a/res/raw/gesture_silence.mp4 b/res/raw/gesture_silence.mp4 new file mode 100644 index 00000000000..e69de29bb2d diff --git a/res/raw/gesture_skip.mp4 b/res/raw/gesture_skip.mp4 new file mode 100644 index 00000000000..e69de29bb2d diff --git a/res/values/strings.xml b/res/values/strings.xml index 313521af130..358a1f1fe76 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -10492,4 +10492,9 @@ + + Skip gesture + + + Silence alerts gesture diff --git a/res/xml/gestures.xml b/res/xml/gestures.xml index df862512793..fe0f94cc310 100644 --- a/res/xml/gestures.xml +++ b/res/xml/gestures.xml @@ -27,6 +27,18 @@ android:fragment="com.android.settings.gestures.AssistGestureSettings" settings:controller="com.android.settings.gestures.AssistGestureSettingsPreferenceController" /> + + + + + + + + + diff --git a/res/xml/skip_gesture_settings.xml b/res/xml/skip_gesture_settings.xml new file mode 100644 index 00000000000..3d88ac81a06 --- /dev/null +++ b/res/xml/skip_gesture_settings.xml @@ -0,0 +1,26 @@ + + + + + + diff --git a/src/com/android/settings/gestures/SilenceGesturePreferenceController.java b/src/com/android/settings/gestures/SilenceGesturePreferenceController.java new file mode 100644 index 00000000000..8059304c355 --- /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 00000000000..e4acab7621c --- /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 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 00000000000..d1c0a039853 --- /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 00000000000..7d1090bdfb9 --- /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 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 00000000000..2dc880bbe5a --- /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 00000000000..c544786bce7 --- /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(); + } +}