Merge "Fixes AOSP crash when WPP isn't installed." into udc-dev

This commit is contained in:
TreeHugger Robot
2023-03-23 00:53:08 +00:00
committed by Android (Google) Code Review
3 changed files with 57 additions and 7 deletions

View File

@@ -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)) {

View File

@@ -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;
@@ -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,
@@ -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;
}
}