package com.lynx.tasm.utils;

import X.2FV;
import X.2He;
import X.7s1;
import X.8jA;
import X.C4266LhB;
import android.content.ClipboardManager;
import android.content.Context;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.util.DisplayMetrics;
import android.view.WindowManager;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import java.lang.reflect.Field;

public class DisplayMetricsHolder {
    public static DisplayMetrics LIZ;
    public static DisplayMetrics LIZIZ;
    public static int LIZJ = -1;
    public static float LIZLLL = -1.0f;
    public static boolean LJ;

    public static native void nativeUpdateDevice(int i, int i2, float f, String str);

    static {
        Covode.recordClassIndex(47094);
    }

    public static synchronized DisplayMetrics LIZ() {
        DisplayMetrics displayMetrics;
        synchronized (DisplayMetricsHolder.class) {
            MethodCollector.i(3919);
            displayMetrics = LIZIZ;
            MethodCollector.o(3919);
        }
        return displayMetrics;
    }

    public static DisplayMetrics LIZ(Context context) {
        DisplayMetrics displayMetrics = new DisplayMetrics();
        displayMetrics.setTo(LIZ);
        WindowManager windowManager = (WindowManager) LIZ(context, "window");
        C4266LhB.LIZ(windowManager, "WindowManager is null!");
        windowManager.getDefaultDisplay().getRealMetrics(displayMetrics);
        return displayMetrics;
    }

    public static Object LIZ(Context context, String str) {
        Object obj;
        MethodCollector.i(3917);
        if (Build.VERSION.SDK_INT > 27 || !"clipboard".equals(str)) {
            if (!2FV.LIZIZ && "connectivity".equals(str)) {
                try {
                    new 7s1().LIZ();
                    2FV.LIZIZ = true;
                    obj = context.getSystemService(str);
                } catch (Throwable unused) {
                }
            }
            obj = context.getSystemService(str);
        } else if (2FV.LIZ) {
            synchronized (ClipboardManager.class) {
                try {
                    obj = context.getSystemService(str);
                    if (Thread.currentThread() != Looper.getMainLooper().getThread()) {
                        Field declaredField = ClipboardManager.class.getDeclaredField("mHandler");
                        declaredField.setAccessible(true);
                        declaredField.set(obj, new 2He((Handler) declaredField.get(obj)));
                    }
                } catch (Exception e) {
                    8jA.LIZ(e, "ClipboardManager Handler Reflect Fail");
                } catch (Throwable th) {
                    MethodCollector.o(3917);
                    throw th;
                }
                2FV.LIZ = false;
            }
        } else {
            obj = context.getSystemService(str);
        }
        MethodCollector.o(3917);
        return obj;
    }
}
