Add settings for the assist gesture.

Availability of the gesture is gated by a new FeatureProvider.

Test: make -j RunSettingsRoboTests; manual test on
      supported/unsupported configurations.

Change-Id: I3529367a73e33370d5112b91d5144293ffa7fa22
This commit is contained in:
Philip Quinn
2017-02-13 20:07:09 -08:00
parent cd79e3a785
commit a9831d40d0
23 changed files with 485 additions and 9 deletions

View File

@@ -0,0 +1,95 @@
/*
* Copyright (C) 2017 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.content.Context;
import android.provider.Settings;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.search2.InlineSwitchPayload;
import com.android.settings.search2.ResultPayload;
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.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
import java.util.ArrayList;
import java.util.List;
import static android.provider.Settings.Secure.ASSIST_GESTURE_ENABLED;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class AssistGesturePreferenceControllerTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private Context mContext;
private FakeFeatureFactory mFactory;
private AssistGesturePreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
FakeFeatureFactory.setupForTest(mContext);
mFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
mController = new AssistGesturePreferenceController(mContext, null);
}
@Test
public void isAvailable_whenSupported_shouldReturnTrue() {
when(mFactory.assistGestureFeatureProvider.isSupported(mContext)).thenReturn(true);
assertThat(mController.isAvailable()).isTrue();
}
@Test
public void isAvailable_whenUnsupported_shouldReturnFalse() {
when(mFactory.assistGestureFeatureProvider.isSupported(mContext)).thenReturn(false);
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void testSwitchEnabled_configIsSet_shouldReturnTrue() {
// Set the setting to be enabled.
final Context context = ShadowApplication.getInstance().getApplicationContext();
Settings.System.putInt(context.getContentResolver(), ASSIST_GESTURE_ENABLED, 1);
mController = new AssistGesturePreferenceController(context, null);
assertThat(mController.isSwitchPrefEnabled()).isTrue();
}
@Test
public void testSwitchEnabled_configIsNotSet_shouldReturnFalse() {
// Set the setting to be disabled.
final Context context = ShadowApplication.getInstance().getApplicationContext();
Settings.System.putInt(context.getContentResolver(), ASSIST_GESTURE_ENABLED, 0);
mController = new AssistGesturePreferenceController(context, null);
assertThat(mController.isSwitchPrefEnabled()).isFalse();
}
}

View File

@@ -0,0 +1,83 @@
/*
* Copyright (C) 2017 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.content.Context;
import android.provider.SearchIndexableResource;
import com.android.settings.R;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settings.core.PreferenceController;
import com.android.settings.testutils.FakeFeatureFactory;
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.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
import java.util.List;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class AssistGestureSettingsTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private Context mContext;
private AssistGestureSettings mSettings;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
FakeFeatureFactory.setupForTest(mContext);
final FakeFeatureFactory factory =
(FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
when(factory.dashboardFeatureProvider.isEnabled()).thenReturn(true);
mSettings = new AssistGestureSettings();
}
@Test
public void testGetPreferenceScreenResId() {
assertThat(mSettings.getPreferenceScreenResId())
.isEqualTo(R.xml.assist_gesture_settings);
}
@Test
public void testGetPreferenceControllers_shouldAllBeCreated() {
final List<PreferenceController> controllers =
mSettings.getPreferenceControllers(mContext);
assertThat(controllers.isEmpty()).isFalse();
}
@Test
public void testSearchIndexProvider_shouldIndexResource() {
final List<SearchIndexableResource> indexRes =
AssistGestureSettings.SEARCH_INDEX_DATA_PROVIDER.getXmlResourcesToIndex(
ShadowApplication.getInstance().getApplicationContext(),
true /* enabled */);
assertThat(indexRes).isNotNull();
assertThat(indexRes.get(0).xmlResId).isEqualTo(mSettings.getPreferenceScreenResId());
}
}

View File

