package e;

import android.content.Context;
import android.content.ContextWrapper;
import android.view.View;
import androidx.annotation.Nullable;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/* JADX INFO: loaded from: classes.dex */
public final class p0 implements View.OnClickListener {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final View f25310a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final String f25311b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public Method f25312c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public Context f25313d;

    public p0(View view, String str) {
        this.f25310a = view;
        this.f25311b = str;
    }

    private void resolveMethod(@Nullable Context context) {
        String str;
        Method method;
        while (true) {
            String str2 = this.f25311b;
            if (context == null) {
                View view = this.f25310a;
                int id2 = view.getId();
                if (id2 == -1) {
                    str = "";
                } else {
                    str = " with id '" + view.getContext().getResources().getResourceEntryName(id2) + "'";
                }
                throw new IllegalStateException("Could not find method " + str2 + "(View) in a parent or ancestor Context for android:onClick attribute defined on view " + view.getClass() + str);
            }
            try {
                if (!context.isRestricted() && (method = context.getClass().getMethod(str2, View.class)) != null) {
                    this.f25312c = method;
                    this.f25313d = context;
                    return;
                }
            } catch (NoSuchMethodException unused) {
            }
            context = context instanceof ContextWrapper ? ((ContextWrapper) context).getBaseContext() : null;
        }
    }

    @Override // android.view.View.OnClickListener
    public final void onClick(View view) {
        if (this.f25312c == null) {
            resolveMethod(this.f25310a.getContext());
        }
        try {
            this.f25312c.invoke(this.f25313d, view);
        } catch (IllegalAccessException e10) {
            throw new IllegalStateException("Could not execute non-public method for android:onClick", e10);
        } catch (InvocationTargetException e11) {
            throw new IllegalStateException("Could not execute method for android:onClick", e11);
        }
    }
}
