package com.pairip;

import android.content.Context;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
/* loaded from: classes8.dex */
final class InitContextProvider {
    /* JADX INFO: Access modifiers changed from: package-private */
    public static Context tryToCreateContextForBindingApp() {
        try {
            Class<?> cls = Class.forName("android.app.LoadedApk");
            Class<?> cls2 = Class.forName("android.app.ActivityThread");
            Method method = cls2.getMethod("currentActivityThread", null);
            Field declaredField = cls2.getDeclaredField("mBoundApplication");
            declaredField.setAccessible(true);
            Field declaredField2 = Class.forName("android.app.ActivityThread$AppBindData").getDeclaredField("info");
            declaredField2.setAccessible(true);
            Method declaredMethod = Class.forName("android.app.ContextImpl").getDeclaredMethod("createAppContext", cls2, cls);
            declaredMethod.setAccessible(true);
            Object invoke = method.invoke(null, null);
            Object invoke2 = declaredMethod.invoke(null, invoke, declaredField2.get(declaredField.get(invoke)));
            tryToInitializeBasicInstrumentationForStartActivity(cls2, invoke);
            return (Context) invoke2;
        } catch (ClassNotFoundException | IllegalAccessException | NoSuchFieldException | NoSuchMethodException | RuntimeException | InvocationTargetException unused) {
            return null;
        }
    }

    private static void tryToInitializeBasicInstrumentationForStartActivity(Class<?> activityThreadClass, Object activityThread) {
        try {
            Field declaredField = activityThreadClass.getDeclaredField("mInstrumentation");
            declaredField.setAccessible(true);
            declaredField.set(activityThread, Class.forName("android.app.Instrumentation").getDeclaredConstructor(null).newInstance(null));
        } catch (ClassNotFoundException | IllegalAccessException | InstantiationException | NoSuchFieldException | NoSuchMethodException | RuntimeException | InvocationTargetException unused) {
        }
    }

    private InitContextProvider() {
    }
}
