package com.seewo.vcommons.utils;

import android.app.ActivityManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.text.TextUtils;
import android.util.Log;
import com.seewo.vcommons.utils.reflect.ActivityManagerInsider;
import java.util.Iterator;

/* JADX INFO: loaded from: classes.dex */
public class PackageUtils {
    private static final String TAG = "PackageUtils";

    private PackageUtils() {
    }

    public static boolean isPackageExist(Context context, String str) {
        Iterator<PackageInfo> it = context.getPackageManager().getInstalledPackages(0).iterator();
        while (it.hasNext()) {
            if (str.equals(it.next().applicationInfo.packageName)) {
                return true;
            }
        }
        return false;
    }

    public static boolean isWidgetExist(Context context, String str, String str2) {
        if (TextUtils.isEmpty(str) || TextUtils.isEmpty(str2)) {
            return false;
        }
        PackageManager packageManager = context.getPackageManager();
        try {
            packageManager.getReceiverInfo(new ComponentName(str, str2), 0);
        } catch (PackageManager.NameNotFoundException e) {
            Log.e(TAG, e.getMessage(), e);
            try {
                packageManager.getReceiverInfo(new ComponentName(packageManager.currentToCanonicalPackageNames(new String[]{str})[0], str2), 0);
            } catch (PackageManager.NameNotFoundException e2) {
                Log.e(TAG, e2.getMessage(), e2);
                return false;
            }
        }
        return true;
    }

    public static void killProcess(Context context, String str) {
        ActivityManagerInsider.forceStopPackage((ActivityManager) context.getSystemService("activity"), str);
    }
}
