package ඓ.ඓ.K.䁗.ᓆ;

import android.annotation.TargetApi;
import android.app.Activity;
import android.app.FragmentManager;
import android.os.Build;
import android.text.TextUtils;
import io.reactivex.internal.operators.observable.ObservableConcatMap;
import io.reactivex.internal.util.ErrorMode;
import io.reactivex.subjects.PublishSubject;
import java.util.ArrayList;
import ඓ.ⁱ.K.ඓ.C1252;
import ඓ.K.K.K.C1293;
import 㴹.K.AbstractC2500;
import 㴹.K.AbstractC2511;
import 㴹.K.AbstractC2512;
import 㴹.K.AbstractC2518;
import 㴹.K.Ԕ.ඓ.ῲ.C2440;
import 㴹.K.Ԕ.ඓ.ῲ.C2447;
import 㴹.K.Ԕ.ῲ.C2456;
import 㴹.K.Ԕ.ῲ.C2457;
import 㴹.K.䁗.AbstractC2521;

/* renamed from: ඓ.ඓ.K.䁗.ᓆ.ʬ  reason: contains not printable characters */
/* compiled from: RxPermissions */
public class C0715 {

    /* renamed from: ῲ  reason: contains not printable characters */
    public static final Object f3730 = new Object();

    /* renamed from: K  reason: contains not printable characters */
    public FragmentC0721 f3731;

    /* renamed from: ඓ.ඓ.K.䁗.ᓆ.ʬ$K  reason: contains not printable characters */
    /* compiled from: RxPermissions */
    public class C0716 implements AbstractC2521<Object, AbstractC2500<C0720>> {

        /* renamed from: ῲ  reason: contains not printable characters */
        public final /* synthetic */ String[] f3733;

        public C0716(String[] strArr) {
            this.f3733 = strArr;
        }

        /* Return type fixed from 'java.lang.Object' to match base method */
        @Override // 㴹.K.䁗.AbstractC2521
        public AbstractC2500<C0720> apply(Object obj) throws Exception {
            return C0715.this.m2140(this.f3733);
        }
    }

    public C0715(Activity activity) {
        FragmentC0721 r0 = (FragmentC0721) activity.getFragmentManager().findFragmentByTag("RxPermissions");
        if (r0 == null) {
            r0 = new FragmentC0721();
            FragmentManager fragmentManager = activity.getFragmentManager();
            fragmentManager.beginTransaction().add(r0, "RxPermissions").commitAllowingStateLoss();
            fragmentManager.executePendingTransactions();
        }
        this.f3731 = r0;
    }

    /* JADX WARNING: Code restructure failed: missing block: B:16:0x006f, code lost:
        if (r6.getActivity().getPackageManager().isPermissionRevokedByPolicy(r5, r6.getActivity().getPackageName()) != false) goto L_0x0073;
     */
    /* JADX WARNING: Removed duplicated region for block: B:12:0x0046  */
    /* JADX WARNING: Removed duplicated region for block: B:13:0x0053  */
    @TargetApi(23)
    /* renamed from: ῲ  reason: contains not printable characters */
    public final AbstractC2500<C0720> m2140(String... strArr) {
        boolean z;
        ArrayList arrayList = new ArrayList(strArr.length);
        ArrayList arrayList2 = new ArrayList();
        int length = strArr.length;
        for (int i = 0; i < length; i++) {
            String str = strArr[i];
            FragmentC0721 r6 = this.f3731;
            r6.m2146("Requesting permission " + str);
            boolean z2 = true;
            if (m2143()) {
                if (!(this.f3731.getActivity().checkSelfPermission(str) == 0)) {
                    z = false;
                    if (!z) {
                        arrayList.add(AbstractC2500.m6536(new C0720(str, true, false)));
                    } else {
                        if (m2143()) {
                            FragmentC0721 r62 = this.f3731;
                        }
                        z2 = false;
                        if (z2) {
                            arrayList.add(AbstractC2500.m6536(new C0720(str, false, false)));
                        } else {
                            PublishSubject<C0720> publishSubject = this.f3731.f3740.get(str);
                            if (publishSubject == null) {
                                arrayList2.add(str);
                                publishSubject = new PublishSubject<>();
                                this.f3731.f3740.put(str, publishSubject);
                            }
                            arrayList.add(publishSubject);
                        }
                    }
                }
            }
            z = true;
            if (!z) {
            }
        }
        if (!arrayList2.isEmpty()) {
            String[] strArr2 = (String[]) arrayList2.toArray(new String[arrayList2.size()]);
            FragmentC0721 r1 = this.f3731;
            StringBuilder r2 = C1293.m3416("requestPermissionsFromFragment ");
            r2.append(TextUtils.join(", ", strArr2));
            r1.m2146(r2.toString());
            this.f3731.requestPermissions(strArr2, 42);
        }
        C2456.m6500(arrayList, "source is null");
        AbstractC2500 r10 = C1252.m3345(new C2447(arrayList));
        int r0 = AbstractC2511.m6556();
        C2456.m6500(r10, "sources is null");
        C2456.m6499(r0, "prefetch");
        return C1252.m3345(new ObservableConcatMap(r10, C2457.m6501(), r0, ErrorMode.IMMEDIATE));
    }

    /* renamed from: K  reason: contains not printable characters */
    public AbstractC2500<Boolean> m2142(String... strArr) {
        return AbstractC2500.m6536(f3730).m6542((AbstractC2512) new C0718(this, strArr));
    }

    /* renamed from: K  reason: contains not printable characters */
    public final AbstractC2500<C0720> m2141(AbstractC2500<?> r6, String... strArr) {
        AbstractC2500 r0;
        AbstractC2500 r62;
        AbstractC2500 r63;
        if (strArr == null || strArr.length == 0) {
            throw new IllegalArgumentException("RxPermissions.request/requestEach requires at least one input permission");
        }
        int length = strArr.length;
        int i = 0;
        while (true) {
            if (i >= length) {
                r0 = AbstractC2500.m6536(f3730);
                break;
            }
            if (!this.f3731.f3740.containsKey(strArr[i])) {
                r0 = AbstractC2500.m6535();
                break;
            }
            i++;
        }
        if (r6 == null) {
            r62 = AbstractC2500.m6536(f3730);
        } else {
            C2456.m6500(r6, "source1 is null");
            C2456.m6500(r0, "source2 is null");
            AbstractC2518[] r3 = {r6, r0};
            C2456.m6500(r3, "items is null");
            if (r3.length == 0) {
                r63 = AbstractC2500.m6535();
            } else if (r3.length == 1) {
                r63 = AbstractC2500.m6536(r3[0]);
            } else {
                r63 = C1252.m3345(new C2440(r3));
            }
            r62 = r63.m6543(C2457.f8414, false, 2);
        }
        return r62.m6543(new C0716(strArr), false, Integer.MAX_VALUE);
    }

    /* renamed from: K  reason: contains not printable characters */
    public boolean m2143() {
        return Build.VERSION.SDK_INT >= 23;
    }
}
