package b.a.e;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;

/* JADX INFO: loaded from: classes.dex */
public abstract class d {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public Random f200a = new Random();

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final Map<Integer, String> f201b = new HashMap();

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final Map<String, Integer> f202c = new HashMap();

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final Map<String, c> f203d = new HashMap();

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public ArrayList<String> f204e = new ArrayList<>();

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final transient Map<String, b<?>> f205f = new HashMap();
    public final Map<String, Object> g = new HashMap();
    public final Bundle h = new Bundle();

    /* JADX INFO: Add missing generic type declarations: [I] */
    public class a<I> extends b.a.e.c<I> {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        public final /* synthetic */ String f206a;

        public a(String str, int i, b.a.e.f.a aVar) {
            this.f206a = str;
        }

        @Override // b.a.e.c
        public void a() {
            d.this.c(this.f206a);
        }
    }

    public static class b<O> {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        public final b.a.e.b<O> f208a;

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        public final b.a.e.f.a<?, O> f209b;

        public b(b.a.e.b<O> bVar, b.a.e.f.a<?, O> aVar) {
            this.f208a = bVar;
            this.f209b = aVar;
        }
    }

    public static class c {
    }

    public final boolean a(int i, int i2, Intent intent) {
        b.a.e.b<?> bVar;
        String str = this.f201b.get(Integer.valueOf(i));
        if (str == null) {
            return false;
        }
        this.f204e.remove(str);
        b<?> bVar2 = this.f205f.get(str);
        if (bVar2 != null && (bVar = bVar2.f208a) != null) {
            bVar.a(bVar2.f209b.a(i2, intent));
            return true;
        }
        this.g.remove(str);
        this.h.putParcelable(str, new b.a.e.a(i2, intent));
        return true;
    }

    /* JADX WARN: Multi-variable type inference failed */
    public final <I, O> b.a.e.c<I> b(String str, b.a.e.f.a<I, O> aVar, b.a.e.b<O> bVar) {
        int iIntValue;
        Integer num = this.f202c.get(str);
        if (num != null) {
            iIntValue = num.intValue();
        } else {
            int iNextInt = this.f200a.nextInt(2147418112);
            while (true) {
                iIntValue = iNextInt + 65536;
                if (!this.f201b.containsKey(Integer.valueOf(iIntValue))) {
                    break;
                }
                iNextInt = this.f200a.nextInt(2147418112);
            }
            this.f201b.put(Integer.valueOf(iIntValue), str);
            this.f202c.put(str, Integer.valueOf(iIntValue));
        }
        this.f205f.put(str, new b<>(bVar, aVar));
        if (this.g.containsKey(str)) {
            Object obj = this.g.get(str);
            this.g.remove(str);
            bVar.a(obj);
        }
        b.a.e.a aVar2 = (b.a.e.a) this.h.getParcelable(str);
        if (aVar2 != null) {
            this.h.remove(str);
            bVar.a(aVar.a(aVar2.f198a, aVar2.f199b));
        }
        return new a(str, iIntValue, aVar);
    }

    public final void c(String str) {
        Integer numRemove;
        if (!this.f204e.contains(str) && (numRemove = this.f202c.remove(str)) != null) {
            this.f201b.remove(numRemove);
        }
        this.f205f.remove(str);
        if (this.g.containsKey(str)) {
            Log.w("ActivityResultRegistry", "Dropping pending result for request " + str + ": " + this.g.get(str));
            this.g.remove(str);
        }
        if (this.h.containsKey(str)) {
            Log.w("ActivityResultRegistry", "Dropping pending result for request " + str + ": " + this.h.getParcelable(str));
            this.h.remove(str);
        }
        if (this.f203d.get(str) != null) {
            throw null;
        }
    }
}
