package com.seewo.vcommons.helper;

import android.content.Context;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.WindowManager;
import java.io.InputStream;

/* JADX INFO: loaded from: classes.dex */
public class WallpaperHelper {
    static final /* synthetic */ boolean $assertionsDisabled = false;
    private static final String TAG = "WallpaperHelper";

    public static String tryGetDefaultWallpaperName(Context context, String str, Resources resources) {
        try {
            WindowManager windowManager = (WindowManager) context.getApplicationContext().getSystemService("window");
            DisplayMetrics displayMetrics = new DisplayMetrics();
            windowManager.getDefaultDisplay().getMetrics(displayMetrics);
            int length = resources.getStringArray(resources.getIdentifier("wallpaper_id_list_5k", "array", str)).length;
            if (displayMetrics.widthPixels < 5120 || length <= 0) {
                return "wallpaper_default";
            }
            return "wallpaper_default_5k";
        } catch (Exception e) {
            Log.i(TAG, "check 5k wallpaper has error e=" + e);
            return "wallpaper_default";
        }
    }

    public static int tryGetDefaultWallpaperResId(Context context, String str, Resources resources) {
        if (resources == null) {
            return -1;
        }
        try {
            return resources.getIdentifier(tryGetDefaultWallpaperName(context, str, resources), "drawable", str);
        } catch (Exception e) {
            Log.i(TAG, "has error when get default wallpaper res id e=" + e);
            return -1;
        }
    }

    public static InputStream tryGetDefaultWallpaper(Context context, String str) {
        Resources resourcesForApplication;
        int iTryGetDefaultWallpaperResId;
        PackageManager packageManager = context.getPackageManager();
        if (TextUtils.isEmpty(str)) {
            return null;
        }
        try {
            resourcesForApplication = packageManager.getResourcesForApplication(str);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
            resourcesForApplication = null;
        }
        if (resourcesForApplication == null || (iTryGetDefaultWallpaperResId = tryGetDefaultWallpaperResId(context, str, resourcesForApplication)) == 0) {
            return null;
        }
        return resourcesForApplication.openRawResource(iTryGetDefaultWallpaperResId);
    }
}