@@ -210,7 +210,7 @@ public class DatabaseIndexingManagerTest {
mManager.indexOneSearchIndexableData(mDb, localeStr, resource,
new HashMap<>());
Cursor cursor = mDb.rawQuery("SELECT * FROM prefs_index", null);
assertThat(cursor.getCount()).isEqualTo(6);
assertThat(cursor.getCount()).isEqualTo(7);
}
@Test
@@ -224,7 +224,7 @@ public class DatabaseIndexingManagerTest {
Cursor cursor = mDb.rawQuery("SELECT * FROM prefs_index WHERE enabled = 0", null);
assertThat(cursor.getCount()).isEqualTo(2);
cursor = mDb.rawQuery("SELECT * FROM prefs_index WHERE enabled = 1", null);
assertThat(cursor.getCount()).isEqualTo(4);
assertThat(cursor.getCount()).isEqualTo(5);
}
@Test
@@ -673,4 +673,4 @@ public class DatabaseIndexingManagerTest {
niks.put(packageName, keysList);
return niks;
}
}
}

View File

@@ -60,7 +60,7 @@ public class XmlParserUtilTest {
"com.android.settings.gestures.GesturePreference");
final AttributeSet attrs = Xml.asAttributeSet(parser);
String title = XmlParserUtils.getDataTitle(mContext, attrs);
String expTitle = mContext.getString(R.string.fingerprint_swipe_for_notifications_title);
String expTitle = mContext.getString(R.string.assist_gesture_title);
assertThat(title).isEqualTo(expTitle);
}
@@ -79,7 +79,7 @@ public class XmlParserUtilTest {
"com.android.settings.gestures.GesturePreference");
final AttributeSet attrs = Xml.asAttributeSet(parser);
String key = XmlParserUtils.getDataKey(mContext, attrs);
String expKey = "gesture_swipe_down_fingerprint";
String expKey = "gesture_assist";
assertThat(key).isEqualTo(expKey);
}
@@ -89,7 +89,7 @@ public class XmlParserUtilTest {
"com.android.settings.gestures.GesturePreference");
final AttributeSet attrs = Xml.asAttributeSet(parser);
String summary = XmlParserUtils.getDataSummary(mContext, attrs);
String expSummary = mContext.getString(R.string.fingerprint_swipe_for_notifications_summary);
String expSummary = mContext.getString(R.string.assist_gesture_summary);
assertThat(summary).isEqualTo(expSummary);
}

View File

@@ -23,6 +23,7 @@ import com.android.settings.dashboard.DashboardFeatureProvider;
import com.android.settings.dashboard.SuggestionFeatureProvider;
import com.android.settings.enterprise.EnterprisePrivacyFeatureProvider;
import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
import com.android.settings.gestures.AssistGestureFeatureProvider;
import com.android.settings.localepicker.LocaleFeatureProvider;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.overlay.SupportFeatureProvider;
@@ -51,6 +52,7 @@ public class FakeFeatureFactory extends FeatureFactory {
public final SurveyFeatureProvider surveyFeatureProvider;
public final SecurityFeatureProvider securityFeatureProvider;
public final SuggestionFeatureProvider suggestionsFeatureProvider;
public final AssistGestureFeatureProvider assistGestureFeatureProvider;
/**
* Call this in {@code @Before} method of the test class to use fake factory.
@@ -84,6 +86,7 @@ public class FakeFeatureFactory extends FeatureFactory {
surveyFeatureProvider = mock(SurveyFeatureProvider.class);
securityFeatureProvider = mock(SecurityFeatureProvider.class);
suggestionsFeatureProvider = mock(SuggestionFeatureProvider.class);
assistGestureFeatureProvider = mock(AssistGestureFeatureProvider.class);
}
@Override
@@ -140,4 +143,9 @@ public class FakeFeatureFactory extends FeatureFactory {
public SecurityFeatureProvider getSecurityFeatureProvider() {
return securityFeatureProvider;
}
@Override
public AssistGestureFeatureProvider getAssistGestureFeatureProvider() {
return assistGestureFeatureProvider;
}
}