package g.f.a;

import android.app.Application;
import android.app.LoadedApk;
import android.content.res.Resources;
import android.util.Log;
import java.io.File;
import java.lang.ref.WeakReference;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/* JADX INFO: loaded from: classes.dex */
public class b {
    public static Resources a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static LoadedApk f4224b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public static ClassLoader f4225c;

    public static Field a(Class<?> cls, String str) throws NoSuchFieldException {
        Class<?> superclass = cls;
        while (true) {
            try {
                Field declaredField = superclass.getDeclaredField(str);
                declaredField.setAccessible(true);
                return declaredField;
            } catch (Throwable unused) {
                if (superclass == Object.class) {
                    StringBuilder sbK = g.a.a.a.a.K("Cannot find field ", str, " in class ");
                    sbK.append(cls.getName());
                    sbK.append(" and its super classes.");
                    throw new NoSuchFieldException(sbK.toString());
                }
                superclass = superclass.getSuperclass();
            }
        }
    }

    public static List<File> b() {
        try {
            ClassLoader classLoader = b.class.getClassLoader();
            Object obj = a(Class.forName("dalvik.system.BaseDexClassLoader", false, classLoader), "pathList").get(classLoader);
            return (List) a(obj.getClass(), "nativeLibraryDirectories").get(obj);
        } catch (Throwable th) {
            Log.e("Hotfix", "getOriginNativeLibraryDirectories failed", th);
            return new ArrayList();
        }
    }

    public static boolean c(File file) {
        return file.exists() && file.canRead() && file.isFile();
    }

    public static void d(Application application, File file) {
        try {
            List<File> listB = b();
            listB.add(0, file.getParentFile());
            StringBuilder sb = new StringBuilder();
            boolean z2 = true;
            for (File file2 : listB) {
                if (file2 != null) {
                    if (z2) {
                        z2 = false;
                    } else {
                        sb.append(File.pathSeparator);
                    }
                    sb.append(file2.getAbsolutePath());
                }
            }
            f4225c = new a(file.getAbsolutePath(), sb.toString(), b.class.getClassLoader());
            Class<?> cls = Class.forName("android.app.ActivityThread");
            Field declaredField = cls.getDeclaredField("sCurrentActivityThread");
            declaredField.setAccessible(true);
            Object obj = declaredField.get(null);
            Field declaredField2 = cls.getDeclaredField("mPackages");
            declaredField2.setAccessible(true);
            f4224b = (LoadedApk) ((WeakReference) ((Map) declaredField2.get(obj)).get(application.getPackageName())).get();
            Field declaredField3 = LoadedApk.class.getDeclaredField("mClassLoader");
            declaredField3.setAccessible(true);
            declaredField3.set(f4224b, f4225c);
        } catch (Throwable th) {
            Log.e("Hotfix", "loadHotfixClassLoader failed", th);
        }
    }
}
