package com.flurry.android;

import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.view.View;
import android.view.ViewGroup;

/* loaded from: /storage/emulated/0/Documents/jadec/sources/com.UBI.A90.WW/dex-files/0.dex */
public class GetAdAsyncTask extends AsyncTask<Void, Void, AdUnit> {
    private final String a = getClass().getSimpleName();
    private Context b;
    private String c;
    private FlurryAdSize d;
    private ViewGroup e;
    private bd f;
    private be g;
    private t h;
    private t i;

    public GetAdAsyncTask(Context context, String str, FlurryAdSize flurryAdSize, ViewGroup viewGroup, be beVar) {
        this.b = context;
        this.c = str;
        this.d = flurryAdSize;
        this.e = viewGroup;
        this.f = beVar.d;
        this.g = beVar;
    }

    @Override // android.os.AsyncTask
    protected void onPreExecute() {
        this.h = this.f.a(this.b, (View) this.e, this.c);
        if (this.h == null) {
            this.h = this.f.a(this.g, this.b, this.e, this.c, this.d);
            this.f.b(this.b, this.h);
        }
        this.i = this.f.a(this.e);
        for (t tVar : this.f.a(this.b, this.e, this.c)) {
            if (!tVar.equals(this.i)) {
                this.f.a(this.b, tVar);
                tVar.c().removeView(tVar);
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // android.os.AsyncTask
    public AdUnit doInBackground(Void... voidArr) {
        int a = y.a(this.b, this.e.getWidth());
        int a2 = y.a(this.b, this.e.getHeight());
        AdUnit d = this.g.d(this.c);
        if (d == null) {
            String str = "Making ad request:" + this.c + "," + a + "x" + a2 + ",refresh:false";
            this.g.a(this.c, a, a2, false, this.d, 0L);
            AdUnit d2 = this.g.d(this.c);
            if (d2 == null) {
                return null;
            }
            return d2;
        }
        return d;
    }

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // android.os.AsyncTask
    public void onPostExecute(AdUnit adUnit) {
        if (adUnit != null) {
            q a = this.g.a(this.b, adUnit);
            if (a.b() != null && a.d()) {
                this.h.removeAllViews();
                if (this.h.getParent() == null) {
                    a.b().a(this.e, this.h);
                }
                this.h.addView(a.b());
                this.h.a(0);
                if (!this.h.equals(this.i)) {
                    if (this.i != null) {
                        this.f.a(this.b, this.i);
                        this.e.removeView(this.i);
                    }
                    this.e.addView(this.h);
                }
                if (this.h.a() > 0 && !this.h.b()) {
                    this.f.a(this.h);
                }
            } else if (a.c()) {
                Intent intent = new Intent();
                intent.setClass(this.b, FlurryFullscreenTakeoverActivity.class);
                if (y.a(this.b, intent)) {
                    this.b.startActivity(intent);
                } else {
                    bc.b("FlurryAgent", "Unable to launch FlurryFullscreenTakeoverActivity. Fix by declaring this Activity in your AndroidManifest.xml");
                }
            }
        }
    }
}
