package o; 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 androidx.core.view.ViewCompat; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; /* loaded from: classes.dex */ public final class Rut { private static Field a = null; private static boolean b = false; private static boolean c = false; private static Method e; /* loaded from: classes.dex */ public interface Sts { boolean superDispatchKeyEvent(KeyEvent keyEvent); } public static boolean rt_(View view, KeyEvent keyEvent) { return ViewCompat.se_(view, keyEvent); } public static boolean ru_(Sts sts, View view, Window.Callback callback, KeyEvent keyEvent) { if (sts == null) { return false; } if (Build.VERSION.SDK_INT >= 28) { return sts.superDispatchKeyEvent(keyEvent); } if (callback instanceof Activity) { return rr_((Activity) callback, keyEvent); } if (callback instanceof Dialog) { return rs_((Dialog) callback, keyEvent); } return (view != null && ViewCompat.sd_(view, keyEvent)) || sts.superDispatchKeyEvent(keyEvent); } private static boolean rq_(ActionBar actionBar, KeyEvent keyEvent) { if (!b) { try { e = actionBar.getClass().getMethod("onMenuKeyEvent", KeyEvent.class); } catch (NoSuchMethodException unused) { } b = true; } Method method = e; if (method != null) { try { Object invoke = method.invoke(actionBar, keyEvent); if (invoke == null) { return false; } return ((Boolean) invoke).booleanValue(); } catch (IllegalAccessException | InvocationTargetException unused2) { } } return false; } private static boolean rr_(Activity activity, KeyEvent keyEvent) { activity.onUserInteraction(); Window window = activity.getWindow(); if (window.hasFeature(8)) { ActionBar actionBar = activity.getActionBar(); if (keyEvent.getKeyCode() == 82 && actionBar != null && rq_(actionBar, keyEvent)) { return true; } } if (window.superDispatchKeyEvent(keyEvent)) { return true; } View decorView = window.getDecorView(); if (ViewCompat.sd_(decorView, keyEvent)) { return true; } return keyEvent.dispatch(activity, decorView != null ? decorView.getKeyDispatcherState() : null, activity); } private static DialogInterface.OnKeyListener rv_(Dialog dialog) { if (!c) { try { Field declaredField = Dialog.class.getDeclaredField("mOnKeyListener"); a = declaredField; declaredField.setAccessible(true); } catch (NoSuchFieldException unused) { } c = true; } Field field = a; if (field == null) { return null; } try { return (DialogInterface.OnKeyListener) field.get(dialog); } catch (IllegalAccessException unused2) { return null; } } private static boolean rs_(Dialog dialog, KeyEvent keyEvent) { DialogInterface.OnKeyListener rv_ = rv_(dialog); if (rv_ != null && rv_.onKey(dialog, keyEvent.getKeyCode(), keyEvent)) { return true; } Window window = dialog.getWindow(); if (window.superDispatchKeyEvent(keyEvent)) { return true; } View decorView = window.getDecorView(); if (ViewCompat.sd_(decorView, keyEvent)) { return true; } return keyEvent.dispatch(dialog, decorView != null ? decorView.getKeyDispatcherState() : null, dialog); } }