Merge "Show Styles & Wallpaper in Settings" into qt-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
c35af0eae2
@@ -47,6 +47,8 @@
|
|||||||
<!-- Package name and fully-qualified class name for the wallpaper picker activity. -->
|
<!-- Package name and fully-qualified class name for the wallpaper picker activity. -->
|
||||||
<string name="config_wallpaper_picker_package" translatable="false">com.android.settings</string>
|
<string name="config_wallpaper_picker_package" translatable="false">com.android.settings</string>
|
||||||
<string name="config_wallpaper_picker_class" translatable="false">com.android.settings.Settings$WallpaperSettingsActivity</string>
|
<string name="config_wallpaper_picker_class" translatable="false">com.android.settings.Settings$WallpaperSettingsActivity</string>
|
||||||
|
<!-- Fully-qualified class name for the styles & wallpaper picker activity. -->
|
||||||
|
<string name="config_styles_and_wallpaper_picker_class" translatable="false"></string>
|
||||||
|
|
||||||
<!-- Manufacturer backup settings to launch -->
|
<!-- Manufacturer backup settings to launch -->
|
||||||
<string name="config_backup_settings_intent" translatable="false"></string>
|
<string name="config_backup_settings_intent" translatable="false"></string>
|
||||||
|
@@ -53,9 +53,6 @@
|
|||||||
settings:keywords="@string/keywords_display_wallpaper"
|
settings:keywords="@string/keywords_display_wallpaper"
|
||||||
settings:useAdminDisabledSummary="true"
|
settings:useAdminDisabledSummary="true"
|
||||||
settings:controller="com.android.settings.display.WallpaperPreferenceController">
|
settings:controller="com.android.settings.display.WallpaperPreferenceController">
|
||||||
<intent
|
|
||||||
android:targetPackage="@string/config_wallpaper_picker_package"
|
|
||||||
android:targetClass="@string/config_wallpaper_picker_class" />
|
|
||||||
</com.android.settingslib.RestrictedPreference>
|
</com.android.settingslib.RestrictedPreference>
|
||||||
|
|
||||||
|
|
||||||
|
@@ -36,11 +36,15 @@ public class TopLevelDisplayPreferenceController extends BasePreferenceControlle
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CharSequence getSummary() {
|
public CharSequence getSummary() {
|
||||||
if (new WallpaperPreferenceController(mContext, "dummy_key").isAvailable()) {
|
final WallpaperPreferenceController controller =
|
||||||
return mContext.getText(R.string.display_dashboard_summary);
|
new WallpaperPreferenceController(mContext, "dummy_key");
|
||||||
|
if (controller.isAvailable()) {
|
||||||
|
return mContext.getText(
|
||||||
|
controller.areStylesAvailable()
|
||||||
|
? R.string.display_dashboard_summary_with_style
|
||||||
|
: R.string.display_dashboard_summary);
|
||||||
} else {
|
} else {
|
||||||
return mContext.getText(R.string.display_dashboard_nowallpaper_summary);
|
return mContext.getText(R.string.display_dashboard_nowallpaper_summary);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -25,6 +25,7 @@ import android.text.TextUtils;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.core.BasePreferenceController;
|
import com.android.settings.core.BasePreferenceController;
|
||||||
@@ -34,16 +35,26 @@ import com.android.settingslib.RestrictedPreference;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class WallpaperPreferenceController extends BasePreferenceController {
|
public class WallpaperPreferenceController extends BasePreferenceController {
|
||||||
|
|
||||||
private static final String TAG = "WallpaperPrefController";
|
private static final String TAG = "WallpaperPrefController";
|
||||||
|
|
||||||
private final String mWallpaperPackage;
|
private final String mWallpaperPackage;
|
||||||
private final String mWallpaperClass;
|
private final String mWallpaperClass;
|
||||||
|
private final String mStylesAndWallpaperClass;
|
||||||
|
|
||||||
public WallpaperPreferenceController(Context context, String key) {
|
public WallpaperPreferenceController(Context context, String key) {
|
||||||
super(context, key);
|
super(context, key);
|
||||||
mWallpaperPackage = mContext.getString(R.string.config_wallpaper_picker_package);
|
mWallpaperPackage = mContext.getString(R.string.config_wallpaper_picker_package);
|
||||||
mWallpaperClass = mContext.getString(R.string.config_wallpaper_picker_class);
|
mWallpaperClass = mContext.getString(R.string.config_wallpaper_picker_class);
|
||||||
|
mStylesAndWallpaperClass =
|
||||||
|
mContext.getString(R.string.config_styles_and_wallpaper_picker_class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void displayPreference(PreferenceScreen screen) {
|
||||||
|
super.displayPreference(screen);
|
||||||
|
Preference preference = screen.findPreference(getPreferenceKey());
|
||||||
|
preference.setTitle(mContext.getString(areStylesAvailable()
|
||||||
|
? R.string.style_and_wallpaper_settings_title : R.string.wallpaper_settings_title));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -52,14 +63,7 @@ public class WallpaperPreferenceController extends BasePreferenceController {
|
|||||||
Log.e(TAG, "No Wallpaper picker specified!");
|
Log.e(TAG, "No Wallpaper picker specified!");
|
||||||
return UNSUPPORTED_ON_DEVICE;
|
return UNSUPPORTED_ON_DEVICE;
|
||||||
}
|
}
|
||||||
final ComponentName componentName =
|
return canResolveWallpaperComponent(mWallpaperClass)
|
||||||
new ComponentName(mWallpaperPackage, mWallpaperClass);
|
|
||||||
final PackageManager pm = mContext.getPackageManager();
|
|
||||||
final Intent intent = new Intent();
|
|
||||||
intent.setComponent(componentName);
|
|
||||||
final List<ResolveInfo> resolveInfos =
|
|
||||||
pm.queryIntentActivities(intent, 0 /* flags */);
|
|
||||||
return resolveInfos != null && !resolveInfos.isEmpty()
|
|
||||||
? AVAILABLE_UNSEARCHABLE : CONDITIONALLY_UNAVAILABLE;
|
? AVAILABLE_UNSEARCHABLE : CONDITIONALLY_UNAVAILABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,6 +72,31 @@ public class WallpaperPreferenceController extends BasePreferenceController {
|
|||||||
disablePreferenceIfManaged((RestrictedPreference) preference);
|
disablePreferenceIfManaged((RestrictedPreference) preference);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||||
|
if (getPreferenceKey().equals(preference.getKey())) {
|
||||||
|
final ComponentName componentName = new ComponentName(mWallpaperPackage,
|
||||||
|
areStylesAvailable() ? mStylesAndWallpaperClass : mWallpaperClass);
|
||||||
|
preference.getContext().startActivity(new Intent().setComponent(componentName));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return super.handlePreferenceTreeClick(preference);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Returns whether Styles & Wallpaper is enabled and available. */
|
||||||
|
public boolean areStylesAvailable() {
|
||||||
|
return !TextUtils.isEmpty(mStylesAndWallpaperClass)
|
||||||
|
&& canResolveWallpaperComponent(mStylesAndWallpaperClass);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean canResolveWallpaperComponent(String className) {
|
||||||
|
final ComponentName componentName = new ComponentName(mWallpaperPackage, className);
|
||||||
|
final PackageManager pm = mContext.getPackageManager();
|
||||||
|
final Intent intent = new Intent().setComponent(componentName);
|
||||||
|
final List<ResolveInfo> resolveInfos = pm.queryIntentActivities(intent, 0 /* flags */);
|
||||||
|
return resolveInfos != null && !resolveInfos.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
private void disablePreferenceIfManaged(RestrictedPreference pref) {
|
private void disablePreferenceIfManaged(RestrictedPreference pref) {
|
||||||
final String restriction = DISALLOW_SET_WALLPAPER;
|
final String restriction = DISALLOW_SET_WALLPAPER;
|
||||||
if (pref != null) {
|
if (pref != null) {
|
||||||
|
@@ -39,14 +39,13 @@ import org.junit.Test;
|
|||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
|
import org.robolectric.RobolectricTestRunner;
|
||||||
|
import org.robolectric.RuntimeEnvironment;
|
||||||
|
import org.robolectric.annotation.Config;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.robolectric.annotation.Config;
|
|
||||||
import org.robolectric.RobolectricTestRunner;
|
|
||||||
import org.robolectric.RuntimeEnvironment;
|
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
public class TopLevelDisplayPreferenceControllerTest {
|
public class TopLevelDisplayPreferenceControllerTest {
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
@@ -88,6 +87,19 @@ public class TopLevelDisplayPreferenceControllerTest {
|
|||||||
.isEqualTo(mContext.getText(R.string.display_dashboard_summary));
|
.isEqualTo(mContext.getText(R.string.display_dashboard_summary));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getSummary_hasWallpaperWithStyles_shouldReturnWallpaperSummary() {
|
||||||
|
when(mContext.getString(R.string.config_styles_and_wallpaper_picker_class))
|
||||||
|
.thenReturn("any.nonempty.class");
|
||||||
|
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_with_style));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getSummary_hasWallpaper_shouldReturnNoWallpaperSummary() {
|
public void getSummary_hasWallpaper_shouldReturnNoWallpaperSummary() {
|
||||||
final List<ResolveInfo> resolveInfos = new ArrayList<>();
|
final List<ResolveInfo> resolveInfos = new ArrayList<>();
|
||||||
|
@@ -18,74 +18,132 @@ package com.android.settings.display;
|
|||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
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.mock;
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.ComponentName;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.content.pm.ResolveInfo;
|
import android.content.pm.ResolveInfo;
|
||||||
|
|
||||||
|
import androidx.fragment.app.FragmentActivity;
|
||||||
|
import androidx.preference.Preference;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
|
import org.robolectric.Robolectric;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import org.robolectric.RobolectricTestRunner;
|
import org.robolectric.RobolectricTestRunner;
|
||||||
|
import org.robolectric.Shadows;
|
||||||
|
import org.robolectric.annotation.Config;
|
||||||
|
import org.robolectric.shadows.ShadowPackageManager;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
@Config(shadows = {SettingsShadowResources.class})
|
||||||
public class WallpaperPreferenceControllerTest {
|
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";
|
private static final String TEST_KEY = "test_key";
|
||||||
|
|
||||||
@Mock
|
private Intent mWallpaperIntent;
|
||||||
private Context mContext;
|
private Intent mStylesAndWallpaperIntent;
|
||||||
@Mock
|
private FragmentActivity mContext;
|
||||||
private PackageManager mPackageManager;
|
private ShadowPackageManager mShadowPackageManager;
|
||||||
|
|
||||||
private WallpaperPreferenceController mController;
|
private WallpaperPreferenceController mController;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
when(mContext.getString(R.string.config_wallpaper_picker_package))
|
mContext = Robolectric.buildActivity(FragmentActivity.class).get();
|
||||||
.thenReturn(WALLPAPER_PACKAGE);
|
SettingsShadowResources.overrideResource(
|
||||||
when(mContext.getString(R.string.config_wallpaper_picker_class))
|
R.string.config_wallpaper_picker_package, "bogus.package.for.testing");
|
||||||
.thenReturn(WALLPAPER_CLASS);
|
SettingsShadowResources.overrideResource(
|
||||||
when(mContext.getPackageManager()).thenReturn(mPackageManager);
|
R.string.config_styles_and_wallpaper_picker_class, "bogus.package.class");
|
||||||
|
mWallpaperIntent = new Intent().setComponent(new ComponentName(
|
||||||
|
mContext.getString(R.string.config_wallpaper_picker_package),
|
||||||
|
mContext.getString(R.string.config_wallpaper_picker_class)));
|
||||||
|
mStylesAndWallpaperIntent = new Intent().setComponent(new ComponentName(
|
||||||
|
mContext.getString(R.string.config_wallpaper_picker_package),
|
||||||
|
mContext.getString(R.string.config_styles_and_wallpaper_picker_class)));
|
||||||
|
mShadowPackageManager = Shadows.shadowOf(mContext.getPackageManager());
|
||||||
mController = new WallpaperPreferenceController(mContext, TEST_KEY);
|
mController = new WallpaperPreferenceController(mContext, TEST_KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAvailable_wallpaperPickerEnabled_shouldReturnTrue() {
|
public void isAvailable_wallpaperPickerEnabled_shouldReturnTrue() {
|
||||||
final List<ResolveInfo> resolveInfos = new ArrayList<>();
|
mShadowPackageManager.setResolveInfosForIntent(
|
||||||
resolveInfos.add(mock(ResolveInfo.class));
|
mWallpaperIntent, Lists.newArrayList(mock(ResolveInfo.class)));
|
||||||
when(mPackageManager.queryIntentActivities(any(Intent.class), anyInt()))
|
|
||||||
.thenReturn(resolveInfos);
|
|
||||||
|
|
||||||
assertThat(mController.isAvailable()).isTrue();
|
assertThat(mController.isAvailable()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAvailable_wallpaperPickerDisabled_shouldReturnFalse() {
|
public void isAvailable_wallpaperPickerDisabled_shouldReturnFalse() {
|
||||||
when(mPackageManager.queryIntentActivities(any(Intent.class), anyInt())).thenReturn(null);
|
mShadowPackageManager.setResolveInfosForIntent(
|
||||||
|
mWallpaperIntent, Lists.newArrayList());
|
||||||
assertThat(mController.isAvailable()).isFalse();
|
|
||||||
|
|
||||||
final List<ResolveInfo> resolveInfos = new ArrayList<>();
|
|
||||||
when(mPackageManager.queryIntentActivities(any(Intent.class), anyInt()))
|
|
||||||
.thenReturn(resolveInfos);
|
|
||||||
|
|
||||||
assertThat(mController.isAvailable()).isFalse();
|
assertThat(mController.isAvailable()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void areStylesAvailable_noComponentSpecified() {
|
||||||
|
SettingsShadowResources.overrideResource(
|
||||||
|
R.string.config_styles_and_wallpaper_picker_class, "");
|
||||||
|
mShadowPackageManager.setResolveInfosForIntent(
|
||||||
|
mStylesAndWallpaperIntent, Lists.newArrayList());
|
||||||
|
|
||||||
|
assertThat(mController.areStylesAvailable()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void areStylesAvailable_componentUnresolveable() {
|
||||||
|
mShadowPackageManager.setResolveInfosForIntent(
|
||||||
|
mStylesAndWallpaperIntent, Lists.newArrayList());
|
||||||
|
|
||||||
|
assertThat(mController.areStylesAvailable()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void areStylesAvailable_componentResolved() {
|
||||||
|
mShadowPackageManager.setResolveInfosForIntent(
|
||||||
|
mStylesAndWallpaperIntent,
|
||||||
|
Lists.newArrayList(mock(ResolveInfo.class)));
|
||||||
|
|
||||||
|
assertThat(mController.areStylesAvailable()).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void handlePreferenceTreeClick_wallpaperOnly() {
|
||||||
|
mShadowPackageManager.setResolveInfosForIntent(
|
||||||
|
mWallpaperIntent, Lists.newArrayList(mock(ResolveInfo.class)));
|
||||||
|
mShadowPackageManager.setResolveInfosForIntent(
|
||||||
|
mStylesAndWallpaperIntent, Lists.newArrayList());
|
||||||
|
Preference preference = new Preference(mContext);
|
||||||
|
preference.setKey(TEST_KEY);
|
||||||
|
|
||||||
|
mController.handlePreferenceTreeClick(preference);
|
||||||
|
|
||||||
|
assertThat(Shadows.shadowOf(mContext)
|
||||||
|
.getNextStartedActivityForResult().intent.getComponent().getClassName())
|
||||||
|
.isEqualTo(mContext.getString(R.string.config_wallpaper_picker_class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void handlePreferenceTreeClick_stylesAndWallpaper() {
|
||||||
|
mShadowPackageManager.setResolveInfosForIntent(
|
||||||
|
mWallpaperIntent, Lists.newArrayList());
|
||||||
|
mShadowPackageManager.setResolveInfosForIntent(
|
||||||
|
mStylesAndWallpaperIntent, Lists.newArrayList(mock(ResolveInfo.class)));
|
||||||
|
Preference preference = new Preference(mContext);
|
||||||
|
preference.setKey(TEST_KEY);
|
||||||
|
|
||||||
|
mController.handlePreferenceTreeClick(preference);
|
||||||
|
|
||||||
|
assertThat(Shadows.shadowOf(mContext)
|
||||||
|
.getNextStartedActivityForResult().intent.getComponent().getClassName())
|
||||||
|
.isEqualTo(mContext.getString(R.string.config_styles_and_wallpaper_picker_class));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -12,6 +12,7 @@ import androidx.annotation.ArrayRes;
|
|||||||
import org.robolectric.annotation.Implementation;
|
import org.robolectric.annotation.Implementation;
|
||||||
import org.robolectric.annotation.Implements;
|
import org.robolectric.annotation.Implements;
|
||||||
import org.robolectric.annotation.RealObject;
|
import org.robolectric.annotation.RealObject;
|
||||||
|
import org.robolectric.annotation.Resetter;
|
||||||
import org.robolectric.shadows.ShadowResources;
|
import org.robolectric.shadows.ShadowResources;
|
||||||
import org.robolectric.util.ReflectionHelpers.ClassParameter;
|
import org.robolectric.util.ReflectionHelpers.ClassParameter;
|
||||||
|
|
||||||
@@ -40,6 +41,7 @@ public class SettingsShadowResources extends ShadowResources {
|
|||||||
overrideResource(resId, value);
|
overrideResource(resId, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Resetter
|
||||||
public static void reset() {
|
public static void reset() {
|
||||||
sResourceOverrides.clear();
|
sResourceOverrides.clear();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user