Loading res/values/config.xml +2 −0 Original line number Diff line number Diff line Loading @@ -47,6 +47,8 @@ <!-- 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_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 --> <string name="config_backup_settings_intent" translatable="false"></string> Loading res/xml/display_settings.xml +0 −3 Original line number Diff line number Diff line Loading @@ -53,9 +53,6 @@ settings:keywords="@string/keywords_display_wallpaper" settings:useAdminDisabledSummary="true" 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> Loading src/com/android/settings/display/TopLevelDisplayPreferenceController.java +7 −3 Original line number Diff line number Diff line Loading @@ -36,11 +36,15 @@ public class TopLevelDisplayPreferenceController extends BasePreferenceControlle @Override public CharSequence getSummary() { if (new WallpaperPreferenceController(mContext, "dummy_key").isAvailable()) { return mContext.getText(R.string.display_dashboard_summary); final WallpaperPreferenceController controller = 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 { return mContext.getText(R.string.display_dashboard_nowallpaper_summary); } } } src/com/android/settings/display/WallpaperPreferenceController.java +38 −9 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import android.text.TextUtils; import android.util.Log; import androidx.preference.Preference; import androidx.preference.PreferenceScreen; import com.android.settings.R; import com.android.settings.core.BasePreferenceController; Loading @@ -34,16 +35,26 @@ import com.android.settingslib.RestrictedPreference; import java.util.List; public class WallpaperPreferenceController extends BasePreferenceController { private static final String TAG = "WallpaperPrefController"; private final String mWallpaperPackage; private final String mWallpaperClass; private final String mStylesAndWallpaperClass; 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); 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 Loading @@ -52,14 +63,7 @@ public class WallpaperPreferenceController extends BasePreferenceController { Log.e(TAG, "No Wallpaper picker specified!"); return UNSUPPORTED_ON_DEVICE; } final ComponentName componentName = 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() return canResolveWallpaperComponent(mWallpaperClass) ? AVAILABLE_UNSEARCHABLE : CONDITIONALLY_UNAVAILABLE; } Loading @@ -68,6 +72,31 @@ public class WallpaperPreferenceController extends BasePreferenceController { 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) { final String restriction = DISALLOW_SET_WALLPAPER; if (pref != null) { Loading tests/robotests/src/com/android/settings/display/TopLevelDisplayPreferenceControllerTest.java +16 −4 Original line number Diff line number Diff line Loading @@ -39,14 +39,13 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Config; import java.util.ArrayList; import java.util.List; import org.robolectric.annotation.Config; import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; @RunWith(RobolectricTestRunner.class) public class TopLevelDisplayPreferenceControllerTest { private Context mContext; Loading Loading @@ -88,6 +87,19 @@ public class TopLevelDisplayPreferenceControllerTest { .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 public void getSummary_hasWallpaper_shouldReturnNoWallpaperSummary() { final List<ResolveInfo> resolveInfos = new ArrayList<>(); Loading Loading
res/values/config.xml +2 −0 Original line number Diff line number Diff line Loading @@ -47,6 +47,8 @@ <!-- 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_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 --> <string name="config_backup_settings_intent" translatable="false"></string> Loading
res/xml/display_settings.xml +0 −3 Original line number Diff line number Diff line Loading @@ -53,9 +53,6 @@ settings:keywords="@string/keywords_display_wallpaper" settings:useAdminDisabledSummary="true" 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> Loading
src/com/android/settings/display/TopLevelDisplayPreferenceController.java +7 −3 Original line number Diff line number Diff line Loading @@ -36,11 +36,15 @@ public class TopLevelDisplayPreferenceController extends BasePreferenceControlle @Override public CharSequence getSummary() { if (new WallpaperPreferenceController(mContext, "dummy_key").isAvailable()) { return mContext.getText(R.string.display_dashboard_summary); final WallpaperPreferenceController controller = 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 { return mContext.getText(R.string.display_dashboard_nowallpaper_summary); } } }
src/com/android/settings/display/WallpaperPreferenceController.java +38 −9 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import android.text.TextUtils; import android.util.Log; import androidx.preference.Preference; import androidx.preference.PreferenceScreen; import com.android.settings.R; import com.android.settings.core.BasePreferenceController; Loading @@ -34,16 +35,26 @@ import com.android.settingslib.RestrictedPreference; import java.util.List; public class WallpaperPreferenceController extends BasePreferenceController { private static final String TAG = "WallpaperPrefController"; private final String mWallpaperPackage; private final String mWallpaperClass; private final String mStylesAndWallpaperClass; 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); 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 Loading @@ -52,14 +63,7 @@ public class WallpaperPreferenceController extends BasePreferenceController { Log.e(TAG, "No Wallpaper picker specified!"); return UNSUPPORTED_ON_DEVICE; } final ComponentName componentName = 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() return canResolveWallpaperComponent(mWallpaperClass) ? AVAILABLE_UNSEARCHABLE : CONDITIONALLY_UNAVAILABLE; } Loading @@ -68,6 +72,31 @@ public class WallpaperPreferenceController extends BasePreferenceController { 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) { final String restriction = DISALLOW_SET_WALLPAPER; if (pref != null) { Loading
tests/robotests/src/com/android/settings/display/TopLevelDisplayPreferenceControllerTest.java +16 −4 Original line number Diff line number Diff line Loading @@ -39,14 +39,13 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Config; import java.util.ArrayList; import java.util.List; import org.robolectric.annotation.Config; import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; @RunWith(RobolectricTestRunner.class) public class TopLevelDisplayPreferenceControllerTest { private Context mContext; Loading Loading @@ -88,6 +87,19 @@ public class TopLevelDisplayPreferenceControllerTest { .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 public void getSummary_hasWallpaper_shouldReturnNoWallpaperSummary() { final List<ResolveInfo> resolveInfos = new ArrayList<>(); Loading