Merge "Nullify the default wallpaper component if it does not exist"

This commit is contained in:
Treehugger Robot
2018-11-30 16:45:02 +00:00
committed by Gerrit Code Review

View File

@@ -1885,23 +1885,33 @@ public class WallpaperManager {
* @hide * @hide
*/ */
public static ComponentName getDefaultWallpaperComponent(Context context) { public static ComponentName getDefaultWallpaperComponent(Context context) {
ComponentName cn = null;
String flat = SystemProperties.get(PROP_WALLPAPER_COMPONENT); String flat = SystemProperties.get(PROP_WALLPAPER_COMPONENT);
if (!TextUtils.isEmpty(flat)) { if (!TextUtils.isEmpty(flat)) {
final ComponentName cn = ComponentName.unflattenFromString(flat); cn = ComponentName.unflattenFromString(flat);
if (cn != null) { }
return cn;
if (cn == null) {
flat = context.getString(com.android.internal.R.string.default_wallpaper_component);
if (!TextUtils.isEmpty(flat)) {
cn = ComponentName.unflattenFromString(flat);
} }
} }
flat = context.getString(com.android.internal.R.string.default_wallpaper_component); // Check if the package exists
if (!TextUtils.isEmpty(flat)) { if (cn != null) {
final ComponentName cn = ComponentName.unflattenFromString(flat); try {
if (cn != null) { final PackageManager packageManager = context.getPackageManager();
return cn; packageManager.getPackageInfo(cn.getPackageName(),
PackageManager.MATCH_DIRECT_BOOT_AWARE
| PackageManager.MATCH_DIRECT_BOOT_UNAWARE);
} catch (PackageManager.NameNotFoundException e) {
cn = null;
} }
} }
return null; return cn;
} }
/** /**