Loading src/com/android/settings/display/CustomizableLockScreenQuickAffordancesPreferenceController.java +1 −1 Original line number Diff line number Diff line Loading @@ -50,7 +50,7 @@ public class CustomizableLockScreenQuickAffordancesPreferenceController extends final Preference preference = screen.findPreference(getPreferenceKey()); if (preference != null) { preference.setOnPreferenceClickListener(preference1 -> { final Intent intent = new Intent(Intent.ACTION_SET_WALLPAPER); final Intent intent = CustomizableLockScreenUtils.newIntent(); final String packageName = mContext.getString(R.string.config_wallpaper_picker_package); if (!TextUtils.isEmpty(packageName)) { Loading src/com/android/settings/display/CustomizableLockScreenUtils.java +19 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,8 @@ package com.android.settings.display; import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; import android.database.Cursor; import android.net.Uri; import android.text.TextUtils; Loading Loading @@ -67,6 +69,10 @@ public final class CustomizableLockScreenUtils { * <p>This is a slow, blocking call that shouldn't be made on the main thread. */ public static boolean isFeatureEnabled(Context context) { if (!isWallpaperPickerInstalled(context)) { return false; } try (Cursor cursor = context.getContentResolver().query( FLAGS_URI, null, Loading Loading @@ -151,4 +157,17 @@ public final class CustomizableLockScreenUtils { return null; } } /** * Returns a new {@link Intent} that can be used to start the wallpaper picker * activity. */ public static Intent newIntent() { return new Intent(Intent.ACTION_SET_WALLPAPER); } private static boolean isWallpaperPickerInstalled(Context context) { final PackageManager packageManager = context.getPackageManager(); return newIntent().resolveActivity(packageManager) != null; } } tests/robotests/src/com/android/settings/display/CustomizableLockScreenQuickAffordancesPreferenceControllerTest.java +37 −6 Original line number Diff line number Diff line Loading @@ -21,6 +21,8 @@ import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_ import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.any; import static org.mockito.Mockito.anyInt; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; Loading @@ -28,6 +30,10 @@ import static org.mockito.Mockito.when; import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.content.pm.ActivityInfo; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.database.MatrixCursor; import android.text.TextUtils; Loading @@ -54,6 +60,7 @@ public class CustomizableLockScreenQuickAffordancesPreferenceControllerTest { @Mock private Context mContext; @Mock private ContentResolver mContentResolver; @Mock private PackageManager mPackageManager; private CustomizableLockScreenQuickAffordancesPreferenceController mUnderTest; Loading @@ -63,20 +70,28 @@ public class CustomizableLockScreenQuickAffordancesPreferenceControllerTest { when(mContext.getContentResolver()).thenReturn(mContentResolver); when(mContext.getResources()) .thenReturn(ApplicationProvider.getApplicationContext().getResources()); when(mContext.getPackageManager()).thenReturn(mPackageManager); mUnderTest = new CustomizableLockScreenQuickAffordancesPreferenceController(mContext, KEY); } @Test public void getAvailabilityStatus_whenEnabled() { setEnabled(true); public void getAvailabilityStatus_whenFeatureEnabled() { setEnabled(/* isWallpaperPickerInstalled= */ true, /* isFeatureEnabled = */ true); assertThat(mUnderTest.getAvailabilityStatus()).isEqualTo(AVAILABLE); } @Test public void getAvailabilityStatus_whenNotEnabled() { setEnabled(false); public void getAvailabilityStatus_whenWallpaperPickerNotInstalledEnabled() { setEnabled(/* isWallpaperPickerInstalled= */ false, /* isFeatureEnabled = */ true); assertThat(mUnderTest.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE); } @Test public void getAvailabilityStatus_whenFeatureNotEnabled() { setEnabled(/* isWallpaperPickerInstalled= */ true, /* isFeatureEnabled = */ false); assertThat(mUnderTest.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE); } Loading Loading @@ -127,13 +142,29 @@ public class CustomizableLockScreenQuickAffordancesPreferenceControllerTest { assertThat(TextUtils.equals(mUnderTest.getSummary(), "one, two")).isTrue(); } private void setEnabled(boolean isEnabled) { private void setEnabled(boolean isWallpaperPickerInstalled, boolean isFeatureEnabled) { if (isWallpaperPickerInstalled) { final ResolveInfo resolveInfo = new ResolveInfo(); final ActivityInfo activityInfo = new ActivityInfo(); final ApplicationInfo applicationInfo = new ApplicationInfo(); applicationInfo.packageName = "com.fake.name"; activityInfo.applicationInfo = applicationInfo; activityInfo.name = "someName"; resolveInfo.activityInfo = activityInfo; when(mPackageManager.resolveActivity(any(), anyInt())).thenReturn(resolveInfo); } else { when(mPackageManager.resolveActivity(any(), anyInt())).thenReturn(null); } final MatrixCursor cursor = new MatrixCursor( new String[] { CustomizableLockScreenUtils.NAME, CustomizableLockScreenUtils.VALUE }); cursor.addRow(new Object[] { CustomizableLockScreenUtils.ENABLED_FLAG, isEnabled ? 1 : 0 }); cursor.addRow( new Object[] { CustomizableLockScreenUtils.ENABLED_FLAG, isFeatureEnabled ? 1 : 0 }); when( mContentResolver.query( CustomizableLockScreenUtils.FLAGS_URI, null, null, null)) Loading Loading
src/com/android/settings/display/CustomizableLockScreenQuickAffordancesPreferenceController.java +1 −1 Original line number Diff line number Diff line Loading @@ -50,7 +50,7 @@ public class CustomizableLockScreenQuickAffordancesPreferenceController extends final Preference preference = screen.findPreference(getPreferenceKey()); if (preference != null) { preference.setOnPreferenceClickListener(preference1 -> { final Intent intent = new Intent(Intent.ACTION_SET_WALLPAPER); final Intent intent = CustomizableLockScreenUtils.newIntent(); final String packageName = mContext.getString(R.string.config_wallpaper_picker_package); if (!TextUtils.isEmpty(packageName)) { Loading
src/com/android/settings/display/CustomizableLockScreenUtils.java +19 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,8 @@ package com.android.settings.display; import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; import android.database.Cursor; import android.net.Uri; import android.text.TextUtils; Loading Loading @@ -67,6 +69,10 @@ public final class CustomizableLockScreenUtils { * <p>This is a slow, blocking call that shouldn't be made on the main thread. */ public static boolean isFeatureEnabled(Context context) { if (!isWallpaperPickerInstalled(context)) { return false; } try (Cursor cursor = context.getContentResolver().query( FLAGS_URI, null, Loading Loading @@ -151,4 +157,17 @@ public final class CustomizableLockScreenUtils { return null; } } /** * Returns a new {@link Intent} that can be used to start the wallpaper picker * activity. */ public static Intent newIntent() { return new Intent(Intent.ACTION_SET_WALLPAPER); } private static boolean isWallpaperPickerInstalled(Context context) { final PackageManager packageManager = context.getPackageManager(); return newIntent().resolveActivity(packageManager) != null; } }
tests/robotests/src/com/android/settings/display/CustomizableLockScreenQuickAffordancesPreferenceControllerTest.java +37 −6 Original line number Diff line number Diff line Loading @@ -21,6 +21,8 @@ import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_ import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.any; import static org.mockito.Mockito.anyInt; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; Loading @@ -28,6 +30,10 @@ import static org.mockito.Mockito.when; import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.content.pm.ActivityInfo; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.database.MatrixCursor; import android.text.TextUtils; Loading @@ -54,6 +60,7 @@ public class CustomizableLockScreenQuickAffordancesPreferenceControllerTest { @Mock private Context mContext; @Mock private ContentResolver mContentResolver; @Mock private PackageManager mPackageManager; private CustomizableLockScreenQuickAffordancesPreferenceController mUnderTest; Loading @@ -63,20 +70,28 @@ public class CustomizableLockScreenQuickAffordancesPreferenceControllerTest { when(mContext.getContentResolver()).thenReturn(mContentResolver); when(mContext.getResources()) .thenReturn(ApplicationProvider.getApplicationContext().getResources()); when(mContext.getPackageManager()).thenReturn(mPackageManager); mUnderTest = new CustomizableLockScreenQuickAffordancesPreferenceController(mContext, KEY); } @Test public void getAvailabilityStatus_whenEnabled() { setEnabled(true); public void getAvailabilityStatus_whenFeatureEnabled() { setEnabled(/* isWallpaperPickerInstalled= */ true, /* isFeatureEnabled = */ true); assertThat(mUnderTest.getAvailabilityStatus()).isEqualTo(AVAILABLE); } @Test public void getAvailabilityStatus_whenNotEnabled() { setEnabled(false); public void getAvailabilityStatus_whenWallpaperPickerNotInstalledEnabled() { setEnabled(/* isWallpaperPickerInstalled= */ false, /* isFeatureEnabled = */ true); assertThat(mUnderTest.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE); } @Test public void getAvailabilityStatus_whenFeatureNotEnabled() { setEnabled(/* isWallpaperPickerInstalled= */ true, /* isFeatureEnabled = */ false); assertThat(mUnderTest.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE); } Loading Loading @@ -127,13 +142,29 @@ public class CustomizableLockScreenQuickAffordancesPreferenceControllerTest { assertThat(TextUtils.equals(mUnderTest.getSummary(), "one, two")).isTrue(); } private void setEnabled(boolean isEnabled) { private void setEnabled(boolean isWallpaperPickerInstalled, boolean isFeatureEnabled) { if (isWallpaperPickerInstalled) { final ResolveInfo resolveInfo = new ResolveInfo(); final ActivityInfo activityInfo = new ActivityInfo(); final ApplicationInfo applicationInfo = new ApplicationInfo(); applicationInfo.packageName = "com.fake.name"; activityInfo.applicationInfo = applicationInfo; activityInfo.name = "someName"; resolveInfo.activityInfo = activityInfo; when(mPackageManager.resolveActivity(any(), anyInt())).thenReturn(resolveInfo); } else { when(mPackageManager.resolveActivity(any(), anyInt())).thenReturn(null); } final MatrixCursor cursor = new MatrixCursor( new String[] { CustomizableLockScreenUtils.NAME, CustomizableLockScreenUtils.VALUE }); cursor.addRow(new Object[] { CustomizableLockScreenUtils.ENABLED_FLAG, isEnabled ? 1 : 0 }); cursor.addRow( new Object[] { CustomizableLockScreenUtils.ENABLED_FLAG, isFeatureEnabled ? 1 : 0 }); when( mContentResolver.query( CustomizableLockScreenUtils.FLAGS_URI, null, null, null)) Loading