Disable AssistGestureSetting search if not supported

Change-Id: Id5f79506635592d98783b2b99b7ee09dd223c43c
Fixes: 64066820
Test: robotests
This commit is contained in:
Fan Zhang
2017-07-31 15:46:46 -07:00
parent 56538f1775
commit eef16a8b0f
3 changed files with 28 additions and 10 deletions

View File

@@ -15,9 +15,10 @@
limitations under the License.
-->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"
android:key="gesture_assist_settings_page"
android:title="@string/assist_gesture_title">
<com.android.settings.widget.VideoPreference

View File

@@ -79,9 +79,17 @@ public class AssistGestureSettings extends DashboardFragment {
}
@Override
public List<AbstractPreferenceController> getPreferenceControllers(Context context) {
public List<AbstractPreferenceController> getPreferenceControllers(
Context context) {
return buildPreferenceControllers(context, null /* lifecycle */);
}
@Override
protected boolean isPageSearchEnabled(Context context) {
return new AssistGesturePreferenceController(context, null /* lifecycle */,
null /* key */, false /* assistOnly */)
.isAvailable();
}
};
}

View File

@@ -17,7 +17,7 @@
package com.android.settings.gestures;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.when;
import android.content.Context;
@@ -34,6 +34,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
@@ -45,14 +46,12 @@ public class AssistGestureSettingsTest {
@Mock
private Context mContext;
private FakeFeatureFactory mFakeFeatureFactory;
private AssistGestureFeatureProvider mFeatureProvider;
private AssistGestureSettings mSettings;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mFakeFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
mFeatureProvider = mFakeFeatureFactory.getAssistGestureFeatureProvider();
mSettings = new AssistGestureSettings();
}
@@ -79,5 +78,15 @@ public class AssistGestureSettingsTest {
assertThat(indexRes).isNotNull();
assertThat(indexRes.get(0).xmlResId).isEqualTo(mSettings.getPreferenceScreenResId());
}
@Test
public void testSearchIndexProvider_noSensor_shouldDisablePageSearch() {
when(mFakeFeatureFactory.assistGestureFeatureProvider.isSensorAvailable(any(Context.class)))
.thenReturn(false);
assertThat(AssistGestureSettings.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(
RuntimeEnvironment.application))
.contains("gesture_assist_settings_page");
}
}