package X6FRs_4.IMuAHx_6.Mqv2r_3;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.util.Log;
import java.util.ArrayList;
import java.util.Iterator;
/* compiled from: TaskStackBuilder.java */
/* loaded from: classes.dex */
public final class Nm6q_10 implements Iterable<Intent> {
    public final Context KQgRr5e_0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public final ArrayList<Intent> f465KQgRr5e_0 = new ArrayList<>();

    /* compiled from: TaskStackBuilder.java */
    /* loaded from: classes.dex */
    public interface KQgRr5e_0 {
        Intent getSupportParentActivityIntent();
    }

    public Nm6q_10(Context context) {
        this.KQgRr5e_0 = context;
    }

    public static Nm6q_10 KQgRr5e_0(Context context) {
        return new Nm6q_10(context);
    }

    @Override // java.lang.Iterable
    @Deprecated
    public Iterator<Intent> iterator() {
        return this.f465KQgRr5e_0.iterator();
    }

    public Nm6q_10 KQgRr5e_0(Intent intent) {
        this.f465KQgRr5e_0.add(intent);
        return this;
    }

    public Nm6q_10 KQgRr5e_0(Activity activity) {
        Intent supportParentActivityIntent = activity instanceof KQgRr5e_0 ? ((KQgRr5e_0) activity).getSupportParentActivityIntent() : null;
        if (supportParentActivityIntent == null) {
            supportParentActivityIntent = Mqv2r_3.KQgRr5e_0(activity);
        }
        if (supportParentActivityIntent != null) {
            ComponentName component = supportParentActivityIntent.getComponent();
            if (component == null) {
                component = supportParentActivityIntent.resolveActivity(this.KQgRr5e_0.getPackageManager());
            }
            KQgRr5e_0(component);
            KQgRr5e_0(supportParentActivityIntent);
        }
        return this;
    }

    public Nm6q_10 KQgRr5e_0(ComponentName componentName) {
        int size = this.f465KQgRr5e_0.size();
        try {
            Intent KQgRr5e_02 = Mqv2r_3.KQgRr5e_0(this.KQgRr5e_0, componentName);
            while (KQgRr5e_02 != null) {
                this.f465KQgRr5e_0.add(size, KQgRr5e_02);
                KQgRr5e_02 = Mqv2r_3.KQgRr5e_0(this.KQgRr5e_0, KQgRr5e_02.getComponent());
            }
            return this;
        } catch (PackageManager.NameNotFoundException e) {
            Log.e("TaskStackBuilder", "Bad ComponentName while traversing activity parent metadata");
            throw new IllegalArgumentException(e);
        }
    }

    public void KQgRr5e_0() {
        KQgRr5e_0((Bundle) null);
    }

    public void KQgRr5e_0(Bundle bundle) {
        if (!this.f465KQgRr5e_0.isEmpty()) {
            ArrayList<Intent> arrayList = this.f465KQgRr5e_0;
            Intent[] intentArr = (Intent[]) arrayList.toArray(new Intent[arrayList.size()]);
            intentArr[0] = new Intent(intentArr[0]).addFlags(268484608);
            if (X6FRs_4.IMuAHx_6.X6FRs_4.KQgRr5e_0.KQgRr5e_0(this.KQgRr5e_0, intentArr, bundle)) {
                return;
            }
            Intent intent = new Intent(intentArr[intentArr.length - 1]);
            intent.addFlags(268435456);
            this.KQgRr5e_0.startActivity(intent);
            return;
        }
        throw new IllegalStateException("No intents added to TaskStackBuilder; cannot startActivities");
    }
}
