package d;

import android.content.Intent;
import android.content.IntentSender;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import android.util.Log;
import androidx.lifecycle.InterfaceC0514t;
import d3.V0;
import d5.AbstractC0844a;
import f.C0893a;
import f.C0897e;
import f.C0898f;
import f.C0899g;
import f.C0900h;
import f.InterfaceC0894b;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import y5.AbstractActivityC1764i;

/* JADX INFO: loaded from: classes.dex */
public final class g {

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final HashMap f11269b = new HashMap();

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

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

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final transient HashMap f11272e = new HashMap();

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final HashMap f11273f = new HashMap();

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

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final /* synthetic */ AbstractActivityC1764i f11275h;

    public g(AbstractActivityC1764i abstractActivityC1764i) {
        this.f11275h = abstractActivityC1764i;
    }

    public final boolean a(int i, int i5, Intent intent) {
        String str = (String) this.f11268a.get(Integer.valueOf(i));
        if (str == null) {
            return false;
        }
        C0898f c0898f = (C0898f) this.f11272e.get(str);
        if (c0898f != null) {
            InterfaceC0894b interfaceC0894b = c0898f.f12597a;
            if (this.f11271d.contains(str)) {
                interfaceC0894b.a(c0898f.f12598b.w(intent, i5));
                this.f11271d.remove(str);
                return true;
            }
        }
        this.f11273f.remove(str);
        this.f11274g.putParcelable(str, new C0893a(intent, i5));
        return true;
    }

    public final void b(int i, s7.l lVar, Object obj) {
        Bundle bundleExtra;
        int i5;
        AbstractActivityC1764i abstractActivityC1764i = this.f11275h;
        V0 v0P = lVar.p(abstractActivityC1764i, obj);
        if (v0P != null) {
            new Handler(Looper.getMainLooper()).post(new f(this, i, v0P, 0));
            return;
        }
        Intent intentG = lVar.g(abstractActivityC1764i, obj);
        if (intentG.getExtras() != null && intentG.getExtras().getClassLoader() == null) {
            intentG.setExtrasClassLoader(abstractActivityC1764i.getClassLoader());
        }
        if (intentG.hasExtra("androidx.activity.result.contract.extra.ACTIVITY_OPTIONS_BUNDLE")) {
            bundleExtra = intentG.getBundleExtra("androidx.activity.result.contract.extra.ACTIVITY_OPTIONS_BUNDLE");
            intentG.removeExtra("androidx.activity.result.contract.extra.ACTIVITY_OPTIONS_BUNDLE");
        } else {
            bundleExtra = null;
        }
        Bundle bundle = bundleExtra;
        if ("androidx.activity.result.contract.action.REQUEST_PERMISSIONS".equals(intentG.getAction())) {
            String[] stringArrayExtra = intentG.getStringArrayExtra("androidx.activity.result.contract.extra.PERMISSIONS");
            if (stringArrayExtra == null) {
                stringArrayExtra = new String[0];
            }
            HashSet hashSet = new HashSet();
            for (int i8 = 0; i8 < stringArrayExtra.length; i8++) {
                if (TextUtils.isEmpty(stringArrayExtra[i8])) {
                    throw new IllegalArgumentException(I1.a.r(new StringBuilder("Permission request for permissions "), Arrays.toString(stringArrayExtra), " must not contain null or empty values"));
                }
                if (Build.VERSION.SDK_INT < 33 && TextUtils.equals(stringArrayExtra[i8], "android.permission.POST_NOTIFICATIONS")) {
                    hashSet.add(Integer.valueOf(i8));
                }
            }
            int size = hashSet.size();
            String[] strArr = size > 0 ? new String[stringArrayExtra.length - size] : stringArrayExtra;
            if (size > 0) {
                if (size == stringArrayExtra.length) {
                    return;
                }
                int i9 = 0;
                for (int i10 = 0; i10 < stringArrayExtra.length; i10++) {
                    if (!hashSet.contains(Integer.valueOf(i10))) {
                        strArr[i9] = stringArrayExtra[i10];
                        i9++;
                    }
                }
            }
            abstractActivityC1764i.requestPermissions(stringArrayExtra, i);
            return;
        }
        if (!"androidx.activity.result.contract.action.INTENT_SENDER_REQUEST".equals(intentG.getAction())) {
            abstractActivityC1764i.startActivityForResult(intentG, i, bundle);
            return;
        }
        C0900h c0900h = (C0900h) intentG.getParcelableExtra("androidx.activity.result.contract.extra.INTENT_SENDER_REQUEST");
        try {
            i5 = i;
            try {
                abstractActivityC1764i.startIntentSenderForResult(c0900h.f12601q, i5, c0900h.f12602r, c0900h.f12603s, c0900h.f12604t, 0, bundle);
            } catch (IntentSender.SendIntentException e8) {
                e = e8;
                new Handler(Looper.getMainLooper()).post(new f(this, i5, e, 1));
            }
        } catch (IntentSender.SendIntentException e9) {
            e = e9;
            i5 = i;
        }
    }

