package X6FRs_4.IMuAHx_6.EuDEkJe_12;

import android.app.ActionBar;
import android.app.Activity;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Build;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
/* compiled from: KeyEventDispatcher.java */
/* loaded from: classes.dex */
public class Mqv2r_3 {
    public static Field KQgRr5e_0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public static Method f377KQgRr5e_0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public static boolean f378KQgRr5e_0;
    public static boolean QxJ9d_1;

    /* compiled from: KeyEventDispatcher.java */
    /* loaded from: classes.dex */
    public interface KQgRr5e_0 {
        boolean superDispatchKeyEvent(KeyEvent keyEvent);
    }

    public static boolean KQgRr5e_0(View view, KeyEvent keyEvent) {
        return ZzDuCHW_20.QxJ9d_1(view, keyEvent);
    }

    public static boolean KQgRr5e_0(KQgRr5e_0 kQgRr5e_0, View view, Window.Callback callback, KeyEvent keyEvent) {
        if (kQgRr5e_0 == null) {
            return false;
        }
        if (Build.VERSION.SDK_INT >= 28) {
            return kQgRr5e_0.superDispatchKeyEvent(keyEvent);
        }
        if (callback instanceof Activity) {
            return KQgRr5e_0((Activity) callback, keyEvent);
        }
        if (callback instanceof Dialog) {
            return KQgRr5e_0((Dialog) callback, keyEvent);
        }
        return (view != null && ZzDuCHW_20.KQgRr5e_0(view, keyEvent)) || kQgRr5e_0.superDispatchKeyEvent(keyEvent);
    }

    public static boolean KQgRr5e_0(ActionBar actionBar, KeyEvent keyEvent) {
        if (!f378KQgRr5e_0) {
            try {
                f377KQgRr5e_0 = actionBar.getClass().getMethod("onMenuKeyEvent", KeyEvent.class);
            } catch (NoSuchMethodException unused) {
            }
            f378KQgRr5e_0 = true;
        }
        Method method = f377KQgRr5e_0;
        if (method != null) {
            try {
                return ((Boolean) method.invoke(actionBar, keyEvent)).booleanValue();
            } catch (IllegalAccessException | InvocationTargetException unused2) {
            }
        }
        return false;
    }

    public static boolean KQgRr5e_0(Activity activity, KeyEvent keyEvent) {
        activity.onUserInteraction();
        Window window = activity.getWindow();
        if (window.hasFeature(8)) {
            ActionBar actionBar = activity.getActionBar();
            if (keyEvent.getKeyCode() == 82 && actionBar != null && KQgRr5e_0(actionBar, keyEvent)) {
                return true;
            }
        }
        if (window.superDispatchKeyEvent(keyEvent)) {
            return true;
        }
        View decorView = window.getDecorView();
        if (ZzDuCHW_20.KQgRr5e_0(decorView, keyEvent)) {
            return true;
        }
        return keyEvent.dispatch(activity, decorView != null ? decorView.getKeyDispatcherState() : null, activity);
    }

    public static DialogInterface.OnKeyListener KQgRr5e_0(Dialog dialog) {
        if (!QxJ9d_1) {
            try {
                Field declaredField = Dialog.class.getDeclaredField("mOnKeyListener");
                KQgRr5e_0 = declaredField;
                declaredField.setAccessible(true);
            } catch (NoSuchFieldException unused) {
            }
            QxJ9d_1 = true;
        }
        Field field = KQgRr5e_0;
        if (field != null) {
            try {
                return (DialogInterface.OnKeyListener) field.get(dialog);
            } catch (IllegalAccessException unused2) {
                return null;
            }
        }
        return null;
    }

    public static boolean KQgRr5e_0(Dialog dialog, KeyEvent keyEvent) {
        DialogInterface.OnKeyListener KQgRr5e_02 = KQgRr5e_0(dialog);
        if (KQgRr5e_02 == null || !KQgRr5e_02.onKey(dialog, keyEvent.getKeyCode(), keyEvent)) {
            Window window = dialog.getWindow();
            if (window.superDispatchKeyEvent(keyEvent)) {
                return true;
            }
            View decorView = window.getDecorView();
            if (ZzDuCHW_20.KQgRr5e_0(decorView, keyEvent)) {
                return true;
            }
            return keyEvent.dispatch(dialog, decorView != null ? decorView.getKeyDispatcherState() : null, dialog);
        }
        return true;
    }
}
