Fix Display settings summary when there is no wallpaper.
Change-Id: I715cef9dc42de1231491b5a7184f0f151d94af11 Fixes: 69905032 Test: robotests
This commit is contained in:
@@ -8920,6 +8920,10 @@
|
||||
<string name="display_summary">Sleep after <xliff:g id="timeout_description" example="10 minutes">%1$s</xliff:g> of inactivity</string>
|
||||
<!-- Summary for Display settings, explaining a few important settings under it [CHAR LIMIT=NONE]-->
|
||||
<string name="display_dashboard_summary">Wallpaper, sleep, font size</string>
|
||||
|
||||
<!-- Summary for Display settings, explaining a few important settings under it [CHAR LIMIT=NONE]-->
|
||||
<string name="display_dashboard_nowallpaper_summary">Sleep, font size</string>
|
||||
|
||||
<!-- Example summary of display used in Setup Wizard preview screen [CHAR LIMIT=NONE] -->
|
||||
<string name="display_summary_example">Sleep after 10 minutes of inactivity</string>
|
||||
|
||||
|
@@ -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">
|
||||
<intent
|
||||
android:targetPackage="@string/config_wallpaper_picker_package"
|
||||
android:targetClass="@string/config_wallpaper_picker_class" />
|
||||
|
@@ -59,10 +59,11 @@
|
||||
<Preference
|
||||
android:key="top_level_display"
|
||||
android:title="@string/display_settings"
|
||||
android:summary="@string/display_dashboard_summary"
|
||||
android:summary="@string/summary_placeholder"
|
||||
android:icon="@drawable/ic_homepage_display"
|
||||
android:order="-70"
|
||||
android:fragment="com.android.settings.DisplaySettings"/>
|
||||
android:fragment="com.android.settings.DisplaySettings"
|
||||
settings:controller="com.android.settings.display.TopLevelDisplayPreferenceController"/>
|
||||
|
||||
<Preference
|
||||
android:key="top_level_sound"
|
||||
|
@@ -85,7 +85,6 @@ public class DisplaySettings extends DashboardFragment {
|
||||
controllers.add(new TimeoutPreferenceController(context, KEY_SCREEN_TIMEOUT));
|
||||
controllers.add(new VrDisplayPreferenceController(context));
|
||||
controllers.add(new ShowOperatorNamePreferenceController(context));
|
||||
controllers.add(new WallpaperPreferenceController(context));
|
||||
controllers.add(new ThemePreferenceController(context));
|
||||
controllers.add(new BrightnessLevelPreferenceController(context, lifecycle));
|
||||
return controllers;
|
||||
|
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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 android.content.Context;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
public class TopLevelDisplayPreferenceController extends BasePreferenceController {
|
||||
|
||||
public TopLevelDisplayPreferenceController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return AVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
if (new WallpaperPreferenceController(mContext, "dummy_key").isAvailable()) {
|
||||
return mContext.getText(R.string.display_dashboard_summary);
|
||||
} else {
|
||||
return mContext.getText(R.string.display_dashboard_nowallpaper_summary);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -27,34 +27,30 @@ import android.util.Log;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settingslib.RestrictedLockUtilsInternal;
|
||||
import com.android.settingslib.RestrictedPreference;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class WallpaperPreferenceController extends AbstractPreferenceController implements
|
||||
PreferenceControllerMixin {
|
||||
public class WallpaperPreferenceController extends BasePreferenceController {
|
||||
|
||||
private static final String TAG = "WallpaperPrefController";
|
||||
|
||||
public static final String KEY_WALLPAPER = "wallpaper";
|
||||
|
||||
private final String mWallpaperPackage;
|
||||
private final String mWallpaperClass;
|
||||
|
||||
public WallpaperPreferenceController(Context context) {
|
||||
super(context);
|
||||
public WallpaperPreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
mWallpaperPackage = mContext.getString(R.string.config_wallpaper_picker_package);
|
||||
mWallpaperClass = mContext.getString(R.string.config_wallpaper_picker_class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
public int getAvailabilityStatus() {
|
||||
if (TextUtils.isEmpty(mWallpaperPackage) || TextUtils.isEmpty(mWallpaperClass)) {
|
||||
Log.e(TAG, "No Wallpaper picker specified!");
|
||||
return false;
|
||||
return UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
final ComponentName componentName =
|
||||
new ComponentName(mWallpaperPackage, mWallpaperClass);
|
||||
@@ -63,12 +59,8 @@ public class WallpaperPreferenceController extends AbstractPreferenceController
|
||||
intent.setComponent(componentName);
|
||||
final List<ResolveInfo> 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
|
||||
|
@@ -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<ResolveInfo> 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<ResolveInfo> resolveInfos = new ArrayList<>();
|
||||
when(mPackageManager.queryIntentActivities(any(Intent.class), anyInt()))
|
||||
.thenReturn(resolveInfos);
|
||||
|
||||
assertThat(mController.getSummary())
|
||||
.isEqualTo(mContext.getText(R.string.display_dashboard_nowallpaper_summary));
|
||||
}
|
||||
|
||||
}
|
@@ -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<ResolveInfo> 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
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user