    public final C0897e c(String str, s7.l lVar, InterfaceC0894b interfaceC0894b) {
        d(str);
        this.f11272e.put(str, new C0898f(interfaceC0894b, lVar));
        HashMap map = this.f11273f;
        if (map.containsKey(str)) {
            Object obj = map.get(str);
            map.remove(str);
            interfaceC0894b.a(obj);
        }
        Bundle bundle = this.f11274g;
        C0893a c0893a = (C0893a) bundle.getParcelable(str);
        if (c0893a != null) {
            bundle.remove(str);
            interfaceC0894b.a(lVar.w(c0893a.f12588r, c0893a.f12587q));
        }
        return new C0897e(this, str, lVar, 1);
    }

    public final void d(String str) {
        HashMap map = this.f11269b;
        if (((Integer) map.get(str)) != null) {
            return;
        }
        S6.a aVar = S6.d.f6298q;
        int iNextInt = S6.d.f6298q.e().nextInt(2147418112);
        while (true) {
            int i = iNextInt + 65536;
            HashMap map2 = this.f11268a;
            if (!map2.containsKey(Integer.valueOf(i))) {
                map2.put(Integer.valueOf(i), str);
                map.put(str, Integer.valueOf(i));
                return;
            } else {
                S6.a aVar2 = S6.d.f6298q;
                iNextInt = S6.d.f6298q.e().nextInt(2147418112);
            }
        }
    }

    public final void e(String str) {
        Integer num;
        if (!this.f11271d.contains(str) && (num = (Integer) this.f11269b.remove(str)) != null) {
            this.f11268a.remove(num);
        }
        this.f11272e.remove(str);
        HashMap map = this.f11273f;
        if (map.containsKey(str)) {
            StringBuilder sbP = AbstractC0844a.p("Dropping pending result for request ", str, ": ");
            sbP.append(map.get(str));
            Log.w("ActivityResultRegistry", sbP.toString());
            map.remove(str);
        }
        Bundle bundle = this.f11274g;
        if (bundle.containsKey(str)) {
            StringBuilder sbP2 = AbstractC0844a.p("Dropping pending result for request ", str, ": ");
            sbP2.append(bundle.getParcelable(str));
            Log.w("ActivityResultRegistry", sbP2.toString());
            bundle.remove(str);
        }
        HashMap map2 = this.f11270c;
        C0899g c0899g = (C0899g) map2.get(str);
        if (c0899g != null) {
            ArrayList arrayList = c0899g.f12600b;
            int size = arrayList.size();
            int i = 0;
            while (i < size) {
                Object obj = arrayList.get(i);
                i++;
                c0899g.f12599a.y((InterfaceC0514t) obj);
            }
            arrayList.clear();
            map2.remove(str);
        }
    }
}
