package e8;

import android.R;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Resources;
import android.util.TypedValue;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.app.l0;
import androidx.core.app.s0;
import androidx.fragment.app.FragmentActivity;
import com.google.android.gms.common.ErrorDialogFragment;
import com.google.android.gms.common.annotation.KeepForSdk;
import com.google.android.gms.common.api.internal.u0;
import com.google.android.gms.common.api.internal.w0;
import com.google.android.gms.common.api.internal.zabx;
import com.google.android.gms.common.internal.ShowFirstParty;
import com.google.android.gms.common.internal.e0;
import com.google.android.gms.common.internal.h0;
import com.google.errorprone.annotations.ResultIgnorabilityUnspecified;

/* JADX INFO: loaded from: classes2.dex */
public final class d extends e {

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public static final Object f25519c = new Object();

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public static final d f25520d = new d();

    @Override // e8.e
    public final int b(Context context, int i10) {
        return super.b(context, i10);
    }

    @Nullable
    public Dialog getErrorDialog(@NonNull Activity activity, int i10, int i11) {
        return getErrorDialog(activity, i10, i11, (DialogInterface.OnCancelListener) null);
    }

    @Override // e8.e
    @Nullable
    @ShowFirstParty
    @KeepForSdk
    public Intent getErrorResolutionIntent(@Nullable Context context, int i10, @Nullable String str) {
        return super.getErrorResolutionIntent(context, i10, str);
    }

    @Override // e8.e
    @Nullable
    public PendingIntent getErrorResolutionPendingIntent(@NonNull Context context, int i10, int i11) {
        return super.getErrorResolutionPendingIntent(context, i10, i11);
    }

