diff --git a/res/values/strings.xml b/res/values/strings.xml index f2661bda11b..56dbc6b8e97 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -8920,6 +8920,10 @@ Sleep after %1$s of inactivity Wallpaper, sleep, font size + + + Sleep, font size + Sleep after 10 minutes of inactivity diff --git a/res/xml/display_settings.xml b/res/xml/display_settings.xml index db4e7d87838..b0e362c41a6 100644 --- a/res/xml/display_settings.xml +++ b/res/xml/display_settings.xml @@ -52,7 +52,7 @@ android:title="@string/wallpaper_settings_title" settings:keywords="@string/keywords_display_wallpaper" settings:useAdminDisabledSummary="true" - settings:searchable="false"> + settings:controller="com.android.settings.display.WallpaperPreferenceController"> diff --git a/res/xml/top_level_settings.xml b/res/xml/top_level_settings.xml index dbb106ec03d..889761bb134 100644 --- a/res/xml/top_level_settings.xml +++ b/res/xml/top_level_settings.xml @@ -59,10 +59,11 @@ + android:fragment="com.android.settings.DisplaySettings" + settings:controller="com.android.settings.display.TopLevelDisplayPreferenceController"/> resolveInfos = pm.queryIntentActivities(intent, 0 /* flags */); - return resolveInfos != null && resolveInfos.size() != 0; - } - - @Override - public String getPreferenceKey() { - return KEY_WALLPAPER; + return resolveInfos != null && !resolveInfos.isEmpty() + ? AVAILABLE_UNSEARCHABLE : CONDITIONALLY_UNAVAILABLE; } @Override diff --git a/tests/robotests/src/com/android/settings/display/TopLevelDisplayPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/display/TopLevelDisplayPreferenceControllerTest.java new file mode 100644 index 00000000000..fe4fcc8e225 --- /dev/null +++ b/tests/robotests/src/com/android/settings/display/TopLevelDisplayPreferenceControllerTest.java @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2018 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.display; + +import static com.android.settings.core.BasePreferenceController.AVAILABLE; + +import static com.google.common.truth.Truth.assertThat; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import android.content.Context; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.content.pm.ResolveInfo; + +import com.android.settings.R; +import com.android.settings.testutils.SettingsRobolectricTestRunner; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +import java.util.ArrayList; +import java.util.List; + +@RunWith(SettingsRobolectricTestRunner.class) +public class TopLevelDisplayPreferenceControllerTest { + @Mock + private Context mContext; + @Mock + private PackageManager mPackageManager; + + private TopLevelDisplayPreferenceController mController; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + when(mContext.getPackageManager()).thenReturn(mPackageManager); + when(mContext.getString(R.string.config_wallpaper_picker_package)) + .thenReturn("pkg"); + when(mContext.getString(R.string.config_wallpaper_picker_class)) + .thenReturn("cls"); + + mController = new TopLevelDisplayPreferenceController(mContext, "test_key"); + } + + @Test + public void getAvailability_alwaysAvailable() { + assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE); + } + + @Test + public void getSummary_hasWallpaper_shouldReturnWallpaperSummary() { + final List resolveInfos = new ArrayList<>(); + resolveInfos.add(mock(ResolveInfo.class)); + when(mPackageManager.queryIntentActivities(any(Intent.class), anyInt())) + .thenReturn(resolveInfos); + + assertThat(mController.getSummary()) + .isEqualTo(mContext.getText(R.string.display_dashboard_summary)); + } + + @Test + public void getSummary_hasWallpaper_shouldReturnNoWallpaperSummary() { + final List resolveInfos = new ArrayList<>(); + when(mPackageManager.queryIntentActivities(any(Intent.class), anyInt())) + .thenReturn(resolveInfos); + + assertThat(mController.getSummary()) + .isEqualTo(mContext.getText(R.string.display_dashboard_nowallpaper_summary)); + } + +} diff --git a/tests/robotests/src/com/android/settings/display/WallpaperPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/display/WallpaperPreferenceControllerTest.java index 8a24241d4f4..b4305b6e9d6 100644 --- a/tests/robotests/src/com/android/settings/display/WallpaperPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/display/WallpaperPreferenceControllerTest.java @@ -45,6 +45,7 @@ public class WallpaperPreferenceControllerTest { private static final String WALLPAPER_PACKAGE = "TestPkg"; private static final String WALLPAPER_CLASS = "TestCls"; + private static final String TEST_KEY = "test_key"; @Mock private Context mContext; @@ -54,7 +55,7 @@ public class WallpaperPreferenceControllerTest { private WallpaperPreferenceController mController; @Before - public void setUp() throws PackageManager.NameNotFoundException { + public void setUp() { MockitoAnnotations.initMocks(this); when(mContext.getString(R.string.config_wallpaper_picker_package)) .thenReturn(WALLPAPER_PACKAGE); @@ -62,11 +63,11 @@ public class WallpaperPreferenceControllerTest { .thenReturn(WALLPAPER_CLASS); when(mContext.getPackageManager()).thenReturn(mPackageManager); - mController = new WallpaperPreferenceController(mContext); + mController = new WallpaperPreferenceController(mContext, TEST_KEY); } @Test - public void isAvailable_wallpaerPickerEnabled_shouldReturnTrue() { + public void isAvailable_wallpaperPickerEnabled_shouldReturnTrue() { final List resolveInfos = new ArrayList<>(); resolveInfos.add(mock(ResolveInfo.class)); when(mPackageManager.queryIntentActivities(any(Intent.class), anyInt())) @@ -76,7 +77,7 @@ public class WallpaperPreferenceControllerTest { } @Test - public void isAvailable_wallpaerPickerDisbled_shouldReturnFalseAndNoCrash() { + public void isAvailable_wallpaperPickerDisabled_shouldReturnFalse() { when(mPackageManager.queryIntentActivities(any(Intent.class), anyInt())).thenReturn(null); assertThat(mController.isAvailable()).isFalse(); @@ -86,6 +87,5 @@ public class WallpaperPreferenceControllerTest { .thenReturn(resolveInfos); assertThat(mController.isAvailable()).isFalse(); - // should not crash } }