package d.a.e;

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

/* JADX INFO: loaded from: classes.dex */
public abstract class e {
    public Random a = new Random();

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

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

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

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

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

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

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final Bundle f1519h = new Bundle();

    /* JADX INFO: Add missing generic type declarations: [I] */
    public class a<I> extends d.a.e.c<I> {
        public final /* synthetic */ String a;

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        public final /* synthetic */ int f1520b;

        /* JADX INFO: renamed from: c, reason: collision with root package name */
        public final /* synthetic */ d.a.e.h.a f1521c;

        public a(String str, int i2, d.a.e.h.a aVar) {
            this.a = str;
            this.f1520b = i2;
            this.f1521c = aVar;
        }

        @Override // d.a.e.c
        public void a(I i2, d.h.b.c cVar) {
            e.this.f1516e.add(this.a);
            Integer num = e.this.f1514c.get(this.a);
            e.this.b(num != null ? num.intValue() : this.f1520b, this.f1521c, i2, null);
        }

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

    public static class b<O> {
        public final d.a.e.b<O> a;

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

        public b(d.a.e.b<O> bVar, d.a.e.h.a<?, O> aVar) {
            this.a = bVar;
            this.f1523b = aVar;
        }
    }

    public static class c {
        public final d.m.e a;

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        public final ArrayList<d.m.f> f1524b = new ArrayList<>();

        public c(d.m.e eVar) {
            this.a = eVar;
        }
    }

    public final boolean a(int i2, int i3, Intent intent) {
        d.a.e.b<?> bVar;
        String str = this.f1513b.get(Integer.valueOf(i2));
        if (str == null) {
            return false;
        }
        this.f1516e.remove(str);
        b<?> bVar2 = this.f1517f.get(str);
        if (bVar2 != null && (bVar = bVar2.a) != null) {
            bVar.a(bVar2.f1523b.c(i3, intent));
            return true;
        }
        this.f1518g.remove(str);
        this.f1519h.putParcelable(str, new d.a.e.a(i3, intent));
        return true;
    }

    public abstract <I, O> void b(int i2, d.a.e.h.a<I, O> aVar, @SuppressLint({"UnknownNullness"}) I i3, d.h.b.c cVar);

    /* JADX WARN: Multi-variable type inference failed */
    public final <I, O> d.a.e.c<I> c(String str, d.a.e.h.a<I, O> aVar, d.a.e.b<O> bVar) {
        int iD = d(str);
        this.f1517f.put(str, new b<>(bVar, aVar));
        if (this.f1518g.containsKey(str)) {
            Object obj = this.f1518g.get(str);
            this.f1518g.remove(str);
            bVar.a(obj);
        }
        d.a.e.a aVar2 = (d.a.e.a) this.f1519h.getParcelable(str);
        if (aVar2 != null) {
            this.f1519h.remove(str);
            bVar.a(aVar.c(aVar2.f1508f, aVar2.f1509m));
        }
        return new a(str, iD, aVar);
    }

    public final int d(String str) {
        Integer num = this.f1514c.get(str);
        if (num != null) {
            return num.intValue();
        }
        int iNextInt = this.a.nextInt(2147418112);
        while (true) {
            int i2 = iNextInt + 65536;
            if (!this.f1513b.containsKey(Integer.valueOf(i2))) {
                this.f1513b.put(Integer.valueOf(i2), str);
                this.f1514c.put(str, Integer.valueOf(i2));
                return i2;
            }
            iNextInt = this.a.nextInt(2147418112);
        }
    }

    public final void e(String str) {
        Integer numRemove;
        if (!this.f1516e.contains(str) && (numRemove = this.f1514c.remove(str)) != null) {
            this.f1513b.remove(numRemove);
        }
        this.f1517f.remove(str);
        if (this.f1518g.containsKey(str)) {
            StringBuilder sbK = g.a.a.a.a.K("Dropping pending result for request ", str, ": ");
            sbK.append(this.f1518g.get(str));
            Log.w("ActivityResultRegistry", sbK.toString());
            this.f1518g.remove(str);
        }
        if (this.f1519h.containsKey(str)) {
            StringBuilder sbK2 = g.a.a.a.a.K("Dropping pending result for request ", str, ": ");
            sbK2.append(this.f1519h.getParcelable(str));
            Log.w("ActivityResultRegistry", sbK2.toString());
            this.f1519h.remove(str);
        }
        c cVar = this.f1515d.get(str);
        if (cVar != null) {
            Iterator<d.m.f> it = cVar.f1524b.iterator();
            while (it.hasNext()) {
                cVar.a.b(it.next());
            }
            cVar.f1524b.clear();
            this.f1515d.remove(str);
        }
    }
}