    @ResultIgnorabilityUnspecified
    public boolean showErrorDialogFragment(@NonNull Activity activity, int i10, int i11, @Nullable DialogInterface.OnCancelListener onCancelListener) {
        Dialog errorDialog = getErrorDialog(activity, i10, i11, onCancelListener);
        if (errorDialog == null) {
            return false;
        }
        zad(activity, errorDialog, "GooglePlayServicesErrorDialog", onCancelListener);
        return true;
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Type inference failed for: r0v0 */
    /* JADX WARN: Type inference failed for: r0v1 */
    /* JADX WARN: Type inference failed for: r0v2, types: [android.app.AlertDialog$Builder] */
    /* JADX WARN: Type inference failed for: r0v3, types: [android.app.AlertDialog$Builder] */
    /* JADX WARN: Type inference failed for: r0v5 */
    /* JADX WARN: Type inference failed for: r8v0, types: [com.google.android.gms.common.internal.h0] */
    /* JADX WARN: Type inference failed for: r8v1, types: [android.content.DialogInterface$OnClickListener] */
    /* JADX WARN: Type inference failed for: r8v2 */
    @Nullable
    public final Dialog zaa(@NonNull Context context, int i10, @Nullable h0 h0Var, @Nullable DialogInterface.OnCancelListener onCancelListener, @Nullable DialogInterface.OnClickListener onClickListener) {
        if (i10 == 0) {
            return null;
        }
        TypedValue typedValue = new TypedValue();
        context.getTheme().resolveAttribute(R.attr.alertDialogTheme, typedValue, true);
        ?? builder = "Theme.Dialog.Alert".equals(context.getResources().getResourceEntryName(typedValue.resourceId)) ? new AlertDialog.Builder(context, 5) : 0;
        if (builder == 0) {
            builder = new AlertDialog.Builder(context);
        }
        builder.setMessage(e0.b(context, i10));
        if (onCancelListener != null) {
            builder.setOnCancelListener(onCancelListener);
        }
        Resources resources = context.getResources();
        String string = i10 != 1 ? i10 != 2 ? i10 != 3 ? resources.getString(R.string.ok) : resources.getString(c8.c.common_google_play_services_enable_button) : resources.getString(c8.c.common_google_play_services_update_button) : resources.getString(c8.c.common_google_play_services_install_button);
        if (string != null) {
            if (h0Var == 0) {
                h0Var = onClickListener;
            }
            builder.setPositiveButton(string, h0Var);
        }
        String strZaf = e0.zaf(context, i10);
        if (strZaf != null) {
            builder.setTitle(strZaf);
        }
        String.format("Creating dialog for Google Play services availability issue. ConnectionResult=%s", Integer.valueOf(i10));
        new IllegalArgumentException();
        return builder.create();
    }

    @Nullable
    @ResultIgnorabilityUnspecified
    public final zabx zac(Context context, com.google.android.gms.common.api.internal.e0 e0Var) {
        IntentFilter intentFilter = new IntentFilter("android.intent.action.PACKAGE_ADDED");
        intentFilter.addDataScheme("package");
        zabx zabxVar = new zabx(e0Var);
        o8.c.zaa(context, zabxVar, intentFilter);
        zabxVar.a(context);
        if (g.b(context)) {
            return zabxVar;
        }
        u0 u0Var = (u0) e0Var;
        w0 w0Var = (w0) u0Var.f8293b.f8296c;
        w0Var.f8300c.set(null);
        o8.e eVar = ((com.google.android.gms.common.api.internal.x) w0Var).f8304g.f8244k;
        eVar.sendMessage(eVar.obtainMessage(3));
        Dialog dialog = u0Var.f8292a;
        if (dialog.isShowing()) {
            dialog.dismiss();
        }
        zabxVar.b();
        return null;
    }

    public final void zad(Activity activity, Dialog dialog, String str, @Nullable DialogInterface.OnCancelListener onCancelListener) {
        try {
            if (activity instanceof FragmentActivity) {
                j.newInstance(dialog, onCancelListener).show(((FragmentActivity) activity).getSupportFragmentManager(), str);
                return;
            }
        } catch (NoClassDefFoundError unused) {
        }
        ErrorDialogFragment.newInstance(dialog, onCancelListener).show(activity.getFragmentManager(), str);
    }

    @TargetApi(20)
    public final void zae(Context context, int i10, @Nullable String str, @Nullable PendingIntent pendingIntent) {
        int i11;
        String.format("GMS core API Availability. ConnectionResult=%s, tag=%s", Integer.valueOf(i10), null);
        new IllegalArgumentException();
        if (i10 == 18) {
            new l(this, context).sendEmptyMessageDelayed(1, 120000L);
            return;
        }
        if (pendingIntent == null) {
            return;
        }
        String strC = e0.c(context, i10);
        String strD = (i10 == 6 || i10 == 19) ? e0.d(context, "common_google_play_services_resolution_required_text", e0.a(context)) : e0.b(context, i10);
        Resources resources = context.getResources();
        NotificationManager notificationManager = (NotificationManager) com.google.android.gms.common.internal.w.checkNotNull(context.getSystemService("notification"));
        s0 s0Var = new s0(context, null);
        s0Var.f1670y = true;
        s0Var.b(16, true);
        s0 style = s0Var.setContentTitle(strC).setStyle(new l0().bigText(strD));
        if (i8.e.d(context)) {
            style.Q.icon = context.getApplicationInfo().icon;
            style.f1658m = 2;
            if (i8.e.e(context)) {
                style.addAction(c8.b.common_full_open_on_phone, resources.getString(c8.c.common_open_on_phone), pendingIntent);
            } else {
                style.setContentIntent(pendingIntent);
            }
        } else {
            style.Q.icon = R.drawable.stat_sys_warning;
            s0 ticker = style.setTicker(resources.getString(c8.c.common_google_play_services_notification_ticker));
            ticker.Q.when = System.currentTimeMillis();
            ticker.setContentIntent(pendingIntent).setContentText(strD);
        }
        if (com.bumptech.glide.g.l()) {
            com.google.android.gms.common.internal.w.g(com.bumptech.glide.g.l());
            synchronized (f25519c) {
            }
            NotificationChannel notificationChannel = notificationManager.getNotificationChannel("com.google.android.gms.availability");
            String string = context.getResources().getString(c8.c.common_google_play_services_notification_channel_name);
            if (notificationChannel == null) {
                notificationManager.createNotificationChannel(com.google.android.material.textfield.w.z(string));
            } else if (!string.contentEquals(notificationChannel.getName())) {
                notificationChannel.setName(string);
                notificationManager.createNotificationChannel(notificationChannel);
            }
            style.J = "com.google.android.gms.availability";
        }
        Notification notificationA = style.a();
        if (i10 == 1 || i10 == 2 || i10 == 3) {
            g.f25524a.set(false);
            i11 = 10436;
        } else {
            i11 = 39789;
        }
        notificationManager.notify(i11, notificationA);
    }

    @ResultIgnorabilityUnspecified
    public final boolean zag(@NonNull Activity activity, @NonNull com.google.android.gms.common.api.internal.i iVar, int i10, int i11, @Nullable DialogInterface.OnCancelListener onCancelListener) {
        Dialog dialogZaa = zaa(activity, i10, h0.zad(iVar, getErrorResolutionIntent(activity, i10, "d"), 2), onCancelListener, null);
        if (dialogZaa == null) {
            return false;
        }
        zad(activity, dialogZaa, "GooglePlayServicesErrorDialog", onCancelListener);
        return true;
    }

    @Nullable
    public Dialog getErrorDialog(@NonNull Activity activity, int i10, int i11, @Nullable DialogInterface.OnCancelListener onCancelListener) {
        return zaa(activity, i10, h0.zab(activity, getErrorResolutionIntent(activity, i10, "d"), i11), onCancelListener, null);
    }

    @Nullable
    public PendingIntent getErrorResolutionPendingIntent(@NonNull Context context, @NonNull b bVar) {
        return bVar.w() ? bVar.getResolution() : getErrorResolutionPendingIntent(context, bVar.f25514b, 0);
    }

    public boolean showErrorDialogFragment(@NonNull Activity activity, int i10, @NonNull androidx.activity.result.d dVar, @Nullable DialogInterface.OnCancelListener onCancelListener) {
        Dialog dialogZaa = zaa(activity, i10, null, onCancelListener, new k(this, activity, i10, dVar));
        if (dialogZaa == null) {
            return false;
        }
        zad(activity, dialogZaa, "GooglePlayServicesErrorDialog", onCancelListener);
        return true;
    }

    @Nullable
    public Dialog getErrorDialog(@NonNull androidx.fragment.app.e0 e0Var, int i10, int i11) {
        return getErrorDialog(e0Var, i10, i11, (DialogInterface.OnCancelListener) null);
    }

    @Nullable
    public Dialog getErrorDialog(@NonNull androidx.fragment.app.e0 e0Var, int i10, int i11, @Nullable DialogInterface.OnCancelListener onCancelListener) {
        return zaa(e0Var.requireContext(), i10, h0.zac(e0Var, getErrorResolutionIntent(e0Var.requireContext(), i10, "d"), i11), onCancelListener, null);
    }
}
